blob: 089e5512bbb3b6fbfa33e86730e6d3e599e4f656 [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
Bjorn Bringert3e244cf2010-02-10 14:17:35 +000019import com.android.common.Search;
20
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.app.Activity;
22import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.app.Dialog;
24import android.app.SearchManager;
25import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070026import android.app.WallpaperManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080028import android.content.BroadcastReceiver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080030import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.content.Context;
32import android.content.DialogInterface;
33import android.content.Intent;
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -070034import android.content.Intent.ShortcutIconResource;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080035import android.content.IntentFilter;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.pm.ActivityInfo;
37import android.content.pm.PackageManager;
38import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070040import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080041import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.graphics.Bitmap;
Romain Guy1fbc1c82009-11-09 20:43:08 -080043import android.graphics.Rect;
Romain Guya6abce82009-11-10 02:54:41 -080044import android.graphics.Canvas;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.graphics.drawable.Drawable;
Romain Guyff0c2e22009-11-10 12:09:59 -080046import android.graphics.drawable.ColorDrawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080048import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.os.Parcelable;
Joe Onoratobe386092009-11-17 17:32:16 -080050import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.provider.LiveFolders;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052import android.text.Selection;
53import android.text.SpannableStringBuilder;
54import android.text.TextUtils;
55import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070056import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080058import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.view.KeyEvent;
60import android.view.LayoutInflater;
61import android.view.Menu;
62import android.view.MenuItem;
63import android.view.View;
64import android.view.ViewGroup;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.view.View.OnLongClickListener;
Joe Onorato8a9625e2010-01-28 15:55:35 -080066import android.view.WindowManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.widget.EditText;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.widget.TextView;
70import android.widget.Toast;
Romain Guy8a73c512009-11-09 19:19:59 -080071import android.widget.ImageView;
Romain Guy1fbc1c82009-11-09 20:43:08 -080072import android.widget.PopupWindow;
Romain Guye6b8e2f2009-11-10 11:56:55 -080073import android.widget.LinearLayout;
The Android Open Source Project7376fae2009-03-11 12:11:58 -070074import android.appwidget.AppWidgetManager;
75import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077import java.util.ArrayList;
Joe Onorato9c1289c2009-08-17 11:03:03 -040078import java.util.HashMap;
Romain Guy98d01652009-06-30 16:21:04 -070079import java.io.DataOutputStream;
80import java.io.FileNotFoundException;
81import java.io.IOException;
82import java.io.DataInputStream;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083
84/**
85 * Default launcher application.
86 */
Joe Onorato9c1289c2009-08-17 11:03:03 -040087public final class Launcher extends Activity
Romain Guya6abce82009-11-10 02:54:41 -080088 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080089 static final String TAG = "Launcher";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090 static final boolean LOGD = false;
91
Joe Onorato9c1289c2009-08-17 11:03:03 -040092 static final boolean PROFILE_STARTUP = false;
93 static final boolean PROFILE_ROTATE = false;
94 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -070095
The Android Open Source Project31dd5032009-03-03 19:32:27 -080096 private static final int WALLPAPER_SCREENS_SPAN = 2;
97
98 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -080099 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
100
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800101 private static final int MENU_ADD = Menu.FIRST + 1;
102 private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
103 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
104 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700105 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800106
107 private static final int REQUEST_CREATE_SHORTCUT = 1;
108 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700109 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800110 private static final int REQUEST_PICK_APPLICATION = 6;
111 private static final int REQUEST_PICK_SHORTCUT = 7;
112 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700113 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700114 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115
116 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
117
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800118 static final int SCREEN_COUNT = 5;
119 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120 static final int NUMBER_CELLS_X = 4;
Romain Guycbb89e42009-06-08 15:52:54 -0700121 static final int NUMBER_CELLS_Y = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
Joe Onorato7c312c12009-08-13 21:36:53 -0700123 static final int DIALOG_CREATE_SHORTCUT = 1;
124 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
Romain Guy98d01652009-06-30 16:21:04 -0700126 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127
128 // Type: int
129 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
130 // Type: boolean
131 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
132 // Type: long
133 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
134 // Type: int
135 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
136 // Type: int
137 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
138 // Type: int
139 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
140 // Type: int
141 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX";
142 // Type: int
143 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY";
144 // Type: int
145 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX";
146 // Type: int
147 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY";
148 // Type: int[]
149 private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells";
150 // Type: boolean
151 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
152 // Type: long
153 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
154
Joe Onorato9c1289c2009-08-17 11:03:03 -0400155 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800158 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800160 private final BroadcastReceiver mCloseSystemDialogsReceiver
161 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800162 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 private LayoutInflater mInflater;
165
Joe Onorato00acb122009-08-04 16:04:30 -0400166 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700168
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700169 private AppWidgetManager mAppWidgetManager;
170 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700171
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private CellLayout.CellInfo mAddItemCellInfo;
173 private CellLayout.CellInfo mMenuAddInfo;
174 private final int[] mCellCoordinates = new int[2];
175 private FolderInfo mFolderInfo;
176
Joe Onorato7c312c12009-08-13 21:36:53 -0700177 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700178 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700179 private AllAppsView mAllAppsGrid;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private Bundle mSavedState;
182
183 private SpannableStringBuilder mDefaultKeySsb = null;
184
Joe Onorato9c1289c2009-08-17 11:03:03 -0400185 private boolean mWorkspaceLoading = true;
186
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800187 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 private boolean mRestoring;
189 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190
191 private Bundle mSavedInstanceState;
192
Joe Onorato9c1289c2009-08-17 11:03:03 -0400193 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800194 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400195
Romain Guy84f296c2009-11-04 15:00:44 -0800196 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
197 private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700198
Romain Guy1fbc1c82009-11-09 20:43:08 -0800199 private ImageView mPreviousView;
200 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500201
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 @Override
203 protected void onCreate(Bundle savedInstanceState) {
204 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700205
Joe Onorato0589f0f2010-02-08 13:44:00 -0800206 LauncherApplication app = ((LauncherApplication)getApplication());
207 mModel = app.setLauncher(this);
208 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400209 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700211
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700212 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700213 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
214 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700215
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216 if (PROFILE_STARTUP) {
217 android.os.Debug.startMethodTracing("/sdcard/launcher");
218 }
219
220 checkForLocaleChange();
221 setWallpaperDimension();
222
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800223 setContentView(R.layout.launcher);
224 setupViews();
225
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800226 registerContentObservers();
227
Joe Onorato7c312c12009-08-13 21:36:53 -0700228 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700229
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230 mSavedState = savedInstanceState;
231 restoreState(mSavedState);
232
233 if (PROFILE_STARTUP) {
234 android.os.Debug.stopMethodTracing();
235 }
236
Joe Onorato1d8e7bb2009-10-15 19:49:43 -0700237 // We have a new AllAppsView, we need to re-bind everything, and it could have
238 // changed in our absence.
239 mModel.setAllAppsDirty();
240 mModel.setWorkspaceDirty();
241
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800242 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400243 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244 }
245
246 // For handling default keys
247 mDefaultKeySsb = new SpannableStringBuilder();
248 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800249
250 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
251 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252 }
Romain Guycbb89e42009-06-08 15:52:54 -0700253
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254 private void checkForLocaleChange() {
Romain Guy98d01652009-06-30 16:21:04 -0700255 final LocaleConfiguration localeConfiguration = new LocaleConfiguration();
256 readConfiguration(this, localeConfiguration);
Jason Samsfd22dac2009-09-20 17:24:16 -0700257
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258 final Configuration configuration = getResources().getConfiguration();
259
Romain Guy98d01652009-06-30 16:21:04 -0700260 final String previousLocale = localeConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800261 final String locale = configuration.locale.toString();
262
Romain Guy98d01652009-06-30 16:21:04 -0700263 final int previousMcc = localeConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 final int mcc = configuration.mcc;
265
Romain Guy98d01652009-06-30 16:21:04 -0700266 final int previousMnc = localeConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 final int mnc = configuration.mnc;
268
Romain Guy84f296c2009-11-04 15:00:44 -0800269 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270
Romain Guy84f296c2009-11-04 15:00:44 -0800271 if (localeChanged) {
Romain Guy98d01652009-06-30 16:21:04 -0700272 localeConfiguration.locale = locale;
273 localeConfiguration.mcc = mcc;
274 localeConfiguration.mnc = mnc;
275
276 writeConfiguration(this, localeConfiguration);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800277 mIconCache.flush();
Romain Guy98d01652009-06-30 16:21:04 -0700278 }
279 }
280
281 private static class LocaleConfiguration {
282 public String locale;
283 public int mcc = -1;
284 public int mnc = -1;
285 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700286
Romain Guy98d01652009-06-30 16:21:04 -0700287 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
288 DataInputStream in = null;
289 try {
290 in = new DataInputStream(context.openFileInput(PREFERENCES));
291 configuration.locale = in.readUTF();
292 configuration.mcc = in.readInt();
293 configuration.mnc = in.readInt();
294 } catch (FileNotFoundException e) {
295 // Ignore
296 } catch (IOException e) {
297 // Ignore
298 } finally {
299 if (in != null) {
300 try {
301 in.close();
302 } catch (IOException e) {
303 // Ignore
304 }
305 }
306 }
307 }
308
309 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
310 DataOutputStream out = null;
311 try {
312 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
313 out.writeUTF(configuration.locale);
314 out.writeInt(configuration.mcc);
315 out.writeInt(configuration.mnc);
316 out.flush();
317 } catch (FileNotFoundException e) {
318 // Ignore
319 } catch (IOException e) {
320 //noinspection ResultOfMethodCallIgnored
321 context.getFileStreamPath(PREFERENCES).delete();
322 } finally {
323 if (out != null) {
324 try {
325 out.close();
326 } catch (IOException e) {
327 // Ignore
328 }
329 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800330 }
331 }
332
333 static int getScreen() {
334 synchronized (sLock) {
335 return sScreen;
336 }
337 }
338
339 static void setScreen(int screen) {
340 synchronized (sLock) {
341 sScreen = screen;
342 }
343 }
344
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800345 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700346 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347
348 Display display = getWindowManager().getDefaultDisplay();
349 boolean isPortrait = display.getWidth() < display.getHeight();
350
351 final int width = isPortrait ? display.getWidth() : display.getHeight();
352 final int height = isPortrait ? display.getHeight() : display.getWidth();
Dianne Hackborn64271802009-08-08 20:54:24 -0700353 wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800354 }
355
356 @Override
357 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700358 mWaitingForResult = false;
359
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 // The pattern used here is that a user PICKs a specific application,
361 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700362
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800363 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
364 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700365
Romain Guy94dabf12009-07-21 10:55:43 -0700366 if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800367 switch (requestCode) {
368 case REQUEST_PICK_APPLICATION:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400369 completeAddApplication(this, data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 break;
371 case REQUEST_PICK_SHORTCUT:
Romain Guy73b979d2009-06-09 12:57:21 -0700372 processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800373 break;
374 case REQUEST_CREATE_SHORTCUT:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400375 completeAddShortcut(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 break;
377 case REQUEST_PICK_LIVE_FOLDER:
378 addLiveFolder(data);
379 break;
380 case REQUEST_CREATE_LIVE_FOLDER:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400381 completeAddLiveFolder(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700383 case REQUEST_PICK_APPWIDGET:
384 addAppWidget(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700386 case REQUEST_CREATE_APPWIDGET:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400387 completeAddAppWidget(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700389 case REQUEST_PICK_WALLPAPER:
390 // We just wanted the activity result here so we can clear mWaitingForResult
391 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800392 }
Romain Guy18042c82009-11-06 11:44:55 -0800393 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
394 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
395 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700396 // Clean up the appWidgetId if we canceled
397 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
398 if (appWidgetId != -1) {
399 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 }
401 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800402 }
403
404 @Override
405 protected void onResume() {
406 super.onResume();
407
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800408 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800409
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800410 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400411 mWorkspaceLoading = true;
412 mModel.startLoader(this, true);
413 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800414 }
415 }
416
417 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700418 protected void onPause() {
419 super.onPause();
Romain Guy1fbc1c82009-11-09 20:43:08 -0800420 dismissPreview(mPreviousView);
421 dismissPreview(mNextView);
Joe Onorato24b6fd82009-11-12 13:47:09 -0800422 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700423 }
Romain Guycbb89e42009-06-08 15:52:54 -0700424
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700425 @Override
426 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400427 // Flag the loader to stop early before switching
428 mModel.stopLoader();
Romain Guycbb89e42009-06-08 15:52:54 -0700429
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700430 if (PROFILE_ROTATE) {
431 android.os.Debug.startMethodTracing("/sdcard/launcher-rotate");
432 }
433 return null;
434 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700435
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800436 // We can't hide the IME if it was forced open. So don't bother
437 /*
438 @Override
439 public void onWindowFocusChanged(boolean hasFocus) {
440 super.onWindowFocusChanged(hasFocus);
441
442 if (hasFocus) {
443 final InputMethodManager inputManager = (InputMethodManager)
444 getSystemService(Context.INPUT_METHOD_SERVICE);
445 WindowManager.LayoutParams lp = getWindow().getAttributes();
446 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
447 android.os.Handler()) {
448 protected void onReceiveResult(int resultCode, Bundle resultData) {
449 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
450 }
451 });
452 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
453 }
454 }
455 */
456
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 private boolean acceptFilter() {
458 final InputMethodManager inputManager = (InputMethodManager)
459 getSystemService(Context.INPUT_METHOD_SERVICE);
460 return !inputManager.isFullscreenMode();
461 }
462
463 @Override
464 public boolean onKeyDown(int keyCode, KeyEvent event) {
465 boolean handled = super.onKeyDown(keyCode, event);
466 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
467 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
468 keyCode, event);
469 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700470 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700471 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700472 // showSearchDialog()
473 // If there are multiple keystrokes before the search dialog takes focus,
474 // onSearchRequested() will be called for every keystroke,
475 // but it is idempotent, so it's fine.
476 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800477 }
478 }
479
Joe Onorato8a9625e2010-01-28 15:55:35 -0800480 // Eat the long press event so the keyboard doesn't come up.
481 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
482 return true;
483 }
484
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800485 return handled;
486 }
487
Karl Rosaen138a0412009-04-23 19:00:21 -0700488 private String getTypedText() {
489 return mDefaultKeySsb.toString();
490 }
491
492 private void clearTypedText() {
493 mDefaultKeySsb.clear();
494 mDefaultKeySsb.clearSpans();
495 Selection.setSelection(mDefaultKeySsb, 0);
496 }
497
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800498 /**
499 * Restores the previous state, if it exists.
500 *
501 * @param savedState The previous state.
502 */
503 private void restoreState(Bundle savedState) {
504 if (savedState == null) {
505 return;
506 }
507
Joe Onorato3a8820b2009-11-10 15:06:42 -0800508 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
509 if (allApps) {
510 showAllApps(false);
511 }
512
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800513 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
514 if (currentScreen > -1) {
515 mWorkspace.setCurrentScreen(currentScreen);
516 }
517
518 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
519 if (addScreen > -1) {
520 mAddItemCellInfo = new CellLayout.CellInfo();
521 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
522 addItemCellInfo.valid = true;
523 addItemCellInfo.screen = addScreen;
524 addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
525 addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
526 addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
527 addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
528 addItemCellInfo.findVacantCellsFromOccupied(
529 savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS),
530 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X),
531 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y));
532 mRestoring = true;
533 }
534
535 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
536 if (renameFolder) {
537 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400538 mFolderInfo = mModel.getFolderById(this, mFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800539 mRestoring = true;
540 }
541 }
542
543 /**
544 * Finds all the views we need and configure them properly.
545 */
546 private void setupViews() {
Joe Onorato00acb122009-08-04 16:04:30 -0400547 DragController dragController = mDragController;
548
Romain Guyb1b69f52009-08-10 15:10:15 -0700549 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400550 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800551
Joe Onorato7c312c12009-08-13 21:36:53 -0700552 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700553 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700554 mAllAppsGrid.setDragController(dragController);
Joe Onorato85a02a82009-09-08 12:34:22 -0700555 mAllAppsGrid.setWillNotDraw(false); // We don't want a hole punched in our window.
Mike Cleronb6082fa2009-10-19 17:03:36 -0700556 // Manage focusability manually since this thing is always visible
557 mAllAppsGrid.setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700558
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800559 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
560 final Workspace workspace = mWorkspace;
561
Joe Onorato7c312c12009-08-13 21:36:53 -0700562 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
563 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564
Joe Onorato7c312c12009-08-13 21:36:53 -0700565 mHandleView = (HandleView) findViewById(R.id.all_apps_button);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700566 mHandleView.setLauncher(this);
Joe Onorato7404ee42009-07-31 11:54:44 -0700567 mHandleView.setOnClickListener(this);
Romain Guyf8e6a802009-12-07 17:48:02 -0800568 mHandleView.setOnLongClickListener(this);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800569
570 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
571 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
572
573 Drawable previous = mPreviousView.getDrawable();
574 Drawable next = mNextView.getDrawable();
Romain Guy8a73c512009-11-09 19:19:59 -0800575 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800576
Joe Onorato0d44e942009-11-16 18:20:51 -0800577 mPreviousView.setHapticFeedbackEnabled(false);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800578 mPreviousView.setOnLongClickListener(this);
Joe Onorato0d44e942009-11-16 18:20:51 -0800579 mNextView.setHapticFeedbackEnabled(false);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800580 mNextView.setOnLongClickListener(this);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800581
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800582 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400583 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800584 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800585
586 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400587 deleteZone.setDragController(dragController);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700588 deleteZone.setHandle(mHandleView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800589
Joe Onorato00acb122009-08-04 16:04:30 -0400590 dragController.setDragScoller(workspace);
591 dragController.setDragListener(deleteZone);
592 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800593 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700594
Joe Onorato00acb122009-08-04 16:04:30 -0400595 // The order here is bottom to top.
596 dragController.addDropTarget(workspace);
597 dragController.addDropTarget(deleteZone);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800598 }
599
Romain Guy8a73c512009-11-09 19:19:59 -0800600 @SuppressWarnings({"UnusedDeclaration"})
601 public void previousScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800602 if (!isAllAppsVisible()) {
603 mWorkspace.scrollLeft();
604 }
Romain Guy8a73c512009-11-09 19:19:59 -0800605 }
606
607 @SuppressWarnings({"UnusedDeclaration"})
608 public void nextScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800609 if (!isAllAppsVisible()) {
610 mWorkspace.scrollRight();
611 }
Romain Guy8a73c512009-11-09 19:19:59 -0800612 }
613
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800614 /**
615 * Creates a view representing a shortcut.
616 *
617 * @param info The data structure describing the shortcut.
618 *
619 * @return A View inflated from R.layout.application.
620 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800621 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800622 return createShortcut(R.layout.application,
623 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
624 }
625
626 /**
627 * Creates a view representing a shortcut inflated from the specified resource.
628 *
629 * @param layoutResId The id of the XML layout used to create the shortcut.
630 * @param parent The group the shortcut belongs to.
631 * @param info The data structure describing the shortcut.
632 *
633 * @return A View inflated from layoutResId.
634 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800635 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800636 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
637
Joe Onorato0589f0f2010-02-08 13:44:00 -0800638 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
639 new FastBitmapDrawable(info.getIcon(mIconCache)),
640 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800641 favorite.setText(info.title);
642 favorite.setTag(info);
643 favorite.setOnClickListener(this);
644
645 return favorite;
646 }
647
648 /**
649 * Add an application shortcut to the workspace.
650 *
651 * @param data The intent describing the application.
652 * @param cellInfo The position on screen where to create the shortcut.
653 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400654 void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 cellInfo.screen = mWorkspace.getCurrentScreen();
656 if (!findSingleSlot(cellInfo)) return;
657
Joe Onorato0589f0f2010-02-08 13:44:00 -0800658 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
659 data, context);
660
Romain Guy73b979d2009-06-09 12:57:21 -0700661 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800662 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800664 info.container = ItemInfo.NO_ID;
665 mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked());
666 } else {
667 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800668 }
669 }
Romain Guycbb89e42009-06-08 15:52:54 -0700670
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 /**
672 * Add a shortcut to the workspace.
673 *
674 * @param data The intent describing the shortcut.
675 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800676 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400677 private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 cellInfo.screen = mWorkspace.getCurrentScreen();
679 if (!findSingleSlot(cellInfo)) return;
Romain Guycbb89e42009-06-08 15:52:54 -0700680
Joe Onorato0589f0f2010-02-08 13:44:00 -0800681 final ShortcutInfo info = mModel.addShortcut(this, data, cellInfo, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682
683 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 final View view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400685 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
686 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800687 }
688 }
689
Romain Guycbb89e42009-06-08 15:52:54 -0700690
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800691 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700692 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 *
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700694 * @param data The intent describing the appWidgetId.
695 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800696 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400697 private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800698 Bundle extras = data.getExtras();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700699 int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Romain Guycbb89e42009-06-08 15:52:54 -0700700
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800701 if (LOGD) Log.d(TAG, "dumping extras content=" + extras.toString());
Romain Guycbb89e42009-06-08 15:52:54 -0700702
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700703 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700704
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700705 // Calculate the grid spans needed to fit this widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706 CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700707 int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
Romain Guycbb89e42009-06-08 15:52:54 -0700708
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800709 // Try finding open space on Launcher screen
710 final int[] xy = mCellCoordinates;
Romain Guy18042c82009-11-06 11:44:55 -0800711 if (!findSlot(cellInfo, xy, spans[0], spans[1])) {
712 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
713 return;
714 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800715
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700716 // Build Launcher-specific widget info and save to database
717 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800718 launcherInfo.spanX = spans[0];
719 launcherInfo.spanY = spans[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700720
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800721 LauncherModel.addItemToDatabase(this, launcherInfo,
722 LauncherSettings.Favorites.CONTAINER_DESKTOP,
723 mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
724
725 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400726 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700727
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800728 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700729 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700730
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700731 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800732 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700733
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800734 mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400735 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800736 }
737 }
Romain Guycbb89e42009-06-08 15:52:54 -0700738
Joe Onorato9c1289c2009-08-17 11:03:03 -0400739 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
740 mDesktopItems.remove(launcherInfo);
741 launcherInfo.hostView = null;
742 }
743
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700744 public LauncherAppWidgetHost getAppWidgetHost() {
745 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800746 }
Romain Guycbb89e42009-06-08 15:52:54 -0700747
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800748 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800749 getWindow().closeAllPanels();
750
751 try {
752 dismissDialog(DIALOG_CREATE_SHORTCUT);
753 // Unlock the workspace if the dialog was showing
754 } catch (Exception e) {
755 // An exception is thrown if the dialog is not visible, which is fine
756 }
757
758 try {
759 dismissDialog(DIALOG_RENAME_FOLDER);
760 // Unlock the workspace if the dialog was showing
761 } catch (Exception e) {
762 // An exception is thrown if the dialog is not visible, which is fine
763 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -0800764
765 // Whatever we were doing is hereby canceled.
766 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800767 }
768
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800769 @Override
770 protected void onNewIntent(Intent intent) {
771 super.onNewIntent(intent);
772
773 // Close the menu
774 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -0800775 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800776 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -0700777
Joe Onorato14f122b2009-11-19 14:06:36 -0800778 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
779 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
780 boolean allAppsVisible = isAllAppsVisible();
Joe Onorato3a8820b2009-11-10 15:06:42 -0800781 if (!mWorkspace.isDefaultScreenShowing()) {
Joe Onorato14f122b2009-11-19 14:06:36 -0800782 mWorkspace.moveToDefaultScreen(alreadyOnHome && !allAppsVisible);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800783 }
Joe Onorato14f122b2009-11-19 14:06:36 -0800784 closeAllApps(alreadyOnHome && allAppsVisible);
Romain Guy1dd3a072009-07-16 13:21:01 -0700785
Joe Onorato3a8820b2009-11-10 15:06:42 -0800786 final View v = getWindow().peekDecorView();
787 if (v != null && v.getWindowToken() != null) {
788 InputMethodManager imm = (InputMethodManager)getSystemService(
789 INPUT_METHOD_SERVICE);
790 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800791 }
792 }
793 }
794
795 @Override
796 protected void onRestoreInstanceState(Bundle savedInstanceState) {
797 // Do not call super here
798 mSavedInstanceState = savedInstanceState;
799 }
800
801 @Override
802 protected void onSaveInstanceState(Bundle outState) {
803 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen());
804
805 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
806 if (folders.size() > 0) {
807 final int count = folders.size();
808 long[] ids = new long[count];
809 for (int i = 0; i < count; i++) {
810 final FolderInfo info = folders.get(i).getInfo();
811 ids[i] = info.id;
812 }
813 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
814 } else {
815 super.onSaveInstanceState(outState);
816 }
817
Joe Onoratofb0ca672009-09-14 17:55:46 -0400818 // TODO should not do this if the drawer is currently closing.
Joe Onorato3a8820b2009-11-10 15:06:42 -0800819 if (isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800820 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -0700821 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800822
823 if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
824 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
825 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);
826
827 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
828 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
829 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
830 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
831 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
832 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
833 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
834 outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS,
835 layout.getOccupiedCells());
836 }
837
838 if (mFolderInfo != null && mWaitingForResult) {
839 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
840 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
841 }
842 }
843
844 @Override
845 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800846 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -0700847
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800848 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700849 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800851 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800852 }
853
854 TextKeyListener.getInstance().release();
855
Joe Onorato9c1289c2009-08-17 11:03:03 -0400856 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857
Joe Onorato9c1289c2009-08-17 11:03:03 -0400858 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800859
860 getContentResolver().unregisterContentObserver(mWidgetObserver);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800861
862 dismissPreview(mPreviousView);
Romain Guya6abce82009-11-10 02:54:41 -0800863 dismissPreview(mNextView);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800864
865 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800866 }
867
868 @Override
869 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -0700870 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800871 super.startActivityForResult(intent, requestCode);
872 }
873
874 @Override
Romain Guycbb89e42009-06-08 15:52:54 -0700875 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800876 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700877
Joe Onorato7bb17492009-09-24 17:51:01 -0700878 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -0700879
Karl Rosaen138a0412009-04-23 19:00:21 -0700880 if (initialQuery == null) {
881 // Use any text typed in the launcher as the initial query
882 initialQuery = getTypedText();
883 clearTypedText();
884 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800885 if (appSearchData == null) {
886 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +0000887 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800888 }
Romain Guycbb89e42009-06-08 15:52:54 -0700889
Karl Rosaen138a0412009-04-23 19:00:21 -0700890 final SearchManager searchManager =
891 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -0700892 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -0700893 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800894 }
895
896 @Override
897 public boolean onCreateOptionsMenu(Menu menu) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400898 if (isWorkspaceLocked()) {
899 return false;
900 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901
902 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800903
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800904 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
905 .setIcon(android.R.drawable.ic_menu_add)
906 .setAlphabeticShortcut('A');
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800907 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800908 .setIcon(android.R.drawable.ic_menu_gallery)
909 .setAlphabeticShortcut('W');
910 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
911 .setIcon(android.R.drawable.ic_search_category_default)
912 .setAlphabeticShortcut(SearchManager.MENU_KEY);
913 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
914 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
915 .setAlphabeticShortcut('N');
916
917 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -0700918 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
919 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800920
921 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
922 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
923 .setIntent(settings);
924
925 return true;
926 }
927
928 @Override
929 public boolean onPrepareOptionsMenu(Menu menu) {
930 super.onPrepareOptionsMenu(menu);
931
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800932 // If all apps is animating, don't show the menu, because we don't know
933 // which one to show.
934 if (mAllAppsGrid.isVisible() && !mAllAppsGrid.isOpaque()) {
935 return false;
936 }
937
938 // Only show the add and wallpaper options when we're not in all apps.
939 boolean visible = !mAllAppsGrid.isOpaque();
940 menu.setGroupVisible(MENU_GROUP_ADD, visible);
941 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
942
943 // Disable add if the workspace is full.
944 if (visible) {
945 mMenuAddInfo = mWorkspace.findAllVacantCells(null);
946 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
947 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800948
949 return true;
950 }
951
952 @Override
953 public boolean onOptionsItemSelected(MenuItem item) {
954 switch (item.getItemId()) {
955 case MENU_ADD:
956 addItems();
957 return true;
958 case MENU_WALLPAPER_SETTINGS:
959 startWallpaper();
960 return true;
961 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700962 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800963 return true;
964 case MENU_NOTIFICATIONS:
965 showNotifications();
966 return true;
967 }
968
969 return super.onOptionsItemSelected(item);
970 }
Romain Guycbb89e42009-06-08 15:52:54 -0700971
Karl Rosaen138a0412009-04-23 19:00:21 -0700972 /**
973 * Indicates that we want global search for this activity by setting the globalSearch
974 * argument for {@link #startSearch} to true.
975 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700977 @Override
978 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -0700979 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -0700980 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -0700981 }
982
Joe Onorato9c1289c2009-08-17 11:03:03 -0400983 public boolean isWorkspaceLocked() {
984 return mWorkspaceLoading || mWaitingForResult;
985 }
986
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800987 private void addItems() {
Joe Onoratoe6168662009-11-08 13:39:30 -0500988 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800989 showAddDialog(mMenuAddInfo);
990 }
991
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700992 void addAppWidget(Intent data) {
993 // TODO: catch bad widget exception when sent
994 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Bjorn Bringert7984c942009-12-09 15:38:25 +0000995 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800996
Bjorn Bringert7984c942009-12-09 15:38:25 +0000997 if (appWidget.configure != null) {
998 // Launch over to configure widget, if needed
999 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1000 intent.setComponent(appWidget.configure);
1001 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1002
1003 startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001004 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001005 // Otherwise just add it
1006 onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001007 }
1008 }
Romain Guycbb89e42009-06-08 15:52:54 -07001009
Romain Guy73b979d2009-06-09 12:57:21 -07001010 void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001011 // Handle case where user selected "Applications"
1012 String applicationName = getResources().getString(R.string.group_applications);
1013 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001014
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001015 if (applicationName != null && applicationName.equals(shortcutName)) {
1016 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1017 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001018
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001019 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1020 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Romain Guy73b979d2009-06-09 12:57:21 -07001021 startActivityForResult(pickIntent, requestCodeApplication);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001022 } else {
Romain Guy73b979d2009-06-09 12:57:21 -07001023 startActivityForResult(intent, requestCodeShortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001024 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001025 }
1026
1027 void addLiveFolder(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001028 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001029 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001030 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001031
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001032 if (folderName != null && folderName.equals(shortcutName)) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001033 addFolder();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001034 } else {
1035 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1036 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 }
1038
Joe Onorato9c1289c2009-08-17 11:03:03 -04001039 void addFolder() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 UserFolderInfo folderInfo = new UserFolderInfo();
1041 folderInfo.title = getText(R.string.folder_name);
1042
1043 CellLayout.CellInfo cellInfo = mAddItemCellInfo;
1044 cellInfo.screen = mWorkspace.getCurrentScreen();
1045 if (!findSingleSlot(cellInfo)) return;
1046
1047 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001048 LauncherModel.addItemToDatabase(this, folderInfo,
1049 LauncherSettings.Favorites.CONTAINER_DESKTOP,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001050 mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001051 mFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001052
1053 // Create the view
1054 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1055 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
1056 mWorkspace.addInCurrentScreen(newFolder,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001057 cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 }
Romain Guycbb89e42009-06-08 15:52:54 -07001059
Joe Onorato9c1289c2009-08-17 11:03:03 -04001060 void removeFolder(FolderInfo folder) {
1061 mFolders.remove(folder.id);
1062 }
1063
1064 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001065 cellInfo.screen = mWorkspace.getCurrentScreen();
1066 if (!findSingleSlot(cellInfo)) return;
1067
1068 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
1069
1070 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
1072 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001073 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
1074 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001075 }
1076 }
1077
1078 static LiveFolderInfo addLiveFolder(Context context, Intent data,
1079 CellLayout.CellInfo cellInfo, boolean notify) {
1080
1081 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1082 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1083
1084 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 Intent.ShortcutIconResource iconResource = null;
1086
1087 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1088 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1089 try {
1090 iconResource = (Intent.ShortcutIconResource) extra;
1091 final PackageManager packageManager = context.getPackageManager();
1092 Resources resources = packageManager.getResourcesForApplication(
1093 iconResource.packageName);
1094 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1095 icon = resources.getDrawable(id);
1096 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001097 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001098 }
1099 }
1100
1101 if (icon == null) {
1102 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1103 }
1104
1105 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001106 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107 info.title = name;
1108 info.iconResource = iconResource;
1109 info.uri = data.getData();
1110 info.baseIntent = baseIntent;
1111 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1112 LiveFolders.DISPLAY_MODE_GRID);
1113
1114 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1115 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001116 mFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001117
1118 return info;
1119 }
1120
1121 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
1122 final int[] xy = new int[2];
1123 if (findSlot(cellInfo, xy, 1, 1)) {
1124 cellInfo.cellX = xy[0];
1125 cellInfo.cellY = xy[1];
1126 return true;
1127 }
1128 return false;
1129 }
1130
1131 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
1132 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1133 boolean[] occupied = mSavedState != null ?
1134 mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null;
1135 cellInfo = mWorkspace.findAllVacantCells(occupied);
1136 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1137 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1138 return false;
1139 }
1140 }
1141 return true;
1142 }
1143
1144 private void showNotifications() {
1145 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1146 if (statusBar != null) {
1147 statusBar.expand();
1148 }
1149 }
1150
1151 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001152 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001153 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001154 Intent chooser = Intent.createChooser(pickWallpaper,
1155 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001156 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1157 // Removed in Eclair MR1
1158// WallpaperManager wm = (WallpaperManager)
1159// getSystemService(Context.WALLPAPER_SERVICE);
1160// WallpaperInfo wi = wm.getWallpaperInfo();
1161// if (wi != null && wi.getSettingsActivity() != null) {
1162// LabeledIntent li = new LabeledIntent(getPackageName(),
1163// R.string.configure_wallpaper, 0);
1164// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1165// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1166// }
Mike Clerona0618e42009-10-22 13:55:21 -07001167 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001168 }
1169
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001170 /**
1171 * Registers various content observers. The current implementation registers
1172 * only a favorites observer to keep track of the favorites applications.
1173 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001174 private void registerContentObservers() {
1175 ContentResolver resolver = getContentResolver();
1176 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1177 true, mWidgetObserver);
1178 }
1179
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001180 @Override
1181 public boolean dispatchKeyEvent(KeyEvent event) {
1182 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1183 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001184 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001185 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001186 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001187 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001188 dumpState();
1189 return true;
1190 }
1191 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001192 }
1193 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1194 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001195 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001196 return true;
1197 }
1198 }
1199
1200 return super.dispatchKeyEvent(event);
1201 }
1202
Joe Onorato88ec0992009-11-19 13:16:06 -08001203 @Override
1204 public void onBackPressed() {
1205 if (isAllAppsVisible()) {
1206 closeAllApps(true);
1207 } else {
1208 closeFolder();
1209 }
1210 dismissPreview(mPreviousView);
1211 dismissPreview(mNextView);
1212 }
1213
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001214 private void closeFolder() {
1215 Folder folder = mWorkspace.getOpenFolder();
1216 if (folder != null) {
1217 closeFolder(folder);
1218 }
1219 }
1220
1221 void closeFolder(Folder folder) {
1222 folder.getInfo().opened = false;
1223 ViewGroup parent = (ViewGroup) folder.getParent();
1224 if (parent != null) {
1225 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001226 if (folder instanceof DropTarget) {
1227 // Live folders aren't DropTargets.
1228 mDragController.removeDropTarget((DropTarget)folder);
1229 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 }
1231 folder.onClose();
1232 }
1233
1234 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001235 * Re-listen when widgets are reset.
1236 */
1237 private void onAppWidgetReset() {
1238 mAppWidgetHost.startListening();
1239 }
1240
1241 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001242 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1243 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001244 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001245 private void unbindDesktopItems() {
1246 for (ItemInfo item: mDesktopItems) {
1247 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248 }
1249 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001250
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 /**
1252 * Launches the intent referred by the clicked shortcut.
1253 *
1254 * @param v The view representing the clicked shortcut.
1255 */
1256 public void onClick(View v) {
1257 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001258 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 // Open shortcut
Joe Onorato0589f0f2010-02-08 13:44:00 -08001260 final Intent intent = ((ShortcutInfo)tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001261 int[] pos = new int[2];
1262 v.getLocationOnScreen(pos);
1263 intent.setSourceBounds(
1264 new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 startActivitySafely(intent);
1266 } else if (tag instanceof FolderInfo) {
1267 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001268 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001269 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001270 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001271 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001272 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001273 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001274 }
1275 }
1276
1277 void startActivitySafely(Intent intent) {
1278 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1279 try {
1280 startActivity(intent);
1281 } catch (ActivityNotFoundException e) {
1282 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1283 } catch (SecurityException e) {
1284 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001285 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1287 "or use the exported attribute for this activity.", e);
1288 }
1289 }
1290
1291 private void handleFolderClick(FolderInfo folderInfo) {
1292 if (!folderInfo.opened) {
1293 // Close any open folder
1294 closeFolder();
1295 // Open the requested folder
1296 openFolder(folderInfo);
1297 } else {
1298 // Find the open folder...
1299 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1300 int folderScreen;
1301 if (openFolder != null) {
1302 folderScreen = mWorkspace.getScreenForView(openFolder);
1303 // .. and close it
1304 closeFolder(openFolder);
1305 if (folderScreen != mWorkspace.getCurrentScreen()) {
1306 // Close any folder open on the current screen
1307 closeFolder();
1308 // Pull the folder onto this screen
1309 openFolder(folderInfo);
1310 }
1311 }
1312 }
1313 }
1314
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315 /**
1316 * Opens the user fodler described by the specified tag. The opening of the folder
1317 * is animated relative to the specified View. If the View is null, no animation
1318 * is played.
1319 *
1320 * @param folderInfo The FolderInfo describing the folder to open.
1321 */
1322 private void openFolder(FolderInfo folderInfo) {
1323 Folder openFolder;
1324
1325 if (folderInfo instanceof UserFolderInfo) {
1326 openFolder = UserFolder.fromXml(this);
1327 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001328 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329 } else {
1330 return;
1331 }
1332
Joe Onorato00acb122009-08-04 16:04:30 -04001333 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001334 openFolder.setLauncher(this);
1335
1336 openFolder.bind(folderInfo);
1337 folderInfo.opened = true;
1338
1339 mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4);
1340 openFolder.onOpen();
1341 }
1342
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001344 switch (v.getId()) {
1345 case R.id.previous_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001346 if (!isAllAppsVisible()) {
1347 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1348 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001349 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001350 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001351 return true;
1352 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001353 if (!isAllAppsVisible()) {
1354 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1355 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001356 showPreviews(v);
1357 }
1358 return true;
1359 case R.id.all_apps_button:
1360 if (!isAllAppsVisible()) {
1361 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1362 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1363 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001364 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001365 return true;
1366 }
1367
Joe Onorato9c1289c2009-08-17 11:03:03 -04001368 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369 return false;
1370 }
1371
1372 if (!(v instanceof CellLayout)) {
1373 v = (View) v.getParent();
1374 }
1375
1376 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
1377
1378 // This happens when long clicking an item with the dpad/trackball
1379 if (cellInfo == null) {
1380 return true;
1381 }
1382
1383 if (mWorkspace.allowLongPress()) {
1384 if (cellInfo.cell == null) {
1385 if (cellInfo.valid) {
1386 // User long pressed on empty space
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001387 mWorkspace.setAllowLongPress(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388 showAddDialog(cellInfo);
1389 }
1390 } else {
1391 if (!(cellInfo.cell instanceof Folder)) {
1392 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001393 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1394 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001395 mWorkspace.startDrag(cellInfo);
1396 }
1397 }
1398 }
1399 return true;
1400 }
1401
Romain Guye6b8e2f2009-11-10 11:56:55 -08001402 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001403 private void dismissPreview(final View v) {
1404 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001405 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001406 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1407 public void onDismiss() {
1408 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1409 int count = group.getChildCount();
1410 for (int i = 0; i < count; i++) {
1411 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1412 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001413 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1414 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1415
1416 v.setTag(R.id.workspace, null);
1417 v.setTag(R.id.icon, null);
1418 window.setOnDismissListener(null);
1419 }
1420 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001421 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001422 }
1423 v.setTag(null);
1424 }
1425
Romain Guyf8e6a802009-12-07 17:48:02 -08001426 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001427 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001428 }
1429
Romain Guya6abce82009-11-10 02:54:41 -08001430 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001431 final Resources resources = getResources();
1432 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001433
Romain Guya6abce82009-11-10 02:54:41 -08001434 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Romain Guy9d31e9f2009-11-11 18:54:28 -08001435
1436 float max = workspace.getChildCount();
Romain Guye6b8e2f2009-11-10 11:56:55 -08001437
Romain Guyf8e6a802009-12-07 17:48:02 -08001438 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001439 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001440 int extraW = (int) ((r.left + r.right) * max);
1441 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001442
1443 int aW = cell.getWidth() - extraW;
1444 float w = aW / max;
1445
1446 int width = cell.getWidth();
1447 int height = cell.getHeight();
1448 int x = cell.getLeftPadding();
1449 int y = cell.getTopPadding();
1450 width -= (x + cell.getRightPadding());
1451 height -= (y + cell.getBottomPadding());
1452
1453 float scale = w / width;
1454
1455 int count = end - start;
1456
1457 final float sWidth = width * scale;
1458 float sHeight = height * scale;
1459
Romain Guye6b8e2f2009-11-10 11:56:55 -08001460 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08001461
Romain Guye6b8e2f2009-11-10 11:56:55 -08001462 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
1463 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08001464
1465 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08001466 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08001467 cell = (CellLayout) workspace.getChildAt(i);
1468
Romain Guyf8e6a802009-12-07 17:48:02 -08001469 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08001470 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08001471
1472 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08001473 c.scale(scale, scale);
1474 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
1475 cell.dispatchDraw(c);
Romain Guya6abce82009-11-10 02:54:41 -08001476
Romain Guy9d31e9f2009-11-11 18:54:28 -08001477 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08001478 image.setImageBitmap(bitmap);
1479 image.setTag(i);
1480 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08001481 image.setOnFocusChangeListener(handler);
1482 image.setFocusable(true);
1483 if (i == mWorkspace.getCurrentScreen()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08001484
1485 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08001486 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
1487
1488 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08001489 }
Romain Guyf8e6a802009-12-07 17:48:02 -08001490
1491 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001492 p.setContentView(preview);
1493 p.setWidth((int) (sWidth * count + extraW));
1494 p.setHeight((int) (sHeight + extraH));
1495 p.setAnimationStyle(R.style.AnimationPreview);
1496 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08001497 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08001498 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08001499 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08001500
Romain Guye6b8e2f2009-11-10 11:56:55 -08001501 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
1502 public void onDismiss() {
1503 dismissPreview(anchor);
1504 }
1505 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001506
1507 anchor.setTag(p);
1508 anchor.setTag(R.id.workspace, preview);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001509 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08001510 }
1511
Romain Guy9d31e9f2009-11-11 18:54:28 -08001512 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08001513 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08001514
Romain Guye6b8e2f2009-11-10 11:56:55 -08001515 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08001516 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08001517 }
1518
1519 public void onClick(View v) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08001520 mWorkspace.snapToScreen((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08001521 v.post(this);
1522 }
1523
1524 public void run() {
1525 dismissPreview(mAnchor);
1526 }
1527
1528 public void onFocusChange(View v, boolean hasFocus) {
1529 if (hasFocus) {
Romain Guye47f55c2009-11-11 19:21:22 -08001530 mWorkspace.snapToScreen((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08001531 }
Romain Guya6abce82009-11-10 02:54:41 -08001532 }
1533 }
1534
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001535 Workspace getWorkspace() {
1536 return mWorkspace;
1537 }
1538
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001539 @Override
1540 protected Dialog onCreateDialog(int id) {
1541 switch (id) {
1542 case DIALOG_CREATE_SHORTCUT:
1543 return new CreateShortcut().createDialog();
1544 case DIALOG_RENAME_FOLDER:
1545 return new RenameFolder().createDialog();
1546 }
1547
1548 return super.onCreateDialog(id);
1549 }
1550
1551 @Override
1552 protected void onPrepareDialog(int id, Dialog dialog) {
1553 switch (id) {
1554 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555 break;
1556 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001557 if (mFolderInfo != null) {
1558 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1559 final CharSequence text = mFolderInfo.title;
1560 input.setText(text);
1561 input.setSelection(0, text.length());
1562 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 break;
1564 }
1565 }
1566
1567 void showRenameDialog(FolderInfo info) {
1568 mFolderInfo = info;
1569 mWaitingForResult = true;
1570 showDialog(DIALOG_RENAME_FOLDER);
1571 }
1572
1573 private void showAddDialog(CellLayout.CellInfo cellInfo) {
1574 mAddItemCellInfo = cellInfo;
1575 mWaitingForResult = true;
1576 showDialog(DIALOG_CREATE_SHORTCUT);
1577 }
1578
Romain Guy73b979d2009-06-09 12:57:21 -07001579 private void pickShortcut(int requestCode, int title) {
1580 Bundle bundle = new Bundle();
1581
1582 ArrayList<String> shortcutNames = new ArrayList<String>();
1583 shortcutNames.add(getString(R.string.group_applications));
1584 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
1585
1586 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
1587 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1588 R.drawable.ic_launcher_application));
1589 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1590
1591 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1592 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
1593 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title));
1594 pickIntent.putExtras(bundle);
1595
1596 startActivityForResult(pickIntent, requestCode);
1597 }
1598
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001599 private class RenameFolder {
1600 private EditText mInput;
1601
1602 Dialog createDialog() {
1603 mWaitingForResult = true;
1604 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1605 mInput = (EditText) layout.findViewById(R.id.folder_name);
1606
1607 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1608 builder.setIcon(0);
1609 builder.setTitle(getString(R.string.rename_folder_title));
1610 builder.setCancelable(true);
1611 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1612 public void onCancel(DialogInterface dialog) {
1613 cleanup();
1614 }
1615 });
1616 builder.setNegativeButton(getString(R.string.cancel_action),
1617 new Dialog.OnClickListener() {
1618 public void onClick(DialogInterface dialog, int which) {
1619 cleanup();
1620 }
1621 }
1622 );
1623 builder.setPositiveButton(getString(R.string.rename_action),
1624 new Dialog.OnClickListener() {
1625 public void onClick(DialogInterface dialog, int which) {
1626 changeFolderName();
1627 }
1628 }
1629 );
1630 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001631
1632 final AlertDialog dialog = builder.create();
1633 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1634 public void onShow(DialogInterface dialog) {
Joe Onoratod753b422009-11-08 13:31:11 -05001635 mInput.requestFocus();
1636 InputMethodManager inputManager = (InputMethodManager)
1637 getSystemService(Context.INPUT_METHOD_SERVICE);
1638 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001639 }
1640 });
1641
1642 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001643 }
1644
1645 private void changeFolderName() {
1646 final String name = mInput.getText().toString();
1647 if (!TextUtils.isEmpty(name)) {
1648 // Make sure we have the right folder info
Joe Onorato9c1289c2009-08-17 11:03:03 -04001649 mFolderInfo = mFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001650 mFolderInfo.title = name;
1651 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1652
Joe Onorato9c1289c2009-08-17 11:03:03 -04001653 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001654 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001655 mModel.setWorkspaceDirty();
1656 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001657 } else {
1658 final FolderIcon folderIcon = (FolderIcon)
1659 mWorkspace.getViewForTag(mFolderInfo);
1660 if (folderIcon != null) {
1661 folderIcon.setText(name);
1662 getWorkspace().requestLayout();
1663 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001664 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001665 mModel.setWorkspaceDirty();
1666 mWorkspaceLoading = true;
1667 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001668 }
1669 }
1670 }
1671 cleanup();
1672 }
1673
1674 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001675 dismissDialog(DIALOG_RENAME_FOLDER);
1676 mWaitingForResult = false;
1677 mFolderInfo = null;
1678 }
1679 }
1680
Joe Onoratofb0ca672009-09-14 17:55:46 -04001681 boolean isAllAppsVisible() {
Joe Onorato7bb17492009-09-24 17:51:01 -07001682 return mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04001683 }
1684
Joe Onorato3a8820b2009-11-10 15:06:42 -08001685 void showAllApps(boolean animated) {
1686 mAllAppsGrid.zoom(1.0f, animated);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001687
Mike Cleronb6082fa2009-10-19 17:03:36 -07001688 mAllAppsGrid.setFocusable(true);
Mike Clerona0618e42009-10-22 13:55:21 -07001689 mAllAppsGrid.requestFocus();
Mike Cleronb6082fa2009-10-19 17:03:36 -07001690
Joe Onorato7c312c12009-08-13 21:36:53 -07001691 // TODO: fade these two too
1692 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04001693 }
1694
Joe Onoratob2061212009-11-24 16:13:54 -05001695 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08001696 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05001697 * - Home from workspace
1698 * - from center screen
1699 * - from other screens
1700 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001701 * - from center screen
1702 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05001703 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001704 * - from center screen
1705 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05001706 * - Launch app from workspace and quit
1707 * - with back
1708 * - with home
1709 * - Launch app from all apps and quit
1710 * - with back
1711 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08001712 * - Go to a screen that's not the default, then all
1713 * apps, and launch and app, and go back
1714 * - with back
1715 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05001716 * - On workspace, long press power and go back
1717 * - with back
1718 * - with home
1719 * - On all apps, long press power and go back
1720 * - with back
1721 * - with home
1722 * - On workspace, power off
1723 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08001724 * - Launch an app and turn off the screen while in that app
1725 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001726 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08001727 * - From all apps
1728 * - From workspace
Joe Onoratob2061212009-11-24 16:13:54 -05001729 */
Joe Onorato7bb17492009-09-24 17:51:01 -07001730 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001731 if (mAllAppsGrid.isVisible()) {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001732 mAllAppsGrid.zoom(0.0f, animated);
Mike Cleronb6082fa2009-10-19 17:03:36 -07001733 mAllAppsGrid.setFocusable(false);
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001734 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07001735 }
Joe Onorato7404ee42009-07-31 11:54:44 -07001736 }
1737
Joe Onorato7c312c12009-08-13 21:36:53 -07001738 void lockAllApps() {
1739 // TODO
1740 }
1741
1742 void unlockAllApps() {
1743 // TODO
1744 }
1745
Joe Onorato7404ee42009-07-31 11:54:44 -07001746 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747 * Displays the shortcut creation dialog and launches, if necessary, the
1748 * appropriate activity.
1749 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001750 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07001751 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
1752 DialogInterface.OnShowListener {
1753
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001754 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07001755
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001756 Dialog createDialog() {
1757 mWaitingForResult = true;
Romain Guycbb89e42009-06-08 15:52:54 -07001758
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001759 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07001760
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001761 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1762 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001763 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07001764
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001765 builder.setInverseBackgroundForced(true);
1766
1767 AlertDialog dialog = builder.create();
1768 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07001769 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07001770 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001771
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772 return dialog;
1773 }
1774
1775 public void onCancel(DialogInterface dialog) {
1776 mWaitingForResult = false;
1777 cleanup();
1778 }
1779
Romain Guycbb89e42009-06-08 15:52:54 -07001780 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07001781 }
1782
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001783 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08001784 try {
1785 dismissDialog(DIALOG_CREATE_SHORTCUT);
1786 } catch (Exception e) {
1787 // An exception is thrown if the dialog is not visible, which is fine
1788 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789 }
1790
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001791 /**
1792 * Handle the action clicked in the "Add to home" dialog.
1793 */
1794 public void onClick(DialogInterface dialog, int which) {
1795 Resources res = getResources();
1796 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07001797
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001798 switch (which) {
1799 case AddAdapter.ITEM_SHORTCUT: {
1800 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07001801 pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001802 break;
1803 }
Romain Guycbb89e42009-06-08 15:52:54 -07001804
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001805 case AddAdapter.ITEM_APPWIDGET: {
1806 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07001807
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001808 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
1809 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001810 // start the pick activity
1811 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
1812 break;
1813 }
Romain Guycbb89e42009-06-08 15:52:54 -07001814
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001815 case AddAdapter.ITEM_LIVE_FOLDER: {
1816 // Insert extra item to handle inserting folder
1817 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07001818
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001819 ArrayList<String> shortcutNames = new ArrayList<String>();
1820 shortcutNames.add(res.getString(R.string.group_folder));
1821 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07001822
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001823 ArrayList<ShortcutIconResource> shortcutIcons =
1824 new ArrayList<ShortcutIconResource>();
1825 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1826 R.drawable.ic_launcher_folder));
1827 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1828
1829 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1830 pickIntent.putExtra(Intent.EXTRA_INTENT,
1831 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
1832 pickIntent.putExtra(Intent.EXTRA_TITLE,
1833 getText(R.string.title_select_live_folder));
1834 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07001835
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001836 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
1837 break;
1838 }
1839
1840 case AddAdapter.ITEM_WALLPAPER: {
1841 startWallpaper();
1842 break;
1843 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 }
1845 }
Romain Guy7b4ef332009-07-14 13:58:08 -07001846
1847 public void onShow(DialogInterface dialog) {
Romain Guy7b4ef332009-07-14 13:58:08 -07001848 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 }
1850
1851 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001852 * Receives notifications when applications are added/removed.
1853 */
1854 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
1855 @Override
1856 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001857 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05001858 String reason = intent.getStringExtra("reason");
1859 if (!"homekey".equals(reason)) {
1860 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001861 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05001862 animate = false;
1863 }
Joe Onoratob2061212009-11-24 16:13:54 -05001864 closeAllApps(animate);
1865 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001866 }
1867 }
1868
1869 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001870 * Receives notifications whenever the appwidgets are reset.
1871 */
1872 private class AppWidgetResetObserver extends ContentObserver {
1873 public AppWidgetResetObserver() {
1874 super(new Handler());
1875 }
1876
1877 @Override
1878 public void onChange(boolean selfChange) {
1879 onAppWidgetReset();
1880 }
1881 }
1882
1883 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001884 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001885 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001886 public int getCurrentWorkspaceScreen() {
1887 return mWorkspace.getCurrentScreen();
1888 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001889
Joe Onorato9c1289c2009-08-17 11:03:03 -04001890 /**
1891 * Refreshes the shortcuts shown on the workspace.
1892 *
1893 * Implementation of the method from LauncherModel.Callbacks.
1894 */
1895 public void startBinding() {
1896 final Workspace workspace = mWorkspace;
1897 int count = workspace.getChildCount();
1898 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04001899 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04001900 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
1901 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001902
Joe Onorato9c1289c2009-08-17 11:03:03 -04001903 if (DEBUG_USER_INTERFACE) {
1904 android.widget.Button finishButton = new android.widget.Button(this);
1905 finishButton.setText("Finish");
1906 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
1907
1908 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
1909 public void onClick(View v) {
1910 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001911 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001912 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001913 }
1914 }
1915
1916 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001917 * Bind the items start-end from the list.
1918 *
1919 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001921 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
1922
1923 final Workspace workspace = mWorkspace;
1924
1925 for (int i=start; i<end; i++) {
1926 final ItemInfo item = shortcuts.get(i);
1927 mDesktopItems.add(item);
1928 switch (item.itemType) {
1929 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1930 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08001931 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001932 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
1933 false);
1934 break;
1935 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
1936 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1937 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1938 (UserFolderInfo) item);
1939 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
1940 false);
1941 break;
1942 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
1943 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
1944 R.layout.live_folder_icon, this,
1945 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
1946 (LiveFolderInfo) item);
1947 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
1948 false);
1949 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001950 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951 }
1952
Joe Onorato9c1289c2009-08-17 11:03:03 -04001953 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954 }
1955
Joe Onorato9c1289c2009-08-17 11:03:03 -04001956 /**
1957 * Implementation of the method from LauncherModel.Callbacks.
1958 */
Joe Onoratoad72e172009-11-06 16:25:04 -05001959 public void bindFolders(HashMap<Long, FolderInfo> folders) {
1960 mFolders.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001961 mFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001963
1964 /**
1965 * Add the views for a widget to the workspace.
1966 *
1967 * Implementation of the method from LauncherModel.Callbacks.
1968 */
1969 public void bindAppWidget(LauncherAppWidgetInfo item) {
1970 final Workspace workspace = mWorkspace;
1971
1972 final int appWidgetId = item.appWidgetId;
1973 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1974 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1975
Joe Onorato9c1289c2009-08-17 11:03:03 -04001976 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1977 item.hostView.setTag(item);
1978
1979 workspace.addInScreen(item.hostView, item.screen, item.cellX,
1980 item.cellY, item.spanX, item.spanY, false);
1981
1982 workspace.requestLayout();
1983
1984 mDesktopItems.add(item);
1985 }
1986
1987 /**
1988 * Callback saying that there aren't any more items to bind.
1989 *
1990 * Implementation of the method from LauncherModel.Callbacks.
1991 */
1992 public void finishBindingItems() {
1993 if (mSavedState != null) {
1994 if (!mWorkspace.hasFocus()) {
1995 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
1996 }
1997
1998 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
1999 if (userFolders != null) {
2000 for (long folderId : userFolders) {
2001 final FolderInfo info = mFolders.get(folderId);
2002 if (info != null) {
2003 openFolder(info);
2004 }
2005 }
2006 final Folder openFolder = mWorkspace.getOpenFolder();
2007 if (openFolder != null) {
2008 openFolder.requestFocus();
2009 }
2010 }
2011
Joe Onorato9c1289c2009-08-17 11:03:03 -04002012 mSavedState = null;
2013 }
2014
2015 if (mSavedInstanceState != null) {
2016 super.onRestoreInstanceState(mSavedInstanceState);
2017 mSavedInstanceState = null;
2018 }
2019
Joe Onorato9c1289c2009-08-17 11:03:03 -04002020 mWorkspaceLoading = false;
2021 }
2022
2023 /**
2024 * Add the icons for all apps.
2025 *
2026 * Implementation of the method from LauncherModel.Callbacks.
2027 */
2028 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08002029 mAllAppsGrid.setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002030 }
2031
2032 /**
2033 * A package was installed.
2034 *
2035 * Implementation of the method from LauncherModel.Callbacks.
2036 */
2037 public void bindPackageAdded(ArrayList<ApplicationInfo> apps) {
2038 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002039 mAllAppsGrid.addApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002040 }
2041
2042 /**
2043 * A package was updated.
2044 *
2045 * Implementation of the method from LauncherModel.Callbacks.
2046 */
2047 public void bindPackageUpdated(String packageName, ArrayList<ApplicationInfo> apps) {
2048 removeDialog(DIALOG_CREATE_SHORTCUT);
2049 mWorkspace.updateShortcutsForPackage(packageName);
Joe Onoratof0be2132009-11-24 19:34:29 -05002050 mAllAppsGrid.updateApps(packageName, apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002051 }
2052
2053 /**
2054 * A package was uninstalled.
2055 *
2056 * Implementation of the method from LauncherModel.Callbacks.
2057 */
2058 public void bindPackageRemoved(String packageName, ArrayList<ApplicationInfo> apps) {
2059 removeDialog(DIALOG_CREATE_SHORTCUT);
Romain Guy5c16f3e2010-01-12 17:24:58 -08002060 mWorkspace.removeItemsForPackage(packageName);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002061 mAllAppsGrid.removeApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002062 }
Joe Onoratobe386092009-11-17 17:32:16 -08002063
2064 /**
2065 * Prints out out state for debugging.
2066 */
2067 public void dumpState() {
2068 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08002069 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08002070 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
2071 Log.d(TAG, "mRestoring=" + mRestoring);
2072 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
2073 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
2074 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
2075 Log.d(TAG, "mFolders.size=" + mFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08002076 mModel.dumpState();
2077 mAllAppsGrid.dumpState();
2078 Log.d(TAG, "END launcher2 dump state");
2079 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002080}