summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwjiang <wjiang@codeaurora.org>2014-02-14 17:45:53 +0800
committeremancebo <emancebo@cyngn.com>2014-09-04 10:40:18 -0700
commita92b9d9f030cf1a9c74ac410a30a5d264743f51e (patch)
treea9a87517af3942652d47f943f85ac02b3cbc4631
parentf919dbf15fb9d3894a4235f6cf0b1d3511124686 (diff)
downloadandroid_packages_apps_Gallery2-a92b9d9f030cf1a9c74ac410a30a5d264743f51e.tar.gz
android_packages_apps_Gallery2-a92b9d9f030cf1a9c74ac410a30a5d264743f51e.tar.bz2
android_packages_apps_Gallery2-a92b9d9f030cf1a9c74ac410a30a5d264743f51e.zip
Gallery2: Fix batches of issues in movie effects
Fix following issues: - All settings aren't restored to previous state when user cancel his operations. - Check the validity to avoid calling member function of an already released object. - Recycle effect instance when MovieActivity pauses. - Don't restore strength from pref when toggling switch. - Force the Effect's dialog to be uncancelable. - Fix null pointer and effect leak issue due to CMCC features. - Fix audio effects dialog display on small screens - Recognize bluetooth headset. Change-Id: I803897508c0c1a6723170b7691e3ece03680e4f1
-rw-r--r--AndroidManifest.xml1
-rw-r--r--res/drawable-hdpi/knob.pngbin34246 -> 51511 bytes
-rw-r--r--res/drawable-hdpi/knob_bg.pngbin14924 -> 0 bytes
-rw-r--r--res/layout/audio_effects_dialog.xml4
-rwxr-xr-xsrc/com/android/gallery3d/app/MovieActivity.java74
-rw-r--r--src/com/android/gallery3d/app/MoviePlayer.java2
-rwxr-xr-xsrc/com/android/gallery3d/ui/Knob.java25
7 files changed, 64 insertions, 42 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4e8a351c3..9e9f1de7a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -35,6 +35,7 @@
<uses-permission android:name="android.permission.WRITE_APN_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER" />
+ <uses-permission android:name="android.permission.BLUETOOTH" />
<supports-screens android:smallScreens="false"
android:normalScreens="true" android:largeScreens="true"
diff --git a/res/drawable-hdpi/knob.png b/res/drawable-hdpi/knob.png
index a6871ad5a..1eba937fe 100644
--- a/res/drawable-hdpi/knob.png
+++ b/res/drawable-hdpi/knob.png
Binary files differ
diff --git a/res/drawable-hdpi/knob_bg.png b/res/drawable-hdpi/knob_bg.png
deleted file mode 100644
index 342350937..000000000
--- a/res/drawable-hdpi/knob_bg.png
+++ /dev/null
Binary files differ
diff --git a/res/layout/audio_effects_dialog.xml b/res/layout/audio_effects_dialog.xml
index 83892c224..4715d54b8 100644
--- a/res/layout/audio_effects_dialog.xml
+++ b/res/layout/audio_effects_dialog.xml
@@ -65,16 +65,16 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
android:id="@+id/bBStrengthKnob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:layout_weight="1"
custom:label="@string/bass_boost_strength"
- custom:background="@drawable/knob_bg"
custom:foreground="@drawable/knob" />
<com.android.gallery3d.ui.Knob
android:id="@+id/vIStrengthKnob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:layout_weight="1"
custom:label="@string/virtualizer_strength"
- custom:background="@drawable/knob_bg"
custom:foreground="@drawable/knob" />
</LinearLayout>
diff --git a/src/com/android/gallery3d/app/MovieActivity.java b/src/com/android/gallery3d/app/MovieActivity.java
index d22e56f82..325930746 100755
--- a/src/com/android/gallery3d/app/MovieActivity.java
+++ b/src/com/android/gallery3d/app/MovieActivity.java
@@ -71,6 +71,8 @@ import org.codeaurora.gallery3d.ext.MovieItem;
import org.codeaurora.gallery3d.ext.MovieUtils;
import org.codeaurora.gallery3d.video.ExtensionHelper;
import org.codeaurora.gallery3d.video.MovieTitleHelper;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothProfile;
/**
* This activity plays a video from a specified URI.
@@ -102,7 +104,6 @@ public class MovieActivity extends Activity {
private boolean mVirtualizerSupported = false;
private boolean mBassBoostSupported = false;
- private SharedPreferences mPrefs;
static enum Key {
global_enabled, bb_strength, virt_strength
};
@@ -114,6 +115,7 @@ public class MovieActivity extends Activity {
private Knob mBassBoostKnob;
private Knob mVirtualizerKnob;
+ private SharedPreferences mPrefs;
private ShareActionProvider mShareProvider;
private IMovieItem mMovieItem;
private IActivityHooker mMovieHooker;
@@ -142,10 +144,10 @@ public class MovieActivity extends Activity {
|| audioManager.isWiredHeadsetOn();
}
} else if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
- mIsHeadsetOn = audioManager.isBluetoothA2dpOn() || audioManager.isWiredHeadsetOn();
+ mIsHeadsetOn = false;
}
if (mEffectDialog != null) {
- if (!mIsHeadsetOn && mEffectDialog.isShowing()) {
+ if (!mIsHeadsetOn && !isBtHeadsetConnected() && mEffectDialog.isShowing()) {
mEffectDialog.dismiss();
showHeadsetPlugToast();
}
@@ -182,6 +184,8 @@ public class MovieActivity extends Activity {
initializeActionBar(intent);
mFinishOnCompletion = intent.getBooleanExtra(
MediaStore.EXTRA_FINISH_ON_COMPLETION, true);
+ mPrefs = getSharedPreferences(getApplicationContext().getPackageName(),
+ Context.MODE_PRIVATE);
mPlayer = new MoviePlayer(rootView, this, mMovieItem, savedInstanceState,
!mFinishOnCompletion) {
@Override
@@ -224,9 +228,6 @@ public class MovieActivity extends Activity {
}
}
- mPrefs = getSharedPreferences(getApplicationContext().getPackageName(),
- Context.MODE_PRIVATE);
-
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
@@ -319,7 +320,7 @@ public class MovieActivity extends Activity {
}
private void onAudioEffectsMenuItemClick() {
- if (!mIsHeadsetOn) {
+ if (!mIsHeadsetOn && !isBtHeadsetConnected()) {
showHeadsetPlugToast();
} else {
LayoutInflater factory = LayoutInflater.from(this);
@@ -332,12 +333,12 @@ public class MovieActivity extends Activity {
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- mBassBoostEffect.setEnabled(isChecked);
- mBassBoostEffect.setStrength((short)
- mPrefs.getInt(Key.bb_strength.toString(), 0));
- mVirtualizerEffect.setEnabled(isChecked);
- mVirtualizerEffect.setStrength((short)
- mPrefs.getInt(Key.virt_strength.toString(), 0));
+ if(mBassBoostEffect != null) {
+ mBassBoostEffect.setEnabled(isChecked);
+ }
+ if(mVirtualizerEffect != null) {
+ mVirtualizerEffect.setEnabled(isChecked);
+ }
mBassBoostKnob.setEnabled(isChecked);
mVirtualizerKnob.setEnabled(isChecked);
}
@@ -350,7 +351,9 @@ public class MovieActivity extends Activity {
mBassBoostKnob.setOnKnobChangeListener(new Knob.OnKnobChangeListener() {
@Override
public void onValueChanged(Knob knob, int value, boolean fromUser) {
- mBassBoostEffect.setStrength((short) value);
+ if(mBassBoostEffect != null) {
+ mBassBoostEffect.setStrength((short) value);
+ }
}
@Override
@@ -374,7 +377,9 @@ public class MovieActivity extends Activity {
mVirtualizerKnob.setOnKnobChangeListener(new Knob.OnKnobChangeListener() {
@Override
public void onValueChanged(Knob knob, int value, boolean fromUser) {
- mVirtualizerEffect.setStrength((short) value);
+ if(mVirtualizerEffect != null) {
+ mVirtualizerEffect.setStrength((short) value);
+ }
}
@Override
@@ -410,14 +415,19 @@ public class MovieActivity extends Activity {
@Override
public void onClick(DialogInterface dialog, int which) {
boolean enabled = mPrefs.getBoolean(Key.global_enabled.toString(), false);
- mBassBoostEffect.setStrength((short)
- mPrefs.getInt(Key.bb_strength.toString(), 0));
- mBassBoostEffect.setEnabled(enabled);
- mVirtualizerEffect.setStrength((short)
- mPrefs.getInt(Key.virt_strength.toString(), 0));
- mVirtualizerEffect.setEnabled(enabled);
+ if(mBassBoostEffect != null) {
+ mBassBoostEffect.setStrength((short)
+ mPrefs.getInt(Key.bb_strength.toString(), 0));
+ mBassBoostEffect.setEnabled(enabled);
+ }
+ if(mVirtualizerEffect != null) {
+ mVirtualizerEffect.setStrength((short)
+ mPrefs.getInt(Key.virt_strength.toString(), 0));
+ mVirtualizerEffect.setEnabled(enabled);
+ }
}
})
+ .setCancelable(false)
.create();
mEffectDialog.show();
}
@@ -433,7 +443,7 @@ public class MovieActivity extends Activity {
mVirtualizerEffect = new Virtualizer(0, sessionId);
}
- if (mIsHeadsetOn) {
+ if (mIsHeadsetOn || isBtHeadsetConnected()) {
if (mPrefs.getBoolean(Key.global_enabled.toString(), false)) {
if (mBassBoostSupported) {
mBassBoostEffect.setStrength((short)
@@ -555,11 +565,11 @@ public class MovieActivity extends Activity {
registerReceiver(mReceiver, intentFilter);
}
- initEffects(mPlayer.getAudioSessionId());
mResumed = true;
if (!isKeyguardLocked() && !mControlResumed && mPlayer != null) {
mPlayer.onResume();
mControlResumed = true;
+ //initEffects(mPlayer.getAudioSessionId());
}
enhanceActionBar();
super.onResume();
@@ -575,6 +585,15 @@ public class MovieActivity extends Activity {
}
}
+ private boolean isBtHeadsetConnected() {
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ if ((BluetoothProfile.STATE_CONNECTED == adapter.getProfileConnectionState(BluetoothProfile.HEADSET))
+ || (BluetoothProfile.STATE_CONNECTED == adapter.getProfileConnectionState(BluetoothProfile.A2DP))) {
+ return true;
+ }
+ return false;
+ }
+
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@@ -583,15 +602,8 @@ public class MovieActivity extends Activity {
@Override
public void onDestroy() {
+ releaseEffects();
mPlayer.onDestroy();
- if (mBassBoostEffect != null) {
- mBassBoostEffect.setEnabled(false);
- mBassBoostEffect.release();
- }
- if (mVirtualizerEffect != null) {
- mVirtualizerEffect.setEnabled(false);
- mVirtualizerEffect.release();
- }
super.onDestroy();
mMovieHooker.onDestroy();
}
diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java
index 1360bb3e8..66005f6a7 100644
--- a/src/com/android/gallery3d/app/MoviePlayer.java
+++ b/src/com/android/gallery3d/app/MoviePlayer.java
@@ -1109,6 +1109,7 @@ public class MoviePlayer implements
mVideoView.stopPlayback();
mVideoView.setVisibility(View.INVISIBLE);
clearVideoInfo();
+ mActivityContext.releaseEffects();
mMovieItem = next;
mActivityContext.refreshMovieInfo(mMovieItem);
doStartVideo(false, 0, 0);
@@ -1145,6 +1146,7 @@ public class MoviePlayer implements
mVideoView.setVisibility(View.INVISIBLE);
mVideoView.setVisibility(View.VISIBLE);
clearVideoInfo();
+ mActivityContext.releaseEffects();
mFirstBePlayed = false;
mController.setCanReplay(true);
mController.showEnded();
diff --git a/src/com/android/gallery3d/ui/Knob.java b/src/com/android/gallery3d/ui/Knob.java
index f246ce59b..d16bf6110 100755
--- a/src/com/android/gallery3d/ui/Knob.java
+++ b/src/com/android/gallery3d/ui/Knob.java
@@ -90,10 +90,9 @@ public class Knob extends FrameLayout {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Knob, 0, 0);
String label;
- int background, foreground;
+ int foreground;
try {
label = a.getString(R.styleable.Knob_label);
- background = a.getResourceId(R.styleable.Knob_background, R.drawable.knob_bg);
foreground = a.getResourceId(R.styleable.Knob_foreground, R.drawable.knob);
} finally {
a.recycle();
@@ -108,7 +107,6 @@ public class Knob extends FrameLayout {
mLowlightColor = res.getColor(R.color.lowlight);
mDisabledColor = res.getColor(R.color.disabled);
- setBackgroundResource(background);
((ImageView) findViewById(R.id.knob_foreground)).setImageResource(foreground);
mLabelTV = (TextView) findViewById(R.id.knob_label);
@@ -213,16 +211,25 @@ public class Knob extends FrameLayout {
@Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
- mWidth = w;
+ int size = w > h ? h : w;
+ mWidth = size;
mIndicatorWidth = mKnobOn.getWidth();
- mRectF = new RectF(STROKE_WIDTH, STROKE_WIDTH,
- mWidth - STROKE_WIDTH, mWidth - STROKE_WIDTH);
+ int diff;
+ if (w > h) {
+ diff = (w - h) / 2;
+ mRectF = new RectF(STROKE_WIDTH + diff, STROKE_WIDTH,
+ w - STROKE_WIDTH - diff, h - STROKE_WIDTH);
+ } else {
+ diff = (h - w) / 2;
+ mRectF = new RectF(STROKE_WIDTH, STROKE_WIDTH + diff,
+ w - STROKE_WIDTH, h - STROKE_WIDTH - diff);
+ }
- mProgressTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, w * 0.16f);
- mProgressTV.setPadding(0, (int) (w * 0.33), 0, 0);
+ mProgressTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, size * 0.16f);
+ mProgressTV.setPadding(0, (int) (size * 0.33), 0, 0);
mProgressTV.setVisibility(View.VISIBLE);
- mLabelTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, w * 0.12f);
+ mLabelTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, size * 0.12f);
mLabelTV.setVisibility(View.VISIBLE);
}