blob: f07810dfc0362bdec33173e7a516a5f527986852 [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;
22import android.app.SearchManager;
23import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070024import android.app.WallpaperManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080026import android.content.BroadcastReceiver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080028import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.content.Context;
30import android.content.DialogInterface;
31import android.content.Intent;
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -070032import android.content.Intent.ShortcutIconResource;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080033import android.content.IntentFilter;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
36import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070038import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.graphics.Bitmap;
Romain Guy1fbc1c82009-11-09 20:43:08 -080041import android.graphics.Rect;
Romain Guya6abce82009-11-10 02:54:41 -080042import android.graphics.Canvas;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.graphics.drawable.Drawable;
Romain Guyff0c2e22009-11-10 12:09:59 -080044import android.graphics.drawable.ColorDrawable;
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;
Joe Onoratobe386092009-11-17 17:32:16 -080048import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.provider.LiveFolders;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.text.Selection;
51import android.text.SpannableStringBuilder;
52import android.text.TextUtils;
53import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070054import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080056import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057import android.view.KeyEvent;
58import android.view.LayoutInflater;
59import android.view.Menu;
60import android.view.MenuItem;
61import android.view.View;
62import android.view.ViewGroup;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.view.View.OnLongClickListener;
64import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.widget.EditText;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066import android.widget.TextView;
67import android.widget.Toast;
Romain Guy8a73c512009-11-09 19:19:59 -080068import android.widget.ImageView;
Romain Guy1fbc1c82009-11-09 20:43:08 -080069import android.widget.PopupWindow;
Romain Guye6b8e2f2009-11-10 11:56:55 -080070import android.widget.LinearLayout;
The Android Open Source Project7376fae2009-03-11 12:11:58 -070071import android.appwidget.AppWidgetManager;
72import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074import java.util.ArrayList;
Joe Onorato9c1289c2009-08-17 11:03:03 -040075import java.util.HashMap;
Romain Guy98d01652009-06-30 16:21:04 -070076import java.io.DataOutputStream;
77import java.io.FileNotFoundException;
78import java.io.IOException;
79import java.io.DataInputStream;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080
81/**
82 * Default launcher application.
83 */
Joe Onorato9c1289c2009-08-17 11:03:03 -040084public final class Launcher extends Activity
Romain Guya6abce82009-11-10 02:54:41 -080085 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080086 static final String TAG = "Launcher";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087 static final boolean LOGD = false;
88
Joe Onorato9c1289c2009-08-17 11:03:03 -040089 static final boolean PROFILE_STARTUP = false;
90 static final boolean PROFILE_ROTATE = false;
91 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -070092
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093 private static final int WALLPAPER_SCREENS_SPAN = 2;
94
95 private static final int MENU_GROUP_ADD = 1;
96 private static final int MENU_ADD = Menu.FIRST + 1;
97 private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
98 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
99 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700100 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800101
102 private static final int REQUEST_CREATE_SHORTCUT = 1;
103 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700104 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800105 private static final int REQUEST_PICK_APPLICATION = 6;
106 private static final int REQUEST_PICK_SHORTCUT = 7;
107 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700108 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700109 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800110
111 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
112
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800113 static final int SCREEN_COUNT = 5;
114 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115 static final int NUMBER_CELLS_X = 4;
Romain Guycbb89e42009-06-08 15:52:54 -0700116 static final int NUMBER_CELLS_Y = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117
Joe Onorato7c312c12009-08-13 21:36:53 -0700118 static final int DIALOG_CREATE_SHORTCUT = 1;
119 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120
Romain Guy98d01652009-06-30 16:21:04 -0700121 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
123 // Type: int
124 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
125 // Type: boolean
126 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
127 // Type: long
128 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
129 // Type: int
130 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
131 // Type: int
132 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
133 // Type: int
134 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
135 // Type: int
136 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX";
137 // Type: int
138 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY";
139 // Type: int
140 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX";
141 // Type: int
142 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY";
143 // Type: int[]
144 private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells";
145 // Type: boolean
146 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
147 // Type: long
148 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
149
Joe Onorato9c1289c2009-08-17 11:03:03 -0400150 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800153 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800155 private final BroadcastReceiver mCloseSystemDialogsReceiver
156 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800157 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
158
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159 private LayoutInflater mInflater;
160
Joe Onorato00acb122009-08-04 16:04:30 -0400161 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700163
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700164 private AppWidgetManager mAppWidgetManager;
165 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700166
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 private CellLayout.CellInfo mAddItemCellInfo;
168 private CellLayout.CellInfo mMenuAddInfo;
169 private final int[] mCellCoordinates = new int[2];
170 private FolderInfo mFolderInfo;
171
Joe Onorato7c312c12009-08-13 21:36:53 -0700172 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700173 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700174 private AllAppsView mAllAppsGrid;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 private Bundle mSavedState;
177
178 private SpannableStringBuilder mDefaultKeySsb = null;
179
Joe Onorato9c1289c2009-08-17 11:03:03 -0400180 private boolean mWorkspaceLoading = true;
181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 private boolean mRestoring;
183 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184
185 private Bundle mSavedInstanceState;
186
Joe Onorato9c1289c2009-08-17 11:03:03 -0400187 private LauncherModel mModel;
188
Romain Guy84f296c2009-11-04 15:00:44 -0800189 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
190 private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700191
Romain Guy1fbc1c82009-11-09 20:43:08 -0800192 private ImageView mPreviousView;
193 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500194
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 @Override
196 protected void onCreate(Bundle savedInstanceState) {
197 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700198
Joe Onorato9c1289c2009-08-17 11:03:03 -0400199 mModel = ((LauncherApplication)getApplication()).setLauncher(this);
Joe Onorato41a12d22009-10-31 18:30:00 -0400200 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800201 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700202
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700203 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700204 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
205 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 if (PROFILE_STARTUP) {
208 android.os.Debug.startMethodTracing("/sdcard/launcher");
209 }
210
211 checkForLocaleChange();
212 setWallpaperDimension();
213
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214 setContentView(R.layout.launcher);
215 setupViews();
216
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800217 registerContentObservers();
218
Joe Onorato7c312c12009-08-13 21:36:53 -0700219 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 mSavedState = savedInstanceState;
222 restoreState(mSavedState);
223
224 if (PROFILE_STARTUP) {
225 android.os.Debug.stopMethodTracing();
226 }
227
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700228 // We have a new AllAppsView, we need to re-bind everything, and it could have
229 // changed in our absence.
230 mModel.setAllAppsDirty();
231 mModel.setWorkspaceDirty();
232
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800233 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400234 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 }
236
237 // For handling default keys
238 mDefaultKeySsb = new SpannableStringBuilder();
239 Selection.setSelection(mDefaultKeySsb, 0);
240 }
Romain Guycbb89e42009-06-08 15:52:54 -0700241
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800242 private void checkForLocaleChange() {
Romain Guy98d01652009-06-30 16:21:04 -0700243 final LocaleConfiguration localeConfiguration = new LocaleConfiguration();
244 readConfiguration(this, localeConfiguration);
Jason Samsfd22dac2009-09-20 17:24:16 -0700245
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246 final Configuration configuration = getResources().getConfiguration();
247
Romain Guy98d01652009-06-30 16:21:04 -0700248 final String previousLocale = localeConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 final String locale = configuration.locale.toString();
250
Romain Guy98d01652009-06-30 16:21:04 -0700251 final int previousMcc = localeConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252 final int mcc = configuration.mcc;
253
Romain Guy98d01652009-06-30 16:21:04 -0700254 final int previousMnc = localeConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 final int mnc = configuration.mnc;
256
Romain Guy84f296c2009-11-04 15:00:44 -0800257 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258
Romain Guy84f296c2009-11-04 15:00:44 -0800259 if (localeChanged) {
Romain Guy98d01652009-06-30 16:21:04 -0700260 localeConfiguration.locale = locale;
261 localeConfiguration.mcc = mcc;
262 localeConfiguration.mnc = mnc;
263
264 writeConfiguration(this, localeConfiguration);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400265 AppInfoCache.flush();
Romain Guy98d01652009-06-30 16:21:04 -0700266 }
267 }
268
269 private static class LocaleConfiguration {
270 public String locale;
271 public int mcc = -1;
272 public int mnc = -1;
273 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700274
Romain Guy98d01652009-06-30 16:21:04 -0700275 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
276 DataInputStream in = null;
277 try {
278 in = new DataInputStream(context.openFileInput(PREFERENCES));
279 configuration.locale = in.readUTF();
280 configuration.mcc = in.readInt();
281 configuration.mnc = in.readInt();
282 } catch (FileNotFoundException e) {
283 // Ignore
284 } catch (IOException e) {
285 // Ignore
286 } finally {
287 if (in != null) {
288 try {
289 in.close();
290 } catch (IOException e) {
291 // Ignore
292 }
293 }
294 }
295 }
296
297 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
298 DataOutputStream out = null;
299 try {
300 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
301 out.writeUTF(configuration.locale);
302 out.writeInt(configuration.mcc);
303 out.writeInt(configuration.mnc);
304 out.flush();
305 } catch (FileNotFoundException e) {
306 // Ignore
307 } catch (IOException e) {
308 //noinspection ResultOfMethodCallIgnored
309 context.getFileStreamPath(PREFERENCES).delete();
310 } finally {
311 if (out != null) {
312 try {
313 out.close();
314 } catch (IOException e) {
315 // Ignore
316 }
317 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800318 }
319 }
320
321 static int getScreen() {
322 synchronized (sLock) {
323 return sScreen;
324 }
325 }
326
327 static void setScreen(int screen) {
328 synchronized (sLock) {
329 sScreen = screen;
330 }
331 }
332
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800333 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700334 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800335
336 Display display = getWindowManager().getDefaultDisplay();
337 boolean isPortrait = display.getWidth() < display.getHeight();
338
339 final int width = isPortrait ? display.getWidth() : display.getHeight();
340 final int height = isPortrait ? display.getHeight() : display.getWidth();
Dianne Hackborn64271802009-08-08 20:54:24 -0700341 wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800342 }
343
344 @Override
345 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700346 mWaitingForResult = false;
347
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800348 // The pattern used here is that a user PICKs a specific application,
349 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700350
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800351 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
352 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700353
Romain Guy94dabf12009-07-21 10:55:43 -0700354 if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800355 switch (requestCode) {
356 case REQUEST_PICK_APPLICATION:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400357 completeAddApplication(this, data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800358 break;
359 case REQUEST_PICK_SHORTCUT:
Romain Guy73b979d2009-06-09 12:57:21 -0700360 processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361 break;
362 case REQUEST_CREATE_SHORTCUT:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400363 completeAddShortcut(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 break;
365 case REQUEST_PICK_LIVE_FOLDER:
366 addLiveFolder(data);
367 break;
368 case REQUEST_CREATE_LIVE_FOLDER:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400369 completeAddLiveFolder(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700371 case REQUEST_PICK_APPWIDGET:
372 addAppWidget(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800373 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700374 case REQUEST_CREATE_APPWIDGET:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400375 completeAddAppWidget(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700377 case REQUEST_PICK_WALLPAPER:
378 // We just wanted the activity result here so we can clear mWaitingForResult
379 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380 }
Romain Guy18042c82009-11-06 11:44:55 -0800381 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
382 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
383 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700384 // Clean up the appWidgetId if we canceled
385 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
386 if (appWidgetId != -1) {
387 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 }
389 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 }
391
392 @Override
393 protected void onResume() {
394 super.onResume();
395
Joe Onorato7e4ed992009-12-03 13:10:49 -0800396 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
397 registerReceiver(mCloseSystemDialogsReceiver, filter);
398
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800399 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400400 mWorkspaceLoading = true;
401 mModel.startLoader(this, true);
402 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800403 }
404 }
405
406 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700407 protected void onPause() {
408 super.onPause();
Romain Guy1fbc1c82009-11-09 20:43:08 -0800409 dismissPreview(mPreviousView);
410 dismissPreview(mNextView);
Joe Onorato24b6fd82009-11-12 13:47:09 -0800411 mDragController.cancelDrag();
Joe Onorato7e4ed992009-12-03 13:10:49 -0800412 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700413 }
Romain Guycbb89e42009-06-08 15:52:54 -0700414
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700415 @Override
416 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400417 // Flag the loader to stop early before switching
418 mModel.stopLoader();
Romain Guycbb89e42009-06-08 15:52:54 -0700419
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700420 if (PROFILE_ROTATE) {
421 android.os.Debug.startMethodTracing("/sdcard/launcher-rotate");
422 }
423 return null;
424 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700425
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800426 private boolean acceptFilter() {
427 final InputMethodManager inputManager = (InputMethodManager)
428 getSystemService(Context.INPUT_METHOD_SERVICE);
429 return !inputManager.isFullscreenMode();
430 }
431
432 @Override
433 public boolean onKeyDown(int keyCode, KeyEvent event) {
434 boolean handled = super.onKeyDown(keyCode, event);
435 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
436 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
437 keyCode, event);
438 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700439 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700440 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700441 // showSearchDialog()
442 // If there are multiple keystrokes before the search dialog takes focus,
443 // onSearchRequested() will be called for every keystroke,
444 // but it is idempotent, so it's fine.
445 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 }
447 }
448
449 return handled;
450 }
451
Karl Rosaen138a0412009-04-23 19:00:21 -0700452 private String getTypedText() {
453 return mDefaultKeySsb.toString();
454 }
455
456 private void clearTypedText() {
457 mDefaultKeySsb.clear();
458 mDefaultKeySsb.clearSpans();
459 Selection.setSelection(mDefaultKeySsb, 0);
460 }
461
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 /**
463 * Restores the previous state, if it exists.
464 *
465 * @param savedState The previous state.
466 */
467 private void restoreState(Bundle savedState) {
468 if (savedState == null) {
469 return;
470 }
471
Joe Onorato3a8820b2009-11-10 15:06:42 -0800472 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
473 if (allApps) {
474 showAllApps(false);
475 }
476
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800477 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
478 if (currentScreen > -1) {
479 mWorkspace.setCurrentScreen(currentScreen);
480 }
481
482 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
483 if (addScreen > -1) {
484 mAddItemCellInfo = new CellLayout.CellInfo();
485 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
486 addItemCellInfo.valid = true;
487 addItemCellInfo.screen = addScreen;
488 addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
489 addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
490 addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
491 addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
492 addItemCellInfo.findVacantCellsFromOccupied(
493 savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS),
494 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X),
495 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y));
496 mRestoring = true;
497 }
498
499 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
500 if (renameFolder) {
501 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400502 mFolderInfo = mModel.getFolderById(this, mFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800503 mRestoring = true;
504 }
505 }
506
507 /**
508 * Finds all the views we need and configure them properly.
509 */
510 private void setupViews() {
Joe Onorato00acb122009-08-04 16:04:30 -0400511 DragController dragController = mDragController;
512
Romain Guyb1b69f52009-08-10 15:10:15 -0700513 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400514 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800515
Joe Onorato7c312c12009-08-13 21:36:53 -0700516 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700517 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700518 mAllAppsGrid.setDragController(dragController);
Joe Onorato85a02a82009-09-08 12:34:22 -0700519 mAllAppsGrid.setWillNotDraw(false); // We don't want a hole punched in our window.
Mike Cleronb6082fa02009-10-19 17:03:36 -0700520 // Manage focusability manually since this thing is always visible
521 mAllAppsGrid.setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700522
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800523 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
524 final Workspace workspace = mWorkspace;
525
Joe Onorato7c312c12009-08-13 21:36:53 -0700526 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
527 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800528
Joe Onorato7c312c12009-08-13 21:36:53 -0700529 mHandleView = (HandleView) findViewById(R.id.all_apps_button);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700530 mHandleView.setLauncher(this);
Joe Onorato7404ee42009-07-31 11:54:44 -0700531 mHandleView.setOnClickListener(this);
Romain Guyf8e6a802009-12-07 17:48:02 -0800532 mHandleView.setOnLongClickListener(this);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800533
534 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
535 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
536
537 Drawable previous = mPreviousView.getDrawable();
538 Drawable next = mNextView.getDrawable();
Romain Guy8a73c512009-11-09 19:19:59 -0800539 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800540
Joe Onorato0d44e942009-11-16 18:20:51 -0800541 mPreviousView.setHapticFeedbackEnabled(false);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800542 mPreviousView.setOnLongClickListener(this);
Joe Onorato0d44e942009-11-16 18:20:51 -0800543 mNextView.setHapticFeedbackEnabled(false);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800544 mNextView.setOnLongClickListener(this);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800545
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800546 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400547 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800548 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800549
550 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400551 deleteZone.setDragController(dragController);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700552 deleteZone.setHandle(mHandleView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800553
Joe Onorato00acb122009-08-04 16:04:30 -0400554 dragController.setDragScoller(workspace);
555 dragController.setDragListener(deleteZone);
556 dragController.setScrollView(dragLayer);
Jason Samsfd22dac2009-09-20 17:24:16 -0700557
Joe Onorato00acb122009-08-04 16:04:30 -0400558 // The order here is bottom to top.
559 dragController.addDropTarget(workspace);
560 dragController.addDropTarget(deleteZone);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 }
562
Romain Guy8a73c512009-11-09 19:19:59 -0800563 @SuppressWarnings({"UnusedDeclaration"})
564 public void previousScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800565 if (!isAllAppsVisible()) {
566 mWorkspace.scrollLeft();
567 }
Romain Guy8a73c512009-11-09 19:19:59 -0800568 }
569
570 @SuppressWarnings({"UnusedDeclaration"})
571 public void nextScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800572 if (!isAllAppsVisible()) {
573 mWorkspace.scrollRight();
574 }
Romain Guy8a73c512009-11-09 19:19:59 -0800575 }
576
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577 /**
578 * Creates a view representing a shortcut.
579 *
580 * @param info The data structure describing the shortcut.
581 *
582 * @return A View inflated from R.layout.application.
583 */
584 View createShortcut(ApplicationInfo info) {
585 return createShortcut(R.layout.application,
586 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
587 }
588
589 /**
590 * Creates a view representing a shortcut inflated from the specified resource.
591 *
592 * @param layoutResId The id of the XML layout used to create the shortcut.
593 * @param parent The group the shortcut belongs to.
594 * @param info The data structure describing the shortcut.
595 *
596 * @return A View inflated from layoutResId.
597 */
598 View createShortcut(int layoutResId, ViewGroup parent, ApplicationInfo info) {
599 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
600
Joe Onorato5162ea92009-09-03 09:39:42 -0700601 if (info.icon == null) {
602 info.icon = AppInfoCache.getIconDrawable(getPackageManager(), info);
603 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800604 if (!info.filtered) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700605 info.icon = Utilities.createIconThumbnail(info.icon, this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800606 info.filtered = true;
607 }
608
609 favorite.setCompoundDrawablesWithIntrinsicBounds(null, info.icon, null, null);
610 favorite.setText(info.title);
611 favorite.setTag(info);
612 favorite.setOnClickListener(this);
613
614 return favorite;
615 }
616
617 /**
618 * Add an application shortcut to the workspace.
619 *
620 * @param data The intent describing the application.
621 * @param cellInfo The position on screen where to create the shortcut.
622 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400623 void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800624 cellInfo.screen = mWorkspace.getCurrentScreen();
625 if (!findSingleSlot(cellInfo)) return;
626
Romain Guy73b979d2009-06-09 12:57:21 -0700627 final ApplicationInfo info = infoFromApplicationIntent(context, data);
628 if (info != null) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400629 mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked());
Romain Guy73b979d2009-06-09 12:57:21 -0700630 }
631 }
632
633 private static ApplicationInfo infoFromApplicationIntent(Context context, Intent data) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800634 ComponentName component = data.getComponent();
635 PackageManager packageManager = context.getPackageManager();
636 ActivityInfo activityInfo = null;
637 try {
638 activityInfo = packageManager.getActivityInfo(component, 0 /* no flags */);
639 } catch (NameNotFoundException e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800640 Log.e(TAG, "Couldn't find ActivityInfo for selected application", e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800641 }
Romain Guycbb89e42009-06-08 15:52:54 -0700642
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800643 if (activityInfo != null) {
644 ApplicationInfo itemInfo = new ApplicationInfo();
Romain Guycbb89e42009-06-08 15:52:54 -0700645
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800646 itemInfo.title = activityInfo.loadLabel(packageManager);
647 if (itemInfo.title == null) {
648 itemInfo.title = activityInfo.name;
649 }
Romain Guycbb89e42009-06-08 15:52:54 -0700650
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800651 itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK |
652 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
653 itemInfo.icon = activityInfo.loadIcon(packageManager);
654 itemInfo.container = ItemInfo.NO_ID;
655
Romain Guy73b979d2009-06-09 12:57:21 -0700656 return itemInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800657 }
Romain Guy73b979d2009-06-09 12:57:21 -0700658
659 return null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800660 }
Romain Guycbb89e42009-06-08 15:52:54 -0700661
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 /**
663 * Add a shortcut to the workspace.
664 *
665 * @param data The intent describing the shortcut.
666 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800667 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400668 private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800669 cellInfo.screen = mWorkspace.getCurrentScreen();
670 if (!findSingleSlot(cellInfo)) return;
Romain Guycbb89e42009-06-08 15:52:54 -0700671
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 final ApplicationInfo info = addShortcut(this, data, cellInfo, false);
673
674 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 final View view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400676 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
677 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 }
679 }
680
Romain Guycbb89e42009-06-08 15:52:54 -0700681
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700683 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 *
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700685 * @param data The intent describing the appWidgetId.
686 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800687 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400688 private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 Bundle extras = data.getExtras();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700690 int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Romain Guycbb89e42009-06-08 15:52:54 -0700691
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800692 if (LOGD) Log.d(TAG, "dumping extras content=" + extras.toString());
Romain Guycbb89e42009-06-08 15:52:54 -0700693
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700694 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700695
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700696 // Calculate the grid spans needed to fit this widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800697 CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700698 int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
Romain Guycbb89e42009-06-08 15:52:54 -0700699
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800700 // Try finding open space on Launcher screen
701 final int[] xy = mCellCoordinates;
Romain Guy18042c82009-11-06 11:44:55 -0800702 if (!findSlot(cellInfo, xy, spans[0], spans[1])) {
703 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
704 return;
705 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700707 // Build Launcher-specific widget info and save to database
708 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800709 launcherInfo.spanX = spans[0];
710 launcherInfo.spanY = spans[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700711
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800712 LauncherModel.addItemToDatabase(this, launcherInfo,
713 LauncherSettings.Favorites.CONTAINER_DESKTOP,
714 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
715
716 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400717 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700718
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800719 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700720 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700721
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700722 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800723 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700724
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800725 mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400726 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800727 }
728 }
Romain Guycbb89e42009-06-08 15:52:54 -0700729
Joe Onorato9c1289c2009-08-17 11:03:03 -0400730 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
731 mDesktopItems.remove(launcherInfo);
732 launcherInfo.hostView = null;
733 }
734
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700735 public LauncherAppWidgetHost getAppWidgetHost() {
736 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800737 }
Romain Guycbb89e42009-06-08 15:52:54 -0700738
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800739 static ApplicationInfo addShortcut(Context context, Intent data,
740 CellLayout.CellInfo cellInfo, boolean notify) {
741
Romain Guy73b979d2009-06-09 12:57:21 -0700742 final ApplicationInfo info = infoFromShortcutIntent(context, data);
743 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
744 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
745
746 return info;
747 }
748
749 private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
751 String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
752 Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
753
754 Drawable icon = null;
755 boolean filtered = false;
756 boolean customIcon = false;
Romain Guy73b979d2009-06-09 12:57:21 -0700757 ShortcutIconResource iconResource = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758
759 if (bitmap != null) {
760 icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
761 filtered = true;
762 customIcon = true;
763 } else {
764 Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
Romain Guy73b979d2009-06-09 12:57:21 -0700765 if (extra != null && extra instanceof ShortcutIconResource) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800766 try {
Romain Guy73b979d2009-06-09 12:57:21 -0700767 iconResource = (ShortcutIconResource) extra;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800768 final PackageManager packageManager = context.getPackageManager();
769 Resources resources = packageManager.getResourcesForApplication(
770 iconResource.packageName);
771 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
772 icon = resources.getDrawable(id);
773 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800774 Log.w(TAG, "Could not load shortcut icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800775 }
776 }
777 }
778
779 if (icon == null) {
780 icon = context.getPackageManager().getDefaultActivityIcon();
781 }
782
783 final ApplicationInfo info = new ApplicationInfo();
784 info.icon = icon;
785 info.filtered = filtered;
786 info.title = name;
787 info.intent = intent;
788 info.customIcon = customIcon;
789 info.iconResource = iconResource;
790
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800791 return info;
792 }
793
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800794 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800795 getWindow().closeAllPanels();
796
797 try {
798 dismissDialog(DIALOG_CREATE_SHORTCUT);
799 // Unlock the workspace if the dialog was showing
800 } catch (Exception e) {
801 // An exception is thrown if the dialog is not visible, which is fine
802 }
803
804 try {
805 dismissDialog(DIALOG_RENAME_FOLDER);
806 // Unlock the workspace if the dialog was showing
807 } catch (Exception e) {
808 // An exception is thrown if the dialog is not visible, which is fine
809 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -0800810
811 // Whatever we were doing is hereby canceled.
812 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800813 }
814
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800815 @Override
816 protected void onNewIntent(Intent intent) {
817 super.onNewIntent(intent);
818
819 // Close the menu
820 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -0800821 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800822 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -0700823
Joe Onorato14f122b2009-11-19 14:06:36 -0800824 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
825 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
826 boolean allAppsVisible = isAllAppsVisible();
Joe Onorato3a8820b2009-11-10 15:06:42 -0800827 if (!mWorkspace.isDefaultScreenShowing()) {
Joe Onorato14f122b2009-11-19 14:06:36 -0800828 mWorkspace.moveToDefaultScreen(alreadyOnHome && !allAppsVisible);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800829 }
Joe Onorato14f122b2009-11-19 14:06:36 -0800830 closeAllApps(alreadyOnHome && allAppsVisible);
Romain Guy1dd3a072009-07-16 13:21:01 -0700831
Joe Onorato3a8820b2009-11-10 15:06:42 -0800832 final View v = getWindow().peekDecorView();
833 if (v != null && v.getWindowToken() != null) {
834 InputMethodManager imm = (InputMethodManager)getSystemService(
835 INPUT_METHOD_SERVICE);
836 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800837 }
838 }
839 }
840
841 @Override
842 protected void onRestoreInstanceState(Bundle savedInstanceState) {
843 // Do not call super here
844 mSavedInstanceState = savedInstanceState;
845 }
846
847 @Override
848 protected void onSaveInstanceState(Bundle outState) {
849 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen());
850
851 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
852 if (folders.size() > 0) {
853 final int count = folders.size();
854 long[] ids = new long[count];
855 for (int i = 0; i < count; i++) {
856 final FolderInfo info = folders.get(i).getInfo();
857 ids[i] = info.id;
858 }
859 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
860 } else {
861 super.onSaveInstanceState(outState);
862 }
863
Joe Onoratofb0ca672009-09-14 17:55:46 -0400864 // TODO should not do this if the drawer is currently closing.
Joe Onorato3a8820b2009-11-10 15:06:42 -0800865 if (isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800866 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -0700867 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868
869 if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
870 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
871 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);
872
873 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
874 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
875 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
876 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
877 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
878 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
879 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
880 outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS,
881 layout.getOccupiedCells());
882 }
883
884 if (mFolderInfo != null && mWaitingForResult) {
885 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
886 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
887 }
888 }
889
890 @Override
891 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800892 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -0700893
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800894 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700895 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800897 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 }
899
900 TextKeyListener.getInstance().release();
901
Joe Onorato9c1289c2009-08-17 11:03:03 -0400902 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800903
Joe Onorato9c1289c2009-08-17 11:03:03 -0400904 unbindDesktopItems();
905 AppInfoCache.unbindDrawables();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800906
907 getContentResolver().unregisterContentObserver(mWidgetObserver);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800908
909 dismissPreview(mPreviousView);
Romain Guya6abce82009-11-10 02:54:41 -0800910 dismissPreview(mNextView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800911 }
912
913 @Override
914 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -0700915 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916 super.startActivityForResult(intent, requestCode);
917 }
918
919 @Override
Romain Guycbb89e42009-06-08 15:52:54 -0700920 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800921 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700922
Joe Onorato7bb17492009-09-24 17:51:01 -0700923 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -0700924
Karl Rosaen138a0412009-04-23 19:00:21 -0700925 if (initialQuery == null) {
926 // Use any text typed in the launcher as the initial query
927 initialQuery = getTypedText();
928 clearTypedText();
929 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800930 if (appSearchData == null) {
931 appSearchData = new Bundle();
932 appSearchData.putString(SearchManager.SOURCE, "launcher-search");
933 }
Romain Guycbb89e42009-06-08 15:52:54 -0700934
Karl Rosaen138a0412009-04-23 19:00:21 -0700935 final SearchManager searchManager =
936 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -0700937 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -0700938 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800939 }
940
941 @Override
942 public boolean onCreateOptionsMenu(Menu menu) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400943 if (isWorkspaceLocked()) {
944 return false;
945 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800946
947 super.onCreateOptionsMenu(menu);
948 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
949 .setIcon(android.R.drawable.ic_menu_add)
950 .setAlphabeticShortcut('A');
951 menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
952 .setIcon(android.R.drawable.ic_menu_gallery)
953 .setAlphabeticShortcut('W');
954 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
955 .setIcon(android.R.drawable.ic_search_category_default)
956 .setAlphabeticShortcut(SearchManager.MENU_KEY);
957 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
958 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
959 .setAlphabeticShortcut('N');
960
961 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -0700962 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
963 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800964
965 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
966 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
967 .setIntent(settings);
968
969 return true;
970 }
971
972 @Override
973 public boolean onPrepareOptionsMenu(Menu menu) {
974 super.onPrepareOptionsMenu(menu);
975
976 mMenuAddInfo = mWorkspace.findAllVacantCells(null);
977 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
978
979 return true;
980 }
981
982 @Override
983 public boolean onOptionsItemSelected(MenuItem item) {
984 switch (item.getItemId()) {
985 case MENU_ADD:
986 addItems();
987 return true;
988 case MENU_WALLPAPER_SETTINGS:
989 startWallpaper();
990 return true;
991 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700992 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800993 return true;
994 case MENU_NOTIFICATIONS:
995 showNotifications();
996 return true;
997 }
998
999 return super.onOptionsItemSelected(item);
1000 }
Romain Guycbb89e42009-06-08 15:52:54 -07001001
Karl Rosaen138a0412009-04-23 19:00:21 -07001002 /**
1003 * Indicates that we want global search for this activity by setting the globalSearch
1004 * argument for {@link #startSearch} to true.
1005 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001006
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001007 @Override
1008 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001009 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001010 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001011 }
1012
Joe Onorato9c1289c2009-08-17 11:03:03 -04001013 public boolean isWorkspaceLocked() {
1014 return mWorkspaceLoading || mWaitingForResult;
1015 }
1016
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001017 private void addItems() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001018 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001019 showAddDialog(mMenuAddInfo);
1020 }
1021
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001022 void addAppWidget(Intent data) {
1023 // TODO: catch bad widget exception when sent
1024 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001025 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001026
Bjorn Bringert7984c942009-12-09 15:38:25 +00001027 if (appWidget.configure != null) {
1028 // Launch over to configure widget, if needed
1029 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1030 intent.setComponent(appWidget.configure);
1031 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1032
1033 startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001034 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001035 // Otherwise just add it
1036 onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 }
1038 }
Romain Guycbb89e42009-06-08 15:52:54 -07001039
Romain Guy73b979d2009-06-09 12:57:21 -07001040 void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001041 // Handle case where user selected "Applications"
1042 String applicationName = getResources().getString(R.string.group_applications);
1043 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001044
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001045 if (applicationName != null && applicationName.equals(shortcutName)) {
1046 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1047 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001048
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001049 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1050 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Romain Guy73b979d2009-06-09 12:57:21 -07001051 startActivityForResult(pickIntent, requestCodeApplication);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001052 } else {
Romain Guy73b979d2009-06-09 12:57:21 -07001053 startActivityForResult(intent, requestCodeShortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001054 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 }
1056
1057 void addLiveFolder(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001058 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001059 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001060 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001061
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001062 if (folderName != null && folderName.equals(shortcutName)) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001063 addFolder();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001064 } else {
1065 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1066 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001067 }
1068
Joe Onorato9c1289c2009-08-17 11:03:03 -04001069 void addFolder() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001070 UserFolderInfo folderInfo = new UserFolderInfo();
1071 folderInfo.title = getText(R.string.folder_name);
1072
1073 CellLayout.CellInfo cellInfo = mAddItemCellInfo;
1074 cellInfo.screen = mWorkspace.getCurrentScreen();
1075 if (!findSingleSlot(cellInfo)) return;
1076
1077 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001078 LauncherModel.addItemToDatabase(this, folderInfo,
1079 LauncherSettings.Favorites.CONTAINER_DESKTOP,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001081 mFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082
1083 // Create the view
1084 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1085 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
1086 mWorkspace.addInCurrentScreen(newFolder,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001087 cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001088 }
Romain Guycbb89e42009-06-08 15:52:54 -07001089
Joe Onorato9c1289c2009-08-17 11:03:03 -04001090 void removeFolder(FolderInfo folder) {
1091 mFolders.remove(folder.id);
1092 }
1093
1094 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001095 cellInfo.screen = mWorkspace.getCurrentScreen();
1096 if (!findSingleSlot(cellInfo)) return;
1097
1098 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
1099
1100 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
1102 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001103 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
1104 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105 }
1106 }
1107
1108 static LiveFolderInfo addLiveFolder(Context context, Intent data,
1109 CellLayout.CellInfo cellInfo, boolean notify) {
1110
1111 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1112 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1113
1114 Drawable icon = null;
1115 boolean filtered = false;
1116 Intent.ShortcutIconResource iconResource = null;
1117
1118 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1119 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1120 try {
1121 iconResource = (Intent.ShortcutIconResource) extra;
1122 final PackageManager packageManager = context.getPackageManager();
1123 Resources resources = packageManager.getResourcesForApplication(
1124 iconResource.packageName);
1125 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1126 icon = resources.getDrawable(id);
1127 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001128 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001129 }
1130 }
1131
1132 if (icon == null) {
1133 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1134 }
1135
1136 final LiveFolderInfo info = new LiveFolderInfo();
1137 info.icon = icon;
1138 info.filtered = filtered;
1139 info.title = name;
1140 info.iconResource = iconResource;
1141 info.uri = data.getData();
1142 info.baseIntent = baseIntent;
1143 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1144 LiveFolders.DISPLAY_MODE_GRID);
1145
1146 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1147 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001148 mFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001149
1150 return info;
1151 }
1152
1153 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
1154 final int[] xy = new int[2];
1155 if (findSlot(cellInfo, xy, 1, 1)) {
1156 cellInfo.cellX = xy[0];
1157 cellInfo.cellY = xy[1];
1158 return true;
1159 }
1160 return false;
1161 }
1162
1163 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
1164 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1165 boolean[] occupied = mSavedState != null ?
1166 mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null;
1167 cellInfo = mWorkspace.findAllVacantCells(occupied);
1168 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1169 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1170 return false;
1171 }
1172 }
1173 return true;
1174 }
1175
1176 private void showNotifications() {
1177 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1178 if (statusBar != null) {
1179 statusBar.expand();
1180 }
1181 }
1182
1183 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001184 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001185 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001186 Intent chooser = Intent.createChooser(pickWallpaper,
1187 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001188 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1189 // Removed in Eclair MR1
1190// WallpaperManager wm = (WallpaperManager)
1191// getSystemService(Context.WALLPAPER_SERVICE);
1192// WallpaperInfo wi = wm.getWallpaperInfo();
1193// if (wi != null && wi.getSettingsActivity() != null) {
1194// LabeledIntent li = new LabeledIntent(getPackageName(),
1195// R.string.configure_wallpaper, 0);
1196// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1197// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1198// }
Mike Clerona0618e42009-10-22 13:55:21 -07001199 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 }
1201
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001202 /**
1203 * Registers various content observers. The current implementation registers
1204 * only a favorites observer to keep track of the favorites applications.
1205 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001206 private void registerContentObservers() {
1207 ContentResolver resolver = getContentResolver();
1208 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1209 true, mWidgetObserver);
1210 }
1211
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 @Override
1213 public boolean dispatchKeyEvent(KeyEvent event) {
1214 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1215 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001217 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001218 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001219 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001220 dumpState();
1221 return true;
1222 }
1223 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001224 }
1225 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1226 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001227 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 return true;
1229 }
1230 }
1231
1232 return super.dispatchKeyEvent(event);
1233 }
1234
Joe Onorato88ec0992009-11-19 13:16:06 -08001235 @Override
1236 public void onBackPressed() {
1237 if (isAllAppsVisible()) {
1238 closeAllApps(true);
1239 } else {
1240 closeFolder();
1241 }
1242 dismissPreview(mPreviousView);
1243 dismissPreview(mNextView);
1244 }
1245
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001246 private void closeFolder() {
1247 Folder folder = mWorkspace.getOpenFolder();
1248 if (folder != null) {
1249 closeFolder(folder);
1250 }
1251 }
1252
1253 void closeFolder(Folder folder) {
1254 folder.getInfo().opened = false;
1255 ViewGroup parent = (ViewGroup) folder.getParent();
1256 if (parent != null) {
1257 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001258 if (folder instanceof DropTarget) {
1259 // Live folders aren't DropTargets.
1260 mDragController.removeDropTarget((DropTarget)folder);
1261 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001262 }
1263 folder.onClose();
1264 }
1265
1266 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001267 * Re-listen when widgets are reset.
1268 */
1269 private void onAppWidgetReset() {
1270 mAppWidgetHost.startListening();
1271 }
1272
1273 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001274 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1275 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001276 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001277 private void unbindDesktopItems() {
1278 for (ItemInfo item: mDesktopItems) {
1279 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001280 }
1281 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001282
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001283 /**
1284 * Launches the intent referred by the clicked shortcut.
1285 *
1286 * @param v The view representing the clicked shortcut.
1287 */
1288 public void onClick(View v) {
1289 Object tag = v.getTag();
1290 if (tag instanceof ApplicationInfo) {
1291 // Open shortcut
1292 final Intent intent = ((ApplicationInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001293 int[] pos = new int[2];
1294 v.getLocationOnScreen(pos);
1295 intent.setSourceBounds(
1296 new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001297 startActivitySafely(intent);
1298 } else if (tag instanceof FolderInfo) {
1299 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001300 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001301 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001302 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001303 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001304 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001305 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001306 }
1307 }
1308
1309 void startActivitySafely(Intent intent) {
1310 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1311 try {
1312 startActivity(intent);
1313 } catch (ActivityNotFoundException e) {
1314 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1315 } catch (SecurityException e) {
1316 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001317 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1319 "or use the exported attribute for this activity.", e);
1320 }
1321 }
1322
1323 private void handleFolderClick(FolderInfo folderInfo) {
1324 if (!folderInfo.opened) {
1325 // Close any open folder
1326 closeFolder();
1327 // Open the requested folder
1328 openFolder(folderInfo);
1329 } else {
1330 // Find the open folder...
1331 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1332 int folderScreen;
1333 if (openFolder != null) {
1334 folderScreen = mWorkspace.getScreenForView(openFolder);
1335 // .. and close it
1336 closeFolder(openFolder);
1337 if (folderScreen != mWorkspace.getCurrentScreen()) {
1338 // Close any folder open on the current screen
1339 closeFolder();
1340 // Pull the folder onto this screen
1341 openFolder(folderInfo);
1342 }
1343 }
1344 }
1345 }
1346
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001347 /**
1348 * Opens the user fodler described by the specified tag. The opening of the folder
1349 * is animated relative to the specified View. If the View is null, no animation
1350 * is played.
1351 *
1352 * @param folderInfo The FolderInfo describing the folder to open.
1353 */
1354 private void openFolder(FolderInfo folderInfo) {
1355 Folder openFolder;
1356
1357 if (folderInfo instanceof UserFolderInfo) {
1358 openFolder = UserFolder.fromXml(this);
1359 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001360 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 } else {
1362 return;
1363 }
1364
Joe Onorato00acb122009-08-04 16:04:30 -04001365 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 openFolder.setLauncher(this);
1367
1368 openFolder.bind(folderInfo);
1369 folderInfo.opened = true;
1370
1371 mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4);
1372 openFolder.onOpen();
1373 }
1374
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001375 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001376 switch (v.getId()) {
1377 case R.id.previous_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001378 if (!isAllAppsVisible()) {
1379 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1380 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001381 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001382 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001383 return true;
1384 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001385 if (!isAllAppsVisible()) {
1386 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1387 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001388 showPreviews(v);
1389 }
1390 return true;
1391 case R.id.all_apps_button:
1392 if (!isAllAppsVisible()) {
1393 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1394 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1395 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001396 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001397 return true;
1398 }
1399
Joe Onorato9c1289c2009-08-17 11:03:03 -04001400 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001401 return false;
1402 }
1403
1404 if (!(v instanceof CellLayout)) {
1405 v = (View) v.getParent();
1406 }
1407
1408 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
1409
1410 // This happens when long clicking an item with the dpad/trackball
1411 if (cellInfo == null) {
1412 return true;
1413 }
1414
1415 if (mWorkspace.allowLongPress()) {
1416 if (cellInfo.cell == null) {
1417 if (cellInfo.valid) {
1418 // User long pressed on empty space
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001419 mWorkspace.setAllowLongPress(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 showAddDialog(cellInfo);
1421 }
1422 } else {
1423 if (!(cellInfo.cell instanceof Folder)) {
1424 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001425 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1426 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427 mWorkspace.startDrag(cellInfo);
1428 }
1429 }
1430 }
1431 return true;
1432 }
1433
Romain Guye6b8e2f2009-11-10 11:56:55 -08001434 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001435 private void dismissPreview(final View v) {
1436 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001437 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001438 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1439 public void onDismiss() {
1440 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1441 int count = group.getChildCount();
1442 for (int i = 0; i < count; i++) {
1443 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1444 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001445 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1446 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1447
1448 v.setTag(R.id.workspace, null);
1449 v.setTag(R.id.icon, null);
1450 window.setOnDismissListener(null);
1451 }
1452 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001453 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001454 }
1455 v.setTag(null);
1456 }
1457
Romain Guyf8e6a802009-12-07 17:48:02 -08001458 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001459 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001460 }
1461
Romain Guya6abce82009-11-10 02:54:41 -08001462 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001463 final Resources resources = getResources();
1464 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001465
Romain Guya6abce82009-11-10 02:54:41 -08001466 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Romain Guy9d31e9f2009-11-11 18:54:28 -08001467
1468 float max = workspace.getChildCount();
Romain Guye6b8e2f2009-11-10 11:56:55 -08001469
Romain Guyf8e6a802009-12-07 17:48:02 -08001470 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001471 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001472 int extraW = (int) ((r.left + r.right) * max);
1473 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001474
1475 int aW = cell.getWidth() - extraW;
1476 float w = aW / max;
1477
1478 int width = cell.getWidth();
1479 int height = cell.getHeight();
1480 int x = cell.getLeftPadding();
1481 int y = cell.getTopPadding();
1482 width -= (x + cell.getRightPadding());
1483 height -= (y + cell.getBottomPadding());
1484
1485 float scale = w / width;
1486
1487 int count = end - start;
1488
1489 final float sWidth = width * scale;
1490 float sHeight = height * scale;
1491
Romain Guye6b8e2f2009-11-10 11:56:55 -08001492 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08001493
Romain Guye6b8e2f2009-11-10 11:56:55 -08001494 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
1495 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08001496
1497 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08001498 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08001499 cell = (CellLayout) workspace.getChildAt(i);
1500
Romain Guyf8e6a802009-12-07 17:48:02 -08001501 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08001502 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08001503
1504 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08001505 c.scale(scale, scale);
1506 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
1507 cell.dispatchDraw(c);
Romain Guya6abce82009-11-10 02:54:41 -08001508
Romain Guy9d31e9f2009-11-11 18:54:28 -08001509 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08001510 image.setImageBitmap(bitmap);
1511 image.setTag(i);
1512 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08001513 image.setOnFocusChangeListener(handler);
1514 image.setFocusable(true);
1515 if (i == mWorkspace.getCurrentScreen()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08001516
1517 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08001518 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
1519
1520 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08001521 }
Romain Guyf8e6a802009-12-07 17:48:02 -08001522
1523 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001524 p.setContentView(preview);
1525 p.setWidth((int) (sWidth * count + extraW));
1526 p.setHeight((int) (sHeight + extraH));
1527 p.setAnimationStyle(R.style.AnimationPreview);
1528 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08001529 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08001530 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08001531 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08001532
Romain Guye6b8e2f2009-11-10 11:56:55 -08001533 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
1534 public void onDismiss() {
1535 dismissPreview(anchor);
1536 }
1537 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001538
1539 anchor.setTag(p);
1540 anchor.setTag(R.id.workspace, preview);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001541 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08001542 }
1543
Romain Guy9d31e9f2009-11-11 18:54:28 -08001544 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08001545 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08001546
Romain Guye6b8e2f2009-11-10 11:56:55 -08001547 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08001548 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08001549 }
1550
1551 public void onClick(View v) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08001552 mWorkspace.snapToScreen((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08001553 v.post(this);
1554 }
1555
1556 public void run() {
1557 dismissPreview(mAnchor);
1558 }
1559
1560 public void onFocusChange(View v, boolean hasFocus) {
1561 if (hasFocus) {
Romain Guye47f55c2009-11-11 19:21:22 -08001562 mWorkspace.snapToScreen((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08001563 }
Romain Guya6abce82009-11-10 02:54:41 -08001564 }
1565 }
1566
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567 Workspace getWorkspace() {
1568 return mWorkspace;
1569 }
1570
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001571 @Override
1572 protected Dialog onCreateDialog(int id) {
1573 switch (id) {
1574 case DIALOG_CREATE_SHORTCUT:
1575 return new CreateShortcut().createDialog();
1576 case DIALOG_RENAME_FOLDER:
1577 return new RenameFolder().createDialog();
1578 }
1579
1580 return super.onCreateDialog(id);
1581 }
1582
1583 @Override
1584 protected void onPrepareDialog(int id, Dialog dialog) {
1585 switch (id) {
1586 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587 break;
1588 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001589 if (mFolderInfo != null) {
1590 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1591 final CharSequence text = mFolderInfo.title;
1592 input.setText(text);
1593 input.setSelection(0, text.length());
1594 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 break;
1596 }
1597 }
1598
1599 void showRenameDialog(FolderInfo info) {
1600 mFolderInfo = info;
1601 mWaitingForResult = true;
1602 showDialog(DIALOG_RENAME_FOLDER);
1603 }
1604
1605 private void showAddDialog(CellLayout.CellInfo cellInfo) {
1606 mAddItemCellInfo = cellInfo;
1607 mWaitingForResult = true;
1608 showDialog(DIALOG_CREATE_SHORTCUT);
1609 }
1610
Romain Guy73b979d2009-06-09 12:57:21 -07001611 private void pickShortcut(int requestCode, int title) {
1612 Bundle bundle = new Bundle();
1613
1614 ArrayList<String> shortcutNames = new ArrayList<String>();
1615 shortcutNames.add(getString(R.string.group_applications));
1616 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
1617
1618 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
1619 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1620 R.drawable.ic_launcher_application));
1621 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1622
1623 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1624 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
1625 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title));
1626 pickIntent.putExtras(bundle);
1627
1628 startActivityForResult(pickIntent, requestCode);
1629 }
1630
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001631 private class RenameFolder {
1632 private EditText mInput;
1633
1634 Dialog createDialog() {
1635 mWaitingForResult = true;
1636 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1637 mInput = (EditText) layout.findViewById(R.id.folder_name);
1638
1639 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1640 builder.setIcon(0);
1641 builder.setTitle(getString(R.string.rename_folder_title));
1642 builder.setCancelable(true);
1643 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1644 public void onCancel(DialogInterface dialog) {
1645 cleanup();
1646 }
1647 });
1648 builder.setNegativeButton(getString(R.string.cancel_action),
1649 new Dialog.OnClickListener() {
1650 public void onClick(DialogInterface dialog, int which) {
1651 cleanup();
1652 }
1653 }
1654 );
1655 builder.setPositiveButton(getString(R.string.rename_action),
1656 new Dialog.OnClickListener() {
1657 public void onClick(DialogInterface dialog, int which) {
1658 changeFolderName();
1659 }
1660 }
1661 );
1662 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001663
1664 final AlertDialog dialog = builder.create();
1665 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1666 public void onShow(DialogInterface dialog) {
Joe Onoratod753b422009-11-08 13:31:11 -05001667 mInput.requestFocus();
1668 InputMethodManager inputManager = (InputMethodManager)
1669 getSystemService(Context.INPUT_METHOD_SERVICE);
1670 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001671 }
1672 });
1673
1674 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001675 }
1676
1677 private void changeFolderName() {
1678 final String name = mInput.getText().toString();
1679 if (!TextUtils.isEmpty(name)) {
1680 // Make sure we have the right folder info
Joe Onorato9c1289c2009-08-17 11:03:03 -04001681 mFolderInfo = mFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001682 mFolderInfo.title = name;
1683 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1684
Joe Onorato9c1289c2009-08-17 11:03:03 -04001685 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001686 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001687 mModel.setWorkspaceDirty();
1688 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 } else {
1690 final FolderIcon folderIcon = (FolderIcon)
1691 mWorkspace.getViewForTag(mFolderInfo);
1692 if (folderIcon != null) {
1693 folderIcon.setText(name);
1694 getWorkspace().requestLayout();
1695 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001696 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001697 mModel.setWorkspaceDirty();
1698 mWorkspaceLoading = true;
1699 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700 }
1701 }
1702 }
1703 cleanup();
1704 }
1705
1706 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 dismissDialog(DIALOG_RENAME_FOLDER);
1708 mWaitingForResult = false;
1709 mFolderInfo = null;
1710 }
1711 }
1712
Joe Onoratofb0ca672009-09-14 17:55:46 -04001713 boolean isAllAppsVisible() {
Joe Onorato7bb17492009-09-24 17:51:01 -07001714 return mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04001715 }
1716
Joe Onorato3a8820b2009-11-10 15:06:42 -08001717 void showAllApps(boolean animated) {
1718 mAllAppsGrid.zoom(1.0f, animated);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001719
Mike Cleronb6082fa02009-10-19 17:03:36 -07001720 mAllAppsGrid.setFocusable(true);
Mike Clerona0618e42009-10-22 13:55:21 -07001721 mAllAppsGrid.requestFocus();
Mike Cleronb6082fa02009-10-19 17:03:36 -07001722
Joe Onorato7c312c12009-08-13 21:36:53 -07001723 // TODO: fade these two too
1724 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04001725 }
1726
Joe Onoratob2061212009-11-24 16:13:54 -05001727 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08001728 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05001729 * - Home from workspace
1730 * - from center screen
1731 * - from other screens
1732 * - Home from all apps
1733 * - Back from all apps
1734 * - Launch app from workspace and quit
1735 * - with back
1736 * - with home
1737 * - Launch app from all apps and quit
1738 * - with back
1739 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08001740 * - Go to a screen that's not the default, then all
1741 * apps, and launch and app, and go back
1742 * - with back
1743 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05001744 * - On workspace, long press power and go back
1745 * - with back
1746 * - with home
1747 * - On all apps, long press power and go back
1748 * - with back
1749 * - with home
1750 * - On workspace, power off
1751 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08001752 * - Launch an app and turn off the screen while in that app
1753 * - Go back with home key
1754 * - Go back with back key
1755 * - From all apps
1756 * - From workspace
Joe Onoratob2061212009-11-24 16:13:54 -05001757 */
Joe Onorato7bb17492009-09-24 17:51:01 -07001758 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001759 if (mAllAppsGrid.isVisible()) {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001760 mAllAppsGrid.zoom(0.0f, animated);
Mike Cleronb6082fa02009-10-19 17:03:36 -07001761 mAllAppsGrid.setFocusable(false);
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001762 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001763 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001764 }
1765
Joe Onorato7c312c12009-08-13 21:36:53 -07001766 void lockAllApps() {
1767 // TODO
1768 }
1769
1770 void unlockAllApps() {
1771 // TODO
1772 }
1773
Joe Onorato7404ee42009-07-31 11:54:44 -07001774 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001775 * Displays the shortcut creation dialog and launches, if necessary, the
1776 * appropriate activity.
1777 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001778 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07001779 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
1780 DialogInterface.OnShowListener {
1781
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001782 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07001783
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001784 Dialog createDialog() {
1785 mWaitingForResult = true;
Romain Guycbb89e42009-06-08 15:52:54 -07001786
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07001788
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1790 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001791 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07001792
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 builder.setInverseBackgroundForced(true);
1794
1795 AlertDialog dialog = builder.create();
1796 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001797 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07001798 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001799
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 return dialog;
1801 }
1802
1803 public void onCancel(DialogInterface dialog) {
1804 mWaitingForResult = false;
1805 cleanup();
1806 }
1807
Romain Guycbb89e42009-06-08 15:52:54 -07001808 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07001809 }
1810
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001811 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08001812 try {
1813 dismissDialog(DIALOG_CREATE_SHORTCUT);
1814 } catch (Exception e) {
1815 // An exception is thrown if the dialog is not visible, which is fine
1816 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 }
1818
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001819 /**
1820 * Handle the action clicked in the "Add to home" dialog.
1821 */
1822 public void onClick(DialogInterface dialog, int which) {
1823 Resources res = getResources();
1824 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07001825
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001826 switch (which) {
1827 case AddAdapter.ITEM_SHORTCUT: {
1828 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07001829 pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001830 break;
1831 }
Romain Guycbb89e42009-06-08 15:52:54 -07001832
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001833 case AddAdapter.ITEM_APPWIDGET: {
1834 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07001835
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001836 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
1837 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001838 // start the pick activity
1839 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
1840 break;
1841 }
Romain Guycbb89e42009-06-08 15:52:54 -07001842
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001843 case AddAdapter.ITEM_LIVE_FOLDER: {
1844 // Insert extra item to handle inserting folder
1845 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07001846
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001847 ArrayList<String> shortcutNames = new ArrayList<String>();
1848 shortcutNames.add(res.getString(R.string.group_folder));
1849 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07001850
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001851 ArrayList<ShortcutIconResource> shortcutIcons =
1852 new ArrayList<ShortcutIconResource>();
1853 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1854 R.drawable.ic_launcher_folder));
1855 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1856
1857 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1858 pickIntent.putExtra(Intent.EXTRA_INTENT,
1859 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
1860 pickIntent.putExtra(Intent.EXTRA_TITLE,
1861 getText(R.string.title_select_live_folder));
1862 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07001863
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001864 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
1865 break;
1866 }
1867
1868 case AddAdapter.ITEM_WALLPAPER: {
1869 startWallpaper();
1870 break;
1871 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001872 }
1873 }
Romain Guy7b4ef332009-07-14 13:58:08 -07001874
1875 public void onShow(DialogInterface dialog) {
Romain Guy7b4ef332009-07-14 13:58:08 -07001876 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 }
1878
1879 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001880 * Receives notifications when applications are added/removed.
1881 */
1882 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
1883 @Override
1884 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001885 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05001886 String reason = intent.getStringExtra("reason");
1887 if (!"homekey".equals(reason)) {
1888 boolean animate = true;
1889 /*
1890 if ("globalactions".equals(reason)) {
1891 // For some reason (probably the fading), this animation is
1892 // choppy, so don't show it.
1893 animate = false;
1894 }
1895 */
1896 closeAllApps(animate);
1897 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001898 }
1899 }
1900
1901 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001902 * Receives notifications whenever the appwidgets are reset.
1903 */
1904 private class AppWidgetResetObserver extends ContentObserver {
1905 public AppWidgetResetObserver() {
1906 super(new Handler());
1907 }
1908
1909 @Override
1910 public void onChange(boolean selfChange) {
1911 onAppWidgetReset();
1912 }
1913 }
1914
1915 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001916 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001917 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001918 public int getCurrentWorkspaceScreen() {
1919 return mWorkspace.getCurrentScreen();
1920 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001921
Joe Onorato9c1289c2009-08-17 11:03:03 -04001922 /**
1923 * Refreshes the shortcuts shown on the workspace.
1924 *
1925 * Implementation of the method from LauncherModel.Callbacks.
1926 */
1927 public void startBinding() {
1928 final Workspace workspace = mWorkspace;
1929 int count = workspace.getChildCount();
1930 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04001931 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04001932 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
1933 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001934
Joe Onorato9c1289c2009-08-17 11:03:03 -04001935 if (DEBUG_USER_INTERFACE) {
1936 android.widget.Button finishButton = new android.widget.Button(this);
1937 finishButton.setText("Finish");
1938 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
1939
1940 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
1941 public void onClick(View v) {
1942 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001943 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001944 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001945 }
1946 }
1947
1948 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001949 * Bind the items start-end from the list.
1950 *
1951 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001953 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
1954
1955 final Workspace workspace = mWorkspace;
1956
1957 for (int i=start; i<end; i++) {
1958 final ItemInfo item = shortcuts.get(i);
1959 mDesktopItems.add(item);
1960 switch (item.itemType) {
1961 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1962 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1963 final View shortcut = createShortcut((ApplicationInfo) item);
1964 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
1965 false);
1966 break;
1967 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
1968 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1969 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1970 (UserFolderInfo) item);
1971 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
1972 false);
1973 break;
1974 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
1975 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
1976 R.layout.live_folder_icon, this,
1977 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1978 (LiveFolderInfo) item);
1979 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
1980 false);
1981 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001982 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001983 }
1984
Joe Onorato9c1289c2009-08-17 11:03:03 -04001985 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001986 }
1987
Joe Onorato9c1289c2009-08-17 11:03:03 -04001988 /**
1989 * Implementation of the method from LauncherModel.Callbacks.
1990 */
Joe Onoratoad72e172009-11-06 16:25:04 -05001991 public void bindFolders(HashMap<Long, FolderInfo> folders) {
1992 mFolders.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001993 mFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001995
1996 /**
1997 * Add the views for a widget to the workspace.
1998 *
1999 * Implementation of the method from LauncherModel.Callbacks.
2000 */
2001 public void bindAppWidget(LauncherAppWidgetInfo item) {
2002 final Workspace workspace = mWorkspace;
2003
2004 final int appWidgetId = item.appWidgetId;
2005 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
2006 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2007
Joe Onorato9c1289c2009-08-17 11:03:03 -04002008 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2009 item.hostView.setTag(item);
2010
2011 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2012 item.cellY, item.spanX, item.spanY, false);
2013
2014 workspace.requestLayout();
2015
2016 mDesktopItems.add(item);
2017 }
2018
2019 /**
2020 * Callback saying that there aren't any more items to bind.
2021 *
2022 * Implementation of the method from LauncherModel.Callbacks.
2023 */
2024 public void finishBindingItems() {
2025 if (mSavedState != null) {
2026 if (!mWorkspace.hasFocus()) {
2027 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
2028 }
2029
2030 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2031 if (userFolders != null) {
2032 for (long folderId : userFolders) {
2033 final FolderInfo info = mFolders.get(folderId);
2034 if (info != null) {
2035 openFolder(info);
2036 }
2037 }
2038 final Folder openFolder = mWorkspace.getOpenFolder();
2039 if (openFolder != null) {
2040 openFolder.requestFocus();
2041 }
2042 }
2043
Joe Onorato9c1289c2009-08-17 11:03:03 -04002044 mSavedState = null;
2045 }
2046
2047 if (mSavedInstanceState != null) {
2048 super.onRestoreInstanceState(mSavedInstanceState);
2049 mSavedInstanceState = null;
2050 }
2051
Joe Onorato9c1289c2009-08-17 11:03:03 -04002052 mWorkspaceLoading = false;
2053 }
2054
2055 /**
2056 * Add the icons for all apps.
2057 *
2058 * Implementation of the method from LauncherModel.Callbacks.
2059 */
2060 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08002061 mAllAppsGrid.setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002062 }
2063
2064 /**
2065 * A package was installed.
2066 *
2067 * Implementation of the method from LauncherModel.Callbacks.
2068 */
2069 public void bindPackageAdded(ArrayList<ApplicationInfo> apps) {
2070 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002071 mAllAppsGrid.addApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002072 }
2073
2074 /**
2075 * A package was updated.
2076 *
2077 * Implementation of the method from LauncherModel.Callbacks.
2078 */
2079 public void bindPackageUpdated(String packageName, ArrayList<ApplicationInfo> apps) {
2080 removeDialog(DIALOG_CREATE_SHORTCUT);
2081 mWorkspace.updateShortcutsForPackage(packageName);
Joe Onoratof0be2132009-11-24 19:34:29 -05002082 mAllAppsGrid.updateApps(packageName, apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002083 }
2084
2085 /**
2086 * A package was uninstalled.
2087 *
2088 * Implementation of the method from LauncherModel.Callbacks.
2089 */
2090 public void bindPackageRemoved(String packageName, ArrayList<ApplicationInfo> apps) {
2091 removeDialog(DIALOG_CREATE_SHORTCUT);
2092 mWorkspace.removeShortcutsForPackage(packageName);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002093 mAllAppsGrid.removeApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002094 }
Joe Onoratobe386092009-11-17 17:32:16 -08002095
2096 /**
2097 * Prints out out state for debugging.
2098 */
2099 public void dumpState() {
2100 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08002101 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08002102 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
2103 Log.d(TAG, "mRestoring=" + mRestoring);
2104 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
2105 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
2106 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
2107 Log.d(TAG, "mFolders.size=" + mFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08002108 mModel.dumpState();
2109 mAllAppsGrid.dumpState();
2110 Log.d(TAG, "END launcher2 dump state");
2111 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112}