diff options
author | blunden <blunden2@gmail.com> | 2012-07-30 15:40:31 +0200 |
---|---|---|
committer | nebkat <nebkat@teamhacksung.org> | 2012-12-15 21:42:35 +0000 |
commit | 0611cbeba4c9a27685e06536b645ffaf12182f2c (patch) | |
tree | 0c412ec51b895ac8c121dda4323f46f77352bd31 | |
parent | 56b46c0f8cb586ca40abc8cc0bc501c69c3f8506 (diff) | |
download | packages_apps_settings-0611cbeba4c9a27685e06536b645ffaf12182f2c.zip packages_apps_settings-0611cbeba4c9a27685e06536b645ffaf12182f2c.tar.gz packages_apps_settings-0611cbeba4c9a27685e06536b645ffaf12182f2c.tar.bz2 |
Settings: Add option to always show battery status on lockscreen (2/2)
Based on the feature by burnsra in CM7
Authored by blunden
Tweaked by dvtonder
Screenshot: https://dl.dropbox.com/u/50993944/Screenshot_2012-08-03-08-47-16.png
Patchset 1 : Initial commit
Patchset 2 : UI redesign
Patchset 3 : Patch description text updated
Patchset 4 : Fix derp in comments
Change-Id: I1c8c8eef3d0c913c621f735e7d5e395c8768fe76
-rw-r--r-- | res/values/arrays.xml | 10 | ||||
-rw-r--r-- | res/values/strings.xml | 5 | ||||
-rw-r--r-- | res/xml/lockscreen_interface_settings.xml | 9 | ||||
-rw-r--r-- | src/com/android/settings/cyanogenmod/LockscreenInterface.java | 30 |
4 files changed, 53 insertions, 1 deletions
diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 11069a8..f93a01a 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1189,5 +1189,15 @@ <item>2</item> </string-array> + <string-array name="lockscreen_battery_status_entries" translatable="false"> + <item>@string/lockscreen_battery_status_charging</item> + <item>@string/lockscreen_battery_status_alwayson</item> + </string-array> + + <string-array name="lockscreen_battery_status_values" translatable="false"> + <item>0</item> + <item>1</item> + </string-array> + <!-- **** CYANOGENMOD EDITS END **** --> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index c3e48bc..46b04c9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4512,6 +4512,11 @@ <string name="lockscreen_vibrate_enabled_title">Vibrate</string> <string name="lockscreen_vibrate_enabled_head">Vibrate when unlocking</string> + <!-- Lock screen misc. settings --> + <string name="lockscreen_battery_status_title">Battery status</string> + <string name="lockscreen_battery_status_charging">Only when charging</string> + <string name="lockscreen_battery_status_alwayson">Always on</string> + <!-- Profiles settings --> <string name="profiles_settings_title">Profiles</string> <string name="profiles_general_title">General</string> diff --git a/res/xml/lockscreen_interface_settings.xml b/res/xml/lockscreen_interface_settings.xml index a4f5365..4138020 100644 --- a/res/xml/lockscreen_interface_settings.xml +++ b/res/xml/lockscreen_interface_settings.xml @@ -25,6 +25,15 @@ <extra android:name="cm_security" android:value="true" /> </PreferenceScreen> + <ListPreference + android:key="lockscreen_battery_status" + android:persistent="false" + android:dialogTitle="@string/lockscreen_battery_status_title" + android:title="@string/lockscreen_battery_status_title" + android:entries="@array/lockscreen_battery_status_entries" + android:entryValues="@array/lockscreen_battery_status_values" + android:defaultValue="0" /> + <Preference android:fragment="com.android.settings.cyanogenmod.LockscreenTargets" android:key="lockscreen_targets" diff --git a/src/com/android/settings/cyanogenmod/LockscreenInterface.java b/src/com/android/settings/cyanogenmod/LockscreenInterface.java index 7df8699..63787c5 100644 --- a/src/com/android/settings/cyanogenmod/LockscreenInterface.java +++ b/src/com/android/settings/cyanogenmod/LockscreenInterface.java @@ -16,18 +16,22 @@ package com.android.settings.cyanogenmod; import android.os.Bundle; +import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceScreen; +import android.provider.Settings; import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; -public class LockscreenInterface extends SettingsPreferenceFragment { +public class LockscreenInterface extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener { private static final String TAG = "LockscreenInterface"; + private static final String KEY_ALWAYS_BATTERY_PREF = "lockscreen_battery_status"; private static final String KEY_LOCKSCREEN_BUTTONS = "lockscreen_buttons"; private PreferenceScreen mLockscreenButtons; + private ListPreference mBatteryStatus; public boolean hasButtons() { return !getResources().getBoolean(com.android.internal.R.bool.config_showNavigationBar); @@ -39,6 +43,9 @@ public class LockscreenInterface extends SettingsPreferenceFragment { addPreferencesFromResource(R.xml.lockscreen_interface_settings); + mBatteryStatus = (ListPreference) findPreference(KEY_ALWAYS_BATTERY_PREF); + mBatteryStatus.setOnPreferenceChangeListener(this); + mLockscreenButtons = (PreferenceScreen) findPreference(KEY_LOCKSCREEN_BUTTONS); if (!hasButtons()) { getPreferenceScreen().removePreference(mLockscreenButtons); @@ -53,10 +60,31 @@ public class LockscreenInterface extends SettingsPreferenceFragment { @Override public void onPause() { super.onPause(); + + // Set the battery status description text + if (mBatteryStatus != null) { + int batteryStatus = Settings.System.getInt(getActivity().getApplicationContext().getContentResolver(), + Settings.System.LOCKSCREEN_ALWAYS_SHOW_BATTERY, 0); + mBatteryStatus.setValueIndex(batteryStatus); + mBatteryStatus.setSummary(mBatteryStatus.getEntries()[batteryStatus]); + } } @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { return super.onPreferenceTreeClick(preferenceScreen, preference); } + + @Override + public boolean onPreferenceChange(Preference preference, Object objValue) { + if (preference == mBatteryStatus) { + int value = Integer.valueOf((String) objValue); + int index = mBatteryStatus.findIndexOfValue((String) objValue); + Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(), + Settings.System.LOCKSCREEN_ALWAYS_SHOW_BATTERY, value); + mBatteryStatus.setSummary(mBatteryStatus.getEntries()[index]); + return true; + } + return false; + } } |