blob: 7a3d5731d43069b82cce525a4a49c6e0ba11e9e5 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
19import android.app.Activity;
20import android.app.AlertDialog;
21import android.app.Application;
22import android.app.Dialog;
Mike LeBeau736cf282009-07-02 17:46:59 -070023import android.app.ISearchManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024import android.app.SearchManager;
25import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070026import android.app.WallpaperManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027import android.content.ActivityNotFoundException;
28import android.content.BroadcastReceiver;
29import android.content.ComponentName;
30import android.content.ContentResolver;
31import android.content.Context;
32import android.content.DialogInterface;
33import android.content.Intent;
34import android.content.IntentFilter;
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -070035import android.content.Intent.ShortcutIconResource;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.pm.ActivityInfo;
37import android.content.pm.PackageManager;
38import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070040import android.content.res.Resources;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.graphics.Bitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.graphics.drawable.BitmapDrawable;
44import android.graphics.drawable.Drawable;
45import android.graphics.drawable.TransitionDrawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.os.Bundle;
47import android.os.Handler;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -070048import android.os.Looper;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.os.Message;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -070050import android.os.MessageQueue;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051import android.os.Parcelable;
52import android.os.RemoteException;
53import android.os.ServiceManager;
Karl Rosaen138a0412009-04-23 19:00:21 -070054import android.provider.LiveFolders;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055import android.text.Selection;
56import android.text.SpannableStringBuilder;
57import android.text.TextUtils;
58import android.text.method.TextKeyListener;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070059import static android.util.Log.*;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.view.Display;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061import android.view.KeyEvent;
62import android.view.LayoutInflater;
63import android.view.Menu;
64import android.view.MenuItem;
65import android.view.View;
66import android.view.ViewGroup;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.view.View.OnLongClickListener;
68import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.widget.EditText;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.widget.TextView;
71import android.widget.Toast;
The Android Open Source Project7376fae2009-03-11 12:11:58 -070072import android.appwidget.AppWidgetManager;
73import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074
75import java.lang.ref.WeakReference;
76import java.util.ArrayList;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -070077import java.util.LinkedList;
Romain Guy98d01652009-06-30 16:21:04 -070078import java.io.DataOutputStream;
79import java.io.FileNotFoundException;
80import java.io.IOException;
81import java.io.DataInputStream;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082
83/**
84 * Default launcher application.
85 */
86public final class Launcher extends Activity implements View.OnClickListener, OnLongClickListener {
87 static final String LOG_TAG = "Launcher";
88 static final boolean LOGD = false;
89
90 private static final boolean PROFILE_STARTUP = false;
The Android Open Source Project7376fae2009-03-11 12:11:58 -070091 private static final boolean PROFILE_DRAWER = false;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -070092 private static final boolean PROFILE_ROTATE = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093 private static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -070094
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095 private static final int WALLPAPER_SCREENS_SPAN = 2;
96
97 private static final int MENU_GROUP_ADD = 1;
98 private static final int MENU_ADD = Menu.FIRST + 1;
99 private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
100 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
101 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700102 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800103
104 private static final int REQUEST_CREATE_SHORTCUT = 1;
105 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700106 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107 private static final int REQUEST_PICK_APPLICATION = 6;
108 private static final int REQUEST_PICK_SHORTCUT = 7;
109 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700110 private static final int REQUEST_PICK_APPWIDGET = 9;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111
112 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
113
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700114 static final String EXTRA_CUSTOM_WIDGET = "custom_widget";
115 static final String SEARCH_WIDGET = "search_widget";
116
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117 static final int SCREEN_COUNT = 3;
118 static final int DEFAULT_SCREN = 1;
119 static final int NUMBER_CELLS_X = 4;
Romain Guycbb89e42009-06-08 15:52:54 -0700120 static final int NUMBER_CELLS_Y = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121
Joe Onorato7404ee42009-07-31 11:54:44 -0700122 static final int DIALOG_ALL_APPS = 1;
123 static final int DIALOG_CREATE_SHORTCUT = 2;
124 static final int DIALOG_RENAME_FOLDER = 3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
Romain Guy98d01652009-06-30 16:21:04 -0700126 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127
128 // Type: int
129 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
130 // Type: boolean
131 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
132 // Type: long
133 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
134 // Type: int
135 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
136 // Type: int
137 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
138 // Type: int
139 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
140 // Type: int
141 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX";
142 // Type: int
143 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY";
144 // Type: int
145 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX";
146 // Type: int
147 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY";
148 // Type: int[]
149 private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells";
150 // Type: boolean
151 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
152 // Type: long
153 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
154
The Android Open Source Projectbc219c32009-03-09 11:52:14 -0700155 private static final LauncherModel sModel = new LauncherModel();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
157 private static Bitmap sWallpaper;
158
159 private static final Object sLock = new Object();
160 private static int sScreen = DEFAULT_SCREN;
161
162 private static WallpaperIntentReceiver sWallpaperReceiver;
163
164 private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver();
165 private final ContentObserver mObserver = new FavoritesChangeObserver();
166
167 private LayoutInflater mInflater;
168
Joe Onorato00acb122009-08-04 16:04:30 -0400169 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 private DragLayer mDragLayer;
Joe Onorato59791172009-07-31 16:21:40 -0700171 private WallpaperView mWallpaperView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700173
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700174 private AppWidgetManager mAppWidgetManager;
175 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700176
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700177 static final int APPWIDGET_HOST_ID = 1024;
Romain Guycbb89e42009-06-08 15:52:54 -0700178
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 private CellLayout.CellInfo mAddItemCellInfo;
180 private CellLayout.CellInfo mMenuAddInfo;
181 private final int[] mCellCoordinates = new int[2];
182 private FolderInfo mFolderInfo;
183
Joe Onorato7404ee42009-07-31 11:54:44 -0700184 private AllAppsDialog mAllAppsDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 private TransitionDrawable mHandleIcon;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700186 private HandleView mHandleView;
Joe Onorato93839052009-08-06 20:34:32 -0700187 private AllAppsView mAllAppsGrid; // TODO: put this into AllAppsDialog
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188
189 private boolean mDesktopLocked = true;
190 private Bundle mSavedState;
191
192 private SpannableStringBuilder mDefaultKeySsb = null;
193
194 private boolean mDestroyed;
Mike LeBeau736cf282009-07-02 17:46:59 -0700195
196 private boolean mIsNewIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197
198 private boolean mRestoring;
199 private boolean mWaitingForResult;
200 private boolean mLocaleChanged;
201
Dianne Hackborn67800862009-07-24 17:15:20 -0700202 private boolean mHomeDown;
203 private boolean mBackDown;
204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private Bundle mSavedInstanceState;
206
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700207 private DesktopBinder mBinder;
Romain Guycbb89e42009-06-08 15:52:54 -0700208
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209 @Override
210 protected void onCreate(Bundle savedInstanceState) {
211 super.onCreate(savedInstanceState);
212 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700213
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700214 mAppWidgetManager = AppWidgetManager.getInstance(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700215
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700216 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
217 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 if (PROFILE_STARTUP) {
220 android.os.Debug.startMethodTracing("/sdcard/launcher");
221 }
222
223 checkForLocaleChange();
224 setWallpaperDimension();
225
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226 setContentView(R.layout.launcher);
227 setupViews();
228
Joe Onorato7404ee42009-07-31 11:54:44 -0700229 mAllAppsDialog = new AllAppsDialog(this);
230 mAllAppsDialog.lock();
231
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800232 registerIntentReceivers();
233 registerContentObservers();
234
235 mSavedState = savedInstanceState;
236 restoreState(mSavedState);
237
238 if (PROFILE_STARTUP) {
239 android.os.Debug.stopMethodTracing();
240 }
241
242 if (!mRestoring) {
243 startLoaders();
244 }
245
246 // For handling default keys
247 mDefaultKeySsb = new SpannableStringBuilder();
248 Selection.setSelection(mDefaultKeySsb, 0);
249 }
Romain Guycbb89e42009-06-08 15:52:54 -0700250
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251 private void checkForLocaleChange() {
Romain Guy98d01652009-06-30 16:21:04 -0700252 final LocaleConfiguration localeConfiguration = new LocaleConfiguration();
253 readConfiguration(this, localeConfiguration);
254
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 final Configuration configuration = getResources().getConfiguration();
256
Romain Guy98d01652009-06-30 16:21:04 -0700257 final String previousLocale = localeConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258 final String locale = configuration.locale.toString();
259
Romain Guy98d01652009-06-30 16:21:04 -0700260 final int previousMcc = localeConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800261 final int mcc = configuration.mcc;
262
Romain Guy98d01652009-06-30 16:21:04 -0700263 final int previousMnc = localeConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 final int mnc = configuration.mnc;
265
266 mLocaleChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
267
268 if (mLocaleChanged) {
Romain Guy98d01652009-06-30 16:21:04 -0700269 localeConfiguration.locale = locale;
270 localeConfiguration.mcc = mcc;
271 localeConfiguration.mnc = mnc;
272
273 writeConfiguration(this, localeConfiguration);
274 }
275 }
276
277 private static class LocaleConfiguration {
278 public String locale;
279 public int mcc = -1;
280 public int mnc = -1;
281 }
282
283 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
284 DataInputStream in = null;
285 try {
286 in = new DataInputStream(context.openFileInput(PREFERENCES));
287 configuration.locale = in.readUTF();
288 configuration.mcc = in.readInt();
289 configuration.mnc = in.readInt();
290 } catch (FileNotFoundException e) {
291 // Ignore
292 } catch (IOException e) {
293 // Ignore
294 } finally {
295 if (in != null) {
296 try {
297 in.close();
298 } catch (IOException e) {
299 // Ignore
300 }
301 }
302 }
303 }
304
305 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
306 DataOutputStream out = null;
307 try {
308 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
309 out.writeUTF(configuration.locale);
310 out.writeInt(configuration.mcc);
311 out.writeInt(configuration.mnc);
312 out.flush();
313 } catch (FileNotFoundException e) {
314 // Ignore
315 } catch (IOException e) {
316 //noinspection ResultOfMethodCallIgnored
317 context.getFileStreamPath(PREFERENCES).delete();
318 } finally {
319 if (out != null) {
320 try {
321 out.close();
322 } catch (IOException e) {
323 // Ignore
324 }
325 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800326 }
327 }
328
329 static int getScreen() {
330 synchronized (sLock) {
331 return sScreen;
332 }
333 }
334
335 static void setScreen(int screen) {
336 synchronized (sLock) {
337 sScreen = screen;
338 }
339 }
340
341 private void startLoaders() {
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700342 boolean loadApplications = sModel.loadApplications(true, this, mLocaleChanged);
343 sModel.loadUserItems(!mLocaleChanged, this, mLocaleChanged, loadApplications);
344
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800345 mRestoring = false;
346 }
347
348 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700349 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350
351 Display display = getWindowManager().getDefaultDisplay();
352 boolean isPortrait = display.getWidth() < display.getHeight();
353
354 final int width = isPortrait ? display.getWidth() : display.getHeight();
355 final int height = isPortrait ? display.getHeight() : display.getWidth();
Dianne Hackborn64271802009-08-08 20:54:24 -0700356 wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800357 }
358
359 @Override
360 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700361 mWaitingForResult = false;
362
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800363 // The pattern used here is that a user PICKs a specific application,
364 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700365
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800366 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
367 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700368
Romain Guy94dabf12009-07-21 10:55:43 -0700369 if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 switch (requestCode) {
371 case REQUEST_PICK_APPLICATION:
372 completeAddApplication(this, data, mAddItemCellInfo, !mDesktopLocked);
373 break;
374 case REQUEST_PICK_SHORTCUT:
Romain Guy73b979d2009-06-09 12:57:21 -0700375 processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 break;
377 case REQUEST_CREATE_SHORTCUT:
378 completeAddShortcut(data, mAddItemCellInfo, !mDesktopLocked);
379 break;
380 case REQUEST_PICK_LIVE_FOLDER:
381 addLiveFolder(data);
382 break;
383 case REQUEST_CREATE_LIVE_FOLDER:
384 completeAddLiveFolder(data, mAddItemCellInfo, !mDesktopLocked);
385 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700386 case REQUEST_PICK_APPWIDGET:
387 addAppWidget(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700389 case REQUEST_CREATE_APPWIDGET:
390 completeAddAppWidget(data, mAddItemCellInfo, !mDesktopLocked);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391 break;
392 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700393 } else if (requestCode == REQUEST_PICK_APPWIDGET &&
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800394 resultCode == RESULT_CANCELED && data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700395 // Clean up the appWidgetId if we canceled
396 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
397 if (appWidgetId != -1) {
398 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800399 }
400 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800401 }
402
403 @Override
404 protected void onResume() {
405 super.onResume();
406
407 if (mRestoring) {
408 startLoaders();
409 }
Mike LeBeau736cf282009-07-02 17:46:59 -0700410
411 // If this was a new intent (i.e., the mIsNewIntent flag got set to true by
412 // onNewIntent), then close the search dialog if needed, because it probably
413 // came from the user pressing 'home' (rather than, for example, pressing 'back').
414 if (mIsNewIntent) {
415 // Post to a handler so that this happens after the search dialog tries to open
416 // itself again.
417 mWorkspace.post(new Runnable() {
418 public void run() {
419 ISearchManager searchManagerService = ISearchManager.Stub.asInterface(
420 ServiceManager.getService(Context.SEARCH_SERVICE));
421 try {
422 searchManagerService.stopSearch();
423 } catch (RemoteException e) {
424 e(LOG_TAG, "error stopping search", e);
425 }
426 }
427 });
428 }
429
430 mIsNewIntent = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800431 }
432
433 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700434 protected void onPause() {
435 super.onPause();
Joe Onoratoe77c08d2009-08-01 00:01:20 -0700436 closeAllAppsDialog(false);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700437 }
Romain Guycbb89e42009-06-08 15:52:54 -0700438
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700439 @Override
440 public Object onRetainNonConfigurationInstance() {
441 // Flag any binder to stop early before switching
442 if (mBinder != null) {
443 mBinder.mTerminate = true;
444 }
Romain Guycbb89e42009-06-08 15:52:54 -0700445
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700446 if (PROFILE_ROTATE) {
447 android.os.Debug.startMethodTracing("/sdcard/launcher-rotate");
448 }
449 return null;
450 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700451
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 private boolean acceptFilter() {
453 final InputMethodManager inputManager = (InputMethodManager)
454 getSystemService(Context.INPUT_METHOD_SERVICE);
455 return !inputManager.isFullscreenMode();
456 }
457
458 @Override
459 public boolean onKeyDown(int keyCode, KeyEvent event) {
460 boolean handled = super.onKeyDown(keyCode, event);
461 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
462 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
463 keyCode, event);
464 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700465 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700466 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700467 // showSearchDialog()
468 // If there are multiple keystrokes before the search dialog takes focus,
469 // onSearchRequested() will be called for every keystroke,
470 // but it is idempotent, so it's fine.
471 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800472 }
473 }
474
475 return handled;
476 }
477
Karl Rosaen138a0412009-04-23 19:00:21 -0700478 private String getTypedText() {
479 return mDefaultKeySsb.toString();
480 }
481
482 private void clearTypedText() {
483 mDefaultKeySsb.clear();
484 mDefaultKeySsb.clearSpans();
485 Selection.setSelection(mDefaultKeySsb, 0);
486 }
487
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800488 /**
489 * Restores the previous state, if it exists.
490 *
491 * @param savedState The previous state.
492 */
493 private void restoreState(Bundle savedState) {
494 if (savedState == null) {
495 return;
496 }
497
498 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
499 if (currentScreen > -1) {
500 mWorkspace.setCurrentScreen(currentScreen);
501 }
502
503 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
504 if (addScreen > -1) {
505 mAddItemCellInfo = new CellLayout.CellInfo();
506 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
507 addItemCellInfo.valid = true;
508 addItemCellInfo.screen = addScreen;
509 addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
510 addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
511 addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
512 addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
513 addItemCellInfo.findVacantCellsFromOccupied(
514 savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS),
515 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X),
516 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y));
517 mRestoring = true;
518 }
519
520 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
521 if (renameFolder) {
522 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
523 mFolderInfo = sModel.getFolderById(this, id);
524 mRestoring = true;
525 }
526 }
527
528 /**
529 * Finds all the views we need and configure them properly.
530 */
531 private void setupViews() {
Joe Onorato00acb122009-08-04 16:04:30 -0400532 mDragController = new DragController(this);
533 DragController dragController = mDragController;
534
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800535 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
536 final DragLayer dragLayer = mDragLayer;
Joe Onorato00acb122009-08-04 16:04:30 -0400537 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800538
Joe Onorato00acb122009-08-04 16:04:30 -0400539 mWallpaperView = (WallpaperView) findViewById(R.id.wallpaper);
Joe Onorato59791172009-07-31 16:21:40 -0700540 final WallpaperView wallpaper = mWallpaperView;
541
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800542 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
543 final Workspace workspace = mWorkspace;
544
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800545 final DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
546
Joe Onorato7404ee42009-07-31 11:54:44 -0700547 mHandleView = (HandleView) findViewById(R.id.all_apps);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700548 mHandleView.setLauncher(this);
Joe Onorato7404ee42009-07-31 11:54:44 -0700549 mHandleView.setOnClickListener(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700550 mHandleIcon = (TransitionDrawable) mHandleView.getDrawable();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800551 mHandleIcon.setCrossFadeEnabled(true);
552
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800553 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400554 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800555 workspace.setLauncher(this);
Joe Onorato59791172009-07-31 16:21:40 -0700556 workspace.setWallpaper(wallpaper);
557
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800558 loadWallpaper();
Joe Onorato59791172009-07-31 16:21:40 -0700559 wallpaper.setScreenCount(workspace.getScreenCount());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800560
561 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400562 deleteZone.setDragController(dragController);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700563 deleteZone.setHandle(mHandleView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564
Joe Onorato00acb122009-08-04 16:04:30 -0400565 dragController.setDragScoller(workspace);
566 dragController.setDragListener(deleteZone);
567 dragController.setScrollView(dragLayer);
568
569 // The order here is bottom to top.
570 dragController.addDropTarget(workspace);
571 dragController.addDropTarget(deleteZone);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800572 }
573
574 /**
575 * Creates a view representing a shortcut.
576 *
577 * @param info The data structure describing the shortcut.
578 *
579 * @return A View inflated from R.layout.application.
580 */
581 View createShortcut(ApplicationInfo info) {
582 return createShortcut(R.layout.application,
583 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
584 }
585
586 /**
587 * Creates a view representing a shortcut inflated from the specified resource.
588 *
589 * @param layoutResId The id of the XML layout used to create the shortcut.
590 * @param parent The group the shortcut belongs to.
591 * @param info The data structure describing the shortcut.
592 *
593 * @return A View inflated from layoutResId.
594 */
595 View createShortcut(int layoutResId, ViewGroup parent, ApplicationInfo info) {
596 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
597
598 if (!info.filtered) {
599 info.icon = Utilities.createIconThumbnail(info.icon, this);
600 info.filtered = true;
601 }
602
603 favorite.setCompoundDrawablesWithIntrinsicBounds(null, info.icon, null, null);
604 favorite.setText(info.title);
605 favorite.setTag(info);
606 favorite.setOnClickListener(this);
607
608 return favorite;
609 }
610
611 /**
612 * Add an application shortcut to the workspace.
613 *
614 * @param data The intent describing the application.
615 * @param cellInfo The position on screen where to create the shortcut.
616 */
617 void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo,
618 boolean insertAtFirst) {
619 cellInfo.screen = mWorkspace.getCurrentScreen();
620 if (!findSingleSlot(cellInfo)) return;
621
Romain Guy73b979d2009-06-09 12:57:21 -0700622 final ApplicationInfo info = infoFromApplicationIntent(context, data);
623 if (info != null) {
624 mWorkspace.addApplicationShortcut(info, cellInfo, insertAtFirst);
625 }
626 }
627
628 private static ApplicationInfo infoFromApplicationIntent(Context context, Intent data) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800629 ComponentName component = data.getComponent();
630 PackageManager packageManager = context.getPackageManager();
631 ActivityInfo activityInfo = null;
632 try {
633 activityInfo = packageManager.getActivityInfo(component, 0 /* no flags */);
634 } catch (NameNotFoundException e) {
Romain Guy73b979d2009-06-09 12:57:21 -0700635 e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800636 }
Romain Guycbb89e42009-06-08 15:52:54 -0700637
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800638 if (activityInfo != null) {
639 ApplicationInfo itemInfo = new ApplicationInfo();
Romain Guycbb89e42009-06-08 15:52:54 -0700640
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800641 itemInfo.title = activityInfo.loadLabel(packageManager);
642 if (itemInfo.title == null) {
643 itemInfo.title = activityInfo.name;
644 }
Romain Guycbb89e42009-06-08 15:52:54 -0700645
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800646 itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK |
647 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
648 itemInfo.icon = activityInfo.loadIcon(packageManager);
649 itemInfo.container = ItemInfo.NO_ID;
650
Romain Guy73b979d2009-06-09 12:57:21 -0700651 return itemInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800652 }
Romain Guy73b979d2009-06-09 12:57:21 -0700653
654 return null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 }
Romain Guycbb89e42009-06-08 15:52:54 -0700656
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800657 /**
658 * Add a shortcut to the workspace.
659 *
660 * @param data The intent describing the shortcut.
661 * @param cellInfo The position on screen where to create the shortcut.
662 * @param insertAtFirst
663 */
664 private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo,
665 boolean insertAtFirst) {
666 cellInfo.screen = mWorkspace.getCurrentScreen();
667 if (!findSingleSlot(cellInfo)) return;
Romain Guycbb89e42009-06-08 15:52:54 -0700668
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800669 final ApplicationInfo info = addShortcut(this, data, cellInfo, false);
670
671 if (!mRestoring) {
672 sModel.addDesktopItem(info);
673
674 final View view = createShortcut(info);
675 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst);
676 } else if (sModel.isDesktopLoaded()) {
677 sModel.addDesktopItem(info);
678 }
679 }
680
Romain Guycbb89e42009-06-08 15:52:54 -0700681
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700683 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 *
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700685 * @param data The intent describing the appWidgetId.
686 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800687 */
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700688 private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo,
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 boolean insertAtFirst) {
690
691 Bundle extras = data.getExtras();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700692 int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Romain Guycbb89e42009-06-08 15:52:54 -0700693
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700694 d(LOG_TAG, "dumping extras content="+extras.toString());
Romain Guycbb89e42009-06-08 15:52:54 -0700695
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700696 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700697
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700698 // Calculate the grid spans needed to fit this widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700700 int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
Romain Guycbb89e42009-06-08 15:52:54 -0700701
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800702 // Try finding open space on Launcher screen
703 final int[] xy = mCellCoordinates;
704 if (!findSlot(cellInfo, xy, spans[0], spans[1])) return;
705
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700706 // Build Launcher-specific widget info and save to database
707 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800708 launcherInfo.spanX = spans[0];
709 launcherInfo.spanY = spans[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700710
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800711 LauncherModel.addItemToDatabase(this, launcherInfo,
712 LauncherSettings.Favorites.CONTAINER_DESKTOP,
713 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
714
715 if (!mRestoring) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700716 sModel.addDesktopAppWidget(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700717
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800718 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700719 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700720
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700721 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800722 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700723
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800724 mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
725 launcherInfo.spanX, launcherInfo.spanY, insertAtFirst);
726 } else if (sModel.isDesktopLoaded()) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700727 sModel.addDesktopAppWidget(launcherInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800728 }
729 }
Romain Guycbb89e42009-06-08 15:52:54 -0700730
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700731 public LauncherAppWidgetHost getAppWidgetHost() {
732 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800733 }
Romain Guycbb89e42009-06-08 15:52:54 -0700734
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800735 static ApplicationInfo addShortcut(Context context, Intent data,
736 CellLayout.CellInfo cellInfo, boolean notify) {
737
Romain Guy73b979d2009-06-09 12:57:21 -0700738 final ApplicationInfo info = infoFromShortcutIntent(context, data);
739 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
740 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
741
742 return info;
743 }
744
745 private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800746 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
747 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
748 Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
749
750 Drawable icon = null;
751 boolean filtered = false;
752 boolean customIcon = false;
Romain Guy73b979d2009-06-09 12:57:21 -0700753 ShortcutIconResource iconResource = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800754
755 if (bitmap != null) {
756 icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
757 filtered = true;
758 customIcon = true;
759 } else {
760 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
Romain Guy73b979d2009-06-09 12:57:21 -0700761 if (extra != null && extra instanceof ShortcutIconResource) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 try {
Romain Guy73b979d2009-06-09 12:57:21 -0700763 iconResource = (ShortcutIconResource) extra;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800764 final PackageManager packageManager = context.getPackageManager();
765 Resources resources = packageManager.getResourcesForApplication(
766 iconResource.packageName);
767 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
768 icon = resources.getDrawable(id);
769 } catch (Exception e) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700770 w(LOG_TAG, "Could not load shortcut icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800771 }
772 }
773 }
774
775 if (icon == null) {
776 icon = context.getPackageManager().getDefaultActivityIcon();
777 }
778
779 final ApplicationInfo info = new ApplicationInfo();
780 info.icon = icon;
781 info.filtered = filtered;
782 info.title = name;
783 info.intent = intent;
784 info.customIcon = customIcon;
785 info.iconResource = iconResource;
786
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800787 return info;
788 }
789
790 @Override
791 protected void onNewIntent(Intent intent) {
792 super.onNewIntent(intent);
793
794 // Close the menu
795 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
796 getWindow().closeAllPanels();
Mike LeBeau736cf282009-07-02 17:46:59 -0700797
798 // Set this flag so that onResume knows to close the search dialog if it's open,
799 // because this was a new intent (thus a press of 'home' or some such) rather than
800 // for example onResume being called when the user pressed the 'back' button.
801 mIsNewIntent = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800802
803 try {
804 dismissDialog(DIALOG_CREATE_SHORTCUT);
805 // Unlock the workspace if the dialog was showing
806 mWorkspace.unlock();
807 } catch (Exception e) {
808 // An exception is thrown if the dialog is not visible, which is fine
809 }
810
811 try {
812 dismissDialog(DIALOG_RENAME_FOLDER);
813 // Unlock the workspace if the dialog was showing
814 mWorkspace.unlock();
815 } catch (Exception e) {
816 // An exception is thrown if the dialog is not visible, which is fine
817 }
818
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800819 if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) !=
820 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) {
Romain Guy73b979d2009-06-09 12:57:21 -0700821
Romain Guy94dabf12009-07-21 10:55:43 -0700822 if (!mWorkspace.isDefaultScreenShowing()) {
823 mWorkspace.moveToDefaultScreen();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800824 }
Romain Guy1dd3a072009-07-16 13:21:01 -0700825
Joe Onoratoe77c08d2009-08-01 00:01:20 -0700826 closeAllAppsDialog(true);
Romain Guy73b979d2009-06-09 12:57:21 -0700827
828 final View v = getWindow().peekDecorView();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800829 if (v != null && v.getWindowToken() != null) {
830 InputMethodManager imm = (InputMethodManager)getSystemService(
831 INPUT_METHOD_SERVICE);
832 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
833 }
834 } else {
Joe Onoratoe77c08d2009-08-01 00:01:20 -0700835 closeAllAppsDialog(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800836 }
837 }
838 }
839
840 @Override
841 protected void onRestoreInstanceState(Bundle savedInstanceState) {
842 // Do not call super here
843 mSavedInstanceState = savedInstanceState;
844 }
845
846 @Override
847 protected void onSaveInstanceState(Bundle outState) {
848 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen());
849
850 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
851 if (folders.size() > 0) {
852 final int count = folders.size();
853 long[] ids = new long[count];
854 for (int i = 0; i < count; i++) {
855 final FolderInfo info = folders.get(i).getInfo();
856 ids[i] = info.id;
857 }
858 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
859 } else {
860 super.onSaveInstanceState(outState);
861 }
862
Romain Guy3cf604f2009-06-16 13:12:53 -0700863 final boolean isConfigurationChange = getChangingConfigurations() != 0;
864
Romain Guy5a941392009-04-28 15:18:25 -0700865 // When the drawer is opened and we are saving the state because of a
866 // configuration change
Joe Onorato7404ee42009-07-31 11:54:44 -0700867 if (mAllAppsDialog.isOpen && isConfigurationChange) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -0700869 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800870
871 if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
872 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
873 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);
874
875 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
876 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
877 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
878 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
879 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
880 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
881 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
882 outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS,
883 layout.getOccupiedCells());
884 }
885
886 if (mFolderInfo != null && mWaitingForResult) {
887 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
888 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
889 }
890 }
891
892 @Override
893 public void onDestroy() {
894 mDestroyed = true;
895
896 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -0700897
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700899 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800900 } catch (NullPointerException ex) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700901 w(LOG_TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902 }
903
904 TextKeyListener.getInstance().release();
905
Joe Onorato93839052009-08-06 20:34:32 -0700906 // TODO mAllAppsGrid.setAdapter(null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800907 sModel.unbind();
908 sModel.abortLoaders();
909
910 getContentResolver().unregisterContentObserver(mObserver);
911 unregisterReceiver(mApplicationsReceiver);
912 }
913
914 @Override
915 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -0700916 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800917 super.startActivityForResult(intent, requestCode);
918 }
919
920 @Override
Romain Guycbb89e42009-06-08 15:52:54 -0700921 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700923
Joe Onoratoe77c08d2009-08-01 00:01:20 -0700924 closeAllAppsDialog(false);
Romain Guycbb89e42009-06-08 15:52:54 -0700925
Karl Rosaen138a0412009-04-23 19:00:21 -0700926 // Slide the search widget to the top, if it's on the current screen,
927 // otherwise show the search dialog immediately.
928 Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
929 if (searchWidget == null) {
930 showSearchDialog(initialQuery, selectInitialQuery, appSearchData, globalSearch);
931 } else {
932 searchWidget.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
933 // show the currently typed text in the search widget while sliding
934 searchWidget.setQuery(getTypedText());
935 }
936 }
Romain Guycbb89e42009-06-08 15:52:54 -0700937
Karl Rosaen138a0412009-04-23 19:00:21 -0700938 /**
939 * Show the search dialog immediately, without changing the search widget.
Romain Guy5a941392009-04-28 15:18:25 -0700940 *
941 * @see Activity#startSearch(String, boolean, android.os.Bundle, boolean)
Karl Rosaen138a0412009-04-23 19:00:21 -0700942 */
Romain Guycbb89e42009-06-08 15:52:54 -0700943 void showSearchDialog(String initialQuery, boolean selectInitialQuery,
Karl Rosaen138a0412009-04-23 19:00:21 -0700944 Bundle appSearchData, boolean globalSearch) {
Romain Guycbb89e42009-06-08 15:52:54 -0700945
Karl Rosaen138a0412009-04-23 19:00:21 -0700946 if (initialQuery == null) {
947 // Use any text typed in the launcher as the initial query
948 initialQuery = getTypedText();
949 clearTypedText();
950 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800951 if (appSearchData == null) {
952 appSearchData = new Bundle();
953 appSearchData.putString(SearchManager.SOURCE, "launcher-search");
954 }
Romain Guycbb89e42009-06-08 15:52:54 -0700955
Karl Rosaen138a0412009-04-23 19:00:21 -0700956 final SearchManager searchManager =
957 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
958
959 final Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
960 if (searchWidget != null) {
961 // This gets called when the user leaves the search dialog to go back to
962 // the Launcher.
963 searchManager.setOnCancelListener(new SearchManager.OnCancelListener() {
964 public void onCancel() {
965 searchManager.setOnCancelListener(null);
Romain Guy5a941392009-04-28 15:18:25 -0700966 stopSearch();
Romain Guycbb89e42009-06-08 15:52:54 -0700967 }
Karl Rosaen138a0412009-04-23 19:00:21 -0700968 });
969 }
Romain Guycbb89e42009-06-08 15:52:54 -0700970
Karl Rosaen138a0412009-04-23 19:00:21 -0700971 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -0700972 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800973 }
974
Karl Rosaen138a0412009-04-23 19:00:21 -0700975 /**
976 * Cancel search dialog if it is open.
Karl Rosaen138a0412009-04-23 19:00:21 -0700977 */
Romain Guy5a941392009-04-28 15:18:25 -0700978 void stopSearch() {
Karl Rosaen138a0412009-04-23 19:00:21 -0700979 // Close search dialog
980 SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Bjorn Bringert0879cef2009-07-08 12:38:25 +0100981 searchManager.stopSearch();
Karl Rosaen138a0412009-04-23 19:00:21 -0700982 // Restore search widget to its normal position
983 Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
984 if (searchWidget != null) {
985 searchWidget.stopSearch(false);
986 }
987 }
Romain Guycbb89e42009-06-08 15:52:54 -0700988
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800989 @Override
990 public boolean onCreateOptionsMenu(Menu menu) {
991 if (mDesktopLocked) return false;
992
993 super.onCreateOptionsMenu(menu);
994 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
995 .setIcon(android.R.drawable.ic_menu_add)
996 .setAlphabeticShortcut('A');
997 menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
998 .setIcon(android.R.drawable.ic_menu_gallery)
999 .setAlphabeticShortcut('W');
1000 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1001 .setIcon(android.R.drawable.ic_search_category_default)
1002 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1003 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1004 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1005 .setAlphabeticShortcut('N');
1006
1007 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001008 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1009 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010
1011 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1012 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1013 .setIntent(settings);
1014
1015 return true;
1016 }
1017
1018 @Override
1019 public boolean onPrepareOptionsMenu(Menu menu) {
1020 super.onPrepareOptionsMenu(menu);
1021
1022 mMenuAddInfo = mWorkspace.findAllVacantCells(null);
1023 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
1024
1025 return true;
1026 }
1027
1028 @Override
1029 public boolean onOptionsItemSelected(MenuItem item) {
1030 switch (item.getItemId()) {
1031 case MENU_ADD:
1032 addItems();
1033 return true;
1034 case MENU_WALLPAPER_SETTINGS:
1035 startWallpaper();
1036 return true;
1037 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001038 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001039 return true;
1040 case MENU_NOTIFICATIONS:
1041 showNotifications();
1042 return true;
1043 }
1044
1045 return super.onOptionsItemSelected(item);
1046 }
Romain Guycbb89e42009-06-08 15:52:54 -07001047
Karl Rosaen138a0412009-04-23 19:00:21 -07001048 /**
1049 * Indicates that we want global search for this activity by setting the globalSearch
1050 * argument for {@link #startSearch} to true.
1051 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001052
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001053 @Override
1054 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001055 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001056 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001057 }
1058
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001059 private void addItems() {
1060 showAddDialog(mMenuAddInfo);
1061 }
1062
1063 private void removeShortcutsForPackage(String packageName) {
1064 if (packageName != null && packageName.length() > 0) {
1065 mWorkspace.removeShortcutsForPackage(packageName);
1066 }
1067 }
Romain Guycbb89e42009-06-08 15:52:54 -07001068
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001069 private void updateShortcutsForPackage(String packageName) {
1070 if (packageName != null && packageName.length() > 0) {
1071 mWorkspace.updateShortcutsForPackage(packageName);
1072 }
1073 }
1074
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001075 void addAppWidget(Intent data) {
1076 // TODO: catch bad widget exception when sent
1077 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001078
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001079 String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
1080 if (SEARCH_WIDGET.equals(customWidget)) {
1081 // We don't need this any more, since this isn't a real app widget.
1082 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1083 // add the search widget
1084 addSearch();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 } else {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001086 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1087
1088 if (appWidget.configure != null) {
1089 // Launch over to configure widget, if needed
1090 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1091 intent.setComponent(appWidget.configure);
1092 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1093
1094 startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
1095 } else {
1096 // Otherwise just add it
1097 onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
1098 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 }
1100 }
Romain Guycbb89e42009-06-08 15:52:54 -07001101
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001102 void addSearch() {
1103 final Widget info = Widget.makeSearch();
1104 final CellLayout.CellInfo cellInfo = mAddItemCellInfo;
Romain Guycbb89e42009-06-08 15:52:54 -07001105
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001106 final int[] xy = mCellCoordinates;
1107 final int spanX = info.spanX;
1108 final int spanY = info.spanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001109
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001110 if (!findSlot(cellInfo, xy, spanX, spanY)) return;
Romain Guycbb89e42009-06-08 15:52:54 -07001111
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001112 sModel.addDesktopItem(info);
1113 LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1114 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
Romain Guycbb89e42009-06-08 15:52:54 -07001115
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001116 final View view = mInflater.inflate(info.layoutResource, null);
1117 view.setTag(info);
Karl Rosaen138a0412009-04-23 19:00:21 -07001118 Search search = (Search) view.findViewById(R.id.widget_search);
1119 search.setLauncher(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001120
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001121 mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY);
1122 }
1123
Romain Guy73b979d2009-06-09 12:57:21 -07001124 void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001125 // Handle case where user selected "Applications"
1126 String applicationName = getResources().getString(R.string.group_applications);
1127 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001128
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001129 if (applicationName != null && applicationName.equals(shortcutName)) {
1130 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1131 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001132
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001133 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1134 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Romain Guy73b979d2009-06-09 12:57:21 -07001135 startActivityForResult(pickIntent, requestCodeApplication);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001136 } else {
Romain Guy73b979d2009-06-09 12:57:21 -07001137 startActivityForResult(intent, requestCodeShortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001138 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001139 }
1140
1141 void addLiveFolder(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001142 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001143 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001144 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001145
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001146 if (folderName != null && folderName.equals(shortcutName)) {
1147 addFolder(!mDesktopLocked);
1148 } else {
1149 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1150 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001151 }
1152
1153 void addFolder(boolean insertAtFirst) {
1154 UserFolderInfo folderInfo = new UserFolderInfo();
1155 folderInfo.title = getText(R.string.folder_name);
1156
1157 CellLayout.CellInfo cellInfo = mAddItemCellInfo;
1158 cellInfo.screen = mWorkspace.getCurrentScreen();
1159 if (!findSingleSlot(cellInfo)) return;
1160
1161 // Update the model
1162 LauncherModel.addItemToDatabase(this, folderInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1163 mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
1164 sModel.addDesktopItem(folderInfo);
1165 sModel.addFolder(folderInfo);
1166
1167 // Create the view
1168 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1169 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
1170 mWorkspace.addInCurrentScreen(newFolder,
1171 cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst);
1172 }
Romain Guycbb89e42009-06-08 15:52:54 -07001173
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001174 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo,
1175 boolean insertAtFirst) {
1176 cellInfo.screen = mWorkspace.getCurrentScreen();
1177 if (!findSingleSlot(cellInfo)) return;
1178
1179 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
1180
1181 if (!mRestoring) {
1182 sModel.addDesktopItem(info);
1183
1184 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
1185 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
1186 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst);
1187 } else if (sModel.isDesktopLoaded()) {
1188 sModel.addDesktopItem(info);
1189 }
1190 }
1191
1192 static LiveFolderInfo addLiveFolder(Context context, Intent data,
1193 CellLayout.CellInfo cellInfo, boolean notify) {
1194
1195 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1196 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1197
1198 Drawable icon = null;
1199 boolean filtered = false;
1200 Intent.ShortcutIconResource iconResource = null;
1201
1202 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1203 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1204 try {
1205 iconResource = (Intent.ShortcutIconResource) extra;
1206 final PackageManager packageManager = context.getPackageManager();
1207 Resources resources = packageManager.getResourcesForApplication(
1208 iconResource.packageName);
1209 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1210 icon = resources.getDrawable(id);
1211 } catch (Exception e) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001212 w(LOG_TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213 }
1214 }
1215
1216 if (icon == null) {
1217 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1218 }
1219
1220 final LiveFolderInfo info = new LiveFolderInfo();
1221 info.icon = icon;
1222 info.filtered = filtered;
1223 info.title = name;
1224 info.iconResource = iconResource;
1225 info.uri = data.getData();
1226 info.baseIntent = baseIntent;
1227 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1228 LiveFolders.DISPLAY_MODE_GRID);
1229
1230 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1231 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
1232 sModel.addFolder(info);
1233
1234 return info;
1235 }
1236
1237 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
1238 final int[] xy = new int[2];
1239 if (findSlot(cellInfo, xy, 1, 1)) {
1240 cellInfo.cellX = xy[0];
1241 cellInfo.cellY = xy[1];
1242 return true;
1243 }
1244 return false;
1245 }
1246
1247 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
1248 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1249 boolean[] occupied = mSavedState != null ?
1250 mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null;
1251 cellInfo = mWorkspace.findAllVacantCells(occupied);
1252 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1253 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1254 return false;
1255 }
1256 }
1257 return true;
1258 }
1259
1260 private void showNotifications() {
1261 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1262 if (statusBar != null) {
1263 statusBar.expand();
1264 }
1265 }
1266
1267 private void startWallpaper() {
1268 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
1269 startActivity(Intent.createChooser(pickWallpaper, getString(R.string.chooser_wallpaper)));
1270 }
1271
1272 /**
1273 * Registers various intent receivers. The current implementation registers
1274 * only a wallpaper intent receiver to let other applications change the
1275 * wallpaper.
1276 */
1277 private void registerIntentReceivers() {
1278 if (sWallpaperReceiver == null) {
1279 final Application application = getApplication();
1280
1281 sWallpaperReceiver = new WallpaperIntentReceiver(application, this);
1282
1283 IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
1284 application.registerReceiver(sWallpaperReceiver, filter);
1285 } else {
1286 sWallpaperReceiver.setLauncher(this);
1287 }
1288
1289 IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
1290 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
1291 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
1292 filter.addDataScheme("package");
1293 registerReceiver(mApplicationsReceiver, filter);
1294 }
1295
1296 /**
1297 * Registers various content observers. The current implementation registers
1298 * only a favorites observer to keep track of the favorites applications.
1299 */
1300 private void registerContentObservers() {
1301 ContentResolver resolver = getContentResolver();
1302 resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true, mObserver);
1303 }
1304
1305 @Override
Dianne Hackborn67800862009-07-24 17:15:20 -07001306 public void onWindowFocusChanged(boolean hasFocus) {
1307 super.onWindowFocusChanged(hasFocus);
1308 if (!hasFocus) {
1309 mBackDown = mHomeDown = false;
1310 }
1311 }
1312
1313 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314 public boolean dispatchKeyEvent(KeyEvent event) {
1315 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1316 switch (event.getKeyCode()) {
1317 case KeyEvent.KEYCODE_BACK:
Dianne Hackborn67800862009-07-24 17:15:20 -07001318 mBackDown = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 return true;
1320 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001321 mHomeDown = true;
1322 return true;
1323 }
1324 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1325 switch (event.getKeyCode()) {
1326 case KeyEvent.KEYCODE_BACK:
1327 if (!event.isCanceled()) {
1328 mWorkspace.dispatchKeyEvent(event);
Joe Onorato7404ee42009-07-31 11:54:44 -07001329 if (mAllAppsDialog.isOpen) {
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001330 closeAllAppsDialog(true);
Dianne Hackborn67800862009-07-24 17:15:20 -07001331 } else {
1332 closeFolder();
1333 }
1334 }
1335 mBackDown = false;
1336 return true;
1337 case KeyEvent.KEYCODE_HOME:
1338 mHomeDown = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001339 return true;
1340 }
1341 }
1342
1343 return super.dispatchKeyEvent(event);
1344 }
1345
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001346 private void closeFolder() {
1347 Folder folder = mWorkspace.getOpenFolder();
1348 if (folder != null) {
1349 closeFolder(folder);
1350 }
1351 }
1352
1353 void closeFolder(Folder folder) {
1354 folder.getInfo().opened = false;
1355 ViewGroup parent = (ViewGroup) folder.getParent();
1356 if (parent != null) {
1357 parent.removeView(folder);
Joe Onorato00acb122009-08-04 16:04:30 -04001358 mDragController.removeDropTarget((DropTarget)folder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001359 }
1360 folder.onClose();
1361 }
1362
1363 /**
1364 * When the notification that favorites have changed is received, requests
1365 * a favorites list refresh.
1366 */
1367 private void onFavoritesChanged() {
1368 mDesktopLocked = true;
Joe Onorato7404ee42009-07-31 11:54:44 -07001369 mAllAppsDialog.lock();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 sModel.loadUserItems(false, this, false, false);
1371 }
1372
1373 void onDesktopItemsLoaded() {
1374 if (mDestroyed) return;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001375 bindDesktopItems();
1376 }
Romain Guycbb89e42009-06-08 15:52:54 -07001377
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378 /**
1379 * Refreshes the shortcuts shown on the workspace.
1380 */
1381 private void bindDesktopItems() {
1382 final ArrayList<ItemInfo> shortcuts = sModel.getDesktopItems();
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001383 final ArrayList<LauncherAppWidgetInfo> appWidgets = sModel.getDesktopAppWidgets();
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001384 final ApplicationsAdapter drawerAdapter = sModel.getApplicationsAdapter();
1385 if (shortcuts == null || appWidgets == null || drawerAdapter == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001386 return;
1387 }
1388
1389 final Workspace workspace = mWorkspace;
1390 int count = workspace.getChildCount();
1391 for (int i = 0; i < count; i++) {
1392 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
1393 }
Romain Guycbb89e42009-06-08 15:52:54 -07001394
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001395 if (DEBUG_USER_INTERFACE) {
1396 android.widget.Button finishButton = new android.widget.Button(this);
1397 finishButton.setText("Finish");
1398 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
1399
1400 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
1401 public void onClick(View v) {
1402 finish();
1403 }
1404 });
1405 }
Romain Guycbb89e42009-06-08 15:52:54 -07001406
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001407 // Flag any old binder to terminate early
1408 if (mBinder != null) {
1409 mBinder.mTerminate = true;
1410 }
Romain Guycbb89e42009-06-08 15:52:54 -07001411
Karl Rosaen138a0412009-04-23 19:00:21 -07001412 mBinder = new DesktopBinder(this, shortcuts, appWidgets, drawerAdapter);
Jeffrey Sharkey2d132af2009-03-24 21:21:09 -07001413 mBinder.startBindingItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 }
1415
1416 private void bindItems(Launcher.DesktopBinder binder,
1417 ArrayList<ItemInfo> shortcuts, int start, int count) {
1418
1419 final Workspace workspace = mWorkspace;
1420 final boolean desktopLocked = mDesktopLocked;
1421
1422 final int end = Math.min(start + DesktopBinder.ITEMS_COUNT, count);
1423 int i = start;
1424
1425 for ( ; i < end; i++) {
1426 final ItemInfo item = shortcuts.get(i);
1427 switch (item.itemType) {
1428 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1429 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1430 final View shortcut = createShortcut((ApplicationInfo) item);
1431 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
1432 !desktopLocked);
1433 break;
1434 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
1435 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1436 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1437 (UserFolderInfo) item);
1438 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
1439 !desktopLocked);
1440 break;
1441 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
1442 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
1443 R.layout.live_folder_icon, this,
1444 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1445 (LiveFolderInfo) item);
1446 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
1447 !desktopLocked);
1448 break;
1449 case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH:
1450 final int screen = workspace.getCurrentScreen();
1451 final View view = mInflater.inflate(R.layout.widget_search,
1452 (ViewGroup) workspace.getChildAt(screen), false);
Romain Guycbb89e42009-06-08 15:52:54 -07001453
Karl Rosaen138a0412009-04-23 19:00:21 -07001454 Search search = (Search) view.findViewById(R.id.widget_search);
1455 search.setLauncher(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001456
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001457 final Widget widget = (Widget) item;
1458 view.setTag(widget);
Romain Guycbb89e42009-06-08 15:52:54 -07001459
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001460 workspace.addWidget(view, widget, !desktopLocked);
1461 break;
1462 }
1463 }
1464
1465 workspace.requestLayout();
1466
1467 if (end >= count) {
1468 finishBindDesktopItems();
Karl Rosaen138a0412009-04-23 19:00:21 -07001469 binder.startBindingDrawer();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470 } else {
1471 binder.obtainMessage(DesktopBinder.MESSAGE_BIND_ITEMS, i, count).sendToTarget();
1472 }
1473 }
1474
1475 private void finishBindDesktopItems() {
1476 if (mSavedState != null) {
1477 if (!mWorkspace.hasFocus()) {
1478 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
1479 }
1480
1481 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
1482 if (userFolders != null) {
1483 for (long folderId : userFolders) {
1484 final FolderInfo info = sModel.findFolderById(folderId);
1485 if (info != null) {
1486 openFolder(info);
1487 }
1488 }
1489 final Folder openFolder = mWorkspace.getOpenFolder();
1490 if (openFolder != null) {
1491 openFolder.requestFocus();
1492 }
1493 }
1494
1495 final boolean allApps = mSavedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
1496 if (allApps) {
Joe Onorato45d43462009-07-31 14:36:51 -07001497 showAllAppsDialog();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 }
1499
1500 mSavedState = null;
1501 }
1502
1503 if (mSavedInstanceState != null) {
1504 super.onRestoreInstanceState(mSavedInstanceState);
1505 mSavedInstanceState = null;
1506 }
1507
Joe Onorato7404ee42009-07-31 11:54:44 -07001508 /* TODO
1509 if (mAllAppsDialog.isOpen && !mDrawer.hasFocus()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001510 mDrawer.requestFocus();
1511 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001512 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513
1514 mDesktopLocked = false;
Joe Onorato7404ee42009-07-31 11:54:44 -07001515 mAllAppsDialog.unlock();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516 }
Romain Guycbb89e42009-06-08 15:52:54 -07001517
Karl Rosaen138a0412009-04-23 19:00:21 -07001518 private void bindDrawer(Launcher.DesktopBinder binder,
1519 ApplicationsAdapter drawerAdapter) {
Joe Onorato93839052009-08-06 20:34:32 -07001520 // TODO mAllAppsGrid.setAdapter(drawerAdapter);
Karl Rosaen138a0412009-04-23 19:00:21 -07001521 binder.startBindingAppWidgetsWhenIdle();
1522 }
Romain Guycbb89e42009-06-08 15:52:54 -07001523
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001524 private void bindAppWidgets(Launcher.DesktopBinder binder,
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001525 LinkedList<LauncherAppWidgetInfo> appWidgets) {
Romain Guycbb89e42009-06-08 15:52:54 -07001526
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001527 final Workspace workspace = mWorkspace;
1528 final boolean desktopLocked = mDesktopLocked;
1529
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001530 if (!appWidgets.isEmpty()) {
1531 final LauncherAppWidgetInfo item = appWidgets.removeFirst();
Romain Guycbb89e42009-06-08 15:52:54 -07001532
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001533 final int appWidgetId = item.appWidgetId;
Karl Rosaen138a0412009-04-23 19:00:21 -07001534 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001535 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001536
Karl Rosaen138a0412009-04-23 19:00:21 -07001537 if (LOGD) d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s", appWidgetId, appWidgetInfo));
Romain Guycbb89e42009-06-08 15:52:54 -07001538
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001539 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1540 item.hostView.setTag(item);
Romain Guycbb89e42009-06-08 15:52:54 -07001541
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001542 workspace.addInScreen(item.hostView, item.screen, item.cellX,
1543 item.cellY, item.spanX, item.spanY, !desktopLocked);
Romain Guycbb89e42009-06-08 15:52:54 -07001544
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001545 workspace.requestLayout();
1546 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001548 if (appWidgets.isEmpty()) {
1549 if (PROFILE_ROTATE) {
1550 android.os.Debug.stopMethodTracing();
1551 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001552 } else {
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001553 binder.obtainMessage(DesktopBinder.MESSAGE_BIND_APPWIDGETS).sendToTarget();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554 }
1555 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001556
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557 /**
1558 * Launches the intent referred by the clicked shortcut.
1559 *
1560 * @param v The view representing the clicked shortcut.
1561 */
1562 public void onClick(View v) {
1563 Object tag = v.getTag();
1564 if (tag instanceof ApplicationInfo) {
1565 // Open shortcut
1566 final Intent intent = ((ApplicationInfo) tag).intent;
1567 startActivitySafely(intent);
1568 } else if (tag instanceof FolderInfo) {
1569 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001570 } else if (v == mHandleView) {
1571 if (mAllAppsDialog.isOpen) {
1572 // TODO how can we be here?
1573 } else {
Joe Onorato45d43462009-07-31 14:36:51 -07001574 showAllAppsDialog();
Joe Onorato7404ee42009-07-31 11:54:44 -07001575 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576 }
1577 }
1578
1579 void startActivitySafely(Intent intent) {
1580 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1581 try {
1582 startActivity(intent);
1583 } catch (ActivityNotFoundException e) {
1584 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1585 } catch (SecurityException e) {
1586 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Romain Guy73b979d2009-06-09 12:57:21 -07001587 e(LOG_TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001588 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1589 "or use the exported attribute for this activity.", e);
1590 }
1591 }
1592
1593 private void handleFolderClick(FolderInfo folderInfo) {
1594 if (!folderInfo.opened) {
1595 // Close any open folder
1596 closeFolder();
1597 // Open the requested folder
1598 openFolder(folderInfo);
1599 } else {
1600 // Find the open folder...
1601 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1602 int folderScreen;
1603 if (openFolder != null) {
1604 folderScreen = mWorkspace.getScreenForView(openFolder);
1605 // .. and close it
1606 closeFolder(openFolder);
1607 if (folderScreen != mWorkspace.getCurrentScreen()) {
1608 // Close any folder open on the current screen
1609 closeFolder();
1610 // Pull the folder onto this screen
1611 openFolder(folderInfo);
1612 }
1613 }
1614 }
1615 }
1616
1617 private void loadWallpaper() {
1618 // The first time the application is started, we load the wallpaper from
1619 // the ApplicationContext
1620 if (sWallpaper == null) {
Joe Onorato7404ee42009-07-31 11:54:44 -07001621 final Drawable drawable;
1622 if (false) {
1623 drawable = getWallpaper();
1624 } else {
1625 drawable = getResources().getDrawable(R.drawable.wallpaper_path);
1626 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001627 if (drawable instanceof BitmapDrawable) {
1628 sWallpaper = ((BitmapDrawable) drawable).getBitmap();
1629 } else {
1630 throw new IllegalStateException("The wallpaper must be a BitmapDrawable.");
1631 }
1632 }
Joe Onorato59791172009-07-31 16:21:40 -07001633 mWallpaperView.loadWallpaper(sWallpaper);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001634 }
1635
1636 /**
1637 * Opens the user fodler described by the specified tag. The opening of the folder
1638 * is animated relative to the specified View. If the View is null, no animation
1639 * is played.
1640 *
1641 * @param folderInfo The FolderInfo describing the folder to open.
1642 */
1643 private void openFolder(FolderInfo folderInfo) {
1644 Folder openFolder;
1645
1646 if (folderInfo instanceof UserFolderInfo) {
1647 openFolder = UserFolder.fromXml(this);
1648 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001649 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001650 } else {
1651 return;
1652 }
1653
Joe Onorato00acb122009-08-04 16:04:30 -04001654 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001655 openFolder.setLauncher(this);
1656
1657 openFolder.bind(folderInfo);
1658 folderInfo.opened = true;
1659
1660 mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4);
1661 openFolder.onOpen();
1662 }
1663
1664 /**
1665 * Returns true if the workspace is being loaded. When the workspace is loading,
1666 * no user interaction should be allowed to avoid any conflict.
1667 *
1668 * @return True if the workspace is locked, false otherwise.
1669 */
1670 boolean isWorkspaceLocked() {
1671 return mDesktopLocked;
1672 }
1673
1674 public boolean onLongClick(View v) {
1675 if (mDesktopLocked) {
1676 return false;
1677 }
1678
1679 if (!(v instanceof CellLayout)) {
1680 v = (View) v.getParent();
1681 }
1682
1683 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
1684
1685 // This happens when long clicking an item with the dpad/trackball
1686 if (cellInfo == null) {
1687 return true;
1688 }
1689
1690 if (mWorkspace.allowLongPress()) {
1691 if (cellInfo.cell == null) {
1692 if (cellInfo.valid) {
1693 // User long pressed on empty space
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001694 mWorkspace.setAllowLongPress(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001695 showAddDialog(cellInfo);
1696 }
1697 } else {
1698 if (!(cellInfo.cell instanceof Folder)) {
1699 // User long pressed on an item
1700 mWorkspace.startDrag(cellInfo);
1701 }
1702 }
1703 }
1704 return true;
1705 }
1706
1707 static LauncherModel getModel() {
1708 return sModel;
1709 }
1710
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001711 View getDrawerHandle() {
1712 return mHandleView;
1713 }
1714
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001715 boolean isDrawerDown() {
Joe Onorato7404ee42009-07-31 11:54:44 -07001716 return /* TODO !mDrawer.isMoving() && */ !mAllAppsDialog.isOpen;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 }
1718
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001719 Workspace getWorkspace() {
1720 return mWorkspace;
1721 }
1722
Joe Onorato7404ee42009-07-31 11:54:44 -07001723 /* TODO
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001724 GridView getApplicationsGrid() {
1725 return mAllAppsGrid;
1726 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001727 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001728
1729 @Override
1730 protected Dialog onCreateDialog(int id) {
1731 switch (id) {
Joe Onorato7404ee42009-07-31 11:54:44 -07001732 case DIALOG_ALL_APPS:
1733 return mAllAppsDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001734 case DIALOG_CREATE_SHORTCUT:
1735 return new CreateShortcut().createDialog();
1736 case DIALOG_RENAME_FOLDER:
1737 return new RenameFolder().createDialog();
1738 }
1739
1740 return super.onCreateDialog(id);
1741 }
1742
1743 @Override
1744 protected void onPrepareDialog(int id, Dialog dialog) {
1745 switch (id) {
Joe Onorato7404ee42009-07-31 11:54:44 -07001746 case DIALOG_ALL_APPS:
Joe Onorato93839052009-08-06 20:34:32 -07001747 // TODO mAllAppsGrid.onPrepareDialog();
Joe Onorato7404ee42009-07-31 11:54:44 -07001748 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001749 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001750 break;
1751 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001752 if (mFolderInfo != null) {
1753 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1754 final CharSequence text = mFolderInfo.title;
1755 input.setText(text);
1756 input.setSelection(0, text.length());
1757 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001758 break;
1759 }
1760 }
1761
1762 void showRenameDialog(FolderInfo info) {
1763 mFolderInfo = info;
1764 mWaitingForResult = true;
1765 showDialog(DIALOG_RENAME_FOLDER);
1766 }
1767
1768 private void showAddDialog(CellLayout.CellInfo cellInfo) {
1769 mAddItemCellInfo = cellInfo;
1770 mWaitingForResult = true;
1771 showDialog(DIALOG_CREATE_SHORTCUT);
1772 }
1773
Romain Guy73b979d2009-06-09 12:57:21 -07001774 private void pickShortcut(int requestCode, int title) {
1775 Bundle bundle = new Bundle();
1776
1777 ArrayList<String> shortcutNames = new ArrayList<String>();
1778 shortcutNames.add(getString(R.string.group_applications));
1779 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
1780
1781 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
1782 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1783 R.drawable.ic_launcher_application));
1784 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1785
1786 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1787 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
1788 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title));
1789 pickIntent.putExtras(bundle);
1790
1791 startActivityForResult(pickIntent, requestCode);
1792 }
1793
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001794 private class RenameFolder {
1795 private EditText mInput;
1796
1797 Dialog createDialog() {
1798 mWaitingForResult = true;
1799 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1800 mInput = (EditText) layout.findViewById(R.id.folder_name);
1801
1802 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1803 builder.setIcon(0);
1804 builder.setTitle(getString(R.string.rename_folder_title));
1805 builder.setCancelable(true);
1806 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1807 public void onCancel(DialogInterface dialog) {
1808 cleanup();
1809 }
1810 });
1811 builder.setNegativeButton(getString(R.string.cancel_action),
1812 new Dialog.OnClickListener() {
1813 public void onClick(DialogInterface dialog, int which) {
1814 cleanup();
1815 }
1816 }
1817 );
1818 builder.setPositiveButton(getString(R.string.rename_action),
1819 new Dialog.OnClickListener() {
1820 public void onClick(DialogInterface dialog, int which) {
1821 changeFolderName();
1822 }
1823 }
1824 );
1825 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001826
1827 final AlertDialog dialog = builder.create();
1828 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1829 public void onShow(DialogInterface dialog) {
1830 mWorkspace.lock();
1831 }
1832 });
1833
1834 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 }
1836
1837 private void changeFolderName() {
1838 final String name = mInput.getText().toString();
1839 if (!TextUtils.isEmpty(name)) {
1840 // Make sure we have the right folder info
1841 mFolderInfo = sModel.findFolderById(mFolderInfo.id);
1842 mFolderInfo.title = name;
1843 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1844
1845 if (mDesktopLocked) {
Joe Onorato7404ee42009-07-31 11:54:44 -07001846 mAllAppsDialog.lock();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001847 sModel.loadUserItems(false, Launcher.this, false, false);
1848 } else {
1849 final FolderIcon folderIcon = (FolderIcon)
1850 mWorkspace.getViewForTag(mFolderInfo);
1851 if (folderIcon != null) {
1852 folderIcon.setText(name);
1853 getWorkspace().requestLayout();
1854 } else {
1855 mDesktopLocked = true;
Joe Onorato7404ee42009-07-31 11:54:44 -07001856 mAllAppsDialog.lock();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001857 sModel.loadUserItems(false, Launcher.this, false, false);
1858 }
1859 }
1860 }
1861 cleanup();
1862 }
1863
1864 private void cleanup() {
1865 mWorkspace.unlock();
1866 dismissDialog(DIALOG_RENAME_FOLDER);
1867 mWaitingForResult = false;
1868 mFolderInfo = null;
1869 }
1870 }
1871
1872 /**
Joe Onorato7404ee42009-07-31 11:54:44 -07001873 * Holds the 3d all apps view.
1874 */
1875 private class AllAppsDialog extends Dialog implements DialogInterface.OnCancelListener,
1876 DialogInterface.OnDismissListener, DialogInterface.OnShowListener {
1877
1878 boolean isOpen;
1879
1880 AllAppsDialog(Context context) {
1881 super(context, android.R.style.Theme_Translucent_NoTitleBar);
1882
1883 setOnCancelListener(this);
1884 setOnDismissListener(this);
1885 setOnShowListener(this);
1886
1887 setContentView(R.layout.all_apps);
Joe Onorato93839052009-08-06 20:34:32 -07001888 AllAppsView grid = mAllAppsGrid = (AllAppsView)findViewById(R.id.all_apps);
Joe Onorato7404ee42009-07-31 11:54:44 -07001889
Joe Onorato00acb122009-08-04 16:04:30 -04001890 DragLayer dragLayer = (DragLayer)findViewById(R.id.drag_layer);
1891 dragLayer.setDragController(mDragController);
1892
Joe Onorato93839052009-08-06 20:34:32 -07001893 // TODO grid.setDragController(mDragController);
1894 // TODO grid.setLauncher(Launcher.this);
Joe Onorato7404ee42009-07-31 11:54:44 -07001895 }
1896
1897 public void onCancel(DialogInterface dialog) {
1898 onDestroy();
1899 }
1900
1901 public void onDismiss(DialogInterface dialog) {
1902 onDestroy();
1903 }
1904
1905 public void onShow(DialogInterface dialog) {
1906 }
1907
1908 private void onDestroy() {
Joe Onorato7404ee42009-07-31 11:54:44 -07001909 }
1910
1911 void lock() {
1912 // TODO
1913 }
1914
1915 void unlock() {
1916 // TODO
1917 }
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001918
1919 @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
1920 switch (keyCode) {
1921 case KeyEvent.KEYCODE_BACK:
1922 closeAllAppsDialog(true);
1923 return true;
1924 default:
1925 return super.onKeyDown(keyCode, event);
1926 }
1927 }
1928 }
1929
1930 void showAllAppsDialog() {
1931 mAllAppsDialog.isOpen = true;
1932 showDialog(DIALOG_ALL_APPS);
1933 mWorkspace.hide();
1934 }
1935
Joe Onorato00acb122009-08-04 16:04:30 -04001936 void showWorkspace() {
1937 mWorkspace.show();
1938 }
1939
1940 void closeAllAppsDialog(boolean animated) {
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001941 if (mAllAppsDialog.isOpen) {
1942 if (animated) {
1943 // TODO mDrawer.animateClose();
1944 mAllAppsDialog.dismiss();
1945 } else {
1946 mAllAppsDialog.dismiss();
1947 }
1948 mAllAppsDialog.isOpen = false;
1949 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
1950 mWorkspace.show();
1951 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001952 }
1953
1954 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001955 * Displays the shortcut creation dialog and launches, if necessary, the
1956 * appropriate activity.
1957 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001958 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07001959 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
1960 DialogInterface.OnShowListener {
1961
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07001963
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 Dialog createDialog() {
1965 mWaitingForResult = true;
Romain Guycbb89e42009-06-08 15:52:54 -07001966
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001967 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07001968
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1970 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001971 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07001972
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001973 builder.setInverseBackgroundForced(true);
1974
1975 AlertDialog dialog = builder.create();
1976 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001977 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07001978 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001979
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001980 return dialog;
1981 }
1982
1983 public void onCancel(DialogInterface dialog) {
1984 mWaitingForResult = false;
1985 cleanup();
1986 }
1987
Romain Guycbb89e42009-06-08 15:52:54 -07001988 public void onDismiss(DialogInterface dialog) {
1989 mWorkspace.unlock();
1990 }
1991
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001992 private void cleanup() {
1993 mWorkspace.unlock();
1994 dismissDialog(DIALOG_CREATE_SHORTCUT);
1995 }
1996
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001997 /**
1998 * Handle the action clicked in the "Add to home" dialog.
1999 */
2000 public void onClick(DialogInterface dialog, int which) {
2001 Resources res = getResources();
2002 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002003
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002004 switch (which) {
2005 case AddAdapter.ITEM_SHORTCUT: {
2006 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002007 pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002008 break;
2009 }
Romain Guycbb89e42009-06-08 15:52:54 -07002010
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002011 case AddAdapter.ITEM_APPWIDGET: {
2012 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002013
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002014 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2015 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2016 // add the search widget
2017 ArrayList<AppWidgetProviderInfo> customInfo =
2018 new ArrayList<AppWidgetProviderInfo>();
2019 AppWidgetProviderInfo info = new AppWidgetProviderInfo();
2020 info.provider = new ComponentName(getPackageName(), "XXX.YYY");
2021 info.label = getString(R.string.group_search);
2022 info.icon = R.drawable.ic_search_widget;
2023 customInfo.add(info);
2024 pickIntent.putParcelableArrayListExtra(
2025 AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
2026 ArrayList<Bundle> customExtras = new ArrayList<Bundle>();
2027 Bundle b = new Bundle();
2028 b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET);
2029 customExtras.add(b);
2030 pickIntent.putParcelableArrayListExtra(
2031 AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
2032 // start the pick activity
2033 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2034 break;
2035 }
Romain Guycbb89e42009-06-08 15:52:54 -07002036
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002037 case AddAdapter.ITEM_LIVE_FOLDER: {
2038 // Insert extra item to handle inserting folder
2039 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002040
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002041 ArrayList<String> shortcutNames = new ArrayList<String>();
2042 shortcutNames.add(res.getString(R.string.group_folder));
2043 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002044
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002045 ArrayList<ShortcutIconResource> shortcutIcons =
2046 new ArrayList<ShortcutIconResource>();
2047 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2048 R.drawable.ic_launcher_folder));
2049 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2050
2051 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2052 pickIntent.putExtra(Intent.EXTRA_INTENT,
2053 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2054 pickIntent.putExtra(Intent.EXTRA_TITLE,
2055 getText(R.string.title_select_live_folder));
2056 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002057
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002058 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2059 break;
2060 }
2061
2062 case AddAdapter.ITEM_WALLPAPER: {
2063 startWallpaper();
2064 break;
2065 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002066 }
2067 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002068
2069 public void onShow(DialogInterface dialog) {
2070 mWorkspace.lock();
2071 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002072 }
2073
2074 /**
2075 * Receives notifications when applications are added/removed.
2076 */
2077 private class ApplicationsIntentReceiver extends BroadcastReceiver {
2078 @Override
2079 public void onReceive(Context context, Intent intent) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002080 final String action = intent.getAction();
2081 final String packageName = intent.getData().getSchemeSpecificPart();
2082 final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
2083
2084 if (LauncherModel.DEBUG_LOADERS) {
2085 d(LauncherModel.LOG_TAG, "application intent received: " + action +
2086 ", replacing=" + replacing);
2087 d(LauncherModel.LOG_TAG, " --> " + intent.getData());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002088 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002089
2090 if (!Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
2091 if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
2092 if (!replacing) {
2093 removeShortcutsForPackage(packageName);
2094 if (LauncherModel.DEBUG_LOADERS) {
2095 d(LauncherModel.LOG_TAG, " --> remove package");
2096 }
2097 sModel.removePackage(Launcher.this, packageName);
2098 }
2099 // else, we are replacing the package, so a PACKAGE_ADDED will be sent
2100 // later, we will update the package at this time
2101 } else {
2102 if (!replacing) {
2103 if (LauncherModel.DEBUG_LOADERS) {
2104 d(LauncherModel.LOG_TAG, " --> add package");
2105 }
2106 sModel.addPackage(Launcher.this, packageName);
2107 } else {
2108 if (LauncherModel.DEBUG_LOADERS) {
2109 d(LauncherModel.LOG_TAG, " --> update package " + packageName);
2110 }
2111 sModel.updatePackage(Launcher.this, packageName);
2112 updateShortcutsForPackage(packageName);
2113 }
2114 }
2115 removeDialog(DIALOG_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002116 } else {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002117 if (LauncherModel.DEBUG_LOADERS) {
2118 d(LauncherModel.LOG_TAG, " --> sync package " + packageName);
2119 }
2120 sModel.syncPackage(Launcher.this, packageName);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002121 }
2122 }
2123 }
2124
2125 /**
2126 * Receives notifications whenever the user favorites have changed.
2127 */
2128 private class FavoritesChangeObserver extends ContentObserver {
2129 public FavoritesChangeObserver() {
2130 super(new Handler());
2131 }
2132
2133 @Override
2134 public void onChange(boolean selfChange) {
2135 onFavoritesChanged();
2136 }
2137 }
2138
2139 /**
2140 * Receives intents from other applications to change the wallpaper.
2141 */
2142 private static class WallpaperIntentReceiver extends BroadcastReceiver {
2143 private final Application mApplication;
2144 private WeakReference<Launcher> mLauncher;
2145
2146 WallpaperIntentReceiver(Application application, Launcher launcher) {
2147 mApplication = application;
2148 setLauncher(launcher);
2149 }
2150
2151 void setLauncher(Launcher launcher) {
2152 mLauncher = new WeakReference<Launcher>(launcher);
2153 }
2154
2155 @Override
2156 public void onReceive(Context context, Intent intent) {
2157 // Load the wallpaper from the ApplicationContext and store it locally
2158 // until the Launcher Activity is ready to use it
2159 final Drawable drawable = mApplication.getWallpaper();
2160 if (drawable instanceof BitmapDrawable) {
2161 sWallpaper = ((BitmapDrawable) drawable).getBitmap();
2162 } else {
2163 throw new IllegalStateException("The wallpaper must be a BitmapDrawable.");
2164 }
2165
2166 // If Launcher is alive, notify we have a new wallpaper
2167 if (mLauncher != null) {
2168 final Launcher launcher = mLauncher.get();
2169 if (launcher != null) {
2170 launcher.loadWallpaper();
2171 }
2172 }
2173 }
2174 }
2175
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002176 private static class DesktopBinder extends Handler implements MessageQueue.IdleHandler {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002177 static final int MESSAGE_BIND_ITEMS = 0x1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002178 static final int MESSAGE_BIND_APPWIDGETS = 0x2;
Karl Rosaen138a0412009-04-23 19:00:21 -07002179 static final int MESSAGE_BIND_DRAWER = 0x3;
Romain Guycbb89e42009-06-08 15:52:54 -07002180
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002181 // Number of items to bind in every pass
2182 static final int ITEMS_COUNT = 6;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002183
2184 private final ArrayList<ItemInfo> mShortcuts;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002185 private final LinkedList<LauncherAppWidgetInfo> mAppWidgets;
Karl Rosaen138a0412009-04-23 19:00:21 -07002186 private final ApplicationsAdapter mDrawerAdapter;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002187 private final WeakReference<Launcher> mLauncher;
Romain Guycbb89e42009-06-08 15:52:54 -07002188
Karl Rosaen138a0412009-04-23 19:00:21 -07002189 public boolean mTerminate = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002190
2191 DesktopBinder(Launcher launcher, ArrayList<ItemInfo> shortcuts,
Karl Rosaen138a0412009-04-23 19:00:21 -07002192 ArrayList<LauncherAppWidgetInfo> appWidgets,
2193 ApplicationsAdapter drawerAdapter) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002194
2195 mLauncher = new WeakReference<Launcher>(launcher);
2196 mShortcuts = shortcuts;
Karl Rosaen138a0412009-04-23 19:00:21 -07002197 mDrawerAdapter = drawerAdapter;
Romain Guycbb89e42009-06-08 15:52:54 -07002198
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002199 // Sort widgets so active workspace is bound first
2200 final int currentScreen = launcher.mWorkspace.getCurrentScreen();
2201 final int size = appWidgets.size();
2202 mAppWidgets = new LinkedList<LauncherAppWidgetInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -07002203
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002204 for (int i = 0; i < size; i++) {
2205 LauncherAppWidgetInfo appWidgetInfo = appWidgets.get(i);
2206 if (appWidgetInfo.screen == currentScreen) {
2207 mAppWidgets.addFirst(appWidgetInfo);
2208 } else {
2209 mAppWidgets.addLast(appWidgetInfo);
2210 }
2211 }
2212 }
Romain Guycbb89e42009-06-08 15:52:54 -07002213
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002214 public void startBindingItems() {
2215 obtainMessage(MESSAGE_BIND_ITEMS, 0, mShortcuts.size()).sendToTarget();
2216 }
Karl Rosaen138a0412009-04-23 19:00:21 -07002217
2218 public void startBindingDrawer() {
2219 obtainMessage(MESSAGE_BIND_DRAWER).sendToTarget();
2220 }
Romain Guycbb89e42009-06-08 15:52:54 -07002221
Jeffrey Sharkey2d132af2009-03-24 21:21:09 -07002222 public void startBindingAppWidgetsWhenIdle() {
2223 // Ask for notification when message queue becomes idle
2224 final MessageQueue messageQueue = Looper.myQueue();
2225 messageQueue.addIdleHandler(this);
2226 }
Romain Guycbb89e42009-06-08 15:52:54 -07002227
Jeffrey Sharkey2d132af2009-03-24 21:21:09 -07002228 public boolean queueIdle() {
2229 // Queue is idle, so start binding items
2230 startBindingAppWidgets();
2231 return false;
2232 }
2233
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002234 public void startBindingAppWidgets() {
2235 obtainMessage(MESSAGE_BIND_APPWIDGETS).sendToTarget();
2236 }
2237
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002238 @Override
2239 public void handleMessage(Message msg) {
2240 Launcher launcher = mLauncher.get();
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002241 if (launcher == null || mTerminate) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002242 return;
2243 }
Romain Guycbb89e42009-06-08 15:52:54 -07002244
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002245 switch (msg.what) {
2246 case MESSAGE_BIND_ITEMS: {
2247 launcher.bindItems(this, mShortcuts, msg.arg1, msg.arg2);
2248 break;
2249 }
Karl Rosaen138a0412009-04-23 19:00:21 -07002250 case MESSAGE_BIND_DRAWER: {
2251 launcher.bindDrawer(this, mDrawerAdapter);
2252 break;
2253 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002254 case MESSAGE_BIND_APPWIDGETS: {
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002255 launcher.bindAppWidgets(this, mAppWidgets);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002256 break;
2257 }
2258 }
2259 }
2260 }
2261}