blob: 85bcd8b5ec642d5615e8d6e46a1a83d10837749d [file] [log] [blame]
Winson Chungd63c59782012-09-05 17:34:41 -07001/*
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
17package com.android.systemui.statusbar.phone;
18
Adam Powell6f2a3d22012-10-05 22:32:04 -070019import com.android.internal.view.RotationPolicy;
Adam Powell6f2a3d22012-10-05 22:32:04 -070020import com.android.systemui.R;
Casey Burkhardtbac221f2012-10-03 18:13:58 -070021
22import com.android.systemui.statusbar.phone.QuickSettingsModel.BluetoothState;
Adam Powell6f2a3d22012-10-05 22:32:04 -070023import com.android.systemui.statusbar.phone.QuickSettingsModel.RSSIState;
24import com.android.systemui.statusbar.phone.QuickSettingsModel.State;
25import com.android.systemui.statusbar.phone.QuickSettingsModel.UserState;
Casey Burkhardtbac221f2012-10-03 18:13:58 -070026import com.android.systemui.statusbar.phone.QuickSettingsModel.WifiState;
Adam Powell6f2a3d22012-10-05 22:32:04 -070027import com.android.systemui.statusbar.policy.BatteryController;
28import com.android.systemui.statusbar.policy.BluetoothController;
Adam Powell6f2a3d22012-10-05 22:32:04 -070029import com.android.systemui.statusbar.policy.LocationController;
30import com.android.systemui.statusbar.policy.NetworkController;
Adam Powell6f2a3d22012-10-05 22:32:04 -070031
Daniel Sandler3ffdcc72012-09-23 14:31:48 -040032import android.app.ActivityManagerNative;
Daniel Sandlerc19d4482012-09-19 16:26:39 -040033import android.app.AlertDialog;
Jeff Brown508257b2012-09-08 23:15:12 -070034import android.app.Dialog;
Winson Chung43229d72012-09-12 18:04:18 -070035import android.app.PendingIntent;
Chris Wrenb2a7d272012-10-03 10:16:51 -040036import android.bluetooth.BluetoothAdapter;
Jeff Brown508257b2012-09-08 23:15:12 -070037import android.content.BroadcastReceiver;
Winson Chunge641b6a2012-09-10 17:30:27 -070038import android.content.ComponentName;
Winson Chungd63c59782012-09-05 17:34:41 -070039import android.content.Context;
Winson Chung1679b362012-09-10 20:08:01 -070040import android.content.DialogInterface;
Daniel Sandlerc19d4482012-09-19 16:26:39 -040041import android.content.DialogInterface.OnClickListener;
Winson Chungd63c59782012-09-05 17:34:41 -070042import android.content.Intent;
Jeff Brown508257b2012-09-08 23:15:12 -070043import android.content.IntentFilter;
Adam Powell6f2a3d22012-10-05 22:32:04 -070044import android.content.pm.PackageManager.NameNotFoundException;
45import android.content.pm.UserInfo;
Winson Chungd63c59782012-09-05 17:34:41 -070046import android.content.res.Resources;
47import android.database.Cursor;
Adam Powell6f2a3d22012-10-05 22:32:04 -070048import android.graphics.Bitmap;
Winson Chungefba3232012-09-27 16:56:42 -070049import android.graphics.drawable.BitmapDrawable;
Winson Chungeaa5ab02012-09-13 16:36:41 -070050import android.graphics.drawable.Drawable;
51import android.graphics.drawable.LevelListDrawable;
Jeff Brown508257b2012-09-08 23:15:12 -070052import android.hardware.display.DisplayManager;
Jeff Brown508257b2012-09-08 23:15:12 -070053import android.hardware.display.WifiDisplayStatus;
Daniel Sandlerab510022012-10-22 22:13:35 -040054import android.net.wifi.WifiManager;
Adam Powell6f2a3d22012-10-05 22:32:04 -070055import android.os.AsyncTask;
Winson Chung3ed6f942012-09-20 16:07:11 -070056import android.os.Handler;
Daniel Sandler3ffdcc72012-09-23 14:31:48 -040057import android.os.RemoteException;
Winson Chung34563e22012-09-21 17:19:49 -070058import android.os.UserHandle;
Winson Chungefba3232012-09-27 16:56:42 -070059import android.os.UserManager;
Winson Chungd63c59782012-09-05 17:34:41 -070060import android.provider.ContactsContract;
Adam Powell6f2a3d22012-10-05 22:32:04 -070061import android.provider.ContactsContract.CommonDataKinds.Phone;
62import android.provider.ContactsContract.Profile;
Winson Chung43229d72012-09-12 18:04:18 -070063import android.provider.Settings;
Adam Powell6f2a3d22012-10-05 22:32:04 -070064import android.util.Log;
65import android.util.Pair;
Winson Chungd63c59782012-09-05 17:34:41 -070066import android.view.LayoutInflater;
67import android.view.View;
68import android.view.ViewGroup;
Jeff Brown508257b2012-09-08 23:15:12 -070069import android.view.WindowManager;
Adam Powell6f2a3d22012-10-05 22:32:04 -070070import android.view.WindowManagerGlobal;
Winson Chungeaa5ab02012-09-13 16:36:41 -070071import android.widget.ImageView;
Winson Chungd63c59782012-09-05 17:34:41 -070072import android.widget.TextView;
73
Winson Chunge641b6a2012-09-10 17:30:27 -070074import java.util.ArrayList;
Winson Chungd63c59782012-09-05 17:34:41 -070075
Winson Chungd63c59782012-09-05 17:34:41 -070076
77/**
78 *
79 */
80class QuickSettings {
Daniel Sandlerb5538e62013-04-12 15:16:53 -040081 static final boolean DEBUG_GONE_TILES = false;
Adam Powell6f2a3d22012-10-05 22:32:04 -070082 private static final String TAG = "QuickSettings";
Daniel Sandlerdd68da82012-10-01 10:19:09 -040083 public static final boolean SHOW_IME_TILE = false;
Winson Chungd63c59782012-09-05 17:34:41 -070084
Daniel Sandlerab510022012-10-22 22:13:35 -040085 public static final boolean LONG_PRESS_TOGGLES = true;
86
Winson Chungd63c59782012-09-05 17:34:41 -070087 private Context mContext;
88 private PanelBar mBar;
89 private QuickSettingsModel mModel;
Daniel Sandler101784e2012-10-15 13:39:38 -040090 private ViewGroup mContainerView;
Winson Chungd63c59782012-09-05 17:34:41 -070091
Jeff Brown508257b2012-09-08 23:15:12 -070092 private DisplayManager mDisplayManager;
93 private WifiDisplayStatus mWifiDisplayStatus;
Daniel Sandler3ffdcc72012-09-23 14:31:48 -040094 private PhoneStatusBar mStatusBarService;
Casey Burkhardtbac221f2012-10-03 18:13:58 -070095 private BluetoothState mBluetoothState;
Daniel Sandlerab510022012-10-22 22:13:35 -040096 private BluetoothAdapter mBluetoothAdapter;
97 private WifiManager mWifiManager;
Jeff Brown89d55462012-09-19 11:33:42 -070098
Winson Chung5f623012012-09-14 14:58:43 -070099 private BluetoothController mBluetoothController;
Winson Chung3ed6f942012-09-20 16:07:11 -0700100
Winson Chung7a6355b2012-10-08 18:19:09 -0700101 private AsyncTask<Void, Void, Pair<String, Drawable>> mUserInfoTask;
Winson Chungd63c59782012-09-05 17:34:41 -0700102
Winson Chungeaa5ab02012-09-13 16:36:41 -0700103 private LevelListDrawable mBatteryLevels;
104 private LevelListDrawable mChargingBatteryLevels;
105
Adam Powell6f2a3d22012-10-05 22:32:04 -0700106 boolean mTilesSetUp = false;
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700107 boolean mUseDefaultAvatar = false;
Adam Powell6f2a3d22012-10-05 22:32:04 -0700108
Winson Chung3ed6f942012-09-20 16:07:11 -0700109 private Handler mHandler;
110
Winson Chungd63c59782012-09-05 17:34:41 -0700111 // The set of QuickSettingsTiles that have dynamic spans (and need to be updated on
112 // configuration change)
113 private final ArrayList<QuickSettingsTileView> mDynamicSpannedTiles =
114 new ArrayList<QuickSettingsTileView>();
115
Winson Chungd4726d02012-09-14 12:27:29 -0700116 private final RotationPolicy.RotationPolicyListener mRotationPolicyListener =
117 new RotationPolicy.RotationPolicyListener() {
118 @Override
119 public void onChange() {
120 mModel.onRotationLockChanged();
121 }
122 };
123
Winson Chungd63c59782012-09-05 17:34:41 -0700124 public QuickSettings(Context context, QuickSettingsContainerView container) {
Jeff Brown508257b2012-09-08 23:15:12 -0700125 mDisplayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
Winson Chungd63c59782012-09-05 17:34:41 -0700126 mContext = context;
Winson Chungd63c59782012-09-05 17:34:41 -0700127 mContainerView = container;
Jeff Brown508257b2012-09-08 23:15:12 -0700128 mModel = new QuickSettingsModel(context);
129 mWifiDisplayStatus = new WifiDisplayStatus();
Chris Wrenb2a7d272012-10-03 10:16:51 -0400130 mBluetoothState = new QuickSettingsModel.BluetoothState();
Daniel Sandlerab510022012-10-22 22:13:35 -0400131 mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
132 mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
133
Winson Chung3ed6f942012-09-20 16:07:11 -0700134 mHandler = new Handler();
Jeff Brown508257b2012-09-08 23:15:12 -0700135
Winson Chungeaa5ab02012-09-13 16:36:41 -0700136 Resources r = mContext.getResources();
137 mBatteryLevels = (LevelListDrawable) r.getDrawable(R.drawable.qs_sys_battery);
138 mChargingBatteryLevels =
139 (LevelListDrawable) r.getDrawable(R.drawable.qs_sys_battery_charging);
140
Jeff Brown508257b2012-09-08 23:15:12 -0700141 IntentFilter filter = new IntentFilter();
142 filter.addAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED);
Chris Wrenb2a7d272012-10-03 10:16:51 -0400143 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
Daniel Sandlerebaefec2012-10-17 11:37:42 -0400144 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700145 filter.addAction(Intent.ACTION_USER_SWITCHED);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700146 filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
Jeff Brown508257b2012-09-08 23:15:12 -0700147 mContext.registerReceiver(mReceiver, filter);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700148
149 IntentFilter profileFilter = new IntentFilter();
150 profileFilter.addAction(ContactsContract.Intents.ACTION_PROFILE_CHANGED);
151 profileFilter.addAction(Intent.ACTION_USER_INFO_CHANGED);
152 mContext.registerReceiverAsUser(mProfileReceiver, UserHandle.ALL, profileFilter,
153 null, null);
Winson Chungd63c59782012-09-05 17:34:41 -0700154 }
155
156 void setBar(PanelBar bar) {
157 mBar = bar;
158 }
159
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400160 public void setService(PhoneStatusBar phoneStatusBar) {
161 mStatusBarService = phoneStatusBar;
162 }
163
164 public PhoneStatusBar getService() {
165 return mStatusBarService;
166 }
167
Winson Chung43229d72012-09-12 18:04:18 -0700168 public void setImeWindowStatus(boolean visible) {
169 mModel.onImeWindowStatusChanged(visible);
170 }
171
Winson Chungd63c59782012-09-05 17:34:41 -0700172 void setup(NetworkController networkController, BluetoothController bluetoothController,
173 BatteryController batteryController, LocationController locationController) {
Winson Chung5f623012012-09-14 14:58:43 -0700174 mBluetoothController = bluetoothController;
175
176 setupQuickSettings();
177 updateWifiDisplayStatus();
178 updateResources();
179
Winson Chungd63c59782012-09-05 17:34:41 -0700180 networkController.addNetworkSignalChangedCallback(mModel);
181 bluetoothController.addStateChangedCallback(mModel);
182 batteryController.addStateChangedCallback(mModel);
183 locationController.addStateChangedCallback(mModel);
Christopher Tate5e08af02012-09-21 17:17:22 -0700184 RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener,
185 UserHandle.USER_ALL);
Winson Chungd63c59782012-09-05 17:34:41 -0700186 }
187
188 private void queryForUserInformation() {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700189 Context currentUserContext = null;
190 UserInfo userInfo = null;
191 try {
192 userInfo = ActivityManagerNative.getDefault().getCurrentUser();
193 currentUserContext = mContext.createPackageContextAsUser("android", 0,
194 new UserHandle(userInfo.id));
195 } catch (NameNotFoundException e) {
196 Log.e(TAG, "Couldn't create user context", e);
197 throw new RuntimeException(e);
198 } catch (RemoteException e) {
199 Log.e(TAG, "Couldn't get user info", e);
200 }
201 final int userId = userInfo.id;
Amith Yamasani7277d5d2012-10-30 14:32:45 -0700202 final String userName = userInfo.name;
Winson Chungefba3232012-09-27 16:56:42 -0700203
Adam Powell6f2a3d22012-10-05 22:32:04 -0700204 final Context context = currentUserContext;
Winson Chung7a6355b2012-10-08 18:19:09 -0700205 mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700206 @Override
Winson Chung7a6355b2012-10-08 18:19:09 -0700207 protected Pair<String, Drawable> doInBackground(Void... params) {
Amith Yamasani27db4682013-03-30 17:07:47 -0700208 final UserManager um = UserManager.get(mContext);
Winson Chungd63c59782012-09-05 17:34:41 -0700209
Winson Chung7a6355b2012-10-08 18:19:09 -0700210 // Fall back to the UserManager nickname if we can't read the name from the local
211 // profile below.
Amith Yamasani7277d5d2012-10-30 14:32:45 -0700212 String name = userName;
Winson Chung7a6355b2012-10-08 18:19:09 -0700213 Drawable avatar = null;
214 Bitmap rawAvatar = um.getUserIcon(userId);
215 if (rawAvatar != null) {
216 avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
217 } else {
218 avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700219 mUseDefaultAvatar = true;
Adam Powelldb43f472012-10-07 15:40:00 -0700220 }
221
Amith Yamasani7277d5d2012-10-30 14:32:45 -0700222 // If it's a single-user device, get the profile name, since the nickname is not
223 // usually valid
224 if (um.getUsers().size() <= 1) {
225 // Try and read the display name from the local profile
226 final Cursor cursor = context.getContentResolver().query(
227 Profile.CONTENT_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME},
228 null, null, null);
229 if (cursor != null) {
230 try {
231 if (cursor.moveToFirst()) {
232 name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
233 }
234 } finally {
235 cursor.close();
Winson Chung7a6355b2012-10-08 18:19:09 -0700236 }
Winson Chungd63c59782012-09-05 17:34:41 -0700237 }
Adam Powell6f2a3d22012-10-05 22:32:04 -0700238 }
Winson Chung7a6355b2012-10-08 18:19:09 -0700239 return new Pair<String, Drawable>(name, avatar);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700240 }
241
242 @Override
Winson Chung7a6355b2012-10-08 18:19:09 -0700243 protected void onPostExecute(Pair<String, Drawable> result) {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700244 super.onPostExecute(result);
245 mModel.setUserTileInfo(result.first, result.second);
246 mUserInfoTask = null;
247 }
248 };
249 mUserInfoTask.execute();
Winson Chungd63c59782012-09-05 17:34:41 -0700250 }
251
252 private void setupQuickSettings() {
253 // Setup the tiles that we are going to be showing (including the temporary ones)
254 LayoutInflater inflater = LayoutInflater.from(mContext);
255
256 addUserTiles(mContainerView, inflater);
257 addSystemTiles(mContainerView, inflater);
258 addTemporaryTiles(mContainerView, inflater);
259
260 queryForUserInformation();
Adam Powell6f2a3d22012-10-05 22:32:04 -0700261 mTilesSetUp = true;
Winson Chungd63c59782012-09-05 17:34:41 -0700262 }
263
Winson Chunge641b6a2012-09-10 17:30:27 -0700264 private void startSettingsActivity(String action) {
265 Intent intent = new Intent(action);
266 startSettingsActivity(intent);
267 }
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400268
Winson Chunge641b6a2012-09-10 17:30:27 -0700269 private void startSettingsActivity(Intent intent) {
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400270 startSettingsActivity(intent, true);
271 }
272
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400273 private void collapsePanels() {
274 getService().animateCollapsePanels();
275 }
276
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400277 private void startSettingsActivity(Intent intent, boolean onlyProvisioned) {
278 if (onlyProvisioned && !getService().isDeviceProvisioned()) return;
279 try {
280 // Dismiss the lock screen when Settings starts.
281 ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
282 } catch (RemoteException e) {
283 }
Winson Chung6072b002012-09-11 17:10:10 -0700284 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Michael Jurka09885242012-09-24 14:42:01 -0700285 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400286 collapsePanels();
Winson Chunge641b6a2012-09-10 17:30:27 -0700287 }
288
Winson Chungd63c59782012-09-05 17:34:41 -0700289 private void addUserTiles(ViewGroup parent, LayoutInflater inflater) {
290 QuickSettingsTileView userTile = (QuickSettingsTileView)
291 inflater.inflate(R.layout.quick_settings_tile, parent, false);
292 userTile.setContent(R.layout.quick_settings_tile_user, inflater);
Winson Chung3ed6f942012-09-20 16:07:11 -0700293 userTile.setOnClickListener(new View.OnClickListener() {
294 @Override
295 public void onClick(View v) {
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400296 collapsePanels();
Amith Yamasani27db4682013-03-30 17:07:47 -0700297 final UserManager um = UserManager.get(mContext);
Winson Chungada86cb2012-10-11 12:48:36 -0700298 if (um.getUsers(true).size() > 1) {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700299 try {
Winson Chungf7614fc2012-11-26 14:43:24 -0800300 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700301 } catch (RemoteException e) {
302 Log.e(TAG, "Couldn't show user switcher", e);
303 }
304 } else {
305 Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent(
306 mContext, v, ContactsContract.Profile.CONTENT_URI,
307 ContactsContract.QuickContact.MODE_LARGE, null);
308 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
309 }
Winson Chung3ed6f942012-09-20 16:07:11 -0700310 }
311 });
Winson Chungd63c59782012-09-05 17:34:41 -0700312 mModel.addUserTile(userTile, new QuickSettingsModel.RefreshCallback() {
313 @Override
314 public void refreshView(QuickSettingsTileView view, State state) {
Winson Chungeaa5ab02012-09-13 16:36:41 -0700315 UserState us = (UserState) state;
Winson Chungefba3232012-09-27 16:56:42 -0700316 ImageView iv = (ImageView) view.findViewById(R.id.user_imageview);
Winson Chungd63c59782012-09-05 17:34:41 -0700317 TextView tv = (TextView) view.findViewById(R.id.user_textview);
318 tv.setText(state.label);
Winson Chung7a6355b2012-10-08 18:19:09 -0700319 iv.setImageDrawable(us.avatar);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700320 view.setContentDescription(mContext.getString(
321 R.string.accessibility_quick_settings_user, state.label));
Winson Chungd63c59782012-09-05 17:34:41 -0700322 }
323 });
324 parent.addView(userTile);
325 mDynamicSpannedTiles.add(userTile);
326
Daniel Sandler3679bf52012-10-16 21:30:28 -0400327 // Brightness
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400328 final QuickSettingsBasicTile brightnessTile
329 = new QuickSettingsBasicTile(mContext);
330 brightnessTile.setImageResource(R.drawable.ic_qs_brightness_auto_off);
Daniel Sandler3679bf52012-10-16 21:30:28 -0400331 brightnessTile.setOnClickListener(new View.OnClickListener() {
332 @Override
333 public void onClick(View v) {
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400334 collapsePanels();
Daniel Sandler3679bf52012-10-16 21:30:28 -0400335 showBrightnessDialog();
336 }
337 });
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400338 mModel.addBrightnessTile(brightnessTile,
339 new QuickSettingsModel.BasicRefreshCallback(brightnessTile));
Daniel Sandler3679bf52012-10-16 21:30:28 -0400340 parent.addView(brightnessTile);
341 mDynamicSpannedTiles.add(brightnessTile);
342
Winson Chungd63c59782012-09-05 17:34:41 -0700343 // Time tile
Daniel Sandler3679bf52012-10-16 21:30:28 -0400344 /*
Winson Chungd63c59782012-09-05 17:34:41 -0700345 QuickSettingsTileView timeTile = (QuickSettingsTileView)
346 inflater.inflate(R.layout.quick_settings_tile, parent, false);
347 timeTile.setContent(R.layout.quick_settings_tile_time, inflater);
Winson Chunge641b6a2012-09-10 17:30:27 -0700348 timeTile.setOnClickListener(new View.OnClickListener() {
349 @Override
350 public void onClick(View v) {
Daniel Sandler2e7d25b2012-10-01 16:43:26 -0400351 // Quick. Clock. Quick. Clock. Quick. Clock.
352 startSettingsActivity(Intent.ACTION_QUICK_CLOCK);
Winson Chunge641b6a2012-09-10 17:30:27 -0700353 }
354 });
355 mModel.addTimeTile(timeTile, new QuickSettingsModel.RefreshCallback() {
356 @Override
Winson Chungc86b23b2012-09-24 11:24:28 -0700357 public void refreshView(QuickSettingsTileView view, State alarmState) {}
Winson Chunge641b6a2012-09-10 17:30:27 -0700358 });
Winson Chungd63c59782012-09-05 17:34:41 -0700359 parent.addView(timeTile);
360 mDynamicSpannedTiles.add(timeTile);
Daniel Sandler3679bf52012-10-16 21:30:28 -0400361 */
Winson Chungd63c59782012-09-05 17:34:41 -0700362
363 // Settings tile
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400364 final QuickSettingsBasicTile settingsTile = new QuickSettingsBasicTile(mContext);
365 settingsTile.setImageResource(R.drawable.ic_qs_settings);
Winson Chungd63c59782012-09-05 17:34:41 -0700366 settingsTile.setOnClickListener(new View.OnClickListener() {
367 @Override
368 public void onClick(View v) {
Winson Chunge641b6a2012-09-10 17:30:27 -0700369 startSettingsActivity(android.provider.Settings.ACTION_SETTINGS);
Winson Chungd63c59782012-09-05 17:34:41 -0700370 }
371 });
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400372 mModel.addSettingsTile(settingsTile,
373 new QuickSettingsModel.BasicRefreshCallback(settingsTile));
Winson Chungd63c59782012-09-05 17:34:41 -0700374 parent.addView(settingsTile);
375 mDynamicSpannedTiles.add(settingsTile);
376 }
377
378 private void addSystemTiles(ViewGroup parent, LayoutInflater inflater) {
379 // Wi-fi
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400380 final QuickSettingsBasicTile wifiTile
381 = new QuickSettingsBasicTile(mContext);
Winson Chungd63c59782012-09-05 17:34:41 -0700382 wifiTile.setOnClickListener(new View.OnClickListener() {
383 @Override
384 public void onClick(View v) {
Winson Chunge641b6a2012-09-10 17:30:27 -0700385 startSettingsActivity(android.provider.Settings.ACTION_WIFI_SETTINGS);
Winson Chungd63c59782012-09-05 17:34:41 -0700386 }
387 });
Daniel Sandlerab510022012-10-22 22:13:35 -0400388 if (LONG_PRESS_TOGGLES) {
389 wifiTile.setOnLongClickListener(new View.OnLongClickListener() {
390 @Override
391 public boolean onLongClick(View v) {
392 final boolean enable =
393 (mWifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED);
394 new AsyncTask<Void, Void, Void>() {
395 @Override
396 protected Void doInBackground(Void... args) {
397 // Disable tethering if enabling Wifi
398 final int wifiApState = mWifiManager.getWifiApState();
399 if (enable && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
400 (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) {
401 mWifiManager.setWifiApEnabled(null, false);
402 }
403
404 mWifiManager.setWifiEnabled(enable);
405 return null;
406 }
407 }.execute();
408 wifiTile.setPressed(false);
409 return true;
410 }} );
411 }
Winson Chungd63c59782012-09-05 17:34:41 -0700412 mModel.addWifiTile(wifiTile, new QuickSettingsModel.RefreshCallback() {
413 @Override
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400414 public void refreshView(QuickSettingsTileView unused, State state) {
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700415 WifiState wifiState = (WifiState) state;
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400416 wifiTile.setImageResource(wifiState.iconId);
417 wifiTile.setText(wifiState.label);
418 wifiTile.setContentDescription(mContext.getString(
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700419 R.string.accessibility_quick_settings_wifi,
420 wifiState.signalContentDescription,
421 (wifiState.connected) ? wifiState.label : ""));
Winson Chungd63c59782012-09-05 17:34:41 -0700422 }
423 });
424 parent.addView(wifiTile);
425
Daniel Sandler50528052012-11-07 23:39:41 -0500426 if (mModel.deviceHasMobileData()) {
Winson Chung43229d72012-09-12 18:04:18 -0700427 // RSSI
428 QuickSettingsTileView rssiTile = (QuickSettingsTileView)
429 inflater.inflate(R.layout.quick_settings_tile, parent, false);
430 rssiTile.setContent(R.layout.quick_settings_tile_rssi, inflater);
431 rssiTile.setOnClickListener(new View.OnClickListener() {
432 @Override
433 public void onClick(View v) {
434 Intent intent = new Intent();
435 intent.setComponent(new ComponentName(
436 "com.android.settings",
437 "com.android.settings.Settings$DataUsageSummaryActivity"));
438 startSettingsActivity(intent);
439 }
440 });
441 mModel.addRSSITile(rssiTile, new QuickSettingsModel.RefreshCallback() {
442 @Override
443 public void refreshView(QuickSettingsTileView view, State state) {
Winson Chung4f49d942012-09-14 14:01:40 -0700444 RSSIState rssiState = (RSSIState) state;
445 ImageView iv = (ImageView) view.findViewById(R.id.rssi_image);
446 ImageView iov = (ImageView) view.findViewById(R.id.rssi_overlay_image);
Winson Chung43229d72012-09-12 18:04:18 -0700447 TextView tv = (TextView) view.findViewById(R.id.rssi_textview);
Fabrice Di Meglio16b9f072013-01-11 15:06:31 -0800448 // Force refresh
449 iv.setImageDrawable(null);
Winson Chung4f49d942012-09-14 14:01:40 -0700450 iv.setImageResource(rssiState.signalIconId);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700451
Winson Chung4f49d942012-09-14 14:01:40 -0700452 if (rssiState.dataTypeIconId > 0) {
453 iov.setImageResource(rssiState.dataTypeIconId);
454 } else {
455 iov.setImageDrawable(null);
456 }
Winson Chung43229d72012-09-12 18:04:18 -0700457 tv.setText(state.label);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700458 view.setContentDescription(mContext.getResources().getString(
459 R.string.accessibility_quick_settings_mobile,
460 rssiState.signalContentDescription, rssiState.dataContentDescription,
461 state.label));
Winson Chung43229d72012-09-12 18:04:18 -0700462 }
463 });
464 parent.addView(rssiTile);
465 }
Winson Chungd63c59782012-09-05 17:34:41 -0700466
Winson Chungd4726d02012-09-14 12:27:29 -0700467 // Rotation Lock
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400468 if (mContext.getResources().getBoolean(R.bool.quick_settings_show_rotation_lock)
469 || DEBUG_GONE_TILES) {
470 final QuickSettingsBasicTile rotationLockTile
471 = new QuickSettingsBasicTile(mContext);
Winson Chungd4726d02012-09-14 12:27:29 -0700472 rotationLockTile.setOnClickListener(new View.OnClickListener() {
473 @Override
474 public void onClick(View v) {
475 boolean locked = RotationPolicy.isRotationLocked(mContext);
476 RotationPolicy.setRotationLock(mContext, !locked);
477 }
478 });
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400479 mModel.addRotationLockTile(rotationLockTile,
480 new QuickSettingsModel.BasicRefreshCallback(rotationLockTile));
Winson Chungd4726d02012-09-14 12:27:29 -0700481 parent.addView(rotationLockTile);
482 }
483
Winson Chungd63c59782012-09-05 17:34:41 -0700484 // Battery
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400485 final QuickSettingsBasicTile batteryTile = new QuickSettingsBasicTile(mContext);
Winson Chungd63c59782012-09-05 17:34:41 -0700486 batteryTile.setOnClickListener(new View.OnClickListener() {
487 @Override
488 public void onClick(View v) {
Winson Chunge641b6a2012-09-10 17:30:27 -0700489 startSettingsActivity(Intent.ACTION_POWER_USAGE_SUMMARY);
Winson Chungd63c59782012-09-05 17:34:41 -0700490 }
491 });
492 mModel.addBatteryTile(batteryTile, new QuickSettingsModel.RefreshCallback() {
493 @Override
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400494 public void refreshView(QuickSettingsTileView unused, State state) {
Winson Chungd63c59782012-09-05 17:34:41 -0700495 QuickSettingsModel.BatteryState batteryState =
496 (QuickSettingsModel.BatteryState) state;
Winson Chungeaa5ab02012-09-13 16:36:41 -0700497 Drawable d = batteryState.pluggedIn
498 ? mChargingBatteryLevels
499 : mBatteryLevels;
500 String t;
501 if (batteryState.batteryLevel == 100) {
502 t = mContext.getString(R.string.quick_settings_battery_charged_label);
503 } else {
504 t = batteryState.pluggedIn
505 ? mContext.getString(R.string.quick_settings_battery_charging_label,
506 batteryState.batteryLevel)
507 : mContext.getString(R.string.status_bar_settings_battery_meter_format,
508 batteryState.batteryLevel);
509 }
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400510 batteryTile.setImageDrawable(d);
John Spurlockd3fc9562013-05-10 12:46:44 -0400511 batteryTile.getImageView().setImageLevel(batteryState.batteryLevel);
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400512 batteryTile.setText(t);
513 batteryTile.setContentDescription(
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700514 mContext.getString(R.string.accessibility_quick_settings_battery, t));
Winson Chungd63c59782012-09-05 17:34:41 -0700515 }
516 });
517 parent.addView(batteryTile);
518
519 // Airplane Mode
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400520 final QuickSettingsBasicTile airplaneTile
521 = new QuickSettingsBasicTile(mContext);
Winson Chungd63c59782012-09-05 17:34:41 -0700522 mModel.addAirplaneModeTile(airplaneTile, new QuickSettingsModel.RefreshCallback() {
523 @Override
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400524 public void refreshView(QuickSettingsTileView unused, State state) {
525 airplaneTile.setImageResource(state.iconId);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700526
527 String airplaneState = mContext.getString(
528 (state.enabled) ? R.string.accessibility_desc_on
529 : R.string.accessibility_desc_off);
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400530 airplaneTile.setContentDescription(
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700531 mContext.getString(R.string.accessibility_quick_settings_airplane, airplaneState));
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400532 airplaneTile.setText(state.label);
Winson Chungd63c59782012-09-05 17:34:41 -0700533 }
534 });
535 parent.addView(airplaneTile);
536
537 // Bluetooth
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400538 if (mModel.deviceSupportsBluetooth()
539 || DEBUG_GONE_TILES) {
540 final QuickSettingsBasicTile bluetoothTile
541 = new QuickSettingsBasicTile(mContext);
Winson Chung6072b002012-09-11 17:10:10 -0700542 bluetoothTile.setOnClickListener(new View.OnClickListener() {
543 @Override
544 public void onClick(View v) {
545 startSettingsActivity(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
546 }
547 });
Daniel Sandlerab510022012-10-22 22:13:35 -0400548 if (LONG_PRESS_TOGGLES) {
549 bluetoothTile.setOnLongClickListener(new View.OnLongClickListener() {
550 @Override
551 public boolean onLongClick(View v) {
552 if (mBluetoothAdapter.isEnabled()) {
553 mBluetoothAdapter.disable();
554 } else {
555 mBluetoothAdapter.enable();
556 }
557 bluetoothTile.setPressed(false);
558 return true;
559 }});
560 }
Winson Chung6072b002012-09-11 17:10:10 -0700561 mModel.addBluetoothTile(bluetoothTile, new QuickSettingsModel.RefreshCallback() {
562 @Override
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400563 public void refreshView(QuickSettingsTileView unused, State state) {
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700564 BluetoothState bluetoothState = (BluetoothState) state;
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400565 bluetoothTile.setImageResource(state.iconId);
Winson Chung5f623012012-09-14 14:58:43 -0700566
Winson Chung5f623012012-09-14 14:58:43 -0700567 /*
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400568 Resources r = mContext.getResources();
Winson Chung5f623012012-09-14 14:58:43 -0700569 //TODO: Show connected bluetooth device label
570 Set<BluetoothDevice> btDevices =
571 mBluetoothController.getBondedBluetoothDevices();
572 if (btDevices.size() == 1) {
573 // Show the name of the bluetooth device you are connected to
574 label = btDevices.iterator().next().getName();
575 } else if (btDevices.size() > 1) {
576 // Show a generic label about the number of bluetooth devices
577 label = r.getString(R.string.quick_settings_bluetooth_multiple_devices_label,
578 btDevices.size());
579 }
580 */
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400581 bluetoothTile.setContentDescription(mContext.getString(
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700582 R.string.accessibility_quick_settings_bluetooth,
583 bluetoothState.stateContentDescription));
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400584 bluetoothTile.setText(state.label);
Winson Chung6072b002012-09-11 17:10:10 -0700585 }
586 });
587 parent.addView(bluetoothTile);
588 }
Winson Chungd63c59782012-09-05 17:34:41 -0700589
Winson Chungd63c59782012-09-05 17:34:41 -0700590 }
591
592 private void addTemporaryTiles(final ViewGroup parent, final LayoutInflater inflater) {
Winson Chungc86b23b2012-09-24 11:24:28 -0700593 // Alarm tile
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400594 final QuickSettingsBasicTile alarmTile
595 = new QuickSettingsBasicTile(mContext);
596 alarmTile.setImageResource(R.drawable.ic_qs_alarm_on);
Winson Chungc86b23b2012-09-24 11:24:28 -0700597 alarmTile.setOnClickListener(new View.OnClickListener() {
598 @Override
599 public void onClick(View v) {
600 // TODO: Jump into the alarm application
601 Intent intent = new Intent();
602 intent.setComponent(new ComponentName(
603 "com.google.android.deskclock",
604 "com.android.deskclock.AlarmClock"));
605 startSettingsActivity(intent);
606 }
607 });
608 mModel.addAlarmTile(alarmTile, new QuickSettingsModel.RefreshCallback() {
609 @Override
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400610 public void refreshView(QuickSettingsTileView unused, State alarmState) {
611 alarmTile.setText(alarmState.label);
612 alarmTile.setVisibility(alarmState.enabled ? View.VISIBLE : View.GONE);
613 alarmTile.setContentDescription(mContext.getString(
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700614 R.string.accessibility_quick_settings_alarm, alarmState.label));
Winson Chungc86b23b2012-09-24 11:24:28 -0700615 }
616 });
617 parent.addView(alarmTile);
618
Winson Chungd63c59782012-09-05 17:34:41 -0700619 // Location
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400620 final QuickSettingsBasicTile locationTile
621 = new QuickSettingsBasicTile(mContext);
622 locationTile.setImageResource(R.drawable.ic_qs_location);
623 locationTile.setTextResource(R.string.quick_settings_location_label);
Winson Chungd63c59782012-09-05 17:34:41 -0700624 locationTile.setOnClickListener(new View.OnClickListener() {
625 @Override
626 public void onClick(View v) {
Winson Chunge641b6a2012-09-10 17:30:27 -0700627 startSettingsActivity(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
Winson Chungd63c59782012-09-05 17:34:41 -0700628 }
629 });
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400630 mModel.addLocationTile(locationTile,
631 new QuickSettingsModel.BasicRefreshCallback(locationTile)
632 .setShowWhenEnabled(true));
Winson Chungd63c59782012-09-05 17:34:41 -0700633 parent.addView(locationTile);
634
Jeff Brown508257b2012-09-08 23:15:12 -0700635 // Wifi Display
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400636 QuickSettingsBasicTile wifiDisplayTile
637 = new QuickSettingsBasicTile(mContext);
638 wifiDisplayTile.setImageResource(R.drawable.ic_qs_remote_display);
Jeff Brown508257b2012-09-08 23:15:12 -0700639 wifiDisplayTile.setOnClickListener(new View.OnClickListener() {
640 @Override
641 public void onClick(View v) {
Jeff Brown89d55462012-09-19 11:33:42 -0700642 startSettingsActivity(android.provider.Settings.ACTION_WIFI_DISPLAY_SETTINGS);
Jeff Brown508257b2012-09-08 23:15:12 -0700643 }
644 });
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400645 mModel.addWifiDisplayTile(wifiDisplayTile,
646 new QuickSettingsModel.BasicRefreshCallback(wifiDisplayTile)
647 .setShowWhenEnabled(true));
Jeff Brown508257b2012-09-08 23:15:12 -0700648 parent.addView(wifiDisplayTile);
649
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400650 if (SHOW_IME_TILE || DEBUG_GONE_TILES) {
Daniel Sandlerdd68da82012-10-01 10:19:09 -0400651 // IME
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400652 final QuickSettingsBasicTile imeTile
653 = new QuickSettingsBasicTile(mContext);
654 imeTile.setImageResource(R.drawable.ic_qs_ime);
Daniel Sandlerdd68da82012-10-01 10:19:09 -0400655 imeTile.setOnClickListener(new View.OnClickListener() {
656 @Override
657 public void onClick(View v) {
658 try {
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400659 collapsePanels();
Daniel Sandlerdd68da82012-10-01 10:19:09 -0400660 Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
661 PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
662 pendingIntent.send();
663 } catch (Exception e) {}
Winson Chung2a4057d2012-09-12 18:30:06 -0700664 }
Daniel Sandlerdd68da82012-10-01 10:19:09 -0400665 });
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400666 mModel.addImeTile(imeTile,
667 new QuickSettingsModel.BasicRefreshCallback(imeTile)
668 .setShowWhenEnabled(true));
Daniel Sandlerdd68da82012-10-01 10:19:09 -0400669 parent.addView(imeTile);
670 }
Winson Chung43229d72012-09-12 18:04:18 -0700671
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400672 // Bug reports
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400673 final QuickSettingsBasicTile bugreportTile
674 = new QuickSettingsBasicTile(mContext);
675 bugreportTile.setImageResource(com.android.internal.R.drawable.stat_sys_adb);
676 bugreportTile.setTextResource(com.android.internal.R.string.bugreport_title);
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400677 bugreportTile.setOnClickListener(new View.OnClickListener() {
678 @Override
679 public void onClick(View v) {
Daniel Sandlerb5538e62013-04-12 15:16:53 -0400680 collapsePanels();
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400681 showBugreportDialog();
682 }
683 });
684 mModel.addBugreportTile(bugreportTile, new QuickSettingsModel.RefreshCallback() {
685 @Override
686 public void refreshView(QuickSettingsTileView view, State state) {
687 view.setVisibility(state.enabled ? View.VISIBLE : View.GONE);
688 }
689 });
690 parent.addView(bugreportTile);
Winson Chungd63c59782012-09-05 17:34:41 -0700691 /*
692 QuickSettingsTileView mediaTile = (QuickSettingsTileView)
693 inflater.inflate(R.layout.quick_settings_tile, parent, false);
694 mediaTile.setContent(R.layout.quick_settings_tile_media, inflater);
695 parent.addView(mediaTile);
696 QuickSettingsTileView imeTile = (QuickSettingsTileView)
697 inflater.inflate(R.layout.quick_settings_tile, parent, false);
698 imeTile.setContent(R.layout.quick_settings_tile_ime, inflater);
699 imeTile.setOnClickListener(new View.OnClickListener() {
700 @Override
701 public void onClick(View v) {
702 parent.removeViewAt(0);
703 }
704 });
705 parent.addView(imeTile);
706 */
707 }
708
709 void updateResources() {
710 Resources r = mContext.getResources();
711
Winson Chungefba3232012-09-27 16:56:42 -0700712 // Update the model
713 mModel.updateResources();
714
Winson Chungd63c59782012-09-05 17:34:41 -0700715 // Update the User, Time, and Settings tiles spans, and reset everything else
716 int span = r.getInteger(R.integer.quick_settings_user_time_settings_tile_span);
717 for (QuickSettingsTileView v : mDynamicSpannedTiles) {
718 v.setColumnSpan(span);
719 }
Daniel Sandler101784e2012-10-15 13:39:38 -0400720 ((QuickSettingsContainerView)mContainerView).updateResources();
Winson Chungd63c59782012-09-05 17:34:41 -0700721 mContainerView.requestLayout();
722 }
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700723
Winson Chung3ed6f942012-09-20 16:07:11 -0700724
Winson Chung1679b362012-09-10 20:08:01 -0700725 private void showBrightnessDialog() {
Michael Wright0087a142013-02-05 16:29:39 -0800726 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
727 mContext.sendBroadcast(intent);
Winson Chung1679b362012-09-10 20:08:01 -0700728 }
Jeff Brown508257b2012-09-08 23:15:12 -0700729
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400730 private void showBugreportDialog() {
731 final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
732 builder.setPositiveButton(com.android.internal.R.string.report, new OnClickListener() {
733 @Override
734 public void onClick(DialogInterface dialog, int which) {
735 if (which == DialogInterface.BUTTON_POSITIVE) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -0700736 // Add a little delay before executing, to give the
737 // dialog a chance to go away before it takes a
738 // screenshot.
739 mHandler.postDelayed(new Runnable() {
740 @Override public void run() {
741 try {
742 ActivityManagerNative.getDefault()
743 .requestBugReport();
744 } catch (RemoteException e) {
745 }
746 }
747 }, 500);
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400748 }
749 }
750 });
751 builder.setMessage(com.android.internal.R.string.bugreport_message);
752 builder.setTitle(com.android.internal.R.string.bugreport_title);
753 builder.setCancelable(true);
754 final Dialog dialog = builder.create();
755 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
Daniel Sandlerb64c3dd2012-10-09 00:37:53 -0400756 try {
757 WindowManagerGlobal.getWindowManagerService().dismissKeyguard();
758 } catch (RemoteException e) {
759 }
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400760 dialog.show();
761 }
762
Jeff Brown508257b2012-09-08 23:15:12 -0700763 private void updateWifiDisplayStatus() {
Jeff Brown89d55462012-09-19 11:33:42 -0700764 mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus();
765 applyWifiDisplayStatus();
Jeff Brown508257b2012-09-08 23:15:12 -0700766 }
767
Jeff Brown89d55462012-09-19 11:33:42 -0700768 private void applyWifiDisplayStatus() {
769 mModel.onWifiDisplayStateChanged(mWifiDisplayStatus);
Jeff Brown508257b2012-09-08 23:15:12 -0700770 }
771
Chris Wrenb2a7d272012-10-03 10:16:51 -0400772 private void applyBluetoothStatus() {
773 mModel.onBluetoothStateChange(mBluetoothState);
774 }
775
Adam Powell6f2a3d22012-10-05 22:32:04 -0700776 void reloadUserInfo() {
777 if (mUserInfoTask != null) {
778 mUserInfoTask.cancel(false);
779 mUserInfoTask = null;
780 }
781 if (mTilesSetUp) {
782 queryForUserInformation();
783 }
784 }
785
Jeff Brown508257b2012-09-08 23:15:12 -0700786 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
787 @Override
788 public void onReceive(Context context, Intent intent) {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700789 final String action = intent.getAction();
790 if (DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED.equals(action)) {
Jeff Brown508257b2012-09-08 23:15:12 -0700791 WifiDisplayStatus status = (WifiDisplayStatus)intent.getParcelableExtra(
792 DisplayManager.EXTRA_WIFI_DISPLAY_STATUS);
Jeff Brown89d55462012-09-19 11:33:42 -0700793 mWifiDisplayStatus = status;
794 applyWifiDisplayStatus();
Daniel Sandlerebaefec2012-10-17 11:37:42 -0400795 } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
796 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
797 BluetoothAdapter.ERROR);
798 mBluetoothState.enabled = (state == BluetoothAdapter.STATE_ON);
799 applyBluetoothStatus();
Adam Powell6f2a3d22012-10-05 22:32:04 -0700800 } else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
Chris Wrenb2a7d272012-10-03 10:16:51 -0400801 int status = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
802 BluetoothAdapter.STATE_DISCONNECTED);
803 mBluetoothState.connected = (status == BluetoothAdapter.STATE_CONNECTED);
804 applyBluetoothStatus();
Adam Powell6f2a3d22012-10-05 22:32:04 -0700805 } else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
806 reloadUserInfo();
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700807 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
808 if (mUseDefaultAvatar) {
809 queryForUserInformation();
810 }
Adam Powell6f2a3d22012-10-05 22:32:04 -0700811 }
812 }
813 };
814
815 private final BroadcastReceiver mProfileReceiver = new BroadcastReceiver() {
816 @Override
817 public void onReceive(Context context, Intent intent) {
818 final String action = intent.getAction();
819 if (ContactsContract.Intents.ACTION_PROFILE_CHANGED.equals(action) ||
820 Intent.ACTION_USER_INFO_CHANGED.equals(action)) {
821 try {
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700822 final int currentUser = ActivityManagerNative.getDefault().getCurrentUser().id;
823 final int changedUser =
824 intent.getIntExtra(Intent.EXTRA_USER_HANDLE, getSendingUserId());
825 if (changedUser == currentUser) {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700826 reloadUserInfo();
827 }
828 } catch (RemoteException e) {
829 Log.e(TAG, "Couldn't get current user id for profile change", e);
830 }
Chris Wrenb2a7d272012-10-03 10:16:51 -0400831 }
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700832
Jeff Brown508257b2012-09-08 23:15:12 -0700833 }
834 };
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400835}