blob: 26e1d46dd119d28bdf933db26e31e45f120d5fc4 [file] [log] [blame]
Jason Monk5dbd4aa2016-02-07 13:13:39 -05001/**
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 */
16package com.android.systemui.tuner;
17
18import android.app.ActivityManager;
Jason Monk76c67aa2016-02-19 14:49:42 -050019import android.content.Intent;
Jason Monk5dbd4aa2016-02-07 13:13:39 -050020import android.provider.Settings;
21
22import com.android.internal.logging.MetricsProto.MetricsEvent;
Jason Monk1b0afeb2016-03-03 18:25:54 -050023import com.android.systemui.Prefs;
24import com.android.systemui.Prefs.Key;
Jason Monk5dbd4aa2016-02-07 13:13:39 -050025import com.android.systemui.R;
26import com.android.systemui.qs.QSTile;
27import com.android.systemui.statusbar.policy.NightModeController;
28
29import java.util.Objects;
30
31
32public class NightModeTile extends QSTile<QSTile.State> implements NightModeController.Listener {
33
34 public static final String NIGHT_MODE_SPEC = "night";
35
36 private final NightModeController mNightModeController;
37
38 private int mIndex;
39 private String mCurrentValue;
40
41 private boolean mCustomEnabled;
42 private String[] mValues;
43 private CharSequence[] mValueTitles;
44
45 public NightModeTile(Host host) {
46 super(host);
47 mNightModeController = host.getNightModeController();
48 }
49
50 @Override
Jason Monk1b0afeb2016-03-03 18:25:54 -050051 public boolean isAvailable() {
52 return Prefs.getBoolean(mContext, Key.QS_NIGHT_ADDED, false)
53 && TunerService.isTunerEnabled(mContext);
54 }
55
56 @Override
Jason Monk5dbd4aa2016-02-07 13:13:39 -050057 public void setListening(boolean listening) {
58 if (listening) {
59 mNightModeController.addListener(this);
60 refreshState();
61 } else {
62 mNightModeController.removeListener(this);
63 }
64 }
65
66 @Override
67 public State newTileState() {
68 return new State();
69 }
70
71 @Override
Jason Monk76c67aa2016-02-19 14:49:42 -050072 public Intent getLongClickIntent() {
73 return new Intent(mContext, TunerActivity.class)
74 .putExtra(NightModeFragment.EXTRA_SHOW_NIGHT_MODE, true);
75 }
76
77 @Override
Jason Monk5dbd4aa2016-02-07 13:13:39 -050078 protected void handleClick() {
79 mNightModeController.setNightMode(!mNightModeController.isEnabled());
80 refreshState();
81 }
82
83 @Override
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
94 public void onNightModeChanged() {
95 refreshState();
96 }
97
98 @Override
99 public void onTwilightAutoChanged() {
100 // Don't care.
101 }
102
103 @Override
104 public int getMetricsCategory() {
105 return MetricsEvent.QS_COLOR_MATRIX;
106 }
107}