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