diff options
7 files changed, 106 insertions, 4 deletions
diff --git a/DeviceSettings/res/values/config.xml b/DeviceSettings/res/values/config.xml index 5667f97..b289bd9 100644 --- a/DeviceSettings/res/values/config.xml +++ b/DeviceSettings/res/values/config.xml @@ -26,4 +26,8 @@ <string name="intensity_default_value">50</string> <string name="intensity_min_value">0</string> + <!-- S-Pen --> + <string name="spen_sysfs_file">"/sys/class/sec/sec_epen"</string> + <string name="spen_powersaving_sysfs_file">"/sys/class/sec/sec_epen/epen_saving_mode"</string> + </resources> diff --git a/DeviceSettings/res/values/strings.xml b/DeviceSettings/res/values/strings.xml index 155e9c2..874adf1 100644 --- a/DeviceSettings/res/values/strings.xml +++ b/DeviceSettings/res/values/strings.xml @@ -53,4 +53,9 @@ <string name="use_dock_audio_title_head">Use Dock USB Audio</string> <string name="use_dock_audio_summary_head">Use the passive audio out on the dock</string> + <!-- S-Pen --> + <string name="spen_subcat_title">S-Pen</string> + <string name="spen_power_save_title_head">Power saving mode</string> + <string name="spen_power_save_summary_head">Disable stylus digitizer when S-Pen is in device</string> + </resources> diff --git a/DeviceSettings/res/xml/screen_preferences.xml b/DeviceSettings/res/xml/screen_preferences.xml index 57d1761..b655618 100644 --- a/DeviceSettings/res/xml/screen_preferences.xml +++ b/DeviceSettings/res/xml/screen_preferences.xml @@ -71,4 +71,15 @@ android:defaultValue="3" /> </PreferenceCategory> + <!-- S-Pen --> + <PreferenceCategory + android:key="category_spen" + android:title="@string/spen_subcat_title"> + <!-- S-Pen power saving mode --> + <com.cyanogenmod.settings.device.SPenPowerSavingMode + android:key="spen_power_save" + android:title="@string/spen_power_save_title_head" + android:summary="@string/spen_power_save_summary_head" /> + </PreferenceCategory> + </PreferenceScreen> diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java b/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java index 486fe79..310b535 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/DeviceSettings.java @@ -46,6 +46,8 @@ public class DeviceSettings extends FragmentActivity { public static final String KEY_HSPA = "hspa"; public static final String KEY_VIBRATOR_INTENSITY = "vibrator_intensity"; public static final String KEY_USE_DOCK_AUDIO = "dock_audio"; + public static final String KEY_CATEGORY_SPEN = "category_spen"; + public static final String KEY_SPEN_POWER_SAVING_MODE = "spen_power_saving"; ViewPager mViewPager; TabsAdapter mTabsAdapter; diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/SPenPowerSavingMode.java b/DeviceSettings/src/com/cyanogenmod/settings/device/SPenPowerSavingMode.java new file mode 100644 index 0000000..e80edd8 --- /dev/null +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/SPenPowerSavingMode.java @@ -0,0 +1,61 @@ +/* + * 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.Intent; +import android.content.SharedPreferences; +import android.util.AttributeSet; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class SPenPowerSavingMode extends CheckBoxPreference implements OnPreferenceChangeListener { + + private static String FILE_PATH = null; + + public SPenPowerSavingMode(Context context, AttributeSet attrs) { + super(context, attrs); + this.setOnPreferenceChangeListener(this); + FILE_PATH = context.getResources().getString(R.string.spen_powersaving_sysfs_file); + } + + public static boolean isSupported(String filePath) { + return Utils.fileExists(filePath); + } + + /** + * Restore s-pen setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + FILE_PATH = context.getResources().getString(R.string.spen_powersaving_sysfs_file); + + if (!isSupported(FILE_PATH)) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(FILE_PATH, sharedPrefs.getBoolean(DeviceSettings.KEY_SPEN_POWER_SAVING_MODE, false) ? "1" : "0"); + } + + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE_PATH, ((Boolean) newValue) ? "1" : "0"); + return true; + } +} diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java b/DeviceSettings/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java index 5a1576d..9efe06d 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/ScreenFragmentActivity.java @@ -17,12 +17,14 @@ package com.cyanogenmod.settings.device; import android.content.Context; +import android.content.res.Resources; 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.PreferenceCategory; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; @@ -40,6 +42,8 @@ public class ScreenFragmentActivity extends PreferenceFragment { private mDNIeNegative mmDNIeNegative; private LedFade mLedFade; + private static boolean sSPenSupported; + private static final String FILE_TOUCHKEY_BRIGHTNESS = "/sys/class/sec/sec_touchkey/brightness"; private static final String FILE_TOUCHKEY_DISABLE = "/sys/class/sec/sec_touchkey/force_disable"; @@ -48,11 +52,14 @@ public class ScreenFragmentActivity extends PreferenceFragment { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.screen_preferences); - PreferenceScreen prefSet = getPreferenceScreen(); + PreferenceScreen preferenceScreen = getPreferenceScreen(); + Resources res = getResources(); + /* CABC */ mCABC = (CABC) findPreference(DeviceSettings.KEY_CABC); mCABC.setEnabled(CABC.isSupported()); + /* mDNIe */ mmDNIeScenario = (mDNIeScenario) findPreference(DeviceSettings.KEY_MDNIE_SCENARIO); mmDNIeScenario.setEnabled(mDNIeScenario.isSupported()); @@ -62,13 +69,24 @@ public class ScreenFragmentActivity extends PreferenceFragment { mmDNIeNegative = (mDNIeNegative) findPreference(DeviceSettings.KEY_MDNIE_NEGATIVE); mmDNIeNegative.setEnabled(mDNIeNegative.isSupported()); + /* LED */ mLedFade = (LedFade) findPreference(DeviceSettings.KEY_LED_FADE); mLedFade.setEnabled(LedFade.isSupported()); - if (((CheckBoxPreference)prefSet.findPreference(DeviceSettings.KEY_TOUCHKEY_LIGHT)).isChecked()) { - prefSet.findPreference(DeviceSettings.KEY_TOUCHKEY_TIMEOUT).setEnabled(true); + /* Touchkey */ + if (((CheckBoxPreference)preferenceScreen.findPreference(DeviceSettings.KEY_TOUCHKEY_LIGHT)).isChecked()) { + preferenceScreen.findPreference(DeviceSettings.KEY_TOUCHKEY_TIMEOUT).setEnabled(true); } else { - prefSet.findPreference(DeviceSettings.KEY_TOUCHKEY_TIMEOUT).setEnabled(false); + preferenceScreen.findPreference(DeviceSettings.KEY_TOUCHKEY_TIMEOUT).setEnabled(false); + } + + /* S-Pen */ + String spenFilePath = res.getString(R.string.spen_sysfs_file); + sSPenSupported = SPenPowerSavingMode.isSupported(spenFilePath); + + PreferenceCategory spenCategory = (PreferenceCategory) findPreference(DeviceSettings.KEY_CATEGORY_SPEN); + if (!sSPenSupported) { + preferenceScreen.removePreference(spenCategory); } } diff --git a/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java b/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java index 950220e..d93d6bf 100644 --- a/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java +++ b/DeviceSettings/src/com/cyanogenmod/settings/device/Startup.java @@ -36,5 +36,6 @@ public class Startup extends BroadcastReceiver { LedFade.restore(context); TouchkeyTimeout.restore(context); VibratorTuningPreference.restore(context); + SPenPowerSavingMode.restore(context); } } |