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