diff options
author | jt1134 <jt1134@gmail.com> | 2012-10-04 19:47:05 -0500 |
---|---|---|
committer | jt1134 <jt1134@gmail.com> | 2012-10-04 19:52:22 -0500 |
commit | 5fc6c41e5893c9ba25ca5a1d711dc4a416d64e8e (patch) | |
tree | 325ec5250444a0ca994287e75ac3c46085d45251 | |
parent | cf58673f75e301ed59bafcebf2e1607fc83b7f80 (diff) | |
download | device_samsung_aries-common-5fc6c41e5893c9ba25ca5a1d711dc4a416d64e8e.zip device_samsung_aries-common-5fc6c41e5893c9ba25ca5a1d711dc4a416d64e8e.tar.gz device_samsung_aries-common-5fc6c41e5893c9ba25ca5a1d711dc4a416d64e8e.tar.bz2 |
AriesParts: add vibration intensity settings
Change-Id: Iff35d34073b4b9c0f6989ff298c91cbf3cf7711e
6 files changed, 193 insertions, 0 deletions
diff --git a/AriesParts/res/layout/preference_dialog_vibration.xml b/AriesParts/res/layout/preference_dialog_vibration.xml new file mode 100644 index 0000000..9e11233 --- /dev/null +++ b/AriesParts/res/layout/preference_dialog_vibration.xml @@ -0,0 +1,36 @@ +<?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"> + + <TextView android:id="@+id/vibration_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/vibration_title" + android:paddingTop="10dip" + android:paddingLeft="20dip" + android:paddingRight="20dip" /> + <TextView android:id="@+id/vibration_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/vibration_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/vibration_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 ef450f3..20be50d 100644 --- a/AriesParts/res/values/strings.xml +++ b/AriesParts/res/values/strings.xml @@ -50,6 +50,11 @@ <string name="deskdock_audio_summary_on">Desk dock audio enabled</string> <string name="deskdock_audio_summary_off">Desk dock audio disabled</string> + <string name="category_vibration_title">Vibration</string> + <string name="vibration_title_head">Vibration</string> + <string name="vibration_summary_head">Control vibration intensity</string> + <string name="vibration_title">Vibration intesity</string> + <!-- Used for activity title. Usually not visible, except on the multi-task screen --> <string name="generic_warning_title">Warning</string> diff --git a/AriesParts/res/xml/main.xml b/AriesParts/res/xml/main.xml index d50ed50..9062424 100644 --- a/AriesParts/res/xml/main.xml +++ b/AriesParts/res/xml/main.xml @@ -90,4 +90,13 @@ android:persistent="true" /> </PreferenceCategory> + <PreferenceCategory + android:title="@string/category_vibration_title"> + <!-- Vibration --> + <com.cyanogenmod.settings.device.VibrationPreference + android:key="vibration" + android:title="@string/vibration_title_head" + android:summary="@string/vibration_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 fff147a..ab87d54 100644 --- a/AriesParts/src/com/cyanogenmod/settings/device/DeviceSettings.java +++ b/AriesParts/src/com/cyanogenmod/settings/device/DeviceSettings.java @@ -27,6 +27,7 @@ public class DeviceSettings extends PreferenceActivity { public static final String KEY_CARDOCK_AUDIO = "cardock_audio"; public static final String KEY_DESKDOCK_AUDIO = "deskdock_audio"; public static final String KEY_DOCK_AUDIO_CATEGORY = "category_dock_audio"; + public static final String KEY_VIBRATION = "vibration"; private ColorTuningPreference mColorTuning; private ListPreference mMdnie; @@ -38,6 +39,7 @@ public class DeviceSettings extends PreferenceActivity { private VolumeBoostPreference mVolumeBoost; private CheckBoxPreference mCarDockAudio; private CheckBoxPreference mDeskDockAudio; + private VibrationPreference mVibration; private BroadcastReceiver mHeadsetReceiver = new BroadcastReceiver() { @@ -93,6 +95,9 @@ public class DeviceSettings extends PreferenceActivity { getPreferenceScreen().removePreference(category); } + mVibration = (VibrationPreference) findPreference(KEY_VIBRATION); + mVibration.setEnabled(VibrationPreference.isSupported()); + mTvOut = new TvOut(); mTvOutEnable = (CheckBoxPreference) findPreference(KEY_TVOUT_ENABLE); mTvOutSystem = (ListPreference) findPreference(KEY_TVOUT_SYSTEM); diff --git a/AriesParts/src/com/cyanogenmod/settings/device/Startup.java b/AriesParts/src/com/cyanogenmod/settings/device/Startup.java index 924a95d..d7c843c 100644 --- a/AriesParts/src/com/cyanogenmod/settings/device/Startup.java +++ b/AriesParts/src/com/cyanogenmod/settings/device/Startup.java @@ -15,6 +15,7 @@ public class Startup extends BroadcastReceiver { VolumeBoostPreference.restore(context); DockAudio.restore(context); Sanity.check(context); + VibrationPreference.restore(context); } } diff --git a/AriesParts/src/com/cyanogenmod/settings/device/VibrationPreference.java b/AriesParts/src/com/cyanogenmod/settings/device/VibrationPreference.java new file mode 100644 index 0000000..9bf6726 --- /dev/null +++ b/AriesParts/src/com/cyanogenmod/settings/device/VibrationPreference.java @@ -0,0 +1,137 @@ +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; + +public class VibrationPreference extends DialogPreference { + + private static final int SEEKBAR_ID = R.id.vibration_seekbar; + + private static final int VALUE_DISPLAY_ID = R.id.vibration_value; + + private static final String FILE_PATH = "/sys/class/misc/pwm_duty/pwm_duty"; + + private VibrationSeekBar mSeekBar = new VibrationSeekBar(); + + private static final int MAX_VALUE = 100; + + // 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 VibrationPreference(Context context, AttributeSet attrs) { + super(context, attrs); + + setDialogLayoutResource(R.layout.preference_dialog_vibration); + } + + @Override + protected void onBindDialogView(View view) { + super.onBindDialogView(view); + + sInstances++; + + SeekBar seekBar = (SeekBar) view.findViewById(SEEKBAR_ID); + TextView valueDisplay = (TextView) view.findViewById(VALUE_DISPLAY_ID); + mSeekBar = new VibrationSeekBar(seekBar, valueDisplay, FILE_PATH); + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + sInstances--; + + if (positiveResult) { + mSeekBar.save(); + } else if (sInstances == 0) { + mSeekBar.reset(); + } + } + + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + int value = sharedPrefs.getInt(FILE_PATH, MAX_VALUE); + Utils.writeValue(FILE_PATH, String.valueOf(value)); + } + + public static boolean isSupported() { + boolean supported = true; + if (!Utils.fileExists(FILE_PATH)) { + supported = false; + } + + return supported; + } + + class VibrationSeekBar implements SeekBar.OnSeekBarChangeListener { + + protected String mFilePath; + protected int mOriginal; + protected SeekBar mSeekBar; + protected TextView mValueDisplay; + + public VibrationSeekBar(SeekBar seekBar, TextView valueDisplay, String filePath) { + mSeekBar = seekBar; + mValueDisplay = valueDisplay; + mFilePath = filePath; + + // Read original value + SharedPreferences sharedPreferences = getSharedPreferences(); + mOriginal = sharedPreferences.getInt(mFilePath, MAX_VALUE); + + seekBar.setMax(MAX_VALUE); + reset(); + seekBar.setOnSeekBarChangeListener(this); + } + + // For inheriting class + protected VibrationSeekBar() { + } + + 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) + "%"); + } + + } + +} |