blob: 759af285cc4ef74e2988f1171467a73b4c276ff3 [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 Onorato7404ee42009-07-31 11:54:44 -0700187 private AllAppsGridView 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 Hackborn107f8392009-08-05 21:32:16 -0700356 wpm.setDimensionHints(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
906 mAllAppsGrid.clearTextFilter();
907 mAllAppsGrid.setAdapter(null);
908 sModel.unbind();
909 sModel.abortLoaders();
910
911 getContentResolver().unregisterContentObserver(mObserver);
912 unregisterReceiver(mApplicationsReceiver);
913 }
914
915 @Override
916 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -0700917 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800918 super.startActivityForResult(intent, requestCode);
919 }
920
921 @Override
Romain Guycbb89e42009-06-08 15:52:54 -0700922 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800923 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700924
Joe Onoratoe77c08d2009-08-01 00:01:20 -0700925 closeAllAppsDialog(false);
Romain Guycbb89e42009-06-08 15:52:54 -0700926
Karl Rosaen138a0412009-04-23 19:00:21 -0700927 // Slide the search widget to the top, if it's on the current screen,
928 // otherwise show the search dialog immediately.
929 Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
930 if (searchWidget == null) {
931 showSearchDialog(initialQuery, selectInitialQuery, appSearchData, globalSearch);
932 } else {
933 searchWidget.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
934 // show the currently typed text in the search widget while sliding
935 searchWidget.setQuery(getTypedText());
936 }
937 }
Romain Guycbb89e42009-06-08 15:52:54 -0700938
Karl Rosaen138a0412009-04-23 19:00:21 -0700939 /**
940 * Show the search dialog immediately, without changing the search widget.
Romain Guy5a941392009-04-28 15:18:25 -0700941 *
942 * @see Activity#startSearch(String, boolean, android.os.Bundle, boolean)
Karl Rosaen138a0412009-04-23 19:00:21 -0700943 */
Romain Guycbb89e42009-06-08 15:52:54 -0700944 void showSearchDialog(String initialQuery, boolean selectInitialQuery,
Karl Rosaen138a0412009-04-23 19:00:21 -0700945 Bundle appSearchData, boolean globalSearch) {
Romain Guycbb89e42009-06-08 15:52:54 -0700946
Karl Rosaen138a0412009-04-23 19:00:21 -0700947 if (initialQuery == null) {
948 // Use any text typed in the launcher as the initial query
949 initialQuery = getTypedText();
950 clearTypedText();
951 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800952 if (appSearchData == null) {
953 appSearchData = new Bundle();
954 appSearchData.putString(SearchManager.SOURCE, "launcher-search");
955 }
Romain Guycbb89e42009-06-08 15:52:54 -0700956
Karl Rosaen138a0412009-04-23 19:00:21 -0700957 final SearchManager searchManager =
958 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
959
960 final Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
961 if (searchWidget != null) {
962 // This gets called when the user leaves the search dialog to go back to
963 // the Launcher.
964 searchManager.setOnCancelListener(new SearchManager.OnCancelListener() {
965 public void onCancel() {
966 searchManager.setOnCancelListener(null);
Romain Guy5a941392009-04-28 15:18:25 -0700967 stopSearch();
Romain Guycbb89e42009-06-08 15:52:54 -0700968 }
Karl Rosaen138a0412009-04-23 19:00:21 -0700969 });
970 }
Romain Guycbb89e42009-06-08 15:52:54 -0700971
Karl Rosaen138a0412009-04-23 19:00:21 -0700972 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -0700973 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800974 }
975
Karl Rosaen138a0412009-04-23 19:00:21 -0700976 /**
977 * Cancel search dialog if it is open.
Karl Rosaen138a0412009-04-23 19:00:21 -0700978 */
Romain Guy5a941392009-04-28 15:18:25 -0700979 void stopSearch() {
Karl Rosaen138a0412009-04-23 19:00:21 -0700980 // Close search dialog
981 SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Bjorn Bringert0879cef2009-07-08 12:38:25 +0100982 searchManager.stopSearch();
Karl Rosaen138a0412009-04-23 19:00:21 -0700983 // Restore search widget to its normal position
984 Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
985 if (searchWidget != null) {
986 searchWidget.stopSearch(false);
987 }
988 }
Romain Guycbb89e42009-06-08 15:52:54 -0700989
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800990 @Override
991 public boolean onCreateOptionsMenu(Menu menu) {
992 if (mDesktopLocked) return false;
993
994 super.onCreateOptionsMenu(menu);
995 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
996 .setIcon(android.R.drawable.ic_menu_add)
997 .setAlphabeticShortcut('A');
998 menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
999 .setIcon(android.R.drawable.ic_menu_gallery)
1000 .setAlphabeticShortcut('W');
1001 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1002 .setIcon(android.R.drawable.ic_search_category_default)
1003 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1004 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1005 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1006 .setAlphabeticShortcut('N');
1007
1008 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001009 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1010 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001011
1012 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1013 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1014 .setIntent(settings);
1015
1016 return true;
1017 }
1018
1019 @Override
1020 public boolean onPrepareOptionsMenu(Menu menu) {
1021 super.onPrepareOptionsMenu(menu);
1022
1023 mMenuAddInfo = mWorkspace.findAllVacantCells(null);
1024 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
1025
1026 return true;
1027 }
1028
1029 @Override
1030 public boolean onOptionsItemSelected(MenuItem item) {
1031 switch (item.getItemId()) {
1032 case MENU_ADD:
1033 addItems();
1034 return true;
1035 case MENU_WALLPAPER_SETTINGS:
1036 startWallpaper();
1037 return true;
1038 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001039 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 return true;
1041 case MENU_NOTIFICATIONS:
1042 showNotifications();
1043 return true;
1044 }
1045
1046 return super.onOptionsItemSelected(item);
1047 }
Romain Guycbb89e42009-06-08 15:52:54 -07001048
Karl Rosaen138a0412009-04-23 19:00:21 -07001049 /**
1050 * Indicates that we want global search for this activity by setting the globalSearch
1051 * argument for {@link #startSearch} to true.
1052 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001054 @Override
1055 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001056 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001057 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001058 }
1059
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 private void addItems() {
1061 showAddDialog(mMenuAddInfo);
1062 }
1063
1064 private void removeShortcutsForPackage(String packageName) {
1065 if (packageName != null && packageName.length() > 0) {
1066 mWorkspace.removeShortcutsForPackage(packageName);
1067 }
1068 }
Romain Guycbb89e42009-06-08 15:52:54 -07001069
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001070 private void updateShortcutsForPackage(String packageName) {
1071 if (packageName != null && packageName.length() > 0) {
1072 mWorkspace.updateShortcutsForPackage(packageName);
1073 }
1074 }
1075
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001076 void addAppWidget(Intent data) {
1077 // TODO: catch bad widget exception when sent
1078 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001079
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001080 String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
1081 if (SEARCH_WIDGET.equals(customWidget)) {
1082 // We don't need this any more, since this isn't a real app widget.
1083 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1084 // add the search widget
1085 addSearch();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001086 } else {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001087 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1088
1089 if (appWidget.configure != null) {
1090 // Launch over to configure widget, if needed
1091 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1092 intent.setComponent(appWidget.configure);
1093 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1094
1095 startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
1096 } else {
1097 // Otherwise just add it
1098 onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
1099 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001100 }
1101 }
Romain Guycbb89e42009-06-08 15:52:54 -07001102
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001103 void addSearch() {
1104 final Widget info = Widget.makeSearch();
1105 final CellLayout.CellInfo cellInfo = mAddItemCellInfo;
Romain Guycbb89e42009-06-08 15:52:54 -07001106
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107 final int[] xy = mCellCoordinates;
1108 final int spanX = info.spanX;
1109 final int spanY = info.spanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001110
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001111 if (!findSlot(cellInfo, xy, spanX, spanY)) return;
Romain Guycbb89e42009-06-08 15:52:54 -07001112
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 sModel.addDesktopItem(info);
1114 LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1115 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
Romain Guycbb89e42009-06-08 15:52:54 -07001116
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001117 final View view = mInflater.inflate(info.layoutResource, null);
1118 view.setTag(info);
Karl Rosaen138a0412009-04-23 19:00:21 -07001119 Search search = (Search) view.findViewById(R.id.widget_search);
1120 search.setLauncher(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001121
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001122 mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY);
1123 }
1124
Romain Guy73b979d2009-06-09 12:57:21 -07001125 void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001126 // Handle case where user selected "Applications"
1127 String applicationName = getResources().getString(R.string.group_applications);
1128 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001129
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001130 if (applicationName != null && applicationName.equals(shortcutName)) {
1131 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1132 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001133
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001134 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1135 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Romain Guy73b979d2009-06-09 12:57:21 -07001136 startActivityForResult(pickIntent, requestCodeApplication);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001137 } else {
Romain Guy73b979d2009-06-09 12:57:21 -07001138 startActivityForResult(intent, requestCodeShortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001139 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001140 }
1141
1142 void addLiveFolder(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001143 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001144 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001145 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001146
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001147 if (folderName != null && folderName.equals(shortcutName)) {
1148 addFolder(!mDesktopLocked);
1149 } else {
1150 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1151 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001152 }
1153
1154 void addFolder(boolean insertAtFirst) {
1155 UserFolderInfo folderInfo = new UserFolderInfo();
1156 folderInfo.title = getText(R.string.folder_name);
1157
1158 CellLayout.CellInfo cellInfo = mAddItemCellInfo;
1159 cellInfo.screen = mWorkspace.getCurrentScreen();
1160 if (!findSingleSlot(cellInfo)) return;
1161
1162 // Update the model
1163 LauncherModel.addItemToDatabase(this, folderInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1164 mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
1165 sModel.addDesktopItem(folderInfo);
1166 sModel.addFolder(folderInfo);
1167
1168 // Create the view
1169 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1170 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
1171 mWorkspace.addInCurrentScreen(newFolder,
1172 cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst);
1173 }
Romain Guycbb89e42009-06-08 15:52:54 -07001174
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo,
1176 boolean insertAtFirst) {
1177 cellInfo.screen = mWorkspace.getCurrentScreen();
1178 if (!findSingleSlot(cellInfo)) return;
1179
1180 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
1181
1182 if (!mRestoring) {
1183 sModel.addDesktopItem(info);
1184
1185 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
1186 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
1187 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst);
1188 } else if (sModel.isDesktopLoaded()) {
1189 sModel.addDesktopItem(info);
1190 }
1191 }
1192
1193 static LiveFolderInfo addLiveFolder(Context context, Intent data,
1194 CellLayout.CellInfo cellInfo, boolean notify) {
1195
1196 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1197 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1198
1199 Drawable icon = null;
1200 boolean filtered = false;
1201 Intent.ShortcutIconResource iconResource = null;
1202
1203 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1204 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1205 try {
1206 iconResource = (Intent.ShortcutIconResource) extra;
1207 final PackageManager packageManager = context.getPackageManager();
1208 Resources resources = packageManager.getResourcesForApplication(
1209 iconResource.packageName);
1210 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1211 icon = resources.getDrawable(id);
1212 } catch (Exception e) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001213 w(LOG_TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001214 }
1215 }
1216
1217 if (icon == null) {
1218 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1219 }
1220
1221 final LiveFolderInfo info = new LiveFolderInfo();
1222 info.icon = icon;
1223 info.filtered = filtered;
1224 info.title = name;
1225 info.iconResource = iconResource;
1226 info.uri = data.getData();
1227 info.baseIntent = baseIntent;
1228 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1229 LiveFolders.DISPLAY_MODE_GRID);
1230
1231 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1232 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
1233 sModel.addFolder(info);
1234
1235 return info;
1236 }
1237
1238 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
1239 final int[] xy = new int[2];
1240 if (findSlot(cellInfo, xy, 1, 1)) {
1241 cellInfo.cellX = xy[0];
1242 cellInfo.cellY = xy[1];
1243 return true;
1244 }
1245 return false;
1246 }
1247
1248 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
1249 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1250 boolean[] occupied = mSavedState != null ?
1251 mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null;
1252 cellInfo = mWorkspace.findAllVacantCells(occupied);
1253 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1254 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1255 return false;
1256 }
1257 }
1258 return true;
1259 }
1260
1261 private void showNotifications() {
1262 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1263 if (statusBar != null) {
1264 statusBar.expand();
1265 }
1266 }
1267
1268 private void startWallpaper() {
1269 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
1270 startActivity(Intent.createChooser(pickWallpaper, getString(R.string.chooser_wallpaper)));
1271 }
1272
1273 /**
1274 * Registers various intent receivers. The current implementation registers
1275 * only a wallpaper intent receiver to let other applications change the
1276 * wallpaper.
1277 */
1278 private void registerIntentReceivers() {
1279 if (sWallpaperReceiver == null) {
1280 final Application application = getApplication();
1281
1282 sWallpaperReceiver = new WallpaperIntentReceiver(application, this);
1283
1284 IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
1285 application.registerReceiver(sWallpaperReceiver, filter);
1286 } else {
1287 sWallpaperReceiver.setLauncher(this);
1288 }
1289
1290 IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
1291 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
1292 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
1293 filter.addDataScheme("package");
1294 registerReceiver(mApplicationsReceiver, filter);
1295 }
1296
1297 /**
1298 * Registers various content observers. The current implementation registers
1299 * only a favorites observer to keep track of the favorites applications.
1300 */
1301 private void registerContentObservers() {
1302 ContentResolver resolver = getContentResolver();
1303 resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true, mObserver);
1304 }
1305
1306 @Override
Dianne Hackborn67800862009-07-24 17:15:20 -07001307 public void onWindowFocusChanged(boolean hasFocus) {
1308 super.onWindowFocusChanged(hasFocus);
1309 if (!hasFocus) {
1310 mBackDown = mHomeDown = false;
1311 }
1312 }
1313
1314 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315 public boolean dispatchKeyEvent(KeyEvent event) {
1316 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1317 switch (event.getKeyCode()) {
1318 case KeyEvent.KEYCODE_BACK:
Dianne Hackborn67800862009-07-24 17:15:20 -07001319 mBackDown = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001320 return true;
1321 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001322 mHomeDown = true;
1323 return true;
1324 }
1325 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1326 switch (event.getKeyCode()) {
1327 case KeyEvent.KEYCODE_BACK:
1328 if (!event.isCanceled()) {
1329 mWorkspace.dispatchKeyEvent(event);
Joe Onorato7404ee42009-07-31 11:54:44 -07001330 if (mAllAppsDialog.isOpen) {
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001331 closeAllAppsDialog(true);
Dianne Hackborn67800862009-07-24 17:15:20 -07001332 } else {
1333 closeFolder();
1334 }
1335 }
1336 mBackDown = false;
1337 return true;
1338 case KeyEvent.KEYCODE_HOME:
1339 mHomeDown = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001340 return true;
1341 }
1342 }
1343
1344 return super.dispatchKeyEvent(event);
1345 }
1346
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001347 private void closeFolder() {
1348 Folder folder = mWorkspace.getOpenFolder();
1349 if (folder != null) {
1350 closeFolder(folder);
1351 }
1352 }
1353
1354 void closeFolder(Folder folder) {
1355 folder.getInfo().opened = false;
1356 ViewGroup parent = (ViewGroup) folder.getParent();
1357 if (parent != null) {
1358 parent.removeView(folder);
Joe Onorato00acb122009-08-04 16:04:30 -04001359 mDragController.removeDropTarget((DropTarget)folder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001360 }
1361 folder.onClose();
1362 }
1363
1364 /**
1365 * When the notification that favorites have changed is received, requests
1366 * a favorites list refresh.
1367 */
1368 private void onFavoritesChanged() {
1369 mDesktopLocked = true;
Joe Onorato7404ee42009-07-31 11:54:44 -07001370 mAllAppsDialog.lock();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 sModel.loadUserItems(false, this, false, false);
1372 }
1373
1374 void onDesktopItemsLoaded() {
1375 if (mDestroyed) return;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001376 bindDesktopItems();
1377 }
Romain Guycbb89e42009-06-08 15:52:54 -07001378
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001379 /**
1380 * Refreshes the shortcuts shown on the workspace.
1381 */
1382 private void bindDesktopItems() {
1383 final ArrayList<ItemInfo> shortcuts = sModel.getDesktopItems();
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001384 final ArrayList<LauncherAppWidgetInfo> appWidgets = sModel.getDesktopAppWidgets();
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001385 final ApplicationsAdapter drawerAdapter = sModel.getApplicationsAdapter();
1386 if (shortcuts == null || appWidgets == null || drawerAdapter == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001387 return;
1388 }
1389
1390 final Workspace workspace = mWorkspace;
1391 int count = workspace.getChildCount();
1392 for (int i = 0; i < count; i++) {
1393 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
1394 }
Romain Guycbb89e42009-06-08 15:52:54 -07001395
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001396 if (DEBUG_USER_INTERFACE) {
1397 android.widget.Button finishButton = new android.widget.Button(this);
1398 finishButton.setText("Finish");
1399 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
1400
1401 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
1402 public void onClick(View v) {
1403 finish();
1404 }
1405 });
1406 }
Romain Guycbb89e42009-06-08 15:52:54 -07001407
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001408 // Flag any old binder to terminate early
1409 if (mBinder != null) {
1410 mBinder.mTerminate = true;
1411 }
Romain Guycbb89e42009-06-08 15:52:54 -07001412
Karl Rosaen138a0412009-04-23 19:00:21 -07001413 mBinder = new DesktopBinder(this, shortcuts, appWidgets, drawerAdapter);
Jeffrey Sharkey2d132af2009-03-24 21:21:09 -07001414 mBinder.startBindingItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001415 }
1416
1417 private void bindItems(Launcher.DesktopBinder binder,
1418 ArrayList<ItemInfo> shortcuts, int start, int count) {
1419
1420 final Workspace workspace = mWorkspace;
1421 final boolean desktopLocked = mDesktopLocked;
1422
1423 final int end = Math.min(start + DesktopBinder.ITEMS_COUNT, count);
1424 int i = start;
1425
1426 for ( ; i < end; i++) {
1427 final ItemInfo item = shortcuts.get(i);
1428 switch (item.itemType) {
1429 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1430 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1431 final View shortcut = createShortcut((ApplicationInfo) item);
1432 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
1433 !desktopLocked);
1434 break;
1435 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
1436 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1437 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1438 (UserFolderInfo) item);
1439 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
1440 !desktopLocked);
1441 break;
1442 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
1443 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
1444 R.layout.live_folder_icon, this,
1445 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1446 (LiveFolderInfo) item);
1447 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
1448 !desktopLocked);
1449 break;
1450 case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH:
1451 final int screen = workspace.getCurrentScreen();
1452 final View view = mInflater.inflate(R.layout.widget_search,
1453 (ViewGroup) workspace.getChildAt(screen), false);
Romain Guycbb89e42009-06-08 15:52:54 -07001454
Karl Rosaen138a0412009-04-23 19:00:21 -07001455 Search search = (Search) view.findViewById(R.id.widget_search);
1456 search.setLauncher(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001457
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458 final Widget widget = (Widget) item;
1459 view.setTag(widget);
Romain Guycbb89e42009-06-08 15:52:54 -07001460
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 workspace.addWidget(view, widget, !desktopLocked);
1462 break;
1463 }
1464 }
1465
1466 workspace.requestLayout();
1467
1468 if (end >= count) {
1469 finishBindDesktopItems();
Karl Rosaen138a0412009-04-23 19:00:21 -07001470 binder.startBindingDrawer();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 } else {
1472 binder.obtainMessage(DesktopBinder.MESSAGE_BIND_ITEMS, i, count).sendToTarget();
1473 }
1474 }
1475
1476 private void finishBindDesktopItems() {
1477 if (mSavedState != null) {
1478 if (!mWorkspace.hasFocus()) {
1479 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
1480 }
1481
1482 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
1483 if (userFolders != null) {
1484 for (long folderId : userFolders) {
1485 final FolderInfo info = sModel.findFolderById(folderId);
1486 if (info != null) {
1487 openFolder(info);
1488 }
1489 }
1490 final Folder openFolder = mWorkspace.getOpenFolder();
1491 if (openFolder != null) {
1492 openFolder.requestFocus();
1493 }
1494 }
1495
1496 final boolean allApps = mSavedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
1497 if (allApps) {
Joe Onorato45d43462009-07-31 14:36:51 -07001498 showAllAppsDialog();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001499 }
1500
1501 mSavedState = null;
1502 }
1503
1504 if (mSavedInstanceState != null) {
1505 super.onRestoreInstanceState(mSavedInstanceState);
1506 mSavedInstanceState = null;
1507 }
1508
Joe Onorato7404ee42009-07-31 11:54:44 -07001509 /* TODO
1510 if (mAllAppsDialog.isOpen && !mDrawer.hasFocus()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001511 mDrawer.requestFocus();
1512 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001513 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001514
1515 mDesktopLocked = false;
Joe Onorato7404ee42009-07-31 11:54:44 -07001516 mAllAppsDialog.unlock();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 }
Romain Guycbb89e42009-06-08 15:52:54 -07001518
Karl Rosaen138a0412009-04-23 19:00:21 -07001519 private void bindDrawer(Launcher.DesktopBinder binder,
1520 ApplicationsAdapter drawerAdapter) {
1521 mAllAppsGrid.setAdapter(drawerAdapter);
1522 binder.startBindingAppWidgetsWhenIdle();
1523 }
Romain Guycbb89e42009-06-08 15:52:54 -07001524
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001525 private void bindAppWidgets(Launcher.DesktopBinder binder,
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001526 LinkedList<LauncherAppWidgetInfo> appWidgets) {
Romain Guycbb89e42009-06-08 15:52:54 -07001527
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001528 final Workspace workspace = mWorkspace;
1529 final boolean desktopLocked = mDesktopLocked;
1530
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001531 if (!appWidgets.isEmpty()) {
1532 final LauncherAppWidgetInfo item = appWidgets.removeFirst();
Romain Guycbb89e42009-06-08 15:52:54 -07001533
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001534 final int appWidgetId = item.appWidgetId;
Karl Rosaen138a0412009-04-23 19:00:21 -07001535 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001536 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001537
Karl Rosaen138a0412009-04-23 19:00:21 -07001538 if (LOGD) d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s", appWidgetId, appWidgetInfo));
Romain Guycbb89e42009-06-08 15:52:54 -07001539
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001540 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1541 item.hostView.setTag(item);
Romain Guycbb89e42009-06-08 15:52:54 -07001542
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001543 workspace.addInScreen(item.hostView, item.screen, item.cellX,
1544 item.cellY, item.spanX, item.spanY, !desktopLocked);
Romain Guycbb89e42009-06-08 15:52:54 -07001545
Jeffrey Sharkeyd18299f2009-03-24 18:11:49 -07001546 workspace.requestLayout();
1547 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001548
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001549 if (appWidgets.isEmpty()) {
1550 if (PROFILE_ROTATE) {
1551 android.os.Debug.stopMethodTracing();
1552 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 } else {
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001554 binder.obtainMessage(DesktopBinder.MESSAGE_BIND_APPWIDGETS).sendToTarget();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555 }
1556 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001557
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 /**
1559 * Launches the intent referred by the clicked shortcut.
1560 *
1561 * @param v The view representing the clicked shortcut.
1562 */
1563 public void onClick(View v) {
1564 Object tag = v.getTag();
1565 if (tag instanceof ApplicationInfo) {
1566 // Open shortcut
1567 final Intent intent = ((ApplicationInfo) tag).intent;
1568 startActivitySafely(intent);
1569 } else if (tag instanceof FolderInfo) {
1570 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001571 } else if (v == mHandleView) {
1572 if (mAllAppsDialog.isOpen) {
1573 // TODO how can we be here?
1574 } else {
Joe Onorato45d43462009-07-31 14:36:51 -07001575 showAllAppsDialog();
Joe Onorato7404ee42009-07-31 11:54:44 -07001576 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577 }
1578 }
1579
1580 void startActivitySafely(Intent intent) {
1581 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1582 try {
1583 startActivity(intent);
1584 } catch (ActivityNotFoundException e) {
1585 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1586 } catch (SecurityException e) {
1587 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Romain Guy73b979d2009-06-09 12:57:21 -07001588 e(LOG_TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001589 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1590 "or use the exported attribute for this activity.", e);
1591 }
1592 }
1593
1594 private void handleFolderClick(FolderInfo folderInfo) {
1595 if (!folderInfo.opened) {
1596 // Close any open folder
1597 closeFolder();
1598 // Open the requested folder
1599 openFolder(folderInfo);
1600 } else {
1601 // Find the open folder...
1602 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1603 int folderScreen;
1604 if (openFolder != null) {
1605 folderScreen = mWorkspace.getScreenForView(openFolder);
1606 // .. and close it
1607 closeFolder(openFolder);
1608 if (folderScreen != mWorkspace.getCurrentScreen()) {
1609 // Close any folder open on the current screen
1610 closeFolder();
1611 // Pull the folder onto this screen
1612 openFolder(folderInfo);
1613 }
1614 }
1615 }
1616 }
1617
1618 private void loadWallpaper() {
1619 // The first time the application is started, we load the wallpaper from
1620 // the ApplicationContext
1621 if (sWallpaper == null) {
Joe Onorato7404ee42009-07-31 11:54:44 -07001622 final Drawable drawable;
1623 if (false) {
1624 drawable = getWallpaper();
1625 } else {
1626 drawable = getResources().getDrawable(R.drawable.wallpaper_path);
1627 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001628 if (drawable instanceof BitmapDrawable) {
1629 sWallpaper = ((BitmapDrawable) drawable).getBitmap();
1630 } else {
1631 throw new IllegalStateException("The wallpaper must be a BitmapDrawable.");
1632 }
1633 }
Joe Onorato59791172009-07-31 16:21:40 -07001634 mWallpaperView.loadWallpaper(sWallpaper);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001635 }
1636
1637 /**
1638 * Opens the user fodler described by the specified tag. The opening of the folder
1639 * is animated relative to the specified View. If the View is null, no animation
1640 * is played.
1641 *
1642 * @param folderInfo The FolderInfo describing the folder to open.
1643 */
1644 private void openFolder(FolderInfo folderInfo) {
1645 Folder openFolder;
1646
1647 if (folderInfo instanceof UserFolderInfo) {
1648 openFolder = UserFolder.fromXml(this);
1649 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001650 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001651 } else {
1652 return;
1653 }
1654
Joe Onorato00acb122009-08-04 16:04:30 -04001655 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001656 openFolder.setLauncher(this);
1657
1658 openFolder.bind(folderInfo);
1659 folderInfo.opened = true;
1660
1661 mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4);
1662 openFolder.onOpen();
1663 }
1664
1665 /**
1666 * Returns true if the workspace is being loaded. When the workspace is loading,
1667 * no user interaction should be allowed to avoid any conflict.
1668 *
1669 * @return True if the workspace is locked, false otherwise.
1670 */
1671 boolean isWorkspaceLocked() {
1672 return mDesktopLocked;
1673 }
1674
1675 public boolean onLongClick(View v) {
1676 if (mDesktopLocked) {
1677 return false;
1678 }
1679
1680 if (!(v instanceof CellLayout)) {
1681 v = (View) v.getParent();
1682 }
1683
1684 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
1685
1686 // This happens when long clicking an item with the dpad/trackball
1687 if (cellInfo == null) {
1688 return true;
1689 }
1690
1691 if (mWorkspace.allowLongPress()) {
1692 if (cellInfo.cell == null) {
1693 if (cellInfo.valid) {
1694 // User long pressed on empty space
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001695 mWorkspace.setAllowLongPress(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001696 showAddDialog(cellInfo);
1697 }
1698 } else {
1699 if (!(cellInfo.cell instanceof Folder)) {
1700 // User long pressed on an item
1701 mWorkspace.startDrag(cellInfo);
1702 }
1703 }
1704 }
1705 return true;
1706 }
1707
1708 static LauncherModel getModel() {
1709 return sModel;
1710 }
1711
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001712 View getDrawerHandle() {
1713 return mHandleView;
1714 }
1715
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716 boolean isDrawerDown() {
Joe Onorato7404ee42009-07-31 11:54:44 -07001717 return /* TODO !mDrawer.isMoving() && */ !mAllAppsDialog.isOpen;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718 }
1719
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001720 Workspace getWorkspace() {
1721 return mWorkspace;
1722 }
1723
Joe Onorato7404ee42009-07-31 11:54:44 -07001724 /* TODO
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001725 GridView getApplicationsGrid() {
1726 return mAllAppsGrid;
1727 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001728 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729
1730 @Override
1731 protected Dialog onCreateDialog(int id) {
1732 switch (id) {
Joe Onorato7404ee42009-07-31 11:54:44 -07001733 case DIALOG_ALL_APPS:
1734 return mAllAppsDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001735 case DIALOG_CREATE_SHORTCUT:
1736 return new CreateShortcut().createDialog();
1737 case DIALOG_RENAME_FOLDER:
1738 return new RenameFolder().createDialog();
1739 }
1740
1741 return super.onCreateDialog(id);
1742 }
1743
1744 @Override
1745 protected void onPrepareDialog(int id, Dialog dialog) {
1746 switch (id) {
Joe Onorato7404ee42009-07-31 11:54:44 -07001747 case DIALOG_ALL_APPS:
Joe Onorato00acb122009-08-04 16:04:30 -04001748 mAllAppsGrid.onPrepareDialog();
Joe Onorato7404ee42009-07-31 11:54:44 -07001749 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001750 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 break;
1752 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001753 if (mFolderInfo != null) {
1754 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1755 final CharSequence text = mFolderInfo.title;
1756 input.setText(text);
1757 input.setSelection(0, text.length());
1758 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001759 break;
1760 }
1761 }
1762
1763 void showRenameDialog(FolderInfo info) {
1764 mFolderInfo = info;
1765 mWaitingForResult = true;
1766 showDialog(DIALOG_RENAME_FOLDER);
1767 }
1768
1769 private void showAddDialog(CellLayout.CellInfo cellInfo) {
1770 mAddItemCellInfo = cellInfo;
1771 mWaitingForResult = true;
1772 showDialog(DIALOG_CREATE_SHORTCUT);
1773 }
1774
Romain Guy73b979d2009-06-09 12:57:21 -07001775 private void pickShortcut(int requestCode, int title) {
1776 Bundle bundle = new Bundle();
1777
1778 ArrayList<String> shortcutNames = new ArrayList<String>();
1779 shortcutNames.add(getString(R.string.group_applications));
1780 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
1781
1782 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
1783 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1784 R.drawable.ic_launcher_application));
1785 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1786
1787 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1788 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
1789 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title));
1790 pickIntent.putExtras(bundle);
1791
1792 startActivityForResult(pickIntent, requestCode);
1793 }
1794
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795 private class RenameFolder {
1796 private EditText mInput;
1797
1798 Dialog createDialog() {
1799 mWaitingForResult = true;
1800 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1801 mInput = (EditText) layout.findViewById(R.id.folder_name);
1802
1803 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1804 builder.setIcon(0);
1805 builder.setTitle(getString(R.string.rename_folder_title));
1806 builder.setCancelable(true);
1807 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1808 public void onCancel(DialogInterface dialog) {
1809 cleanup();
1810 }
1811 });
1812 builder.setNegativeButton(getString(R.string.cancel_action),
1813 new Dialog.OnClickListener() {
1814 public void onClick(DialogInterface dialog, int which) {
1815 cleanup();
1816 }
1817 }
1818 );
1819 builder.setPositiveButton(getString(R.string.rename_action),
1820 new Dialog.OnClickListener() {
1821 public void onClick(DialogInterface dialog, int which) {
1822 changeFolderName();
1823 }
1824 }
1825 );
1826 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001827
1828 final AlertDialog dialog = builder.create();
1829 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1830 public void onShow(DialogInterface dialog) {
1831 mWorkspace.lock();
1832 }
1833 });
1834
1835 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001836 }
1837
1838 private void changeFolderName() {
1839 final String name = mInput.getText().toString();
1840 if (!TextUtils.isEmpty(name)) {
1841 // Make sure we have the right folder info
1842 mFolderInfo = sModel.findFolderById(mFolderInfo.id);
1843 mFolderInfo.title = name;
1844 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1845
1846 if (mDesktopLocked) {
Joe Onorato7404ee42009-07-31 11:54:44 -07001847 mAllAppsDialog.lock();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001848 sModel.loadUserItems(false, Launcher.this, false, false);
1849 } else {
1850 final FolderIcon folderIcon = (FolderIcon)
1851 mWorkspace.getViewForTag(mFolderInfo);
1852 if (folderIcon != null) {
1853 folderIcon.setText(name);
1854 getWorkspace().requestLayout();
1855 } else {
1856 mDesktopLocked = true;
Joe Onorato7404ee42009-07-31 11:54:44 -07001857 mAllAppsDialog.lock();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001858 sModel.loadUserItems(false, Launcher.this, false, false);
1859 }
1860 }
1861 }
1862 cleanup();
1863 }
1864
1865 private void cleanup() {
1866 mWorkspace.unlock();
1867 dismissDialog(DIALOG_RENAME_FOLDER);
1868 mWaitingForResult = false;
1869 mFolderInfo = null;
1870 }
1871 }
1872
1873 /**
Joe Onorato7404ee42009-07-31 11:54:44 -07001874 * Holds the 3d all apps view.
1875 */
1876 private class AllAppsDialog extends Dialog implements DialogInterface.OnCancelListener,
1877 DialogInterface.OnDismissListener, DialogInterface.OnShowListener {
1878
1879 boolean isOpen;
1880
1881 AllAppsDialog(Context context) {
1882 super(context, android.R.style.Theme_Translucent_NoTitleBar);
1883
1884 setOnCancelListener(this);
1885 setOnDismissListener(this);
1886 setOnShowListener(this);
1887
1888 setContentView(R.layout.all_apps);
1889 AllAppsGridView grid = mAllAppsGrid = (AllAppsGridView)findViewById(R.id.all_apps);
1890
Joe Onorato00acb122009-08-04 16:04:30 -04001891 DragLayer dragLayer = (DragLayer)findViewById(R.id.drag_layer);
1892 dragLayer.setDragController(mDragController);
1893
Joe Onorato7404ee42009-07-31 11:54:44 -07001894 grid.setTextFilterEnabled(false);
Joe Onorato00acb122009-08-04 16:04:30 -04001895 grid.setDragController(mDragController);
Joe Onorato7404ee42009-07-31 11:54:44 -07001896 grid.setLauncher(Launcher.this);
1897 }
1898
1899 public void onCancel(DialogInterface dialog) {
1900 onDestroy();
1901 }
1902
1903 public void onDismiss(DialogInterface dialog) {
1904 onDestroy();
1905 }
1906
1907 public void onShow(DialogInterface dialog) {
1908 }
1909
1910 private void onDestroy() {
Joe Onorato7404ee42009-07-31 11:54:44 -07001911 }
1912
1913 void lock() {
1914 // TODO
1915 }
1916
1917 void unlock() {
1918 // TODO
1919 }
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001920
1921 @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
1922 switch (keyCode) {
1923 case KeyEvent.KEYCODE_BACK:
1924 closeAllAppsDialog(true);
1925 return true;
1926 default:
1927 return super.onKeyDown(keyCode, event);
1928 }
1929 }
1930 }
1931
1932 void showAllAppsDialog() {
1933 mAllAppsDialog.isOpen = true;
1934 showDialog(DIALOG_ALL_APPS);
1935 mWorkspace.hide();
1936 }
1937
Joe Onorato00acb122009-08-04 16:04:30 -04001938 void showWorkspace() {
1939 mWorkspace.show();
1940 }
1941
1942 void closeAllAppsDialog(boolean animated) {
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001943 if (mAllAppsDialog.isOpen) {
1944 if (animated) {
1945 // TODO mDrawer.animateClose();
1946 mAllAppsDialog.dismiss();
1947 } else {
1948 mAllAppsDialog.dismiss();
1949 }
1950 mAllAppsDialog.isOpen = false;
1951 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
1952 mWorkspace.show();
1953 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001954 }
1955
1956 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 * Displays the shortcut creation dialog and launches, if necessary, the
1958 * appropriate activity.
1959 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001960 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07001961 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
1962 DialogInterface.OnShowListener {
1963
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07001965
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001966 Dialog createDialog() {
1967 mWaitingForResult = true;
Romain Guycbb89e42009-06-08 15:52:54 -07001968
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07001970
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001971 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1972 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001973 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07001974
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975 builder.setInverseBackgroundForced(true);
1976
1977 AlertDialog dialog = builder.create();
1978 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001979 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07001980 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001981
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001982 return dialog;
1983 }
1984
1985 public void onCancel(DialogInterface dialog) {
1986 mWaitingForResult = false;
1987 cleanup();
1988 }
1989
Romain Guycbb89e42009-06-08 15:52:54 -07001990 public void onDismiss(DialogInterface dialog) {
1991 mWorkspace.unlock();
1992 }
1993
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 private void cleanup() {
1995 mWorkspace.unlock();
1996 dismissDialog(DIALOG_CREATE_SHORTCUT);
1997 }
1998
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001999 /**
2000 * Handle the action clicked in the "Add to home" dialog.
2001 */
2002 public void onClick(DialogInterface dialog, int which) {
2003 Resources res = getResources();
2004 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002005
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002006 switch (which) {
2007 case AddAdapter.ITEM_SHORTCUT: {
2008 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002009 pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002010 break;
2011 }
Romain Guycbb89e42009-06-08 15:52:54 -07002012
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002013 case AddAdapter.ITEM_APPWIDGET: {
2014 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002015
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002016 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2017 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2018 // add the search widget
2019 ArrayList<AppWidgetProviderInfo> customInfo =
2020 new ArrayList<AppWidgetProviderInfo>();
2021 AppWidgetProviderInfo info = new AppWidgetProviderInfo();
2022 info.provider = new ComponentName(getPackageName(), "XXX.YYY");
2023 info.label = getString(R.string.group_search);
2024 info.icon = R.drawable.ic_search_widget;
2025 customInfo.add(info);
2026 pickIntent.putParcelableArrayListExtra(
2027 AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
2028 ArrayList<Bundle> customExtras = new ArrayList<Bundle>();
2029 Bundle b = new Bundle();
2030 b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET);
2031 customExtras.add(b);
2032 pickIntent.putParcelableArrayListExtra(
2033 AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
2034 // start the pick activity
2035 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2036 break;
2037 }
Romain Guycbb89e42009-06-08 15:52:54 -07002038
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002039 case AddAdapter.ITEM_LIVE_FOLDER: {
2040 // Insert extra item to handle inserting folder
2041 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002042
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002043 ArrayList<String> shortcutNames = new ArrayList<String>();
2044 shortcutNames.add(res.getString(R.string.group_folder));
2045 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002046
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002047 ArrayList<ShortcutIconResource> shortcutIcons =
2048 new ArrayList<ShortcutIconResource>();
2049 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2050 R.drawable.ic_launcher_folder));
2051 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2052
2053 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2054 pickIntent.putExtra(Intent.EXTRA_INTENT,
2055 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2056 pickIntent.putExtra(Intent.EXTRA_TITLE,
2057 getText(R.string.title_select_live_folder));
2058 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002059
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002060 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2061 break;
2062 }
2063
2064 case AddAdapter.ITEM_WALLPAPER: {
2065 startWallpaper();
2066 break;
2067 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002068 }
2069 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002070
2071 public void onShow(DialogInterface dialog) {
2072 mWorkspace.lock();
2073 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002074 }
2075
2076 /**
2077 * Receives notifications when applications are added/removed.
2078 */
2079 private class ApplicationsIntentReceiver extends BroadcastReceiver {
2080 @Override
2081 public void onReceive(Context context, Intent intent) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002082 final String action = intent.getAction();
2083 final String packageName = intent.getData().getSchemeSpecificPart();
2084 final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
2085
2086 if (LauncherModel.DEBUG_LOADERS) {
2087 d(LauncherModel.LOG_TAG, "application intent received: " + action +
2088 ", replacing=" + replacing);
2089 d(LauncherModel.LOG_TAG, " --> " + intent.getData());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002090 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002091
2092 if (!Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
2093 if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
2094 if (!replacing) {
2095 removeShortcutsForPackage(packageName);
2096 if (LauncherModel.DEBUG_LOADERS) {
2097 d(LauncherModel.LOG_TAG, " --> remove package");
2098 }
2099 sModel.removePackage(Launcher.this, packageName);
2100 }
2101 // else, we are replacing the package, so a PACKAGE_ADDED will be sent
2102 // later, we will update the package at this time
2103 } else {
2104 if (!replacing) {
2105 if (LauncherModel.DEBUG_LOADERS) {
2106 d(LauncherModel.LOG_TAG, " --> add package");
2107 }
2108 sModel.addPackage(Launcher.this, packageName);
2109 } else {
2110 if (LauncherModel.DEBUG_LOADERS) {
2111 d(LauncherModel.LOG_TAG, " --> update package " + packageName);
2112 }
2113 sModel.updatePackage(Launcher.this, packageName);
2114 updateShortcutsForPackage(packageName);
2115 }
2116 }
2117 removeDialog(DIALOG_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002118 } else {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002119 if (LauncherModel.DEBUG_LOADERS) {
2120 d(LauncherModel.LOG_TAG, " --> sync package " + packageName);
2121 }
2122 sModel.syncPackage(Launcher.this, packageName);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123 }
2124 }
2125 }
2126
2127 /**
2128 * Receives notifications whenever the user favorites have changed.
2129 */
2130 private class FavoritesChangeObserver extends ContentObserver {
2131 public FavoritesChangeObserver() {
2132 super(new Handler());
2133 }
2134
2135 @Override
2136 public void onChange(boolean selfChange) {
2137 onFavoritesChanged();
2138 }
2139 }
2140
2141 /**
2142 * Receives intents from other applications to change the wallpaper.
2143 */
2144 private static class WallpaperIntentReceiver extends BroadcastReceiver {
2145 private final Application mApplication;
2146 private WeakReference<Launcher> mLauncher;
2147
2148 WallpaperIntentReceiver(Application application, Launcher launcher) {
2149 mApplication = application;
2150 setLauncher(launcher);
2151 }
2152
2153 void setLauncher(Launcher launcher) {
2154 mLauncher = new WeakReference<Launcher>(launcher);
2155 }
2156
2157 @Override
2158 public void onReceive(Context context, Intent intent) {
2159 // Load the wallpaper from the ApplicationContext and store it locally
2160 // until the Launcher Activity is ready to use it
2161 final Drawable drawable = mApplication.getWallpaper();
2162 if (drawable instanceof BitmapDrawable) {
2163 sWallpaper = ((BitmapDrawable) drawable).getBitmap();
2164 } else {
2165 throw new IllegalStateException("The wallpaper must be a BitmapDrawable.");
2166 }
2167
2168 // If Launcher is alive, notify we have a new wallpaper
2169 if (mLauncher != null) {
2170 final Launcher launcher = mLauncher.get();
2171 if (launcher != null) {
2172 launcher.loadWallpaper();
2173 }
2174 }
2175 }
2176 }
2177
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002178 private static class DesktopBinder extends Handler implements MessageQueue.IdleHandler {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002179 static final int MESSAGE_BIND_ITEMS = 0x1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002180 static final int MESSAGE_BIND_APPWIDGETS = 0x2;
Karl Rosaen138a0412009-04-23 19:00:21 -07002181 static final int MESSAGE_BIND_DRAWER = 0x3;
Romain Guycbb89e42009-06-08 15:52:54 -07002182
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002183 // Number of items to bind in every pass
2184 static final int ITEMS_COUNT = 6;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002185
2186 private final ArrayList<ItemInfo> mShortcuts;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002187 private final LinkedList<LauncherAppWidgetInfo> mAppWidgets;
Karl Rosaen138a0412009-04-23 19:00:21 -07002188 private final ApplicationsAdapter mDrawerAdapter;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 private final WeakReference<Launcher> mLauncher;
Romain Guycbb89e42009-06-08 15:52:54 -07002190
Karl Rosaen138a0412009-04-23 19:00:21 -07002191 public boolean mTerminate = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002192
2193 DesktopBinder(Launcher launcher, ArrayList<ItemInfo> shortcuts,
Karl Rosaen138a0412009-04-23 19:00:21 -07002194 ArrayList<LauncherAppWidgetInfo> appWidgets,
2195 ApplicationsAdapter drawerAdapter) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002196
2197 mLauncher = new WeakReference<Launcher>(launcher);
2198 mShortcuts = shortcuts;
Karl Rosaen138a0412009-04-23 19:00:21 -07002199 mDrawerAdapter = drawerAdapter;
Romain Guycbb89e42009-06-08 15:52:54 -07002200
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002201 // Sort widgets so active workspace is bound first
2202 final int currentScreen = launcher.mWorkspace.getCurrentScreen();
2203 final int size = appWidgets.size();
2204 mAppWidgets = new LinkedList<LauncherAppWidgetInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -07002205
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002206 for (int i = 0; i < size; i++) {
2207 LauncherAppWidgetInfo appWidgetInfo = appWidgets.get(i);
2208 if (appWidgetInfo.screen == currentScreen) {
2209 mAppWidgets.addFirst(appWidgetInfo);
2210 } else {
2211 mAppWidgets.addLast(appWidgetInfo);
2212 }
2213 }
2214 }
Romain Guycbb89e42009-06-08 15:52:54 -07002215
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002216 public void startBindingItems() {
2217 obtainMessage(MESSAGE_BIND_ITEMS, 0, mShortcuts.size()).sendToTarget();
2218 }
Karl Rosaen138a0412009-04-23 19:00:21 -07002219
2220 public void startBindingDrawer() {
2221 obtainMessage(MESSAGE_BIND_DRAWER).sendToTarget();
2222 }
Romain Guycbb89e42009-06-08 15:52:54 -07002223
Jeffrey Sharkey2d132af2009-03-24 21:21:09 -07002224 public void startBindingAppWidgetsWhenIdle() {
2225 // Ask for notification when message queue becomes idle
2226 final MessageQueue messageQueue = Looper.myQueue();
2227 messageQueue.addIdleHandler(this);
2228 }
Romain Guycbb89e42009-06-08 15:52:54 -07002229
Jeffrey Sharkey2d132af2009-03-24 21:21:09 -07002230 public boolean queueIdle() {
2231 // Queue is idle, so start binding items
2232 startBindingAppWidgets();
2233 return false;
2234 }
2235
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002236 public void startBindingAppWidgets() {
2237 obtainMessage(MESSAGE_BIND_APPWIDGETS).sendToTarget();
2238 }
2239
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002240 @Override
2241 public void handleMessage(Message msg) {
2242 Launcher launcher = mLauncher.get();
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002243 if (launcher == null || mTerminate) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002244 return;
2245 }
Romain Guycbb89e42009-06-08 15:52:54 -07002246
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002247 switch (msg.what) {
2248 case MESSAGE_BIND_ITEMS: {
2249 launcher.bindItems(this, mShortcuts, msg.arg1, msg.arg2);
2250 break;
2251 }
Karl Rosaen138a0412009-04-23 19:00:21 -07002252 case MESSAGE_BIND_DRAWER: {
2253 launcher.bindDrawer(this, mDrawerAdapter);
2254 break;
2255 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002256 case MESSAGE_BIND_APPWIDGETS: {
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07002257 launcher.bindAppWidgets(this, mAppWidgets);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002258 break;
2259 }
2260 }
2261 }
2262 }
2263}