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