John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame^] | 19 | import android.os.UserManager; |
| 20 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [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; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 23 | import com.android.systemui.R; |
| 24 | import com.android.systemui.qs.QSTile; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 25 | import com.android.systemui.statusbar.policy.HotspotController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 26 | |
| 27 | /** Quick settings tile: Hotspot **/ |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 28 | public class HotspotTile extends QSTile<QSTile.BooleanState> { |
John Spurlock | 1832d2f | 2014-11-09 18:37:19 -0500 | [diff] [blame] | 29 | private final AnimationIcon mEnable = |
| 30 | new AnimationIcon(R.drawable.ic_hotspot_enable_animation); |
| 31 | private final AnimationIcon mDisable = |
| 32 | new AnimationIcon(R.drawable.ic_hotspot_disable_animation); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 33 | private final HotspotController mController; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 34 | private final Callback mCallback = new Callback(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 35 | |
| 36 | public HotspotTile(Host host) { |
| 37 | super(host); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 38 | mController = host.getHotspotController(); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | @Override |
| 42 | protected void handleDestroy() { |
| 43 | super.handleDestroy(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Override |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 47 | protected BooleanState newTileState() { |
| 48 | return new BooleanState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 52 | public void setListening(boolean listening) { |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 53 | if (listening) { |
| 54 | mController.addCallback(mCallback); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 55 | } else { |
| 56 | mController.removeCallback(mCallback); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 57 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected void handleClick() { |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 62 | final boolean isEnabled = (Boolean) mState.value; |
Chris Wren | 9e7283f | 2015-05-08 17:23:47 -0400 | [diff] [blame] | 63 | MetricsLogger.action(mContext, getMetricsCategory(), !isEnabled); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 64 | mController.setHotspotEnabled(!isEnabled); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 68 | protected void handleUpdateState(BooleanState state, Object arg) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 69 | state.label = mContext.getString(R.string.quick_settings_hotspot_label); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 70 | |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame^] | 71 | state.disabledByPolicy = mController.isTetheringAllowed(); |
| 72 | checkIfRestrictionEnforced(state, UserManager.DISALLOW_CONFIG_TETHERING); |
Julia Reynolds | b8a46a6 | 2015-07-14 13:36:30 -0400 | [diff] [blame] | 73 | if (arg instanceof Boolean) { |
| 74 | state.value = (boolean) arg; |
| 75 | } else { |
Jason Monk | dd5bdc6 | 2015-07-20 12:18:38 -0400 | [diff] [blame] | 76 | state.value = mController.isHotspotEnabled(); |
Julia Reynolds | b8a46a6 | 2015-07-14 13:36:30 -0400 | [diff] [blame] | 77 | } |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 78 | state.icon = state.value ? mEnable : mDisable; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 81 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 82 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 83 | return MetricsEvent.QS_HOTSPOT; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 87 | protected String composeChangeAnnouncement() { |
| 88 | if (mState.value) { |
| 89 | return mContext.getString(R.string.accessibility_quick_settings_hotspot_changed_on); |
| 90 | } else { |
| 91 | return mContext.getString(R.string.accessibility_quick_settings_hotspot_changed_off); |
| 92 | } |
| 93 | } |
| 94 | |
John Spurlock | e2efefe | 2014-07-28 11:17:12 -0400 | [diff] [blame] | 95 | private final class Callback implements HotspotController.Callback { |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 96 | @Override |
| 97 | public void onHotspotChanged(boolean enabled) { |
Julia Reynolds | b8a46a6 | 2015-07-14 13:36:30 -0400 | [diff] [blame] | 98 | refreshState(enabled); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 99 | } |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 100 | }; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 101 | } |