• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.hardware.display.ColorDisplayManager;
21 import android.text.TextUtils;
22 
23 import com.android.settings.R;
24 import com.android.settings.core.TogglePreferenceController;
25 import com.android.settings.overlay.FeatureFactory;
26 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
27 
28 /**
29  * Controller that updates the night display.
30  */
31 public class NightDisplayActivationPreferenceController extends TogglePreferenceController {
32 
33     private final MetricsFeatureProvider mMetricsFeatureProvider;
34     private ColorDisplayManager mColorDisplayManager;
35     private NightDisplayTimeFormatter mTimeFormatter;
36 
NightDisplayActivationPreferenceController(Context context, String key)37     public NightDisplayActivationPreferenceController(Context context, String key) {
38         super(context, key);
39 
40         mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
41         mTimeFormatter = new NightDisplayTimeFormatter(context);
42         mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
43     }
44 
45     @Override
getAvailabilityStatus()46     public int getAvailabilityStatus() {
47         return ColorDisplayManager.isNightDisplayAvailable(mContext) ? AVAILABLE_UNSEARCHABLE
48                 : UNSUPPORTED_ON_DEVICE;
49     }
50 
51     @Override
isSliceable()52     public boolean isSliceable() {
53         return TextUtils.equals(getPreferenceKey(), "night_display_activated");
54     }
55 
56     @Override
isPublicSlice()57     public boolean isPublicSlice() {
58         return true;
59     }
60 
61     @Override
getSliceHighlightMenuRes()62     public int getSliceHighlightMenuRes() {
63         return R.string.menu_key_display;
64     }
65 
66     /** FOR SLICES */
67 
68     @Override
isChecked()69     public boolean isChecked() {
70         return mColorDisplayManager.isNightDisplayActivated();
71     }
72 
73     @Override
setChecked(boolean isChecked)74     public boolean setChecked(boolean isChecked) {
75         return mColorDisplayManager.setNightDisplayActivated(isChecked);
76     }
77 
78     @Override
getSummary()79     public CharSequence getSummary() {
80         return mTimeFormatter.getAutoModeSummary(mContext, mColorDisplayManager);
81     }
82 
83 }
84