blob: 65332529d881db5cee0afff6c6486af7143d3172 [file] [log] [blame]
John Spurlockaf8d6c42014-05-07 17:49:08 -04001/*
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
17package com.android.systemui.qs.tiles;
18
Jason Monk76c67aa2016-02-19 14:49:42 -050019import android.content.Intent;
Sudheer Shankab6fc9312016-01-27 19:59:03 +000020import android.os.UserManager;
21
Jason Monk76c67aa2016-02-19 14:49:42 -050022import android.provider.Settings;
Chris Wren457a21c2015-05-06 17:50:34 -040023import com.android.internal.logging.MetricsLogger;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050024import com.android.internal.logging.MetricsProto.MetricsEvent;
John Spurlockaf8d6c42014-05-07 17:49:08 -040025import com.android.systemui.R;
26import com.android.systemui.qs.QSTile;
John Spurlock657c62c2014-07-22 12:18:09 -040027import com.android.systemui.statusbar.policy.KeyguardMonitor;
John Spurlockaf8d6c42014-05-07 17:49:08 -040028import com.android.systemui.statusbar.policy.LocationController;
29import com.android.systemui.statusbar.policy.LocationController.LocationSettingsChangeCallback;
30
31/** Quick settings tile: Location **/
32public class LocationTile extends QSTile<QSTile.BooleanState> {
33
John Spurlockc6df3cf2014-11-04 19:36:44 -050034 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 Spurlockaf8d6c42014-05-07 17:49:08 -040039 private final LocationController mController;
John Spurlock657c62c2014-07-22 12:18:09 -040040 private final KeyguardMonitor mKeyguard;
41 private final Callback mCallback = new Callback();
John Spurlockaf8d6c42014-05-07 17:49:08 -040042
43 public LocationTile(Host host) {
44 super(host);
45 mController = host.getLocationController();
John Spurlock657c62c2014-07-22 12:18:09 -040046 mKeyguard = host.getKeyguardMonitor();
John Spurlockaf8d6c42014-05-07 17:49:08 -040047 }
48
49 @Override
Jason Monk62b63a02016-02-02 15:15:31 -050050 public BooleanState newTileState() {
John Spurlockaf8d6c42014-05-07 17:49:08 -040051 return new BooleanState();
52 }
53
John Spurlockccb6b9a2014-05-17 15:54:40 -040054 @Override
55 public void setListening(boolean listening) {
56 if (listening) {
57 mController.addSettingsChangedCallback(mCallback);
John Spurlock657c62c2014-07-22 12:18:09 -040058 mKeyguard.addCallback(mCallback);
John Spurlockccb6b9a2014-05-17 15:54:40 -040059 } else {
60 mController.removeSettingsChangedCallback(mCallback);
John Spurlock657c62c2014-07-22 12:18:09 -040061 mKeyguard.removeCallback(mCallback);
John Spurlockccb6b9a2014-05-17 15:54:40 -040062 }
John Spurlockaf8d6c42014-05-07 17:49:08 -040063 }
64
65 @Override
Jason Monk76c67aa2016-02-19 14:49:42 -050066 public Intent getLongClickIntent() {
67 return new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
68 }
69
70 @Override
John Spurlockaf8d6c42014-05-07 17:49:08 -040071 protected void handleClick() {
Jason Monkba2318e2015-12-08 09:04:23 -050072 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 Monkba2318e2015-12-08 09:04:23 -050080 }
81 });
82 return;
83 }
John Spurlockaf8d6c42014-05-07 17:49:08 -040084 final boolean wasEnabled = (Boolean) mState.value;
Chris Wren9e7283f2015-05-08 17:23:47 -040085 MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled);
John Spurlockd21df602014-08-28 14:25:05 -040086 mController.setLocationEnabled(!wasEnabled);
John Spurlockaf8d6c42014-05-07 17:49:08 -040087 }
88
89 @Override
90 protected void handleUpdateState(BooleanState state, Object arg) {
91 final boolean locationEnabled = mController.isLocationEnabled();
Tom O'Neilld5289302014-09-05 08:22:47 -070092
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 Spurlock899f4392014-06-11 10:59:11 -040096 state.value = locationEnabled;
Sudheer Shankaa8fbbb32016-02-11 17:17:57 +000097 checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_SHARE_LOCATION);
John Spurlockaf8d6c42014-05-07 17:49:08 -040098 if (locationEnabled) {
John Spurlockc6df3cf2014-11-04 19:36:44 -050099 state.icon = mEnable;
John Spurlockaf8d6c42014-05-07 17:49:08 -0400100 state.label = mContext.getString(R.string.quick_settings_location_label);
101 state.contentDescription = mContext.getString(
Selim Cinek4fda7b22014-08-18 22:07:25 +0200102 R.string.accessibility_quick_settings_location_on);
John Spurlockaf8d6c42014-05-07 17:49:08 -0400103 } else {
John Spurlockc6df3cf2014-11-04 19:36:44 -0500104 state.icon = mDisable;
John Spurlock012d4a22014-06-04 00:40:18 -0400105 state.label = mContext.getString(R.string.quick_settings_location_label);
John Spurlockaf8d6c42014-05-07 17:49:08 -0400106 state.contentDescription = mContext.getString(
Selim Cinek4fda7b22014-08-18 22:07:25 +0200107 R.string.accessibility_quick_settings_location_off);
108 }
109 }
110
111 @Override
Chris Wren457a21c2015-05-06 17:50:34 -0400112 public int getMetricsCategory() {
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500113 return MetricsEvent.QS_LOCATION;
Chris Wren457a21c2015-05-06 17:50:34 -0400114 }
115
116 @Override
Selim Cinek4fda7b22014-08-18 22:07:25 +0200117 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 Spurlockaf8d6c42014-05-07 17:49:08 -0400122 }
123 }
124
John Spurlock657c62c2014-07-22 12:18:09 -0400125 private final class Callback implements LocationSettingsChangeCallback,
126 KeyguardMonitor.Callback {
John Spurlockaf8d6c42014-05-07 17:49:08 -0400127 @Override
128 public void onLocationSettingsChanged(boolean enabled) {
129 refreshState();
130 }
John Spurlock657c62c2014-07-22 12:18:09 -0400131
132 @Override
133 public void onKeyguardChanged() {
134 refreshState();
135 }
John Spurlockaf8d6c42014-05-07 17:49:08 -0400136 };
137}