11205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu/* 21205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * Copyright (C) 2015 The Android Open Source Project 31205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * 41205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * Licensed under the Apache License, Version 2.0 (the "License"); 51205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * you may not use this file except in compliance with the License. 61205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * You may obtain a copy of the License at 71205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * 81205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * http://www.apache.org/licenses/LICENSE-2.0 91205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * 101205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * Unless required by applicable law or agreed to in writing, software 111205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * distributed under the License is distributed on an "AS IS" BASIS, 121205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * See the License for the specific language governing permissions and 141205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu * limitations under the License. 151205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu */ 161205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 171205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xupackage com.android.systemui.qs.tiles; 181205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 1976c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monkimport android.content.Intent; 2076c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monkimport android.provider.Settings; 213250885c9feb9b42d60058a823c57a027c0dcf58Jason Monkimport android.service.quicksettings.Tile; 2220aef8a2914478a85aa679ec31bf739c7818eb3cJulia Reynoldsimport android.widget.Switch; 2320aef8a2914478a85aa679ec31bf739c7818eb3cJulia Reynolds 241205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xuimport com.android.internal.logging.MetricsLogger; 25383db5ebcc3a4a615faf249bf4f126f42e80b82eTamas Berghammerimport com.android.internal.logging.nano.MetricsProto.MetricsEvent; 269c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monkimport com.android.systemui.Dependency; 271205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xuimport com.android.systemui.R; 28702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monkimport com.android.systemui.qs.QSHost; 29702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monkimport com.android.systemui.plugins.qs.QSTile.BooleanState; 30702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monkimport com.android.systemui.qs.tileimpl.QSTileImpl; 31c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monkimport com.android.systemui.statusbar.phone.ManagedProfileController; 321205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 331205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu/** Quick settings tile: Work profile on/off */ 34702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monkpublic class WorkModeTile extends QSTileImpl<BooleanState> implements 35c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk ManagedProfileController.Callback { 361205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu private final AnimationIcon mEnable = 371aec93f1819369bda9e6cb0bd282419808c304c3Jason Monk new AnimationIcon(R.drawable.ic_signal_workmode_enable_animation, 381aec93f1819369bda9e6cb0bd282419808c304c3Jason Monk R.drawable.ic_signal_workmode_disable); 391205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu private final AnimationIcon mDisable = 401aec93f1819369bda9e6cb0bd282419808c304c3Jason Monk new AnimationIcon(R.drawable.ic_signal_workmode_disable_animation, 411aec93f1819369bda9e6cb0bd282419808c304c3Jason Monk R.drawable.ic_signal_workmode_enable); 421205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 43c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk private final ManagedProfileController mProfileController; 441205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 45702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monk public WorkModeTile(QSHost host) { 461205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu super(host); 479c7844cb91b43929d0a86b1c90aa1efb37f5463aJason Monk mProfileController = Dependency.get(ManagedProfileController.class); 481205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 491205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 501205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu @Override 5162b63a02d7ca630e3ad39991ea6550cab57e5d22Jason Monk public BooleanState newTileState() { 521205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu return new BooleanState(); 531205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 541205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 551205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu @Override 56c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk public void setListening(boolean listening) { 57c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk if (listening) { 58c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk mProfileController.addCallback(this); 59c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk } else { 60c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk mProfileController.removeCallback(this); 61c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk } 621205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 631205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 64c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk @Override 6576c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk public Intent getLongClickIntent() { 6638bb832e7d1238d85760de75efa17e8bc2e2ccecRicky Wai return new Intent(Settings.ACTION_MANAGED_PROFILE_SETTINGS); 6776c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk } 6876c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk 6976c67aa361f65dfb2f5e03d06cc1ccebce9cecd9Jason Monk @Override 70c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk public void handleClick() { 71c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk mProfileController.setWorkModeEnabled(!mState.value); 721205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 731205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 74c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk @Override 75c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk public boolean isAvailable() { 76c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk return mProfileController.hasActiveProfile(); 771205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 781205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 79c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk @Override 80c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk public void onManagedProfileChanged() { 81c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk refreshState(mProfileController.isWorkModeEnabled()); 821205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 831205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 84c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk @Override 85c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk public void onManagedProfileRemoved() { 86c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk mHost.removeTile(getTileSpec()); 871205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 881205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 891205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu @Override 9039c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk public CharSequence getTileLabel() { 9139c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk return mContext.getString(R.string.quick_settings_work_mode_label); 9239c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk } 9339c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk 9439c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk @Override 951205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu protected void handleUpdateState(BooleanState state, Object arg) { 9666239fbdfce1586555b339854b8a21f8187e805fJason Monk if (arg instanceof Boolean) { 9766239fbdfce1586555b339854b8a21f8187e805fJason Monk state.value = (Boolean) arg; 981205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } else { 99c3f42c102422f70f5bbe67105e16515ce9c306a3Jason Monk state.value = mProfileController.isWorkModeEnabled(); 1001205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 1011205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 1021205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu state.label = mContext.getString(R.string.quick_settings_work_mode_label); 1031205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu if (state.value) { 10466239fbdfce1586555b339854b8a21f8187e805fJason Monk state.icon = mEnable; 1051205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu state.contentDescription = mContext.getString( 1061205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu R.string.accessibility_quick_settings_work_mode_on); 1071205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } else { 10866239fbdfce1586555b339854b8a21f8187e805fJason Monk state.icon = mDisable; 1091205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu state.contentDescription = mContext.getString( 1101205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu R.string.accessibility_quick_settings_work_mode_off); 1111205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 112702e2ebf9fbfb715c1d9b716683c9e4d182b575eJason Monk state.expandedAccessibilityClassName = Switch.class.getName(); 1133250885c9feb9b42d60058a823c57a027c0dcf58Jason Monk state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; 1141205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 1151205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 1161205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu @Override 1171205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu public int getMetricsCategory() { 118f6e9228b8a97603d3ceb8f0d61e8d87cf19bd21fChris Wren return MetricsEvent.QS_WORKMODE; 1191205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 1201205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu 1211205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu @Override 1221205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu protected String composeChangeAnnouncement() { 1231205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu if (mState.value) { 1241205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_on); 1251205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } else { 1261205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_off); 1271205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 1281205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu } 1291205fb1d92f51b5f36e5ba126c3942381f564821Rubin Xu} 130