1af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock/* 2af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * Copyright (C) 2014 The Android Open Source Project 3af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * 4af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * Licensed under the Apache License, Version 2.0 (the "License"); 5af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * you may not use this file except in compliance with the License. 6af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * You may obtain a copy of the License at 7af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * 8af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * http://www.apache.org/licenses/LICENSE-2.0 9af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * 10af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * Unless required by applicable law or agreed to in writing, software 11af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * distributed under the License is distributed on an "AS IS" BASIS, 12af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * See the License for the specific language governing permissions and 14af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * limitations under the License. 15af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock */ 16af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 17af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockpackage com.android.systemui.qs.tiles; 18af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 1976c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monkimport android.content.Intent; 2076c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monkimport android.provider.Settings; 21af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockimport android.provider.Settings.Secure; 223250885c9feb9b42d60058a823c57a027c0dcf58Jason Monkimport android.service.quicksettings.Tile; 2320aef8a2914478a85aa679ec31bf739c7818eb3cJulia Reynoldsimport android.widget.Switch; 24f6e9228b8a97603d3ceb8f0d61e8d87cf19bd21fChris Wren 25457a21cdeac04565a0c40ad8c43a928c1182ddd1Chris Wrenimport com.android.internal.logging.MetricsLogger; 26383db5ebcc3a4a615faf249bf4f126f42e80b82eTamas Berghammerimport com.android.internal.logging.nano.MetricsProto.MetricsEvent; 27af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockimport com.android.systemui.R; 28395617fd35ef0e712945359a760a00eb1aaf7475Jason Monkimport com.android.systemui.R.drawable; 29702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monkimport com.android.systemui.qs.QSHost; 30702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monkimport com.android.systemui.plugins.qs.QSTile.BooleanState; 31702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monkimport com.android.systemui.qs.tileimpl.QSTileImpl; 32af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockimport com.android.systemui.qs.SecureSetting; 33af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 34af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock/** Quick settings tile: Invert colors **/ 35702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monkpublic class ColorInversionTile extends QSTileImpl<BooleanState> { 36af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 37bcdd0465c07114784122a1feb20239ae63a7db90Evan Laird private final Icon mIcon = ResourceIcon.get(drawable.ic_invert_colors); 38af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock private final SecureSetting mSetting; 39af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 40e1f653350eed6320a995c58ab5393fa4f2c17b46John Spurlock private boolean mListening; 41e1f653350eed6320a995c58ab5393fa4f2c17b46John Spurlock 42702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monk public ColorInversionTile(QSHost host) { 43af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock super(host); 44af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 45af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock mSetting = new SecureSetting(mContext, mHandler, 46af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED) { 47af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock @Override 4818764bf55158ca668d94364fd07feb168497a0c2John Spurlock protected void handleValueChanged(int value, boolean observedChange) { 49ba2318eff373a729f9768b146350a001dd22e4c5Jason Monk handleRefreshState(value); 50af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 51af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock }; 52bceed060f0090a4f86418c4515128d5ec8ebdd4aJohn Spurlock } 53bceed060f0090a4f86418c4515128d5ec8ebdd4aJohn Spurlock 54bceed060f0090a4f86418c4515128d5ec8ebdd4aJohn Spurlock @Override 55bceed060f0090a4f86418c4515128d5ec8ebdd4aJohn Spurlock protected void handleDestroy() { 56bceed060f0090a4f86418c4515128d5ec8ebdd4aJohn Spurlock super.handleDestroy(); 57e1f653350eed6320a995c58ab5393fa4f2c17b46John Spurlock mSetting.setListening(false); 58af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 59af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 60af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock @Override 6162b63a02d7ca630e3ad39991ea6550cab57e5d22Jason Monk public BooleanState newTileState() { 62af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock return new BooleanState(); 63af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 64af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 65af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock @Override 661c6116cbbb0c8000b576443e4b13026b1d8529d9Jason Monk public void handleSetListening(boolean listening) { 67ba2318eff373a729f9768b146350a001dd22e4c5Jason Monk mSetting.setListening(listening); 68af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 69af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 70af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock @Override 71af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock protected void handleUserSwitch(int newUserId) { 7232d88e8ead4ccf6b698cac343461cfe12ef168b8Adrian Roos mSetting.setUserId(newUserId); 7332d88e8ead4ccf6b698cac343461cfe12ef168b8Adrian Roos handleRefreshState(mSetting.getValue()); 74af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 75af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 76af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock @Override 7776c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk public Intent getLongClickIntent() { 7876c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk return new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); 7976c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk } 8076c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk 8176c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk @Override 82af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock protected void handleClick() { 83af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock mSetting.setValue(mState.value ? 0 : 1); 84af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 85af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 86af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock @Override 8739c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk public CharSequence getTileLabel() { 8839c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk return mContext.getString(R.string.quick_settings_inversion_label); 8939c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk } 9039c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk 9139c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk @Override 92af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock protected void handleUpdateState(BooleanState state, Object arg) { 93af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue(); 94af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock final boolean enabled = value != 0; 95395617fd35ef0e712945359a760a00eb1aaf7475Jason Monk if (state.slash == null) { 96395617fd35ef0e712945359a760a00eb1aaf7475Jason Monk state.slash = new SlashState(); 97395617fd35ef0e712945359a760a00eb1aaf7475Jason Monk } 98af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock state.value = enabled; 99395617fd35ef0e712945359a760a00eb1aaf7475Jason Monk state.slash.isSlashed = !state.value; 1003250885c9feb9b42d60058a823c57a027c0dcf58Jason Monk state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; 101af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock state.label = mContext.getString(R.string.quick_settings_inversion_label); 102395617fd35ef0e712945359a760a00eb1aaf7475Jason Monk state.icon = mIcon; 103702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monk state.expandedAccessibilityClassName = Switch.class.getName(); 10420aef8a2914478a85aa679ec31bf739c7818eb3cJulia Reynolds state.contentDescription = state.label; 105af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 1064fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek 1074fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek @Override 108457a21cdeac04565a0c40ad8c43a928c1182ddd1Chris Wren public int getMetricsCategory() { 109f6e9228b8a97603d3ceb8f0d61e8d87cf19bd21fChris Wren return MetricsEvent.QS_COLORINVERSION; 110457a21cdeac04565a0c40ad8c43a928c1182ddd1Chris Wren } 111457a21cdeac04565a0c40ad8c43a928c1182ddd1Chris Wren 112457a21cdeac04565a0c40ad8c43a928c1182ddd1Chris Wren @Override 1134fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek protected String composeChangeAnnouncement() { 1144fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek if (mState.value) { 1154fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek return mContext.getString( 1164fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek R.string.accessibility_quick_settings_color_inversion_changed_on); 1174fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek } else { 1184fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek return mContext.getString( 1194fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek R.string.accessibility_quick_settings_color_inversion_changed_off); 1204fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek } 1214fda7b2d97c77c64bac0b44dc7a44597ad2c48b0Selim Cinek } 122af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock} 123