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 | |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 19 | import android.content.Intent; |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame] | 20 | import android.os.UserManager; |
| 21 | |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 22 | import android.provider.Settings; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 23 | import android.widget.Switch; |
| 24 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 25 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | cbd3f0c | 2016-06-22 15:21:38 +0100 | [diff] [blame^] | 26 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 27 | import com.android.systemui.R; |
| 28 | import com.android.systemui.qs.QSTile; |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 29 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 30 | import com.android.systemui.statusbar.policy.LocationController; |
| 31 | import com.android.systemui.statusbar.policy.LocationController.LocationSettingsChangeCallback; |
| 32 | |
| 33 | /** Quick settings tile: Location **/ |
| 34 | public class LocationTile extends QSTile<QSTile.BooleanState> { |
| 35 | |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 36 | private final AnimationIcon mEnable = |
Jason Monk | 1aec93f | 2016-03-01 09:39:30 -0500 | [diff] [blame] | 37 | new AnimationIcon(R.drawable.ic_signal_location_enable_animation, |
| 38 | R.drawable.ic_signal_location_disable); |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 39 | private final AnimationIcon mDisable = |
Jason Monk | 1aec93f | 2016-03-01 09:39:30 -0500 | [diff] [blame] | 40 | new AnimationIcon(R.drawable.ic_signal_location_disable_animation, |
| 41 | R.drawable.ic_signal_location_enable); |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 42 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 43 | private final LocationController mController; |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 44 | private final KeyguardMonitor mKeyguard; |
| 45 | private final Callback mCallback = new Callback(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 46 | |
| 47 | public LocationTile(Host host) { |
| 48 | super(host); |
| 49 | mController = host.getLocationController(); |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 50 | mKeyguard = host.getKeyguardMonitor(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Override |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 54 | public BooleanState newTileState() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 55 | return new BooleanState(); |
| 56 | } |
| 57 | |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 58 | @Override |
| 59 | public void setListening(boolean listening) { |
| 60 | if (listening) { |
| 61 | mController.addSettingsChangedCallback(mCallback); |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 62 | mKeyguard.addCallback(mCallback); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 63 | } else { |
| 64 | mController.removeSettingsChangedCallback(mCallback); |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 65 | mKeyguard.removeCallback(mCallback); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 66 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 70 | public Intent getLongClickIntent() { |
| 71 | return new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
| 72 | } |
| 73 | |
| 74 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 75 | protected void handleClick() { |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 76 | if (mKeyguard.isSecure() && mKeyguard.isShowing()) { |
| 77 | mHost.startRunnableDismissingKeyguard(new Runnable() { |
| 78 | @Override |
| 79 | public void run() { |
| 80 | final boolean wasEnabled = (Boolean) mState.value; |
| 81 | mHost.openPanels(); |
| 82 | MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled); |
| 83 | mController.setLocationEnabled(!wasEnabled); |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 84 | } |
| 85 | }); |
| 86 | return; |
| 87 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 88 | final boolean wasEnabled = (Boolean) mState.value; |
Chris Wren | 9e7283f | 2015-05-08 17:23:47 -0400 | [diff] [blame] | 89 | MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled); |
John Spurlock | d21df60 | 2014-08-28 14:25:05 -0400 | [diff] [blame] | 90 | mController.setLocationEnabled(!wasEnabled); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 94 | public CharSequence getTileLabel() { |
| 95 | return mContext.getString(R.string.quick_settings_location_label); |
| 96 | } |
| 97 | |
| 98 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 99 | protected void handleUpdateState(BooleanState state, Object arg) { |
| 100 | final boolean locationEnabled = mController.isLocationEnabled(); |
Tom O'Neill | d528930 | 2014-09-05 08:22:47 -0700 | [diff] [blame] | 101 | |
| 102 | // Work around for bug 15916487: don't show location tile on top of lock screen. After the |
| 103 | // bug is fixed, this should be reverted to only hiding it on secure lock screens: |
| 104 | // state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing()); |
John Spurlock | 899f439 | 2014-06-11 10:59:11 -0400 | [diff] [blame] | 105 | state.value = locationEnabled; |
Sudheer Shanka | a8fbbb3 | 2016-02-11 17:17:57 +0000 | [diff] [blame] | 106 | checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_SHARE_LOCATION); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 107 | if (locationEnabled) { |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 108 | state.icon = mEnable; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 109 | state.label = mContext.getString(R.string.quick_settings_location_label); |
| 110 | state.contentDescription = mContext.getString( |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 111 | R.string.accessibility_quick_settings_location_on); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 112 | } else { |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 113 | state.icon = mDisable; |
John Spurlock | 012d4a2 | 2014-06-04 00:40:18 -0400 | [diff] [blame] | 114 | state.label = mContext.getString(R.string.quick_settings_location_label); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 115 | state.contentDescription = mContext.getString( |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 116 | R.string.accessibility_quick_settings_location_off); |
| 117 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 118 | state.minimalAccessibilityClassName = state.expandedAccessibilityClassName |
| 119 | = Switch.class.getName(); |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 123 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 124 | return MetricsEvent.QS_LOCATION; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Override |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 128 | protected String composeChangeAnnouncement() { |
| 129 | if (mState.value) { |
| 130 | return mContext.getString(R.string.accessibility_quick_settings_location_changed_on); |
| 131 | } else { |
| 132 | return mContext.getString(R.string.accessibility_quick_settings_location_changed_off); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 136 | private final class Callback implements LocationSettingsChangeCallback, |
| 137 | KeyguardMonitor.Callback { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 138 | @Override |
| 139 | public void onLocationSettingsChanged(boolean enabled) { |
| 140 | refreshState(); |
| 141 | } |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 142 | |
| 143 | @Override |
| 144 | public void onKeyguardChanged() { |
| 145 | refreshState(); |
| 146 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 147 | }; |
| 148 | } |