diff options
author | Brandon McAnsh <brandon.mcansh@gmail.com> | 2015-06-22 09:26:25 -0400 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2015-11-03 11:56:04 -0800 |
commit | e06cbb57173c3c8206db74a3fdf26553c52ae969 (patch) | |
tree | 028fccf19cc25be0379c0610ef8ea6689581b73e | |
parent | 4705f54afbe860337ef1dd9745d3ba9b889d04e3 (diff) | |
download | packages_apps_Settings-e06cbb57173c3c8206db74a3fdf26553c52ae969.zip packages_apps_Settings-e06cbb57173c3c8206db74a3fdf26553c52ae969.tar.gz packages_apps_Settings-e06cbb57173c3c8206db74a3fdf26553c52ae969.tar.bz2 |
Development: Add choices to 'Stay Awake' preference
* Per a request on Google+ for Google Engineers to add to M, the stay awake values
can now be never, while usb debugging, and always.
* Keep them pixels awake.
Change-Id: I7f43200bab0f000dc7547cc3142c4cacda2f4732
Signed-off-by: Brandon McAnsh <brandon.mcansh@gmail.com>
-rw-r--r-- | res/values/cm_arrays.xml | 12 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 4 | ||||
-rw-r--r-- | res/xml/development_prefs.xml | 9 | ||||
-rw-r--r-- | src/com/android/settings/DevelopmentSettings.java | 41 |
4 files changed, 53 insertions, 13 deletions
diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml index 7bbb8b0..1ee23a1 100644 --- a/res/values/cm_arrays.xml +++ b/res/values/cm_arrays.xml @@ -348,4 +348,16 @@ <item>1</item> <item>2</item> </string-array> + + <string-array name="keep_screen_on_titles" translatable="false"> + <item>@string/keep_screen_on_never</item> + <item>@string/keep_screen_on_debugging</item> + <item>@string/keep_screen_on_charging</item> + </string-array> + + <string-array name="keep_screen_on_values" translatable="false"> + <item>0</item> + <item>1</item> + <item>2</item> + </string-array> </resources> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 9bb751e..a65dbd5 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -616,4 +616,8 @@ <string name="edge_gesture_service_title">Block gesture touch events</string> <string name="edge_gesture_service_summary">Don\'t send touch events for navigation and status bar gestures to apps</string> + <!-- Keep screen on strings --> + <string name="keep_screen_on_never">Never</string> + <string name="keep_screen_on_debugging">While USB debugging</string> + <string name="keep_screen_on_charging">While charging</string> </resources> diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml index 899b1c9..b869474 100644 --- a/res/xml/development_prefs.xml +++ b/res/xml/development_prefs.xml @@ -43,10 +43,13 @@ android:targetClass="com.android.settings.SetFullBackupPassword" /> </PreferenceScreen> - <SwitchPreference - android:key="keep_screen_on" + <ListPreference + android:key="keep_screen_on_modes" android:title="@string/keep_screen_on" - android:summary="@string/keep_screen_on_summary"/> + android:dialogTitle="@string/keep_screen_on" + android:entries="@array/keep_screen_on_titles" + android:entryValues="@array/keep_screen_on_values" + android:persistent="false" /> <ListPreference android:key="hdcp_checking" diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 0c55cb3..916788d 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -110,7 +110,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private static final String ADB_TCPIP = "adb_over_network"; private static final String CLEAR_ADB_KEYS = "clear_adb_keys"; private static final String ENABLE_TERMINAL = "enable_terminal"; - private static final String KEEP_SCREEN_ON = "keep_screen_on"; + private static final String KEEP_SCREEN_ON_MODES = "keep_screen_on_modes"; private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log"; private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable"; private static final String HDCP_CHECKING_KEY = "hdcp_checking"; @@ -212,7 +212,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private SwitchPreference mEnableTerminal; private Preference mBugreport; private SwitchPreference mBugreportInPower; - private SwitchPreference mKeepScreenOn; + private ListPreference mKeepScreenOn; private SwitchPreference mBtHciSnoopLog; private SwitchPreference mEnableOemUnlock; private SwitchPreference mDebugViewAttributes; @@ -334,7 +334,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment mBugreport = findPreference(BUGREPORT); mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY); - mKeepScreenOn = findAndInitSwitchPref(KEEP_SCREEN_ON); + mKeepScreenOn = addListPreference(KEEP_SCREEN_ON_MODES); mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG); mEnableOemUnlock = findAndInitSwitchPref(ENABLE_OEM_UNLOCK); if (!showEnableOemUnlockPreference()) { @@ -602,8 +602,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment } updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr, Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0); - updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr, - Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0); + updateStayAwakeOptions(); updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr, Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0); if (mEnableOemUnlock != null) { @@ -749,6 +748,23 @@ public class DevelopmentSettings extends SettingsPreferenceFragment updateRootAccessOptions(); } + private void updateStayAwakeOptions() { + int index = Settings.Global.getInt(getActivity().getContentResolver(), + Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0); + final String[] values = getResources().getStringArray(R.array.keep_screen_on_values); + final String[] summaries = getResources().getStringArray(R.array.keep_screen_on_titles); + // The old value contained 0 (disable) or 3 (BATTERY_PLUGGED_AC|BATTERY_PLUGGED_USB) + // Currently only have 3 values (0: Not enabled; 1: debugging over usb; >2: charging) + // NOTE: If we have newer values, then we need to migrate + // this property + if (index >= values.length) { + index = values.length - 1; + } + mKeepScreenOn.setValue(values[index]); + mKeepScreenOn.setSummary(summaries[index]); + mKeepScreenOn.setOnPreferenceChangeListener(this); + } + private void updateHdcpValues() { ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY); if (hdcpChecking != null) { @@ -1145,6 +1161,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]); } + private void writeStayAwakeOptions(Object newValue) { + int val = Integer.parseInt((String) newValue); + Settings.Global.putInt(getActivity().getContentResolver(), + Settings.Global.STAY_ON_WHILE_PLUGGED_IN, val); + updateStayAwakeOptions(); + } + private void writeShowNonRectClipOptions(Object newValue) { SystemProperties.set(HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY, newValue == null ? "" : newValue.toString()); @@ -1750,11 +1773,6 @@ public class DevelopmentSettings extends SettingsPreferenceFragment Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.BUGREPORT_IN_POWER_MENU, mBugreportInPower.isChecked() ? 1 : 0); - } else if (preference == mKeepScreenOn) { - Settings.Global.putInt(getActivity().getContentResolver(), - Settings.Global.STAY_ON_WHILE_PLUGGED_IN, - mKeepScreenOn.isChecked() ? - (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0); } else if (preference == mBtHciSnoopLog) { writeBtHciSnoopLogOptions(); } else if (preference == mEnableOemUnlock) { @@ -1911,6 +1929,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment writeRootAccessOptions(newValue); } return true; + } else if (preference == mKeepScreenOn) { + writeStayAwakeOptions(newValue); + return true; } return false; } |