From f5a640bbed057a3b4af7f2720a8a99cc4d8f158d Mon Sep 17 00:00:00 2001 From: Andrew Dodd Date: Sun, 17 Jun 2012 12:16:05 -0400 Subject: DeviceSettings: Control vibrator strength Change-Id: I504f483cf8ef30274ceb2742d87be380aadacf6b --- DeviceSettings/res/values-de/arrays.xml | 8 +++ DeviceSettings/res/values-de/strings.xml | 5 ++ DeviceSettings/res/values/arrays.xml | 16 ++++++ DeviceSettings/res/values/strings.xml | 5 ++ DeviceSettings/res/xml/haptic_preferences.xml | 13 +++++ .../settings/device/DeviceSettings.java | 3 + .../settings/device/HapticFragmentActivity.java | 66 ++++++++++++++++++++++ .../com/cyanogenmod/settings/device/Startup.java | 2 + .../settings/device/VibratorIntensity.java | 59 +++++++++++++++++++ init.smdk4210.rc | 2 + 10 files changed, 179 insertions(+) create mode 100644 DeviceSettings/res/xml/haptic_preferences.xml create mode 100644 DeviceSettings/src/com/cyanogenmod/settings/device/HapticFragmentActivity.java create mode 100644 DeviceSettings/src/com/cyanogenmod/settings/device/VibratorIntensity.java diff --git a/DeviceSettings/res/values-de/arrays.xml b/DeviceSettings/res/values-de/arrays.xml index 982125b..6f5dda7 100644 --- a/DeviceSettings/res/values-de/arrays.xml +++ b/DeviceSettings/res/values-de/arrays.xml @@ -42,6 +42,14 @@ 100 + + 0% + 25% + 50% (Standard) + 75% + 100% + + Nur UMTS Nur HSDPA diff --git a/DeviceSettings/res/values-de/strings.xml b/DeviceSettings/res/values-de/strings.xml index cf1e922..4d0589e 100644 --- a/DeviceSettings/res/values-de/strings.xml +++ b/DeviceSettings/res/values-de/strings.xml @@ -29,6 +29,11 @@ Aktiviere Tastenbeleuchtung Tasten leuchten auf während der Birdschirm aktiv ist + Haptik + Vibrator + Vibrator Intensität + Setze Vibrator Intensität + Mobilfunk HSPA Aktiviert HSDPA/HSUPA diff --git a/DeviceSettings/res/values/arrays.xml b/DeviceSettings/res/values/arrays.xml index 894157d..e75ee6e 100644 --- a/DeviceSettings/res/values/arrays.xml +++ b/DeviceSettings/res/values/arrays.xml @@ -84,6 +84,22 @@ 100 + + 0% + 25% + 50% (Default) + 75% + 100% + + + + 0 + 25 + 50 + 75 + 100 + + UMTS Only HSDPA Only diff --git a/DeviceSettings/res/values/strings.xml b/DeviceSettings/res/values/strings.xml index 6259102..5c38440 100644 --- a/DeviceSettings/res/values/strings.xml +++ b/DeviceSettings/res/values/strings.xml @@ -29,6 +29,11 @@ Enable keys backlight Light up touch keys when screen is on + Haptic + Vibrator + Vibrator Intensity + Set vibrator intensity + Radio HSPA Enable HSDPA/HSUPA diff --git a/DeviceSettings/res/xml/haptic_preferences.xml b/DeviceSettings/res/xml/haptic_preferences.xml new file mode 100644 index 0000000..31c0e21 --- /dev/null +++ b/DeviceSettings/res/xml/haptic_preferences.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java b/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java index 4bd1810..58003a2 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java @@ -45,6 +45,7 @@ public class DeviceSettings extends FragmentActivity { public static final String KEY_CALIBRATE_GYRO = "calibrate_gyro"; public static final String KEY_TOUCHSCREEN_SENSITIVITY = "touchscreen_sensitivity"; public static final String KEY_TOUCHKEY_LIGHT = "touchkey_light"; + public static final String KEY_VIBRATOR_INTENSITY = "vibrator_intensity"; ViewPager mViewPager; TabsAdapter mTabsAdapter; @@ -69,6 +70,8 @@ public class DeviceSettings extends FragmentActivity { mDNIeFragmentActivity.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.category_sensors_title), SensorsFragmentActivity.class, null); + mTabsAdapter.addTab(bar.newTab().setText(R.string.category_haptic_title), + HapticFragmentActivity.class, null); if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0)); diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/HapticFragmentActivity.java b/DeviceSettings/src/com/cyanogenmod/settings/device/HapticFragmentActivity.java new file mode 100644 index 0000000..d67c234 --- /dev/null +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/HapticFragmentActivity.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2012 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cyanogenmod.settings.device; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; +import android.util.Log; + +import com.cyanogenmod.settings.device.R; + +public class HapticFragmentActivity extends PreferenceFragment { + + private static final String PREF_ENABLED = "1"; + private static final String TAG = "GalaxyNoteParts_General"; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.haptic_preferences); + + PreferenceScreen prefSet = getPreferenceScreen(); + + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + + String boxValue; + String key = preference.getKey(); + + Log.w(TAG, "key: " + key); + + return true; + } + + public static boolean isSupported(String FILE) { + return Utils.fileExists(FILE); + } + + public static void restore(Context context) { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + } +} diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java b/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java index 6951f26..7566273 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java @@ -29,6 +29,8 @@ public class Startup extends BroadcastReceiver { mDNIeNegative.restore(context); mDNIeOutdoor.restore(context); RadioFragmentActivity.restore(context); + HapticFragmentActivity.restore(context); + VibratorIntensity.restore(context); } } diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/VibratorIntensity.java b/DeviceSettings/src/com/cyanogenmod/settings/device/VibratorIntensity.java new file mode 100644 index 0000000..7a809a5 --- /dev/null +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/VibratorIntensity.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2012 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cyanogenmod.settings.device; + +import java.io.IOException; +import android.content.Context; +import android.util.AttributeSet; +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.ListPreference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class VibratorIntensity extends ListPreference implements OnPreferenceChangeListener { + + public VibratorIntensity(Context context, AttributeSet attrs) { + super(context, attrs); + this.setOnPreferenceChangeListener(this); + } + + private static final String FILE = "/sys/vibrator/pwm_val"; + + public static boolean isSupported() { + return Utils.fileExists(FILE); + } + + /** + * Restore vibrator intensity setting 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); + Utils.writeValue(FILE, sharedPrefs.getString(DeviceSettings.KEY_VIBRATOR_INTENSITY, "50")); + } + + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +} diff --git a/init.smdk4210.rc b/init.smdk4210.rc index 53da0e1..0acd613 100644 --- a/init.smdk4210.rc +++ b/init.smdk4210.rc @@ -228,6 +228,8 @@ on post-fs-data # Vibetonz chmod 0660 /dev/tspdrv chown root shell /dev/tspdrv + chmod 0660 /sys/vibrator/pwm_val + chown system system /sys/vibrator/pwm_val # Permissions for LCD chown system radio /sys/class/lcd/panel/lcd_power -- cgit v1.1