Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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.statusbar.phone; |
| 18 | |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 19 | import android.animation.ValueAnimator; |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 20 | import android.app.ActivityManagerNative; |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 21 | import android.app.AlertDialog; |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 22 | import android.app.Dialog; |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 23 | import android.app.PendingIntent; |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 24 | import android.app.admin.DevicePolicyManager; |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 25 | import android.bluetooth.BluetoothAdapter; |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 28 | import android.content.Context; |
Winson Chung | 1679b36 | 2012-09-10 20:08:01 -0700 | [diff] [blame] | 29 | import android.content.DialogInterface; |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 30 | import android.content.DialogInterface.OnClickListener; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 31 | import android.content.Intent; |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 32 | import android.content.IntentFilter; |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager.NameNotFoundException; |
| 34 | import android.content.pm.UserInfo; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 35 | import android.content.res.Resources; |
| 36 | import android.database.Cursor; |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 37 | import android.graphics.Bitmap; |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 38 | import android.graphics.drawable.BitmapDrawable; |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 39 | import android.graphics.drawable.Drawable; |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 40 | import android.hardware.display.DisplayManager; |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame^] | 41 | import android.media.MediaRouter; |
Daniel Sandler | ab51002 | 2012-10-22 22:13:35 -0400 | [diff] [blame] | 42 | import android.net.wifi.WifiManager; |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 43 | import android.os.AsyncTask; |
Winson Chung | 3ed6f94 | 2012-09-20 16:07:11 -0700 | [diff] [blame] | 44 | import android.os.Handler; |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 45 | import android.os.RemoteException; |
Winson Chung | 34563e2 | 2012-09-21 17:19:49 -0700 | [diff] [blame] | 46 | import android.os.UserHandle; |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 47 | import android.os.UserManager; |
Satoshi Kataoka | c44f7a2 | 2013-05-22 08:54:56 +0900 | [diff] [blame] | 48 | import android.provider.AlarmClock; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 49 | import android.provider.ContactsContract; |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 50 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 51 | import android.provider.ContactsContract.Profile; |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 52 | import android.provider.Settings; |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 53 | import android.security.KeyChain; |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 54 | import android.util.Log; |
| 55 | import android.util.Pair; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 56 | import android.view.LayoutInflater; |
| 57 | import android.view.View; |
| 58 | import android.view.ViewGroup; |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 59 | import android.view.WindowManager; |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 60 | import android.view.WindowManagerGlobal; |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 61 | import android.widget.ImageView; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 62 | import android.widget.TextView; |
| 63 | |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame^] | 64 | import com.android.internal.app.MediaRouteDialogPresenter; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 65 | import com.android.systemui.R; |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 66 | import com.android.systemui.statusbar.phone.QuickSettingsModel.ActivityState; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 67 | import com.android.systemui.statusbar.phone.QuickSettingsModel.BluetoothState; |
| 68 | import com.android.systemui.statusbar.phone.QuickSettingsModel.RSSIState; |
| 69 | import com.android.systemui.statusbar.phone.QuickSettingsModel.State; |
| 70 | import com.android.systemui.statusbar.phone.QuickSettingsModel.UserState; |
| 71 | import com.android.systemui.statusbar.phone.QuickSettingsModel.WifiState; |
| 72 | import com.android.systemui.statusbar.policy.BatteryController; |
| 73 | import com.android.systemui.statusbar.policy.BluetoothController; |
| 74 | import com.android.systemui.statusbar.policy.LocationController; |
| 75 | import com.android.systemui.statusbar.policy.NetworkController; |
| 76 | import com.android.systemui.statusbar.policy.RotationLockController; |
| 77 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 78 | import java.util.ArrayList; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 79 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 80 | /** |
| 81 | * |
| 82 | */ |
| 83 | class QuickSettings { |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 84 | static final boolean DEBUG_GONE_TILES = false; |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 85 | private static final String TAG = "QuickSettings"; |
Daniel Sandler | dd68da8 | 2012-10-01 10:19:09 -0400 | [diff] [blame] | 86 | public static final boolean SHOW_IME_TILE = false; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 87 | |
Daniel Sandler | ab51002 | 2012-10-22 22:13:35 -0400 | [diff] [blame] | 88 | public static final boolean LONG_PRESS_TOGGLES = true; |
| 89 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 90 | private Context mContext; |
| 91 | private PanelBar mBar; |
| 92 | private QuickSettingsModel mModel; |
Daniel Sandler | 101784e | 2012-10-15 13:39:38 -0400 | [diff] [blame] | 93 | private ViewGroup mContainerView; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 94 | |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 95 | private DevicePolicyManager mDevicePolicyManager; |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 96 | private PhoneStatusBar mStatusBarService; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 97 | private BluetoothState mBluetoothState; |
Daniel Sandler | ab51002 | 2012-10-22 22:13:35 -0400 | [diff] [blame] | 98 | private BluetoothAdapter mBluetoothAdapter; |
| 99 | private WifiManager mWifiManager; |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 100 | |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 101 | private BluetoothController mBluetoothController; |
Svetoslav | 79578b2 | 2013-04-29 16:55:57 -0700 | [diff] [blame] | 102 | private RotationLockController mRotationLockController; |
David Christie | 03ed012 | 2013-07-30 18:11:23 -0700 | [diff] [blame] | 103 | private LocationController mLocationController; |
Winson Chung | 3ed6f94 | 2012-09-20 16:07:11 -0700 | [diff] [blame] | 104 | |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 105 | private AsyncTask<Void, Void, Pair<String, Drawable>> mUserInfoTask; |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 106 | private AsyncTask<Void, Void, Pair<Boolean, Boolean>> mQueryCertTask; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 107 | |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 108 | boolean mTilesSetUp = false; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 109 | boolean mUseDefaultAvatar = false; |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 110 | |
Winson Chung | 3ed6f94 | 2012-09-20 16:07:11 -0700 | [diff] [blame] | 111 | private Handler mHandler; |
| 112 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 113 | // The set of QuickSettingsTiles that have dynamic spans (and need to be updated on |
| 114 | // configuration change) |
| 115 | private final ArrayList<QuickSettingsTileView> mDynamicSpannedTiles = |
| 116 | new ArrayList<QuickSettingsTileView>(); |
| 117 | |
| 118 | public QuickSettings(Context context, QuickSettingsContainerView container) { |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 119 | mDevicePolicyManager |
| 120 | = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 121 | mContext = context; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 122 | mContainerView = container; |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 123 | mModel = new QuickSettingsModel(context); |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 124 | mBluetoothState = new QuickSettingsModel.BluetoothState(); |
Daniel Sandler | ab51002 | 2012-10-22 22:13:35 -0400 | [diff] [blame] | 125 | mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); |
| 126 | mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); |
| 127 | |
Winson Chung | 3ed6f94 | 2012-09-20 16:07:11 -0700 | [diff] [blame] | 128 | mHandler = new Handler(); |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 129 | |
| 130 | IntentFilter filter = new IntentFilter(); |
| 131 | filter.addAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED); |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 132 | filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); |
Daniel Sandler | ebaefec | 2012-10-17 11:37:42 -0400 | [diff] [blame] | 133 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 134 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 135 | filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 136 | filter.addAction(KeyChain.ACTION_STORAGE_CHANGED); |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 137 | mContext.registerReceiver(mReceiver, filter); |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 138 | |
| 139 | IntentFilter profileFilter = new IntentFilter(); |
| 140 | profileFilter.addAction(ContactsContract.Intents.ACTION_PROFILE_CHANGED); |
| 141 | profileFilter.addAction(Intent.ACTION_USER_INFO_CHANGED); |
| 142 | mContext.registerReceiverAsUser(mProfileReceiver, UserHandle.ALL, profileFilter, |
| 143 | null, null); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void setBar(PanelBar bar) { |
| 147 | mBar = bar; |
| 148 | } |
| 149 | |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 150 | public void setService(PhoneStatusBar phoneStatusBar) { |
| 151 | mStatusBarService = phoneStatusBar; |
| 152 | } |
| 153 | |
| 154 | public PhoneStatusBar getService() { |
| 155 | return mStatusBarService; |
| 156 | } |
| 157 | |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 158 | public void setImeWindowStatus(boolean visible) { |
| 159 | mModel.onImeWindowStatusChanged(visible); |
| 160 | } |
| 161 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 162 | void setup(NetworkController networkController, BluetoothController bluetoothController, |
Svetoslav | 79578b2 | 2013-04-29 16:55:57 -0700 | [diff] [blame] | 163 | BatteryController batteryController, LocationController locationController, |
| 164 | RotationLockController rotationLockController) { |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 165 | mBluetoothController = bluetoothController; |
Svetoslav | 79578b2 | 2013-04-29 16:55:57 -0700 | [diff] [blame] | 166 | mRotationLockController = rotationLockController; |
David Christie | 03ed012 | 2013-07-30 18:11:23 -0700 | [diff] [blame] | 167 | mLocationController = locationController; |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 168 | |
| 169 | setupQuickSettings(); |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 170 | updateResources(); |
David Christie | 03ed012 | 2013-07-30 18:11:23 -0700 | [diff] [blame] | 171 | applyLocationEnabledStatus(); |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 172 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 173 | networkController.addNetworkSignalChangedCallback(mModel); |
| 174 | bluetoothController.addStateChangedCallback(mModel); |
| 175 | batteryController.addStateChangedCallback(mModel); |
David Christie | 03ed012 | 2013-07-30 18:11:23 -0700 | [diff] [blame] | 176 | locationController.addSettingsChangedCallback(mModel); |
Svetoslav | 79578b2 | 2013-04-29 16:55:57 -0700 | [diff] [blame] | 177 | rotationLockController.addRotationLockControllerCallback(mModel); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 180 | private void queryForSslCaCerts() { |
| 181 | mQueryCertTask = new AsyncTask<Void, Void, Pair<Boolean, Boolean>>() { |
| 182 | @Override |
| 183 | protected Pair<Boolean, Boolean> doInBackground(Void... params) { |
Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 184 | boolean hasCert = DevicePolicyManager.hasAnyCaCertsInstalled(); |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 185 | boolean isManaged = mDevicePolicyManager.getDeviceOwner() != null; |
| 186 | |
| 187 | return Pair.create(hasCert, isManaged); |
| 188 | } |
| 189 | @Override |
| 190 | protected void onPostExecute(Pair<Boolean, Boolean> result) { |
| 191 | super.onPostExecute(result); |
| 192 | boolean hasCert = result.first; |
| 193 | boolean isManaged = result.second; |
| 194 | mModel.setSslCaCertWarningTileInfo(hasCert, isManaged); |
| 195 | } |
| 196 | }; |
| 197 | mQueryCertTask.execute(); |
| 198 | } |
| 199 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 200 | private void queryForUserInformation() { |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 201 | Context currentUserContext = null; |
| 202 | UserInfo userInfo = null; |
| 203 | try { |
| 204 | userInfo = ActivityManagerNative.getDefault().getCurrentUser(); |
| 205 | currentUserContext = mContext.createPackageContextAsUser("android", 0, |
| 206 | new UserHandle(userInfo.id)); |
| 207 | } catch (NameNotFoundException e) { |
| 208 | Log.e(TAG, "Couldn't create user context", e); |
| 209 | throw new RuntimeException(e); |
| 210 | } catch (RemoteException e) { |
| 211 | Log.e(TAG, "Couldn't get user info", e); |
| 212 | } |
| 213 | final int userId = userInfo.id; |
Amith Yamasani | 7277d5d | 2012-10-30 14:32:45 -0700 | [diff] [blame] | 214 | final String userName = userInfo.name; |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 215 | |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 216 | final Context context = currentUserContext; |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 217 | mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() { |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 218 | @Override |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 219 | protected Pair<String, Drawable> doInBackground(Void... params) { |
Amith Yamasani | 27db468 | 2013-03-30 17:07:47 -0700 | [diff] [blame] | 220 | final UserManager um = UserManager.get(mContext); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 221 | |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 222 | // Fall back to the UserManager nickname if we can't read the name from the local |
| 223 | // profile below. |
Amith Yamasani | 7277d5d | 2012-10-30 14:32:45 -0700 | [diff] [blame] | 224 | String name = userName; |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 225 | Drawable avatar = null; |
| 226 | Bitmap rawAvatar = um.getUserIcon(userId); |
| 227 | if (rawAvatar != null) { |
| 228 | avatar = new BitmapDrawable(mContext.getResources(), rawAvatar); |
| 229 | } else { |
| 230 | avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 231 | mUseDefaultAvatar = true; |
Adam Powell | db43f47 | 2012-10-07 15:40:00 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Amith Yamasani | 7277d5d | 2012-10-30 14:32:45 -0700 | [diff] [blame] | 234 | // If it's a single-user device, get the profile name, since the nickname is not |
| 235 | // usually valid |
| 236 | if (um.getUsers().size() <= 1) { |
| 237 | // Try and read the display name from the local profile |
| 238 | final Cursor cursor = context.getContentResolver().query( |
| 239 | Profile.CONTENT_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME}, |
| 240 | null, null, null); |
| 241 | if (cursor != null) { |
| 242 | try { |
| 243 | if (cursor.moveToFirst()) { |
| 244 | name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME)); |
| 245 | } |
| 246 | } finally { |
| 247 | cursor.close(); |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 248 | } |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 249 | } |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 250 | } |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 251 | return new Pair<String, Drawable>(name, avatar); |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Override |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 255 | protected void onPostExecute(Pair<String, Drawable> result) { |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 256 | super.onPostExecute(result); |
| 257 | mModel.setUserTileInfo(result.first, result.second); |
| 258 | mUserInfoTask = null; |
| 259 | } |
| 260 | }; |
| 261 | mUserInfoTask.execute(); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | private void setupQuickSettings() { |
| 265 | // Setup the tiles that we are going to be showing (including the temporary ones) |
| 266 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 267 | |
| 268 | addUserTiles(mContainerView, inflater); |
| 269 | addSystemTiles(mContainerView, inflater); |
| 270 | addTemporaryTiles(mContainerView, inflater); |
| 271 | |
| 272 | queryForUserInformation(); |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 273 | queryForSslCaCerts(); |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 274 | mTilesSetUp = true; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 277 | private void startSettingsActivity(String action) { |
| 278 | Intent intent = new Intent(action); |
| 279 | startSettingsActivity(intent); |
| 280 | } |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 281 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 282 | private void startSettingsActivity(Intent intent) { |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 283 | startSettingsActivity(intent, true); |
| 284 | } |
| 285 | |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 286 | private void collapsePanels() { |
| 287 | getService().animateCollapsePanels(); |
| 288 | } |
| 289 | |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 290 | private void startSettingsActivity(Intent intent, boolean onlyProvisioned) { |
| 291 | if (onlyProvisioned && !getService().isDeviceProvisioned()) return; |
| 292 | try { |
| 293 | // Dismiss the lock screen when Settings starts. |
| 294 | ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity(); |
| 295 | } catch (RemoteException e) { |
| 296 | } |
Winson Chung | 6072b00 | 2012-09-11 17:10:10 -0700 | [diff] [blame] | 297 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Michael Jurka | 0988524 | 2012-09-24 14:42:01 -0700 | [diff] [blame] | 298 | mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 299 | collapsePanels(); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 302 | private void addUserTiles(ViewGroup parent, LayoutInflater inflater) { |
| 303 | QuickSettingsTileView userTile = (QuickSettingsTileView) |
| 304 | inflater.inflate(R.layout.quick_settings_tile, parent, false); |
| 305 | userTile.setContent(R.layout.quick_settings_tile_user, inflater); |
Winson Chung | 3ed6f94 | 2012-09-20 16:07:11 -0700 | [diff] [blame] | 306 | userTile.setOnClickListener(new View.OnClickListener() { |
| 307 | @Override |
| 308 | public void onClick(View v) { |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 309 | collapsePanels(); |
Amith Yamasani | 27db468 | 2013-03-30 17:07:47 -0700 | [diff] [blame] | 310 | final UserManager um = UserManager.get(mContext); |
Winson Chung | ada86cb | 2012-10-11 12:48:36 -0700 | [diff] [blame] | 311 | if (um.getUsers(true).size() > 1) { |
Jim Miller | 8a26b43 | 2013-10-30 15:23:46 -0700 | [diff] [blame] | 312 | // Since keyguard and systemui were merged into the same process to save |
| 313 | // memory, they share the same Looper and graphics context. As a result, |
| 314 | // there's no way to allow concurrent animation while keyguard inflates. |
| 315 | // The workaround is to add a slight delay to allow the animation to finish. |
| 316 | mHandler.postDelayed(new Runnable() { |
| 317 | public void run() { |
| 318 | try { |
| 319 | WindowManagerGlobal.getWindowManagerService().lockNow(null); |
| 320 | } catch (RemoteException e) { |
| 321 | Log.e(TAG, "Couldn't show user switcher", e); |
| 322 | } |
| 323 | } |
| 324 | }, 400); // TODO: ideally this would be tied to the collapse of the panel |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 325 | } else { |
| 326 | Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent( |
| 327 | mContext, v, ContactsContract.Profile.CONTENT_URI, |
| 328 | ContactsContract.QuickContact.MODE_LARGE, null); |
| 329 | mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); |
| 330 | } |
Winson Chung | 3ed6f94 | 2012-09-20 16:07:11 -0700 | [diff] [blame] | 331 | } |
| 332 | }); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 333 | mModel.addUserTile(userTile, new QuickSettingsModel.RefreshCallback() { |
| 334 | @Override |
| 335 | public void refreshView(QuickSettingsTileView view, State state) { |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 336 | UserState us = (UserState) state; |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 337 | ImageView iv = (ImageView) view.findViewById(R.id.user_imageview); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 338 | TextView tv = (TextView) view.findViewById(R.id.user_textview); |
| 339 | tv.setText(state.label); |
Winson Chung | 7a6355b | 2012-10-08 18:19:09 -0700 | [diff] [blame] | 340 | iv.setImageDrawable(us.avatar); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 341 | view.setContentDescription(mContext.getString( |
| 342 | R.string.accessibility_quick_settings_user, state.label)); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 343 | } |
| 344 | }); |
| 345 | parent.addView(userTile); |
| 346 | mDynamicSpannedTiles.add(userTile); |
| 347 | |
Daniel Sandler | 3679bf5 | 2012-10-16 21:30:28 -0400 | [diff] [blame] | 348 | // Brightness |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 349 | final QuickSettingsBasicTile brightnessTile |
| 350 | = new QuickSettingsBasicTile(mContext); |
| 351 | brightnessTile.setImageResource(R.drawable.ic_qs_brightness_auto_off); |
Daniel Sandler | 3679bf5 | 2012-10-16 21:30:28 -0400 | [diff] [blame] | 352 | brightnessTile.setOnClickListener(new View.OnClickListener() { |
| 353 | @Override |
| 354 | public void onClick(View v) { |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 355 | collapsePanels(); |
Daniel Sandler | 3679bf5 | 2012-10-16 21:30:28 -0400 | [diff] [blame] | 356 | showBrightnessDialog(); |
| 357 | } |
| 358 | }); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 359 | mModel.addBrightnessTile(brightnessTile, |
| 360 | new QuickSettingsModel.BasicRefreshCallback(brightnessTile)); |
Daniel Sandler | 3679bf5 | 2012-10-16 21:30:28 -0400 | [diff] [blame] | 361 | parent.addView(brightnessTile); |
| 362 | mDynamicSpannedTiles.add(brightnessTile); |
| 363 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 364 | // Settings tile |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 365 | final QuickSettingsBasicTile settingsTile = new QuickSettingsBasicTile(mContext); |
| 366 | settingsTile.setImageResource(R.drawable.ic_qs_settings); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 367 | settingsTile.setOnClickListener(new View.OnClickListener() { |
| 368 | @Override |
| 369 | public void onClick(View v) { |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 370 | startSettingsActivity(android.provider.Settings.ACTION_SETTINGS); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 371 | } |
| 372 | }); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 373 | mModel.addSettingsTile(settingsTile, |
| 374 | new QuickSettingsModel.BasicRefreshCallback(settingsTile)); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 375 | parent.addView(settingsTile); |
| 376 | mDynamicSpannedTiles.add(settingsTile); |
| 377 | } |
| 378 | |
| 379 | private void addSystemTiles(ViewGroup parent, LayoutInflater inflater) { |
| 380 | // Wi-fi |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 381 | final QuickSettingsTileView wifiTile = (QuickSettingsTileView) |
| 382 | inflater.inflate(R.layout.quick_settings_tile, parent, false); |
| 383 | wifiTile.setContent(R.layout.quick_settings_tile_wifi, inflater); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 384 | wifiTile.setOnClickListener(new View.OnClickListener() { |
| 385 | @Override |
| 386 | public void onClick(View v) { |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 387 | startSettingsActivity(android.provider.Settings.ACTION_WIFI_SETTINGS); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 388 | } |
| 389 | }); |
Daniel Sandler | ab51002 | 2012-10-22 22:13:35 -0400 | [diff] [blame] | 390 | if (LONG_PRESS_TOGGLES) { |
| 391 | wifiTile.setOnLongClickListener(new View.OnLongClickListener() { |
| 392 | @Override |
| 393 | public boolean onLongClick(View v) { |
| 394 | final boolean enable = |
| 395 | (mWifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED); |
| 396 | new AsyncTask<Void, Void, Void>() { |
| 397 | @Override |
| 398 | protected Void doInBackground(Void... args) { |
| 399 | // Disable tethering if enabling Wifi |
| 400 | final int wifiApState = mWifiManager.getWifiApState(); |
| 401 | if (enable && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) || |
| 402 | (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) { |
| 403 | mWifiManager.setWifiApEnabled(null, false); |
| 404 | } |
| 405 | |
| 406 | mWifiManager.setWifiEnabled(enable); |
| 407 | return null; |
| 408 | } |
| 409 | }.execute(); |
| 410 | wifiTile.setPressed(false); |
| 411 | return true; |
| 412 | }} ); |
| 413 | } |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 414 | mModel.addWifiTile(wifiTile, new NetworkActivityCallback() { |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 415 | @Override |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 416 | public void refreshView(QuickSettingsTileView view, State state) { |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 417 | WifiState wifiState = (WifiState) state; |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 418 | ImageView iv = (ImageView) view.findViewById(R.id.image); |
| 419 | iv.setImageResource(wifiState.iconId); |
| 420 | setActivity(view, wifiState); |
| 421 | TextView tv = (TextView) view.findViewById(R.id.text); |
| 422 | tv.setText(wifiState.label); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 423 | wifiTile.setContentDescription(mContext.getString( |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 424 | R.string.accessibility_quick_settings_wifi, |
| 425 | wifiState.signalContentDescription, |
| 426 | (wifiState.connected) ? wifiState.label : "")); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 427 | } |
| 428 | }); |
| 429 | parent.addView(wifiTile); |
| 430 | |
Daniel Sandler | 5052805 | 2012-11-07 23:39:41 -0500 | [diff] [blame] | 431 | if (mModel.deviceHasMobileData()) { |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 432 | // RSSI |
| 433 | QuickSettingsTileView rssiTile = (QuickSettingsTileView) |
| 434 | inflater.inflate(R.layout.quick_settings_tile, parent, false); |
| 435 | rssiTile.setContent(R.layout.quick_settings_tile_rssi, inflater); |
| 436 | rssiTile.setOnClickListener(new View.OnClickListener() { |
| 437 | @Override |
| 438 | public void onClick(View v) { |
| 439 | Intent intent = new Intent(); |
| 440 | intent.setComponent(new ComponentName( |
| 441 | "com.android.settings", |
| 442 | "com.android.settings.Settings$DataUsageSummaryActivity")); |
| 443 | startSettingsActivity(intent); |
| 444 | } |
| 445 | }); |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 446 | mModel.addRSSITile(rssiTile, new NetworkActivityCallback() { |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 447 | @Override |
| 448 | public void refreshView(QuickSettingsTileView view, State state) { |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 449 | RSSIState rssiState = (RSSIState) state; |
| 450 | ImageView iv = (ImageView) view.findViewById(R.id.rssi_image); |
| 451 | ImageView iov = (ImageView) view.findViewById(R.id.rssi_overlay_image); |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 452 | TextView tv = (TextView) view.findViewById(R.id.rssi_textview); |
Fabrice Di Meglio | 16b9f07 | 2013-01-11 15:06:31 -0800 | [diff] [blame] | 453 | // Force refresh |
| 454 | iv.setImageDrawable(null); |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 455 | iv.setImageResource(rssiState.signalIconId); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 456 | |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 457 | if (rssiState.dataTypeIconId > 0) { |
| 458 | iov.setImageResource(rssiState.dataTypeIconId); |
| 459 | } else { |
| 460 | iov.setImageDrawable(null); |
| 461 | } |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 462 | setActivity(view, rssiState); |
| 463 | |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 464 | tv.setText(state.label); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 465 | view.setContentDescription(mContext.getResources().getString( |
| 466 | R.string.accessibility_quick_settings_mobile, |
| 467 | rssiState.signalContentDescription, rssiState.dataContentDescription, |
| 468 | state.label)); |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 469 | } |
| 470 | }); |
| 471 | parent.addView(rssiTile); |
| 472 | } |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 473 | |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 474 | // Rotation Lock |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 475 | if (mContext.getResources().getBoolean(R.bool.quick_settings_show_rotation_lock) |
| 476 | || DEBUG_GONE_TILES) { |
| 477 | final QuickSettingsBasicTile rotationLockTile |
| 478 | = new QuickSettingsBasicTile(mContext); |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 479 | rotationLockTile.setOnClickListener(new View.OnClickListener() { |
| 480 | @Override |
Svetoslav | 79578b2 | 2013-04-29 16:55:57 -0700 | [diff] [blame] | 481 | public void onClick(View view) { |
| 482 | final boolean locked = mRotationLockController.isRotationLocked(); |
| 483 | mRotationLockController.setRotationLocked(!locked); |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 484 | } |
| 485 | }); |
Svetoslav | 79578b2 | 2013-04-29 16:55:57 -0700 | [diff] [blame] | 486 | mModel.addRotationLockTile(rotationLockTile, mRotationLockController, |
| 487 | new QuickSettingsModel.RefreshCallback() { |
| 488 | @Override |
| 489 | public void refreshView(QuickSettingsTileView view, State state) { |
| 490 | QuickSettingsModel.RotationLockState rotationLockState = |
| 491 | (QuickSettingsModel.RotationLockState) state; |
| 492 | view.setVisibility(rotationLockState.visible |
| 493 | ? View.VISIBLE : View.GONE); |
| 494 | if (state.iconId != 0) { |
| 495 | // needed to flush any cached IDs |
| 496 | rotationLockTile.setImageDrawable(null); |
| 497 | rotationLockTile.setImageResource(state.iconId); |
| 498 | } |
| 499 | if (state.label != null) { |
| 500 | rotationLockTile.setText(state.label); |
| 501 | } |
| 502 | } |
| 503 | }); |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 504 | parent.addView(rotationLockTile); |
| 505 | } |
| 506 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 507 | // Battery |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 508 | final QuickSettingsTileView batteryTile = (QuickSettingsTileView) |
| 509 | inflater.inflate(R.layout.quick_settings_tile, parent, false); |
| 510 | batteryTile.setContent(R.layout.quick_settings_tile_battery, inflater); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 511 | batteryTile.setOnClickListener(new View.OnClickListener() { |
| 512 | @Override |
| 513 | public void onClick(View v) { |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 514 | startSettingsActivity(Intent.ACTION_POWER_USAGE_SUMMARY); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 515 | } |
| 516 | }); |
| 517 | mModel.addBatteryTile(batteryTile, new QuickSettingsModel.RefreshCallback() { |
| 518 | @Override |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 519 | public void refreshView(QuickSettingsTileView unused, State state) { |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 520 | QuickSettingsModel.BatteryState batteryState = |
| 521 | (QuickSettingsModel.BatteryState) state; |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 522 | String t; |
| 523 | if (batteryState.batteryLevel == 100) { |
| 524 | t = mContext.getString(R.string.quick_settings_battery_charged_label); |
| 525 | } else { |
| 526 | t = batteryState.pluggedIn |
| 527 | ? mContext.getString(R.string.quick_settings_battery_charging_label, |
| 528 | batteryState.batteryLevel) |
| 529 | : mContext.getString(R.string.status_bar_settings_battery_meter_format, |
| 530 | batteryState.batteryLevel); |
| 531 | } |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 532 | ((TextView)batteryTile.findViewById(R.id.text)).setText(t); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 533 | batteryTile.setContentDescription( |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 534 | mContext.getString(R.string.accessibility_quick_settings_battery, t)); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 535 | } |
| 536 | }); |
| 537 | parent.addView(batteryTile); |
| 538 | |
| 539 | // Airplane Mode |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 540 | final QuickSettingsBasicTile airplaneTile |
| 541 | = new QuickSettingsBasicTile(mContext); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 542 | mModel.addAirplaneModeTile(airplaneTile, new QuickSettingsModel.RefreshCallback() { |
| 543 | @Override |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 544 | public void refreshView(QuickSettingsTileView unused, State state) { |
| 545 | airplaneTile.setImageResource(state.iconId); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 546 | |
| 547 | String airplaneState = mContext.getString( |
| 548 | (state.enabled) ? R.string.accessibility_desc_on |
| 549 | : R.string.accessibility_desc_off); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 550 | airplaneTile.setContentDescription( |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 551 | mContext.getString(R.string.accessibility_quick_settings_airplane, airplaneState)); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 552 | airplaneTile.setText(state.label); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 553 | } |
| 554 | }); |
| 555 | parent.addView(airplaneTile); |
| 556 | |
| 557 | // Bluetooth |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 558 | if (mModel.deviceSupportsBluetooth() |
| 559 | || DEBUG_GONE_TILES) { |
| 560 | final QuickSettingsBasicTile bluetoothTile |
| 561 | = new QuickSettingsBasicTile(mContext); |
Winson Chung | 6072b00 | 2012-09-11 17:10:10 -0700 | [diff] [blame] | 562 | bluetoothTile.setOnClickListener(new View.OnClickListener() { |
| 563 | @Override |
| 564 | public void onClick(View v) { |
| 565 | startSettingsActivity(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS); |
| 566 | } |
| 567 | }); |
Daniel Sandler | ab51002 | 2012-10-22 22:13:35 -0400 | [diff] [blame] | 568 | if (LONG_PRESS_TOGGLES) { |
| 569 | bluetoothTile.setOnLongClickListener(new View.OnLongClickListener() { |
| 570 | @Override |
| 571 | public boolean onLongClick(View v) { |
| 572 | if (mBluetoothAdapter.isEnabled()) { |
| 573 | mBluetoothAdapter.disable(); |
| 574 | } else { |
| 575 | mBluetoothAdapter.enable(); |
| 576 | } |
| 577 | bluetoothTile.setPressed(false); |
| 578 | return true; |
| 579 | }}); |
| 580 | } |
Winson Chung | 6072b00 | 2012-09-11 17:10:10 -0700 | [diff] [blame] | 581 | mModel.addBluetoothTile(bluetoothTile, new QuickSettingsModel.RefreshCallback() { |
| 582 | @Override |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 583 | public void refreshView(QuickSettingsTileView unused, State state) { |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 584 | BluetoothState bluetoothState = (BluetoothState) state; |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 585 | bluetoothTile.setImageResource(state.iconId); |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 586 | |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 587 | /* |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 588 | Resources r = mContext.getResources(); |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 589 | //TODO: Show connected bluetooth device label |
| 590 | Set<BluetoothDevice> btDevices = |
| 591 | mBluetoothController.getBondedBluetoothDevices(); |
| 592 | if (btDevices.size() == 1) { |
| 593 | // Show the name of the bluetooth device you are connected to |
| 594 | label = btDevices.iterator().next().getName(); |
| 595 | } else if (btDevices.size() > 1) { |
| 596 | // Show a generic label about the number of bluetooth devices |
| 597 | label = r.getString(R.string.quick_settings_bluetooth_multiple_devices_label, |
| 598 | btDevices.size()); |
| 599 | } |
| 600 | */ |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 601 | bluetoothTile.setContentDescription(mContext.getString( |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 602 | R.string.accessibility_quick_settings_bluetooth, |
| 603 | bluetoothState.stateContentDescription)); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 604 | bluetoothTile.setText(state.label); |
Winson Chung | 6072b00 | 2012-09-11 17:10:10 -0700 | [diff] [blame] | 605 | } |
| 606 | }); |
| 607 | parent.addView(bluetoothTile); |
| 608 | } |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 609 | |
David Christie | 03ed012 | 2013-07-30 18:11:23 -0700 | [diff] [blame] | 610 | // Location |
| 611 | final QuickSettingsBasicTile locationTile |
| 612 | = new QuickSettingsBasicTile(mContext); |
| 613 | locationTile.setImageResource(R.drawable.ic_qs_location_on); |
| 614 | locationTile.setTextResource(R.string.quick_settings_location_label); |
| 615 | locationTile.setOnClickListener(new View.OnClickListener() { |
| 616 | @Override |
| 617 | public void onClick(View v) { |
| 618 | startSettingsActivity(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
| 619 | } |
| 620 | }); |
| 621 | if (LONG_PRESS_TOGGLES) { |
| 622 | locationTile.setOnLongClickListener(new View.OnLongClickListener() { |
| 623 | @Override |
| 624 | public boolean onLongClick(View v) { |
| 625 | boolean newLocationEnabledState = !mLocationController.isLocationEnabled(); |
David Christie | b12ba93 | 2013-09-03 17:15:28 -0700 | [diff] [blame] | 626 | if (mLocationController.setLocationEnabled(newLocationEnabledState) |
| 627 | && newLocationEnabledState) { |
| 628 | // If we've successfully switched from location off to on, close the |
| 629 | // notifications tray to show the network location provider consent dialog. |
David Christie | 03ed012 | 2013-07-30 18:11:23 -0700 | [diff] [blame] | 630 | Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 631 | mContext.sendBroadcast(closeDialog); |
| 632 | } |
| 633 | return true; // Consume click |
| 634 | }} ); |
| 635 | } |
Victoria Lease | 3ac54a3 | 2013-10-14 14:54:10 -0700 | [diff] [blame] | 636 | mModel.addLocationTile(locationTile, new QuickSettingsModel.RefreshCallback() { |
| 637 | @Override |
| 638 | public void refreshView(QuickSettingsTileView unused, State state) { |
| 639 | locationTile.setImageResource(state.iconId); |
| 640 | String locationState = mContext.getString( |
| 641 | (state.enabled) ? R.string.accessibility_desc_on |
| 642 | : R.string.accessibility_desc_off); |
| 643 | locationTile.setContentDescription(mContext.getString( |
| 644 | R.string.accessibility_quick_settings_location, |
| 645 | locationState)); |
| 646 | locationTile.setText(state.label); |
| 647 | } |
| 648 | }); |
David Christie | 03ed012 | 2013-07-30 18:11:23 -0700 | [diff] [blame] | 649 | parent.addView(locationTile); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | private void addTemporaryTiles(final ViewGroup parent, final LayoutInflater inflater) { |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 653 | // Alarm tile |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 654 | final QuickSettingsBasicTile alarmTile |
| 655 | = new QuickSettingsBasicTile(mContext); |
| 656 | alarmTile.setImageResource(R.drawable.ic_qs_alarm_on); |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 657 | alarmTile.setOnClickListener(new View.OnClickListener() { |
| 658 | @Override |
| 659 | public void onClick(View v) { |
Daniel Sandler | 0e9925a | 2013-09-13 14:49:39 -0400 | [diff] [blame] | 660 | startSettingsActivity(AlarmClock.ACTION_SHOW_ALARMS); |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 661 | } |
| 662 | }); |
| 663 | mModel.addAlarmTile(alarmTile, new QuickSettingsModel.RefreshCallback() { |
| 664 | @Override |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 665 | public void refreshView(QuickSettingsTileView unused, State alarmState) { |
| 666 | alarmTile.setText(alarmState.label); |
| 667 | alarmTile.setVisibility(alarmState.enabled ? View.VISIBLE : View.GONE); |
| 668 | alarmTile.setContentDescription(mContext.getString( |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 669 | R.string.accessibility_quick_settings_alarm, alarmState.label)); |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 670 | } |
| 671 | }); |
| 672 | parent.addView(alarmTile); |
| 673 | |
Jeff Brown | 635e915 | 2013-11-07 00:38:14 -0800 | [diff] [blame] | 674 | // Remote Display |
| 675 | QuickSettingsBasicTile remoteDisplayTile |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 676 | = new QuickSettingsBasicTile(mContext); |
Jeff Brown | 635e915 | 2013-11-07 00:38:14 -0800 | [diff] [blame] | 677 | remoteDisplayTile.setOnClickListener(new View.OnClickListener() { |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 678 | @Override |
| 679 | public void onClick(View v) { |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame^] | 680 | collapsePanels(); |
| 681 | |
| 682 | final Dialog[] dialog = new Dialog[1]; |
| 683 | dialog[0] = MediaRouteDialogPresenter.createDialog(mContext, |
| 684 | MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY, |
| 685 | new View.OnClickListener() { |
| 686 | @Override |
| 687 | public void onClick(View v) { |
| 688 | dialog[0].dismiss(); |
| 689 | startSettingsActivity( |
| 690 | android.provider.Settings.ACTION_WIFI_DISPLAY_SETTINGS); |
| 691 | } |
| 692 | }); |
| 693 | dialog[0].getWindow().setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY); |
| 694 | dialog[0].show(); |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 695 | } |
| 696 | }); |
Jeff Brown | 635e915 | 2013-11-07 00:38:14 -0800 | [diff] [blame] | 697 | mModel.addRemoteDisplayTile(remoteDisplayTile, |
| 698 | new QuickSettingsModel.BasicRefreshCallback(remoteDisplayTile) |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 699 | .setShowWhenEnabled(true)); |
Jeff Brown | 635e915 | 2013-11-07 00:38:14 -0800 | [diff] [blame] | 700 | parent.addView(remoteDisplayTile); |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 701 | |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 702 | if (SHOW_IME_TILE || DEBUG_GONE_TILES) { |
Daniel Sandler | dd68da8 | 2012-10-01 10:19:09 -0400 | [diff] [blame] | 703 | // IME |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 704 | final QuickSettingsBasicTile imeTile |
| 705 | = new QuickSettingsBasicTile(mContext); |
| 706 | imeTile.setImageResource(R.drawable.ic_qs_ime); |
Daniel Sandler | dd68da8 | 2012-10-01 10:19:09 -0400 | [diff] [blame] | 707 | imeTile.setOnClickListener(new View.OnClickListener() { |
| 708 | @Override |
| 709 | public void onClick(View v) { |
| 710 | try { |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 711 | collapsePanels(); |
Daniel Sandler | dd68da8 | 2012-10-01 10:19:09 -0400 | [diff] [blame] | 712 | Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER); |
| 713 | PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
| 714 | pendingIntent.send(); |
| 715 | } catch (Exception e) {} |
Winson Chung | 2a4057d | 2012-09-12 18:30:06 -0700 | [diff] [blame] | 716 | } |
Daniel Sandler | dd68da8 | 2012-10-01 10:19:09 -0400 | [diff] [blame] | 717 | }); |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 718 | mModel.addImeTile(imeTile, |
| 719 | new QuickSettingsModel.BasicRefreshCallback(imeTile) |
| 720 | .setShowWhenEnabled(true)); |
Daniel Sandler | dd68da8 | 2012-10-01 10:19:09 -0400 | [diff] [blame] | 721 | parent.addView(imeTile); |
| 722 | } |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 723 | |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 724 | // Bug reports |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 725 | final QuickSettingsBasicTile bugreportTile |
| 726 | = new QuickSettingsBasicTile(mContext); |
| 727 | bugreportTile.setImageResource(com.android.internal.R.drawable.stat_sys_adb); |
| 728 | bugreportTile.setTextResource(com.android.internal.R.string.bugreport_title); |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 729 | bugreportTile.setOnClickListener(new View.OnClickListener() { |
| 730 | @Override |
| 731 | public void onClick(View v) { |
Daniel Sandler | b5538e6 | 2013-04-12 15:16:53 -0400 | [diff] [blame] | 732 | collapsePanels(); |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 733 | showBugreportDialog(); |
| 734 | } |
| 735 | }); |
| 736 | mModel.addBugreportTile(bugreportTile, new QuickSettingsModel.RefreshCallback() { |
| 737 | @Override |
| 738 | public void refreshView(QuickSettingsTileView view, State state) { |
| 739 | view.setVisibility(state.enabled ? View.VISIBLE : View.GONE); |
| 740 | } |
| 741 | }); |
| 742 | parent.addView(bugreportTile); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 743 | /* |
| 744 | QuickSettingsTileView mediaTile = (QuickSettingsTileView) |
| 745 | inflater.inflate(R.layout.quick_settings_tile, parent, false); |
| 746 | mediaTile.setContent(R.layout.quick_settings_tile_media, inflater); |
| 747 | parent.addView(mediaTile); |
| 748 | QuickSettingsTileView imeTile = (QuickSettingsTileView) |
| 749 | inflater.inflate(R.layout.quick_settings_tile, parent, false); |
| 750 | imeTile.setContent(R.layout.quick_settings_tile_ime, inflater); |
| 751 | imeTile.setOnClickListener(new View.OnClickListener() { |
| 752 | @Override |
| 753 | public void onClick(View v) { |
| 754 | parent.removeViewAt(0); |
| 755 | } |
| 756 | }); |
| 757 | parent.addView(imeTile); |
| 758 | */ |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 759 | |
| 760 | // SSL CA Cert Warning. |
Maggie Benthall | 68881e4 | 2013-09-17 19:23:59 -0400 | [diff] [blame] | 761 | final QuickSettingsBasicTile sslCaCertWarningTile = |
| 762 | new QuickSettingsBasicTile(mContext, null, R.layout.quick_settings_tile_monitoring); |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 763 | sslCaCertWarningTile.setOnClickListener(new View.OnClickListener() { |
| 764 | @Override |
| 765 | public void onClick(View v) { |
| 766 | collapsePanels(); |
Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 767 | startSettingsActivity(Settings.ACTION_MONITORING_CERT_INFO); |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 768 | } |
| 769 | }); |
| 770 | |
| 771 | sslCaCertWarningTile.setImageResource( |
| 772 | com.android.internal.R.drawable.indicator_input_error); |
| 773 | sslCaCertWarningTile.setTextResource(R.string.ssl_ca_cert_warning); |
| 774 | |
| 775 | mModel.addSslCaCertWarningTile(sslCaCertWarningTile, |
| 776 | new QuickSettingsModel.BasicRefreshCallback(sslCaCertWarningTile) |
| 777 | .setShowWhenEnabled(true)); |
| 778 | parent.addView(sslCaCertWarningTile); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | void updateResources() { |
| 782 | Resources r = mContext.getResources(); |
| 783 | |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 784 | // Update the model |
| 785 | mModel.updateResources(); |
| 786 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 787 | // Update the User, Time, and Settings tiles spans, and reset everything else |
| 788 | int span = r.getInteger(R.integer.quick_settings_user_time_settings_tile_span); |
| 789 | for (QuickSettingsTileView v : mDynamicSpannedTiles) { |
| 790 | v.setColumnSpan(span); |
| 791 | } |
Daniel Sandler | 101784e | 2012-10-15 13:39:38 -0400 | [diff] [blame] | 792 | ((QuickSettingsContainerView)mContainerView).updateResources(); |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 793 | mContainerView.requestLayout(); |
| 794 | } |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 795 | |
Winson Chung | 3ed6f94 | 2012-09-20 16:07:11 -0700 | [diff] [blame] | 796 | |
Winson Chung | 1679b36 | 2012-09-10 20:08:01 -0700 | [diff] [blame] | 797 | private void showBrightnessDialog() { |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 798 | Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG); |
| 799 | mContext.sendBroadcast(intent); |
Winson Chung | 1679b36 | 2012-09-10 20:08:01 -0700 | [diff] [blame] | 800 | } |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 801 | |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 802 | private void showBugreportDialog() { |
| 803 | final AlertDialog.Builder builder = new AlertDialog.Builder(mContext); |
| 804 | builder.setPositiveButton(com.android.internal.R.string.report, new OnClickListener() { |
| 805 | @Override |
| 806 | public void onClick(DialogInterface dialog, int which) { |
| 807 | if (which == DialogInterface.BUTTON_POSITIVE) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 808 | // Add a little delay before executing, to give the |
| 809 | // dialog a chance to go away before it takes a |
| 810 | // screenshot. |
| 811 | mHandler.postDelayed(new Runnable() { |
| 812 | @Override public void run() { |
| 813 | try { |
| 814 | ActivityManagerNative.getDefault() |
| 815 | .requestBugReport(); |
| 816 | } catch (RemoteException e) { |
| 817 | } |
| 818 | } |
| 819 | }, 500); |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | }); |
| 823 | builder.setMessage(com.android.internal.R.string.bugreport_message); |
| 824 | builder.setTitle(com.android.internal.R.string.bugreport_title); |
| 825 | builder.setCancelable(true); |
| 826 | final Dialog dialog = builder.create(); |
| 827 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
Daniel Sandler | b64c3dd | 2012-10-09 00:37:53 -0400 | [diff] [blame] | 828 | try { |
| 829 | WindowManagerGlobal.getWindowManagerService().dismissKeyguard(); |
| 830 | } catch (RemoteException e) { |
| 831 | } |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 832 | dialog.show(); |
| 833 | } |
| 834 | |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 835 | private void applyBluetoothStatus() { |
| 836 | mModel.onBluetoothStateChange(mBluetoothState); |
| 837 | } |
| 838 | |
David Christie | 03ed012 | 2013-07-30 18:11:23 -0700 | [diff] [blame] | 839 | private void applyLocationEnabledStatus() { |
| 840 | mModel.onLocationSettingsChanged(mLocationController.isLocationEnabled()); |
| 841 | } |
| 842 | |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 843 | void reloadUserInfo() { |
| 844 | if (mUserInfoTask != null) { |
| 845 | mUserInfoTask.cancel(false); |
| 846 | mUserInfoTask = null; |
| 847 | } |
| 848 | if (mTilesSetUp) { |
| 849 | queryForUserInformation(); |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 850 | queryForSslCaCerts(); |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 854 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 855 | @Override |
| 856 | public void onReceive(Context context, Intent intent) { |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 857 | final String action = intent.getAction(); |
Jeff Brown | 635e915 | 2013-11-07 00:38:14 -0800 | [diff] [blame] | 858 | if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { |
Daniel Sandler | ebaefec | 2012-10-17 11:37:42 -0400 | [diff] [blame] | 859 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, |
| 860 | BluetoothAdapter.ERROR); |
| 861 | mBluetoothState.enabled = (state == BluetoothAdapter.STATE_ON); |
| 862 | applyBluetoothStatus(); |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 863 | } else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) { |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 864 | int status = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, |
| 865 | BluetoothAdapter.STATE_DISCONNECTED); |
| 866 | mBluetoothState.connected = (status == BluetoothAdapter.STATE_CONNECTED); |
| 867 | applyBluetoothStatus(); |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 868 | } else if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 869 | reloadUserInfo(); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 870 | } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { |
| 871 | if (mUseDefaultAvatar) { |
| 872 | queryForUserInformation(); |
| 873 | } |
Geoffrey Borggaard | 348fc48 | 2013-08-08 14:32:39 -0400 | [diff] [blame] | 874 | } else if (KeyChain.ACTION_STORAGE_CHANGED.equals(action)) { |
| 875 | queryForSslCaCerts(); |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 876 | } |
| 877 | } |
| 878 | }; |
| 879 | |
| 880 | private final BroadcastReceiver mProfileReceiver = new BroadcastReceiver() { |
| 881 | @Override |
| 882 | public void onReceive(Context context, Intent intent) { |
| 883 | final String action = intent.getAction(); |
| 884 | if (ContactsContract.Intents.ACTION_PROFILE_CHANGED.equals(action) || |
| 885 | Intent.ACTION_USER_INFO_CHANGED.equals(action)) { |
| 886 | try { |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 887 | final int currentUser = ActivityManagerNative.getDefault().getCurrentUser().id; |
| 888 | final int changedUser = |
| 889 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, getSendingUserId()); |
| 890 | if (changedUser == currentUser) { |
Adam Powell | 6f2a3d2 | 2012-10-05 22:32:04 -0700 | [diff] [blame] | 891 | reloadUserInfo(); |
| 892 | } |
| 893 | } catch (RemoteException e) { |
| 894 | Log.e(TAG, "Couldn't get current user id for profile change", e); |
| 895 | } |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 896 | } |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 897 | |
Jeff Brown | 508257b | 2012-09-08 23:15:12 -0700 | [diff] [blame] | 898 | } |
| 899 | }; |
John Spurlock | 4367087 | 2013-09-05 16:50:21 -0400 | [diff] [blame] | 900 | |
| 901 | private abstract static class NetworkActivityCallback |
| 902 | implements QuickSettingsModel.RefreshCallback { |
| 903 | private final long mDefaultDuration = new ValueAnimator().getDuration(); |
| 904 | private final long mShortDuration = mDefaultDuration / 3; |
| 905 | |
| 906 | public void setActivity(View view, ActivityState state) { |
| 907 | setVisibility(view.findViewById(R.id.activity_in), state.activityIn); |
| 908 | setVisibility(view.findViewById(R.id.activity_out), state.activityOut); |
| 909 | } |
| 910 | |
| 911 | private void setVisibility(View view, boolean visible) { |
| 912 | final float newAlpha = visible ? 1 : 0; |
| 913 | if (view.getAlpha() != newAlpha) { |
| 914 | view.animate() |
| 915 | .setDuration(visible ? mShortDuration : mDefaultDuration) |
| 916 | .alpha(newAlpha) |
| 917 | .start(); |
| 918 | } |
| 919 | } |
| 920 | } |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 921 | } |