Support virtualizers without strength parameter
b/7277614
Change-Id: Iaa4d9896c99f27d2980eb327c333c0d60d616d7d
diff --git a/res/layout-land/music_main.xml b/res/layout-land/music_main.xml
index 11fcf5e..905a602 100644
--- a/res/layout-land/music_main.xml
+++ b/res/layout-land/music_main.xml
@@ -124,6 +124,13 @@
android:paddingTop="2dip"
android:paddingLeft="20dip"
android:paddingRight="20dip" />
+ <Switch
+ android:id="@+id/vIStrengthToggle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="2dip"
+ android:paddingLeft="20dip"
+ android:paddingRight="20dip" />
</LinearLayout>
<Spinner android:id="@+id/prSpinner"
diff --git a/res/layout/music_main.xml b/res/layout/music_main.xml
index 367d5a2..be32c96 100644
--- a/res/layout/music_main.xml
+++ b/res/layout/music_main.xml
@@ -114,6 +114,13 @@
android:paddingTop="2dip"
android:paddingLeft="20dip"
android:paddingRight="20dip" />
+ <Switch
+ android:id="@+id/vIStrengthToggle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="2dip"
+ android:paddingLeft="20dip"
+ android:paddingRight="20dip" />
</LinearLayout>
<Spinner android:id="@+id/prSpinner"
diff --git a/src/com/android/musicfx/ActivityMusic.java b/src/com/android/musicfx/ActivityMusic.java
index 0d14729..6f9718a 100644
--- a/src/com/android/musicfx/ActivityMusic.java
+++ b/src/com/android/musicfx/ActivityMusic.java
@@ -351,6 +351,16 @@
}
}
});
+
+ final Switch sw = (Switch) findViewById(R.id.vIStrengthToggle);
+ sw.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(final CompoundButton buttonView,
+ final boolean isChecked) {
+ ControlPanelEffect.setParameterBoolean(mContext, mCallingPackageName,
+ mAudioSession, ControlPanelEffect.Key.virt_enabled, isChecked);
+ }
+ });
}
// Initialize the Bass Boost elements.
@@ -559,9 +569,21 @@
updateUIHeadset();
if (mVirtualizerSupported) {
- ((SeekBar) findViewById(R.id.vIStrengthSeekBar)).setProgress(ControlPanelEffect
+ SeekBar bar = (SeekBar) findViewById(R.id.vIStrengthSeekBar);
+ Switch sw = (Switch) findViewById(R.id.vIStrengthToggle);
+ int strength = ControlPanelEffect
.getParameterInt(mContext, mCallingPackageName, mAudioSession,
- ControlPanelEffect.Key.virt_strength));
+ ControlPanelEffect.Key.virt_strength);
+ bar.setProgress(strength);
+ boolean hasStrength = ControlPanelEffect.getParameterBoolean(mContext,
+ mCallingPackageName, mAudioSession,
+ ControlPanelEffect.Key.virt_strength_supported);
+ if (hasStrength) {
+ sw.setVisibility(View.GONE);
+ } else {
+ bar.setVisibility(View.GONE);
+ sw.setChecked(sw.isEnabled() && strength != 0);
+ }
}
if (mBassBoostSupported) {
((SeekBar) findViewById(R.id.bBStrengthSeekBar)).setProgress(ControlPanelEffect
diff --git a/src/com/android/musicfx/ControlPanelEffect.java b/src/com/android/musicfx/ControlPanelEffect.java
index db46c3e..810ab01 100644
--- a/src/com/android/musicfx/ControlPanelEffect.java
+++ b/src/com/android/musicfx/ControlPanelEffect.java
@@ -59,7 +59,12 @@
}
static enum Key {
- global_enabled, virt_enabled, virt_strength, virt_type, bb_enabled, bb_strength, te_enabled, te_strength, avl_enabled, lm_enabled, lm_strength, eq_enabled, eq_num_bands, eq_level_range, eq_center_freq, eq_band_level, eq_num_presets, eq_preset_name, eq_preset_user_band_level, eq_preset_user_band_level_default, eq_preset_opensl_es_band_level, eq_preset_ci_extreme_band_level, eq_current_preset, pr_enabled, pr_current_preset
+ global_enabled, virt_enabled, virt_strength_supported, virt_strength, virt_type, bb_enabled,
+ bb_strength, te_enabled, te_strength, avl_enabled, lm_enabled, lm_strength, eq_enabled,
+ eq_num_bands, eq_level_range, eq_center_freq, eq_band_level, eq_num_presets, eq_preset_name,
+ eq_preset_user_band_level, eq_preset_user_band_level_default,
+ eq_preset_opensl_es_band_level, eq_preset_ci_extreme_band_level, eq_current_preset,
+ pr_enabled, pr_current_preset
}
// Effect/audio session Mappings
@@ -171,6 +176,22 @@
VIRTUALIZER_STRENGTH_DEFAULT);
editor.putBoolean(Key.virt_enabled.toString(), isVIEnabled);
editor.putInt(Key.virt_strength.toString(), vIStrength);
+ {
+ final MediaPlayer mediaPlayer = new MediaPlayer();
+ final int session = mediaPlayer.getAudioSessionId();
+ Virtualizer virtualizerEffect = null;
+ try {
+ virtualizerEffect = new Virtualizer(PRIORITY, session);
+ editor.putBoolean(Key.virt_strength_supported.toString(),
+ virtualizerEffect.getStrengthSupported());
+ } finally {
+ if (virtualizerEffect != null) {
+ Log.d(TAG, "Releasing dummy Virtualizer effect");
+ virtualizerEffect.release();
+ }
+ mediaPlayer.release();
+ }
+ }
// BassBoost
final boolean isBBEnabled = prefs.getBoolean(Key.bb_enabled.toString(),