blob: a2a3e9a9d23279d45b72b7fa9f16147ebde152c2 [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;
Romain Guy1a304a12009-11-10 00:02:32 -080043import android.graphics.Matrix;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080044import android.graphics.drawable.Drawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080046import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.os.Parcelable;
48import android.os.RemoteException;
49import android.os.ServiceManager;
Joe Onorato080d9b62009-11-02 12:01:11 -050050import android.os.SystemClock;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.provider.LiveFolders;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052import android.text.Selection;
53import android.text.SpannableStringBuilder;
54import android.text.TextUtils;
55import android.text.method.TextKeyListener;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070056import static android.util.Log.*;
Joe Onorato7c312c12009-08-13 21:36:53 -070057import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058import android.view.Display;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.view.KeyEvent;
60import android.view.LayoutInflater;
61import android.view.Menu;
62import android.view.MenuItem;
63import android.view.View;
64import android.view.ViewGroup;
Romain Guy1fbc1c82009-11-09 20:43:08 -080065import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066import android.view.View.OnLongClickListener;
67import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.widget.EditText;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.widget.TextView;
70import android.widget.Toast;
Romain Guy8a73c512009-11-09 19:19:59 -080071import android.widget.ImageView;
Romain Guy1fbc1c82009-11-09 20:43:08 -080072import android.widget.PopupWindow;
The Android Open Source Project7376fae2009-03-11 12:11:58 -070073import android.appwidget.AppWidgetManager;
74import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import java.util.ArrayList;
Joe Onorato9c1289c2009-08-17 11:03:03 -040077import java.util.HashMap;
Romain Guy98d01652009-06-30 16:21:04 -070078import java.io.DataOutputStream;
79import java.io.FileNotFoundException;
80import java.io.IOException;
81import java.io.DataInputStream;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082
83/**
84 * Default launcher application.
85 */
Joe Onorato9c1289c2009-08-17 11:03:03 -040086public final class Launcher extends Activity
Romain Guy1fbc1c82009-11-09 20:43:08 -080087 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, View.OnTouchListener, View.OnKeyListener {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088 static final String LOG_TAG = "Launcher";
Joe Onorato9c1289c2009-08-17 11:03:03 -040089 static final String TAG = LOG_TAG;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090 static final boolean LOGD = false;
91
Joe Onorato9c1289c2009-08-17 11:03:03 -040092 static final boolean PROFILE_STARTUP = false;
93 static final boolean PROFILE_ROTATE = false;
94 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -070095
The Android Open Source Project31dd5032009-03-03 19:32:27 -080096 private static final int WALLPAPER_SCREENS_SPAN = 2;
97
98 private static final int MENU_GROUP_ADD = 1;
99 private static final int MENU_ADD = Menu.FIRST + 1;
100 private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
101 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
102 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700103 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800104
105 private static final int REQUEST_CREATE_SHORTCUT = 1;
106 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700107 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108 private static final int REQUEST_PICK_APPLICATION = 6;
109 private static final int REQUEST_PICK_SHORTCUT = 7;
110 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700111 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700112 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800113
114 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
115
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700116 static final String EXTRA_CUSTOM_WIDGET = "custom_widget";
117 static final String SEARCH_WIDGET = "search_widget";
118
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800119 static final int SCREEN_COUNT = 5;
120 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 static final int NUMBER_CELLS_X = 4;
Romain Guycbb89e42009-06-08 15:52:54 -0700122 static final int NUMBER_CELLS_Y = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123
Joe Onorato7c312c12009-08-13 21:36:53 -0700124 static final int DIALOG_CREATE_SHORTCUT = 1;
125 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800126
Romain Guy98d01652009-06-30 16:21:04 -0700127 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
129 // Type: int
130 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
131 // Type: boolean
132 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
133 // Type: long
134 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
135 // Type: int
136 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
137 // Type: int
138 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
139 // Type: int
140 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
141 // Type: int
142 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX";
143 // Type: int
144 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY";
145 // Type: int
146 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX";
147 // Type: int
148 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY";
149 // Type: int[]
150 private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells";
151 // Type: boolean
152 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
153 // Type: long
154 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
155
Joe Onorato9c1289c2009-08-17 11:03:03 -0400156 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800159 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800161 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 private LayoutInflater mInflater;
164
Joe Onorato00acb122009-08-04 16:04:30 -0400165 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700167
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700168 private AppWidgetManager mAppWidgetManager;
169 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700170
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 private CellLayout.CellInfo mAddItemCellInfo;
172 private CellLayout.CellInfo mMenuAddInfo;
173 private final int[] mCellCoordinates = new int[2];
174 private FolderInfo mFolderInfo;
175
Joe Onorato7c312c12009-08-13 21:36:53 -0700176 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700177 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700178 private AllAppsView mAllAppsGrid;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180 private Bundle mSavedState;
181
182 private SpannableStringBuilder mDefaultKeySsb = null;
183
Mike LeBeau736cf282009-07-02 17:46:59 -0700184 private boolean mIsNewIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185
Joe Onorato9c1289c2009-08-17 11:03:03 -0400186 private boolean mWorkspaceLoading = true;
187
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 private boolean mRestoring;
189 private boolean mWaitingForResult;
Joe Onoratoff3862d2009-10-07 10:35:51 -0700190 private boolean mExitingBecauseOfLaunch;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
192 private Bundle mSavedInstanceState;
193
Joe Onorato9c1289c2009-08-17 11:03:03 -0400194 private LauncherModel mModel;
195
Romain Guy84f296c2009-11-04 15:00:44 -0800196 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
197 private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700198
Joe Onorato080d9b62009-11-02 12:01:11 -0500199 public static long lastStartTime;
Romain Guy1fbc1c82009-11-09 20:43:08 -0800200 private ImageView mPreviousView;
201 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500202
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800203 @Override
204 protected void onCreate(Bundle savedInstanceState) {
Joe Onorato080d9b62009-11-02 12:01:11 -0500205 lastStartTime = SystemClock.uptimeMillis();
206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700208
Joe Onorato9c1289c2009-08-17 11:03:03 -0400209 mModel = ((LauncherApplication)getApplication()).setLauncher(this);
Joe Onorato41a12d22009-10-31 18:30:00 -0400210 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700212
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700213 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700214 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
215 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700216
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217 if (PROFILE_STARTUP) {
218 android.os.Debug.startMethodTracing("/sdcard/launcher");
219 }
220
221 checkForLocaleChange();
222 setWallpaperDimension();
223
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224 setContentView(R.layout.launcher);
225 setupViews();
226
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800227 registerContentObservers();
228
Joe Onorato7c312c12009-08-13 21:36:53 -0700229 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700230
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800231 mSavedState = savedInstanceState;
232 restoreState(mSavedState);
233
234 if (PROFILE_STARTUP) {
235 android.os.Debug.stopMethodTracing();
236 }
237
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700238 // We have a new AllAppsView, we need to re-bind everything, and it could have
239 // changed in our absence.
240 mModel.setAllAppsDirty();
241 mModel.setWorkspaceDirty();
242
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800243 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400244 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800245 }
246
247 // For handling default keys
248 mDefaultKeySsb = new SpannableStringBuilder();
249 Selection.setSelection(mDefaultKeySsb, 0);
250 }
Romain Guycbb89e42009-06-08 15:52:54 -0700251
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252 private void checkForLocaleChange() {
Romain Guy98d01652009-06-30 16:21:04 -0700253 final LocaleConfiguration localeConfiguration = new LocaleConfiguration();
254 readConfiguration(this, localeConfiguration);
Jason Samsfd22dac2009-09-20 17:24:16 -0700255
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256 final Configuration configuration = getResources().getConfiguration();
257
Romain Guy98d01652009-06-30 16:21:04 -0700258 final String previousLocale = localeConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259 final String locale = configuration.locale.toString();
260
Romain Guy98d01652009-06-30 16:21:04 -0700261 final int previousMcc = localeConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262 final int mcc = configuration.mcc;
263
Romain Guy98d01652009-06-30 16:21:04 -0700264 final int previousMnc = localeConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265 final int mnc = configuration.mnc;
266
Romain Guy84f296c2009-11-04 15:00:44 -0800267 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268
Romain Guy84f296c2009-11-04 15:00:44 -0800269 if (localeChanged) {
Romain Guy98d01652009-06-30 16:21:04 -0700270 localeConfiguration.locale = locale;
271 localeConfiguration.mcc = mcc;
272 localeConfiguration.mnc = mnc;
273
274 writeConfiguration(this, localeConfiguration);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400275 AppInfoCache.flush();
Romain Guy98d01652009-06-30 16:21:04 -0700276 }
277 }
278
279 private static class LocaleConfiguration {
280 public String locale;
281 public int mcc = -1;
282 public int mnc = -1;
283 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700284
Romain Guy98d01652009-06-30 16:21:04 -0700285 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
286 DataInputStream in = null;
287 try {
288 in = new DataInputStream(context.openFileInput(PREFERENCES));
289 configuration.locale = in.readUTF();
290 configuration.mcc = in.readInt();
291 configuration.mnc = in.readInt();
292 } catch (FileNotFoundException e) {
293 // Ignore
294 } catch (IOException e) {
295 // Ignore
296 } finally {
297 if (in != null) {
298 try {
299 in.close();
300 } catch (IOException e) {
301 // Ignore
302 }
303 }
304 }
305 }
306
307 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
308 DataOutputStream out = null;
309 try {
310 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
311 out.writeUTF(configuration.locale);
312 out.writeInt(configuration.mcc);
313 out.writeInt(configuration.mnc);
314 out.flush();
315 } catch (FileNotFoundException e) {
316 // Ignore
317 } catch (IOException e) {
318 //noinspection ResultOfMethodCallIgnored
319 context.getFileStreamPath(PREFERENCES).delete();
320 } finally {
321 if (out != null) {
322 try {
323 out.close();
324 } catch (IOException e) {
325 // Ignore
326 }
327 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800328 }
329 }
330
331 static int getScreen() {
332 synchronized (sLock) {
333 return sScreen;
334 }
335 }
336
337 static void setScreen(int screen) {
338 synchronized (sLock) {
339 sScreen = screen;
340 }
341 }
342
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700344 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800345
346 Display display = getWindowManager().getDefaultDisplay();
347 boolean isPortrait = display.getWidth() < display.getHeight();
348
349 final int width = isPortrait ? display.getWidth() : display.getHeight();
350 final int height = isPortrait ? display.getHeight() : display.getWidth();
Dianne Hackborn64271802009-08-08 20:54:24 -0700351 wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800352 }
353
354 @Override
355 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700356 mWaitingForResult = false;
357
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800358 // The pattern used here is that a user PICKs a specific application,
359 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700360
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
362 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700363
Romain Guy94dabf12009-07-21 10:55:43 -0700364 if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800365 switch (requestCode) {
366 case REQUEST_PICK_APPLICATION:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400367 completeAddApplication(this, data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800368 break;
369 case REQUEST_PICK_SHORTCUT:
Romain Guy73b979d2009-06-09 12:57:21 -0700370 processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800371 break;
372 case REQUEST_CREATE_SHORTCUT:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400373 completeAddShortcut(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800374 break;
375 case REQUEST_PICK_LIVE_FOLDER:
376 addLiveFolder(data);
377 break;
378 case REQUEST_CREATE_LIVE_FOLDER:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400379 completeAddLiveFolder(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700381 case REQUEST_PICK_APPWIDGET:
382 addAppWidget(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800383 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700384 case REQUEST_CREATE_APPWIDGET:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400385 completeAddAppWidget(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800386 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700387 case REQUEST_PICK_WALLPAPER:
388 // We just wanted the activity result here so we can clear mWaitingForResult
389 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 }
Romain Guy18042c82009-11-06 11:44:55 -0800391 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
392 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
393 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700394 // Clean up the appWidgetId if we canceled
395 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
396 if (appWidgetId != -1) {
397 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800398 }
399 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 }
401
402 @Override
403 protected void onResume() {
Joe Onorato080d9b62009-11-02 12:01:11 -0500404 if (lastStartTime == 0) {
405 lastStartTime = SystemClock.uptimeMillis();
406 }
407
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 super.onResume();
409
410 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400411 mWorkspaceLoading = true;
412 mModel.startLoader(this, true);
413 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800414 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700415
Mike LeBeau736cf282009-07-02 17:46:59 -0700416 // If this was a new intent (i.e., the mIsNewIntent flag got set to true by
417 // onNewIntent), then close the search dialog if needed, because it probably
418 // came from the user pressing 'home' (rather than, for example, pressing 'back').
419 if (mIsNewIntent) {
420 // Post to a handler so that this happens after the search dialog tries to open
421 // itself again.
422 mWorkspace.post(new Runnable() {
423 public void run() {
424 ISearchManager searchManagerService = ISearchManager.Stub.asInterface(
425 ServiceManager.getService(Context.SEARCH_SERVICE));
426 try {
427 searchManagerService.stopSearch();
428 } catch (RemoteException e) {
429 e(LOG_TAG, "error stopping search", e);
Jason Samsfd22dac2009-09-20 17:24:16 -0700430 }
Mike LeBeau736cf282009-07-02 17:46:59 -0700431 }
432 });
433 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700434
Mike LeBeau736cf282009-07-02 17:46:59 -0700435 mIsNewIntent = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 }
437
438 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700439 protected void onPause() {
440 super.onPause();
Joe Onoratoff3862d2009-10-07 10:35:51 -0700441 if (mExitingBecauseOfLaunch) {
442 mExitingBecauseOfLaunch = false;
443 closeAllApps(false);
444 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800445 dismissPreview(mPreviousView);
446 dismissPreview(mNextView);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700447 }
Romain Guycbb89e42009-06-08 15:52:54 -0700448
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700449 @Override
450 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400451 // Flag the loader to stop early before switching
452 mModel.stopLoader();
Romain Guycbb89e42009-06-08 15:52:54 -0700453
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700454 if (PROFILE_ROTATE) {
455 android.os.Debug.startMethodTracing("/sdcard/launcher-rotate");
456 }
457 return null;
458 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700459
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 private boolean acceptFilter() {
461 final InputMethodManager inputManager = (InputMethodManager)
462 getSystemService(Context.INPUT_METHOD_SERVICE);
463 return !inputManager.isFullscreenMode();
464 }
465
466 @Override
467 public boolean onKeyDown(int keyCode, KeyEvent event) {
468 boolean handled = super.onKeyDown(keyCode, event);
469 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
470 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
471 keyCode, event);
472 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700473 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700474 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700475 // showSearchDialog()
476 // If there are multiple keystrokes before the search dialog takes focus,
477 // onSearchRequested() will be called for every keystroke,
478 // but it is idempotent, so it's fine.
479 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800480 }
481 }
482
483 return handled;
484 }
485
Karl Rosaen138a0412009-04-23 19:00:21 -0700486 private String getTypedText() {
487 return mDefaultKeySsb.toString();
488 }
489
490 private void clearTypedText() {
491 mDefaultKeySsb.clear();
492 mDefaultKeySsb.clearSpans();
493 Selection.setSelection(mDefaultKeySsb, 0);
494 }
495
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800496 /**
497 * Restores the previous state, if it exists.
498 *
499 * @param savedState The previous state.
500 */
501 private void restoreState(Bundle savedState) {
502 if (savedState == null) {
503 return;
504 }
505
506 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
507 if (currentScreen > -1) {
508 mWorkspace.setCurrentScreen(currentScreen);
509 }
510
511 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
512 if (addScreen > -1) {
513 mAddItemCellInfo = new CellLayout.CellInfo();
514 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
515 addItemCellInfo.valid = true;
516 addItemCellInfo.screen = addScreen;
517 addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
518 addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
519 addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
520 addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
521 addItemCellInfo.findVacantCellsFromOccupied(
522 savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS),
523 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X),
524 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y));
525 mRestoring = true;
526 }
527
528 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
529 if (renameFolder) {
530 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400531 mFolderInfo = mModel.getFolderById(this, mFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800532 mRestoring = true;
533 }
534 }
535
536 /**
537 * Finds all the views we need and configure them properly.
538 */
539 private void setupViews() {
Joe Onorato00acb122009-08-04 16:04:30 -0400540 DragController dragController = mDragController;
541
Romain Guyb1b69f52009-08-10 15:10:15 -0700542 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400543 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800544
Joe Onorato7c312c12009-08-13 21:36:53 -0700545 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700546 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700547 mAllAppsGrid.setDragController(dragController);
Joe Onorato85a02a82009-09-08 12:34:22 -0700548 mAllAppsGrid.setWillNotDraw(false); // We don't want a hole punched in our window.
Mike Cleronb6082fa02009-10-19 17:03:36 -0700549 // Manage focusability manually since this thing is always visible
550 mAllAppsGrid.setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700551
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800552 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
553 final Workspace workspace = mWorkspace;
554
Joe Onorato7c312c12009-08-13 21:36:53 -0700555 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
556 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800557
Joe Onorato7c312c12009-08-13 21:36:53 -0700558 mHandleView = (HandleView) findViewById(R.id.all_apps_button);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700559 mHandleView.setLauncher(this);
Joe Onorato7404ee42009-07-31 11:54:44 -0700560 mHandleView.setOnClickListener(this);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800561
562 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
563 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
564
565 Drawable previous = mPreviousView.getDrawable();
566 Drawable next = mNextView.getDrawable();
Romain Guy8a73c512009-11-09 19:19:59 -0800567 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800568
Romain Guy1fbc1c82009-11-09 20:43:08 -0800569 mPreviousView.setOnLongClickListener(this);
570 mPreviousView.setOnTouchListener(this);
571 mPreviousView.setOnKeyListener(this);
572 mNextView.setOnLongClickListener(this);
573 mNextView.setOnTouchListener(this);
574 mNextView.setOnKeyListener(this);
575
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800576 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400577 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800578 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800579
580 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400581 deleteZone.setDragController(dragController);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700582 deleteZone.setHandle(mHandleView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800583
Joe Onorato00acb122009-08-04 16:04:30 -0400584 dragController.setDragScoller(workspace);
585 dragController.setDragListener(deleteZone);
586 dragController.setScrollView(dragLayer);
Jason Samsfd22dac2009-09-20 17:24:16 -0700587
Joe Onorato00acb122009-08-04 16:04:30 -0400588 // The order here is bottom to top.
589 dragController.addDropTarget(workspace);
590 dragController.addDropTarget(deleteZone);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800591 }
592
Romain Guy8a73c512009-11-09 19:19:59 -0800593 @SuppressWarnings({"UnusedDeclaration"})
594 public void previousScreen(View v) {
595 mWorkspace.scrollLeft();
596 }
597
598 @SuppressWarnings({"UnusedDeclaration"})
599 public void nextScreen(View v) {
600 mWorkspace.scrollRight();
601 }
602
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800603 /**
604 * Creates a view representing a shortcut.
605 *
606 * @param info The data structure describing the shortcut.
607 *
608 * @return A View inflated from R.layout.application.
609 */
610 View createShortcut(ApplicationInfo info) {
611 return createShortcut(R.layout.application,
612 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
613 }
614
615 /**
616 * Creates a view representing a shortcut inflated from the specified resource.
617 *
618 * @param layoutResId The id of the XML layout used to create the shortcut.
619 * @param parent The group the shortcut belongs to.
620 * @param info The data structure describing the shortcut.
621 *
622 * @return A View inflated from layoutResId.
623 */
624 View createShortcut(int layoutResId, ViewGroup parent, ApplicationInfo info) {
625 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
626
Joe Onorato5162ea92009-09-03 09:39:42 -0700627 if (info.icon == null) {
628 info.icon = AppInfoCache.getIconDrawable(getPackageManager(), info);
629 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 if (!info.filtered) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700631 info.icon = Utilities.createIconThumbnail(info.icon, this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800632 info.filtered = true;
633 }
634
635 favorite.setCompoundDrawablesWithIntrinsicBounds(null, info.icon, null, null);
636 favorite.setText(info.title);
637 favorite.setTag(info);
638 favorite.setOnClickListener(this);
639
640 return favorite;
641 }
642
643 /**
644 * Add an application shortcut to the workspace.
645 *
646 * @param data The intent describing the application.
647 * @param cellInfo The position on screen where to create the shortcut.
648 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400649 void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800650 cellInfo.screen = mWorkspace.getCurrentScreen();
651 if (!findSingleSlot(cellInfo)) return;
652
Romain Guy73b979d2009-06-09 12:57:21 -0700653 final ApplicationInfo info = infoFromApplicationIntent(context, data);
654 if (info != null) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400655 mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked());
Romain Guy73b979d2009-06-09 12:57:21 -0700656 }
657 }
658
659 private static ApplicationInfo infoFromApplicationIntent(Context context, Intent data) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800660 ComponentName component = data.getComponent();
661 PackageManager packageManager = context.getPackageManager();
662 ActivityInfo activityInfo = null;
663 try {
664 activityInfo = packageManager.getActivityInfo(component, 0 /* no flags */);
665 } catch (NameNotFoundException e) {
Romain Guy73b979d2009-06-09 12:57:21 -0700666 e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800667 }
Romain Guycbb89e42009-06-08 15:52:54 -0700668
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800669 if (activityInfo != null) {
670 ApplicationInfo itemInfo = new ApplicationInfo();
Romain Guycbb89e42009-06-08 15:52:54 -0700671
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 itemInfo.title = activityInfo.loadLabel(packageManager);
673 if (itemInfo.title == null) {
674 itemInfo.title = activityInfo.name;
675 }
Romain Guycbb89e42009-06-08 15:52:54 -0700676
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800677 itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK |
678 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
679 itemInfo.icon = activityInfo.loadIcon(packageManager);
680 itemInfo.container = ItemInfo.NO_ID;
681
Romain Guy73b979d2009-06-09 12:57:21 -0700682 return itemInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800683 }
Romain Guy73b979d2009-06-09 12:57:21 -0700684
685 return null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800686 }
Romain Guycbb89e42009-06-08 15:52:54 -0700687
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800688 /**
689 * Add a shortcut to the workspace.
690 *
691 * @param data The intent describing the shortcut.
692 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400694 private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800695 cellInfo.screen = mWorkspace.getCurrentScreen();
696 if (!findSingleSlot(cellInfo)) return;
Romain Guycbb89e42009-06-08 15:52:54 -0700697
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800698 final ApplicationInfo info = addShortcut(this, data, cellInfo, false);
699
700 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800701 final View view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400702 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
703 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800704 }
705 }
706
Romain Guycbb89e42009-06-08 15:52:54 -0700707
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800708 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700709 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800710 *
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700711 * @param data The intent describing the appWidgetId.
712 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800713 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400714 private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800715 Bundle extras = data.getExtras();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700716 int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Romain Guycbb89e42009-06-08 15:52:54 -0700717
Romain Guy18042c82009-11-06 11:44:55 -0800718 if (LOGD) d(LOG_TAG, "dumping extras content=" + extras.toString());
Romain Guycbb89e42009-06-08 15:52:54 -0700719
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700720 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700721
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700722 // Calculate the grid spans needed to fit this widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800723 CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700724 int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
Romain Guycbb89e42009-06-08 15:52:54 -0700725
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800726 // Try finding open space on Launcher screen
727 final int[] xy = mCellCoordinates;
Romain Guy18042c82009-11-06 11:44:55 -0800728 if (!findSlot(cellInfo, xy, spans[0], spans[1])) {
729 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
730 return;
731 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800732
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700733 // Build Launcher-specific widget info and save to database
734 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800735 launcherInfo.spanX = spans[0];
736 launcherInfo.spanY = spans[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700737
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800738 LauncherModel.addItemToDatabase(this, launcherInfo,
739 LauncherSettings.Favorites.CONTAINER_DESKTOP,
740 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
741
742 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400743 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700744
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800745 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700746 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700747
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700748 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800749 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700750
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800751 mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400752 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800753 }
754 }
Romain Guycbb89e42009-06-08 15:52:54 -0700755
Joe Onorato9c1289c2009-08-17 11:03:03 -0400756 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
757 mDesktopItems.remove(launcherInfo);
758 launcherInfo.hostView = null;
759 }
760
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700761 public LauncherAppWidgetHost getAppWidgetHost() {
762 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800763 }
Romain Guycbb89e42009-06-08 15:52:54 -0700764
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800765 static ApplicationInfo addShortcut(Context context, Intent data,
766 CellLayout.CellInfo cellInfo, boolean notify) {
767
Romain Guy73b979d2009-06-09 12:57:21 -0700768 final ApplicationInfo info = infoFromShortcutIntent(context, data);
769 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
770 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
771
772 return info;
773 }
774
775 private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800776 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
777 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
778 Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
779
780 Drawable icon = null;
781 boolean filtered = false;
782 boolean customIcon = false;
Romain Guy73b979d2009-06-09 12:57:21 -0700783 ShortcutIconResource iconResource = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800784
785 if (bitmap != null) {
786 icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
787 filtered = true;
788 customIcon = true;
789 } else {
790 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
Romain Guy73b979d2009-06-09 12:57:21 -0700791 if (extra != null && extra instanceof ShortcutIconResource) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800792 try {
Romain Guy73b979d2009-06-09 12:57:21 -0700793 iconResource = (ShortcutIconResource) extra;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800794 final PackageManager packageManager = context.getPackageManager();
795 Resources resources = packageManager.getResourcesForApplication(
796 iconResource.packageName);
797 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
798 icon = resources.getDrawable(id);
799 } catch (Exception e) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700800 w(LOG_TAG, "Could not load shortcut icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800801 }
802 }
803 }
804
805 if (icon == null) {
806 icon = context.getPackageManager().getDefaultActivityIcon();
807 }
808
809 final ApplicationInfo info = new ApplicationInfo();
810 info.icon = icon;
811 info.filtered = filtered;
812 info.title = name;
813 info.intent = intent;
814 info.customIcon = customIcon;
815 info.iconResource = iconResource;
816
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 return info;
818 }
819
820 @Override
821 protected void onNewIntent(Intent intent) {
822 super.onNewIntent(intent);
823
824 // Close the menu
825 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
826 getWindow().closeAllPanels();
Jason Samsfd22dac2009-09-20 17:24:16 -0700827
Joe Onorato742966b2009-10-07 10:26:17 -0700828 // Whatever we were doing is hereby canceled.
829 mWaitingForResult = false;
830
Mike LeBeau736cf282009-07-02 17:46:59 -0700831 // Set this flag so that onResume knows to close the search dialog if it's open,
832 // because this was a new intent (thus a press of 'home' or some such) rather than
833 // for example onResume being called when the user pressed the 'back' button.
834 mIsNewIntent = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800835
836 try {
837 dismissDialog(DIALOG_CREATE_SHORTCUT);
838 // Unlock the workspace if the dialog was showing
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800839 } catch (Exception e) {
840 // An exception is thrown if the dialog is not visible, which is fine
841 }
842
843 try {
844 dismissDialog(DIALOG_RENAME_FOLDER);
845 // Unlock the workspace if the dialog was showing
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800846 } catch (Exception e) {
847 // An exception is thrown if the dialog is not visible, which is fine
848 }
849
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) !=
851 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) {
Romain Guy73b979d2009-06-09 12:57:21 -0700852
Romain Guy94dabf12009-07-21 10:55:43 -0700853 if (!mWorkspace.isDefaultScreenShowing()) {
854 mWorkspace.moveToDefaultScreen();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 }
Romain Guy1dd3a072009-07-16 13:21:01 -0700856
Joe Onorato7bb17492009-09-24 17:51:01 -0700857 closeAllApps(true);
Romain Guy73b979d2009-06-09 12:57:21 -0700858
859 final View v = getWindow().peekDecorView();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800860 if (v != null && v.getWindowToken() != null) {
861 InputMethodManager imm = (InputMethodManager)getSystemService(
862 INPUT_METHOD_SERVICE);
863 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
864 }
865 } else {
Joe Onorato7bb17492009-09-24 17:51:01 -0700866 closeAllApps(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 }
868 }
869 }
870
871 @Override
872 protected void onRestoreInstanceState(Bundle savedInstanceState) {
873 // Do not call super here
874 mSavedInstanceState = savedInstanceState;
875 }
876
877 @Override
878 protected void onSaveInstanceState(Bundle outState) {
879 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen());
880
881 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
882 if (folders.size() > 0) {
883 final int count = folders.size();
884 long[] ids = new long[count];
885 for (int i = 0; i < count; i++) {
886 final FolderInfo info = folders.get(i).getInfo();
887 ids[i] = info.id;
888 }
889 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
890 } else {
891 super.onSaveInstanceState(outState);
892 }
893
Romain Guy3cf604f2009-06-16 13:12:53 -0700894 final boolean isConfigurationChange = getChangingConfigurations() != 0;
895
Romain Guy5a941392009-04-28 15:18:25 -0700896 // When the drawer is opened and we are saving the state because of a
897 // configuration change
Joe Onoratofb0ca672009-09-14 17:55:46 -0400898 // TODO should not do this if the drawer is currently closing.
899 if (isAllAppsVisible() && isConfigurationChange) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800900 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -0700901 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902
903 if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
904 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
905 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);
906
907 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
908 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
909 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
910 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
911 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
912 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
913 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
914 outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS,
915 layout.getOccupiedCells());
916 }
917
918 if (mFolderInfo != null && mWaitingForResult) {
919 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
920 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
921 }
922 }
923
924 @Override
925 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800926 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -0700927
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800928 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700929 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800930 } catch (NullPointerException ex) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -0700931 w(LOG_TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800932 }
933
934 TextKeyListener.getInstance().release();
935
Joe Onorato9c1289c2009-08-17 11:03:03 -0400936 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800937
Joe Onorato9c1289c2009-08-17 11:03:03 -0400938 unbindDesktopItems();
939 AppInfoCache.unbindDrawables();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800940
941 getContentResolver().unregisterContentObserver(mWidgetObserver);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800942
943 dismissPreview(mPreviousView);
944 dismissPreview(mNextView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800945 }
946
947 @Override
948 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -0700949 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 super.startActivityForResult(intent, requestCode);
951 }
952
953 @Override
Romain Guycbb89e42009-06-08 15:52:54 -0700954 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800955 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700956
Joe Onorato7bb17492009-09-24 17:51:01 -0700957 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -0700958
Karl Rosaen138a0412009-04-23 19:00:21 -0700959 // Slide the search widget to the top, if it's on the current screen,
960 // otherwise show the search dialog immediately.
961 Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
962 if (searchWidget == null) {
963 showSearchDialog(initialQuery, selectInitialQuery, appSearchData, globalSearch);
964 } else {
965 searchWidget.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
966 // show the currently typed text in the search widget while sliding
967 searchWidget.setQuery(getTypedText());
968 }
969 }
Romain Guycbb89e42009-06-08 15:52:54 -0700970
Karl Rosaen138a0412009-04-23 19:00:21 -0700971 /**
972 * Show the search dialog immediately, without changing the search widget.
Romain Guy5a941392009-04-28 15:18:25 -0700973 *
974 * @see Activity#startSearch(String, boolean, android.os.Bundle, boolean)
Karl Rosaen138a0412009-04-23 19:00:21 -0700975 */
Romain Guycbb89e42009-06-08 15:52:54 -0700976 void showSearchDialog(String initialQuery, boolean selectInitialQuery,
Karl Rosaen138a0412009-04-23 19:00:21 -0700977 Bundle appSearchData, boolean globalSearch) {
Romain Guycbb89e42009-06-08 15:52:54 -0700978
Karl Rosaen138a0412009-04-23 19:00:21 -0700979 if (initialQuery == null) {
980 // Use any text typed in the launcher as the initial query
981 initialQuery = getTypedText();
982 clearTypedText();
983 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800984 if (appSearchData == null) {
985 appSearchData = new Bundle();
986 appSearchData.putString(SearchManager.SOURCE, "launcher-search");
987 }
Romain Guycbb89e42009-06-08 15:52:54 -0700988
Karl Rosaen138a0412009-04-23 19:00:21 -0700989 final SearchManager searchManager =
990 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
991
992 final Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
993 if (searchWidget != null) {
994 // This gets called when the user leaves the search dialog to go back to
995 // the Launcher.
996 searchManager.setOnCancelListener(new SearchManager.OnCancelListener() {
997 public void onCancel() {
998 searchManager.setOnCancelListener(null);
Romain Guy5a941392009-04-28 15:18:25 -0700999 stopSearch();
Romain Guycbb89e42009-06-08 15:52:54 -07001000 }
Karl Rosaen138a0412009-04-23 19:00:21 -07001001 });
1002 }
Romain Guycbb89e42009-06-08 15:52:54 -07001003
Karl Rosaen138a0412009-04-23 19:00:21 -07001004 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001005 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001006 }
1007
Karl Rosaen138a0412009-04-23 19:00:21 -07001008 /**
1009 * Cancel search dialog if it is open.
Karl Rosaen138a0412009-04-23 19:00:21 -07001010 */
Romain Guy5a941392009-04-28 15:18:25 -07001011 void stopSearch() {
Karl Rosaen138a0412009-04-23 19:00:21 -07001012 // Close search dialog
1013 SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Bjorn Bringert0879cef2009-07-08 12:38:25 +01001014 searchManager.stopSearch();
Karl Rosaen138a0412009-04-23 19:00:21 -07001015 // Restore search widget to its normal position
1016 Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
1017 if (searchWidget != null) {
1018 searchWidget.stopSearch(false);
1019 }
1020 }
Romain Guycbb89e42009-06-08 15:52:54 -07001021
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022 @Override
1023 public boolean onCreateOptionsMenu(Menu menu) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001024 if (isWorkspaceLocked()) {
1025 return false;
1026 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001027
1028 super.onCreateOptionsMenu(menu);
1029 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1030 .setIcon(android.R.drawable.ic_menu_add)
1031 .setAlphabeticShortcut('A');
1032 menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1033 .setIcon(android.R.drawable.ic_menu_gallery)
1034 .setAlphabeticShortcut('W');
1035 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1036 .setIcon(android.R.drawable.ic_search_category_default)
1037 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1038 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1039 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1040 .setAlphabeticShortcut('N');
1041
1042 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001043 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1044 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001045
1046 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1047 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1048 .setIntent(settings);
1049
1050 return true;
1051 }
1052
1053 @Override
1054 public boolean onPrepareOptionsMenu(Menu menu) {
1055 super.onPrepareOptionsMenu(menu);
1056
1057 mMenuAddInfo = mWorkspace.findAllVacantCells(null);
1058 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
1059
1060 return true;
1061 }
1062
1063 @Override
1064 public boolean onOptionsItemSelected(MenuItem item) {
1065 switch (item.getItemId()) {
1066 case MENU_ADD:
1067 addItems();
1068 return true;
1069 case MENU_WALLPAPER_SETTINGS:
1070 startWallpaper();
1071 return true;
1072 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001073 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 return true;
1075 case MENU_NOTIFICATIONS:
1076 showNotifications();
1077 return true;
1078 }
1079
1080 return super.onOptionsItemSelected(item);
1081 }
Romain Guycbb89e42009-06-08 15:52:54 -07001082
Karl Rosaen138a0412009-04-23 19:00:21 -07001083 /**
1084 * Indicates that we want global search for this activity by setting the globalSearch
1085 * argument for {@link #startSearch} to true.
1086 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001087
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001088 @Override
1089 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001090 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001091 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001092 }
1093
Joe Onorato9c1289c2009-08-17 11:03:03 -04001094 public boolean isWorkspaceLocked() {
1095 return mWorkspaceLoading || mWaitingForResult;
1096 }
1097
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001098 private void addItems() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001099 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001100 showAddDialog(mMenuAddInfo);
1101 }
1102
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001103 void addAppWidget(Intent data) {
1104 // TODO: catch bad widget exception when sent
1105 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001106
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001107 String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
1108 if (SEARCH_WIDGET.equals(customWidget)) {
1109 // We don't need this any more, since this isn't a real app widget.
1110 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1111 // add the search widget
1112 addSearch();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 } else {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001114 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1115
1116 if (appWidget.configure != null) {
1117 // Launch over to configure widget, if needed
1118 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1119 intent.setComponent(appWidget.configure);
1120 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1121
1122 startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
1123 } else {
1124 // Otherwise just add it
1125 onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
1126 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001127 }
1128 }
Romain Guycbb89e42009-06-08 15:52:54 -07001129
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130 void addSearch() {
1131 final Widget info = Widget.makeSearch();
1132 final CellLayout.CellInfo cellInfo = mAddItemCellInfo;
Romain Guycbb89e42009-06-08 15:52:54 -07001133
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001134 final int[] xy = mCellCoordinates;
1135 final int spanX = info.spanX;
1136 final int spanY = info.spanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001137
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001138 if (!findSlot(cellInfo, xy, spanX, spanY)) return;
Romain Guycbb89e42009-06-08 15:52:54 -07001139
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001140 LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1141 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
Romain Guycbb89e42009-06-08 15:52:54 -07001142
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001143 final View view = mInflater.inflate(info.layoutResource, null);
1144 view.setTag(info);
Karl Rosaen138a0412009-04-23 19:00:21 -07001145 Search search = (Search) view.findViewById(R.id.widget_search);
1146 search.setLauncher(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001147
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001148 mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY);
1149 }
1150
Romain Guy73b979d2009-06-09 12:57:21 -07001151 void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001152 // Handle case where user selected "Applications"
1153 String applicationName = getResources().getString(R.string.group_applications);
1154 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001155
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001156 if (applicationName != null && applicationName.equals(shortcutName)) {
1157 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1158 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001159
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001160 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1161 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Romain Guy73b979d2009-06-09 12:57:21 -07001162 startActivityForResult(pickIntent, requestCodeApplication);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001163 } else {
Romain Guy73b979d2009-06-09 12:57:21 -07001164 startActivityForResult(intent, requestCodeShortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001165 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001166 }
1167
1168 void addLiveFolder(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001169 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001170 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001171 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001172
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001173 if (folderName != null && folderName.equals(shortcutName)) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001174 addFolder();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001175 } else {
1176 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1177 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001178 }
1179
Joe Onorato9c1289c2009-08-17 11:03:03 -04001180 void addFolder() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001181 UserFolderInfo folderInfo = new UserFolderInfo();
1182 folderInfo.title = getText(R.string.folder_name);
1183
1184 CellLayout.CellInfo cellInfo = mAddItemCellInfo;
1185 cellInfo.screen = mWorkspace.getCurrentScreen();
1186 if (!findSingleSlot(cellInfo)) return;
1187
1188 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001189 LauncherModel.addItemToDatabase(this, folderInfo,
1190 LauncherSettings.Favorites.CONTAINER_DESKTOP,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001191 mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001192 mFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001193
1194 // Create the view
1195 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1196 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
1197 mWorkspace.addInCurrentScreen(newFolder,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001198 cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001199 }
Romain Guycbb89e42009-06-08 15:52:54 -07001200
Joe Onorato9c1289c2009-08-17 11:03:03 -04001201 void removeFolder(FolderInfo folder) {
1202 mFolders.remove(folder.id);
1203 }
1204
1205 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001206 cellInfo.screen = mWorkspace.getCurrentScreen();
1207 if (!findSingleSlot(cellInfo)) return;
1208
1209 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
1210
1211 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
1213 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001214 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
1215 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 }
1217 }
1218
1219 static LiveFolderInfo addLiveFolder(Context context, Intent data,
1220 CellLayout.CellInfo cellInfo, boolean notify) {
1221
1222 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1223 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1224
1225 Drawable icon = null;
1226 boolean filtered = false;
1227 Intent.ShortcutIconResource iconResource = null;
1228
1229 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1230 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1231 try {
1232 iconResource = (Intent.ShortcutIconResource) extra;
1233 final PackageManager packageManager = context.getPackageManager();
1234 Resources resources = packageManager.getResourcesForApplication(
1235 iconResource.packageName);
1236 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1237 icon = resources.getDrawable(id);
1238 } catch (Exception e) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001239 w(LOG_TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001240 }
1241 }
1242
1243 if (icon == null) {
1244 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1245 }
1246
1247 final LiveFolderInfo info = new LiveFolderInfo();
1248 info.icon = icon;
1249 info.filtered = filtered;
1250 info.title = name;
1251 info.iconResource = iconResource;
1252 info.uri = data.getData();
1253 info.baseIntent = baseIntent;
1254 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1255 LiveFolders.DISPLAY_MODE_GRID);
1256
1257 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1258 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001259 mFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260
1261 return info;
1262 }
1263
1264 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
1265 final int[] xy = new int[2];
1266 if (findSlot(cellInfo, xy, 1, 1)) {
1267 cellInfo.cellX = xy[0];
1268 cellInfo.cellY = xy[1];
1269 return true;
1270 }
1271 return false;
1272 }
1273
1274 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
1275 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1276 boolean[] occupied = mSavedState != null ?
1277 mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null;
1278 cellInfo = mWorkspace.findAllVacantCells(occupied);
1279 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1280 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1281 return false;
1282 }
1283 }
1284 return true;
1285 }
1286
1287 private void showNotifications() {
1288 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1289 if (statusBar != null) {
1290 statusBar.expand();
1291 }
1292 }
1293
1294 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001295 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001296 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001297 Intent chooser = Intent.createChooser(pickWallpaper,
1298 getText(R.string.chooser_wallpaper));
1299 WallpaperManager wm = (WallpaperManager)
1300 getSystemService(Context.WALLPAPER_SERVICE);
1301 WallpaperInfo wi = wm.getWallpaperInfo();
1302 if (wi != null && wi.getSettingsActivity() != null) {
1303 LabeledIntent li = new LabeledIntent(getPackageName(),
1304 R.string.configure_wallpaper, 0);
1305 li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1306 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1307 }
Mike Clerona0618e42009-10-22 13:55:21 -07001308 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 }
1310
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001311 private void registerContentObservers() {
1312 ContentResolver resolver = getContentResolver();
1313 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1314 true, mWidgetObserver);
1315 }
1316
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001317 @Override
1318 public boolean dispatchKeyEvent(KeyEvent event) {
1319 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1320 switch (event.getKeyCode()) {
1321 case KeyEvent.KEYCODE_BACK:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 return true;
1323 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001324 return true;
1325 }
1326 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1327 switch (event.getKeyCode()) {
1328 case KeyEvent.KEYCODE_BACK:
1329 if (!event.isCanceled()) {
1330 mWorkspace.dispatchKeyEvent(event);
Joe Onoratofb0ca672009-09-14 17:55:46 -04001331 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001332 closeAllApps(true);
Dianne Hackborn67800862009-07-24 17:15:20 -07001333 } else {
1334 closeFolder();
1335 }
1336 }
Dianne Hackborn67800862009-07-24 17:15:20 -07001337 return true;
1338 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001339 return true;
1340 }
1341 }
1342
1343 return super.dispatchKeyEvent(event);
1344 }
1345
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001346 private void closeFolder() {
1347 Folder folder = mWorkspace.getOpenFolder();
1348 if (folder != null) {
1349 closeFolder(folder);
1350 }
1351 }
1352
1353 void closeFolder(Folder folder) {
1354 folder.getInfo().opened = false;
1355 ViewGroup parent = (ViewGroup) folder.getParent();
1356 if (parent != null) {
1357 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001358 if (folder instanceof DropTarget) {
1359 // Live folders aren't DropTargets.
1360 mDragController.removeDropTarget((DropTarget)folder);
1361 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001362 }
1363 folder.onClose();
1364 }
1365
1366 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001367 * Re-listen when widgets are reset.
1368 */
1369 private void onAppWidgetReset() {
1370 mAppWidgetHost.startListening();
1371 }
1372
1373 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001374 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1375 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001376 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001377 private void unbindDesktopItems() {
1378 for (ItemInfo item: mDesktopItems) {
1379 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001380 }
1381 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001382
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001383 /**
1384 * Launches the intent referred by the clicked shortcut.
1385 *
1386 * @param v The view representing the clicked shortcut.
1387 */
1388 public void onClick(View v) {
1389 Object tag = v.getTag();
1390 if (tag instanceof ApplicationInfo) {
1391 // Open shortcut
1392 final Intent intent = ((ApplicationInfo) tag).intent;
1393 startActivitySafely(intent);
Joe Onoratoff3862d2009-10-07 10:35:51 -07001394 mExitingBecauseOfLaunch = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001395 } else if (tag instanceof FolderInfo) {
1396 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001397 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001398 Log.d(TAG, "onClick");
1399 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001400 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001401 } else {
Jason Samsfd22dac2009-09-20 17:24:16 -07001402 showAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -07001403 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 }
1405 }
1406
1407 void startActivitySafely(Intent intent) {
1408 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1409 try {
1410 startActivity(intent);
1411 } catch (ActivityNotFoundException e) {
1412 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1413 } catch (SecurityException e) {
1414 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Romain Guy73b979d2009-06-09 12:57:21 -07001415 e(LOG_TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1417 "or use the exported attribute for this activity.", e);
1418 }
1419 }
1420
1421 private void handleFolderClick(FolderInfo folderInfo) {
1422 if (!folderInfo.opened) {
1423 // Close any open folder
1424 closeFolder();
1425 // Open the requested folder
1426 openFolder(folderInfo);
1427 } else {
1428 // Find the open folder...
1429 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1430 int folderScreen;
1431 if (openFolder != null) {
1432 folderScreen = mWorkspace.getScreenForView(openFolder);
1433 // .. and close it
1434 closeFolder(openFolder);
1435 if (folderScreen != mWorkspace.getCurrentScreen()) {
1436 // Close any folder open on the current screen
1437 closeFolder();
1438 // Pull the folder onto this screen
1439 openFolder(folderInfo);
1440 }
1441 }
1442 }
1443 }
1444
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001445 /**
1446 * Opens the user fodler described by the specified tag. The opening of the folder
1447 * is animated relative to the specified View. If the View is null, no animation
1448 * is played.
1449 *
1450 * @param folderInfo The FolderInfo describing the folder to open.
1451 */
1452 private void openFolder(FolderInfo folderInfo) {
1453 Folder openFolder;
1454
1455 if (folderInfo instanceof UserFolderInfo) {
1456 openFolder = UserFolder.fromXml(this);
1457 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001458 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001459 } else {
1460 return;
1461 }
1462
Joe Onorato00acb122009-08-04 16:04:30 -04001463 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001464 openFolder.setLauncher(this);
1465
1466 openFolder.bind(folderInfo);
1467 folderInfo.opened = true;
1468
1469 mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4);
1470 openFolder.onOpen();
1471 }
1472
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001474 switch (v.getId()) {
1475 case R.id.previous_screen:
1476 showPreviousPreview(v);
1477 return true;
1478 case R.id.next_screen:
1479 showNextPreview(v);
1480 return true;
1481 }
1482
Joe Onorato9c1289c2009-08-17 11:03:03 -04001483 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001484 return false;
1485 }
1486
1487 if (!(v instanceof CellLayout)) {
1488 v = (View) v.getParent();
1489 }
1490
1491 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
1492
1493 // This happens when long clicking an item with the dpad/trackball
1494 if (cellInfo == null) {
1495 return true;
1496 }
1497
1498 if (mWorkspace.allowLongPress()) {
1499 if (cellInfo.cell == null) {
1500 if (cellInfo.valid) {
1501 // User long pressed on empty space
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001502 mWorkspace.setAllowLongPress(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001503 showAddDialog(cellInfo);
1504 }
1505 } else {
1506 if (!(cellInfo.cell instanceof Folder)) {
1507 // User long pressed on an item
1508 mWorkspace.startDrag(cellInfo);
1509 }
1510 }
1511 }
1512 return true;
1513 }
1514
Romain Guy1fbc1c82009-11-09 20:43:08 -08001515 public boolean onKey(View v, int keyCode, KeyEvent event) {
1516 if (event.getAction() == KeyEvent.ACTION_UP) {
1517 dismissPreview(v);
1518 }
1519 return false;
1520 }
1521
1522 public boolean onTouch(View v, MotionEvent event) {
1523 if (event.getAction() == MotionEvent.ACTION_UP) {
1524 dismissPreview(v);
1525 }
1526 return false;
1527 }
1528
1529 private void dismissPreview(View v) {
1530 PopupWindow window = (PopupWindow) v.getTag();
1531 if (window != null) {
1532 window.dismiss();
1533 ((ImageView) v.getTag(R.id.workspace)).setImageBitmap(null);
1534 ((Bitmap) v.getTag(R.id.icon)).recycle();
1535
1536 v.setTag(R.id.workspace, null);
1537 v.setTag(R.id.icon, null);
1538 }
1539 v.setTag(null);
1540 }
1541
1542 private void showPreviousPreview(View anchor) {
1543 int current = mWorkspace.getCurrentScreen();
1544 if (current <= 0) return;
1545
1546 View previous = mWorkspace.getChildAt(current - 1);
1547 showPreview(anchor, previous);
1548 }
1549
1550 private void showNextPreview(View anchor) {
1551 int current = mWorkspace.getCurrentScreen();
1552 if (current >= mWorkspace.getChildCount() - 1) return;
1553
1554 View next = mWorkspace.getChildAt(current + 1);
1555 showPreview(anchor, next);
1556 }
1557
1558 private void showPreview(View anchor, View source) {
1559 boolean cacheEnabled = source.isDrawingCacheEnabled();
1560 source.setDrawingCacheEnabled(true);
1561 source.buildDrawingCache();
1562
1563 Bitmap cache = source.getDrawingCache();
1564 if (cache == null) return;
1565
Romain Guy1a304a12009-11-10 00:02:32 -08001566 int width = cache.getWidth();
1567 int height = cache.getHeight();
1568 float sx = (int) (width / 2.5f) / (float) width;
1569 float sy = (int) (height / 2.5f) / (float) height;
1570
1571 Matrix m = new Matrix();
1572 m.setScale(sx, sy);
1573
1574 CellLayout cell = ((CellLayout) source);
1575 int x = cell.getLeftPadding();
1576 int y = cell.getTopPadding();
1577 width -= (x + cell.getRightPadding());
1578 height -= (y + cell.getBottomPadding());
1579
1580 Bitmap bitmap = Bitmap.createBitmap(cache, x, y, width, height, m, true);
Romain Guy1fbc1c82009-11-09 20:43:08 -08001581
1582 ImageView preview = new ImageView(this);
1583 preview.setImageBitmap(bitmap);
1584 Drawable d = getResources().getDrawable(R.drawable.preview_popup);
1585 preview.setBackgroundDrawable(d);
1586
1587 Rect r = new Rect();
1588 d.getPadding(r);
1589 int extraW = r.left + r.right;
1590 int extraH = r.top + r.bottom;
1591
1592 PopupWindow p = new PopupWindow(preview, bitmap.getWidth() + extraW,
1593 bitmap.getHeight() + extraH);
1594 p.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,
1595 ViewGroup.LayoutParams.WRAP_CONTENT);
1596 p.setAnimationStyle(R.style.AnimationPreview);
1597 p.showAsDropDown(anchor, 0, 0);
1598
1599 source.destroyDrawingCache();
1600 if (!cacheEnabled) source.setDrawingCacheEnabled(cacheEnabled);
1601
1602 anchor.setTag(p);
1603 anchor.setTag(R.id.workspace, preview);
1604 anchor.setTag(R.id.icon, bitmap);
1605 }
1606
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001607 View getDrawerHandle() {
1608 return mHandleView;
1609 }
1610
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001611 Workspace getWorkspace() {
1612 return mWorkspace;
1613 }
1614
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001615 @Override
1616 protected Dialog onCreateDialog(int id) {
1617 switch (id) {
1618 case DIALOG_CREATE_SHORTCUT:
1619 return new CreateShortcut().createDialog();
1620 case DIALOG_RENAME_FOLDER:
1621 return new RenameFolder().createDialog();
1622 }
1623
1624 return super.onCreateDialog(id);
1625 }
1626
1627 @Override
1628 protected void onPrepareDialog(int id, Dialog dialog) {
1629 switch (id) {
1630 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001631 break;
1632 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001633 if (mFolderInfo != null) {
1634 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1635 final CharSequence text = mFolderInfo.title;
1636 input.setText(text);
1637 input.setSelection(0, text.length());
1638 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001639 break;
1640 }
1641 }
1642
1643 void showRenameDialog(FolderInfo info) {
1644 mFolderInfo = info;
1645 mWaitingForResult = true;
1646 showDialog(DIALOG_RENAME_FOLDER);
1647 }
1648
1649 private void showAddDialog(CellLayout.CellInfo cellInfo) {
1650 mAddItemCellInfo = cellInfo;
1651 mWaitingForResult = true;
1652 showDialog(DIALOG_CREATE_SHORTCUT);
1653 }
1654
Romain Guy73b979d2009-06-09 12:57:21 -07001655 private void pickShortcut(int requestCode, int title) {
1656 Bundle bundle = new Bundle();
1657
1658 ArrayList<String> shortcutNames = new ArrayList<String>();
1659 shortcutNames.add(getString(R.string.group_applications));
1660 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
1661
1662 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
1663 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1664 R.drawable.ic_launcher_application));
1665 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1666
1667 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1668 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
1669 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title));
1670 pickIntent.putExtras(bundle);
1671
1672 startActivityForResult(pickIntent, requestCode);
1673 }
1674
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001675 private class RenameFolder {
1676 private EditText mInput;
1677
1678 Dialog createDialog() {
1679 mWaitingForResult = true;
1680 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1681 mInput = (EditText) layout.findViewById(R.id.folder_name);
1682
1683 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1684 builder.setIcon(0);
1685 builder.setTitle(getString(R.string.rename_folder_title));
1686 builder.setCancelable(true);
1687 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1688 public void onCancel(DialogInterface dialog) {
1689 cleanup();
1690 }
1691 });
1692 builder.setNegativeButton(getString(R.string.cancel_action),
1693 new Dialog.OnClickListener() {
1694 public void onClick(DialogInterface dialog, int which) {
1695 cleanup();
1696 }
1697 }
1698 );
1699 builder.setPositiveButton(getString(R.string.rename_action),
1700 new Dialog.OnClickListener() {
1701 public void onClick(DialogInterface dialog, int which) {
1702 changeFolderName();
1703 }
1704 }
1705 );
1706 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001707
1708 final AlertDialog dialog = builder.create();
1709 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1710 public void onShow(DialogInterface dialog) {
Joe Onoratod753b422009-11-08 13:31:11 -05001711 mInput.requestFocus();
1712 InputMethodManager inputManager = (InputMethodManager)
1713 getSystemService(Context.INPUT_METHOD_SERVICE);
1714 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001715 }
1716 });
1717
1718 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001719 }
1720
1721 private void changeFolderName() {
1722 final String name = mInput.getText().toString();
1723 if (!TextUtils.isEmpty(name)) {
1724 // Make sure we have the right folder info
Joe Onorato9c1289c2009-08-17 11:03:03 -04001725 mFolderInfo = mFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 mFolderInfo.title = name;
1727 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1728
Joe Onorato9c1289c2009-08-17 11:03:03 -04001729 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001730 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001731 mModel.setWorkspaceDirty();
1732 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733 } else {
1734 final FolderIcon folderIcon = (FolderIcon)
1735 mWorkspace.getViewForTag(mFolderInfo);
1736 if (folderIcon != null) {
1737 folderIcon.setText(name);
1738 getWorkspace().requestLayout();
1739 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001740 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001741 mModel.setWorkspaceDirty();
1742 mWorkspaceLoading = true;
1743 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 }
1745 }
1746 }
1747 cleanup();
1748 }
1749
1750 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 dismissDialog(DIALOG_RENAME_FOLDER);
1752 mWaitingForResult = false;
1753 mFolderInfo = null;
1754 }
1755 }
1756
Joe Onoratofb0ca672009-09-14 17:55:46 -04001757 boolean isAllAppsVisible() {
Joe Onorato7bb17492009-09-24 17:51:01 -07001758 return mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04001759 }
1760
Jason Samsfd22dac2009-09-20 17:24:16 -07001761 void showAllApps() {
Jason Sams12c14a82009-10-06 14:33:15 -07001762 mAllAppsGrid.zoom(1.0f);
Joe Onorato7bb17492009-09-24 17:51:01 -07001763 //mWorkspace.hide();
Jason Samsfd22dac2009-09-20 17:24:16 -07001764
Mike Cleronb6082fa02009-10-19 17:03:36 -07001765 mAllAppsGrid.setFocusable(true);
Mike Clerona0618e42009-10-22 13:55:21 -07001766 mAllAppsGrid.requestFocus();
Mike Cleronb6082fa02009-10-19 17:03:36 -07001767
Joe Onorato7c312c12009-08-13 21:36:53 -07001768 // TODO: fade these two too
1769 mDeleteZone.setVisibility(View.GONE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04001770 //mHandleView.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04001771 }
1772
Joe Onorato7bb17492009-09-24 17:51:01 -07001773 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001774 if (mAllAppsGrid.isVisible()) {
Jason Sams12c14a82009-10-06 14:33:15 -07001775 mAllAppsGrid.zoom(0.0f);
Mike Cleronb6082fa02009-10-19 17:03:36 -07001776 mAllAppsGrid.setFocusable(false);
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001777 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
Joe Onorato7c312c12009-08-13 21:36:53 -07001778
Mike Cleronb6082fa02009-10-19 17:03:36 -07001779
Joe Onorato7c312c12009-08-13 21:36:53 -07001780 // TODO: fade these two too
Joe Onoratofb0ca672009-09-14 17:55:46 -04001781 /*
Joe Onorato7c312c12009-08-13 21:36:53 -07001782 mDeleteZone.setVisibility(View.VISIBLE);
1783 mHandleView.setVisibility(View.VISIBLE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04001784 */
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001785 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001786 }
1787
Joe Onorato7c312c12009-08-13 21:36:53 -07001788 void lockAllApps() {
1789 // TODO
1790 }
1791
1792 void unlockAllApps() {
1793 // TODO
1794 }
1795
Joe Onorato7404ee42009-07-31 11:54:44 -07001796 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001797 * Displays the shortcut creation dialog and launches, if necessary, the
1798 * appropriate activity.
1799 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001800 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07001801 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
1802 DialogInterface.OnShowListener {
1803
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001804 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07001805
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001806 Dialog createDialog() {
1807 mWaitingForResult = true;
Romain Guycbb89e42009-06-08 15:52:54 -07001808
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07001810
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001811 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1812 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001813 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07001814
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 builder.setInverseBackgroundForced(true);
1816
1817 AlertDialog dialog = builder.create();
1818 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001819 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07001820 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001821
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001822 return dialog;
1823 }
1824
1825 public void onCancel(DialogInterface dialog) {
1826 mWaitingForResult = false;
1827 cleanup();
1828 }
1829
Romain Guycbb89e42009-06-08 15:52:54 -07001830 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07001831 }
1832
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001833 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834 dismissDialog(DIALOG_CREATE_SHORTCUT);
1835 }
1836
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001837 /**
1838 * Handle the action clicked in the "Add to home" dialog.
1839 */
1840 public void onClick(DialogInterface dialog, int which) {
1841 Resources res = getResources();
1842 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07001843
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001844 switch (which) {
1845 case AddAdapter.ITEM_SHORTCUT: {
1846 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07001847 pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001848 break;
1849 }
Romain Guycbb89e42009-06-08 15:52:54 -07001850
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001851 case AddAdapter.ITEM_APPWIDGET: {
1852 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07001853
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001854 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
1855 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1856 // add the search widget
1857 ArrayList<AppWidgetProviderInfo> customInfo =
1858 new ArrayList<AppWidgetProviderInfo>();
1859 AppWidgetProviderInfo info = new AppWidgetProviderInfo();
1860 info.provider = new ComponentName(getPackageName(), "XXX.YYY");
1861 info.label = getString(R.string.group_search);
1862 info.icon = R.drawable.ic_search_widget;
1863 customInfo.add(info);
1864 pickIntent.putParcelableArrayListExtra(
1865 AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
1866 ArrayList<Bundle> customExtras = new ArrayList<Bundle>();
1867 Bundle b = new Bundle();
1868 b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET);
1869 customExtras.add(b);
1870 pickIntent.putParcelableArrayListExtra(
1871 AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
1872 // start the pick activity
1873 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
1874 break;
1875 }
Romain Guycbb89e42009-06-08 15:52:54 -07001876
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001877 case AddAdapter.ITEM_LIVE_FOLDER: {
1878 // Insert extra item to handle inserting folder
1879 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07001880
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001881 ArrayList<String> shortcutNames = new ArrayList<String>();
1882 shortcutNames.add(res.getString(R.string.group_folder));
1883 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07001884
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001885 ArrayList<ShortcutIconResource> shortcutIcons =
1886 new ArrayList<ShortcutIconResource>();
1887 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1888 R.drawable.ic_launcher_folder));
1889 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1890
1891 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1892 pickIntent.putExtra(Intent.EXTRA_INTENT,
1893 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
1894 pickIntent.putExtra(Intent.EXTRA_TITLE,
1895 getText(R.string.title_select_live_folder));
1896 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07001897
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001898 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
1899 break;
1900 }
1901
1902 case AddAdapter.ITEM_WALLPAPER: {
1903 startWallpaper();
1904 break;
1905 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001906 }
1907 }
Romain Guy7b4ef332009-07-14 13:58:08 -07001908
1909 public void onShow(DialogInterface dialog) {
Romain Guy7b4ef332009-07-14 13:58:08 -07001910 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 }
1912
1913 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001914 * Receives notifications whenever the appwidgets are reset.
1915 */
1916 private class AppWidgetResetObserver extends ContentObserver {
1917 public AppWidgetResetObserver() {
1918 super(new Handler());
1919 }
1920
1921 @Override
1922 public void onChange(boolean selfChange) {
1923 onAppWidgetReset();
1924 }
1925 }
1926
1927 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001928 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001929 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001930 public int getCurrentWorkspaceScreen() {
1931 return mWorkspace.getCurrentScreen();
1932 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001933
Joe Onorato9c1289c2009-08-17 11:03:03 -04001934 /**
1935 * Refreshes the shortcuts shown on the workspace.
1936 *
1937 * Implementation of the method from LauncherModel.Callbacks.
1938 */
1939 public void startBinding() {
1940 final Workspace workspace = mWorkspace;
1941 int count = workspace.getChildCount();
1942 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04001943 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04001944 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
1945 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001946
Joe Onorato9c1289c2009-08-17 11:03:03 -04001947 if (DEBUG_USER_INTERFACE) {
1948 android.widget.Button finishButton = new android.widget.Button(this);
1949 finishButton.setText("Finish");
1950 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
1951
1952 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
1953 public void onClick(View v) {
1954 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001955 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001956 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 }
1958 }
1959
1960 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001961 * Bind the items start-end from the list.
1962 *
1963 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001965 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
1966
1967 final Workspace workspace = mWorkspace;
1968
1969 for (int i=start; i<end; i++) {
1970 final ItemInfo item = shortcuts.get(i);
1971 mDesktopItems.add(item);
1972 switch (item.itemType) {
1973 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1974 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1975 final View shortcut = createShortcut((ApplicationInfo) item);
1976 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
1977 false);
1978 break;
1979 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
1980 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1981 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1982 (UserFolderInfo) item);
1983 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
1984 false);
1985 break;
1986 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
1987 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
1988 R.layout.live_folder_icon, this,
1989 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1990 (LiveFolderInfo) item);
1991 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
1992 false);
1993 break;
1994 case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH:
1995 final int screen = workspace.getCurrentScreen();
1996 final View view = mInflater.inflate(R.layout.widget_search,
1997 (ViewGroup) workspace.getChildAt(screen), false);
1998
1999 Search search = (Search) view.findViewById(R.id.widget_search);
2000 search.setLauncher(this);
2001
2002 final Widget widget = (Widget) item;
2003 view.setTag(widget);
2004
2005 workspace.addWidget(view, widget, false);
2006 break;
2007 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002008 }
2009
Joe Onorato9c1289c2009-08-17 11:03:03 -04002010 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002011 }
2012
Joe Onorato9c1289c2009-08-17 11:03:03 -04002013 /**
2014 * Implementation of the method from LauncherModel.Callbacks.
2015 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002016 public void bindFolders(HashMap<Long, FolderInfo> folders) {
2017 mFolders.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002018 mFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002020
2021 /**
2022 * Add the views for a widget to the workspace.
2023 *
2024 * Implementation of the method from LauncherModel.Callbacks.
2025 */
2026 public void bindAppWidget(LauncherAppWidgetInfo item) {
2027 final Workspace workspace = mWorkspace;
2028
2029 final int appWidgetId = item.appWidgetId;
2030 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
2031 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2032
Joe Onorato9c1289c2009-08-17 11:03:03 -04002033 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2034 item.hostView.setTag(item);
2035
2036 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2037 item.cellY, item.spanX, item.spanY, false);
2038
2039 workspace.requestLayout();
2040
2041 mDesktopItems.add(item);
2042 }
2043
2044 /**
2045 * Callback saying that there aren't any more items to bind.
2046 *
2047 * Implementation of the method from LauncherModel.Callbacks.
2048 */
2049 public void finishBindingItems() {
2050 if (mSavedState != null) {
2051 if (!mWorkspace.hasFocus()) {
2052 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
2053 }
2054
2055 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2056 if (userFolders != null) {
2057 for (long folderId : userFolders) {
2058 final FolderInfo info = mFolders.get(folderId);
2059 if (info != null) {
2060 openFolder(info);
2061 }
2062 }
2063 final Folder openFolder = mWorkspace.getOpenFolder();
2064 if (openFolder != null) {
2065 openFolder.requestFocus();
2066 }
2067 }
2068
2069 final boolean allApps = mSavedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
2070 if (allApps) {
Jason Samsfd22dac2009-09-20 17:24:16 -07002071 showAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002072 }
2073
2074 mSavedState = null;
2075 }
2076
2077 if (mSavedInstanceState != null) {
2078 super.onRestoreInstanceState(mSavedInstanceState);
2079 mSavedInstanceState = null;
2080 }
2081
Joe Onorato9c1289c2009-08-17 11:03:03 -04002082 Log.d(TAG, "finishBindingItems done");
2083 mWorkspaceLoading = false;
2084 }
2085
2086 /**
2087 * Add the icons for all apps.
2088 *
2089 * Implementation of the method from LauncherModel.Callbacks.
2090 */
2091 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08002092 mAllAppsGrid.setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002093 }
2094
2095 /**
2096 * A package was installed.
2097 *
2098 * Implementation of the method from LauncherModel.Callbacks.
2099 */
2100 public void bindPackageAdded(ArrayList<ApplicationInfo> apps) {
2101 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002102 mAllAppsGrid.addApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002103 }
2104
2105 /**
2106 * A package was updated.
2107 *
2108 * Implementation of the method from LauncherModel.Callbacks.
2109 */
2110 public void bindPackageUpdated(String packageName, ArrayList<ApplicationInfo> apps) {
2111 removeDialog(DIALOG_CREATE_SHORTCUT);
2112 mWorkspace.updateShortcutsForPackage(packageName);
2113 }
2114
2115 /**
2116 * A package was uninstalled.
2117 *
2118 * Implementation of the method from LauncherModel.Callbacks.
2119 */
2120 public void bindPackageRemoved(String packageName, ArrayList<ApplicationInfo> apps) {
2121 removeDialog(DIALOG_CREATE_SHORTCUT);
2122 mWorkspace.removeShortcutsForPackage(packageName);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002123 mAllAppsGrid.removeApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002124 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002125}