summaryrefslogtreecommitdiffstats
path: root/AriesParts/src
diff options
context:
space:
mode:
authorjt1134 <jt1134@gmail.com>2012-10-04 19:47:05 -0500
committerjt1134 <jt1134@gmail.com>2012-10-04 19:52:22 -0500
commit5fc6c41e5893c9ba25ca5a1d711dc4a416d64e8e (patch)
tree325ec5250444a0ca994287e75ac3c46085d45251 /AriesParts/src
parentcf58673f75e301ed59bafcebf2e1607fc83b7f80 (diff)
downloaddevice_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
Diffstat (limited to 'AriesParts/src')
-rw-r--r--AriesParts/src/com/cyanogenmod/settings/device/DeviceSettings.java5
-rw-r--r--AriesParts/src/com/cyanogenmod/settings/device/Startup.java1
-rw-r--r--AriesParts/src/com/cyanogenmod/settings/device/VibrationPreference.java137
3 files changed, 143 insertions, 0 deletions
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) + "%");
+ }
+
+ }
+
+}