• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.settings.display;
16 
17 import android.content.Context;
18 import android.support.v14.preference.SwitchPreference;
19 import android.util.AttributeSet;
20 
21 import com.android.internal.app.ColorDisplayController;
22 
23 import java.time.LocalTime;
24 
25 public class NightDisplayPreference extends SwitchPreference
26         implements ColorDisplayController.Callback {
27 
28     private ColorDisplayController mController;
29     private NightDisplayTimeFormatter mTimeFormatter;
30 
NightDisplayPreference(Context context, AttributeSet attrs)31     public NightDisplayPreference(Context context, AttributeSet attrs) {
32         super(context, attrs);
33 
34         mController = new ColorDisplayController(context);
35         mTimeFormatter = new NightDisplayTimeFormatter(context);
36     }
37 
38     @Override
onAttached()39     public void onAttached() {
40         super.onAttached();
41 
42         // Listen for changes only while attached.
43         mController.setListener(this);
44 
45         // Update the summary since the state may have changed while not attached.
46         updateSummary();
47     }
48 
49     @Override
onDetached()50     public void onDetached() {
51         super.onDetached();
52 
53         // Stop listening for state changes.
54         mController.setListener(null);
55     }
56 
57     @Override
onActivated(boolean activated)58     public void onActivated(boolean activated) {
59         updateSummary();
60     }
61 
62     @Override
onAutoModeChanged(int autoMode)63     public void onAutoModeChanged(int autoMode) {
64         updateSummary();
65     }
66 
67     @Override
onCustomStartTimeChanged(LocalTime startTime)68     public void onCustomStartTimeChanged(LocalTime startTime) {
69         updateSummary();
70     }
71 
72     @Override
onCustomEndTimeChanged(LocalTime endTime)73     public void onCustomEndTimeChanged(LocalTime endTime) {
74         updateSummary();
75     }
76 
updateSummary()77     private void updateSummary() {
78         setSummary(mTimeFormatter.getAutoModeTimeSummary(getContext(), mController));
79     }
80 }
81