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 | |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame^] | 19 | import com.android.settings.search.BaseSearchIndexProvider; |
| 20 | import com.android.settings.search.Indexable; |
| 21 | |
Adrian Roos | 244e8ce | 2014-05-13 17:00:46 +0200 | [diff] [blame] | 22 | import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE; |
| 23 | import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; |
| 24 | import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 25 | import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; |
| 26 | |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 27 | import android.app.ActivityManagerNative; |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 28 | import android.app.Dialog; |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 29 | import android.app.admin.DevicePolicyManager; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 30 | import android.content.ContentResolver; |
| 31 | import android.content.Context; |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 32 | import android.content.res.Configuration; |
Christopher Tate | 8a510c5 | 2011-07-29 16:16:22 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 34 | import android.os.Bundle; |
Chris Wren | ad1b7eb | 2014-02-28 16:16:59 -0500 | [diff] [blame] | 35 | import android.os.Handler; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 36 | import android.os.RemoteException; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 37 | import android.preference.CheckBoxPreference; |
| 38 | import android.preference.ListPreference; |
| 39 | import android.preference.Preference; |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 40 | import android.preference.Preference.OnPreferenceClickListener; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 41 | import android.preference.PreferenceScreen; |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame^] | 42 | import android.provider.SearchIndexableResource; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 43 | import android.provider.Settings; |
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 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 46 | import java.util.ArrayList; |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame^] | 47 | import java.util.List; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 48 | |
| 49 | public class DisplaySettings extends SettingsPreferenceFragment implements |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame^] | 50 | Preference.OnPreferenceChangeListener, OnPreferenceClickListener, Indexable { |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 51 | private static final String TAG = "DisplaySettings"; |
| 52 | |
| 53 | /** If there is no setting in the provider, use this. */ |
| 54 | private static final int FALLBACK_SCREEN_TIMEOUT_VALUE = 30000; |
| 55 | |
| 56 | private static final String KEY_SCREEN_TIMEOUT = "screen_timeout"; |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 57 | private static final String KEY_FONT_SIZE = "font_size"; |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 58 | private static final String KEY_SCREEN_SAVER = "screensaver"; |
Adrian Roos | 244e8ce | 2014-05-13 17:00:46 +0200 | [diff] [blame] | 59 | private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness"; |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 60 | |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 61 | private static final int DLG_GLOBAL_CHANGE_WARNING = 1; |
| 62 | |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 63 | private WarnedListPreference mFontSizePref; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 64 | |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 65 | private final Configuration mCurConfig = new Configuration(); |
Chris Wren | ad1b7eb | 2014-02-28 16:16:59 -0500 | [diff] [blame] | 66 | private final Handler mHandler = new Handler(); |
Shuhrat Dehkanov | 7e77699 | 2013-11-01 17:39:44 +0900 | [diff] [blame] | 67 | |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 68 | private ListPreference mScreenTimeoutPreference; |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 69 | private Preference mScreenSaverPreference; |
Adrian Roos | 244e8ce | 2014-05-13 17:00:46 +0200 | [diff] [blame] | 70 | private CheckBoxPreference mAutoBrightnessPreference; |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 71 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 72 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 73 | public void onCreate(Bundle savedInstanceState) { |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 74 | super.onCreate(savedInstanceState); |
Chris Wren | ad1b7eb | 2014-02-28 16:16:59 -0500 | [diff] [blame] | 75 | final ContentResolver resolver = getActivity().getContentResolver(); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 76 | |
| 77 | addPreferencesFromResource(R.xml.display_settings); |
| 78 | |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 79 | mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER); |
Daniel Sandler | 47c991f | 2012-02-01 14:14:18 -0500 | [diff] [blame] | 80 | if (mScreenSaverPreference != null |
| 81 | && getResources().getBoolean( |
John Spurlock | d983e1d | 2012-10-18 16:41:09 -0400 | [diff] [blame] | 82 | com.android.internal.R.bool.config_dreamsSupported) == false) { |
Daniel Sandler | 47c991f | 2012-02-01 14:14:18 -0500 | [diff] [blame] | 83 | getPreferenceScreen().removePreference(mScreenSaverPreference); |
| 84 | } |
Amith Yamasani | 78b8265 | 2013-08-16 16:35:54 -0700 | [diff] [blame] | 85 | |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 86 | mScreenTimeoutPreference = (ListPreference) findPreference(KEY_SCREEN_TIMEOUT); |
| 87 | final long currentTimeout = Settings.System.getLong(resolver, SCREEN_OFF_TIMEOUT, |
| 88 | FALLBACK_SCREEN_TIMEOUT_VALUE); |
| 89 | mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout)); |
| 90 | mScreenTimeoutPreference.setOnPreferenceChangeListener(this); |
| 91 | disableUnusableTimeouts(mScreenTimeoutPreference); |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 92 | updateTimeoutPreferenceDescription(currentTimeout); |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 93 | |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 94 | mFontSizePref = (WarnedListPreference) findPreference(KEY_FONT_SIZE); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 95 | mFontSizePref.setOnPreferenceChangeListener(this); |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 96 | mFontSizePref.setOnPreferenceClickListener(this); |
Adrian Roos | 244e8ce | 2014-05-13 17:00:46 +0200 | [diff] [blame] | 97 | |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame^] | 98 | if (isAutomaticBrightnessAvailable(getResources())) { |
Adrian Roos | 244e8ce | 2014-05-13 17:00:46 +0200 | [diff] [blame] | 99 | mAutoBrightnessPreference = (CheckBoxPreference) findPreference(KEY_AUTO_BRIGHTNESS); |
| 100 | mAutoBrightnessPreference.setOnPreferenceChangeListener(this); |
| 101 | } else { |
| 102 | removePreference(KEY_AUTO_BRIGHTNESS); |
| 103 | } |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame^] | 106 | private static boolean isAutomaticBrightnessAvailable(Resources res) { |
| 107 | return res.getBoolean(com.android.internal.R.bool.config_automatic_brightness_available); |
| 108 | } |
| 109 | |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 110 | private void updateTimeoutPreferenceDescription(long currentTimeout) { |
| 111 | ListPreference preference = mScreenTimeoutPreference; |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 112 | String summary; |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 113 | if (currentTimeout < 0) { |
| 114 | // Unsupported value |
| 115 | summary = ""; |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 116 | } else { |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 117 | final CharSequence[] entries = preference.getEntries(); |
| 118 | final CharSequence[] values = preference.getEntryValues(); |
Amith Yamasani | 64516a1 | 2012-10-22 16:38:02 -0700 | [diff] [blame] | 119 | if (entries == null || entries.length == 0) { |
| 120 | summary = ""; |
| 121 | } else { |
| 122 | int best = 0; |
| 123 | for (int i = 0; i < values.length; i++) { |
| 124 | long timeout = Long.parseLong(values[i].toString()); |
| 125 | if (currentTimeout >= timeout) { |
| 126 | best = i; |
| 127 | } |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 128 | } |
Amith Yamasani | 64516a1 | 2012-10-22 16:38:02 -0700 | [diff] [blame] | 129 | summary = preference.getContext().getString(R.string.screen_timeout_summary, |
| 130 | entries[best]); |
Jim Miller | 9391b95 | 2011-01-07 16:55:33 -0800 | [diff] [blame] | 131 | } |
| 132 | } |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 133 | preference.setSummary(summary); |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 134 | } |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 135 | |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 136 | private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) { |
Jim Miller | fc5a022 | 2010-04-13 15:31:41 -0700 | [diff] [blame] | 137 | final DevicePolicyManager dpm = |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 138 | (DevicePolicyManager) getActivity().getSystemService( |
| 139 | Context.DEVICE_POLICY_SERVICE); |
Jim Miller | fc5a022 | 2010-04-13 15:31:41 -0700 | [diff] [blame] | 140 | final long maxTimeout = dpm != null ? dpm.getMaximumTimeToLock(null) : 0; |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 141 | if (maxTimeout == 0) { |
| 142 | return; // policy not enforced |
| 143 | } |
| 144 | final CharSequence[] entries = screenTimeoutPreference.getEntries(); |
| 145 | final CharSequence[] values = screenTimeoutPreference.getEntryValues(); |
| 146 | ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>(); |
| 147 | ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>(); |
| 148 | for (int i = 0; i < values.length; i++) { |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 149 | long timeout = Long.parseLong(values[i].toString()); |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 150 | if (timeout <= maxTimeout) { |
| 151 | revisedEntries.add(entries[i]); |
| 152 | revisedValues.add(values[i]); |
| 153 | } |
| 154 | } |
| 155 | if (revisedEntries.size() != entries.length || revisedValues.size() != values.length) { |
Amith Yamasani | 78b8265 | 2013-08-16 16:35:54 -0700 | [diff] [blame] | 156 | final int userPreference = Integer.parseInt(screenTimeoutPreference.getValue()); |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 157 | screenTimeoutPreference.setEntries( |
| 158 | revisedEntries.toArray(new CharSequence[revisedEntries.size()])); |
| 159 | screenTimeoutPreference.setEntryValues( |
| 160 | revisedValues.toArray(new CharSequence[revisedValues.size()])); |
Jim Miller | fc5a022 | 2010-04-13 15:31:41 -0700 | [diff] [blame] | 161 | if (userPreference <= maxTimeout) { |
| 162 | screenTimeoutPreference.setValue(String.valueOf(userPreference)); |
Amith Yamasani | 78b8265 | 2013-08-16 16:35:54 -0700 | [diff] [blame] | 163 | } else if (revisedValues.size() > 0 |
| 164 | && Long.parseLong(revisedValues.get(revisedValues.size() - 1).toString()) |
| 165 | == maxTimeout) { |
| 166 | // If the last one happens to be the same as the max timeout, select that |
| 167 | screenTimeoutPreference.setValue(String.valueOf(maxTimeout)); |
Jim Miller | fc5a022 | 2010-04-13 15:31:41 -0700 | [diff] [blame] | 168 | } else { |
| 169 | // There will be no highlighted selection since nothing in the list matches |
| 170 | // maxTimeout. The user can still select anything less than maxTimeout. |
| 171 | // TODO: maybe append maxTimeout to the list and mark selected. |
| 172 | } |
Jim Miller | d90b5a8 | 2010-03-29 20:18:51 -0700 | [diff] [blame] | 173 | } |
| 174 | screenTimeoutPreference.setEnabled(revisedEntries.size() > 0); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Christopher Tate | 8a510c5 | 2011-07-29 16:16:22 -0700 | [diff] [blame] | 177 | int floatToIndex(float val) { |
| 178 | String[] indices = getResources().getStringArray(R.array.entryvalues_font_size); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 179 | float lastVal = Float.parseFloat(indices[0]); |
| 180 | for (int i=1; i<indices.length; i++) { |
| 181 | float thisVal = Float.parseFloat(indices[i]); |
| 182 | if (val < (lastVal + (thisVal-lastVal)*.5f)) { |
| 183 | return i-1; |
| 184 | } |
| 185 | lastVal = thisVal; |
| 186 | } |
| 187 | return indices.length-1; |
| 188 | } |
Shuhrat Dehkanov | 7e77699 | 2013-11-01 17:39:44 +0900 | [diff] [blame] | 189 | |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 190 | public void readFontSizePreference(ListPreference pref) { |
| 191 | try { |
Gilles Debunne | 737c81c | 2011-07-08 09:40:00 -0700 | [diff] [blame] | 192 | mCurConfig.updateFrom(ActivityManagerNative.getDefault().getConfiguration()); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 193 | } catch (RemoteException e) { |
Gilles Debunne | 737c81c | 2011-07-08 09:40:00 -0700 | [diff] [blame] | 194 | Log.w(TAG, "Unable to retrieve font size"); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 195 | } |
Christopher Tate | 8a510c5 | 2011-07-29 16:16:22 -0700 | [diff] [blame] | 196 | |
| 197 | // mark the appropriate item in the preferences list |
| 198 | int index = floatToIndex(mCurConfig.fontScale); |
| 199 | pref.setValueIndex(index); |
| 200 | |
| 201 | // report the current size in the summary text |
| 202 | final Resources res = getResources(); |
| 203 | String[] fontSizeNames = res.getStringArray(R.array.entries_font_size); |
| 204 | pref.setSummary(String.format(res.getString(R.string.summary_font_size), |
| 205 | fontSizeNames[index])); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 206 | } |
Shuhrat Dehkanov | 7e77699 | 2013-11-01 17:39:44 +0900 | [diff] [blame] | 207 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 208 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 209 | public void onResume() { |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 210 | super.onResume(); |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 211 | updateState(); |
Amith Yamasani | 26a1f89 | 2011-02-28 17:24:31 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | @Override |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 215 | public Dialog onCreateDialog(int dialogId) { |
| 216 | if (dialogId == DLG_GLOBAL_CHANGE_WARNING) { |
| 217 | return Utils.buildGlobalChangeWarningDialog(getActivity(), |
| 218 | R.string.global_font_change_title, |
| 219 | new Runnable() { |
| 220 | public void run() { |
| 221 | mFontSizePref.click(); |
| 222 | } |
| 223 | }); |
| 224 | } |
| 225 | return null; |
| 226 | } |
| 227 | |
Gilles Debunne | 737c81c | 2011-07-08 09:40:00 -0700 | [diff] [blame] | 228 | private void updateState() { |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 229 | readFontSizePreference(mFontSizePref); |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 230 | updateScreenSaverSummary(); |
Adrian Roos | 244e8ce | 2014-05-13 17:00:46 +0200 | [diff] [blame] | 231 | |
| 232 | // Update auto brightness if it is available. |
| 233 | if (mAutoBrightnessPreference != null) { |
| 234 | int brightnessMode = Settings.System.getInt(getContentResolver(), |
| 235 | SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL); |
| 236 | mAutoBrightnessPreference.setChecked(brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL); |
| 237 | } |
Daniel Sandler | 6f0ea44 | 2011-11-17 10:44:51 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | private void updateScreenSaverSummary() { |
Daniel Sandler | c825bc8 | 2012-10-18 10:33:59 -0400 | [diff] [blame] | 241 | if (mScreenSaverPreference != null) { |
| 242 | mScreenSaverPreference.setSummary( |
| 243 | DreamSettings.getSummaryTextWithDreamName(getActivity())); |
| 244 | } |
Amith Yamasani | 26a1f89 | 2011-02-28 17:24:31 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 247 | public void writeFontSizePreference(Object objValue) { |
| 248 | try { |
| 249 | mCurConfig.fontScale = Float.parseFloat(objValue.toString()); |
Dianne Hackborn | 92c8eba | 2011-07-19 14:59:01 -0700 | [diff] [blame] | 250 | ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 251 | } catch (RemoteException e) { |
Gilles Debunne | 737c81c | 2011-07-08 09:40:00 -0700 | [diff] [blame] | 252 | Log.w(TAG, "Unable to save font size"); |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
Amith Yamasani | 883d850 | 2011-09-20 14:41:03 -0700 | [diff] [blame] | 255 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 256 | @Override |
| 257 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Daniel Sandler | 2943cfa | 2011-04-15 11:18:57 -0400 | [diff] [blame] | 258 | return super.onPreferenceTreeClick(preferenceScreen, preference); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Jeff Brown | 4e54c2a | 2013-11-10 21:02:20 -0800 | [diff] [blame] | 261 | @Override |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 262 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
| 263 | final String key = preference.getKey(); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 264 | if (KEY_SCREEN_TIMEOUT.equals(key)) { |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 265 | try { |
Shuhrat Dehkanov | 7e77699 | 2013-11-01 17:39:44 +0900 | [diff] [blame] | 266 | int value = Integer.parseInt((String) objValue); |
Gilles Debunne | 698c24f | 2011-09-02 15:47:24 -0700 | [diff] [blame] | 267 | Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, value); |
| 268 | updateTimeoutPreferenceDescription(value); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 269 | } catch (NumberFormatException e) { |
| 270 | Log.e(TAG, "could not persist screen timeout setting", e); |
| 271 | } |
| 272 | } |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 273 | if (KEY_FONT_SIZE.equals(key)) { |
| 274 | writeFontSizePreference(objValue); |
| 275 | } |
Adrian Roos | 244e8ce | 2014-05-13 17:00:46 +0200 | [diff] [blame] | 276 | if (preference == mAutoBrightnessPreference) { |
| 277 | boolean auto = (Boolean) objValue; |
| 278 | Settings.System.putInt(getContentResolver(), SCREEN_BRIGHTNESS_MODE, |
| 279 | auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL); |
| 280 | } |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 281 | return true; |
| 282 | } |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 283 | |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 284 | @Override |
| 285 | public boolean onPreferenceClick(Preference preference) { |
| 286 | if (preference == mFontSizePref) { |
| 287 | if (Utils.hasMultipleUsers(getActivity())) { |
| 288 | showDialog(DLG_GLOBAL_CHANGE_WARNING); |
| 289 | return true; |
| 290 | } else { |
| 291 | mFontSizePref.click(); |
| 292 | } |
| 293 | } |
| 294 | return false; |
| 295 | } |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame^] | 296 | |
| 297 | public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 298 | new BaseSearchIndexProvider() { |
| 299 | @Override |
| 300 | public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, |
| 301 | boolean enabled) { |
| 302 | ArrayList<SearchIndexableResource> result = new ArrayList<>(1); |
| 303 | |
| 304 | SearchIndexableResource sir = new SearchIndexableResource(context); |
| 305 | sir.xmlResId = R.xml.display_settings; |
| 306 | result.add(sir); |
| 307 | |
| 308 | return result; |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public List<String> getNonIndexableKeys(Context context) { |
| 313 | ArrayList<String> nonIndexableKeys = new ArrayList<>(1); |
| 314 | if (!isAutomaticBrightnessAvailable(context.getResources())) { |
| 315 | nonIndexableKeys.add(KEY_AUTO_BRIGHTNESS); |
| 316 | } |
| 317 | return nonIndexableKeys; |
| 318 | } |
| 319 | }; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 320 | } |