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; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 21 | import android.service.quicksettings.Tile; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 22 | import android.widget.Switch; |
| 23 | |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 24 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 25 | import com.android.systemui.R; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 26 | import com.android.systemui.plugins.qs.QSTile.BooleanState; |
Tony Mak | e9861b4 | 2018-03-02 17:24:10 +0000 | [diff] [blame] | 27 | import com.android.systemui.qs.QSHost; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 28 | import com.android.systemui.qs.tileimpl.QSTileImpl; |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 29 | import com.android.systemui.statusbar.phone.ManagedProfileController; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 30 | |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 31 | import javax.inject.Inject; |
| 32 | |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 33 | /** Quick settings tile: Work profile on/off */ |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 34 | public class WorkModeTile extends QSTileImpl<BooleanState> implements |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 35 | ManagedProfileController.Callback { |
Evan Laird | 351e444 | 2017-05-12 12:52:09 -0400 | [diff] [blame] | 36 | private final Icon mIcon = ResourceIcon.get(R.drawable.ic_signal_workmode_disable); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 37 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 38 | private final ManagedProfileController mProfileController; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 39 | |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 40 | @Inject |
Jason Monk | c0e0e2b | 2018-12-26 16:47:41 -0500 | [diff] [blame] | 41 | public WorkModeTile(QSHost host, ManagedProfileController managedProfileController) { |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 42 | super(host); |
Jason Monk | c0e0e2b | 2018-12-26 16:47:41 -0500 | [diff] [blame] | 43 | mProfileController = managedProfileController; |
Jason Monk | fa452ef | 2018-12-26 17:26:10 -0500 | [diff] [blame] | 44 | mProfileController.observe(getLifecycle(), this); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 48 | public BooleanState newTileState() { |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 49 | return new BooleanState(); |
| 50 | } |
| 51 | |
| 52 | @Override |
Jason Monk | 1c6116c | 2017-09-06 17:33:01 -0400 | [diff] [blame] | 53 | public void handleSetListening(boolean listening) { |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 57 | public Intent getLongClickIntent() { |
Ricky Wai | 38bb832 | 2017-02-01 15:23:50 +0000 | [diff] [blame] | 58 | return new Intent(Settings.ACTION_MANAGED_PROFILE_SETTINGS); |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 62 | public void handleClick() { |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 63 | mProfileController.setWorkModeEnabled(!mState.value); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 66 | @Override |
| 67 | public boolean isAvailable() { |
| 68 | return mProfileController.hasActiveProfile(); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 71 | @Override |
| 72 | public void onManagedProfileChanged() { |
| 73 | refreshState(mProfileController.isWorkModeEnabled()); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 76 | @Override |
| 77 | public void onManagedProfileRemoved() { |
| 78 | mHost.removeTile(getTileSpec()); |
arangelov | 5fe9598 | 2018-08-17 18:43:31 +0100 | [diff] [blame] | 79 | mHost.unmarkTileAsAutoAdded(getTileSpec()); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 83 | public CharSequence getTileLabel() { |
Adam Lesinski | 6cd4155 | 2018-03-02 11:40:50 -0800 | [diff] [blame] | 84 | return mContext.getString(R.string.quick_settings_work_mode_label); |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 88 | protected void handleUpdateState(BooleanState state, Object arg) { |
Tony Mak | e9861b4 | 2018-03-02 17:24:10 +0000 | [diff] [blame] | 89 | if (!isAvailable()) { |
| 90 | onManagedProfileRemoved(); |
| 91 | } |
| 92 | |
Evan Laird | 351e444 | 2017-05-12 12:52:09 -0400 | [diff] [blame] | 93 | if (state.slash == null) { |
| 94 | state.slash = new SlashState(); |
| 95 | } |
| 96 | |
Jason Monk | 66239fb | 2015-12-21 14:27:00 -0500 | [diff] [blame] | 97 | if (arg instanceof Boolean) { |
| 98 | state.value = (Boolean) arg; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 99 | } else { |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 100 | state.value = mProfileController.isWorkModeEnabled(); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Evan Laird | 351e444 | 2017-05-12 12:52:09 -0400 | [diff] [blame] | 103 | state.icon = mIcon; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 104 | if (state.value) { |
Evan Laird | 351e444 | 2017-05-12 12:52:09 -0400 | [diff] [blame] | 105 | state.slash.isSlashed = false; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 106 | state.contentDescription = mContext.getString( |
| 107 | R.string.accessibility_quick_settings_work_mode_on); |
| 108 | } else { |
Evan Laird | 351e444 | 2017-05-12 12:52:09 -0400 | [diff] [blame] | 109 | state.slash.isSlashed = true; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 110 | state.contentDescription = mContext.getString( |
| 111 | R.string.accessibility_quick_settings_work_mode_off); |
| 112 | } |
Tony Mak | 83533f4 | 2018-02-22 18:22:32 +0000 | [diff] [blame] | 113 | state.label = mContext.getString(R.string.quick_settings_work_mode_label); |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 114 | state.expandedAccessibilityClassName = Switch.class.getName(); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 115 | state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 120 | return MetricsEvent.QS_WORKMODE; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
| 124 | protected String composeChangeAnnouncement() { |
| 125 | if (mState.value) { |
| 126 | return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_on); |
| 127 | } else { |
| 128 | return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_off); |
| 129 | } |
| 130 | } |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 131 | } |