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