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