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