blob: e7a4a3c877f97e8330dc9ace5298d7ebc0ff4558 [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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.app.Dialog;
Mike LeBeau736cf282009-07-02 17:46:59 -070022import android.app.ISearchManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.app.SearchManager;
24import android.app.StatusBarManager;
Dianne Hackborn8355ae32009-09-07 21:47:51 -070025import android.app.WallpaperInfo;
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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080029import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.content.Context;
31import android.content.DialogInterface;
32import android.content.Intent;
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -070033import android.content.Intent.ShortcutIconResource;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.pm.ActivityInfo;
Dianne Hackborn8355ae32009-09-07 21:47:51 -070035import android.content.pm.LabeledIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.pm.PackageManager;
37import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070039import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.graphics.Bitmap;
Romain Guy1fbc1c82009-11-09 20:43:08 -080042import android.graphics.Rect;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.graphics.drawable.Drawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080044import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080045import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.os.Parcelable;
47import android.os.RemoteException;
48import android.os.ServiceManager;
Joe Onorato080d9b62009-11-02 12:01:11 -050049import android.os.SystemClock;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.provider.LiveFolders;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051import android.text.Selection;
52import android.text.SpannableStringBuilder;
53import android.text.TextUtils;
54import android.text.method.TextKeyListener;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070055import static android.util.Log.*;
Joe Onorato7c312c12009-08-13 21:36:53 -070056import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057import android.view.Display;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058import android.view.KeyEvent;
59import android.view.LayoutInflater;
60import android.view.Menu;
61import android.view.MenuItem;
62import android.view.View;
63import android.view.ViewGroup;
Romain Guy1fbc1c82009-11-09 20:43:08 -080064import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.view.View.OnLongClickListener;
66import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.widget.EditText;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.widget.TextView;
69import android.widget.Toast;
Romain Guy8a73c512009-11-09 19:19:59 -080070import android.widget.ImageView;
Romain Guy1fbc1c82009-11-09 20:43:08 -080071import android.widget.PopupWindow;
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
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075import java.util.ArrayList;
Joe Onorato9c1289c2009-08-17 11:03:03 -040076import java.util.HashMap;
Romain Guy98d01652009-06-30 16:21:04 -070077import java.io.DataOutputStream;
78import java.io.FileNotFoundException;
79import java.io.IOException;
80import java.io.DataInputStream;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081
82/**
83 * Default launcher application.
84 */
Joe Onorato9c1289c2009-08-17 11:03:03 -040085public final class Launcher extends Activity
Romain Guy1fbc1c82009-11-09 20:43:08 -080086 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, View.OnTouchListener, View.OnKeyListener {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087 static final String LOG_TAG = "Launcher";
Joe Onorato9c1289c2009-08-17 11:03:03 -040088 static final String TAG = LOG_TAG;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089 static final boolean LOGD = false;
90
Joe Onorato9c1289c2009-08-17 11:03:03 -040091 static final boolean PROFILE_STARTUP = false;
92 static final boolean PROFILE_ROTATE = false;
93 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;
Mike Clerona0618e42009-10-22 13:55:21 -0700111 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800112
113 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
114
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700115 static final String EXTRA_CUSTOM_WIDGET = "custom_widget";
116 static final String SEARCH_WIDGET = "search_widget";
117
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800118 static final int SCREEN_COUNT = 5;
119 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120 static final int NUMBER_CELLS_X = 4;
Romain Guycbb89e42009-06-08 15:52:54 -0700121 static final int NUMBER_CELLS_Y = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
Joe Onorato7c312c12009-08-13 21:36:53 -0700123 static final int DIALOG_CREATE_SHORTCUT = 1;
124 static final int DIALOG_RENAME_FOLDER = 2;
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
Joe Onorato9c1289c2009-08-17 11:03:03 -0400155 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800158 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800160 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
161
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 private LayoutInflater mInflater;
163
Joe Onorato00acb122009-08-04 16:04:30 -0400164 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700166
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700167 private AppWidgetManager mAppWidgetManager;
168 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700169
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 private CellLayout.CellInfo mAddItemCellInfo;
171 private CellLayout.CellInfo mMenuAddInfo;
172 private final int[] mCellCoordinates = new int[2];
173 private FolderInfo mFolderInfo;
174
Joe Onorato7c312c12009-08-13 21:36:53 -0700175 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700176 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700177 private AllAppsView mAllAppsGrid;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 private Bundle mSavedState;
180
181 private SpannableStringBuilder mDefaultKeySsb = null;
182
Mike LeBeau736cf282009-07-02 17:46:59 -0700183 private boolean mIsNewIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184
Joe Onorato9c1289c2009-08-17 11:03:03 -0400185 private boolean mWorkspaceLoading = true;
186
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 private boolean mRestoring;
188 private boolean mWaitingForResult;
Joe Onoratoff3862d2009-10-07 10:35:51 -0700189 private boolean mExitingBecauseOfLaunch;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190
191 private Bundle mSavedInstanceState;
192
Joe Onorato9c1289c2009-08-17 11:03:03 -0400193 private LauncherModel mModel;
194
Romain Guy84f296c2009-11-04 15:00:44 -0800195 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
196 private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700197
Joe Onorato080d9b62009-11-02 12:01:11 -0500198 public static long lastStartTime;
Romain Guy1fbc1c82009-11-09 20:43:08 -0800199 private ImageView mPreviousView;
200 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500201
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 @Override
203 protected void onCreate(Bundle savedInstanceState) {
Joe Onorato080d9b62009-11-02 12:01:11 -0500204 lastStartTime = SystemClock.uptimeMillis();
205
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700207
Joe Onorato9c1289c2009-08-17 11:03:03 -0400208 mModel = ((LauncherApplication)getApplication()).setLauncher(this);
Joe Onorato41a12d22009-10-31 18:30:00 -0400209 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700211
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700212 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700213 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
214 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700215
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216 if (PROFILE_STARTUP) {
217 android.os.Debug.startMethodTracing("/sdcard/launcher");
218 }
219
220 checkForLocaleChange();
221 setWallpaperDimension();
222
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800223 setContentView(R.layout.launcher);
224 setupViews();
225
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800226 registerContentObservers();
227
Joe Onorato7c312c12009-08-13 21:36:53 -0700228 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700229
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230 mSavedState = savedInstanceState;
231 restoreState(mSavedState);
232
233 if (PROFILE_STARTUP) {
234 android.os.Debug.stopMethodTracing();
235 }
236
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700237 // We have a new AllAppsView, we need to re-bind everything, and it could have
238 // changed in our absence.
239 mModel.setAllAppsDirty();
240 mModel.setWorkspaceDirty();
241
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800242 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400243 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244 }
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);
Jason Samsfd22dac2009-09-20 17:24:16 -0700254
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
Romain Guy84f296c2009-11-04 15:00:44 -0800266 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267
Romain Guy84f296c2009-11-04 15:00:44 -0800268 if (localeChanged) {
Romain Guy98d01652009-06-30 16:21:04 -0700269 localeConfiguration.locale = locale;
270 localeConfiguration.mcc = mcc;
271 localeConfiguration.mnc = mnc;
272
273 writeConfiguration(this, localeConfiguration);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400274 AppInfoCache.flush();
Romain Guy98d01652009-06-30 16:21:04 -0700275 }
276 }
277
278 private static class LocaleConfiguration {
279 public String locale;
280 public int mcc = -1;
281 public int mnc = -1;
282 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700283
Romain Guy98d01652009-06-30 16:21:04 -0700284 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
285 DataInputStream in = null;
286 try {
287 in = new DataInputStream(context.openFileInput(PREFERENCES));
288 configuration.locale = in.readUTF();
289 configuration.mcc = in.readInt();
290 configuration.mnc = in.readInt();
291 } catch (FileNotFoundException e) {
292 // Ignore
293 } catch (IOException e) {
294 // Ignore
295 } finally {
296 if (in != null) {
297 try {
298 in.close();
299 } catch (IOException e) {
300 // Ignore
301 }
302 }
303 }
304 }
305
306 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
307 DataOutputStream out = null;
308 try {
309 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
310 out.writeUTF(configuration.locale);
311 out.writeInt(configuration.mcc);
312 out.writeInt(configuration.mnc);
313 out.flush();
314 } catch (FileNotFoundException e) {
315 // Ignore
316 } catch (IOException e) {
317 //noinspection ResultOfMethodCallIgnored
318 context.getFileStreamPath(PREFERENCES).delete();
319 } finally {
320 if (out != null) {
321 try {
322 out.close();
323 } catch (IOException e) {
324 // Ignore
325 }
326 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800327 }
328 }
329
330 static int getScreen() {
331 synchronized (sLock) {
332 return sScreen;
333 }
334 }
335
336 static void setScreen(int screen) {
337 synchronized (sLock) {
338 sScreen = screen;
339 }
340 }
341
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800342 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700343 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800344
345 Display display = getWindowManager().getDefaultDisplay();
346 boolean isPortrait = display.getWidth() < display.getHeight();
347
348 final int width = isPortrait ? display.getWidth() : display.getHeight();
349 final int height = isPortrait ? display.getHeight() : display.getWidth();
Dianne Hackborn64271802009-08-08 20:54:24 -0700350 wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800351 }
352
353 @Override
354 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700355 mWaitingForResult = false;
356
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800357 // The pattern used here is that a user PICKs a specific application,
358 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700359
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
361 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700362
Romain Guy94dabf12009-07-21 10:55:43 -0700363 if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 switch (requestCode) {
365 case REQUEST_PICK_APPLICATION:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400366 completeAddApplication(this, data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800367 break;
368 case REQUEST_PICK_SHORTCUT:
Romain Guy73b979d2009-06-09 12:57:21 -0700369 processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 break;
371 case REQUEST_CREATE_SHORTCUT:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400372 completeAddShortcut(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800373 break;
374 case REQUEST_PICK_LIVE_FOLDER:
375 addLiveFolder(data);
376 break;
377 case REQUEST_CREATE_LIVE_FOLDER:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400378 completeAddLiveFolder(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700380 case REQUEST_PICK_APPWIDGET:
381 addAppWidget(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700383 case REQUEST_CREATE_APPWIDGET:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400384 completeAddAppWidget(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700386 case REQUEST_PICK_WALLPAPER:
387 // We just wanted the activity result here so we can clear mWaitingForResult
388 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800389 }
Romain Guy18042c82009-11-06 11:44:55 -0800390 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
391 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
392 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700393 // Clean up the appWidgetId if we canceled
394 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
395 if (appWidgetId != -1) {
396 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800397 }
398 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800399 }
400
401 @Override
402 protected void onResume() {
Joe Onorato080d9b62009-11-02 12:01:11 -0500403 if (lastStartTime == 0) {
404 lastStartTime = SystemClock.uptimeMillis();
405 }
406
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 super.onResume();
408
409 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400410 mWorkspaceLoading = true;
411 mModel.startLoader(this, true);
412 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800413 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700414
Mike LeBeau736cf282009-07-02 17:46:59 -0700415 // If this was a new intent (i.e., the mIsNewIntent flag got set to true by
416 // onNewIntent), then close the search dialog if needed, because it probably
417 // came from the user pressing 'home' (rather than, for example, pressing 'back').
418 if (mIsNewIntent) {
419 // Post to a handler so that this happens after the search dialog tries to open
420 // itself again.
421 mWorkspace.post(new Runnable() {
422 public void run() {
423 ISearchManager searchManagerService = ISearchManager.Stub.asInterface(
424 ServiceManager.getService(Context.SEARCH_SERVICE));
425 try {
426 searchManagerService.stopSearch();
427 } catch (RemoteException e) {
428 e(LOG_TAG, "error stopping search", e);
Jason Samsfd22dac2009-09-20 17:24:16 -0700429 }
Mike LeBeau736cf282009-07-02 17:46:59 -0700430 }
431 });
432 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700433
Mike LeBeau736cf282009-07-02 17:46:59 -0700434 mIsNewIntent = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435 }
436
437 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700438 protected void onPause() {
439 super.onPause();
Joe Onoratoff3862d2009-10-07 10:35:51 -0700440 if (mExitingBecauseOfLaunch) {
441 mExitingBecauseOfLaunch = false;
442 closeAllApps(false);
443 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800444 dismissPreview(mPreviousView);
445 dismissPreview(mNextView);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700446 }
Romain Guycbb89e42009-06-08 15:52:54 -0700447
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700448 @Override
449 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400450 // Flag the loader to stop early before switching
451 mModel.stopLoader();
Romain Guycbb89e42009-06-08 15:52:54 -0700452
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700453 if (PROFILE_ROTATE) {
454 android.os.Debug.startMethodTracing("/sdcard/launcher-rotate");
455 }
456 return null;
457 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700458
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459 private boolean acceptFilter() {
460 final InputMethodManager inputManager = (InputMethodManager)
461 getSystemService(Context.INPUT_METHOD_SERVICE);
462 return !inputManager.isFullscreenMode();
463 }
464
465 @Override
466 public boolean onKeyDown(int keyCode, KeyEvent event) {
467 boolean handled = super.onKeyDown(keyCode, event);
468 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
469 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
470 keyCode, event);
471 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700472 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700473 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700474 // showSearchDialog()
475 // If there are multiple keystrokes before the search dialog takes focus,
476 // onSearchRequested() will be called for every keystroke,
477 // but it is idempotent, so it's fine.
478 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800479 }
480 }
481
482 return handled;
483 }
484
Karl Rosaen138a0412009-04-23 19:00:21 -0700485 private String getTypedText() {
486 return mDefaultKeySsb.toString();
487 }
488
489 private void clearTypedText() {
490 mDefaultKeySsb.clear();
491 mDefaultKeySsb.clearSpans();
492 Selection.setSelection(mDefaultKeySsb, 0);
493 }
494
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800495 /**
496 * Restores the previous state, if it exists.
497 *
498 * @param savedState The previous state.
499 */
500 private void restoreState(Bundle savedState) {
501 if (savedState == null) {
502 return;
503 }
504
505 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
506 if (currentScreen > -1) {
507 mWorkspace.setCurrentScreen(currentScreen);
508 }
509
510 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
511 if (addScreen > -1) {
512 mAddItemCellInfo = new CellLayout.CellInfo();
513 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
514 addItemCellInfo.valid = true;
515 addItemCellInfo.screen = addScreen;
516 addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
517 addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
518 addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
519 addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
520 addItemCellInfo.findVacantCellsFromOccupied(
521 savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS),
522 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X),
523 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y));
524 mRestoring = true;
525 }
526
527 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
528 if (renameFolder) {
529 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400530 mFolderInfo = mModel.getFolderById(this, mFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800531 mRestoring = true;
532 }
533 }
534
535 /**
536 * Finds all the views we need and configure them properly.
537 */
538 private void setupViews() {
Joe Onorato00acb122009-08-04 16:04:30 -0400539 DragController dragController = mDragController;
540
Romain Guyb1b69f52009-08-10 15:10:15 -0700541 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400542 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800543
Joe Onorato7c312c12009-08-13 21:36:53 -0700544 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700545 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700546 mAllAppsGrid.setDragController(dragController);
Joe Onorato85a02a82009-09-08 12:34:22 -0700547 mAllAppsGrid.setWillNotDraw(false); // We don't want a hole punched in our window.
Mike Cleronb6082fa2009-10-19 17:03:36 -0700548 // Manage focusability manually since this thing is always visible
549 mAllAppsGrid.setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700550
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800551 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
552 final Workspace workspace = mWorkspace;
553
Joe Onorato7c312c12009-08-13 21:36:53 -0700554 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
555 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800556
Joe Onorato7c312c12009-08-13 21:36:53 -0700557 mHandleView = (HandleView) findViewById(R.id.all_apps_button);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700558 mHandleView.setLauncher(this);
Joe Onorato7404ee42009-07-31 11:54:44 -0700559 mHandleView.setOnClickListener(this);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800560
561 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
562 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
563
564 Drawable previous = mPreviousView.getDrawable();
565 Drawable next = mNextView.getDrawable();
Romain Guy8a73c512009-11-09 19:19:59 -0800566 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800567
Romain Guy1fbc1c82009-11-09 20:43:08 -0800568 mPreviousView.setOnLongClickListener(this);
569 mPreviousView.setOnTouchListener(this);
570 mPreviousView.setOnKeyListener(this);
571 mNextView.setOnLongClickListener(this);
572 mNextView.setOnTouchListener(this);
573 mNextView.setOnKeyListener(this);
574
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400576 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800578
579 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400580 deleteZone.setDragController(dragController);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700581 deleteZone.setHandle(mHandleView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800582
Joe Onorato00acb122009-08-04 16:04:30 -0400583 dragController.setDragScoller(workspace);
584 dragController.setDragListener(deleteZone);
585 dragController.setScrollView(dragLayer);
Jason Samsfd22dac2009-09-20 17:24:16 -0700586
Joe Onorato00acb122009-08-04 16:04:30 -0400587 // The order here is bottom to top.
588 dragController.addDropTarget(workspace);
589 dragController.addDropTarget(deleteZone);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800590 }
591
Romain Guy8a73c512009-11-09 19:19:59 -0800592 @SuppressWarnings({"UnusedDeclaration"})
593 public void previousScreen(View v) {
594 mWorkspace.scrollLeft();
595 }
596
597 @SuppressWarnings({"UnusedDeclaration"})
598 public void nextScreen(View v) {
599 mWorkspace.scrollRight();
600 }
601
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800602 /**
603 * Creates a view representing a shortcut.
604 *
605 * @param info The data structure describing the shortcut.
606 *
607 * @return A View inflated from R.layout.application.
608 */
609 View createShortcut(ApplicationInfo info) {
610 return createShortcut(R.layout.application,
611 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
612 }
613
614 /**
615 * Creates a view representing a shortcut inflated from the specified resource.
616 *
617 * @param layoutResId The id of the XML layout used to create the shortcut.
618 * @param parent The group the shortcut belongs to.
619 * @param info The data structure describing the shortcut.
620 *
621 * @return A View inflated from layoutResId.
622 */
623 View createShortcut(int layoutResId, ViewGroup parent, ApplicationInfo info) {
624 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
625
Joe Onorato5162ea92009-09-03 09:39:42 -0700626 if (info.icon == null) {
627 info.icon = AppInfoCache.getIconDrawable(getPackageManager(), info);
628 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800629 if (!info.filtered) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700630 info.icon = Utilities.createIconThumbnail(info.icon, this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800631 info.filtered = true;
632 }
633
634 favorite.setCompoundDrawablesWithIntrinsicBounds(null, info.icon, null, null);
635 favorite.setText(info.title);
636 favorite.setTag(info);
637 favorite.setOnClickListener(this);
638
639 return favorite;
640 }
641
642 /**
643 * Add an application shortcut to the workspace.
644 *
645 * @param data The intent describing the application.
646 * @param cellInfo The position on screen where to create the shortcut.
647 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400648 void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800649 cellInfo.screen = mWorkspace.getCurrentScreen();
650 if (!findSingleSlot(cellInfo)) return;
651
Romain Guy73b979d2009-06-09 12:57:21 -0700652 final ApplicationInfo info = infoFromApplicationIntent(context, data);
653 if (info != null) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400654 mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked());
Romain Guy73b979d2009-06-09 12:57:21 -0700655 }
656 }
657
658 private static ApplicationInfo infoFromApplicationIntent(Context context, Intent data) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800659 ComponentName component = data.getComponent();
660 PackageManager packageManager = context.getPackageManager();
661 ActivityInfo activityInfo = null;
662 try {
663 activityInfo = packageManager.getActivityInfo(component, 0 /* no flags */);
664 } catch (NameNotFoundException e) {
Romain Guy73b979d2009-06-09 12:57:21 -0700665 e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 }
Romain Guycbb89e42009-06-08 15:52:54 -0700667
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800668 if (activityInfo != null) {
669 ApplicationInfo itemInfo = new ApplicationInfo();
Romain Guycbb89e42009-06-08 15:52:54 -0700670
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 itemInfo.title = activityInfo.loadLabel(packageManager);
672 if (itemInfo.title == null) {
673 itemInfo.title = activityInfo.name;
674 }
Romain Guycbb89e42009-06-08 15:52:54 -0700675
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800676 itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK |
677 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
678 itemInfo.icon = activityInfo.loadIcon(packageManager);
679 itemInfo.container = ItemInfo.NO_ID;
680
Romain Guy73b979d2009-06-09 12:57:21 -0700681 return itemInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 }
Romain Guy73b979d2009-06-09 12:57:21 -0700683
684 return null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800685 }
Romain Guycbb89e42009-06-08 15:52:54 -0700686
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800687 /**
688 * Add a shortcut to the workspace.
689 *
690 * @param data The intent describing the shortcut.
691 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400693 private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694 cellInfo.screen = mWorkspace.getCurrentScreen();
695 if (!findSingleSlot(cellInfo)) return;
Romain Guycbb89e42009-06-08 15:52:54 -0700696
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800697 final ApplicationInfo info = addShortcut(this, data, cellInfo, false);
698
699 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800700 final View view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400701 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
702 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800703 }
704 }
705
Romain Guycbb89e42009-06-08 15:52:54 -0700706
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800707 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700708 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800709 *
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700710 * @param data The intent describing the appWidgetId.
711 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800712 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400713 private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800714 Bundle extras = data.getExtras();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700715 int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Romain Guycbb89e42009-06-08 15:52:54 -0700716
Romain Guy18042c82009-11-06 11:44:55 -0800717 if (LOGD) d(LOG_TAG, "dumping extras content=" + extras.toString());
Romain Guycbb89e42009-06-08 15:52:54 -0700718
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700719 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700720
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700721 // Calculate the grid spans needed to fit this widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800722 CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700723 int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
Romain Guycbb89e42009-06-08 15:52:54 -0700724
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800725 // Try finding open space on Launcher screen
726 final int[] xy = mCellCoordinates;
Romain Guy18042c82009-11-06 11:44:55 -0800727 if (!findSlot(cellInfo, xy, spans[0], spans[1])) {
728 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
729 return;
730 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800731
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700732 // Build Launcher-specific widget info and save to database
733 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800734 launcherInfo.spanX = spans[0];
735 launcherInfo.spanY = spans[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700736
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800737 LauncherModel.addItemToDatabase(this, launcherInfo,
738 LauncherSettings.Favorites.CONTAINER_DESKTOP,
739 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
740
741 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400742 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700743
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800744 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700745 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700746
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700747 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800748 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700749
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400751 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800752 }
753 }
Romain Guycbb89e42009-06-08 15:52:54 -0700754
Joe Onorato9c1289c2009-08-17 11:03:03 -0400755 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
756 mDesktopItems.remove(launcherInfo);
757 launcherInfo.hostView = null;
758 }
759
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700760 public LauncherAppWidgetHost getAppWidgetHost() {
761 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 }
Romain Guycbb89e42009-06-08 15:52:54 -0700763
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800764 static ApplicationInfo addShortcut(Context context, Intent data,
765 CellLayout.CellInfo cellInfo, boolean notify) {
766
Romain Guy73b979d2009-06-09 12:57:21 -0700767 final ApplicationInfo info = infoFromShortcutIntent(context, data);
768 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
769 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
770
771 return info;
772 }
773
774 private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800775 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
776 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
777 Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
778
779 Drawable icon = null;
780 boolean filtered = false;
781 boolean customIcon = false;
Romain Guy73b979d2009-06-09 12:57:21 -0700782 ShortcutIconResource iconResource = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800783
784 if (bitmap != null) {
785 icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
786 filtered = true;
787 customIcon = true;
788 } else {
789 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
Romain Guy73b979d2009-06-09 12:57:21 -0700790 if (extra != null && extra instanceof ShortcutIconResource) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800791 try {
Romain Guy73b979d2009-06-09 12:57:21 -0700792 iconResource = (ShortcutIconResource) extra;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800793 final PackageManager packageManager = context.getPackageManager();
794 Resources resources = packageManager.getResourcesForApplication(
795 iconResource.packageName);
796 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
797 icon = resources.getDrawable(id);
798 } catch (Exception e) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700799 w(LOG_TAG, "Could not load shortcut icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800800 }
801 }
802 }
803
804 if (icon == null) {
805 icon = context.getPackageManager().getDefaultActivityIcon();
806 }
807
808 final ApplicationInfo info = new ApplicationInfo();
809 info.icon = icon;
810 info.filtered = filtered;
811 info.title = name;
812 info.intent = intent;
813 info.customIcon = customIcon;
814 info.iconResource = iconResource;
815
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800816 return info;
817 }
818
819 @Override
820 protected void onNewIntent(Intent intent) {
821 super.onNewIntent(intent);
822
823 // Close the menu
824 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
825 getWindow().closeAllPanels();
Jason Samsfd22dac2009-09-20 17:24:16 -0700826
Joe Onorato742966b2009-10-07 10:26:17 -0700827 // Whatever we were doing is hereby canceled.
828 mWaitingForResult = false;
829
Mike LeBeau736cf282009-07-02 17:46:59 -0700830 // Set this flag so that onResume knows to close the search dialog if it's open,
831 // because this was a new intent (thus a press of 'home' or some such) rather than
832 // for example onResume being called when the user pressed the 'back' button.
833 mIsNewIntent = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800834
835 try {
836 dismissDialog(DIALOG_CREATE_SHORTCUT);
837 // Unlock the workspace if the dialog was showing
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800838 } catch (Exception e) {
839 // An exception is thrown if the dialog is not visible, which is fine
840 }
841
842 try {
843 dismissDialog(DIALOG_RENAME_FOLDER);
844 // Unlock the workspace if the dialog was showing
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 } catch (Exception e) {
846 // An exception is thrown if the dialog is not visible, which is fine
847 }
848
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) !=
850 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) {
Romain Guy73b979d2009-06-09 12:57:21 -0700851
Romain Guy94dabf12009-07-21 10:55:43 -0700852 if (!mWorkspace.isDefaultScreenShowing()) {
853 mWorkspace.moveToDefaultScreen();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 }
Romain Guy1dd3a072009-07-16 13:21:01 -0700855
Joe Onorato7bb17492009-09-24 17:51:01 -0700856 closeAllApps(true);
Romain Guy73b979d2009-06-09 12:57:21 -0700857
858 final View v = getWindow().peekDecorView();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800859 if (v != null && v.getWindowToken() != null) {
860 InputMethodManager imm = (InputMethodManager)getSystemService(
861 INPUT_METHOD_SERVICE);
862 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
863 }
864 } else {
Joe Onorato7bb17492009-09-24 17:51:01 -0700865 closeAllApps(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800866 }
867 }
868 }
869
870 @Override
871 protected void onRestoreInstanceState(Bundle savedInstanceState) {
872 // Do not call super here
873 mSavedInstanceState = savedInstanceState;
874 }
875
876 @Override
877 protected void onSaveInstanceState(Bundle outState) {
878 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen());
879
880 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
881 if (folders.size() > 0) {
882 final int count = folders.size();
883 long[] ids = new long[count];
884 for (int i = 0; i < count; i++) {
885 final FolderInfo info = folders.get(i).getInfo();
886 ids[i] = info.id;
887 }
888 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
889 } else {
890 super.onSaveInstanceState(outState);
891 }
892
Romain Guy3cf604f2009-06-16 13:12:53 -0700893 final boolean isConfigurationChange = getChangingConfigurations() != 0;
894
Romain Guy5a941392009-04-28 15:18:25 -0700895 // When the drawer is opened and we are saving the state because of a
896 // configuration change
Joe Onoratofb0ca672009-09-14 17:55:46 -0400897 // TODO should not do this if the drawer is currently closing.
898 if (isAllAppsVisible() && isConfigurationChange) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800899 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -0700900 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901
902 if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
903 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
904 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);
905
906 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
907 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
908 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
909 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
910 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
911 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
912 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
913 outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS,
914 layout.getOccupiedCells());
915 }
916
917 if (mFolderInfo != null && mWaitingForResult) {
918 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
919 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
920 }
921 }
922
923 @Override
924 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800925 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -0700926
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800927 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700928 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800929 } catch (NullPointerException ex) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700930 w(LOG_TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800931 }
932
933 TextKeyListener.getInstance().release();
934
Joe Onorato9c1289c2009-08-17 11:03:03 -0400935 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800936
Joe Onorato9c1289c2009-08-17 11:03:03 -0400937 unbindDesktopItems();
938 AppInfoCache.unbindDrawables();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800939
940 getContentResolver().unregisterContentObserver(mWidgetObserver);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800941
942 dismissPreview(mPreviousView);
943 dismissPreview(mNextView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800944 }
945
946 @Override
947 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -0700948 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800949 super.startActivityForResult(intent, requestCode);
950 }
951
952 @Override
Romain Guycbb89e42009-06-08 15:52:54 -0700953 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800954 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700955
Joe Onorato7bb17492009-09-24 17:51:01 -0700956 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -0700957
Karl Rosaen138a0412009-04-23 19:00:21 -0700958 // Slide the search widget to the top, if it's on the current screen,
959 // otherwise show the search dialog immediately.
960 Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
961 if (searchWidget == null) {
962 showSearchDialog(initialQuery, selectInitialQuery, appSearchData, globalSearch);
963 } else {
964 searchWidget.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
965 // show the currently typed text in the search widget while sliding
966 searchWidget.setQuery(getTypedText());
967 }
968 }
Romain Guycbb89e42009-06-08 15:52:54 -0700969
Karl Rosaen138a0412009-04-23 19:00:21 -0700970 /**
971 * Show the search dialog immediately, without changing the search widget.
Romain Guy5a941392009-04-28 15:18:25 -0700972 *
973 * @see Activity#startSearch(String, boolean, android.os.Bundle, boolean)
Karl Rosaen138a0412009-04-23 19:00:21 -0700974 */
Romain Guycbb89e42009-06-08 15:52:54 -0700975 void showSearchDialog(String initialQuery, boolean selectInitialQuery,
Karl Rosaen138a0412009-04-23 19:00:21 -0700976 Bundle appSearchData, boolean globalSearch) {
Romain Guycbb89e42009-06-08 15:52:54 -0700977
Karl Rosaen138a0412009-04-23 19:00:21 -0700978 if (initialQuery == null) {
979 // Use any text typed in the launcher as the initial query
980 initialQuery = getTypedText();
981 clearTypedText();
982 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800983 if (appSearchData == null) {
984 appSearchData = new Bundle();
985 appSearchData.putString(SearchManager.SOURCE, "launcher-search");
986 }
Romain Guycbb89e42009-06-08 15:52:54 -0700987
Karl Rosaen138a0412009-04-23 19:00:21 -0700988 final SearchManager searchManager =
989 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
990
991 final Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
992 if (searchWidget != null) {
993 // This gets called when the user leaves the search dialog to go back to
994 // the Launcher.
995 searchManager.setOnCancelListener(new SearchManager.OnCancelListener() {
996 public void onCancel() {
997 searchManager.setOnCancelListener(null);
Romain Guy5a941392009-04-28 15:18:25 -0700998 stopSearch();
Romain Guycbb89e42009-06-08 15:52:54 -0700999 }
Karl Rosaen138a0412009-04-23 19:00:21 -07001000 });
1001 }
Romain Guycbb89e42009-06-08 15:52:54 -07001002
Karl Rosaen138a0412009-04-23 19:00:21 -07001003 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001004 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001005 }
1006
Karl Rosaen138a0412009-04-23 19:00:21 -07001007 /**
1008 * Cancel search dialog if it is open.
Karl Rosaen138a0412009-04-23 19:00:21 -07001009 */
Romain Guy5a941392009-04-28 15:18:25 -07001010 void stopSearch() {
Karl Rosaen138a0412009-04-23 19:00:21 -07001011 // Close search dialog
1012 SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Bjorn Bringert0879cef2009-07-08 12:38:25 +01001013 searchManager.stopSearch();
Karl Rosaen138a0412009-04-23 19:00:21 -07001014 // Restore search widget to its normal position
1015 Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
1016 if (searchWidget != null) {
1017 searchWidget.stopSearch(false);
1018 }
1019 }
Romain Guycbb89e42009-06-08 15:52:54 -07001020
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001021 @Override
1022 public boolean onCreateOptionsMenu(Menu menu) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001023 if (isWorkspaceLocked()) {
1024 return false;
1025 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001026
1027 super.onCreateOptionsMenu(menu);
1028 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1029 .setIcon(android.R.drawable.ic_menu_add)
1030 .setAlphabeticShortcut('A');
1031 menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1032 .setIcon(android.R.drawable.ic_menu_gallery)
1033 .setAlphabeticShortcut('W');
1034 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1035 .setIcon(android.R.drawable.ic_search_category_default)
1036 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1037 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1038 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1039 .setAlphabeticShortcut('N');
1040
1041 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001042 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1043 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001044
1045 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1046 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1047 .setIntent(settings);
1048
1049 return true;
1050 }
1051
1052 @Override
1053 public boolean onPrepareOptionsMenu(Menu menu) {
1054 super.onPrepareOptionsMenu(menu);
1055
1056 mMenuAddInfo = mWorkspace.findAllVacantCells(null);
1057 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
1058
1059 return true;
1060 }
1061
1062 @Override
1063 public boolean onOptionsItemSelected(MenuItem item) {
1064 switch (item.getItemId()) {
1065 case MENU_ADD:
1066 addItems();
1067 return true;
1068 case MENU_WALLPAPER_SETTINGS:
1069 startWallpaper();
1070 return true;
1071 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001072 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001073 return true;
1074 case MENU_NOTIFICATIONS:
1075 showNotifications();
1076 return true;
1077 }
1078
1079 return super.onOptionsItemSelected(item);
1080 }
Romain Guycbb89e42009-06-08 15:52:54 -07001081
Karl Rosaen138a0412009-04-23 19:00:21 -07001082 /**
1083 * Indicates that we want global search for this activity by setting the globalSearch
1084 * argument for {@link #startSearch} to true.
1085 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001086
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001087 @Override
1088 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001089 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001090 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001091 }
1092
Joe Onorato9c1289c2009-08-17 11:03:03 -04001093 public boolean isWorkspaceLocked() {
1094 return mWorkspaceLoading || mWaitingForResult;
1095 }
1096
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001097 private void addItems() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001098 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 showAddDialog(mMenuAddInfo);
1100 }
1101
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001102 void addAppWidget(Intent data) {
1103 // TODO: catch bad widget exception when sent
1104 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001106 String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
1107 if (SEARCH_WIDGET.equals(customWidget)) {
1108 // We don't need this any more, since this isn't a real app widget.
1109 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1110 // add the search widget
1111 addSearch();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001112 } else {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001113 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1114
1115 if (appWidget.configure != null) {
1116 // Launch over to configure widget, if needed
1117 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1118 intent.setComponent(appWidget.configure);
1119 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1120
1121 startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
1122 } else {
1123 // Otherwise just add it
1124 onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
1125 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001126 }
1127 }
Romain Guycbb89e42009-06-08 15:52:54 -07001128
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001129 void addSearch() {
1130 final Widget info = Widget.makeSearch();
1131 final CellLayout.CellInfo cellInfo = mAddItemCellInfo;
Romain Guycbb89e42009-06-08 15:52:54 -07001132
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133 final int[] xy = mCellCoordinates;
1134 final int spanX = info.spanX;
1135 final int spanY = info.spanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001136
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001137 if (!findSlot(cellInfo, xy, spanX, spanY)) return;
Romain Guycbb89e42009-06-08 15:52:54 -07001138
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001139 LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1140 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
Romain Guycbb89e42009-06-08 15:52:54 -07001141
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001142 final View view = mInflater.inflate(info.layoutResource, null);
1143 view.setTag(info);
Karl Rosaen138a0412009-04-23 19:00:21 -07001144 Search search = (Search) view.findViewById(R.id.widget_search);
1145 search.setLauncher(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001146
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147 mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY);
1148 }
1149
Romain Guy73b979d2009-06-09 12:57:21 -07001150 void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001151 // Handle case where user selected "Applications"
1152 String applicationName = getResources().getString(R.string.group_applications);
1153 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001154
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001155 if (applicationName != null && applicationName.equals(shortcutName)) {
1156 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1157 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001158
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001159 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1160 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Romain Guy73b979d2009-06-09 12:57:21 -07001161 startActivityForResult(pickIntent, requestCodeApplication);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001162 } else {
Romain Guy73b979d2009-06-09 12:57:21 -07001163 startActivityForResult(intent, requestCodeShortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001164 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 }
1166
1167 void addLiveFolder(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001168 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001169 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001170 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001171
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001172 if (folderName != null && folderName.equals(shortcutName)) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001173 addFolder();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001174 } else {
1175 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1176 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 }
1178
Joe Onorato9c1289c2009-08-17 11:03:03 -04001179 void addFolder() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001180 UserFolderInfo folderInfo = new UserFolderInfo();
1181 folderInfo.title = getText(R.string.folder_name);
1182
1183 CellLayout.CellInfo cellInfo = mAddItemCellInfo;
1184 cellInfo.screen = mWorkspace.getCurrentScreen();
1185 if (!findSingleSlot(cellInfo)) return;
1186
1187 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001188 LauncherModel.addItemToDatabase(this, folderInfo,
1189 LauncherSettings.Favorites.CONTAINER_DESKTOP,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001190 mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001191 mFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001192
1193 // Create the view
1194 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1195 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
1196 mWorkspace.addInCurrentScreen(newFolder,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001197 cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001198 }
Romain Guycbb89e42009-06-08 15:52:54 -07001199
Joe Onorato9c1289c2009-08-17 11:03:03 -04001200 void removeFolder(FolderInfo folder) {
1201 mFolders.remove(folder.id);
1202 }
1203
1204 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001205 cellInfo.screen = mWorkspace.getCurrentScreen();
1206 if (!findSingleSlot(cellInfo)) return;
1207
1208 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
1209
1210 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
1212 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001213 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
1214 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001215 }
1216 }
1217
1218 static LiveFolderInfo addLiveFolder(Context context, Intent data,
1219 CellLayout.CellInfo cellInfo, boolean notify) {
1220
1221 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1222 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1223
1224 Drawable icon = null;
1225 boolean filtered = false;
1226 Intent.ShortcutIconResource iconResource = null;
1227
1228 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1229 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1230 try {
1231 iconResource = (Intent.ShortcutIconResource) extra;
1232 final PackageManager packageManager = context.getPackageManager();
1233 Resources resources = packageManager.getResourcesForApplication(
1234 iconResource.packageName);
1235 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1236 icon = resources.getDrawable(id);
1237 } catch (Exception e) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001238 w(LOG_TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 }
1240 }
1241
1242 if (icon == null) {
1243 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1244 }
1245
1246 final LiveFolderInfo info = new LiveFolderInfo();
1247 info.icon = icon;
1248 info.filtered = filtered;
1249 info.title = name;
1250 info.iconResource = iconResource;
1251 info.uri = data.getData();
1252 info.baseIntent = baseIntent;
1253 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1254 LiveFolders.DISPLAY_MODE_GRID);
1255
1256 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1257 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001258 mFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259
1260 return info;
1261 }
1262
1263 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
1264 final int[] xy = new int[2];
1265 if (findSlot(cellInfo, xy, 1, 1)) {
1266 cellInfo.cellX = xy[0];
1267 cellInfo.cellY = xy[1];
1268 return true;
1269 }
1270 return false;
1271 }
1272
1273 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
1274 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1275 boolean[] occupied = mSavedState != null ?
1276 mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null;
1277 cellInfo = mWorkspace.findAllVacantCells(occupied);
1278 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1279 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1280 return false;
1281 }
1282 }
1283 return true;
1284 }
1285
1286 private void showNotifications() {
1287 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1288 if (statusBar != null) {
1289 statusBar.expand();
1290 }
1291 }
1292
1293 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001294 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001295 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001296 Intent chooser = Intent.createChooser(pickWallpaper,
1297 getText(R.string.chooser_wallpaper));
1298 WallpaperManager wm = (WallpaperManager)
1299 getSystemService(Context.WALLPAPER_SERVICE);
1300 WallpaperInfo wi = wm.getWallpaperInfo();
1301 if (wi != null && wi.getSettingsActivity() != null) {
1302 LabeledIntent li = new LabeledIntent(getPackageName(),
1303 R.string.configure_wallpaper, 0);
1304 li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1305 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1306 }
Mike Clerona0618e42009-10-22 13:55:21 -07001307 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001308 }
1309
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001310 private void registerContentObservers() {
1311 ContentResolver resolver = getContentResolver();
1312 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1313 true, mWidgetObserver);
1314 }
1315
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001316 @Override
1317 public boolean dispatchKeyEvent(KeyEvent event) {
1318 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1319 switch (event.getKeyCode()) {
1320 case KeyEvent.KEYCODE_BACK:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 return true;
1322 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001323 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 Onoratofb0ca672009-09-14 17:55:46 -04001330 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001331 closeAllApps(true);
Dianne Hackborn67800862009-07-24 17:15:20 -07001332 } else {
1333 closeFolder();
1334 }
1335 }
Dianne Hackborn67800862009-07-24 17:15:20 -07001336 return true;
1337 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001338 return true;
1339 }
1340 }
1341
1342 return super.dispatchKeyEvent(event);
1343 }
1344
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 private void closeFolder() {
1346 Folder folder = mWorkspace.getOpenFolder();
1347 if (folder != null) {
1348 closeFolder(folder);
1349 }
1350 }
1351
1352 void closeFolder(Folder folder) {
1353 folder.getInfo().opened = false;
1354 ViewGroup parent = (ViewGroup) folder.getParent();
1355 if (parent != null) {
1356 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001357 if (folder instanceof DropTarget) {
1358 // Live folders aren't DropTargets.
1359 mDragController.removeDropTarget((DropTarget)folder);
1360 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 }
1362 folder.onClose();
1363 }
1364
1365 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001366 * Re-listen when widgets are reset.
1367 */
1368 private void onAppWidgetReset() {
1369 mAppWidgetHost.startListening();
1370 }
1371
1372 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001373 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1374 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001375 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001376 private void unbindDesktopItems() {
1377 for (ItemInfo item: mDesktopItems) {
1378 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001379 }
1380 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001381
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001382 /**
1383 * Launches the intent referred by the clicked shortcut.
1384 *
1385 * @param v The view representing the clicked shortcut.
1386 */
1387 public void onClick(View v) {
1388 Object tag = v.getTag();
1389 if (tag instanceof ApplicationInfo) {
1390 // Open shortcut
1391 final Intent intent = ((ApplicationInfo) tag).intent;
1392 startActivitySafely(intent);
Joe Onoratoff3862d2009-10-07 10:35:51 -07001393 mExitingBecauseOfLaunch = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394 } else if (tag instanceof FolderInfo) {
1395 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001396 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001397 Log.d(TAG, "onClick");
1398 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001399 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001400 } else {
Jason Samsfd22dac2009-09-20 17:24:16 -07001401 showAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -07001402 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403 }
1404 }
1405
1406 void startActivitySafely(Intent intent) {
1407 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1408 try {
1409 startActivity(intent);
1410 } catch (ActivityNotFoundException e) {
1411 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1412 } catch (SecurityException e) {
1413 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Romain Guy73b979d2009-06-09 12:57:21 -07001414 e(LOG_TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001415 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1416 "or use the exported attribute for this activity.", e);
1417 }
1418 }
1419
1420 private void handleFolderClick(FolderInfo folderInfo) {
1421 if (!folderInfo.opened) {
1422 // Close any open folder
1423 closeFolder();
1424 // Open the requested folder
1425 openFolder(folderInfo);
1426 } else {
1427 // Find the open folder...
1428 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1429 int folderScreen;
1430 if (openFolder != null) {
1431 folderScreen = mWorkspace.getScreenForView(openFolder);
1432 // .. and close it
1433 closeFolder(openFolder);
1434 if (folderScreen != mWorkspace.getCurrentScreen()) {
1435 // Close any folder open on the current screen
1436 closeFolder();
1437 // Pull the folder onto this screen
1438 openFolder(folderInfo);
1439 }
1440 }
1441 }
1442 }
1443
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444 /**
1445 * Opens the user fodler described by the specified tag. The opening of the folder
1446 * is animated relative to the specified View. If the View is null, no animation
1447 * is played.
1448 *
1449 * @param folderInfo The FolderInfo describing the folder to open.
1450 */
1451 private void openFolder(FolderInfo folderInfo) {
1452 Folder openFolder;
1453
1454 if (folderInfo instanceof UserFolderInfo) {
1455 openFolder = UserFolder.fromXml(this);
1456 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001457 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458 } else {
1459 return;
1460 }
1461
Joe Onorato00acb122009-08-04 16:04:30 -04001462 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001463 openFolder.setLauncher(this);
1464
1465 openFolder.bind(folderInfo);
1466 folderInfo.opened = true;
1467
1468 mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4);
1469 openFolder.onOpen();
1470 }
1471
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001472 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001473 switch (v.getId()) {
1474 case R.id.previous_screen:
1475 showPreviousPreview(v);
1476 return true;
1477 case R.id.next_screen:
1478 showNextPreview(v);
1479 return true;
1480 }
1481
Joe Onorato9c1289c2009-08-17 11:03:03 -04001482 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 return false;
1484 }
1485
1486 if (!(v instanceof CellLayout)) {
1487 v = (View) v.getParent();
1488 }
1489
1490 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
1491
1492 // This happens when long clicking an item with the dpad/trackball
1493 if (cellInfo == null) {
1494 return true;
1495 }
1496
1497 if (mWorkspace.allowLongPress()) {
1498 if (cellInfo.cell == null) {
1499 if (cellInfo.valid) {
1500 // User long pressed on empty space
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001501 mWorkspace.setAllowLongPress(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001502 showAddDialog(cellInfo);
1503 }
1504 } else {
1505 if (!(cellInfo.cell instanceof Folder)) {
1506 // User long pressed on an item
1507 mWorkspace.startDrag(cellInfo);
1508 }
1509 }
1510 }
1511 return true;
1512 }
1513
Romain Guy1fbc1c82009-11-09 20:43:08 -08001514 public boolean onKey(View v, int keyCode, KeyEvent event) {
1515 if (event.getAction() == KeyEvent.ACTION_UP) {
1516 dismissPreview(v);
1517 }
1518 return false;
1519 }
1520
1521 public boolean onTouch(View v, MotionEvent event) {
1522 if (event.getAction() == MotionEvent.ACTION_UP) {
1523 dismissPreview(v);
1524 }
1525 return false;
1526 }
1527
1528 private void dismissPreview(View v) {
1529 PopupWindow window = (PopupWindow) v.getTag();
1530 if (window != null) {
1531 window.dismiss();
1532 ((ImageView) v.getTag(R.id.workspace)).setImageBitmap(null);
1533 ((Bitmap) v.getTag(R.id.icon)).recycle();
1534
1535 v.setTag(R.id.workspace, null);
1536 v.setTag(R.id.icon, null);
1537 }
1538 v.setTag(null);
1539 }
1540
1541 private void showPreviousPreview(View anchor) {
1542 int current = mWorkspace.getCurrentScreen();
1543 if (current <= 0) return;
1544
1545 View previous = mWorkspace.getChildAt(current - 1);
1546 showPreview(anchor, previous);
1547 }
1548
1549 private void showNextPreview(View anchor) {
1550 int current = mWorkspace.getCurrentScreen();
1551 if (current >= mWorkspace.getChildCount() - 1) return;
1552
1553 View next = mWorkspace.getChildAt(current + 1);
1554 showPreview(anchor, next);
1555 }
1556
1557 private void showPreview(View anchor, View source) {
1558 boolean cacheEnabled = source.isDrawingCacheEnabled();
1559 source.setDrawingCacheEnabled(true);
1560 source.buildDrawingCache();
1561
1562 Bitmap cache = source.getDrawingCache();
1563 if (cache == null) return;
1564
1565 Bitmap bitmap = Bitmap.createScaledBitmap(cache,
1566 (int) (cache.getWidth() / 2.5f), (int) (cache.getHeight() / 2.5f), true);
1567
1568 ImageView preview = new ImageView(this);
1569 preview.setImageBitmap(bitmap);
1570 Drawable d = getResources().getDrawable(R.drawable.preview_popup);
1571 preview.setBackgroundDrawable(d);
1572
1573 Rect r = new Rect();
1574 d.getPadding(r);
1575 int extraW = r.left + r.right;
1576 int extraH = r.top + r.bottom;
1577
1578 PopupWindow p = new PopupWindow(preview, bitmap.getWidth() + extraW,
1579 bitmap.getHeight() + extraH);
1580 p.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,
1581 ViewGroup.LayoutParams.WRAP_CONTENT);
1582 p.setAnimationStyle(R.style.AnimationPreview);
1583 p.showAsDropDown(anchor, 0, 0);
1584
1585 source.destroyDrawingCache();
1586 if (!cacheEnabled) source.setDrawingCacheEnabled(cacheEnabled);
1587
1588 anchor.setTag(p);
1589 anchor.setTag(R.id.workspace, preview);
1590 anchor.setTag(R.id.icon, bitmap);
1591 }
1592
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001593 View getDrawerHandle() {
1594 return mHandleView;
1595 }
1596
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597 Workspace getWorkspace() {
1598 return mWorkspace;
1599 }
1600
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 @Override
1602 protected Dialog onCreateDialog(int id) {
1603 switch (id) {
1604 case DIALOG_CREATE_SHORTCUT:
1605 return new CreateShortcut().createDialog();
1606 case DIALOG_RENAME_FOLDER:
1607 return new RenameFolder().createDialog();
1608 }
1609
1610 return super.onCreateDialog(id);
1611 }
1612
1613 @Override
1614 protected void onPrepareDialog(int id, Dialog dialog) {
1615 switch (id) {
1616 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001617 break;
1618 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001619 if (mFolderInfo != null) {
1620 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1621 final CharSequence text = mFolderInfo.title;
1622 input.setText(text);
1623 input.setSelection(0, text.length());
1624 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001625 break;
1626 }
1627 }
1628
1629 void showRenameDialog(FolderInfo info) {
1630 mFolderInfo = info;
1631 mWaitingForResult = true;
1632 showDialog(DIALOG_RENAME_FOLDER);
1633 }
1634
1635 private void showAddDialog(CellLayout.CellInfo cellInfo) {
1636 mAddItemCellInfo = cellInfo;
1637 mWaitingForResult = true;
1638 showDialog(DIALOG_CREATE_SHORTCUT);
1639 }
1640
Romain Guy73b979d2009-06-09 12:57:21 -07001641 private void pickShortcut(int requestCode, int title) {
1642 Bundle bundle = new Bundle();
1643
1644 ArrayList<String> shortcutNames = new ArrayList<String>();
1645 shortcutNames.add(getString(R.string.group_applications));
1646 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
1647
1648 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
1649 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1650 R.drawable.ic_launcher_application));
1651 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1652
1653 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1654 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
1655 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title));
1656 pickIntent.putExtras(bundle);
1657
1658 startActivityForResult(pickIntent, requestCode);
1659 }
1660
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001661 private class RenameFolder {
1662 private EditText mInput;
1663
1664 Dialog createDialog() {
1665 mWaitingForResult = true;
1666 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1667 mInput = (EditText) layout.findViewById(R.id.folder_name);
1668
1669 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1670 builder.setIcon(0);
1671 builder.setTitle(getString(R.string.rename_folder_title));
1672 builder.setCancelable(true);
1673 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1674 public void onCancel(DialogInterface dialog) {
1675 cleanup();
1676 }
1677 });
1678 builder.setNegativeButton(getString(R.string.cancel_action),
1679 new Dialog.OnClickListener() {
1680 public void onClick(DialogInterface dialog, int which) {
1681 cleanup();
1682 }
1683 }
1684 );
1685 builder.setPositiveButton(getString(R.string.rename_action),
1686 new Dialog.OnClickListener() {
1687 public void onClick(DialogInterface dialog, int which) {
1688 changeFolderName();
1689 }
1690 }
1691 );
1692 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001693
1694 final AlertDialog dialog = builder.create();
1695 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1696 public void onShow(DialogInterface dialog) {
Joe Onoratod753b422009-11-08 13:31:11 -05001697 mInput.requestFocus();
1698 InputMethodManager inputManager = (InputMethodManager)
1699 getSystemService(Context.INPUT_METHOD_SERVICE);
1700 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001701 }
1702 });
1703
1704 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001705 }
1706
1707 private void changeFolderName() {
1708 final String name = mInput.getText().toString();
1709 if (!TextUtils.isEmpty(name)) {
1710 // Make sure we have the right folder info
Joe Onorato9c1289c2009-08-17 11:03:03 -04001711 mFolderInfo = mFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712 mFolderInfo.title = name;
1713 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1714
Joe Onorato9c1289c2009-08-17 11:03:03 -04001715 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001716 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001717 mModel.setWorkspaceDirty();
1718 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001719 } else {
1720 final FolderIcon folderIcon = (FolderIcon)
1721 mWorkspace.getViewForTag(mFolderInfo);
1722 if (folderIcon != null) {
1723 folderIcon.setText(name);
1724 getWorkspace().requestLayout();
1725 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001726 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001727 mModel.setWorkspaceDirty();
1728 mWorkspaceLoading = true;
1729 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001730 }
1731 }
1732 }
1733 cleanup();
1734 }
1735
1736 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737 dismissDialog(DIALOG_RENAME_FOLDER);
1738 mWaitingForResult = false;
1739 mFolderInfo = null;
1740 }
1741 }
1742
Joe Onoratofb0ca672009-09-14 17:55:46 -04001743 boolean isAllAppsVisible() {
Joe Onorato7bb17492009-09-24 17:51:01 -07001744 return mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04001745 }
1746
Jason Samsfd22dac2009-09-20 17:24:16 -07001747 void showAllApps() {
Jason Sams12c14a82009-10-06 14:33:15 -07001748 mAllAppsGrid.zoom(1.0f);
Joe Onorato7bb17492009-09-24 17:51:01 -07001749 //mWorkspace.hide();
Jason Samsfd22dac2009-09-20 17:24:16 -07001750
Mike Cleronb6082fa2009-10-19 17:03:36 -07001751 mAllAppsGrid.setFocusable(true);
Mike Clerona0618e42009-10-22 13:55:21 -07001752 mAllAppsGrid.requestFocus();
Mike Cleronb6082fa2009-10-19 17:03:36 -07001753
Joe Onorato7c312c12009-08-13 21:36:53 -07001754 // TODO: fade these two too
1755 mDeleteZone.setVisibility(View.GONE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04001756 //mHandleView.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04001757 }
1758
Joe Onorato7bb17492009-09-24 17:51:01 -07001759 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001760 if (mAllAppsGrid.isVisible()) {
Jason Sams12c14a82009-10-06 14:33:15 -07001761 mAllAppsGrid.zoom(0.0f);
Mike Cleronb6082fa2009-10-19 17:03:36 -07001762 mAllAppsGrid.setFocusable(false);
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001763 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
Joe Onorato7c312c12009-08-13 21:36:53 -07001764
Mike Cleronb6082fa2009-10-19 17:03:36 -07001765
Joe Onorato7c312c12009-08-13 21:36:53 -07001766 // TODO: fade these two too
Joe Onoratofb0ca672009-09-14 17:55:46 -04001767 /*
Joe Onorato7c312c12009-08-13 21:36:53 -07001768 mDeleteZone.setVisibility(View.VISIBLE);
1769 mHandleView.setVisibility(View.VISIBLE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04001770 */
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001771 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001772 }
1773
Joe Onorato7c312c12009-08-13 21:36:53 -07001774 void lockAllApps() {
1775 // TODO
1776 }
1777
1778 void unlockAllApps() {
1779 // TODO
1780 }
1781
Joe Onorato7404ee42009-07-31 11:54:44 -07001782 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001783 * Displays the shortcut creation dialog and launches, if necessary, the
1784 * appropriate activity.
1785 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001786 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07001787 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
1788 DialogInterface.OnShowListener {
1789
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001790 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07001791
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001792 Dialog createDialog() {
1793 mWaitingForResult = true;
Romain Guycbb89e42009-06-08 15:52:54 -07001794
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07001796
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001797 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1798 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001799 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07001800
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001801 builder.setInverseBackgroundForced(true);
1802
1803 AlertDialog dialog = builder.create();
1804 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001805 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07001806 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001808 return dialog;
1809 }
1810
1811 public void onCancel(DialogInterface dialog) {
1812 mWaitingForResult = false;
1813 cleanup();
1814 }
1815
Romain Guycbb89e42009-06-08 15:52:54 -07001816 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07001817 }
1818
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001819 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 dismissDialog(DIALOG_CREATE_SHORTCUT);
1821 }
1822
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001823 /**
1824 * Handle the action clicked in the "Add to home" dialog.
1825 */
1826 public void onClick(DialogInterface dialog, int which) {
1827 Resources res = getResources();
1828 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07001829
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001830 switch (which) {
1831 case AddAdapter.ITEM_SHORTCUT: {
1832 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07001833 pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001834 break;
1835 }
Romain Guycbb89e42009-06-08 15:52:54 -07001836
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001837 case AddAdapter.ITEM_APPWIDGET: {
1838 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07001839
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001840 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
1841 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1842 // add the search widget
1843 ArrayList<AppWidgetProviderInfo> customInfo =
1844 new ArrayList<AppWidgetProviderInfo>();
1845 AppWidgetProviderInfo info = new AppWidgetProviderInfo();
1846 info.provider = new ComponentName(getPackageName(), "XXX.YYY");
1847 info.label = getString(R.string.group_search);
1848 info.icon = R.drawable.ic_search_widget;
1849 customInfo.add(info);
1850 pickIntent.putParcelableArrayListExtra(
1851 AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
1852 ArrayList<Bundle> customExtras = new ArrayList<Bundle>();
1853 Bundle b = new Bundle();
1854 b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET);
1855 customExtras.add(b);
1856 pickIntent.putParcelableArrayListExtra(
1857 AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
1858 // start the pick activity
1859 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
1860 break;
1861 }
Romain Guycbb89e42009-06-08 15:52:54 -07001862
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001863 case AddAdapter.ITEM_LIVE_FOLDER: {
1864 // Insert extra item to handle inserting folder
1865 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07001866
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001867 ArrayList<String> shortcutNames = new ArrayList<String>();
1868 shortcutNames.add(res.getString(R.string.group_folder));
1869 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07001870
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001871 ArrayList<ShortcutIconResource> shortcutIcons =
1872 new ArrayList<ShortcutIconResource>();
1873 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1874 R.drawable.ic_launcher_folder));
1875 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1876
1877 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1878 pickIntent.putExtra(Intent.EXTRA_INTENT,
1879 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
1880 pickIntent.putExtra(Intent.EXTRA_TITLE,
1881 getText(R.string.title_select_live_folder));
1882 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07001883
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001884 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
1885 break;
1886 }
1887
1888 case AddAdapter.ITEM_WALLPAPER: {
1889 startWallpaper();
1890 break;
1891 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892 }
1893 }
Romain Guy7b4ef332009-07-14 13:58:08 -07001894
1895 public void onShow(DialogInterface dialog) {
Romain Guy7b4ef332009-07-14 13:58:08 -07001896 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897 }
1898
1899 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001900 * Receives notifications whenever the appwidgets are reset.
1901 */
1902 private class AppWidgetResetObserver extends ContentObserver {
1903 public AppWidgetResetObserver() {
1904 super(new Handler());
1905 }
1906
1907 @Override
1908 public void onChange(boolean selfChange) {
1909 onAppWidgetReset();
1910 }
1911 }
1912
1913 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001914 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001916 public int getCurrentWorkspaceScreen() {
1917 return mWorkspace.getCurrentScreen();
1918 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001919
Joe Onorato9c1289c2009-08-17 11:03:03 -04001920 /**
1921 * Refreshes the shortcuts shown on the workspace.
1922 *
1923 * Implementation of the method from LauncherModel.Callbacks.
1924 */
1925 public void startBinding() {
1926 final Workspace workspace = mWorkspace;
1927 int count = workspace.getChildCount();
1928 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04001929 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04001930 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
1931 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001932
Joe Onorato9c1289c2009-08-17 11:03:03 -04001933 if (DEBUG_USER_INTERFACE) {
1934 android.widget.Button finishButton = new android.widget.Button(this);
1935 finishButton.setText("Finish");
1936 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
1937
1938 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
1939 public void onClick(View v) {
1940 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001941 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001942 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 }
1944 }
1945
1946 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001947 * Bind the items start-end from the list.
1948 *
1949 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001951 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
1952
1953 final Workspace workspace = mWorkspace;
1954
1955 for (int i=start; i<end; i++) {
1956 final ItemInfo item = shortcuts.get(i);
1957 mDesktopItems.add(item);
1958 switch (item.itemType) {
1959 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1960 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1961 final View shortcut = createShortcut((ApplicationInfo) item);
1962 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
1963 false);
1964 break;
1965 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
1966 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1967 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1968 (UserFolderInfo) item);
1969 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
1970 false);
1971 break;
1972 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
1973 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
1974 R.layout.live_folder_icon, this,
1975 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1976 (LiveFolderInfo) item);
1977 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
1978 false);
1979 break;
1980 case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH:
1981 final int screen = workspace.getCurrentScreen();
1982 final View view = mInflater.inflate(R.layout.widget_search,
1983 (ViewGroup) workspace.getChildAt(screen), false);
1984
1985 Search search = (Search) view.findViewById(R.id.widget_search);
1986 search.setLauncher(this);
1987
1988 final Widget widget = (Widget) item;
1989 view.setTag(widget);
1990
1991 workspace.addWidget(view, widget, false);
1992 break;
1993 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 }
1995
Joe Onorato9c1289c2009-08-17 11:03:03 -04001996 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 }
1998
Joe Onorato9c1289c2009-08-17 11:03:03 -04001999 /**
2000 * Implementation of the method from LauncherModel.Callbacks.
2001 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002002 public void bindFolders(HashMap<Long, FolderInfo> folders) {
2003 mFolders.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002004 mFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002005 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002006
2007 /**
2008 * Add the views for a widget to the workspace.
2009 *
2010 * Implementation of the method from LauncherModel.Callbacks.
2011 */
2012 public void bindAppWidget(LauncherAppWidgetInfo item) {
2013 final Workspace workspace = mWorkspace;
2014
2015 final int appWidgetId = item.appWidgetId;
2016 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
2017 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2018
Joe Onorato9c1289c2009-08-17 11:03:03 -04002019 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2020 item.hostView.setTag(item);
2021
2022 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2023 item.cellY, item.spanX, item.spanY, false);
2024
2025 workspace.requestLayout();
2026
2027 mDesktopItems.add(item);
2028 }
2029
2030 /**
2031 * Callback saying that there aren't any more items to bind.
2032 *
2033 * Implementation of the method from LauncherModel.Callbacks.
2034 */
2035 public void finishBindingItems() {
2036 if (mSavedState != null) {
2037 if (!mWorkspace.hasFocus()) {
2038 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
2039 }
2040
2041 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2042 if (userFolders != null) {
2043 for (long folderId : userFolders) {
2044 final FolderInfo info = mFolders.get(folderId);
2045 if (info != null) {
2046 openFolder(info);
2047 }
2048 }
2049 final Folder openFolder = mWorkspace.getOpenFolder();
2050 if (openFolder != null) {
2051 openFolder.requestFocus();
2052 }
2053 }
2054
2055 final boolean allApps = mSavedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
2056 if (allApps) {
Jason Samsfd22dac2009-09-20 17:24:16 -07002057 showAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002058 }
2059
2060 mSavedState = null;
2061 }
2062
2063 if (mSavedInstanceState != null) {
2064 super.onRestoreInstanceState(mSavedInstanceState);
2065 mSavedInstanceState = null;
2066 }
2067
Joe Onorato9c1289c2009-08-17 11:03:03 -04002068 Log.d(TAG, "finishBindingItems done");
2069 mWorkspaceLoading = false;
2070 }
2071
2072 /**
2073 * Add the icons for all apps.
2074 *
2075 * Implementation of the method from LauncherModel.Callbacks.
2076 */
2077 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08002078 mAllAppsGrid.setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002079 }
2080
2081 /**
2082 * A package was installed.
2083 *
2084 * Implementation of the method from LauncherModel.Callbacks.
2085 */
2086 public void bindPackageAdded(ArrayList<ApplicationInfo> apps) {
2087 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002088 mAllAppsGrid.addApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002089 }
2090
2091 /**
2092 * A package was updated.
2093 *
2094 * Implementation of the method from LauncherModel.Callbacks.
2095 */
2096 public void bindPackageUpdated(String packageName, ArrayList<ApplicationInfo> apps) {
2097 removeDialog(DIALOG_CREATE_SHORTCUT);
2098 mWorkspace.updateShortcutsForPackage(packageName);
2099 }
2100
2101 /**
2102 * A package was uninstalled.
2103 *
2104 * Implementation of the method from LauncherModel.Callbacks.
2105 */
2106 public void bindPackageRemoved(String packageName, ArrayList<ApplicationInfo> apps) {
2107 removeDialog(DIALOG_CREATE_SHORTCUT);
2108 mWorkspace.removeShortcutsForPackage(packageName);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002109 mAllAppsGrid.removeApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002110 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002111}