• 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");
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 package com.android.systemui.tuner;
17 
18 import android.content.Intent;
19 import com.android.internal.logging.MetricsProto.MetricsEvent;
20 import com.android.systemui.Prefs;
21 import com.android.systemui.Prefs.Key;
22 import com.android.systemui.R;
23 import com.android.systemui.qs.QSTile;
24 import com.android.systemui.statusbar.policy.NightModeController;
25 
26 
27 public class NightModeTile extends QSTile<QSTile.State> implements NightModeController.Listener {
28 
29     public static final String NIGHT_MODE_SPEC = "night";
30 
31     private final NightModeController mNightModeController;
32 
33     private int mIndex;
34     private String mCurrentValue;
35 
36     private boolean mCustomEnabled;
37     private String[] mValues;
38     private CharSequence[] mValueTitles;
39 
NightModeTile(Host host)40     public NightModeTile(Host host) {
41         super(host);
42         mNightModeController = host.getNightModeController();
43     }
44 
45     @Override
isAvailable()46     public boolean isAvailable() {
47         return Prefs.getBoolean(mContext, Key.QS_NIGHT_ADDED, false)
48                 && TunerService.isTunerEnabled(mContext);
49     }
50 
51     @Override
setListening(boolean listening)52     public void setListening(boolean listening) {
53         if (listening) {
54             mNightModeController.addListener(this);
55             refreshState();
56         } else {
57             mNightModeController.removeListener(this);
58         }
59     }
60 
61     @Override
newTileState()62     public State newTileState() {
63         return new State();
64     }
65 
66     @Override
getLongClickIntent()67     public Intent getLongClickIntent() {
68         return new Intent(mContext, TunerActivity.class)
69                 .putExtra(NightModeFragment.EXTRA_SHOW_NIGHT_MODE, true);
70     }
71 
72     @Override
handleClick()73     protected void handleClick() {
74         mNightModeController.setNightMode(!mNightModeController.isEnabled());
75         refreshState();
76     }
77 
78     @Override
getTileLabel()79     public CharSequence getTileLabel() {
80         return mContext.getString(R.string.night_mode);
81     }
82 
83     @Override
handleUpdateState(State state, Object arg)84     protected void handleUpdateState(State state, Object arg) {
85         // TODO: Right now this is just a dropper, needs an actual night icon.
86         boolean enabled = mNightModeController.isEnabled();
87         state.icon = ResourceIcon.get(enabled ? R.drawable.ic_night_mode
88                 : R.drawable.ic_night_mode_disabled);
89         state.label = mContext.getString(R.string.night_mode);
90         state.contentDescription = mContext.getString(R.string.night_mode);
91     }
92 
93     @Override
onNightModeChanged()94     public void onNightModeChanged() {
95         refreshState();
96     }
97 
98     @Override
onTwilightAutoChanged()99     public void onTwilightAutoChanged() {
100         // Don't care.
101     }
102 
103     @Override
getMetricsCategory()104     public int getMetricsCategory() {
105         return MetricsEvent.QS_COLOR_MATRIX;
106     }
107 }
108