diff options
author | wjiang <wjiang@codeaurora.org> | 2014-02-14 17:45:53 +0800 |
---|---|---|
committer | Xiaojing Zhang <zhangx@codeaurora.org> | 2014-11-04 20:38:14 -0800 |
commit | 47184c7b2bfb477a1ff800ac8a463478e4674dd9 (patch) | |
tree | c7646ed7247010ca7d483d93e37d2b99c90c20b9 | |
parent | 99cfa4d1f436735ec403b1e1dbb4167b26d43cd9 (diff) | |
download | android_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
-rw-r--r-- | AndroidManifest.xml | 1 | ||||
-rw-r--r-- | res/drawable-hdpi/knob.png | bin | 34246 -> 51511 bytes | |||
-rw-r--r-- | res/drawable-hdpi/knob_bg.png | bin | 14924 -> 0 bytes | |||
-rw-r--r-- | res/drawable-hdpi/switch_thumb_activated.9.png | bin | 0 -> 5117 bytes | |||
-rw-r--r-- | res/drawable-hdpi/switch_thumb_off.9.png | bin | 0 -> 5098 bytes | |||
-rw-r--r-- | res/layout/audio_effects_dialog.xml | 16 | ||||
-rw-r--r-- | res/layout/audio_effects_title.xml | 60 | ||||
-rw-r--r-- | res/layout/knob.xml | 1 | ||||
-rw-r--r-- | res/values/colors.xml | 8 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/MovieActivity.java | 90 | ||||
-rwxr-xr-x | src/com/android/gallery3d/app/MoviePlayer.java | 2 |
11 files changed, 126 insertions, 52 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 780ee8bc6..679ca0408 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -32,6 +32,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 Binary files differindex a6871ad5a..1eba937fe 100644 --- a/res/drawable-hdpi/knob.png +++ b/res/drawable-hdpi/knob.png diff --git a/res/drawable-hdpi/knob_bg.png b/res/drawable-hdpi/knob_bg.png Binary files differdeleted file mode 100644 index 342350937..000000000 --- a/res/drawable-hdpi/knob_bg.png +++ /dev/null diff --git a/res/drawable-hdpi/switch_thumb_activated.9.png b/res/drawable-hdpi/switch_thumb_activated.9.png Binary files differnew file mode 100644 index 000000000..072aa649c --- /dev/null +++ b/res/drawable-hdpi/switch_thumb_activated.9.png diff --git a/res/drawable-hdpi/switch_thumb_off.9.png b/res/drawable-hdpi/switch_thumb_off.9.png Binary files differnew file mode 100644 index 000000000..45786a309 --- /dev/null +++ b/res/drawable-hdpi/switch_thumb_off.9.png diff --git a/res/layout/audio_effects_dialog.xml b/res/layout/audio_effects_dialog.xml index 83892c224..49dcafb56 100644 --- a/res/layout/audio_effects_dialog.xml +++ b/res/layout/audio_effects_dialog.xml @@ -42,22 +42,12 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. android:gravity="center_horizontal" android:paddingBottom="10dp"> - <Switch - android:id="@+id/audio_effects_switch" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/audio_effects" - android:textAppearance="?android:attr/textAppearanceSmall" - android:layout_marginTop="10dp" - android:layout_marginLeft="25dp" - android:layout_marginRight="30dp" /> - <LinearLayout android:id="@+id/aEffectsPanel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" - android:layout_marginTop="5dp" + android:layout_marginTop="12dp" android:layout_marginBottom="10dp" android:gravity="center_vertical"> @@ -65,16 +55,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/res/layout/audio_effects_title.xml b/res/layout/audio_effects_title.xml new file mode 100644 index 000000000..fcfb11d1e --- /dev/null +++ b/res/layout/audio_effects_title.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (c) 2014, The Linux Foundation. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:custom="http://schemas.android.com/apk/res/com.android.gallery3d" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:gravity="left|center_vertical"> + + <TextView + android:text="@string/audio_effects_dialog_title" + android:gravity="left|center_vertical" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="10dp" + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp" + android:textSize="20dp" /> + + <View + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" /> + + <ToggleButton + android:id="@+id/audio_effects_switch" + android:textOn="" + android:textOff="" + android:layout_width="72dp" + android:layout_height="34dp" + android:layout_marginEnd="4dp"/> +</LinearLayout> diff --git a/res/layout/knob.xml b/res/layout/knob.xml index 41c982ebc..d504774e7 100644 --- a/res/layout/knob.xml +++ b/res/layout/knob.xml @@ -67,6 +67,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. android:id="@+id/knob_label" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:gravity="center" android:ellipsize="marquee" android:visibility="gone" /> </LinearLayout> diff --git a/res/values/colors.xml b/res/values/colors.xml index 1f1d6ec1e..20b2930d7 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -70,8 +70,8 @@ <color name="face_detect_fail">#80d05060</color> <color name="gray">#FFAAAAAA</color> - <color name="highlight">#00a8ff</color> - <color name="lowlight">#00527c</color> - <color name="grey">#999999</color> - <color name="disabled_knob">#505050</color> + <color name="highlight">#f41e26</color> + <color name="lowlight">#650101</color> + <color name="grey">#e7e7e7</color> + <color name="disabled_knob">#575757</color> </resources> 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(); |