From cd22b8edae1eda959013e73ffa7eec1ecd947cdf Mon Sep 17 00:00:00 2001 From: jt1134 Date: Sun, 3 Jun 2012 03:30:47 -0500 Subject: AriesParts: add controls for CDMA in-call volume settings requires kernel patch: http://review.cyanogenmod.com/#/c/17019/ Patch-set 2: * completely disable volume boost category on unsupported device * fix whitespace Patch-set 3: * remove extraneous setEnabled() call * add KEY constant for volume boost category Change-Id: Ic34f873e9b95b724cb2b94deec393ac92c11e3be --- .../res/layout/preference_dialog_volume_boost.xml | 212 ++++++++++++++++++ AriesParts/res/values/strings.xml | 12 + AriesParts/res/xml/main.xml | 11 + .../settings/device/DeviceSettings.java | 11 + .../com/cyanogenmod/settings/device/Startup.java | 1 + .../settings/device/VolumeBoostPreference.java | 245 +++++++++++++++++++++ 6 files changed, 492 insertions(+) create mode 100644 AriesParts/res/layout/preference_dialog_volume_boost.xml create mode 100644 AriesParts/src/com/cyanogenmod/settings/device/VolumeBoostPreference.java (limited to 'AriesParts') diff --git a/AriesParts/res/layout/preference_dialog_volume_boost.xml b/AriesParts/res/layout/preference_dialog_volume_boost.xml new file mode 100644 index 0000000..8134a55 --- /dev/null +++ b/AriesParts/res/layout/preference_dialog_volume_boost.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AriesParts/res/values/strings.xml b/AriesParts/res/values/strings.xml index 45ee818..f4a8d23 100644 --- a/AriesParts/res/values/strings.xml +++ b/AriesParts/res/values/strings.xml @@ -29,4 +29,16 @@ TV Out enabled TV System Set your TV system for TV Out + + Volume Controls + In-Call Volume Controls + Boost in-call volume settings + Earpiece Volume + Bluetooth Volume + Speakerphone Volume + Headphone Volume + Earpiece Mic + Speakerphone Mic + Headphone Mic + Headphone (with no mic) Mic diff --git a/AriesParts/res/xml/main.xml b/AriesParts/res/xml/main.xml index 66876f2..c371a4f 100644 --- a/AriesParts/res/xml/main.xml +++ b/AriesParts/res/xml/main.xml @@ -59,4 +59,15 @@ android:entryValues="@array/tvout_system_entries_values" android:defaultValue="2" /> + + + + + + diff --git a/AriesParts/src/com/cyanogenmod/settings/device/DeviceSettings.java b/AriesParts/src/com/cyanogenmod/settings/device/DeviceSettings.java index 42710da..466feeb 100644 --- a/AriesParts/src/com/cyanogenmod/settings/device/DeviceSettings.java +++ b/AriesParts/src/com/cyanogenmod/settings/device/DeviceSettings.java @@ -10,6 +10,7 @@ import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; +import android.preference.PreferenceCategory; public class DeviceSettings extends PreferenceActivity { @@ -19,6 +20,8 @@ public class DeviceSettings extends PreferenceActivity { public static final String KEY_HSPA = "hspa"; public static final String KEY_TVOUT_ENABLE = "tvout_enable"; public static final String KEY_TVOUT_SYSTEM = "tvout_system"; + public static final String KEY_VOLUME_BOOST = "volume_boost"; + public static final String KEY_VOLUME_CATEGORY = "category_volume_boost"; private ColorTuningPreference mColorTuning; private ListPreference mMdnie; @@ -27,6 +30,7 @@ public class DeviceSettings extends PreferenceActivity { private CheckBoxPreference mTvOutEnable; private ListPreference mTvOutSystem; private TvOut mTvOut; + private VolumeBoostPreference mVolumeBoost; private BroadcastReceiver mHeadsetReceiver = new BroadcastReceiver() { @@ -58,6 +62,13 @@ public class DeviceSettings extends PreferenceActivity { mHspa.setEnabled(Hspa.isSupported()); mHspa.setOnPreferenceChangeListener(new Hspa(this)); + mVolumeBoost = (VolumeBoostPreference) findPreference(KEY_VOLUME_BOOST); + if (!VolumeBoostPreference.isSupported()) { + PreferenceCategory category = (PreferenceCategory) getPreferenceScreen().findPreference(KEY_VOLUME_CATEGORY); + category.removePreference(mVolumeBoost); + getPreferenceScreen().removePreference(category); + } + mTvOut = new TvOut(); mTvOutEnable = (CheckBoxPreference) findPreference(KEY_TVOUT_ENABLE); mTvOutEnable.setChecked(mTvOut._isEnabled()); diff --git a/AriesParts/src/com/cyanogenmod/settings/device/Startup.java b/AriesParts/src/com/cyanogenmod/settings/device/Startup.java index c2affb4..7437c64 100644 --- a/AriesParts/src/com/cyanogenmod/settings/device/Startup.java +++ b/AriesParts/src/com/cyanogenmod/settings/device/Startup.java @@ -12,6 +12,7 @@ public class Startup extends BroadcastReceiver { Mdnie.restore(context); TouchKeyBacklightTimeout.restore(context); Hspa.restore(context); + VolumeBoostPreference.restore(context); } } diff --git a/AriesParts/src/com/cyanogenmod/settings/device/VolumeBoostPreference.java b/AriesParts/src/com/cyanogenmod/settings/device/VolumeBoostPreference.java new file mode 100644 index 0000000..efbf293 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/VolumeBoostPreference.java @@ -0,0 +1,245 @@ +package com.cyanogenmod.settings.device; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.preference.DialogPreference; +import android.preference.PreferenceManager; +import android.util.AttributeSet; +import android.view.View; +import android.widget.SeekBar; +import android.widget.TextView; + +/** + * Special preference type that allows configuration of both the in call volume and + * in call mic gain. + */ +public class VolumeBoostPreference extends DialogPreference { + + private static final int[] SEEKBAR_ID = new int[] { + R.id.boost_rcv_seekbar, + R.id.boost_bt_seekbar, + R.id.boost_spk_seekbar, + R.id.boost_hp_seekbar + }; + + private static final int[] VALUE_DISPLAY_ID = new int[] { + R.id.boost_rcv_value, + R.id.boost_bt_value, + R.id.boost_spk_value, + R.id.boost_hp_value + }; + + private static final int[] MIC_SEEKBAR_ID = new int[] { + R.id.mic_rcv_seekbar, + R.id.mic_spk_seekbar, + R.id.mic_hp_seekbar, + R.id.mic_hp_no_mic_seekbar + }; + + private static final int[] MIC_VALUE_DISPLAY_ID = new int[] { + R.id.mic_rcv_value, + R.id.mic_spk_value, + R.id.mic_hp_value, + R.id.mic_hp_no_mic_value + }; + + private static final String[] BOOST_FILE_PATH = new String[] { + "/sys/devices/virtual/misc/voodoo_sound/incall_boost_rcv", + "/sys/devices/virtual/misc/voodoo_sound/incall_boost_bt", + "/sys/devices/virtual/misc/voodoo_sound/incall_boost_spk", + "/sys/devices/virtual/misc/voodoo_sound/incall_boost_hp" + }; + + private static final String[] MIC_FILE_PATH = new String[] { + "/sys/devices/virtual/misc/voodoo_sound/incall_mic_gain_rcv", + "/sys/devices/virtual/misc/voodoo_sound/incall_mic_gain_spk", + "/sys/devices/virtual/misc/voodoo_sound/incall_mic_gain_hp", + "/sys/devices/virtual/misc/voodoo_sound/incall_mic_gain_hp_no_mic" + }; + + private VolumeSeekBar mSeekBars[] = new VolumeSeekBar[8]; + + private static final int BOOST_DEFAULT_VALUE = 2; + private static final int BOOST_MAX_VALUE = 3; + + private static final int[] MIC_DEFAULT_VALUE = new int[] { 19, 31, 29, 18 }; + private static final int MIC_MAX_VALUE = 31; + + // Track instances to know when to restore original value + // (when the orientation changes, a new dialog is created before the old one is destroyed) + private static int sInstances = 0; + + public VolumeBoostPreference(Context context, AttributeSet attrs) { + super(context, attrs); + + setDialogLayoutResource(R.layout.preference_dialog_volume_boost); + } + + @Override + protected void onBindDialogView(View view) { + super.onBindDialogView(view); + + sInstances++; + + for (int i = 0; i < SEEKBAR_ID.length; i++) { + SeekBar seekBar = (SeekBar) view.findViewById(SEEKBAR_ID[i]); + TextView valueDisplay = (TextView) view.findViewById(VALUE_DISPLAY_ID[i]); + mSeekBars[i] = new VolumeSeekBar(seekBar, valueDisplay, BOOST_FILE_PATH[i]); + } + + for (int i = 0; i < MIC_SEEKBAR_ID.length; i++) { + SeekBar seekBar = (SeekBar) view.findViewById(MIC_SEEKBAR_ID[i]); + TextView valueDisplay = (TextView) view.findViewById(MIC_VALUE_DISPLAY_ID[i]); + mSeekBars[SEEKBAR_ID.length + i] = new MicSeekBar(seekBar, valueDisplay, MIC_FILE_PATH[i], i); + } + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + sInstances--; + + if (positiveResult) { + for (VolumeSeekBar vsb : mSeekBars) { + vsb.save(); + } + } else if (sInstances == 0) { + for (VolumeSeekBar vsb : mSeekBars) { + vsb.reset(); + } + } + } + + /** + * Restore volume preference from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + for (int i = 0; i < BOOST_FILE_PATH.length; i++) { + int value = sharedPrefs.getInt(BOOST_FILE_PATH[i], BOOST_DEFAULT_VALUE); + Utils.writeValue(BOOST_FILE_PATH[i], String.valueOf(value)); + } + + for (int i = 0; i < MIC_FILE_PATH.length; i++) { + int value = sharedPrefs.getInt(MIC_FILE_PATH[i], MIC_DEFAULT_VALUE[i]); + Utils.writeValue(MIC_FILE_PATH[i], String.valueOf(value)); + } + } + + /** + * Check whether the running kernel supports volume boost or not. + * @return Whether volume boost is supported or not + */ + public static boolean isSupported() { + boolean supported = true; + + for (int i = 0; i < BOOST_FILE_PATH.length; i++) { + if (!Utils.fileExists(BOOST_FILE_PATH[i])) { + supported = false; + } + } + for (int i = 0; i < MIC_FILE_PATH.length; i++) { + if (!Utils.fileExists(MIC_FILE_PATH[i])) { + supported = false; + } + } + + return supported; + } + + class VolumeSeekBar implements SeekBar.OnSeekBarChangeListener { + + protected String mFilePath; + protected int mOriginal; + protected SeekBar mSeekBar; + protected TextView mValueDisplay; + + public VolumeSeekBar(SeekBar seekBar, TextView valueDisplay, String filePath) { + mSeekBar = seekBar; + mValueDisplay = valueDisplay; + mFilePath = filePath; + + // Read original value + SharedPreferences sharedPreferences = getSharedPreferences(); + mOriginal = sharedPreferences.getInt(mFilePath, BOOST_DEFAULT_VALUE); + + seekBar.setMax(BOOST_MAX_VALUE); + reset(); + seekBar.setOnSeekBarChangeListener(this); + } + + // For inheriting class + protected VolumeSeekBar() { + } + + public void reset() { + mSeekBar.setProgress(mOriginal); + updateValue(mOriginal); + } + + public void save() { + Editor editor = getEditor(); + editor.putInt(mFilePath, mSeekBar.getProgress()); + editor.commit(); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, + boolean fromUser) { + Utils.writeValue(mFilePath, String.valueOf(progress)); + updateValue(progress); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Do nothing + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Do nothing + } + + protected void updateValue(int progress) { + mValueDisplay.setText(String.valueOf(progress)); + } + + } + + class MicSeekBar extends VolumeSeekBar { + + public MicSeekBar(SeekBar seekBar, TextView valueDisplay, String filePath, int defaultValue) { + mSeekBar = seekBar; + mValueDisplay = valueDisplay; + mFilePath = filePath; + + // Read original value + SharedPreferences sharedPreferences = getSharedPreferences(); + mOriginal = sharedPreferences.getInt(mFilePath, MIC_DEFAULT_VALUE[defaultValue]); + + seekBar.setMax(MIC_MAX_VALUE); + reset(); + seekBar.setOnSeekBarChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, + boolean fromUser) { + Utils.writeValue(mFilePath, String.valueOf(progress)); + updateValue(progress); + } + + @Override + protected void updateValue(int progress) { + mValueDisplay.setText(String.valueOf(progress)); + } + + } +} -- cgit v1.1