blob: 9b0a3207113e07101177d01937d97cc8f5074395 [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;
20import com.android.internal.widget.LockPatternUtils;
21import com.android.systemui.R;
Casey Burkhardtbac221f2012-10-03 18:13:58 -070022
23import com.android.systemui.statusbar.phone.QuickSettingsModel.BluetoothState;
Adam Powell6f2a3d22012-10-05 22:32:04 -070024import com.android.systemui.statusbar.phone.QuickSettingsModel.RSSIState;
25import com.android.systemui.statusbar.phone.QuickSettingsModel.State;
26import com.android.systemui.statusbar.phone.QuickSettingsModel.UserState;
Casey Burkhardtbac221f2012-10-03 18:13:58 -070027import com.android.systemui.statusbar.phone.QuickSettingsModel.WifiState;
Adam Powell6f2a3d22012-10-05 22:32:04 -070028import com.android.systemui.statusbar.policy.BatteryController;
29import com.android.systemui.statusbar.policy.BluetoothController;
30import com.android.systemui.statusbar.policy.BrightnessController;
31import com.android.systemui.statusbar.policy.LocationController;
32import com.android.systemui.statusbar.policy.NetworkController;
33import com.android.systemui.statusbar.policy.ToggleSlider;
34
Daniel Sandler3ffdcc72012-09-23 14:31:48 -040035import android.app.ActivityManagerNative;
Daniel Sandlerc19d4482012-09-19 16:26:39 -040036import android.app.AlertDialog;
Jeff Brown508257b2012-09-08 23:15:12 -070037import android.app.Dialog;
Winson Chung43229d72012-09-12 18:04:18 -070038import android.app.PendingIntent;
Chris Wrenb2a7d272012-10-03 10:16:51 -040039import android.bluetooth.BluetoothAdapter;
Jeff Brown508257b2012-09-08 23:15:12 -070040import android.content.BroadcastReceiver;
Winson Chunge641b6a2012-09-10 17:30:27 -070041import android.content.ComponentName;
Winson Chungd63c59782012-09-05 17:34:41 -070042import android.content.Context;
43import android.content.CursorLoader;
Winson Chung1679b362012-09-10 20:08:01 -070044import android.content.DialogInterface;
Daniel Sandlerc19d4482012-09-19 16:26:39 -040045import android.content.DialogInterface.OnClickListener;
Winson Chungd63c59782012-09-05 17:34:41 -070046import android.content.Intent;
Jeff Brown508257b2012-09-08 23:15:12 -070047import android.content.IntentFilter;
Adam Powell6f2a3d22012-10-05 22:32:04 -070048import android.content.pm.PackageManager.NameNotFoundException;
49import android.content.pm.UserInfo;
Winson Chungd63c59782012-09-05 17:34:41 -070050import android.content.res.Resources;
51import android.database.Cursor;
Adam Powell6f2a3d22012-10-05 22:32:04 -070052import android.graphics.Bitmap;
Winson Chungefba3232012-09-27 16:56:42 -070053import android.graphics.drawable.BitmapDrawable;
Winson Chungeaa5ab02012-09-13 16:36:41 -070054import android.graphics.drawable.Drawable;
55import android.graphics.drawable.LevelListDrawable;
Jeff Brown508257b2012-09-08 23:15:12 -070056import android.hardware.display.DisplayManager;
Jeff Brown508257b2012-09-08 23:15:12 -070057import android.hardware.display.WifiDisplayStatus;
Daniel Sandlerab510022012-10-22 22:13:35 -040058import android.net.wifi.WifiManager;
Adam Powell6f2a3d22012-10-05 22:32:04 -070059import android.os.AsyncTask;
Winson Chung3ed6f942012-09-20 16:07:11 -070060import android.os.Handler;
Daniel Sandler3ffdcc72012-09-23 14:31:48 -040061import android.os.RemoteException;
Winson Chung34563e22012-09-21 17:19:49 -070062import android.os.UserHandle;
Winson Chungefba3232012-09-27 16:56:42 -070063import android.os.UserManager;
Winson Chungd63c59782012-09-05 17:34:41 -070064import android.provider.ContactsContract;
Adam Powell6f2a3d22012-10-05 22:32:04 -070065import android.provider.ContactsContract.CommonDataKinds.Phone;
66import android.provider.ContactsContract.Profile;
Winson Chung43229d72012-09-12 18:04:18 -070067import android.provider.Settings;
Adam Powell6f2a3d22012-10-05 22:32:04 -070068import android.util.Log;
69import android.util.Pair;
Winson Chungd63c59782012-09-05 17:34:41 -070070import android.view.LayoutInflater;
71import android.view.View;
72import android.view.ViewGroup;
Winson Chung1679b362012-09-10 20:08:01 -070073import android.view.Window;
Jeff Brown508257b2012-09-08 23:15:12 -070074import android.view.WindowManager;
Adam Powell6f2a3d22012-10-05 22:32:04 -070075import android.view.WindowManagerGlobal;
Winson Chungeaa5ab02012-09-13 16:36:41 -070076import android.widget.ImageView;
Winson Chungd63c59782012-09-05 17:34:41 -070077import android.widget.TextView;
78
Winson Chunge641b6a2012-09-10 17:30:27 -070079import java.util.ArrayList;
Winson Chungd63c59782012-09-05 17:34:41 -070080
Winson Chungd63c59782012-09-05 17:34:41 -070081
82/**
83 *
84 */
85class QuickSettings {
Adam Powell6f2a3d22012-10-05 22:32:04 -070086 private static final String TAG = "QuickSettings";
Daniel Sandlerdd68da82012-10-01 10:19:09 -040087 public static final boolean SHOW_IME_TILE = false;
Winson Chungd63c59782012-09-05 17:34:41 -070088
Daniel Sandlerab510022012-10-22 22:13:35 -040089 public static final boolean LONG_PRESS_TOGGLES = true;
90
Winson Chungd63c59782012-09-05 17:34:41 -070091 private Context mContext;
92 private PanelBar mBar;
93 private QuickSettingsModel mModel;
Daniel Sandler101784e2012-10-15 13:39:38 -040094 private ViewGroup mContainerView;
Winson Chungd63c59782012-09-05 17:34:41 -070095
Jeff Brown508257b2012-09-08 23:15:12 -070096 private DisplayManager mDisplayManager;
97 private WifiDisplayStatus mWifiDisplayStatus;
Daniel Sandler3ffdcc72012-09-23 14:31:48 -040098 private PhoneStatusBar mStatusBarService;
Casey Burkhardtbac221f2012-10-03 18:13:58 -070099 private BluetoothState mBluetoothState;
Daniel Sandlerab510022012-10-22 22:13:35 -0400100 private BluetoothAdapter mBluetoothAdapter;
101 private WifiManager mWifiManager;
Jeff Brown89d55462012-09-19 11:33:42 -0700102
Winson Chung1679b362012-09-10 20:08:01 -0700103 private BrightnessController mBrightnessController;
Winson Chung5f623012012-09-14 14:58:43 -0700104 private BluetoothController mBluetoothController;
Winson Chung3ed6f942012-09-20 16:07:11 -0700105
Winson Chung1679b362012-09-10 20:08:01 -0700106 private Dialog mBrightnessDialog;
Winson Chung3ed6f942012-09-20 16:07:11 -0700107 private int mBrightnessDialogShortTimeout;
108 private int mBrightnessDialogLongTimeout;
Jeff Brown508257b2012-09-08 23:15:12 -0700109
Winson Chung7a6355b2012-10-08 18:19:09 -0700110 private AsyncTask<Void, Void, Pair<String, Drawable>> mUserInfoTask;
Winson Chungd63c59782012-09-05 17:34:41 -0700111
Winson Chungeaa5ab02012-09-13 16:36:41 -0700112 private LevelListDrawable mBatteryLevels;
113 private LevelListDrawable mChargingBatteryLevels;
114
Adam Powell6f2a3d22012-10-05 22:32:04 -0700115 boolean mTilesSetUp = false;
116
Winson Chung3ed6f942012-09-20 16:07:11 -0700117 private Handler mHandler;
118
Winson Chungd63c59782012-09-05 17:34:41 -0700119 // The set of QuickSettingsTiles that have dynamic spans (and need to be updated on
120 // configuration change)
121 private final ArrayList<QuickSettingsTileView> mDynamicSpannedTiles =
122 new ArrayList<QuickSettingsTileView>();
123
Winson Chungd4726d02012-09-14 12:27:29 -0700124 private final RotationPolicy.RotationPolicyListener mRotationPolicyListener =
125 new RotationPolicy.RotationPolicyListener() {
126 @Override
127 public void onChange() {
128 mModel.onRotationLockChanged();
129 }
130 };
131
Winson Chungd63c59782012-09-05 17:34:41 -0700132 public QuickSettings(Context context, QuickSettingsContainerView container) {
Jeff Brown508257b2012-09-08 23:15:12 -0700133 mDisplayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
Winson Chungd63c59782012-09-05 17:34:41 -0700134 mContext = context;
Winson Chungd63c59782012-09-05 17:34:41 -0700135 mContainerView = container;
Jeff Brown508257b2012-09-08 23:15:12 -0700136 mModel = new QuickSettingsModel(context);
137 mWifiDisplayStatus = new WifiDisplayStatus();
Chris Wrenb2a7d272012-10-03 10:16:51 -0400138 mBluetoothState = new QuickSettingsModel.BluetoothState();
Daniel Sandlerab510022012-10-22 22:13:35 -0400139 mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
140 mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
141
Winson Chung3ed6f942012-09-20 16:07:11 -0700142 mHandler = new Handler();
Jeff Brown508257b2012-09-08 23:15:12 -0700143
Winson Chungeaa5ab02012-09-13 16:36:41 -0700144 Resources r = mContext.getResources();
145 mBatteryLevels = (LevelListDrawable) r.getDrawable(R.drawable.qs_sys_battery);
146 mChargingBatteryLevels =
147 (LevelListDrawable) r.getDrawable(R.drawable.qs_sys_battery_charging);
Winson Chung3ed6f942012-09-20 16:07:11 -0700148 mBrightnessDialogLongTimeout =
149 r.getInteger(R.integer.quick_settings_brightness_dialog_long_timeout);
150 mBrightnessDialogShortTimeout =
151 r.getInteger(R.integer.quick_settings_brightness_dialog_short_timeout);
Winson Chungeaa5ab02012-09-13 16:36:41 -0700152
Jeff Brown508257b2012-09-08 23:15:12 -0700153 IntentFilter filter = new IntentFilter();
154 filter.addAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED);
Chris Wrenb2a7d272012-10-03 10:16:51 -0400155 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
Daniel Sandlerebaefec2012-10-17 11:37:42 -0400156 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700157 filter.addAction(Intent.ACTION_USER_SWITCHED);
Jeff Brown508257b2012-09-08 23:15:12 -0700158 mContext.registerReceiver(mReceiver, filter);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700159
160 IntentFilter profileFilter = new IntentFilter();
161 profileFilter.addAction(ContactsContract.Intents.ACTION_PROFILE_CHANGED);
162 profileFilter.addAction(Intent.ACTION_USER_INFO_CHANGED);
163 mContext.registerReceiverAsUser(mProfileReceiver, UserHandle.ALL, profileFilter,
164 null, null);
Winson Chungd63c59782012-09-05 17:34:41 -0700165 }
166
167 void setBar(PanelBar bar) {
168 mBar = bar;
169 }
170
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400171 public void setService(PhoneStatusBar phoneStatusBar) {
172 mStatusBarService = phoneStatusBar;
173 }
174
175 public PhoneStatusBar getService() {
176 return mStatusBarService;
177 }
178
Winson Chung43229d72012-09-12 18:04:18 -0700179 public void setImeWindowStatus(boolean visible) {
180 mModel.onImeWindowStatusChanged(visible);
181 }
182
Winson Chungd63c59782012-09-05 17:34:41 -0700183 void setup(NetworkController networkController, BluetoothController bluetoothController,
184 BatteryController batteryController, LocationController locationController) {
Winson Chung5f623012012-09-14 14:58:43 -0700185 mBluetoothController = bluetoothController;
186
187 setupQuickSettings();
188 updateWifiDisplayStatus();
189 updateResources();
190
Winson Chungd63c59782012-09-05 17:34:41 -0700191 networkController.addNetworkSignalChangedCallback(mModel);
192 bluetoothController.addStateChangedCallback(mModel);
193 batteryController.addStateChangedCallback(mModel);
194 locationController.addStateChangedCallback(mModel);
Christopher Tate5e08af02012-09-21 17:17:22 -0700195 RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener,
196 UserHandle.USER_ALL);
Winson Chungd63c59782012-09-05 17:34:41 -0700197 }
198
199 private void queryForUserInformation() {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700200 Context currentUserContext = null;
201 UserInfo userInfo = null;
202 try {
203 userInfo = ActivityManagerNative.getDefault().getCurrentUser();
204 currentUserContext = mContext.createPackageContextAsUser("android", 0,
205 new UserHandle(userInfo.id));
206 } catch (NameNotFoundException e) {
207 Log.e(TAG, "Couldn't create user context", e);
208 throw new RuntimeException(e);
209 } catch (RemoteException e) {
210 Log.e(TAG, "Couldn't get user info", e);
211 }
212 final int userId = userInfo.id;
Amith Yamasani7277d5d2012-10-30 14:32:45 -0700213 final String userName = userInfo.name;
Winson Chungefba3232012-09-27 16:56:42 -0700214
Adam Powell6f2a3d22012-10-05 22:32:04 -0700215 final Context context = currentUserContext;
Winson Chung7a6355b2012-10-08 18:19:09 -0700216 mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700217 @Override
Winson Chung7a6355b2012-10-08 18:19:09 -0700218 protected Pair<String, Drawable> doInBackground(Void... params) {
Winson Chung7a6355b2012-10-08 18:19:09 -0700219 final UserManager um =
220 (UserManager) mContext.getSystemService(Context.USER_SERVICE);
Winson Chungd63c59782012-09-05 17:34:41 -0700221
Winson Chung7a6355b2012-10-08 18:19:09 -0700222 // Fall back to the UserManager nickname if we can't read the name from the local
223 // profile below.
Amith Yamasani7277d5d2012-10-30 14:32:45 -0700224 String name = userName;
Winson Chung7a6355b2012-10-08 18:19:09 -0700225 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);
Adam Powelldb43f472012-10-07 15:40:00 -0700231 }
232
Amith Yamasani7277d5d2012-10-30 14:32:45 -0700233 // If it's a single-user device, get the profile name, since the nickname is not
234 // usually valid
235 if (um.getUsers().size() <= 1) {
236 // Try and read the display name from the local profile
237 final Cursor cursor = context.getContentResolver().query(
238 Profile.CONTENT_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME},
239 null, null, null);
240 if (cursor != null) {
241 try {
242 if (cursor.moveToFirst()) {
243 name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
244 }
245 } finally {
246 cursor.close();
Winson Chung7a6355b2012-10-08 18:19:09 -0700247 }
Winson Chungd63c59782012-09-05 17:34:41 -0700248 }
Adam Powell6f2a3d22012-10-05 22:32:04 -0700249 }
Winson Chung7a6355b2012-10-08 18:19:09 -0700250 return new Pair<String, Drawable>(name, avatar);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700251 }
252
253 @Override
Winson Chung7a6355b2012-10-08 18:19:09 -0700254 protected void onPostExecute(Pair<String, Drawable> result) {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700255 super.onPostExecute(result);
256 mModel.setUserTileInfo(result.first, result.second);
257 mUserInfoTask = null;
258 }
259 };
260 mUserInfoTask.execute();
Winson Chungd63c59782012-09-05 17:34:41 -0700261 }
262
263 private void setupQuickSettings() {
264 // Setup the tiles that we are going to be showing (including the temporary ones)
265 LayoutInflater inflater = LayoutInflater.from(mContext);
266
267 addUserTiles(mContainerView, inflater);
268 addSystemTiles(mContainerView, inflater);
269 addTemporaryTiles(mContainerView, inflater);
270
271 queryForUserInformation();
Adam Powell6f2a3d22012-10-05 22:32:04 -0700272 mTilesSetUp = true;
Winson Chungd63c59782012-09-05 17:34:41 -0700273 }
274
Winson Chunge641b6a2012-09-10 17:30:27 -0700275 private void startSettingsActivity(String action) {
276 Intent intent = new Intent(action);
277 startSettingsActivity(intent);
278 }
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400279
Winson Chunge641b6a2012-09-10 17:30:27 -0700280 private void startSettingsActivity(Intent intent) {
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400281 startSettingsActivity(intent, true);
282 }
283
284 private void startSettingsActivity(Intent intent, boolean onlyProvisioned) {
285 if (onlyProvisioned && !getService().isDeviceProvisioned()) return;
286 try {
287 // Dismiss the lock screen when Settings starts.
288 ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
289 } catch (RemoteException e) {
290 }
Winson Chung6072b002012-09-11 17:10:10 -0700291 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Michael Jurka09885242012-09-24 14:42:01 -0700292 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Daniel Sandler11cf1782012-09-27 14:03:08 -0400293 getService().animateCollapsePanels();
Winson Chunge641b6a2012-09-10 17:30:27 -0700294 }
295
Winson Chungd63c59782012-09-05 17:34:41 -0700296 private void addUserTiles(ViewGroup parent, LayoutInflater inflater) {
297 QuickSettingsTileView userTile = (QuickSettingsTileView)
298 inflater.inflate(R.layout.quick_settings_tile, parent, false);
299 userTile.setContent(R.layout.quick_settings_tile_user, inflater);
Winson Chung3ed6f942012-09-20 16:07:11 -0700300 userTile.setOnClickListener(new View.OnClickListener() {
301 @Override
302 public void onClick(View v) {
303 mBar.collapseAllPanels(true);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700304 final UserManager um =
305 (UserManager) mContext.getSystemService(Context.USER_SERVICE);
Winson Chungada86cb2012-10-11 12:48:36 -0700306 if (um.getUsers(true).size() > 1) {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700307 try {
Winson Chungf7614fc2012-11-26 14:43:24 -0800308 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Adam Powell6f2a3d22012-10-05 22:32:04 -0700309 } catch (RemoteException e) {
310 Log.e(TAG, "Couldn't show user switcher", e);
311 }
312 } else {
313 Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent(
314 mContext, v, ContactsContract.Profile.CONTENT_URI,
315 ContactsContract.QuickContact.MODE_LARGE, null);
316 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
317 }
Winson Chung3ed6f942012-09-20 16:07:11 -0700318 }
319 });
Winson Chungd63c59782012-09-05 17:34:41 -0700320 mModel.addUserTile(userTile, new QuickSettingsModel.RefreshCallback() {
321 @Override
322 public void refreshView(QuickSettingsTileView view, State state) {
Winson Chungeaa5ab02012-09-13 16:36:41 -0700323 UserState us = (UserState) state;
Winson Chungefba3232012-09-27 16:56:42 -0700324 ImageView iv = (ImageView) view.findViewById(R.id.user_imageview);
Winson Chungd63c59782012-09-05 17:34:41 -0700325 TextView tv = (TextView) view.findViewById(R.id.user_textview);
326 tv.setText(state.label);
Winson Chung7a6355b2012-10-08 18:19:09 -0700327 iv.setImageDrawable(us.avatar);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700328 view.setContentDescription(mContext.getString(
329 R.string.accessibility_quick_settings_user, state.label));
Winson Chungd63c59782012-09-05 17:34:41 -0700330 }
331 });
332 parent.addView(userTile);
333 mDynamicSpannedTiles.add(userTile);
334
Daniel Sandler3679bf52012-10-16 21:30:28 -0400335 // Brightness
336 QuickSettingsTileView brightnessTile = (QuickSettingsTileView)
337 inflater.inflate(R.layout.quick_settings_tile, parent, false);
338 brightnessTile.setContent(R.layout.quick_settings_tile_brightness, inflater);
339 brightnessTile.setOnClickListener(new View.OnClickListener() {
340 @Override
341 public void onClick(View v) {
342 mBar.collapseAllPanels(true);
343 showBrightnessDialog();
344 }
345 });
346 mModel.addBrightnessTile(brightnessTile, new QuickSettingsModel.RefreshCallback() {
347 @Override
348 public void refreshView(QuickSettingsTileView view, State state) {
349 TextView tv = (TextView) view.findViewById(R.id.brightness_textview);
350 tv.setCompoundDrawablesWithIntrinsicBounds(0, state.iconId, 0, 0);
351 tv.setText(state.label);
352 dismissBrightnessDialog(mBrightnessDialogShortTimeout);
353 }
354 });
355 parent.addView(brightnessTile);
356 mDynamicSpannedTiles.add(brightnessTile);
357
Winson Chungd63c59782012-09-05 17:34:41 -0700358 // Time tile
Daniel Sandler3679bf52012-10-16 21:30:28 -0400359 /*
Winson Chungd63c59782012-09-05 17:34:41 -0700360 QuickSettingsTileView timeTile = (QuickSettingsTileView)
361 inflater.inflate(R.layout.quick_settings_tile, parent, false);
362 timeTile.setContent(R.layout.quick_settings_tile_time, inflater);
Winson Chunge641b6a2012-09-10 17:30:27 -0700363 timeTile.setOnClickListener(new View.OnClickListener() {
364 @Override
365 public void onClick(View v) {
Daniel Sandler2e7d25b2012-10-01 16:43:26 -0400366 // Quick. Clock. Quick. Clock. Quick. Clock.
367 startSettingsActivity(Intent.ACTION_QUICK_CLOCK);
Winson Chunge641b6a2012-09-10 17:30:27 -0700368 }
369 });
370 mModel.addTimeTile(timeTile, new QuickSettingsModel.RefreshCallback() {
371 @Override
Winson Chungc86b23b2012-09-24 11:24:28 -0700372 public void refreshView(QuickSettingsTileView view, State alarmState) {}
Winson Chunge641b6a2012-09-10 17:30:27 -0700373 });
Winson Chungd63c59782012-09-05 17:34:41 -0700374 parent.addView(timeTile);
375 mDynamicSpannedTiles.add(timeTile);
Daniel Sandler3679bf52012-10-16 21:30:28 -0400376 */
Winson Chungd63c59782012-09-05 17:34:41 -0700377
378 // Settings tile
379 QuickSettingsTileView settingsTile = (QuickSettingsTileView)
380 inflater.inflate(R.layout.quick_settings_tile, parent, false);
381 settingsTile.setContent(R.layout.quick_settings_tile_settings, inflater);
382 settingsTile.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_SETTINGS);
Winson Chungd63c59782012-09-05 17:34:41 -0700386 }
387 });
Winson Chungefba3232012-09-27 16:56:42 -0700388 mModel.addSettingsTile(settingsTile, new QuickSettingsModel.RefreshCallback() {
389 @Override
390 public void refreshView(QuickSettingsTileView view, State state) {
391 TextView tv = (TextView) view.findViewById(R.id.settings_tileview);
392 tv.setText(state.label);
393 }
394 });
Winson Chungd63c59782012-09-05 17:34:41 -0700395 parent.addView(settingsTile);
396 mDynamicSpannedTiles.add(settingsTile);
397 }
398
399 private void addSystemTiles(ViewGroup parent, LayoutInflater inflater) {
400 // Wi-fi
Daniel Sandlerab510022012-10-22 22:13:35 -0400401 final QuickSettingsTileView wifiTile = (QuickSettingsTileView)
Winson Chungd63c59782012-09-05 17:34:41 -0700402 inflater.inflate(R.layout.quick_settings_tile, parent, false);
403 wifiTile.setContent(R.layout.quick_settings_tile_wifi, inflater);
404 wifiTile.setOnClickListener(new View.OnClickListener() {
405 @Override
406 public void onClick(View v) {
Winson Chunge641b6a2012-09-10 17:30:27 -0700407 startSettingsActivity(android.provider.Settings.ACTION_WIFI_SETTINGS);
Winson Chungd63c59782012-09-05 17:34:41 -0700408 }
409 });
Daniel Sandlerab510022012-10-22 22:13:35 -0400410 if (LONG_PRESS_TOGGLES) {
411 wifiTile.setOnLongClickListener(new View.OnLongClickListener() {
412 @Override
413 public boolean onLongClick(View v) {
414 final boolean enable =
415 (mWifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED);
416 new AsyncTask<Void, Void, Void>() {
417 @Override
418 protected Void doInBackground(Void... args) {
419 // Disable tethering if enabling Wifi
420 final int wifiApState = mWifiManager.getWifiApState();
421 if (enable && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
422 (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) {
423 mWifiManager.setWifiApEnabled(null, false);
424 }
425
426 mWifiManager.setWifiEnabled(enable);
427 return null;
428 }
429 }.execute();
430 wifiTile.setPressed(false);
431 return true;
432 }} );
433 }
Winson Chungd63c59782012-09-05 17:34:41 -0700434 mModel.addWifiTile(wifiTile, new QuickSettingsModel.RefreshCallback() {
435 @Override
436 public void refreshView(QuickSettingsTileView view, State state) {
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700437 WifiState wifiState = (WifiState) state;
Winson Chungd63c59782012-09-05 17:34:41 -0700438 TextView tv = (TextView) view.findViewById(R.id.wifi_textview);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700439 tv.setCompoundDrawablesWithIntrinsicBounds(0, wifiState.iconId, 0, 0);
440 tv.setText(wifiState.label);
441 view.setContentDescription(mContext.getString(
442 R.string.accessibility_quick_settings_wifi,
443 wifiState.signalContentDescription,
444 (wifiState.connected) ? wifiState.label : ""));
Winson Chungd63c59782012-09-05 17:34:41 -0700445 }
446 });
447 parent.addView(wifiTile);
448
Daniel Sandler50528052012-11-07 23:39:41 -0500449 if (mModel.deviceHasMobileData()) {
Winson Chung43229d72012-09-12 18:04:18 -0700450 // RSSI
451 QuickSettingsTileView rssiTile = (QuickSettingsTileView)
452 inflater.inflate(R.layout.quick_settings_tile, parent, false);
453 rssiTile.setContent(R.layout.quick_settings_tile_rssi, inflater);
454 rssiTile.setOnClickListener(new View.OnClickListener() {
455 @Override
456 public void onClick(View v) {
457 Intent intent = new Intent();
458 intent.setComponent(new ComponentName(
459 "com.android.settings",
460 "com.android.settings.Settings$DataUsageSummaryActivity"));
461 startSettingsActivity(intent);
462 }
463 });
464 mModel.addRSSITile(rssiTile, new QuickSettingsModel.RefreshCallback() {
465 @Override
466 public void refreshView(QuickSettingsTileView view, State state) {
Winson Chung4f49d942012-09-14 14:01:40 -0700467 RSSIState rssiState = (RSSIState) state;
468 ImageView iv = (ImageView) view.findViewById(R.id.rssi_image);
469 ImageView iov = (ImageView) view.findViewById(R.id.rssi_overlay_image);
Winson Chung43229d72012-09-12 18:04:18 -0700470 TextView tv = (TextView) view.findViewById(R.id.rssi_textview);
Winson Chung4f49d942012-09-14 14:01:40 -0700471 iv.setImageResource(rssiState.signalIconId);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700472
Winson Chung4f49d942012-09-14 14:01:40 -0700473 if (rssiState.dataTypeIconId > 0) {
474 iov.setImageResource(rssiState.dataTypeIconId);
475 } else {
476 iov.setImageDrawable(null);
477 }
Winson Chung43229d72012-09-12 18:04:18 -0700478 tv.setText(state.label);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700479 view.setContentDescription(mContext.getResources().getString(
480 R.string.accessibility_quick_settings_mobile,
481 rssiState.signalContentDescription, rssiState.dataContentDescription,
482 state.label));
Winson Chung43229d72012-09-12 18:04:18 -0700483 }
484 });
485 parent.addView(rssiTile);
486 }
Winson Chungd63c59782012-09-05 17:34:41 -0700487
Winson Chungd4726d02012-09-14 12:27:29 -0700488 // Rotation Lock
489 if (mContext.getResources().getBoolean(R.bool.quick_settings_show_rotation_lock)) {
490 QuickSettingsTileView rotationLockTile = (QuickSettingsTileView)
491 inflater.inflate(R.layout.quick_settings_tile, parent, false);
492 rotationLockTile.setContent(R.layout.quick_settings_tile_rotation_lock, inflater);
493 rotationLockTile.setOnClickListener(new View.OnClickListener() {
494 @Override
495 public void onClick(View v) {
496 boolean locked = RotationPolicy.isRotationLocked(mContext);
497 RotationPolicy.setRotationLock(mContext, !locked);
498 }
499 });
500 mModel.addRotationLockTile(rotationLockTile, new QuickSettingsModel.RefreshCallback() {
501 @Override
502 public void refreshView(QuickSettingsTileView view, State state) {
503 TextView tv = (TextView) view.findViewById(R.id.rotation_lock_textview);
Winson Chung5f623012012-09-14 14:58:43 -0700504 tv.setCompoundDrawablesWithIntrinsicBounds(0, state.iconId, 0, 0);
Winson Chungd4726d02012-09-14 12:27:29 -0700505 tv.setText(state.label);
506 }
507 });
508 parent.addView(rotationLockTile);
509 }
510
Winson Chungd63c59782012-09-05 17:34:41 -0700511 // Battery
512 QuickSettingsTileView batteryTile = (QuickSettingsTileView)
513 inflater.inflate(R.layout.quick_settings_tile, parent, false);
514 batteryTile.setContent(R.layout.quick_settings_tile_battery, inflater);
515 batteryTile.setOnClickListener(new View.OnClickListener() {
516 @Override
517 public void onClick(View v) {
Winson Chunge641b6a2012-09-10 17:30:27 -0700518 startSettingsActivity(Intent.ACTION_POWER_USAGE_SUMMARY);
Winson Chungd63c59782012-09-05 17:34:41 -0700519 }
520 });
521 mModel.addBatteryTile(batteryTile, new QuickSettingsModel.RefreshCallback() {
522 @Override
523 public void refreshView(QuickSettingsTileView view, State state) {
524 QuickSettingsModel.BatteryState batteryState =
525 (QuickSettingsModel.BatteryState) state;
526 TextView tv = (TextView) view.findViewById(R.id.battery_textview);
Winson Chungeaa5ab02012-09-13 16:36:41 -0700527 ImageView iv = (ImageView) view.findViewById(R.id.battery_image);
528 Drawable d = batteryState.pluggedIn
529 ? mChargingBatteryLevels
530 : mBatteryLevels;
531 String t;
532 if (batteryState.batteryLevel == 100) {
533 t = mContext.getString(R.string.quick_settings_battery_charged_label);
534 } else {
535 t = batteryState.pluggedIn
536 ? mContext.getString(R.string.quick_settings_battery_charging_label,
537 batteryState.batteryLevel)
538 : mContext.getString(R.string.status_bar_settings_battery_meter_format,
539 batteryState.batteryLevel);
540 }
541 iv.setImageDrawable(d);
542 iv.setImageLevel(batteryState.batteryLevel);
543 tv.setText(t);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700544 view.setContentDescription(
545 mContext.getString(R.string.accessibility_quick_settings_battery, t));
Winson Chungd63c59782012-09-05 17:34:41 -0700546 }
547 });
548 parent.addView(batteryTile);
549
550 // Airplane Mode
551 QuickSettingsTileView airplaneTile = (QuickSettingsTileView)
552 inflater.inflate(R.layout.quick_settings_tile, parent, false);
553 airplaneTile.setContent(R.layout.quick_settings_tile_airplane, inflater);
554 mModel.addAirplaneModeTile(airplaneTile, new QuickSettingsModel.RefreshCallback() {
555 @Override
556 public void refreshView(QuickSettingsTileView view, State state) {
557 TextView tv = (TextView) view.findViewById(R.id.airplane_mode_textview);
Winson Chung5f623012012-09-14 14:58:43 -0700558 tv.setCompoundDrawablesWithIntrinsicBounds(0, state.iconId, 0, 0);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700559
560 String airplaneState = mContext.getString(
561 (state.enabled) ? R.string.accessibility_desc_on
562 : R.string.accessibility_desc_off);
563 view.setContentDescription(
564 mContext.getString(R.string.accessibility_quick_settings_airplane, airplaneState));
Winson Chungefba3232012-09-27 16:56:42 -0700565 tv.setText(state.label);
Winson Chungd63c59782012-09-05 17:34:41 -0700566 }
567 });
568 parent.addView(airplaneTile);
569
570 // Bluetooth
Winson Chung6072b002012-09-11 17:10:10 -0700571 if (mModel.deviceSupportsBluetooth()) {
Daniel Sandlerab510022012-10-22 22:13:35 -0400572 final QuickSettingsTileView bluetoothTile = (QuickSettingsTileView)
Winson Chung6072b002012-09-11 17:10:10 -0700573 inflater.inflate(R.layout.quick_settings_tile, parent, false);
574 bluetoothTile.setContent(R.layout.quick_settings_tile_bluetooth, inflater);
575 bluetoothTile.setOnClickListener(new View.OnClickListener() {
576 @Override
577 public void onClick(View v) {
578 startSettingsActivity(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
579 }
580 });
Daniel Sandlerab510022012-10-22 22:13:35 -0400581 if (LONG_PRESS_TOGGLES) {
582 bluetoothTile.setOnLongClickListener(new View.OnLongClickListener() {
583 @Override
584 public boolean onLongClick(View v) {
585 if (mBluetoothAdapter.isEnabled()) {
586 mBluetoothAdapter.disable();
587 } else {
588 mBluetoothAdapter.enable();
589 }
590 bluetoothTile.setPressed(false);
591 return true;
592 }});
593 }
Winson Chung6072b002012-09-11 17:10:10 -0700594 mModel.addBluetoothTile(bluetoothTile, new QuickSettingsModel.RefreshCallback() {
595 @Override
596 public void refreshView(QuickSettingsTileView view, State state) {
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700597 BluetoothState bluetoothState = (BluetoothState) state;
Winson Chung6072b002012-09-11 17:10:10 -0700598 TextView tv = (TextView) view.findViewById(R.id.bluetooth_textview);
Winson Chung5f623012012-09-14 14:58:43 -0700599 tv.setCompoundDrawablesWithIntrinsicBounds(0, state.iconId, 0, 0);
600
601 Resources r = mContext.getResources();
Winson Chung34563e22012-09-21 17:19:49 -0700602 String label = state.label;
Winson Chung5f623012012-09-14 14:58:43 -0700603 /*
604 //TODO: Show connected bluetooth device label
605 Set<BluetoothDevice> btDevices =
606 mBluetoothController.getBondedBluetoothDevices();
607 if (btDevices.size() == 1) {
608 // Show the name of the bluetooth device you are connected to
609 label = btDevices.iterator().next().getName();
610 } else if (btDevices.size() > 1) {
611 // Show a generic label about the number of bluetooth devices
612 label = r.getString(R.string.quick_settings_bluetooth_multiple_devices_label,
613 btDevices.size());
614 }
615 */
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700616 view.setContentDescription(mContext.getString(
617 R.string.accessibility_quick_settings_bluetooth,
618 bluetoothState.stateContentDescription));
Winson Chung5f623012012-09-14 14:58:43 -0700619 tv.setText(label);
Winson Chung6072b002012-09-11 17:10:10 -0700620 }
621 });
622 parent.addView(bluetoothTile);
623 }
Winson Chungd63c59782012-09-05 17:34:41 -0700624
Winson Chungd63c59782012-09-05 17:34:41 -0700625 }
626
627 private void addTemporaryTiles(final ViewGroup parent, final LayoutInflater inflater) {
Winson Chungc86b23b2012-09-24 11:24:28 -0700628 // Alarm tile
629 QuickSettingsTileView alarmTile = (QuickSettingsTileView)
630 inflater.inflate(R.layout.quick_settings_tile, parent, false);
631 alarmTile.setContent(R.layout.quick_settings_tile_alarm, inflater);
632 alarmTile.setOnClickListener(new View.OnClickListener() {
633 @Override
634 public void onClick(View v) {
635 // TODO: Jump into the alarm application
636 Intent intent = new Intent();
637 intent.setComponent(new ComponentName(
638 "com.google.android.deskclock",
639 "com.android.deskclock.AlarmClock"));
640 startSettingsActivity(intent);
641 }
642 });
643 mModel.addAlarmTile(alarmTile, new QuickSettingsModel.RefreshCallback() {
644 @Override
645 public void refreshView(QuickSettingsTileView view, State alarmState) {
646 TextView tv = (TextView) view.findViewById(R.id.alarm_textview);
647 tv.setText(alarmState.label);
648 view.setVisibility(alarmState.enabled ? View.VISIBLE : View.GONE);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700649 view.setContentDescription(mContext.getString(
650 R.string.accessibility_quick_settings_alarm, alarmState.label));
Winson Chungc86b23b2012-09-24 11:24:28 -0700651 }
652 });
653 parent.addView(alarmTile);
654
Winson Chungd63c59782012-09-05 17:34:41 -0700655 // Location
656 QuickSettingsTileView locationTile = (QuickSettingsTileView)
657 inflater.inflate(R.layout.quick_settings_tile, parent, false);
658 locationTile.setContent(R.layout.quick_settings_tile_location, inflater);
659 locationTile.setOnClickListener(new View.OnClickListener() {
660 @Override
661 public void onClick(View v) {
Winson Chunge641b6a2012-09-10 17:30:27 -0700662 startSettingsActivity(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
Winson Chungd63c59782012-09-05 17:34:41 -0700663 }
664 });
665 mModel.addLocationTile(locationTile, new QuickSettingsModel.RefreshCallback() {
666 @Override
667 public void refreshView(QuickSettingsTileView view, State state) {
668 TextView tv = (TextView) view.findViewById(R.id.location_textview);
669 tv.setText(state.label);
Winson Chunge641b6a2012-09-10 17:30:27 -0700670 view.setVisibility(state.enabled ? View.VISIBLE : View.GONE);
Winson Chungd63c59782012-09-05 17:34:41 -0700671 }
672 });
673 parent.addView(locationTile);
674
Jeff Brown508257b2012-09-08 23:15:12 -0700675 // Wifi Display
676 QuickSettingsTileView wifiDisplayTile = (QuickSettingsTileView)
677 inflater.inflate(R.layout.quick_settings_tile, parent, false);
678 wifiDisplayTile.setContent(R.layout.quick_settings_tile_wifi_display, inflater);
679 wifiDisplayTile.setOnClickListener(new View.OnClickListener() {
680 @Override
681 public void onClick(View v) {
Jeff Brown89d55462012-09-19 11:33:42 -0700682 startSettingsActivity(android.provider.Settings.ACTION_WIFI_DISPLAY_SETTINGS);
Jeff Brown508257b2012-09-08 23:15:12 -0700683 }
684 });
685 mModel.addWifiDisplayTile(wifiDisplayTile, new QuickSettingsModel.RefreshCallback() {
686 @Override
687 public void refreshView(QuickSettingsTileView view, State state) {
688 TextView tv = (TextView) view.findViewById(R.id.wifi_display_textview);
689 tv.setText(state.label);
John Spurlock01e2f4f2012-10-05 17:33:31 -0400690 tv.setCompoundDrawablesWithIntrinsicBounds(0, state.iconId, 0, 0);
Winson Chunge641b6a2012-09-10 17:30:27 -0700691 view.setVisibility(state.enabled ? View.VISIBLE : View.GONE);
Jeff Brown508257b2012-09-08 23:15:12 -0700692 }
693 });
694 parent.addView(wifiDisplayTile);
695
Daniel Sandlerdd68da82012-10-01 10:19:09 -0400696 if (SHOW_IME_TILE) {
697 // IME
698 QuickSettingsTileView imeTile = (QuickSettingsTileView)
699 inflater.inflate(R.layout.quick_settings_tile, parent, false);
700 imeTile.setContent(R.layout.quick_settings_tile_ime, inflater);
701 imeTile.setOnClickListener(new View.OnClickListener() {
702 @Override
703 public void onClick(View v) {
704 try {
705 mBar.collapseAllPanels(true);
706 Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
707 PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
708 pendingIntent.send();
709 } catch (Exception e) {}
Winson Chung2a4057d2012-09-12 18:30:06 -0700710 }
Daniel Sandlerdd68da82012-10-01 10:19:09 -0400711 });
712 mModel.addImeTile(imeTile, new QuickSettingsModel.RefreshCallback() {
713 @Override
714 public void refreshView(QuickSettingsTileView view, State state) {
715 TextView tv = (TextView) view.findViewById(R.id.ime_textview);
716 if (state.label != null) {
717 tv.setText(state.label);
718 }
719 view.setVisibility(state.enabled ? View.VISIBLE : View.GONE);
720 }
721 });
722 parent.addView(imeTile);
723 }
Winson Chung43229d72012-09-12 18:04:18 -0700724
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400725 // Bug reports
726 QuickSettingsTileView bugreportTile = (QuickSettingsTileView)
727 inflater.inflate(R.layout.quick_settings_tile, parent, false);
728 bugreportTile.setContent(R.layout.quick_settings_tile_bugreport, inflater);
729 bugreportTile.setOnClickListener(new View.OnClickListener() {
730 @Override
731 public void onClick(View v) {
732 mBar.collapseAllPanels(true);
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 Chungd63c59782012-09-05 17:34:41 -0700743 /*
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 */
759 }
760
761 void updateResources() {
762 Resources r = mContext.getResources();
763
Winson Chungefba3232012-09-27 16:56:42 -0700764 // Update the model
765 mModel.updateResources();
766
Winson Chungd63c59782012-09-05 17:34:41 -0700767 // Update the User, Time, and Settings tiles spans, and reset everything else
768 int span = r.getInteger(R.integer.quick_settings_user_time_settings_tile_span);
769 for (QuickSettingsTileView v : mDynamicSpannedTiles) {
770 v.setColumnSpan(span);
771 }
Daniel Sandler101784e2012-10-15 13:39:38 -0400772 ((QuickSettingsContainerView)mContainerView).updateResources();
Winson Chungd63c59782012-09-05 17:34:41 -0700773 mContainerView.requestLayout();
Winson Chung3ed6f942012-09-20 16:07:11 -0700774
775 // Reset the dialog
776 boolean isBrightnessDialogVisible = false;
777 if (mBrightnessDialog != null) {
778 removeAllBrightnessDialogCallbacks();
779
780 isBrightnessDialogVisible = mBrightnessDialog.isShowing();
781 mBrightnessDialog.dismiss();
782 }
783 mBrightnessDialog = null;
784 if (isBrightnessDialogVisible) {
785 showBrightnessDialog();
786 }
Winson Chungd63c59782012-09-05 17:34:41 -0700787 }
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700788
Winson Chung3ed6f942012-09-20 16:07:11 -0700789 private void removeAllBrightnessDialogCallbacks() {
790 mHandler.removeCallbacks(mDismissBrightnessDialogRunnable);
791 }
792
793 private Runnable mDismissBrightnessDialogRunnable = new Runnable() {
794 public void run() {
795 if (mBrightnessDialog != null && mBrightnessDialog.isShowing()) {
796 mBrightnessDialog.dismiss();
797 }
798 removeAllBrightnessDialogCallbacks();
799 };
800 };
801
Winson Chung1679b362012-09-10 20:08:01 -0700802 private void showBrightnessDialog() {
803 if (mBrightnessDialog == null) {
804 mBrightnessDialog = new Dialog(mContext);
805 mBrightnessDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
806 mBrightnessDialog.setContentView(R.layout.quick_settings_brightness_dialog);
807 mBrightnessDialog.setCanceledOnTouchOutside(true);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700808
Winson Chung1679b362012-09-10 20:08:01 -0700809 mBrightnessController = new BrightnessController(mContext,
John Spurlockf5bc42d2012-10-12 15:24:36 -0400810 (ImageView) mBrightnessDialog.findViewById(R.id.brightness_icon),
Winson Chung1679b362012-09-10 20:08:01 -0700811 (ToggleSlider) mBrightnessDialog.findViewById(R.id.brightness_slider));
Winson Chung5f623012012-09-14 14:58:43 -0700812 mBrightnessController.addStateChangedCallback(mModel);
Winson Chung1679b362012-09-10 20:08:01 -0700813 mBrightnessDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
814 @Override
815 public void onDismiss(DialogInterface dialog) {
816 mBrightnessController = null;
817 }
818 });
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700819
Winson Chung1679b362012-09-10 20:08:01 -0700820 mBrightnessDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
Amith Yamasani7ecdc7f2012-10-22 16:09:58 -0700821 mBrightnessDialog.getWindow().getAttributes().privateFlags |=
822 WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Winson Chung1679b362012-09-10 20:08:01 -0700823 mBrightnessDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
824 }
825 if (!mBrightnessDialog.isShowing()) {
Daniel Sandlerb64c3dd2012-10-09 00:37:53 -0400826 try {
827 WindowManagerGlobal.getWindowManagerService().dismissKeyguard();
828 } catch (RemoteException e) {
829 }
Winson Chung1679b362012-09-10 20:08:01 -0700830 mBrightnessDialog.show();
Winson Chung3ed6f942012-09-20 16:07:11 -0700831 dismissBrightnessDialog(mBrightnessDialogLongTimeout);
832 }
833 }
834
835 private void dismissBrightnessDialog(int timeout) {
Winson Chungf4b5ab12012-09-24 16:47:46 -0700836 removeAllBrightnessDialogCallbacks();
Winson Chung3ed6f942012-09-20 16:07:11 -0700837 if (mBrightnessDialog != null) {
838 mHandler.postDelayed(mDismissBrightnessDialogRunnable, timeout);
Winson Chung1679b362012-09-10 20:08:01 -0700839 }
840 }
Jeff Brown508257b2012-09-08 23:15:12 -0700841
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400842 private void showBugreportDialog() {
843 final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
844 builder.setPositiveButton(com.android.internal.R.string.report, new OnClickListener() {
845 @Override
846 public void onClick(DialogInterface dialog, int which) {
847 if (which == DialogInterface.BUTTON_POSITIVE) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -0700848 // Add a little delay before executing, to give the
849 // dialog a chance to go away before it takes a
850 // screenshot.
851 mHandler.postDelayed(new Runnable() {
852 @Override public void run() {
853 try {
854 ActivityManagerNative.getDefault()
855 .requestBugReport();
856 } catch (RemoteException e) {
857 }
858 }
859 }, 500);
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400860 }
861 }
862 });
863 builder.setMessage(com.android.internal.R.string.bugreport_message);
864 builder.setTitle(com.android.internal.R.string.bugreport_title);
865 builder.setCancelable(true);
866 final Dialog dialog = builder.create();
867 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
Daniel Sandlerb64c3dd2012-10-09 00:37:53 -0400868 try {
869 WindowManagerGlobal.getWindowManagerService().dismissKeyguard();
870 } catch (RemoteException e) {
871 }
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400872 dialog.show();
873 }
874
Jeff Brown508257b2012-09-08 23:15:12 -0700875 private void updateWifiDisplayStatus() {
Jeff Brown89d55462012-09-19 11:33:42 -0700876 mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus();
877 applyWifiDisplayStatus();
Jeff Brown508257b2012-09-08 23:15:12 -0700878 }
879
Jeff Brown89d55462012-09-19 11:33:42 -0700880 private void applyWifiDisplayStatus() {
881 mModel.onWifiDisplayStateChanged(mWifiDisplayStatus);
Jeff Brown508257b2012-09-08 23:15:12 -0700882 }
883
Chris Wrenb2a7d272012-10-03 10:16:51 -0400884 private void applyBluetoothStatus() {
885 mModel.onBluetoothStateChange(mBluetoothState);
886 }
887
Adam Powell6f2a3d22012-10-05 22:32:04 -0700888 void reloadUserInfo() {
889 if (mUserInfoTask != null) {
890 mUserInfoTask.cancel(false);
891 mUserInfoTask = null;
892 }
893 if (mTilesSetUp) {
894 queryForUserInformation();
895 }
896 }
897
Jeff Brown508257b2012-09-08 23:15:12 -0700898 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
899 @Override
900 public void onReceive(Context context, Intent intent) {
Adam Powell6f2a3d22012-10-05 22:32:04 -0700901 final String action = intent.getAction();
902 if (DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED.equals(action)) {
Jeff Brown508257b2012-09-08 23:15:12 -0700903 WifiDisplayStatus status = (WifiDisplayStatus)intent.getParcelableExtra(
904 DisplayManager.EXTRA_WIFI_DISPLAY_STATUS);
Jeff Brown89d55462012-09-19 11:33:42 -0700905 mWifiDisplayStatus = status;
906 applyWifiDisplayStatus();
Daniel Sandlerebaefec2012-10-17 11:37:42 -0400907 } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
908 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
909 BluetoothAdapter.ERROR);
910 mBluetoothState.enabled = (state == BluetoothAdapter.STATE_ON);
911 applyBluetoothStatus();
Adam Powell6f2a3d22012-10-05 22:32:04 -0700912 } else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
Chris Wrenb2a7d272012-10-03 10:16:51 -0400913 int status = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
914 BluetoothAdapter.STATE_DISCONNECTED);
915 mBluetoothState.connected = (status == BluetoothAdapter.STATE_CONNECTED);
916 applyBluetoothStatus();
Adam Powell6f2a3d22012-10-05 22:32:04 -0700917 } else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
918 reloadUserInfo();
919 }
920 }
921 };
922
923 private final BroadcastReceiver mProfileReceiver = new BroadcastReceiver() {
924 @Override
925 public void onReceive(Context context, Intent intent) {
926 final String action = intent.getAction();
927 if (ContactsContract.Intents.ACTION_PROFILE_CHANGED.equals(action) ||
928 Intent.ACTION_USER_INFO_CHANGED.equals(action)) {
929 try {
930 final int userId = ActivityManagerNative.getDefault().getCurrentUser().id;
931 if (getSendingUserId() == userId) {
932 reloadUserInfo();
933 }
934 } catch (RemoteException e) {
935 Log.e(TAG, "Couldn't get current user id for profile change", e);
936 }
Chris Wrenb2a7d272012-10-03 10:16:51 -0400937 }
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700938
Jeff Brown508257b2012-09-08 23:15:12 -0700939 }
940 };
Daniel Sandlerc19d4482012-09-19 16:26:39 -0400941}