Skip to content

Commit

Permalink
Merge pull request #4 from modular-ftc/update-to-4.3-lite
Browse files Browse the repository at this point in the history
Update to 4.3 lite
  • Loading branch information
iamwood authored Nov 10, 2018
2 parents 72da7d0 + c24fe99 commit 4f214eb
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.ftc_version = '4.0'
ext.ftc_version = '4.3'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
targetSdkVersion 19
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

versionCode 44
versionCode 45
versionName "$ftc_version.0-lite"

ndk {
Expand Down
11 changes: 10 additions & 1 deletion library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- FtcCommon manifest -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.qualcomm.ftccommon">
package="com.qualcomm.ftccommon"
android:versionCode="55"
android:versionName="8.9" >

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission
Expand All @@ -10,6 +12,9 @@
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:required="true" />
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
android:required="true" />

<application
android:allowBackup="true"
Expand Down Expand Up @@ -74,6 +79,10 @@
android:exported="true"
android:label="@string/title_activity_wifi_remembered_groups_editor" >
</activity>
<activity
android:name="com.qualcomm.ftccommon.AboutActivity"
android:label="@string/about_activity" >
</activity>
<activity
android:name="com.qualcomm.ftccommon.FtcAboutActivity"
android:label="@string/ftc_about_activity" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,8 @@ public IBinder onBind(Intent intent) {

NetworkType networkType = (NetworkType) intent.getSerializableExtra(NetworkConnectionFactory.NETWORK_CONNECTION_TYPE);

NetworkConnectionHandler networkConnectionHandler = NetworkConnectionHandler.getInstance();
networkConnectionHandler.pushNetworkConnectionCallback(this);

networkConnection = NetworkConnectionFactory.getNetworkConnection(networkType, getBaseContext());
networkConnection.setCallback(this);
networkConnection.enable();
networkConnection.createConnection();

Expand Down Expand Up @@ -474,6 +472,7 @@ public synchronized void shutdownRobot() {
@Override
public CallbackResult onNetworkConnectionEvent(NetworkConnection.NetworkEvent event) {
CallbackResult result = CallbackResult.NOT_HANDLED;
RobotLog.ii(TAG, "onNetworkConnectionEvent: " + event.toString());
switch (event) {
case CONNECTED_AS_GROUP_OWNER:
RobotLog.ii(TAG, "Wifi Direct - connected as group owner");
Expand Down
73 changes: 64 additions & 9 deletions library/src/main/java/com/qualcomm/ftccommon/SoundPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ are permitted (subject to the limitations in the disclaimer below) provided that

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.CheckResult;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -125,6 +128,7 @@ public static SoundPlayer getInstance()
protected float soundOnVolume = 1.0f;
protected float soundOffVolume = 0.0f;
protected float masterVolume = 1.0f;
protected MediaPlayer mediaSizer;

protected static class CurrentlyPlaying
{
Expand Down Expand Up @@ -155,7 +159,29 @@ protected enum StopWhat { All, Loops }
*/
public SoundPlayer(int simultaneousStreams, int cacheSize)
{
soundPool = new SoundPool(simultaneousStreams, AudioManager.STREAM_MUSIC, /*quality*/0); // can't use SoundPool.Builder on KitKat
mediaSizer = new MediaPlayer();
if (Build.VERSION.SDK_INT >= 21)
{
AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder();
audioAttributesBuilder.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
AudioAttributes audioAttributes = audioAttributesBuilder.build();

SoundPool.Builder soundPoolBuilder = new SoundPool.Builder();
soundPoolBuilder.setAudioAttributes(audioAttributes);
soundPoolBuilder.setMaxStreams(simultaneousStreams);
soundPool = soundPoolBuilder.build();

mediaSizer.setAudioAttributes(audioAttributes);
AudioManager audioManager = (AudioManager)(AppUtil.getDefContext().getSystemService(Context.AUDIO_SERVICE));
int audioSessionId = audioManager.generateAudioSessionId();
mediaSizer.setAudioSessionId(audioSessionId);
}
else
{
/** {@link AudioManager#STREAM_NOTIFICATION} might have been a better choice, but we use STREAM_MUSIC because we've always done so; not worth changing */
soundPool = new SoundPool(simultaneousStreams, AudioManager.STREAM_MUSIC, /*quality*/0); // can't use SoundPool.Builder on KitKat
mediaSizer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
loadedSounds = new LoadedSoundCache(cacheSize);
currentlyPlayingSounds = new HashSet<>();
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(AppUtil.getDefContext());
Expand Down Expand Up @@ -191,6 +217,10 @@ public void close()
scheduledThreadPool.shutdownNow();
ThreadPool.awaitTerminationOrExitApplication(scheduledThreadPool, 3, TimeUnit.SECONDS, "SoundPool", "internal error");
}
if (mediaSizer != null)
{
mediaSizer.release();
}
}

/**
Expand Down Expand Up @@ -627,18 +657,43 @@ protected void startPlayingLoadedSound(final SoundInfo soundInfo, @Nullable Play

protected int getMsDuration(Context context, @RawRes int resourceId)
{
MediaPlayer mediaPlayer = MediaPlayer.create(context, resourceId);
int msDuration = mediaPlayer.getDuration();
mediaPlayer.release();
return msDuration;
int msDuration = 0;
synchronized (lock)
{
try {
mediaSizer.reset();
AssetFileDescriptor afd = context.getResources().openRawResourceFd(resourceId);
mediaSizer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
mediaSizer.prepare();
msDuration = mediaSizer.getDuration();
}
catch (IOException e)
{
tracer.traceError(e,"exception preparing media sizer; media duration taken to be zero");;
}
}
return msDuration < 0 ? 0 : msDuration;
}

protected int getMsDuration(Context context, File file)
{
MediaPlayer mediaPlayer = MediaPlayer.create(context, Uri.fromFile(file));
int msDuration = mediaPlayer.getDuration();
mediaPlayer.release();
return msDuration;
Uri uri = Uri.fromFile(file);
int msDuration = 0;
synchronized (lock)
{
try {
mediaSizer.reset();
mediaSizer.setDataSource(context, uri);
mediaSizer.prepare();
msDuration = mediaSizer.getDuration();
}
catch (IOException e)
{
tracer.traceError(e,"exception preparing media sizer; media duration taken to be zero");;
}
}
return msDuration < 0 ? 0 : msDuration;
}

protected void waitForLoadCompletion()
Expand Down
5 changes: 3 additions & 2 deletions library/src/main/java/com/qualcomm/ftccommon/UpdateUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ void refreshNetworkStatus() {
final String message = String.format(format, strNetworkStatus, strPeerStatus);

// Log if changed
if (DEBUG || !message.equals(UpdateUI.this.networkStatusMessage)) RobotLog.v(message);
UpdateUI.this.networkStatusMessage = message;
if (!message.equals(UpdateUI.this.networkStatusMessage)) RobotLog.vv(TAG, message);

UpdateUI.this.networkStatusMessage = message;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -295,6 +295,7 @@ String trimTextErrorMessage(String message) {
//------------------------------------------------------------------------------------------------

public static final boolean DEBUG = false;
private static final String TAG = "UpdateUI";
private static final int NUM_GAMEPADS = 2;

protected TextView textDeviceName;
Expand Down
Binary file modified library/src/main/res/raw/chimeconnect.wav
Binary file not shown.

0 comments on commit 4f214eb

Please sign in to comment.