blob: 421a2cf9cc51d8e4135ede56856e143c8b684e89 [file] [log] [blame]
Rubin Xu1205fb12015-11-04 17:45:03 +00001/*
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
Jason Monk76c67aa2016-02-19 14:49:42 -050019import android.content.Intent;
20import android.provider.Settings;
Rubin Xu1205fb12015-11-04 17:45:03 +000021import com.android.internal.logging.MetricsLogger;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050022import com.android.internal.logging.MetricsProto.MetricsEvent;
Rubin Xu1205fb12015-11-04 17:45:03 +000023import com.android.systemui.R;
24import com.android.systemui.qs.QSTile;
Jason Monkc3f42c12016-02-05 12:33:13 -050025import com.android.systemui.statusbar.phone.ManagedProfileController;
Rubin Xu1205fb12015-11-04 17:45:03 +000026
27/** Quick settings tile: Work profile on/off */
Jason Monkc3f42c12016-02-05 12:33:13 -050028public class WorkModeTile extends QSTile<QSTile.BooleanState> implements
29 ManagedProfileController.Callback {
Rubin Xu1205fb12015-11-04 17:45:03 +000030 private final AnimationIcon mEnable =
Jason Monk1aec93f2016-03-01 09:39:30 -050031 new AnimationIcon(R.drawable.ic_signal_workmode_enable_animation,
32 R.drawable.ic_signal_workmode_disable);
Rubin Xu1205fb12015-11-04 17:45:03 +000033 private final AnimationIcon mDisable =
Jason Monk1aec93f2016-03-01 09:39:30 -050034 new AnimationIcon(R.drawable.ic_signal_workmode_disable_animation,
35 R.drawable.ic_signal_workmode_enable);
Rubin Xu1205fb12015-11-04 17:45:03 +000036
Jason Monkc3f42c12016-02-05 12:33:13 -050037 private final ManagedProfileController mProfileController;
Rubin Xu1205fb12015-11-04 17:45:03 +000038
39 public WorkModeTile(Host host) {
40 super(host);
Jason Monkc3f42c12016-02-05 12:33:13 -050041 mProfileController = host.getManagedProfileController();
Rubin Xu1205fb12015-11-04 17:45:03 +000042 }
43
44 @Override
Jason Monk62b63a02016-02-02 15:15:31 -050045 public BooleanState newTileState() {
Rubin Xu1205fb12015-11-04 17:45:03 +000046 return new BooleanState();
47 }
48
49 @Override
Jason Monkc3f42c12016-02-05 12:33:13 -050050 public void setListening(boolean listening) {
51 if (listening) {
52 mProfileController.addCallback(this);
53 } else {
54 mProfileController.removeCallback(this);
55 }
56 }
57
58 @Override
Jason Monk76c67aa2016-02-19 14:49:42 -050059 public Intent getLongClickIntent() {
60 return new Intent(Settings.ACTION_SYNC_SETTINGS);
61 }
62
63 @Override
Rubin Xu1205fb12015-11-04 17:45:03 +000064 public void handleClick() {
65 MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
Jason Monkc3f42c12016-02-05 12:33:13 -050066 mProfileController.setWorkModeEnabled(!mState.value);
Rubin Xu1205fb12015-11-04 17:45:03 +000067 }
68
Jason Monkc3f42c12016-02-05 12:33:13 -050069 @Override
70 public boolean isAvailable() {
71 return mProfileController.hasActiveProfile();
Rubin Xu1205fb12015-11-04 17:45:03 +000072 }
73
Jason Monkc3f42c12016-02-05 12:33:13 -050074 @Override
75 public void onManagedProfileChanged() {
76 refreshState(mProfileController.isWorkModeEnabled());
Rubin Xu1205fb12015-11-04 17:45:03 +000077 }
78
Jason Monkc3f42c12016-02-05 12:33:13 -050079 @Override
80 public void onManagedProfileRemoved() {
81 mHost.removeTile(getTileSpec());
Rubin Xu1205fb12015-11-04 17:45:03 +000082 }
83
84 @Override
85 protected void handleUpdateState(BooleanState state, Object arg) {
Jason Monk66239fb2015-12-21 14:27:00 -050086 if (arg instanceof Boolean) {
87 state.value = (Boolean) arg;
Rubin Xu1205fb12015-11-04 17:45:03 +000088 } else {
Jason Monkc3f42c12016-02-05 12:33:13 -050089 state.value = mProfileController.isWorkModeEnabled();
Rubin Xu1205fb12015-11-04 17:45:03 +000090 }
91
Rubin Xu1205fb12015-11-04 17:45:03 +000092 state.label = mContext.getString(R.string.quick_settings_work_mode_label);
93 if (state.value) {
Jason Monk66239fb2015-12-21 14:27:00 -050094 state.icon = mEnable;
Rubin Xu1205fb12015-11-04 17:45:03 +000095 state.contentDescription = mContext.getString(
96 R.string.accessibility_quick_settings_work_mode_on);
97 } else {
Jason Monk66239fb2015-12-21 14:27:00 -050098 state.icon = mDisable;
Rubin Xu1205fb12015-11-04 17:45:03 +000099 state.contentDescription = mContext.getString(
100 R.string.accessibility_quick_settings_work_mode_off);
101 }
Rubin Xu1205fb12015-11-04 17:45:03 +0000102 }
103
104 @Override
105 public int getMetricsCategory() {
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500106 return MetricsEvent.QS_WORKMODE;
Rubin Xu1205fb12015-11-04 17:45:03 +0000107 }
108
109 @Override
110 protected String composeChangeAnnouncement() {
111 if (mState.value) {
112 return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_on);
113 } else {
114 return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_off);
115 }
116 }
Rubin Xu1205fb12015-11-04 17:45:03 +0000117}