blob: 42ce69c579786e8dc0eeec38f04caa3ac48fa813 [file] [log] [blame]
John Spurlockaf8d6c42014-05-07 17:49:08 -04001/*
2 * Copyright (C) 2014 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
17package com.android.systemui.qs.tiles;
18
Jason Monk76c67aa2016-02-19 14:49:42 -050019import android.content.Intent;
20import android.provider.Settings;
John Spurlockaf8d6c42014-05-07 17:49:08 -040021import android.provider.Settings.Secure;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050022
Chris Wren457a21c2015-05-06 17:50:34 -040023import com.android.internal.logging.MetricsLogger;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050024import com.android.internal.logging.MetricsProto.MetricsEvent;
John Spurlockaf8d6c42014-05-07 17:49:08 -040025import com.android.systemui.R;
26import com.android.systemui.qs.QSTile;
27import com.android.systemui.qs.SecureSetting;
28
29/** Quick settings tile: Invert colors **/
30public class ColorInversionTile extends QSTile<QSTile.BooleanState> {
31
John Spurlockc6df3cf2014-11-04 19:36:44 -050032 private final AnimationIcon mEnable
33 = new AnimationIcon(R.drawable.ic_invert_colors_enable_animation);
34 private final AnimationIcon mDisable
35 = new AnimationIcon(R.drawable.ic_invert_colors_disable_animation);
John Spurlockaf8d6c42014-05-07 17:49:08 -040036 private final SecureSetting mSetting;
John Spurlockaf8d6c42014-05-07 17:49:08 -040037
John Spurlocke1f65332014-08-18 15:37:59 -040038 private boolean mListening;
39
John Spurlockaf8d6c42014-05-07 17:49:08 -040040 public ColorInversionTile(Host host) {
41 super(host);
42
43 mSetting = new SecureSetting(mContext, mHandler,
44 Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED) {
45 @Override
John Spurlock18764bf2014-11-19 20:33:40 -050046 protected void handleValueChanged(int value, boolean observedChange) {
Jason Monkba2318e2015-12-08 09:04:23 -050047 handleRefreshState(value);
John Spurlockaf8d6c42014-05-07 17:49:08 -040048 }
49 };
John Spurlockbceed062014-08-10 18:04:16 -040050 }
51
52 @Override
53 protected void handleDestroy() {
54 super.handleDestroy();
John Spurlocke1f65332014-08-18 15:37:59 -040055 mSetting.setListening(false);
John Spurlockaf8d6c42014-05-07 17:49:08 -040056 }
57
58 @Override
Jason Monk62b63a02016-02-02 15:15:31 -050059 public BooleanState newTileState() {
John Spurlockaf8d6c42014-05-07 17:49:08 -040060 return new BooleanState();
61 }
62
63 @Override
John Spurlockccb6b9a2014-05-17 15:54:40 -040064 public void setListening(boolean listening) {
Jason Monkba2318e2015-12-08 09:04:23 -050065 mSetting.setListening(listening);
John Spurlockaf8d6c42014-05-07 17:49:08 -040066 }
67
68 @Override
69 protected void handleUserSwitch(int newUserId) {
Adrian Roos32d88e82014-09-24 17:08:22 +020070 mSetting.setUserId(newUserId);
71 handleRefreshState(mSetting.getValue());
John Spurlockaf8d6c42014-05-07 17:49:08 -040072 }
73
74 @Override
Jason Monk76c67aa2016-02-19 14:49:42 -050075 public Intent getLongClickIntent() {
76 return new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
77 }
78
79 @Override
John Spurlockaf8d6c42014-05-07 17:49:08 -040080 protected void handleClick() {
Chris Wren9e7283f2015-05-08 17:23:47 -040081 MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
John Spurlockaf8d6c42014-05-07 17:49:08 -040082 mSetting.setValue(mState.value ? 0 : 1);
83 }
84
85 @Override
86 protected void handleUpdateState(BooleanState state, Object arg) {
87 final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue();
88 final boolean enabled = value != 0;
John Spurlockaf8d6c42014-05-07 17:49:08 -040089 state.value = enabled;
90 state.label = mContext.getString(R.string.quick_settings_inversion_label);
John Spurlockc6df3cf2014-11-04 19:36:44 -050091 state.icon = enabled ? mEnable : mDisable;
John Spurlockaf8d6c42014-05-07 17:49:08 -040092 }
Selim Cinek4fda7b22014-08-18 22:07:25 +020093
94 @Override
Chris Wren457a21c2015-05-06 17:50:34 -040095 public int getMetricsCategory() {
Chris Wrenf6e9228b2016-01-26 18:04:35 -050096 return MetricsEvent.QS_COLORINVERSION;
Chris Wren457a21c2015-05-06 17:50:34 -040097 }
98
99 @Override
Selim Cinek4fda7b22014-08-18 22:07:25 +0200100 protected String composeChangeAnnouncement() {
101 if (mState.value) {
102 return mContext.getString(
103 R.string.accessibility_quick_settings_color_inversion_changed_on);
104 } else {
105 return mContext.getString(
106 R.string.accessibility_quick_settings_color_inversion_changed_off);
107 }
108 }
John Spurlockaf8d6c42014-05-07 17:49:08 -0400109}