WorkModeTile.java revision 39c98e652fd3e0e3ea3a334d60ba6ee979985978
1/* 2 * Copyright (C) 2015 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 19import android.content.Intent; 20import android.provider.Settings; 21import com.android.internal.logging.MetricsLogger; 22import com.android.internal.logging.MetricsProto.MetricsEvent; 23import com.android.systemui.R; 24import com.android.systemui.qs.QSTile; 25import com.android.systemui.statusbar.phone.ManagedProfileController; 26 27/** Quick settings tile: Work profile on/off */ 28public class WorkModeTile extends QSTile<QSTile.BooleanState> implements 29 ManagedProfileController.Callback { 30 private final AnimationIcon mEnable = 31 new AnimationIcon(R.drawable.ic_signal_workmode_enable_animation, 32 R.drawable.ic_signal_workmode_disable); 33 private final AnimationIcon mDisable = 34 new AnimationIcon(R.drawable.ic_signal_workmode_disable_animation, 35 R.drawable.ic_signal_workmode_enable); 36 37 private final ManagedProfileController mProfileController; 38 39 public WorkModeTile(Host host) { 40 super(host); 41 mProfileController = host.getManagedProfileController(); 42 } 43 44 @Override 45 public BooleanState newTileState() { 46 return new BooleanState(); 47 } 48 49 @Override 50 public void setListening(boolean listening) { 51 if (listening) { 52 mProfileController.addCallback(this); 53 } else { 54 mProfileController.removeCallback(this); 55 } 56 } 57 58 @Override 59 public Intent getLongClickIntent() { 60 return new Intent(Settings.ACTION_SYNC_SETTINGS); 61 } 62 63 @Override 64 public void handleClick() { 65 MetricsLogger.action(mContext, getMetricsCategory(), !mState.value); 66 mProfileController.setWorkModeEnabled(!mState.value); 67 } 68 69 @Override 70 public boolean isAvailable() { 71 return mProfileController.hasActiveProfile(); 72 } 73 74 @Override 75 public void onManagedProfileChanged() { 76 refreshState(mProfileController.isWorkModeEnabled()); 77 } 78 79 @Override 80 public void onManagedProfileRemoved() { 81 mHost.removeTile(getTileSpec()); 82 } 83 84 @Override 85 public CharSequence getTileLabel() { 86 return mContext.getString(R.string.quick_settings_work_mode_label); 87 } 88 89 @Override 90 protected void handleUpdateState(BooleanState state, Object arg) { 91 if (arg instanceof Boolean) { 92 state.value = (Boolean) arg; 93 } else { 94 state.value = mProfileController.isWorkModeEnabled(); 95 } 96 97 state.label = mContext.getString(R.string.quick_settings_work_mode_label); 98 if (state.value) { 99 state.icon = mEnable; 100 state.contentDescription = mContext.getString( 101 R.string.accessibility_quick_settings_work_mode_on); 102 } else { 103 state.icon = mDisable; 104 state.contentDescription = mContext.getString( 105 R.string.accessibility_quick_settings_work_mode_off); 106 } 107 } 108 109 @Override 110 public int getMetricsCategory() { 111 return MetricsEvent.QS_WORKMODE; 112 } 113 114 @Override 115 protected String composeChangeAnnouncement() { 116 if (mState.value) { 117 return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_on); 118 } else { 119 return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_off); 120 } 121 } 122} 123