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 19 import android.content.Intent; 20 import android.provider.Settings; 21 import android.provider.Settings.Secure; 22 import android.widget.Switch; 23 24 import com.android.internal.logging.MetricsLogger; 25 import com.android.internal.logging.MetricsProto.MetricsEvent; 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 33 private final AnimationIcon mEnable 34 = new AnimationIcon(R.drawable.ic_invert_colors_enable_animation, 35 R.drawable.ic_invert_colors_disable); 36 private final AnimationIcon mDisable 37 = new AnimationIcon(R.drawable.ic_invert_colors_disable_animation, 38 R.drawable.ic_invert_colors_enable); 39 private final SecureSetting mSetting; 40 41 private boolean mListening; 42 43 public ColorInversionTile(Host host) { 44 super(host); 45 46 mSetting = new SecureSetting(mContext, mHandler, 47 Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED) { 48 @Override 49 protected void handleValueChanged(int value, boolean observedChange) { 50 handleRefreshState(value); 51 } 52 }; 53 } 54 55 @Override 56 protected void handleDestroy() { 57 super.handleDestroy(); 58 mSetting.setListening(false); 59 } 60 61 @Override 62 public BooleanState newTileState() { 63 return new BooleanState(); 64 } 65 66 @Override 67 public void setListening(boolean listening) { 68 mSetting.setListening(listening); 69 } 70 71 @Override 72 protected void handleUserSwitch(int newUserId) { 73 mSetting.setUserId(newUserId); 74 handleRefreshState(mSetting.getValue()); 75 } 76 77 @Override 78 public Intent getLongClickIntent() { 79 return new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); 80 } 81 82 @Override 83 protected void handleClick() { 84 MetricsLogger.action(mContext, getMetricsCategory(), !mState.value); 85 mSetting.setValue(mState.value ? 0 : 1); 86 } 87 88 @Override 89 public CharSequence getTileLabel() { 90 return mContext.getString(R.string.quick_settings_inversion_label); 91 } 92 93 @Override 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; 97 state.value = enabled; 98 state.label = mContext.getString(R.string.quick_settings_inversion_label); 99 state.icon = enabled ? mEnable : mDisable; 100 state.minimalAccessibilityClassName = state.expandedAccessibilityClassName 101 = Switch.class.getName(); 102 state.contentDescription = state.label; 103 } 104 105 @Override 106 public int getMetricsCategory() { 107 return MetricsEvent.QS_COLORINVERSION; 108 } 109 110 @Override 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 } 120 } 121