Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 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.app.ActivityManager; |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 19 | import android.content.Intent; |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 20 | import android.provider.Settings; |
| 21 | |
| 22 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Jason Monk | 1b0afeb | 2016-03-03 18:25:54 -0500 | [diff] [blame] | 23 | import com.android.systemui.Prefs; |
| 24 | import com.android.systemui.Prefs.Key; |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 25 | import com.android.systemui.R; |
| 26 | import com.android.systemui.qs.QSTile; |
| 27 | import com.android.systemui.statusbar.policy.NightModeController; |
| 28 | |
| 29 | import java.util.Objects; |
| 30 | |
| 31 | |
| 32 | public 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 Monk | 1b0afeb | 2016-03-03 18:25:54 -0500 | [diff] [blame] | 51 | public boolean isAvailable() { |
| 52 | return Prefs.getBoolean(mContext, Key.QS_NIGHT_ADDED, false) |
| 53 | && TunerService.isTunerEnabled(mContext); |
| 54 | } |
| 55 | |
| 56 | @Override |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 57 | 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 Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 72 | public Intent getLongClickIntent() { |
| 73 | return new Intent(mContext, TunerActivity.class) |
| 74 | .putExtra(NightModeFragment.EXTRA_SHOW_NIGHT_MODE, true); |
| 75 | } |
| 76 | |
| 77 | @Override |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 78 | 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 | } |