Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; |
| 20 | |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 21 | import android.app.ActivityManagerNative; |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 22 | import android.app.admin.DevicePolicyManager; |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 23 | import android.content.BroadcastReceiver; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 24 | import android.content.ContentResolver; |
| 25 | import android.content.Context; |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 28 | import android.content.res.Configuration; |
Christopher Tate | 8a510c5 | 2011-07-29 16:16:22 -0700 | [diff] [blame] | 29 | import android.content.res.Resources; |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 30 | import android.hardware.display.DisplayManager; |
| 31 | import android.hardware.display.WifiDisplay; |
| 32 | import android.hardware.display.WifiDisplayStatus; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 33 | import android.os.Bundle; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 34 | import android.os.RemoteException; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 35 | import android.preference.CheckBoxPreference; |
| 36 | import android.preference.ListPreference; |
| 37 | import android.preference.Preference; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 38 | import android.preference.PreferenceScreen; |
| 39 | import android.provider.Settings; |
Amith Yamasani | 883d850 | 2011-09-20 14:41:03 -0700 | [diff] [blame] | 40 | import android.provider.Settings.SettingNotFoundException; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 41 | import android.util.Log; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 42 | |
Jeff Brown | 10fbf52 | 2012-06-05 17:49:24 -0700 | [diff] [blame] | 43 | import com.android.internal.view.RotationPolicy; |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 44 | import com.android.settings.DreamSettings; |
| 45 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 46 | import java.util.ArrayList; |
| 47 | |
| 48 | public class DisplaySettings extends SettingsPreferenceFragment implements |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 49 | Preference.OnPreferenceChangeListener { |
| 50 | private static final String TAG = "DisplaySettings"; |
| 51 | |
| 52 | /** If there is no setting in the provider, use this. */ |
| 53 | private static final int FALLBACK_SCREEN_TIMEOUT_VALUE = 30000; |
| 54 | |
| 55 | private static final String KEY_SCREEN_TIMEOUT = "screen_timeout"; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 56 | private static final String KEY_ACCELEROMETER = "accelerometer"; |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 57 | private static final String KEY_FONT_SIZE = "font_size"; |
Amith Yamasani | 883d850 | 2011-09-20 14:41:03 -0700 | [diff] [blame] | 58 | private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 59 | private static final String KEY_SCREEN_SAVER = "screensaver"; |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 60 | private static final String KEY_WIFI_DISPLAY = "wifi_display"; |
| 61 | |
| 62 | private DisplayManager mDisplayManager; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 63 | |
Jeff Brown | 56c58d5 | 2012-06-04 15:37:57 -0700 | [diff] [blame] | 64 | private CheckBoxPreference mAccelerometer; |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 65 | private ListPreference mFontSizePref; |
Amith Yamasani | 883d850 | 2011-09-20 14:41:03 -0700 | [diff] [blame] | 66 | private CheckBoxPreference mNotificationPulse; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 67 | |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 68 | private final Configuration mCurConfig = new Configuration(); |
| 69 | |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 70 | private ListPreference mScreenTimeoutPreference; |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 71 | private Preference mScreenSaverPreference; |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 72 | |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 73 | private WifiDisplayStatus mWifiDisplayStatus; |
| 74 | private Preference mWifiDisplayPreference; |
| 75 | |
Jeff Brown | 10fbf52 | 2012-06-05 17:49:24 -0700 | [diff] [blame] | 76 | private final RotationPolicy.RotationPolicyListener mRotationPolicyListener = |
| 77 | new RotationPolicy.RotationPolicyListener() { |
Amith Yamasani | 26a1f89 | 2011-02-28 17:24:31 -0800 | [diff] [blame] | 78 | @Override |
Jeff Brown | 10fbf52 | 2012-06-05 17:49:24 -0700 | [diff] [blame] | 79 | public void onChange() { |
Jeff Brown | 56c58d5 | 2012-06-04 15:37:57 -0700 | [diff] [blame] | 80 | updateAccelerometerRotationCheckbox(); |
Amith Yamasani | 26a1f89 | 2011-02-28 17:24:31 -0800 | [diff] [blame] | 81 | } |
| 82 | }; |
| 83 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 84 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 85 | public void onCreate(Bundle savedInstanceState) { |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 86 | super.onCreate(savedInstanceState); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 87 | ContentResolver resolver = getActivity().getContentResolver(); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 88 | |
| 89 | addPreferencesFromResource(R.xml.display_settings); |
| 90 | |
Jeff Brown | 56c58d5 | 2012-06-04 15:37:57 -0700 | [diff] [blame] | 91 | mAccelerometer = (CheckBoxPreference) findPreference(KEY_ACCELEROMETER); |
| 92 | mAccelerometer.setPersistent(false); |
Jeff Brown | 10fbf52 | 2012-06-05 17:49:24 -0700 | [diff] [blame] | 93 | if (RotationPolicy.isRotationLockToggleSupported(getActivity())) { |
| 94 | // If rotation lock is supported, then we do not provide this option in |
| 95 | // Display settings. However, is still available in Accessibility settings. |
| 96 | getPreferenceScreen().removePreference(mAccelerometer); |
| 97 | } |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 98 | |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 99 | mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER); |
Daniel Sandler | 47c991f | 2012-02-01 14:14:18 -0500 | [diff] [blame] | 100 | if (mScreenSaverPreference != null |
| 101 | && getResources().getBoolean( |
| 102 | com.android.internal.R.bool.config_enableDreams) == false) { |
| 103 | getPreferenceScreen().removePreference(mScreenSaverPreference); |
| 104 | } |
| 105 | |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 106 | mScreenTimeoutPreference = (ListPreference) findPreference(KEY_SCREEN_TIMEOUT); |
| 107 | final long currentTimeout = Settings.System.getLong(resolver, SCREEN_OFF_TIMEOUT, |
| 108 | FALLBACK_SCREEN_TIMEOUT_VALUE); |
| 109 | mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout)); |
| 110 | mScreenTimeoutPreference.setOnPreferenceChangeListener(this); |
| 111 | disableUnusableTimeouts(mScreenTimeoutPreference); |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 112 | updateTimeoutPreferenceDescription(currentTimeout); |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 113 | |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 114 | mFontSizePref = (ListPreference) findPreference(KEY_FONT_SIZE); |
| 115 | mFontSizePref.setOnPreferenceChangeListener(this); |
Amith Yamasani | 883d850 | 2011-09-20 14:41:03 -0700 | [diff] [blame] | 116 | mNotificationPulse = (CheckBoxPreference) findPreference(KEY_NOTIFICATION_PULSE); |
| 117 | if (mNotificationPulse != null |
| 118 | && getResources().getBoolean( |
| 119 | com.android.internal.R.bool.config_intrusiveNotificationLed) == false) { |
| 120 | getPreferenceScreen().removePreference(mNotificationPulse); |
| 121 | } else { |
| 122 | try { |
| 123 | mNotificationPulse.setChecked(Settings.System.getInt(resolver, |
| 124 | Settings.System.NOTIFICATION_LIGHT_PULSE) == 1); |
| 125 | mNotificationPulse.setOnPreferenceChangeListener(this); |
| 126 | } catch (SettingNotFoundException snfe) { |
| 127 | Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found"); |
| 128 | } |
| 129 | } |
Daniel Sandler | 47c991f | 2012-02-01 14:14:18 -0500 | [diff] [blame] | 130 | |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 131 | mDisplayManager = (DisplayManager)getActivity().getSystemService( |
| 132 | Context.DISPLAY_SERVICE); |
| 133 | mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus(); |
| 134 | mWifiDisplayPreference = (Preference)findPreference(KEY_WIFI_DISPLAY); |
| 135 | if (mWifiDisplayStatus.getFeatureState() |
| 136 | == WifiDisplayStatus.FEATURE_STATE_UNAVAILABLE) { |
| 137 | getPreferenceScreen().removePreference(mWifiDisplayPreference); |
| 138 | mWifiDisplayPreference = null; |
| 139 | } |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 142 | private void updateTimeoutPreferenceDescription(long currentTimeout) { |
| 143 | ListPreference preference = mScreenTimeoutPreference; |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 144 | String summary; |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 145 | if (currentTimeout < 0) { |
| 146 | // Unsupported value |
| 147 | summary = ""; |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 148 | } else { |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 149 | final CharSequence[] entries = preference.getEntries(); |
| 150 | final CharSequence[] values = preference.getEntryValues(); |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 151 | int best = 0; |
| 152 | for (int i = 0; i < values.length; i++) { |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 153 | long timeout = Long.parseLong(values[i].toString()); |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 154 | if (currentTimeout >= timeout) { |
| 155 | best = i; |
| 156 | } |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 157 | } |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 158 | summary = preference.getContext().getString(R.string.screen_timeout_summary, |
| 159 | entries[best]); |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 160 | } |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 161 | preference.setSummary(summary); |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 162 | } |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 163 | |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 164 | private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) { |
Jim Miller | fc5a022 | 2010-04-13 15:31:41 -0700 | [diff] [blame] | 165 | final DevicePolicyManager dpm = |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 166 | (DevicePolicyManager) getActivity().getSystemService( |
| 167 | Context.DEVICE_POLICY_SERVICE); |
Jim Miller | fc5a022 | 2010-04-13 15:31:41 -0700 | [diff] [blame] | 168 | final long maxTimeout = dpm != null ? dpm.getMaximumTimeToLock(null) : 0; |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 169 | if (maxTimeout == 0) { |
| 170 | return; // policy not enforced |
| 171 | } |
| 172 | final CharSequence[] entries = screenTimeoutPreference.getEntries(); |
| 173 | final CharSequence[] values = screenTimeoutPreference.getEntryValues(); |
| 174 | ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>(); |
| 175 | ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>(); |
| 176 | for (int i = 0; i < values.length; i++) { |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 177 | long timeout = Long.parseLong(values[i].toString()); |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 178 | if (timeout <= maxTimeout) { |
| 179 | revisedEntries.add(entries[i]); |
| 180 | revisedValues.add(values[i]); |
| 181 | } |
| 182 | } |
| 183 | if (revisedEntries.size() != entries.length || revisedValues.size() != values.length) { |
| 184 | screenTimeoutPreference.setEntries( |
| 185 | revisedEntries.toArray(new CharSequence[revisedEntries.size()])); |
| 186 | screenTimeoutPreference.setEntryValues( |
| 187 | revisedValues.toArray(new CharSequence[revisedValues.size()])); |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 188 | final int userPreference = Integer.parseInt(screenTimeoutPreference.getValue()); |
Jim Miller | fc5a022 | 2010-04-13 15:31:41 -0700 | [diff] [blame] | 189 | if (userPreference <= maxTimeout) { |
| 190 | screenTimeoutPreference.setValue(String.valueOf(userPreference)); |
| 191 | } else { |
| 192 | // There will be no highlighted selection since nothing in the list matches |
| 193 | // maxTimeout. The user can still select anything less than maxTimeout. |
| 194 | // TODO: maybe append maxTimeout to the list and mark selected. |
| 195 | } |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 196 | } |
| 197 | screenTimeoutPreference.setEnabled(revisedEntries.size() > 0); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Christopher Tate | 8a510c5 | 2011-07-29 16:16:22 -0700 | [diff] [blame] | 200 | int floatToIndex(float val) { |
| 201 | String[] indices = getResources().getStringArray(R.array.entryvalues_font_size); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 202 | float lastVal = Float.parseFloat(indices[0]); |
| 203 | for (int i=1; i<indices.length; i++) { |
| 204 | float thisVal = Float.parseFloat(indices[i]); |
| 205 | if (val < (lastVal + (thisVal-lastVal)*.5f)) { |
| 206 | return i-1; |
| 207 | } |
| 208 | lastVal = thisVal; |
| 209 | } |
| 210 | return indices.length-1; |
| 211 | } |
| 212 | |
| 213 | public void readFontSizePreference(ListPreference pref) { |
| 214 | try { |
Gilles Debunne | 737c81c | 2011-07-08 09:40:00 -0700 | [diff] [blame] | 215 | mCurConfig.updateFrom(ActivityManagerNative.getDefault().getConfiguration()); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 216 | } catch (RemoteException e) { |
Gilles Debunne | 737c81c | 2011-07-08 09:40:00 -0700 | [diff] [blame] | 217 | Log.w(TAG, "Unable to retrieve font size"); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 218 | } |
Christopher Tate | 8a510c5 | 2011-07-29 16:16:22 -0700 | [diff] [blame] | 219 | |
| 220 | // mark the appropriate item in the preferences list |
| 221 | int index = floatToIndex(mCurConfig.fontScale); |
| 222 | pref.setValueIndex(index); |
| 223 | |
| 224 | // report the current size in the summary text |
| 225 | final Resources res = getResources(); |
| 226 | String[] fontSizeNames = res.getStringArray(R.array.entries_font_size); |
| 227 | pref.setSummary(String.format(res.getString(R.string.summary_font_size), |
| 228 | fontSizeNames[index])); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 231 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 232 | public void onResume() { |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 233 | super.onResume(); |
| 234 | |
Jeff Brown | 10fbf52 | 2012-06-05 17:49:24 -0700 | [diff] [blame] | 235 | RotationPolicy.registerRotationPolicyListener(getActivity(), |
| 236 | mRotationPolicyListener); |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 237 | |
| 238 | if (mWifiDisplayPreference != null) { |
| 239 | getActivity().registerReceiver(mReceiver, new IntentFilter( |
| 240 | DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)); |
| 241 | mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus(); |
| 242 | } |
| 243 | |
| 244 | updateState(); |
Amith Yamasani | 26a1f89 | 2011-02-28 17:24:31 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public void onPause() { |
| 249 | super.onPause(); |
| 250 | |
Jeff Brown | 10fbf52 | 2012-06-05 17:49:24 -0700 | [diff] [blame] | 251 | RotationPolicy.unregisterRotationPolicyListener(getActivity(), |
| 252 | mRotationPolicyListener); |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 253 | |
| 254 | if (mWifiDisplayPreference != null) { |
| 255 | getActivity().unregisterReceiver(mReceiver); |
| 256 | } |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Gilles Debunne | 737c81c | 2011-07-08 09:40:00 -0700 | [diff] [blame] | 259 | private void updateState() { |
Jeff Brown | 56c58d5 | 2012-06-04 15:37:57 -0700 | [diff] [blame] | 260 | updateAccelerometerRotationCheckbox(); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 261 | readFontSizePreference(mFontSizePref); |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 262 | updateScreenSaverSummary(); |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 263 | updateWifiDisplaySummary(); |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | private void updateScreenSaverSummary() { |
John Spurlock | 6df18e2 | 2012-08-22 09:21:58 -0400 | [diff] [blame] | 267 | int summaryResId = DreamSettings.getSummaryResource(getActivity()); |
| 268 | if (summaryResId > 0) |
| 269 | mScreenSaverPreference.setSummary(summaryResId); |
| 270 | else |
| 271 | mScreenSaverPreference.setSummary(""); |
Amith Yamasani | 26a1f89 | 2011-02-28 17:24:31 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 274 | private void updateWifiDisplaySummary() { |
| 275 | if (mWifiDisplayPreference != null) { |
| 276 | switch (mWifiDisplayStatus.getFeatureState()) { |
| 277 | case WifiDisplayStatus.FEATURE_STATE_OFF: |
| 278 | mWifiDisplayPreference.setSummary(R.string.wifi_display_summary_off); |
| 279 | break; |
| 280 | case WifiDisplayStatus.FEATURE_STATE_ON: |
| 281 | mWifiDisplayPreference.setSummary(R.string.wifi_display_summary_on); |
| 282 | break; |
| 283 | case WifiDisplayStatus.FEATURE_STATE_DISABLED: |
| 284 | default: |
| 285 | mWifiDisplayPreference.setSummary(R.string.wifi_display_summary_disabled); |
| 286 | break; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
Jeff Brown | 56c58d5 | 2012-06-04 15:37:57 -0700 | [diff] [blame] | 291 | private void updateAccelerometerRotationCheckbox() { |
Amith Yamasani | 980a6c3 | 2012-05-14 17:46:23 -0700 | [diff] [blame] | 292 | if (getActivity() == null) return; |
Jeff Brown | 10fbf52 | 2012-06-05 17:49:24 -0700 | [diff] [blame] | 293 | |
| 294 | mAccelerometer.setChecked(!RotationPolicy.isRotationLocked(getActivity())); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 297 | public void writeFontSizePreference(Object objValue) { |
| 298 | try { |
| 299 | mCurConfig.fontScale = Float.parseFloat(objValue.toString()); |
Dianne Hackborn | 92c8eba | 2011-07-19 14:59:01 -0700 | [diff] [blame] | 300 | ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 301 | } catch (RemoteException e) { |
Gilles Debunne | 737c81c | 2011-07-08 09:40:00 -0700 | [diff] [blame] | 302 | Log.w(TAG, "Unable to save font size"); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 303 | } |
| 304 | } |
Amith Yamasani | 883d850 | 2011-09-20 14:41:03 -0700 | [diff] [blame] | 305 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 306 | @Override |
| 307 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Jeff Brown | 56c58d5 | 2012-06-04 15:37:57 -0700 | [diff] [blame] | 308 | if (preference == mAccelerometer) { |
Jeff Brown | 10fbf52 | 2012-06-05 17:49:24 -0700 | [diff] [blame] | 309 | RotationPolicy.setRotationLockForAccessibility( |
| 310 | getActivity(), !mAccelerometer.isChecked()); |
Amith Yamasani | 883d850 | 2011-09-20 14:41:03 -0700 | [diff] [blame] | 311 | } else if (preference == mNotificationPulse) { |
| 312 | boolean value = mNotificationPulse.isChecked(); |
| 313 | Settings.System.putInt(getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, |
| 314 | value ? 1 : 0); |
| 315 | return true; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 316 | } |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 317 | return super.onPreferenceTreeClick(preferenceScreen, preference); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
| 321 | final String key = preference.getKey(); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 322 | if (KEY_SCREEN_TIMEOUT.equals(key)) { |
| 323 | int value = Integer.parseInt((String) objValue); |
| 324 | try { |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 325 | Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, value); |
| 326 | updateTimeoutPreferenceDescription(value); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 327 | } catch (NumberFormatException e) { |
| 328 | Log.e(TAG, "could not persist screen timeout setting", e); |
| 329 | } |
| 330 | } |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 331 | if (KEY_FONT_SIZE.equals(key)) { |
| 332 | writeFontSizePreference(objValue); |
| 333 | } |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 334 | |
| 335 | return true; |
| 336 | } |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame^] | 337 | |
| 338 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 339 | @Override |
| 340 | public void onReceive(Context context, Intent intent) { |
| 341 | if (intent.getAction().equals(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)) { |
| 342 | mWifiDisplayStatus = (WifiDisplayStatus)intent.getParcelableExtra( |
| 343 | DisplayManager.EXTRA_WIFI_DISPLAY_STATUS); |
| 344 | updateWifiDisplaySummary(); |
| 345 | } |
| 346 | } |
| 347 | }; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 348 | } |