Winson Chung | e641b6a | 2012-09-10 17:30:27 -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 | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 20 | import android.bluetooth.BluetoothAdapter; |
| 21 | import android.bluetooth.BluetoothAdapter.BluetoothStateChangeCallback; |
| 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.ContentResolver; |
| 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
| 26 | import android.content.IntentFilter; |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 28 | import android.content.res.Resources; |
| 29 | import android.database.ContentObserver; |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 30 | import android.graphics.drawable.Drawable; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 31 | import android.hardware.display.WifiDisplayStatus; |
Daniel Sandler | 5052805 | 2012-11-07 23:39:41 -0500 | [diff] [blame] | 32 | import android.net.ConnectivityManager; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 33 | import android.os.Handler; |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 34 | import android.os.UserHandle; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 35 | import android.provider.Settings; |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 36 | import android.provider.Settings.SettingNotFoundException; |
Winson Chung | 2a4057d | 2012-09-12 18:30:06 -0700 | [diff] [blame] | 37 | import android.text.TextUtils; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 38 | import android.view.View; |
Winson Chung | 2a4057d | 2012-09-12 18:30:06 -0700 | [diff] [blame] | 39 | import android.view.inputmethod.InputMethodInfo; |
| 40 | import android.view.inputmethod.InputMethodManager; |
| 41 | import android.view.inputmethod.InputMethodSubtype; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 42 | |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 43 | import com.android.internal.view.RotationPolicy; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 44 | import com.android.systemui.R; |
| 45 | import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback; |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 46 | import com.android.systemui.statusbar.policy.BrightnessController.BrightnessStateChangeCallback; |
John Spurlock | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 47 | import com.android.systemui.statusbar.policy.CurrentUserTracker; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 48 | import com.android.systemui.statusbar.policy.LocationController.LocationGpsStateChangeCallback; |
| 49 | import com.android.systemui.statusbar.policy.NetworkController.NetworkSignalChangedCallback; |
| 50 | |
Winson Chung | 2a4057d | 2012-09-12 18:30:06 -0700 | [diff] [blame] | 51 | import java.util.List; |
| 52 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 53 | |
| 54 | class QuickSettingsModel implements BluetoothStateChangeCallback, |
| 55 | NetworkSignalChangedCallback, |
| 56 | BatteryStateChangeCallback, |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 57 | LocationGpsStateChangeCallback, |
| 58 | BrightnessStateChangeCallback { |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 59 | |
Winson Chung | 34563e2 | 2012-09-21 17:19:49 -0700 | [diff] [blame] | 60 | // Sett InputMethoManagerService |
| 61 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
| 62 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 63 | /** Represents the state of a given attribute. */ |
| 64 | static class State { |
| 65 | int iconId; |
| 66 | String label; |
| 67 | boolean enabled = false; |
| 68 | } |
| 69 | static class BatteryState extends State { |
| 70 | int batteryLevel; |
| 71 | boolean pluggedIn; |
| 72 | } |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 73 | static class RSSIState extends State { |
| 74 | int signalIconId; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 75 | String signalContentDescription; |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 76 | int dataTypeIconId; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 77 | String dataContentDescription; |
| 78 | } |
| 79 | static class WifiState extends State { |
| 80 | String signalContentDescription; |
| 81 | boolean connected; |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 82 | } |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 83 | static class UserState extends State { |
| 84 | Drawable avatar; |
| 85 | } |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 86 | static class BrightnessState extends State { |
| 87 | boolean autoBrightness; |
| 88 | } |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 89 | public static class BluetoothState extends State { |
| 90 | boolean connected = false; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 91 | String stateContentDescription; |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 92 | } |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 93 | |
| 94 | /** The callback to update a given tile. */ |
| 95 | interface RefreshCallback { |
| 96 | public void refreshView(QuickSettingsTileView view, State state); |
| 97 | } |
| 98 | |
| 99 | /** Broadcast receive to determine if there is an alarm set. */ |
| 100 | private BroadcastReceiver mAlarmIntentReceiver = new BroadcastReceiver() { |
| 101 | @Override |
| 102 | public void onReceive(Context context, Intent intent) { |
| 103 | String action = intent.getAction(); |
| 104 | if (action.equals(Intent.ACTION_ALARM_CHANGED)) { |
| 105 | onAlarmChanged(intent); |
| 106 | onNextAlarmChanged(); |
| 107 | } |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | /** ContentObserver to determine the next alarm */ |
| 112 | private class NextAlarmObserver extends ContentObserver { |
| 113 | public NextAlarmObserver(Handler handler) { |
| 114 | super(handler); |
| 115 | } |
| 116 | |
| 117 | @Override public void onChange(boolean selfChange) { |
| 118 | onNextAlarmChanged(); |
| 119 | } |
| 120 | |
| 121 | public void startObserving() { |
| 122 | final ContentResolver cr = mContext.getContentResolver(); |
| 123 | cr.registerContentObserver( |
Daniel Sandler | 0f92a80 | 2012-12-03 12:33:41 -0500 | [diff] [blame] | 124 | Settings.System.getUriFor(Settings.System.NEXT_ALARM_FORMATTED), false, this, |
| 125 | UserHandle.USER_ALL); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 129 | /** ContentObserver to watch adb */ |
| 130 | private class BugreportObserver extends ContentObserver { |
| 131 | public BugreportObserver(Handler handler) { |
| 132 | super(handler); |
| 133 | } |
| 134 | |
| 135 | @Override public void onChange(boolean selfChange) { |
| 136 | onBugreportChanged(); |
| 137 | } |
| 138 | |
| 139 | public void startObserving() { |
| 140 | final ContentResolver cr = mContext.getContentResolver(); |
| 141 | cr.registerContentObserver( |
| 142 | Settings.Secure.getUriFor(Settings.Secure.BUGREPORT_IN_POWER_MENU), false, this); |
| 143 | } |
| 144 | } |
John Spurlock | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 145 | |
| 146 | /** ContentObserver to watch brightness **/ |
| 147 | private class BrightnessObserver extends ContentObserver { |
| 148 | public BrightnessObserver(Handler handler) { |
| 149 | super(handler); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void onChange(boolean selfChange) { |
| 154 | onBrightnessLevelChanged(); |
| 155 | } |
| 156 | |
| 157 | public void startObserving() { |
| 158 | final ContentResolver cr = mContext.getContentResolver(); |
| 159 | cr.unregisterContentObserver(this); |
| 160 | cr.registerContentObserver( |
| 161 | Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE), |
| 162 | false, this, mUserTracker.getCurrentUserId()); |
| 163 | cr.registerContentObserver( |
| 164 | Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS), |
| 165 | false, this, mUserTracker.getCurrentUserId()); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | private final Context mContext; |
| 170 | private final Handler mHandler; |
| 171 | private final CurrentUserTracker mUserTracker; |
| 172 | private final NextAlarmObserver mNextAlarmObserver; |
| 173 | private final BugreportObserver mBugreportObserver; |
| 174 | private final BrightnessObserver mBrightnessObserver; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 175 | |
Daniel Sandler | 5052805 | 2012-11-07 23:39:41 -0500 | [diff] [blame] | 176 | private final boolean mHasMobileData; |
| 177 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 178 | private QuickSettingsTileView mUserTile; |
| 179 | private RefreshCallback mUserCallback; |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 180 | private UserState mUserState = new UserState(); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 181 | |
| 182 | private QuickSettingsTileView mTimeTile; |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 183 | private RefreshCallback mTimeCallback; |
| 184 | private State mTimeState = new State(); |
| 185 | |
| 186 | private QuickSettingsTileView mAlarmTile; |
| 187 | private RefreshCallback mAlarmCallback; |
| 188 | private State mAlarmState = new State(); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 189 | |
| 190 | private QuickSettingsTileView mAirplaneModeTile; |
| 191 | private RefreshCallback mAirplaneModeCallback; |
| 192 | private State mAirplaneModeState = new State(); |
| 193 | |
| 194 | private QuickSettingsTileView mWifiTile; |
| 195 | private RefreshCallback mWifiCallback; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 196 | private WifiState mWifiState = new WifiState(); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 197 | |
| 198 | private QuickSettingsTileView mWifiDisplayTile; |
| 199 | private RefreshCallback mWifiDisplayCallback; |
| 200 | private State mWifiDisplayState = new State(); |
| 201 | |
| 202 | private QuickSettingsTileView mRSSITile; |
| 203 | private RefreshCallback mRSSICallback; |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 204 | private RSSIState mRSSIState = new RSSIState(); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 205 | |
| 206 | private QuickSettingsTileView mBluetoothTile; |
| 207 | private RefreshCallback mBluetoothCallback; |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 208 | private BluetoothState mBluetoothState = new BluetoothState(); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 209 | |
| 210 | private QuickSettingsTileView mBatteryTile; |
| 211 | private RefreshCallback mBatteryCallback; |
| 212 | private BatteryState mBatteryState = new BatteryState(); |
| 213 | |
| 214 | private QuickSettingsTileView mLocationTile; |
| 215 | private RefreshCallback mLocationCallback; |
| 216 | private State mLocationState = new State(); |
| 217 | |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 218 | private QuickSettingsTileView mImeTile; |
Daniel Sandler | aca0c75 | 2012-10-01 12:59:36 -0400 | [diff] [blame] | 219 | private RefreshCallback mImeCallback = null; |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 220 | private State mImeState = new State(); |
| 221 | |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 222 | private QuickSettingsTileView mRotationLockTile; |
| 223 | private RefreshCallback mRotationLockCallback; |
| 224 | private State mRotationLockState = new State(); |
| 225 | |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 226 | private QuickSettingsTileView mBrightnessTile; |
| 227 | private RefreshCallback mBrightnessCallback; |
| 228 | private BrightnessState mBrightnessState = new BrightnessState(); |
| 229 | |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 230 | private QuickSettingsTileView mBugreportTile; |
| 231 | private RefreshCallback mBugreportCallback; |
| 232 | private State mBugreportState = new State(); |
| 233 | |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 234 | private QuickSettingsTileView mSettingsTile; |
| 235 | private RefreshCallback mSettingsCallback; |
| 236 | private State mSettingsState = new State(); |
| 237 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 238 | public QuickSettingsModel(Context context) { |
| 239 | mContext = context; |
| 240 | mHandler = new Handler(); |
John Spurlock | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 241 | mUserTracker = new CurrentUserTracker(mContext) { |
| 242 | @Override |
| 243 | public void onReceive(Context context, Intent intent) { |
| 244 | super.onReceive(context, intent); |
| 245 | onUserSwitched(); |
| 246 | } |
| 247 | }; |
| 248 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 249 | mNextAlarmObserver = new NextAlarmObserver(mHandler); |
| 250 | mNextAlarmObserver.startObserving(); |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 251 | mBugreportObserver = new BugreportObserver(mHandler); |
| 252 | mBugreportObserver.startObserving(); |
John Spurlock | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 253 | mBrightnessObserver = new BrightnessObserver(mHandler); |
| 254 | mBrightnessObserver.startObserving(); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 255 | |
Daniel Sandler | 5052805 | 2012-11-07 23:39:41 -0500 | [diff] [blame] | 256 | ConnectivityManager cm = (ConnectivityManager) |
| 257 | context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| 258 | mHasMobileData = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); |
| 259 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 260 | IntentFilter alarmIntentFilter = new IntentFilter(); |
| 261 | alarmIntentFilter.addAction(Intent.ACTION_ALARM_CHANGED); |
| 262 | context.registerReceiver(mAlarmIntentReceiver, alarmIntentFilter); |
| 263 | } |
| 264 | |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 265 | void updateResources() { |
| 266 | refreshSettingsTile(); |
| 267 | refreshBatteryTile(); |
| 268 | refreshBluetoothTile(); |
| 269 | refreshBrightnessTile(); |
| 270 | refreshRotationLockTile(); |
| 271 | } |
| 272 | |
| 273 | // Settings |
| 274 | void addSettingsTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 275 | mSettingsTile = view; |
| 276 | mSettingsCallback = cb; |
| 277 | refreshSettingsTile(); |
| 278 | } |
| 279 | void refreshSettingsTile() { |
| 280 | Resources r = mContext.getResources(); |
| 281 | mSettingsState.label = r.getString(R.string.quick_settings_settings_label); |
| 282 | mSettingsCallback.refreshView(mSettingsTile, mSettingsState); |
| 283 | } |
| 284 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 285 | // User |
| 286 | void addUserTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 287 | mUserTile = view; |
| 288 | mUserCallback = cb; |
| 289 | mUserCallback.refreshView(mUserTile, mUserState); |
| 290 | } |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 291 | void setUserTileInfo(String name, Drawable avatar) { |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 292 | mUserState.label = name; |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 293 | mUserState.avatar = avatar; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 294 | mUserCallback.refreshView(mUserTile, mUserState); |
| 295 | } |
| 296 | |
| 297 | // Time |
| 298 | void addTimeTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 299 | mTimeTile = view; |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 300 | mTimeCallback = cb; |
| 301 | mTimeCallback.refreshView(view, mTimeState); |
| 302 | } |
| 303 | |
| 304 | // Alarm |
| 305 | void addAlarmTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 306 | mAlarmTile = view; |
| 307 | mAlarmCallback = cb; |
| 308 | mAlarmCallback.refreshView(view, mAlarmState); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 309 | } |
| 310 | void onAlarmChanged(Intent intent) { |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 311 | mAlarmState.enabled = intent.getBooleanExtra("alarmSet", false); |
| 312 | mAlarmCallback.refreshView(mAlarmTile, mAlarmState); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 313 | } |
| 314 | void onNextAlarmChanged() { |
Daniel Sandler | 0f92a80 | 2012-12-03 12:33:41 -0500 | [diff] [blame] | 315 | final String alarmText = Settings.System.getStringForUser(mContext.getContentResolver(), |
| 316 | Settings.System.NEXT_ALARM_FORMATTED, |
| 317 | UserHandle.USER_CURRENT); |
| 318 | mAlarmState.label = alarmText; |
| 319 | |
| 320 | // When switching users, this is the only clue we're going to get about whether the |
| 321 | // alarm is actually set, since we won't get the ACTION_ALARM_CHANGED broadcast |
| 322 | mAlarmState.enabled = ! TextUtils.isEmpty(alarmText); |
| 323 | |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 324 | mAlarmCallback.refreshView(mAlarmTile, mAlarmState); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // Airplane Mode |
| 328 | void addAirplaneModeTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 329 | mAirplaneModeTile = view; |
| 330 | mAirplaneModeTile.setOnClickListener(new View.OnClickListener() { |
| 331 | @Override |
| 332 | public void onClick(View v) { |
| 333 | if (mAirplaneModeState.enabled) { |
| 334 | setAirplaneModeState(false); |
| 335 | } else { |
| 336 | setAirplaneModeState(true); |
| 337 | } |
| 338 | } |
| 339 | }); |
| 340 | mAirplaneModeCallback = cb; |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 341 | int airplaneMode = Settings.Global.getInt(mContext.getContentResolver(), |
| 342 | Settings.Global.AIRPLANE_MODE_ON, 0); |
| 343 | onAirplaneModeChanged(airplaneMode != 0); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 344 | } |
| 345 | private void setAirplaneModeState(boolean enabled) { |
| 346 | // TODO: Sets the view to be "awaiting" if not already awaiting |
| 347 | |
| 348 | // Change the system setting |
Winson Chung | 08b1cc8 | 2012-09-11 10:00:53 -0700 | [diff] [blame] | 349 | Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 350 | enabled ? 1 : 0); |
| 351 | |
| 352 | // Post the intent |
| 353 | Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
| 354 | intent.putExtra("state", enabled); |
| 355 | mContext.sendBroadcast(intent); |
| 356 | } |
| 357 | // NetworkSignalChanged callback |
| 358 | @Override |
| 359 | public void onAirplaneModeChanged(boolean enabled) { |
| 360 | // TODO: If view is in awaiting state, disable |
| 361 | Resources r = mContext.getResources(); |
| 362 | mAirplaneModeState.enabled = enabled; |
| 363 | mAirplaneModeState.iconId = (enabled ? |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 364 | R.drawable.ic_qs_airplane_on : |
| 365 | R.drawable.ic_qs_airplane_off); |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 366 | mAirplaneModeState.label = r.getString(R.string.quick_settings_airplane_mode_label); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 367 | mAirplaneModeCallback.refreshView(mAirplaneModeTile, mAirplaneModeState); |
| 368 | } |
| 369 | |
| 370 | // Wifi |
| 371 | void addWifiTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 372 | mWifiTile = view; |
| 373 | mWifiCallback = cb; |
| 374 | mWifiCallback.refreshView(mWifiTile, mWifiState); |
| 375 | } |
Winson Chung | 34563e2 | 2012-09-21 17:19:49 -0700 | [diff] [blame] | 376 | // Remove the double quotes that the SSID may contain |
| 377 | public static String removeDoubleQuotes(String string) { |
| 378 | if (string == null) return null; |
| 379 | final int length = string.length(); |
| 380 | if ((length > 1) && (string.charAt(0) == '"') && (string.charAt(length - 1) == '"')) { |
| 381 | return string.substring(1, length - 1); |
| 382 | } |
| 383 | return string; |
| 384 | } |
Winson Chung | f4b5ab1 | 2012-09-24 16:47:46 -0700 | [diff] [blame] | 385 | // Remove the period from the network name |
| 386 | public static String removeTrailingPeriod(String string) { |
| 387 | if (string == null) return null; |
| 388 | final int length = string.length(); |
| 389 | if (string.endsWith(".")) { |
| 390 | string.substring(0, length - 1); |
| 391 | } |
| 392 | return string; |
| 393 | } |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 394 | // NetworkSignalChanged callback |
| 395 | @Override |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 396 | public void onWifiSignalChanged(boolean enabled, int wifiSignalIconId, |
| 397 | String wifiSignalContentDescription, String enabledDesc) { |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 398 | // TODO: If view is in awaiting state, disable |
| 399 | Resources r = mContext.getResources(); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 400 | |
Winson Chung | f4b5ab1 | 2012-09-24 16:47:46 -0700 | [diff] [blame] | 401 | boolean wifiConnected = enabled && (wifiSignalIconId > 0) && (enabledDesc != null); |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 402 | boolean wifiNotConnected = (wifiSignalIconId > 0) && (enabledDesc == null); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 403 | mWifiState.enabled = enabled; |
| 404 | mWifiState.connected = wifiConnected; |
Winson Chung | f4b5ab1 | 2012-09-24 16:47:46 -0700 | [diff] [blame] | 405 | if (wifiConnected) { |
| 406 | mWifiState.iconId = wifiSignalIconId; |
| 407 | mWifiState.label = removeDoubleQuotes(enabledDesc); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 408 | mWifiState.signalContentDescription = wifiSignalContentDescription; |
Winson Chung | f4b5ab1 | 2012-09-24 16:47:46 -0700 | [diff] [blame] | 409 | } else if (wifiNotConnected) { |
| 410 | mWifiState.iconId = R.drawable.ic_qs_wifi_0; |
Chris Wren | daab6af | 2012-10-03 15:13:10 -0400 | [diff] [blame] | 411 | mWifiState.label = r.getString(R.string.quick_settings_wifi_label); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 412 | mWifiState.signalContentDescription = r.getString(R.string.accessibility_no_wifi); |
Winson Chung | f4b5ab1 | 2012-09-24 16:47:46 -0700 | [diff] [blame] | 413 | } else { |
| 414 | mWifiState.iconId = R.drawable.ic_qs_wifi_no_network; |
| 415 | mWifiState.label = r.getString(R.string.quick_settings_wifi_off_label); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 416 | mWifiState.signalContentDescription = r.getString(R.string.accessibility_wifi_off); |
Winson Chung | f4b5ab1 | 2012-09-24 16:47:46 -0700 | [diff] [blame] | 417 | } |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 418 | mWifiCallback.refreshView(mWifiTile, mWifiState); |
| 419 | } |
| 420 | |
Daniel Sandler | 5052805 | 2012-11-07 23:39:41 -0500 | [diff] [blame] | 421 | boolean deviceHasMobileData() { |
| 422 | return mHasMobileData; |
| 423 | } |
| 424 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 425 | // RSSI |
| 426 | void addRSSITile(QuickSettingsTileView view, RefreshCallback cb) { |
| 427 | mRSSITile = view; |
| 428 | mRSSICallback = cb; |
| 429 | mRSSICallback.refreshView(mRSSITile, mRSSIState); |
| 430 | } |
| 431 | // NetworkSignalChanged callback |
| 432 | @Override |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 433 | public void onMobileDataSignalChanged( |
| 434 | boolean enabled, int mobileSignalIconId, String signalContentDescription, |
| 435 | int dataTypeIconId, String dataContentDescription, String enabledDesc) { |
Daniel Sandler | 5052805 | 2012-11-07 23:39:41 -0500 | [diff] [blame] | 436 | if (deviceHasMobileData()) { |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 437 | // TODO: If view is in awaiting state, disable |
| 438 | Resources r = mContext.getResources(); |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 439 | mRSSIState.signalIconId = enabled && (mobileSignalIconId > 0) |
Winson Chung | ed1395f | 2012-09-13 18:13:44 -0700 | [diff] [blame] | 440 | ? mobileSignalIconId |
| 441 | : R.drawable.ic_qs_signal_no_signal; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 442 | mRSSIState.signalContentDescription = enabled && (mobileSignalIconId > 0) |
| 443 | ? signalContentDescription |
| 444 | : r.getString(R.string.accessibility_no_signal); |
Winson Chung | c86b23b | 2012-09-24 11:24:28 -0700 | [diff] [blame] | 445 | mRSSIState.dataTypeIconId = enabled && (dataTypeIconId > 0) && !mWifiState.enabled |
Winson Chung | 4f49d94 | 2012-09-14 14:01:40 -0700 | [diff] [blame] | 446 | ? dataTypeIconId |
| 447 | : 0; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 448 | mRSSIState.dataContentDescription = enabled && (dataTypeIconId > 0) && !mWifiState.enabled |
| 449 | ? dataContentDescription |
| 450 | : r.getString(R.string.accessibility_no_data); |
Winson Chung | ed1395f | 2012-09-13 18:13:44 -0700 | [diff] [blame] | 451 | mRSSIState.label = enabled |
Winson Chung | f4b5ab1 | 2012-09-24 16:47:46 -0700 | [diff] [blame] | 452 | ? removeTrailingPeriod(enabledDesc) |
Winson Chung | ed1395f | 2012-09-13 18:13:44 -0700 | [diff] [blame] | 453 | : r.getString(R.string.quick_settings_rssi_emergency_only); |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 454 | mRSSICallback.refreshView(mRSSITile, mRSSIState); |
| 455 | } |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | // Bluetooth |
| 459 | void addBluetoothTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 460 | mBluetoothTile = view; |
| 461 | mBluetoothCallback = cb; |
| 462 | |
| 463 | final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 464 | mBluetoothState.enabled = adapter.isEnabled(); |
| 465 | mBluetoothState.connected = |
| 466 | (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED); |
| 467 | onBluetoothStateChange(mBluetoothState); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 468 | } |
Winson Chung | 6072b00 | 2012-09-11 17:10:10 -0700 | [diff] [blame] | 469 | boolean deviceSupportsBluetooth() { |
| 470 | return (BluetoothAdapter.getDefaultAdapter() != null); |
| 471 | } |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 472 | // BluetoothController callback |
| 473 | @Override |
| 474 | public void onBluetoothStateChange(boolean on) { |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 475 | mBluetoothState.enabled = on; |
| 476 | onBluetoothStateChange(mBluetoothState); |
| 477 | } |
| 478 | public void onBluetoothStateChange(BluetoothState bluetoothStateIn) { |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 479 | // TODO: If view is in awaiting state, disable |
| 480 | Resources r = mContext.getResources(); |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 481 | mBluetoothState.enabled = bluetoothStateIn.enabled; |
| 482 | mBluetoothState.connected = bluetoothStateIn.connected; |
| 483 | if (mBluetoothState.enabled) { |
| 484 | if (mBluetoothState.connected) { |
| 485 | mBluetoothState.iconId = R.drawable.ic_qs_bluetooth_on; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 486 | mBluetoothState.stateContentDescription = r.getString(R.string.accessibility_desc_connected); |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 487 | } else { |
| 488 | mBluetoothState.iconId = R.drawable.ic_qs_bluetooth_not_connected; |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 489 | mBluetoothState.stateContentDescription = r.getString(R.string.accessibility_desc_on); |
Chris Wren | b2a7d27 | 2012-10-03 10:16:51 -0400 | [diff] [blame] | 490 | } |
Winson Chung | 34563e2 | 2012-09-21 17:19:49 -0700 | [diff] [blame] | 491 | mBluetoothState.label = r.getString(R.string.quick_settings_bluetooth_label); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 492 | } else { |
Winson Chung | eaa5ab0 | 2012-09-13 16:36:41 -0700 | [diff] [blame] | 493 | mBluetoothState.iconId = R.drawable.ic_qs_bluetooth_off; |
Winson Chung | 34563e2 | 2012-09-21 17:19:49 -0700 | [diff] [blame] | 494 | mBluetoothState.label = r.getString(R.string.quick_settings_bluetooth_off_label); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 495 | mBluetoothState.stateContentDescription = r.getString(R.string.accessibility_desc_off); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 496 | } |
| 497 | mBluetoothCallback.refreshView(mBluetoothTile, mBluetoothState); |
| 498 | } |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 499 | void refreshBluetoothTile() { |
| 500 | if (mBluetoothTile != null) { |
| 501 | onBluetoothStateChange(mBluetoothState.enabled); |
| 502 | } |
| 503 | } |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 504 | |
| 505 | // Battery |
| 506 | void addBatteryTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 507 | mBatteryTile = view; |
| 508 | mBatteryCallback = cb; |
| 509 | mBatteryCallback.refreshView(mBatteryTile, mBatteryState); |
| 510 | } |
| 511 | // BatteryController callback |
| 512 | @Override |
| 513 | public void onBatteryLevelChanged(int level, boolean pluggedIn) { |
| 514 | mBatteryState.batteryLevel = level; |
| 515 | mBatteryState.pluggedIn = pluggedIn; |
| 516 | mBatteryCallback.refreshView(mBatteryTile, mBatteryState); |
| 517 | } |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 518 | void refreshBatteryTile() { |
| 519 | mBatteryCallback.refreshView(mBatteryTile, mBatteryState); |
| 520 | } |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 521 | |
| 522 | // Location |
| 523 | void addLocationTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 524 | mLocationTile = view; |
| 525 | mLocationCallback = cb; |
| 526 | mLocationCallback.refreshView(mLocationTile, mLocationState); |
| 527 | } |
| 528 | // LocationController callback |
| 529 | @Override |
| 530 | public void onLocationGpsStateChanged(boolean inUse, String description) { |
| 531 | mLocationState.enabled = inUse; |
| 532 | mLocationState.label = description; |
| 533 | mLocationCallback.refreshView(mLocationTile, mLocationState); |
| 534 | } |
| 535 | |
Daniel Sandler | c19d448 | 2012-09-19 16:26:39 -0400 | [diff] [blame] | 536 | // Bug report |
| 537 | void addBugreportTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 538 | mBugreportTile = view; |
| 539 | mBugreportCallback = cb; |
| 540 | onBugreportChanged(); |
| 541 | } |
| 542 | // SettingsObserver callback |
| 543 | public void onBugreportChanged() { |
| 544 | final ContentResolver cr = mContext.getContentResolver(); |
| 545 | boolean enabled = false; |
| 546 | try { |
| 547 | enabled = (Settings.Secure.getInt(cr, Settings.Secure.BUGREPORT_IN_POWER_MENU) != 0); |
| 548 | } catch (SettingNotFoundException e) { |
| 549 | } |
| 550 | |
| 551 | mBugreportState.enabled = enabled; |
| 552 | mBugreportCallback.refreshView(mBugreportTile, mBugreportState); |
| 553 | } |
| 554 | |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 555 | // Wifi Display |
| 556 | void addWifiDisplayTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 557 | mWifiDisplayTile = view; |
| 558 | mWifiDisplayCallback = cb; |
| 559 | } |
| 560 | public void onWifiDisplayStateChanged(WifiDisplayStatus status) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 561 | mWifiDisplayState.enabled = |
Winson Chung | 3ed6f94 | 2012-09-20 16:07:11 -0700 | [diff] [blame] | 562 | (status.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON); |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 563 | if (status.getActiveDisplay() != null) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 564 | mWifiDisplayState.label = status.getActiveDisplay().getFriendlyDisplayName(); |
John Spurlock | 01e2f4f | 2012-10-05 17:33:31 -0400 | [diff] [blame] | 565 | mWifiDisplayState.iconId = R.drawable.ic_qs_remote_display_connected; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 566 | } else { |
| 567 | mWifiDisplayState.label = mContext.getString( |
| 568 | R.string.quick_settings_wifi_display_no_connection_label); |
John Spurlock | 01e2f4f | 2012-10-05 17:33:31 -0400 | [diff] [blame] | 569 | mWifiDisplayState.iconId = R.drawable.ic_qs_remote_display; |
Winson Chung | e641b6a | 2012-09-10 17:30:27 -0700 | [diff] [blame] | 570 | } |
| 571 | mWifiDisplayCallback.refreshView(mWifiDisplayTile, mWifiDisplayState); |
| 572 | |
| 573 | } |
| 574 | |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 575 | // IME |
| 576 | void addImeTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 577 | mImeTile = view; |
| 578 | mImeCallback = cb; |
| 579 | mImeCallback.refreshView(mImeTile, mImeState); |
| 580 | } |
Winson Chung | 34563e2 | 2012-09-21 17:19:49 -0700 | [diff] [blame] | 581 | /* This implementation is taken from |
| 582 | InputMethodManagerService.needsToShowImeSwitchOngoingNotification(). */ |
| 583 | private boolean needsToShowImeSwitchOngoingNotification(InputMethodManager imm) { |
| 584 | List<InputMethodInfo> imis = imm.getEnabledInputMethodList(); |
| 585 | final int N = imis.size(); |
| 586 | if (N > 2) return true; |
| 587 | if (N < 1) return false; |
| 588 | int nonAuxCount = 0; |
| 589 | int auxCount = 0; |
| 590 | InputMethodSubtype nonAuxSubtype = null; |
| 591 | InputMethodSubtype auxSubtype = null; |
| 592 | for(int i = 0; i < N; ++i) { |
| 593 | final InputMethodInfo imi = imis.get(i); |
| 594 | final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, |
| 595 | true); |
| 596 | final int subtypeCount = subtypes.size(); |
| 597 | if (subtypeCount == 0) { |
| 598 | ++nonAuxCount; |
| 599 | } else { |
| 600 | for (int j = 0; j < subtypeCount; ++j) { |
| 601 | final InputMethodSubtype subtype = subtypes.get(j); |
| 602 | if (!subtype.isAuxiliary()) { |
| 603 | ++nonAuxCount; |
| 604 | nonAuxSubtype = subtype; |
| 605 | } else { |
| 606 | ++auxCount; |
| 607 | auxSubtype = subtype; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | if (nonAuxCount > 1 || auxCount > 1) { |
| 613 | return true; |
| 614 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 615 | if (nonAuxSubtype != null && auxSubtype != null |
| 616 | && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 617 | || auxSubtype.overridesImplicitlyEnabledSubtype() |
| 618 | || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) |
| 619 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 620 | return false; |
| 621 | } |
| 622 | return true; |
| 623 | } |
| 624 | return false; |
| 625 | } |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 626 | void onImeWindowStatusChanged(boolean visible) { |
Winson Chung | 2a4057d | 2012-09-12 18:30:06 -0700 | [diff] [blame] | 627 | InputMethodManager imm = |
| 628 | (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); |
| 629 | List<InputMethodInfo> imis = imm.getInputMethodList(); |
| 630 | |
Winson Chung | 34563e2 | 2012-09-21 17:19:49 -0700 | [diff] [blame] | 631 | mImeState.enabled = (visible && needsToShowImeSwitchOngoingNotification(imm)); |
Winson Chung | 2a4057d | 2012-09-12 18:30:06 -0700 | [diff] [blame] | 632 | mImeState.label = getCurrentInputMethodName(mContext, mContext.getContentResolver(), |
| 633 | imm, imis, mContext.getPackageManager()); |
Daniel Sandler | aca0c75 | 2012-10-01 12:59:36 -0400 | [diff] [blame] | 634 | if (mImeCallback != null) { |
| 635 | mImeCallback.refreshView(mImeTile, mImeState); |
| 636 | } |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 637 | } |
Winson Chung | 2a4057d | 2012-09-12 18:30:06 -0700 | [diff] [blame] | 638 | private static String getCurrentInputMethodName(Context context, ContentResolver resolver, |
| 639 | InputMethodManager imm, List<InputMethodInfo> imis, PackageManager pm) { |
| 640 | if (resolver == null || imis == null) return null; |
| 641 | final String currentInputMethodId = Settings.Secure.getString(resolver, |
| 642 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 643 | if (TextUtils.isEmpty(currentInputMethodId)) return null; |
| 644 | for (InputMethodInfo imi : imis) { |
| 645 | if (currentInputMethodId.equals(imi.getId())) { |
| 646 | final InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype(); |
| 647 | final CharSequence summary = subtype != null |
| 648 | ? subtype.getDisplayName(context, imi.getPackageName(), |
| 649 | imi.getServiceInfo().applicationInfo) |
| 650 | : context.getString(R.string.quick_settings_ime_label); |
| 651 | return summary.toString(); |
| 652 | } |
| 653 | } |
| 654 | return null; |
| 655 | } |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 656 | |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 657 | // Rotation lock |
| 658 | void addRotationLockTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 659 | mRotationLockTile = view; |
| 660 | mRotationLockCallback = cb; |
| 661 | onRotationLockChanged(); |
| 662 | } |
| 663 | void onRotationLockChanged() { |
| 664 | boolean locked = RotationPolicy.isRotationLocked(mContext); |
| 665 | mRotationLockState.enabled = locked; |
| 666 | mRotationLockState.iconId = locked |
| 667 | ? R.drawable.ic_qs_rotation_locked |
| 668 | : R.drawable.ic_qs_auto_rotate; |
| 669 | mRotationLockState.label = locked |
| 670 | ? mContext.getString(R.string.quick_settings_rotation_locked_label) |
| 671 | : mContext.getString(R.string.quick_settings_rotation_unlocked_label); |
Daniel Sandler | 8dd9206 | 2012-09-14 17:29:12 -0700 | [diff] [blame] | 672 | |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 673 | // may be called before addRotationLockTile due to RotationPolicyListener in QuickSettings |
Daniel Sandler | 8dd9206 | 2012-09-14 17:29:12 -0700 | [diff] [blame] | 674 | if (mRotationLockTile != null && mRotationLockCallback != null) { |
| 675 | mRotationLockCallback.refreshView(mRotationLockTile, mRotationLockState); |
| 676 | } |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 677 | } |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 678 | void refreshRotationLockTile() { |
| 679 | if (mRotationLockTile != null) { |
| 680 | onRotationLockChanged(); |
| 681 | } |
| 682 | } |
Winson Chung | d4726d0 | 2012-09-14 12:27:29 -0700 | [diff] [blame] | 683 | |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 684 | // Brightness |
| 685 | void addBrightnessTile(QuickSettingsTileView view, RefreshCallback cb) { |
| 686 | mBrightnessTile = view; |
| 687 | mBrightnessCallback = cb; |
| 688 | onBrightnessLevelChanged(); |
| 689 | } |
| 690 | @Override |
| 691 | public void onBrightnessLevelChanged() { |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 692 | Resources r = mContext.getResources(); |
John Spurlock | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 693 | int mode = Settings.System.getIntForUser(mContext.getContentResolver(), |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 694 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
John Spurlock | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 695 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 696 | mUserTracker.getCurrentUserId()); |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 697 | mBrightnessState.autoBrightness = |
| 698 | (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); |
| 699 | mBrightnessState.iconId = mBrightnessState.autoBrightness |
| 700 | ? R.drawable.ic_qs_brightness_auto_on |
| 701 | : R.drawable.ic_qs_brightness_auto_off; |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 702 | mBrightnessState.label = r.getString(R.string.quick_settings_brightness_label); |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 703 | mBrightnessCallback.refreshView(mBrightnessTile, mBrightnessState); |
| 704 | } |
Winson Chung | efba323 | 2012-09-27 16:56:42 -0700 | [diff] [blame] | 705 | void refreshBrightnessTile() { |
| 706 | onBrightnessLevelChanged(); |
| 707 | } |
Winson Chung | 5f62301 | 2012-09-14 14:58:43 -0700 | [diff] [blame] | 708 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 709 | // User switch: need to update visuals of all tiles known to have per-user state |
John Spurlock | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 710 | void onUserSwitched() { |
| 711 | mBrightnessObserver.startObserving(); |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 712 | onRotationLockChanged(); |
| 713 | onBrightnessLevelChanged(); |
| 714 | onNextAlarmChanged(); |
| 715 | onBugreportChanged(); |
| 716 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 717 | } |