John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.qs.tiles; |
| 18 | |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 19 | import android.content.Intent; |
| 20 | import android.provider.Settings; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 21 | import android.provider.Settings.Secure; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 22 | import android.widget.Switch; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 23 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 24 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | cbd3f0c | 2016-06-22 15:21:38 +0100 | [diff] [blame^] | 25 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 26 | import com.android.systemui.R; |
| 27 | import com.android.systemui.qs.QSTile; |
| 28 | import com.android.systemui.qs.SecureSetting; |
| 29 | |
| 30 | /** Quick settings tile: Invert colors **/ |
| 31 | public class ColorInversionTile extends QSTile<QSTile.BooleanState> { |
| 32 | |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 33 | private final AnimationIcon mEnable |
Jason Monk | 1aec93f | 2016-03-01 09:39:30 -0500 | [diff] [blame] | 34 | = new AnimationIcon(R.drawable.ic_invert_colors_enable_animation, |
| 35 | R.drawable.ic_invert_colors_disable); |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 36 | private final AnimationIcon mDisable |
Jason Monk | 1aec93f | 2016-03-01 09:39:30 -0500 | [diff] [blame] | 37 | = new AnimationIcon(R.drawable.ic_invert_colors_disable_animation, |
| 38 | R.drawable.ic_invert_colors_enable); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 39 | private final SecureSetting mSetting; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 40 | |
John Spurlock | e1f6533 | 2014-08-18 15:37:59 -0400 | [diff] [blame] | 41 | private boolean mListening; |
| 42 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 43 | public ColorInversionTile(Host host) { |
| 44 | super(host); |
| 45 | |
| 46 | mSetting = new SecureSetting(mContext, mHandler, |
| 47 | Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED) { |
| 48 | @Override |
John Spurlock | 18764bf | 2014-11-19 20:33:40 -0500 | [diff] [blame] | 49 | protected void handleValueChanged(int value, boolean observedChange) { |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 50 | handleRefreshState(value); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 51 | } |
| 52 | }; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected void handleDestroy() { |
| 57 | super.handleDestroy(); |
John Spurlock | e1f6533 | 2014-08-18 15:37:59 -0400 | [diff] [blame] | 58 | mSetting.setListening(false); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 62 | public BooleanState newTileState() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 63 | return new BooleanState(); |
| 64 | } |
| 65 | |
| 66 | @Override |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 67 | public void setListening(boolean listening) { |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 68 | mSetting.setListening(listening); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | protected void handleUserSwitch(int newUserId) { |
Adrian Roos | 32d88e8 | 2014-09-24 17:08:22 +0200 | [diff] [blame] | 73 | mSetting.setUserId(newUserId); |
| 74 | handleRefreshState(mSetting.getValue()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 78 | public Intent getLongClickIntent() { |
| 79 | return new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); |
| 80 | } |
| 81 | |
| 82 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 83 | protected void handleClick() { |
Chris Wren | 9e7283f | 2015-05-08 17:23:47 -0400 | [diff] [blame] | 84 | MetricsLogger.action(mContext, getMetricsCategory(), !mState.value); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 85 | mSetting.setValue(mState.value ? 0 : 1); |
| 86 | } |
| 87 | |
| 88 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 89 | public CharSequence getTileLabel() { |
| 90 | return mContext.getString(R.string.quick_settings_inversion_label); |
| 91 | } |
| 92 | |
| 93 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 94 | protected void handleUpdateState(BooleanState state, Object arg) { |
| 95 | final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue(); |
| 96 | final boolean enabled = value != 0; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 97 | state.value = enabled; |
| 98 | state.label = mContext.getString(R.string.quick_settings_inversion_label); |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 99 | state.icon = enabled ? mEnable : mDisable; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 100 | state.minimalAccessibilityClassName = state.expandedAccessibilityClassName |
| 101 | = Switch.class.getName(); |
| 102 | state.contentDescription = state.label; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 103 | } |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 104 | |
| 105 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 106 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 107 | return MetricsEvent.QS_COLORINVERSION; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Override |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 111 | protected String composeChangeAnnouncement() { |
| 112 | if (mState.value) { |
| 113 | return mContext.getString( |
| 114 | R.string.accessibility_quick_settings_color_inversion_changed_on); |
| 115 | } else { |
| 116 | return mContext.getString( |
| 117 | R.string.accessibility_quick_settings_color_inversion_changed_off); |
| 118 | } |
| 119 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 120 | } |