Home | History | Annotate | Download | only in display
      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.dashboard.DashboardFragment;
     27 import com.android.settings.gestures.DoubleTapScreenPreferenceController;
     28 import com.android.settings.gestures.PickupGesturePreferenceController;
     29 import com.android.settings.overlay.FeatureFactory;
     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.instrumentation.MetricsFeatureProvider;
     34 import com.android.settingslib.core.lifecycle.Lifecycle;
     35 
     36 import java.util.ArrayList;
     37 import java.util.List;
     38 
     39 /**
     40  * Settings screen for Ambient display.
     41  */
     42 public class AmbientDisplaySettings extends DashboardFragment {
     43 
     44     public static final String KEY_AMBIENT_DISPLAY_ALWAYS_ON = "ambient_display_always_on";
     45 
     46     private static final String TAG = "AmbientDisplaySettings";
     47 
     48     private AmbientDisplayConfiguration mConfig;
     49 
     50     @Override
     51     public void onAttach(Context context) {
     52         super.onAttach(context);
     53         use(AmbientDisplayAlwaysOnPreferenceController.class)
     54             .setConfig(getConfig(context))
     55             .setCallback(this::updatePreferenceStates);
     56         use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context));
     57         use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
     58         use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
     59     }
     60 
     61     @Override
     62     protected String getLogTag() {
     63         return TAG;
     64     }
     65 
     66     @Override
     67     protected int getPreferenceScreenResId() {
     68         return R.xml.ambient_display_settings;
     69     }
     70 
     71     @Override
     72     public int getMetricsCategory() {
     73         return MetricsProto.MetricsEvent.AMBIENT_DISPLAY_SETTINGS;
     74     }
     75 
     76     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
     77             new BaseSearchIndexProvider() {
     78                 @Override
     79                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
     80                         boolean enabled) {
     81                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
     82 
     83                     final SearchIndexableResource sir = new SearchIndexableResource(context);
     84                     sir.xmlResId = R.xml.ambient_display_settings;
     85                     result.add(sir);
     86                     return result;
     87                 }
     88             };
     89 
     90     private AmbientDisplayConfiguration getConfig(Context context) {
     91         if (mConfig == null) {
     92             mConfig = new AmbientDisplayConfiguration(context);
     93         }
     94         return mConfig;
     95     }
     96 }
     97