diff options
author | jt1134 <jt1134@gmail.com> | 2012-06-03 03:30:47 -0500 |
---|---|---|
committer | jt1134 <jt1134@gmail.com> | 2012-06-04 23:04:14 -0500 |
commit | cd22b8edae1eda959013e73ffa7eec1ecd947cdf (patch) | |
tree | 7e8e1184f704ce538543a31776b0d5dfe46c2b9a | |
parent | bf0b021ce9a5de773b33e42d1ea98fe7908e644d (diff) | |
download | device_samsung_aries-common-cd22b8edae1eda959013e73ffa7eec1ecd947cdf.zip device_samsung_aries-common-cd22b8edae1eda959013e73ffa7eec1ecd947cdf.tar.gz device_samsung_aries-common-cd22b8edae1eda959013e73ffa7eec1ecd947cdf.tar.bz2 |
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
6 files changed, 492 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="utf-8"?> + +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:paddingBottom="20dip"> + + <!-- Volume Boost RCV --> + <TextView android:id="@+id/boost_rcv_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/boost_rcv_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/boost_rcv_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/boost_rcv_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/boost_rcv_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <!-- Volume Boost BT --> + <TextView android:id="@+id/boost_bt_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/boost_rcv_seekbar" + android:text="@string/boost_bt_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/boost_bt_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/boost_rcv_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/boost_bt_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/boost_bt_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <!-- Volume Boost SPK --> + <TextView android:id="@+id/boost_spk_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/boost_bt_seekbar" + android:text="@string/boost_spk_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/boost_spk_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/boost_bt_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/boost_spk_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/boost_spk_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <!-- Volume Boost HP --> + <TextView android:id="@+id/boost_hp_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/boost_spk_seekbar" + android:text="@string/boost_hp_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/boost_hp_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/boost_spk_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/boost_hp_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/boost_hp_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <!-- Mic Gain RCV --> + <TextView android:id="@+id/mic_rcv_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/boost_hp_seekbar" + android:text="@string/mic_rcv_title" + android:paddingTop="30dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/mic_rcv_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/boost_hp_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="30dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/mic_rcv_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/mic_rcv_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <!-- Mic Gain SPK --> + <TextView android:id="@+id/mic_spk_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/mic_rcv_seekbar" + android:text="@string/mic_spk_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/mic_spk_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/mic_rcv_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/mic_spk_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/mic_spk_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <!-- Mic Gain HP --> + <TextView android:id="@+id/mic_hp_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/mic_spk_seekbar" + android:text="@string/mic_hp_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/mic_hp_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/mic_spk_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/mic_hp_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/mic_hp_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + <!-- Mic Gain HP no Mic --> + <TextView android:id="@+id/mic_hp_no_mic_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/mic_hp_seekbar" + android:text="@string/mic_hp_no_mic_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/mic_hp_no_mic_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/mic_hp_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <SeekBar android:id="@+id/mic_hp_no_mic_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/mic_hp_no_mic_text" + android:paddingTop="2dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + + </RelativeLayout> +</ScrollView> 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 @@ <string name="tvout_enable_summary_on">TV Out enabled</string> <string name="tvout_system_head">TV System</string> <string name="tvout_system_summary">Set your TV system for TV Out</string> + + <string name="category_volume_boost_title">Volume Controls</string> + <string name="volume_boost_title_head">In-Call Volume Controls</string> + <string name="volume_boost_summary_head">Boost in-call volume settings</string> + <string name="boost_rcv_title">Earpiece Volume</string> + <string name="boost_bt_title">Bluetooth Volume</string> + <string name="boost_spk_title">Speakerphone Volume</string> + <string name="boost_hp_title">Headphone Volume</string> + <string name="mic_rcv_title">Earpiece Mic</string> + <string name="mic_spk_title">Speakerphone Mic</string> + <string name="mic_hp_title">Headphone Mic</string> + <string name="mic_hp_no_mic_title">Headphone (with no mic) Mic</string> </resources> 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" /> </PreferenceCategory> + + <PreferenceCategory + android:title="@string/category_volume_boost_title" + android:key="category_volume_boost"> + <!-- Volume Boost --> + <com.cyanogenmod.settings.device.VolumeBoostPreference + android:key="volume_boost" + android:title="@string/volume_boost_title_head" + android:summary="@string/volume_boost_summary_head" /> + </PreferenceCategory> + </PreferenceScreen> 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)); + } + + } +} |