1 /* 2 * Copyright (C) 2017 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.display; 18 19 import android.content.Context; 20 import android.os.UserHandle; 21 import android.provider.SearchIndexableResource; 22 23 import com.android.internal.hardware.AmbientDisplayConfiguration; 24 import com.android.internal.logging.nano.MetricsProto; 25 import com.android.settings.R; 26 import com.android.settings.core.instrumentation.MetricsFeatureProvider; 27 import com.android.settings.dashboard.DashboardFragment; 28 import com.android.settings.gestures.DoubleTapScreenPreferenceController; 29 import com.android.settings.gestures.PickupGesturePreferenceController; 30 import com.android.settings.search.BaseSearchIndexProvider; 31 import com.android.settings.search.Indexable; 32 import com.android.settingslib.core.AbstractPreferenceController; 33 import com.android.settingslib.core.lifecycle.Lifecycle; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 38 /** 39 * Settings screen for Ambient display. 40 */ 41 public class AmbientDisplaySettings extends DashboardFragment { 42 43 private static final String TAG = "AmbientDisplaySettings"; 44 private static final int MY_USER_ID = UserHandle.myUserId(); 45 46 private static final String KEY_AMBIENT_DISPLAY_ALWAYS_ON = "ambient_display_always_on"; 47 private static final String KEY_AMBIENT_DISPLAY_DOUBLE_TAP = "ambient_display_double_tap"; 48 private static final String KEY_AMBIENT_DISPLAY_PICK_UP = "ambient_display_pick_up"; 49 private static final String KEY_AMBIENT_DISPLAY_NOTIFICATION = "ambient_display_notification"; 50 buildPreferenceControllers(Context context, Lifecycle lifecycle, AmbientDisplayConfiguration config, MetricsFeatureProvider metricsFeatureProvider, AmbientDisplayAlwaysOnPreferenceController.OnPreferenceChangedCallback aodCallback)51 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 52 Lifecycle lifecycle, AmbientDisplayConfiguration config, 53 MetricsFeatureProvider metricsFeatureProvider, 54 AmbientDisplayAlwaysOnPreferenceController.OnPreferenceChangedCallback aodCallback) { 55 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 56 controllers.add(new AmbientDisplayNotificationsPreferenceController(context, config, 57 metricsFeatureProvider)); 58 controllers.add(new AmbientDisplayAlwaysOnPreferenceController(context, config, 59 aodCallback)); 60 controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle, config, 61 MY_USER_ID, KEY_AMBIENT_DISPLAY_DOUBLE_TAP)); 62 controllers.add(new PickupGesturePreferenceController(context, lifecycle, config, 63 MY_USER_ID, KEY_AMBIENT_DISPLAY_PICK_UP)); 64 return controllers; 65 } 66 67 68 @Override getLogTag()69 protected String getLogTag() { 70 return TAG; 71 } 72 73 @Override getPreferenceScreenResId()74 protected int getPreferenceScreenResId() { 75 return R.xml.ambient_display_settings; 76 } 77 78 @Override getPreferenceControllers(Context context)79 protected List<AbstractPreferenceController> getPreferenceControllers(Context context) { 80 return buildPreferenceControllers(context, getLifecycle(), 81 new AmbientDisplayConfiguration(context), mMetricsFeatureProvider, 82 () -> { updatePreferenceStates(); }); 83 } 84 85 @Override getMetricsCategory()86 public int getMetricsCategory() { 87 return MetricsProto.MetricsEvent.AMBIENT_DISPLAY_SETTINGS; 88 } 89 90 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 91 new BaseSearchIndexProvider() { 92 @Override 93 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 94 boolean enabled) { 95 final ArrayList<SearchIndexableResource> result = new ArrayList<>(); 96 97 final SearchIndexableResource sir = new SearchIndexableResource(context); 98 sir.xmlResId = R.xml.ambient_display_settings; 99 result.add(sir); 100 return result; 101 } 102 103 @Override 104 public List<AbstractPreferenceController> getPreferenceControllers(Context context) { 105 return buildPreferenceControllers(context, null, 106 new AmbientDisplayConfiguration(context), null, null); 107 } 108 }; 109 } 110