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