Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.qs.tiles; |
| 18 | |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 19 | import android.content.Intent; |
| 20 | import android.provider.Settings; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 21 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 22 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 23 | import com.android.systemui.R; |
| 24 | import com.android.systemui.qs.QSTile; |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 25 | import com.android.systemui.statusbar.phone.ManagedProfileController; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 26 | |
| 27 | /** Quick settings tile: Work profile on/off */ |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 28 | public class WorkModeTile extends QSTile<QSTile.BooleanState> implements |
| 29 | ManagedProfileController.Callback { |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 30 | 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 Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 35 | private final ManagedProfileController mProfileController; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 36 | |
| 37 | public WorkModeTile(Host host) { |
| 38 | super(host); |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 39 | mProfileController = host.getManagedProfileController(); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | @Override |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 43 | public BooleanState newTileState() { |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 44 | return new BooleanState(); |
| 45 | } |
| 46 | |
| 47 | @Override |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 48 | public void setListening(boolean listening) { |
| 49 | if (listening) { |
| 50 | mProfileController.addCallback(this); |
| 51 | } else { |
| 52 | mProfileController.removeCallback(this); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 57 | public Intent getLongClickIntent() { |
| 58 | return new Intent(Settings.ACTION_SYNC_SETTINGS); |
| 59 | } |
| 60 | |
| 61 | @Override |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 62 | public void handleClick() { |
| 63 | MetricsLogger.action(mContext, getMetricsCategory(), !mState.value); |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 64 | mProfileController.setWorkModeEnabled(!mState.value); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 67 | @Override |
| 68 | public boolean isAvailable() { |
| 69 | return mProfileController.hasActiveProfile(); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 72 | @Override |
| 73 | public void onManagedProfileChanged() { |
| 74 | refreshState(mProfileController.isWorkModeEnabled()); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 77 | @Override |
| 78 | public void onManagedProfileRemoved() { |
| 79 | mHost.removeTile(getTileSpec()); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected void handleUpdateState(BooleanState state, Object arg) { |
Jason Monk | 66239fb | 2015-12-21 14:27:00 -0500 | [diff] [blame] | 84 | if (arg instanceof Boolean) { |
| 85 | state.value = (Boolean) arg; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 86 | } else { |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 87 | state.value = mProfileController.isWorkModeEnabled(); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 90 | state.label = mContext.getString(R.string.quick_settings_work_mode_label); |
| 91 | if (state.value) { |
Jason Monk | 66239fb | 2015-12-21 14:27:00 -0500 | [diff] [blame] | 92 | state.icon = mEnable; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 93 | state.contentDescription = mContext.getString( |
| 94 | R.string.accessibility_quick_settings_work_mode_on); |
| 95 | } else { |
Jason Monk | 66239fb | 2015-12-21 14:27:00 -0500 | [diff] [blame] | 96 | state.icon = mDisable; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 97 | state.contentDescription = mContext.getString( |
| 98 | R.string.accessibility_quick_settings_work_mode_off); |
| 99 | } |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 104 | return MetricsEvent.QS_WORKMODE; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 105 | } |
| 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 Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 115 | } |