From 3f7b71553971be861faf7d486735c4a8cc4f7854 Mon Sep 17 00:00:00 2001 From: Sam Mortimer Date: Thu, 28 Jun 2012 21:58:22 -0700 Subject: n7000: configurable touchkey backlight timeout (2/2) requires smdk4210 kernel change: http://review.cyanogenmod.com/#/c/18357/ Patch applied with conflict resolution to N7000 tree. Change-Id: Icd4bd6749886ef1eaf7f4527bf7052a18b549868 --- .../settings/device/DeviceSettings.java | 1 + .../settings/device/SensorsFragmentActivity.java | 25 +++++++-- .../com/cyanogenmod/settings/device/Startup.java | 1 + .../settings/device/TouchkeyTimeout.java | 59 ++++++++++++++++++++++ 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 DeviceSettings/src/com/cyanogenmod/settings/device/TouchkeyTimeout.java (limited to 'DeviceSettings/src') diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java b/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java index 58003a2..a60d9e8 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_TOUCHKEY_TIMEOUT = "touchkey_timeout"; public static final String KEY_VIBRATOR_INTENSITY = "vibrator_intensity"; ViewPager mViewPager; diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java b/DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java index bc42a95..bbe5f08 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/SensorsFragmentActivity.java @@ -36,8 +36,8 @@ public class SensorsFragmentActivity extends PreferenceFragment { private static final String TAG = "GalaxyNoteParts_General"; private static final String FILE_USE_GYRO_CALIB = "/sys/class/sec/gsensorcal/calibration"; - private static final String FILE_TOUCHKEY_LIGHT = "/data/.disable_touchlight"; - private static final String FILE_TOUCHKEY_TOGGLE = "/sys/class/sec/sec_touchkey/brightness"; + private static final String FILE_TOUCHKEY_DISABLE = "/sys/class/sec/sec_touchkey/force_disable"; + private static final String FILE_TOUCHKEY_BRIGHTNESS = "/sys/class/sec/sec_touchkey/brightness"; @Override public void onCreate(Bundle savedInstanceState) { @@ -47,6 +47,12 @@ public class SensorsFragmentActivity extends PreferenceFragment { PreferenceScreen prefSet = getPreferenceScreen(); + if (((CheckBoxPreference)prefSet.findPreference(DeviceSettings.KEY_TOUCHKEY_LIGHT)).isChecked()) { + prefSet.findPreference(DeviceSettings.KEY_TOUCHKEY_TIMEOUT).setEnabled(true); + } else { + prefSet.findPreference(DeviceSettings.KEY_TOUCHKEY_TIMEOUT).setEnabled(false); + } + } @Override @@ -67,8 +73,15 @@ public class SensorsFragmentActivity extends PreferenceFragment { Utils.writeValue(FILE_USE_GYRO_CALIB, "1"); Utils.showDialog((Context)getActivity(), "Calibration done", "The gyroscope has been successfully calibrated!"); } else if (key.compareTo(DeviceSettings.KEY_TOUCHKEY_LIGHT) == 0) { - Utils.writeValue(FILE_TOUCHKEY_LIGHT, ((CheckBoxPreference)preference).isChecked() ? "1" : "0"); - Utils.writeValue(FILE_TOUCHKEY_TOGGLE, ((CheckBoxPreference)preference).isChecked() ? "1" : "2"); + if (((CheckBoxPreference)preference).isChecked()) { + Utils.writeValue(FILE_TOUCHKEY_DISABLE, "0"); + Utils.writeValue(FILE_TOUCHKEY_BRIGHTNESS, "1"); + preferenceScreen.findPreference(DeviceSettings.KEY_TOUCHKEY_TIMEOUT).setEnabled(true); + } else { + Utils.writeValue(FILE_TOUCHKEY_DISABLE, "1"); + Utils.writeValue(FILE_TOUCHKEY_BRIGHTNESS, "2"); + preferenceScreen.findPreference(DeviceSettings.KEY_TOUCHKEY_TIMEOUT).setEnabled(false); + } } return true; @@ -89,6 +102,8 @@ public class SensorsFragmentActivity extends PreferenceFragment { Utils.writeValue(FILE_USE_GYRO_CALIB, "0"); boolean light = sharedPrefs.getBoolean(DeviceSettings.KEY_TOUCHKEY_LIGHT, true); - Utils.writeValue(FILE_TOUCHKEY_LIGHT, light); + + Utils.writeValue(FILE_TOUCHKEY_BRIGHTNESS, light ? "1" : "0"); + Utils.writeValue(FILE_TOUCHKEY_DISABLE, light ? "0" : "1"); } } diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java b/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java index a3b5135..cb3624a 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java @@ -32,6 +32,7 @@ public class Startup extends BroadcastReceiver { HapticFragmentActivity.restore(context); VibratorIntensity.restore(context); SensorsFragmentActivity.restore(context); + TouchkeyTimeout.restore(context); } } diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/TouchkeyTimeout.java b/DeviceSettings/src/com/cyanogenmod/settings/device/TouchkeyTimeout.java new file mode 100644 index 0000000..ce741f8 --- /dev/null +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/TouchkeyTimeout.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 TouchkeyTimeout extends ListPreference implements OnPreferenceChangeListener { + + public TouchkeyTimeout(Context context, AttributeSet attrs) { + super(context, attrs); + this.setOnPreferenceChangeListener(this); + } + + private static final String FILE_TOUCHKEY_TIMEOUT = "/sys/class/sec/sec_touchkey/led_timeout"; + + public static boolean isSupported() { + return Utils.fileExists(FILE_TOUCHKEY_TIMEOUT); + } + + /** + * Restore touchscreen sensitivity 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_TOUCHKEY_TIMEOUT, sharedPrefs.getString(DeviceSettings.KEY_TOUCHKEY_TIMEOUT, "3")); + } + + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE_TOUCHKEY_TIMEOUT, (String) newValue); + return true; + } + +} -- cgit v1.1