summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorwjiang <wjiang@codeaurora.org>2014-02-14 17:45:53 +0800
committerXiaojing Zhang <zhangx@codeaurora.org>2014-11-04 20:38:14 -0800
commit47184c7b2bfb477a1ff800ac8a463478e4674dd9 (patch)
treec7646ed7247010ca7d483d93e37d2b99c90c20b9 /src/com
parent99cfa4d1f436735ec403b1e1dbb4167b26d43cd9 (diff)
downloadandroid_packages_apps_Gallery2-47184c7b2bfb477a1ff800ac8a463478e4674dd9.tar.gz
android_packages_apps_Gallery2-47184c7b2bfb477a1ff800ac8a463478e4674dd9.tar.bz2
android_packages_apps_Gallery2-47184c7b2bfb477a1ff800ac8a463478e4674dd9.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. - Update visual design. Conflicts: src/com/android/gallery3d/ui/Knob.java Change-Id: I803897508c0c1a6723170b7691e3ece03680e4f1
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/gallery3d/app/MovieActivity.java90
-rwxr-xr-xsrc/com/android/gallery3d/app/MoviePlayer.java2
2 files changed, 57 insertions, 35 deletions
diff --git a/src/com/android/gallery3d/app/MovieActivity.java b/src/com/android/gallery3d/app/MovieActivity.java
index 7fb5954d3..e42314025 100644
--- a/src/com/android/gallery3d/app/MovieActivity.java
+++ b/src/com/android/gallery3d/app/MovieActivity.java
@@ -58,7 +58,7 @@ import android.view.Window;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ShareActionProvider;
-import android.widget.Switch;
+import android.widget.ToggleButton;
import android.widget.Toast;
import com.android.gallery3d.R;
@@ -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
};
@@ -110,10 +111,11 @@ public class MovieActivity extends Activity {
private BassBoost mBassBoostEffect;
private Virtualizer mVirtualizerEffect;
private AlertDialog mEffectDialog;
- private Switch mSwitch;
+ private ToggleButton mSwitch;
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,25 +320,31 @@ public class MovieActivity extends Activity {
}
private void onAudioEffectsMenuItemClick() {
- if (!mIsHeadsetOn) {
+ if (!mIsHeadsetOn && !isBtHeadsetConnected()) {
showHeadsetPlugToast();
} else {
LayoutInflater factory = LayoutInflater.from(this);
final View content = factory.inflate(R.layout.audio_effects_dialog, null);
+ final View title = factory.inflate(R.layout.audio_effects_title, null);
boolean enabled = mPrefs.getBoolean(Key.global_enabled.toString(), false);
- mSwitch = (Switch) content.findViewById(R.id.audio_effects_switch);
+ mSwitch = (ToggleButton) title.findViewById(R.id.audio_effects_switch);
mSwitch.setChecked(enabled);
+ mSwitch.setBackgroundResource(enabled ?
+ R.drawable.switch_thumb_activated : R.drawable.switch_thumb_off);
+
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));
+ mSwitch.setBackgroundResource(isChecked ?
+ R.drawable.switch_thumb_activated : R.drawable.switch_thumb_off);
+ if(mBassBoostEffect != null) {
+ mBassBoostEffect.setEnabled(isChecked);
+ }
+ if(mVirtualizerEffect != null) {
+ mVirtualizerEffect.setEnabled(isChecked);
+ }
mBassBoostKnob.setEnabled(isChecked);
mVirtualizerKnob.setEnabled(isChecked);
}
@@ -350,7 +357,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
@@ -366,7 +375,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
@@ -377,7 +388,7 @@ public class MovieActivity extends Activity {
mEffectDialog = new AlertDialog.Builder(MovieActivity.this,
AlertDialog.THEME_HOLO_DARK)
- .setTitle(R.string.audio_effects_dialog_title)
+ .setCustomTitle(title)
.setView(content)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
@@ -394,16 +405,23 @@ 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();
+ mEffectDialog.findViewById(com.android.internal.R.id.titleDivider)
+ .setBackgroundResource(R.color.highlight);
}
}
@@ -417,7 +435,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)
@@ -539,11 +557,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();
@@ -559,6 +577,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);
@@ -567,15 +594,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 3afd32abf..48818a8bb 100755
--- a/src/com/android/gallery3d/app/MoviePlayer.java
+++ b/src/com/android/gallery3d/app/MoviePlayer.java
@@ -1099,6 +1099,7 @@ public class MoviePlayer implements
mVideoView.stopPlayback();
mVideoView.setVisibility(View.INVISIBLE);
clearVideoInfo();
+ mActivityContext.releaseEffects();
mMovieItem = next;
mActivityContext.refreshMovieInfo(mMovieItem);
doStartVideo(false, 0, 0);
@@ -1135,6 +1136,7 @@ public class MoviePlayer implements
mVideoView.setVisibility(View.INVISIBLE);
mVideoView.setVisibility(View.VISIBLE);
clearVideoInfo();
+ mActivityContext.releaseEffects();
mFirstBePlayed = false;
mController.setCanReplay(true);
mController.showEnded();