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 | |
Jason Monk | d3232da | 2014-08-20 13:29:20 -0400 | [diff] [blame] | 19 | import android.app.Activity; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame] | 21 | import android.provider.SearchIndexableResource; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 22 | import android.provider.Settings; |
Jason Monk | 1230ac8 | 2015-12-11 20:14:43 -0500 | [diff] [blame] | 23 | |
Tamas Berghammer | 265d3c2 | 2016-06-22 15:34:45 +0100 | [diff] [blame] | 24 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 25 | import com.android.settings.core.PreferenceController; |
| 26 | import com.android.settings.dashboard.DashboardFragment; |
Jason Monk | 3069581 | 2015-11-17 09:01:08 -0500 | [diff] [blame] | 27 | import com.android.settings.dashboard.SummaryLoader; |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 28 | import com.android.settings.display.AutoBrightnessPreferenceController; |
| 29 | import com.android.settings.display.AutoRotatePreferenceController; |
| 30 | import com.android.settings.display.CameraGesturePreferenceController; |
| 31 | import com.android.settings.display.DozePreferenceController; |
| 32 | import com.android.settings.display.FontSizePreferenceController; |
| 33 | import com.android.settings.display.LiftToWakePreferenceController; |
| 34 | import com.android.settings.display.NightDisplayPreferenceController; |
| 35 | import com.android.settings.display.NightModePreferenceController; |
| 36 | import com.android.settings.display.ScreenSaverPreferenceController; |
| 37 | import com.android.settings.display.TapToWakePreferenceController; |
| 38 | import com.android.settings.display.TimeoutPreferenceController; |
| 39 | import com.android.settings.display.VrDisplayPreferenceController; |
| 40 | import com.android.settings.display.WallpaperPreferenceController; |
Fan Zhang | 99abc02 | 2016-10-11 14:23:13 -0700 | [diff] [blame] | 41 | import com.android.settings.overlay.FeatureFactory; |
Jason Monk | 49b6103 | 2015-08-12 11:31:29 -0400 | [diff] [blame] | 42 | import com.android.settings.search.BaseSearchIndexProvider; |
| 43 | import com.android.settings.search.Indexable; |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 44 | import com.android.settingslib.drawer.CategoryKey; |
Jason Monk | 49b6103 | 2015-08-12 11:31:29 -0400 | [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 | |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 49 | import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; |
Sudheer Shanka | 550d068 | 2016-01-13 15:16:55 +0000 | [diff] [blame] | 50 | |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 51 | public class DisplaySettings extends DashboardFragment { |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 52 | private static final String TAG = "DisplaySettings"; |
| 53 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 54 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 55 | public int getMetricsCategory() { |
Chris Wren | 9d1bfd1 | 2016-01-26 18:04:01 -0500 | [diff] [blame] | 56 | return MetricsEvent.DISPLAY; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 60 | protected String getLogTag() { |
| 61 | return TAG; |
Stephen Chen | 2b98ffa | 2016-09-20 13:15:11 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 64 | @Override |
Fan Zhang | d916dae | 2017-01-06 16:10:28 -0800 | [diff] [blame] | 65 | public void onAttach(Context context) { |
| 66 | super.onAttach(context); |
| 67 | mProgressiveDisclosureMixin.setTileLimit(4); |
| 68 | } |
| 69 | |
| 70 | @Override |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 71 | protected String getCategoryKey() { |
| 72 | return CategoryKey.CATEGORY_DISPLAY; |
Dianne Hackborn | 6677e56 | 2011-03-04 17:30:54 -0800 | [diff] [blame] | 73 | } |
Amith Yamasani | 883d850 | 2011-09-20 14:41:03 -0700 | [diff] [blame] | 74 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 75 | @Override |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 76 | protected int getPreferenceScreenResId() { |
Fan Zhang | 99abc02 | 2016-10-11 14:23:13 -0700 | [diff] [blame] | 77 | if (mDashboardFeatureProvider.isEnabled()) { |
| 78 | return R.xml.ia_display_settings; |
| 79 | } else { |
| 80 | return R.xml.display_settings; |
| 81 | } |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 82 | } |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 83 | |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 84 | @Override |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 85 | protected List<PreferenceController> getPreferenceControllers(Context context) { |
| 86 | final List<PreferenceController> controllers = new ArrayList<>(); |
| 87 | controllers.add(new AutoBrightnessPreferenceController(context)); |
| 88 | controllers.add(new AutoRotatePreferenceController(context)); |
| 89 | controllers.add(new CameraGesturePreferenceController(context)); |
| 90 | controllers.add(new DozePreferenceController(context)); |
| 91 | controllers.add(new FontSizePreferenceController(context)); |
| 92 | controllers.add(new LiftToWakePreferenceController(context)); |
| 93 | controllers.add(new NightDisplayPreferenceController(context)); |
| 94 | controllers.add(new NightModePreferenceController(context)); |
| 95 | controllers.add(new ScreenSaverPreferenceController(context)); |
| 96 | controllers.add(new TapToWakePreferenceController(context)); |
| 97 | controllers.add(new TimeoutPreferenceController(context)); |
| 98 | controllers.add(new VrDisplayPreferenceController(context)); |
| 99 | controllers.add(new WallpaperPreferenceController(context)); |
| 100 | return controllers; |
Doris Ling | b727e9c | 2016-08-01 14:56:26 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
Jason Monk | 23acc2b | 2015-04-14 15:06:39 -0400 | [diff] [blame] | 104 | protected int getHelpResource() { |
| 105 | return R.string.help_uri_display; |
| 106 | } |
| 107 | |
Jason Monk | 3069581 | 2015-11-17 09:01:08 -0500 | [diff] [blame] | 108 | private static class SummaryProvider implements SummaryLoader.SummaryProvider { |
| 109 | private final Context mContext; |
| 110 | private final SummaryLoader mLoader; |
| 111 | |
| 112 | private SummaryProvider(Context context, SummaryLoader loader) { |
| 113 | mContext = context; |
| 114 | mLoader = loader; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void setListening(boolean listening) { |
| 119 | if (listening) { |
| 120 | updateSummary(); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | private void updateSummary() { |
Stephen Chen | 2b98ffa | 2016-09-20 13:15:11 -0700 | [diff] [blame] | 125 | final long currentTimeout = Settings.System.getLong(mContext.getContentResolver(), |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 126 | SCREEN_OFF_TIMEOUT, TimeoutPreferenceController.FALLBACK_SCREEN_TIMEOUT_VALUE); |
Stephen Chen | 2b98ffa | 2016-09-20 13:15:11 -0700 | [diff] [blame] | 127 | final CharSequence[] entries = |
| 128 | mContext.getResources().getTextArray(R.array.screen_timeout_entries); |
| 129 | final CharSequence[] values = |
| 130 | mContext.getResources().getTextArray(R.array.screen_timeout_values); |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 131 | final CharSequence timeoutDescription = TimeoutPreferenceController |
| 132 | .getTimeoutDescription(currentTimeout, entries, values); |
Stephen Chen | 2b98ffa | 2016-09-20 13:15:11 -0700 | [diff] [blame] | 133 | final String summary = timeoutDescription == null ? "" |
| 134 | : mContext.getString(R.string.display_summary, timeoutDescription); |
| 135 | mLoader.setSummary(this, summary); |
Jason Monk | 3069581 | 2015-11-17 09:01:08 -0500 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY |
| 140 | = new SummaryLoader.SummaryProviderFactory() { |
| 141 | @Override |
| 142 | public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity, |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 143 | SummaryLoader summaryLoader) { |
Jason Monk | 3069581 | 2015-11-17 09:01:08 -0500 | [diff] [blame] | 144 | return new SummaryProvider(activity, summaryLoader); |
| 145 | } |
| 146 | }; |
| 147 | |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame] | 148 | public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 149 | new BaseSearchIndexProvider() { |
| 150 | @Override |
| 151 | public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, |
| 152 | boolean enabled) { |
Fan Zhang | 99abc02 | 2016-10-11 14:23:13 -0700 | [diff] [blame] | 153 | final ArrayList<SearchIndexableResource> result = new ArrayList<>(); |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame] | 154 | |
Fan Zhang | 99abc02 | 2016-10-11 14:23:13 -0700 | [diff] [blame] | 155 | final SearchIndexableResource sir = new SearchIndexableResource(context); |
| 156 | final boolean useNewIA = FeatureFactory.getFactory(context) |
| 157 | .getDashboardFeatureProvider(context) |
| 158 | .isEnabled(); |
| 159 | if (useNewIA) { |
| 160 | sir.xmlResId = R.xml.ia_display_settings; |
| 161 | } else { |
| 162 | sir.xmlResId = R.xml.display_settings; |
| 163 | } |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame] | 164 | result.add(sir); |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame] | 165 | return result; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public List<String> getNonIndexableKeys(Context context) { |
Fan Zhang | 66b573a | 2016-10-06 16:33:13 -0700 | [diff] [blame] | 170 | ArrayList<String> result = new ArrayList<>(); |
| 171 | |
| 172 | new AutoBrightnessPreferenceController(context).updateNonIndexableKeys(result); |
| 173 | new AutoRotatePreferenceController(context).updateNonIndexableKeys(result); |
| 174 | new CameraGesturePreferenceController(context).updateNonIndexableKeys(result); |
| 175 | new DozePreferenceController(context).updateNonIndexableKeys(result); |
| 176 | new FontSizePreferenceController(context).updateNonIndexableKeys(result); |
| 177 | new LiftToWakePreferenceController(context).updateNonIndexableKeys(result); |
| 178 | new NightDisplayPreferenceController(context).updateNonIndexableKeys(result); |
| 179 | new NightModePreferenceController(context).updateNonIndexableKeys(result); |
| 180 | new ScreenSaverPreferenceController(context).updateNonIndexableKeys(result); |
| 181 | new TapToWakePreferenceController(context).updateNonIndexableKeys(result); |
| 182 | new TimeoutPreferenceController(context).updateNonIndexableKeys(result); |
| 183 | new VrDisplayPreferenceController(context).updateNonIndexableKeys(result); |
| 184 | new WallpaperPreferenceController(context).updateNonIndexableKeys(result); |
| 185 | |
Fabrice Di Meglio | d407f2a | 2014-06-09 10:13:43 -0700 | [diff] [blame] | 186 | return result; |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame] | 187 | } |
Matthew Fritze | 516b0f1 | 2017-01-26 14:37:48 -0800 | [diff] [blame^] | 188 | |
| 189 | @Override |
| 190 | public List<PreferenceController> getPreferenceControllers(Context context) { |
| 191 | final List<PreferenceController> controllers = new ArrayList<>(); |
| 192 | controllers.add(new AutoBrightnessPreferenceController(context)); |
| 193 | return controllers; |
| 194 | } |
Adrian Roos | 8ab0954 | 2014-06-02 20:33:56 +0200 | [diff] [blame] | 195 | }; |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 196 | } |