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 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 22 | import android.content.res.Resources; |
| 23 | import android.provider.Settings; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 24 | import android.util.Log; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 25 | import android.view.View; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 26 | import android.view.ViewGroup; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 27 | import android.widget.Button; |
| 28 | import android.widget.Switch; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 29 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 30 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | cbd3f0c | 2016-06-22 15:21:38 +0100 | [diff] [blame^] | 31 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 32 | import com.android.settingslib.wifi.AccessPoint; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 33 | import com.android.systemui.R; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 34 | import com.android.systemui.qs.QSDetailItems; |
| 35 | import com.android.systemui.qs.QSDetailItems.Item; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 36 | import com.android.systemui.qs.QSIconView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 37 | import com.android.systemui.qs.QSTile; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 38 | import com.android.systemui.qs.SignalTileView; |
| 39 | import com.android.systemui.statusbar.policy.NetworkController; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 40 | import com.android.systemui.statusbar.policy.NetworkController.AccessPointController; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 41 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.SignalCallbackAdapter; |
| 43 | |
| 44 | import java.util.List; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 45 | |
| 46 | /** Quick settings tile: Wifi **/ |
| 47 | public class WifiTile extends QSTile<QSTile.SignalState> { |
| 48 | private static final Intent WIFI_SETTINGS = new Intent(Settings.ACTION_WIFI_SETTINGS); |
| 49 | |
| 50 | private final NetworkController mController; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 51 | private final AccessPointController mWifiController; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 52 | private final WifiDetailAdapter mDetailAdapter; |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 53 | private final QSTile.SignalState mStateBeforeClick = newTileState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 54 | |
Jason Monk | f117961 | 2015-09-23 11:11:00 -0400 | [diff] [blame] | 55 | protected final WifiSignalCallback mSignalCallback = new WifiSignalCallback(); |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 56 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 57 | public WifiTile(Host host) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 58 | super(host); |
| 59 | mController = host.getNetworkController(); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 60 | mWifiController = mController.getAccessPointController(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 61 | mDetailAdapter = new WifiDetailAdapter(); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 65 | public SignalState newTileState() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 66 | return new SignalState(); |
| 67 | } |
| 68 | |
| 69 | @Override |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 70 | public void setListening(boolean listening) { |
| 71 | if (listening) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 72 | mController.addSignalCallback(mSignalCallback); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 73 | } else { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 74 | mController.removeSignalCallback(mSignalCallback); |
Jason Monk | 0d6a1c4 | 2015-04-20 16:38:51 -0400 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void setDetailListening(boolean listening) { |
| 80 | if (listening) { |
| 81 | mWifiController.addAccessPointCallback(mDetailAdapter); |
| 82 | } else { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 83 | mWifiController.removeAccessPointCallback(mDetailAdapter); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 84 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 88 | public DetailAdapter getDetailAdapter() { |
| 89 | return mDetailAdapter; |
| 90 | } |
| 91 | |
| 92 | @Override |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 93 | public QSIconView createTileView(Context context) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 94 | return new SignalTileView(context); |
| 95 | } |
| 96 | |
| 97 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 98 | public Intent getLongClickIntent() { |
| 99 | return WIFI_SETTINGS; |
| 100 | } |
| 101 | |
| 102 | @Override |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 103 | protected void handleSecondaryClick() { |
| 104 | // Secondary clicks are header clicks, just toggle. |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 105 | mState.copyTo(mStateBeforeClick); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 106 | MetricsLogger.action(mContext, getMetricsCategory(), !mState.value); |
| 107 | mController.setWifiEnabled(!mState.value); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Override |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 111 | protected void handleClick() { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 112 | if (!mWifiController.canConfigWifi()) { |
Jason Monk | ee43cdf | 2015-06-19 14:20:46 -0400 | [diff] [blame] | 113 | mHost.startActivityDismissingKeyguard(new Intent(Settings.ACTION_WIFI_SETTINGS)); |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 114 | return; |
| 115 | } |
Jason Monk | 48e093e | 2016-07-15 10:37:07 -0400 | [diff] [blame] | 116 | showDetail(true); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 117 | if (!mState.value) { |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 118 | mController.setWifiEnabled(true); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 119 | mState.value = true; |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 120 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 124 | public CharSequence getTileLabel() { |
| 125 | return mContext.getString(R.string.quick_settings_wifi_label); |
| 126 | } |
| 127 | |
| 128 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 129 | protected void handleUpdateState(SignalState state, Object arg) { |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 130 | if (DEBUG) Log.d(TAG, "handleUpdateState arg=" + arg); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 131 | CallbackInfo cb = (CallbackInfo) arg; |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 132 | if (cb == null) { |
| 133 | cb = mSignalCallback.mInfo; |
| 134 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 135 | |
| 136 | boolean wifiConnected = cb.enabled && (cb.wifiSignalIconId > 0) && (cb.enabledDesc != null); |
| 137 | boolean wifiNotConnected = (cb.wifiSignalIconId > 0) && (cb.enabledDesc == null); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 138 | boolean enabledChanging = state.value != cb.enabled; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 139 | if (enabledChanging) { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 140 | mDetailAdapter.setItemsVisible(cb.enabled); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 141 | fireToggleStateChanged(cb.enabled); |
| 142 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 143 | state.value = cb.enabled; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 144 | state.connected = wifiConnected; |
| 145 | state.activityIn = cb.enabled && cb.activityIn; |
| 146 | state.activityOut = cb.enabled && cb.activityOut; |
John Spurlock | 899f439 | 2014-06-11 10:59:11 -0400 | [diff] [blame] | 147 | state.filter = true; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 148 | final StringBuffer minimalContentDescription = new StringBuffer(); |
| 149 | final StringBuffer expandedContentDescription = new StringBuffer(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 150 | final Resources r = mContext.getResources(); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 151 | if (!state.value) { |
John Spurlock | 2d69581 | 2014-10-30 13:25:21 -0400 | [diff] [blame] | 152 | state.icon = ResourceIcon.get(R.drawable.ic_qs_wifi_disabled); |
John Spurlock | c1d48a5 | 2014-08-01 12:12:32 -0400 | [diff] [blame] | 153 | state.label = r.getString(R.string.quick_settings_wifi_label); |
John Spurlock | c1d48a5 | 2014-08-01 12:12:32 -0400 | [diff] [blame] | 154 | } else if (wifiConnected) { |
John Spurlock | 2d69581 | 2014-10-30 13:25:21 -0400 | [diff] [blame] | 155 | state.icon = ResourceIcon.get(cb.wifiSignalIconId); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 156 | state.label = removeDoubleQuotes(cb.enabledDesc); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 157 | } else if (wifiNotConnected) { |
Jason Monk | be83cc0 | 2016-03-31 13:38:59 -0400 | [diff] [blame] | 158 | state.icon = ResourceIcon.get(R.drawable.ic_qs_wifi_disconnected); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 159 | state.label = r.getString(R.string.quick_settings_wifi_label); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 160 | } else { |
John Spurlock | 2d69581 | 2014-10-30 13:25:21 -0400 | [diff] [blame] | 161 | state.icon = ResourceIcon.get(R.drawable.ic_qs_wifi_no_network); |
John Spurlock | 012d4a2 | 2014-06-04 00:40:18 -0400 | [diff] [blame] | 162 | state.label = r.getString(R.string.quick_settings_wifi_label); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 163 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 164 | minimalContentDescription.append( |
| 165 | mContext.getString(R.string.quick_settings_wifi_label)).append(","); |
| 166 | if (state.value) { |
| 167 | expandedContentDescription.append( |
| 168 | r.getString(R.string.quick_settings_wifi_on_label)).append(","); |
| 169 | if (wifiConnected) { |
| 170 | minimalContentDescription.append(cb.wifiSignalContentDescription).append(","); |
| 171 | minimalContentDescription.append(removeDoubleQuotes(cb.enabledDesc)); |
| 172 | expandedContentDescription.append(cb.wifiSignalContentDescription).append(","); |
| 173 | expandedContentDescription.append(removeDoubleQuotes(cb.enabledDesc)); |
| 174 | } |
| 175 | } else { |
| 176 | expandedContentDescription.append( |
| 177 | r.getString(R.string.quick_settings_wifi_off_label)); |
| 178 | } |
| 179 | state.minimalContentDescription = minimalContentDescription; |
| 180 | expandedContentDescription.append(",").append( |
| 181 | r.getString(R.string.accessibility_quick_settings_open_settings, getTileLabel())); |
| 182 | state.contentDescription = expandedContentDescription; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 183 | CharSequence wifiName = state.label; |
Selim Cinek | e5557a9 | 2014-08-15 19:59:23 +0200 | [diff] [blame] | 184 | if (state.connected) { |
| 185 | wifiName = r.getString(R.string.accessibility_wifi_name, state.label); |
| 186 | } |
| 187 | state.dualLabelContentDescription = wifiName; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 188 | state.expandedAccessibilityClassName = Button.class.getName(); |
| 189 | state.minimalAccessibilityClassName = Switch.class.getName(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 192 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 193 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 194 | return MetricsEvent.QS_WIFI; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | @Override |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 198 | protected boolean shouldAnnouncementBeDelayed() { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 199 | return mStateBeforeClick.value == mState.value; |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | @Override |
| 203 | protected String composeChangeAnnouncement() { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 204 | if (mState.value) { |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 205 | return mContext.getString(R.string.accessibility_quick_settings_wifi_changed_on); |
| 206 | } else { |
| 207 | return mContext.getString(R.string.accessibility_quick_settings_wifi_changed_off); |
| 208 | } |
| 209 | } |
| 210 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 211 | @Override |
| 212 | public boolean isAvailable() { |
| 213 | return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI); |
| 214 | } |
| 215 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 216 | private static String removeDoubleQuotes(String string) { |
| 217 | if (string == null) return null; |
| 218 | final int length = string.length(); |
| 219 | if ((length > 1) && (string.charAt(0) == '"') && (string.charAt(length - 1) == '"')) { |
| 220 | return string.substring(1, length - 1); |
| 221 | } |
| 222 | return string; |
| 223 | } |
| 224 | |
Jason Monk | f117961 | 2015-09-23 11:11:00 -0400 | [diff] [blame] | 225 | protected static final class CallbackInfo { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 226 | boolean enabled; |
John Spurlock | d5cd2fd | 2014-07-27 11:36:33 -0400 | [diff] [blame] | 227 | boolean connected; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 228 | int wifiSignalIconId; |
| 229 | String enabledDesc; |
| 230 | boolean activityIn; |
| 231 | boolean activityOut; |
| 232 | String wifiSignalContentDescription; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 233 | |
| 234 | @Override |
| 235 | public String toString() { |
| 236 | return new StringBuilder("CallbackInfo[") |
| 237 | .append("enabled=").append(enabled) |
John Spurlock | d5cd2fd | 2014-07-27 11:36:33 -0400 | [diff] [blame] | 238 | .append(",connected=").append(connected) |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 239 | .append(",wifiSignalIconId=").append(wifiSignalIconId) |
| 240 | .append(",enabledDesc=").append(enabledDesc) |
| 241 | .append(",activityIn=").append(activityIn) |
| 242 | .append(",activityOut=").append(activityOut) |
| 243 | .append(",wifiSignalContentDescription=").append(wifiSignalContentDescription) |
| 244 | .append(']').toString(); |
| 245 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Jason Monk | f117961 | 2015-09-23 11:11:00 -0400 | [diff] [blame] | 248 | protected final class WifiSignalCallback extends SignalCallbackAdapter { |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 249 | final CallbackInfo mInfo = new CallbackInfo(); |
| 250 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 251 | @Override |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 252 | public void setWifiIndicators(boolean enabled, IconState statusIcon, IconState qsIcon, |
| 253 | boolean activityIn, boolean activityOut, String description) { |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 254 | if (DEBUG) Log.d(TAG, "onWifiSignalChanged enabled=" + enabled); |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 255 | mInfo.enabled = enabled; |
| 256 | mInfo.connected = qsIcon.visible; |
| 257 | mInfo.wifiSignalIconId = qsIcon.icon; |
| 258 | mInfo.enabledDesc = description; |
| 259 | mInfo.activityIn = activityIn; |
| 260 | mInfo.activityOut = activityOut; |
| 261 | mInfo.wifiSignalContentDescription = qsIcon.contentDescription; |
| 262 | refreshState(mInfo); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 263 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 264 | }; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 265 | |
| 266 | private final class WifiDetailAdapter implements DetailAdapter, |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 267 | NetworkController.AccessPointController.AccessPointCallback, QSDetailItems.Callback { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 268 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 269 | private QSDetailItems mItems; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 270 | private AccessPoint[] mAccessPoints; |
| 271 | |
| 272 | @Override |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 273 | public CharSequence getTitle() { |
| 274 | return mContext.getString(R.string.quick_settings_wifi_label); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | public Intent getSettingsIntent() { |
| 278 | return WIFI_SETTINGS; |
| 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public Boolean getToggleState() { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 283 | return mState.value; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void setToggleState(boolean state) { |
| 288 | if (DEBUG) Log.d(TAG, "setToggleState " + state); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 289 | MetricsLogger.action(mContext, MetricsEvent.QS_WIFI_TOGGLE, state); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 290 | mController.setWifiEnabled(state); |
| 291 | showDetail(false); |
| 292 | } |
| 293 | |
| 294 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 295 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 296 | return MetricsEvent.QS_WIFI_DETAILS; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | @Override |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 300 | public View createDetailView(Context context, View convertView, ViewGroup parent) { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 301 | if (DEBUG) Log.d(TAG, "createDetailView convertView=" + (convertView != null)); |
| 302 | mAccessPoints = null; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 303 | mWifiController.scanForAccessPoints(); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 304 | fireScanStateChanged(true); |
| 305 | mItems = QSDetailItems.convertOrInflate(context, convertView, parent); |
| 306 | mItems.setTagSuffix("Wifi"); |
| 307 | mItems.setCallback(this); |
| 308 | mItems.setEmptyState(R.drawable.ic_qs_wifi_detail_empty, |
| 309 | R.string.quick_settings_wifi_detail_empty_text); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 310 | updateItems(); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 311 | setItemsVisible(mState.value); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 312 | return mItems; |
| 313 | } |
| 314 | |
| 315 | @Override |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 316 | public void onAccessPointsChanged(final List<AccessPoint> accessPoints) { |
| 317 | mAccessPoints = accessPoints.toArray(new AccessPoint[accessPoints.size()]); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 318 | updateItems(); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 319 | if (accessPoints != null && accessPoints.size() > 0) { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 320 | fireScanStateChanged(false); |
| 321 | } |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 322 | } |
| 323 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 324 | @Override |
Jason Monk | 17f3c3f | 2015-01-14 10:13:22 -0500 | [diff] [blame] | 325 | public void onSettingsActivityTriggered(Intent settingsIntent) { |
Jason Monk | ee43cdf | 2015-06-19 14:20:46 -0400 | [diff] [blame] | 326 | mHost.startActivityDismissingKeyguard(settingsIntent); |
Jason Monk | 17f3c3f | 2015-01-14 10:13:22 -0500 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | @Override |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 330 | public void onDetailItemClick(Item item) { |
| 331 | if (item == null || item.tag == null) return; |
| 332 | final AccessPoint ap = (AccessPoint) item.tag; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 333 | if (!ap.isActive()) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 334 | if (mWifiController.connect(ap)) { |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 335 | mHost.collapsePanels(); |
| 336 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 337 | } |
| 338 | showDetail(false); |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public void onDetailItemDisconnect(Item item) { |
| 343 | // noop |
| 344 | } |
| 345 | |
| 346 | public void setItemsVisible(boolean visible) { |
| 347 | if (mItems == null) return; |
| 348 | mItems.setItemsVisible(visible); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | private void updateItems() { |
| 352 | if (mItems == null) return; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 353 | Item[] items = null; |
| 354 | if (mAccessPoints != null) { |
| 355 | items = new Item[mAccessPoints.length]; |
| 356 | for (int i = 0; i < mAccessPoints.length; i++) { |
| 357 | final AccessPoint ap = mAccessPoints[i]; |
| 358 | final Item item = new Item(); |
| 359 | item.tag = ap; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 360 | item.icon = mWifiController.getIcon(ap); |
| 361 | item.line1 = ap.getSsid(); |
Jason Monk | 283c8b7 | 2015-05-26 12:54:12 -0400 | [diff] [blame] | 362 | item.line2 = ap.isActive() ? ap.getSummary() : null; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 363 | item.overlay = ap.getSecurity() != AccessPoint.SECURITY_NONE |
Jason Monk | b27ec6d3 | 2014-12-01 17:50:16 -0500 | [diff] [blame] | 364 | ? mContext.getDrawable(R.drawable.qs_ic_wifi_lock) |
| 365 | : null; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 366 | items[i] = item; |
| 367 | } |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 368 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 369 | mItems.setItems(items); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 370 | } |
Fan Zhang | 3bfda44 | 2016-07-15 10:39:03 -0700 | [diff] [blame] | 371 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 372 | } |