blob: 003e9c15ad430d8fd8202a615f5295ef18b8530b [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 =
31 new AnimationIcon(R.drawable.ic_signal_workmode_enable_animation);
32 private final AnimationIcon mDisable =
33 new AnimationIcon(R.drawable.ic_signal_workmode_disable_animation);
34
Jason Monkc3f42c12016-02-05 12:33:13 -050035 private final ManagedProfileController mProfileController;
Rubin Xu1205fb12015-11-04 17:45:03 +000036
37 public WorkModeTile(Host host) {
38 super(host);
Jason Monkc3f42c12016-02-05 12:33:13 -050039 mProfileController = host.getManagedProfileController();
Rubin Xu1205fb12015-11-04 17:45:03 +000040 }
41
42 @Override
Jason Monk62b63a02016-02-02 15:15:31 -050043 public BooleanState newTileState() {
Rubin Xu1205fb12015-11-04 17:45:03 +000044 return new BooleanState();
45 }
46
47 @Override
Jason Monkc3f42c12016-02-05 12:33:13 -050048 public void setListening(boolean listening) {
49 if (listening) {
50 mProfileController.addCallback(this);
51 } else {
52 mProfileController.removeCallback(this);
53 }
54 }
55
56 @Override
Jason Monk76c67aa2016-02-19 14:49:42 -050057 public Intent getLongClickIntent() {
58 return new Intent(Settings.ACTION_SYNC_SETTINGS);
59 }
60
61 @Override
Rubin Xu1205fb12015-11-04 17:45:03 +000062 public void handleClick() {
63 MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
Jason Monkc3f42c12016-02-05 12:33:13 -050064 mProfileController.setWorkModeEnabled(!mState.value);
Rubin Xu1205fb12015-11-04 17:45:03 +000065 }
66
Jason Monkc3f42c12016-02-05 12:33:13 -050067 @Override
68 public boolean isAvailable() {
69 return mProfileController.hasActiveProfile();
Rubin Xu1205fb12015-11-04 17:45:03 +000070 }
71
Jason Monkc3f42c12016-02-05 12:33:13 -050072 @Override
73 public void onManagedProfileChanged() {
74 refreshState(mProfileController.isWorkModeEnabled());
Rubin Xu1205fb12015-11-04 17:45:03 +000075 }
76
Jason Monkc3f42c12016-02-05 12:33:13 -050077 @Override
78 public void onManagedProfileRemoved() {
79 mHost.removeTile(getTileSpec());
Rubin Xu1205fb12015-11-04 17:45:03 +000080 }
81
82 @Override
83 protected void handleUpdateState(BooleanState state, Object arg) {
Jason Monk66239fb2015-12-21 14:27:00 -050084 if (arg instanceof Boolean) {
85 state.value = (Boolean) arg;
Rubin Xu1205fb12015-11-04 17:45:03 +000086 } else {
Jason Monkc3f42c12016-02-05 12:33:13 -050087 state.value = mProfileController.isWorkModeEnabled();
Rubin Xu1205fb12015-11-04 17:45:03 +000088 }
89
Rubin Xu1205fb12015-11-04 17:45:03 +000090 state.label = mContext.getString(R.string.quick_settings_work_mode_label);
91 if (state.value) {
Jason Monk66239fb2015-12-21 14:27:00 -050092 state.icon = mEnable;
Rubin Xu1205fb12015-11-04 17:45:03 +000093 state.contentDescription = mContext.getString(
94 R.string.accessibility_quick_settings_work_mode_on);
95 } else {
Jason Monk66239fb2015-12-21 14:27:00 -050096 state.icon = mDisable;
Rubin Xu1205fb12015-11-04 17:45:03 +000097 state.contentDescription = mContext.getString(
98 R.string.accessibility_quick_settings_work_mode_off);
99 }
Rubin Xu1205fb12015-11-04 17:45:03 +0000100 }
101
102 @Override
103 public int getMetricsCategory() {
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500104 return MetricsEvent.QS_WORKMODE;
Rubin Xu1205fb12015-11-04 17:45:03 +0000105 }
106
107 @Override
108 protected String composeChangeAnnouncement() {
109 if (mState.value) {
110 return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_on);
111 } else {
112 return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_off);
113 }
114 }
Rubin Xu1205fb12015-11-04 17:45:03 +0000115}