blob: 1a486d705b54be0f33c5bdd861d0df10b468502f [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Winson Chung68846fd2010-10-29 11:00:27 -070020import java.io.DataInputStream;
21import java.io.DataOutputStream;
22import java.io.FileNotFoundException;
23import java.io.IOException;
24import java.util.ArrayList;
25import java.util.HashMap;
26import java.util.List;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070027
Gilles Debunnedd6c9922010-10-25 11:23:41 -070028import android.animation.Animator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070029import android.animation.AnimatorSet;
Chet Haaseb1254a62010-09-07 13:35:00 -070030import android.animation.ObjectAnimator;
Patrick Dubroy07a0de42010-08-26 11:48:35 -070031import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070032import android.animation.ValueAnimator;
Michael Jurka946ad472010-07-09 18:05:18 -070033import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.app.Dialog;
36import android.app.SearchManager;
37import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070038import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070039import android.appwidget.AppWidgetManager;
40import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080042import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070043import android.content.ClipData;
44import android.content.ClipDescription;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040045import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080046import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.Context;
48import android.content.DialogInterface;
49import android.content.Intent;
Winson Chung68846fd2010-10-29 11:00:27 -070050import android.content.IntentFilter;
Adam Cohended9f8d2010-11-03 13:25:16 -070051import android.content.Intent.ShortcutIconResource;
Winson Chungaafa03c2010-06-11 17:34:16 -070052import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053import android.content.pm.PackageManager;
Winson Chung68846fd2010-10-29 11:00:27 -070054import android.content.pm.ResolveInfo;
Adam Cohended9f8d2010-11-03 13:25:16 -070055import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070057import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040058import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080059import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080061import android.graphics.Canvas;
Michael Jurkaaf442092010-06-10 17:01:57 -070062import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080063import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070064import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040065import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070066import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020068import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080069import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070070import android.os.Message;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040072import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080073import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070074import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070075import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080076import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077import android.text.Selection;
78import android.text.SpannableStringBuilder;
79import android.text.TextUtils;
80import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070081import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080083import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080084import android.view.KeyEvent;
85import android.view.LayoutInflater;
86import android.view.Menu;
87import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070088import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.view.View;
90import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070091import android.view.WindowManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070092import android.view.View.OnLongClickListener;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070093import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070094import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070096import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070098import android.widget.ImageView;
99import android.widget.LinearLayout;
100import android.widget.PopupWindow;
Michael Jurka0e260592010-06-30 17:07:39 -0700101import android.widget.TabHost;
Winson Chung68846fd2010-10-29 11:00:27 -0700102import android.widget.TextView;
103import android.widget.Toast;
Adam Cohended9f8d2010-11-03 13:25:16 -0700104import android.widget.TabHost.OnTabChangeListener;
105import android.widget.TabHost.TabContentFactory;
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700106
Winson Chung68846fd2010-10-29 11:00:27 -0700107import com.android.common.Search;
108import com.android.launcher.R;
Romain Guyedcce092010-03-04 13:03:17 -0800109
Adam Cohended9f8d2010-11-03 13:25:16 -0700110
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111/**
112 * Default launcher application.
113 */
Michael Jurka946ad472010-07-09 18:05:18 -0700114public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700115 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
116 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800117 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700118 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119
Joe Onorato9c1289c2009-08-17 11:03:03 -0400120 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400121 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400122 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700123
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800125 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
126
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700128 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
129 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
131 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700132 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133
134 private static final int REQUEST_CREATE_SHORTCUT = 1;
135 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
139 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700140 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700141 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142
143 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
144
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800145 static final int SCREEN_COUNT = 5;
146 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147
Joe Onorato7c312c12009-08-13 21:36:53 -0700148 static final int DIALOG_CREATE_SHORTCUT = 1;
149 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
Romain Guy98d01652009-06-30 16:21:04 -0700151 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152
153 // Type: int
154 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700155 // Type: int
156 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157 // Type: long
158 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
159 // Type: int
160 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
161 // Type: int
162 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
163 // Type: int
164 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: boolean
166 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
167 // Type: long
168 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
169
Winson Chung80baf5a2010-08-09 16:03:15 -0700170 // tags for the customization tabs
171 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700172 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700173 private static final String SHORTCUTS_TAG = "shortcuts";
174 private static final String WALLPAPERS_TAG = "wallpapers";
175
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700176 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
177
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700178 /** The different states that Launcher can be in. */
179 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700180 private State mState = State.WORKSPACE;
181 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700182
Joe Onorato9c1289c2009-08-17 11:03:03 -0400183 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800186 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800188 private final BroadcastReceiver mCloseSystemDialogsReceiver
189 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800190 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
191
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 private LayoutInflater mInflater;
193
Joe Onorato00acb122009-08-04 16:04:30 -0400194 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700196
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700197 private AppWidgetManager mAppWidgetManager;
198 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700199
Michael Jurka0280c3b2010-09-17 15:00:07 -0700200 private int mAddScreen = -1;
201 private int mAddIntersectCellX = -1;
202 private int mAddIntersectCellY = -1;
203 private int[] mAddDropPosition;
204 private int[] mTmpAddItemCellCoordinates = new int[2];
205
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206 private FolderInfo mFolderInfo;
207
Joe Onorato7c312c12009-08-13 21:36:53 -0700208 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700209 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700210 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700211 private TabHost mHomeCustomizationDrawer;
Adam Cohended9f8d2010-11-03 13:25:16 -0700212 private boolean mAutoAdvanceRunning = false;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700213
214 private PagedView mAllAppsPagedView = null;
215 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217 private Bundle mSavedState;
218
219 private SpannableStringBuilder mDefaultKeySsb = null;
220
Joe Onorato9c1289c2009-08-17 11:03:03 -0400221 private boolean mWorkspaceLoading = true;
222
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800223 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224 private boolean mRestoring;
225 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700226 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800227
228 private Bundle mSavedInstanceState;
229
Joe Onorato9c1289c2009-08-17 11:03:03 -0400230 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800231 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800232 private boolean mUserPresent = true;
233 private boolean mVisible = false;
234 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400235
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700236 private static LocaleConfiguration sLocaleConfiguration = null;
237
Romain Guy84f296c2009-11-04 15:00:44 -0800238 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700239
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700240 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700241
Romain Guy1fbc1c82009-11-09 20:43:08 -0800242 private ImageView mPreviousView;
243 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500244
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400245 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400246 private String[] mHotseatConfig = null;
247 private Intent[] mHotseats = null;
248 private Drawable[] mHotseatIcons = null;
249 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400250
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700251 private Intent mAppMarketIntent = null;
252
Adam Cohended9f8d2010-11-03 13:25:16 -0700253 // Related to the auto-advancing of widgets
254 private final int ADVANCE_MSG = 1;
255 private final int mAdvanceInterval = 20000;
256 private final int mAdvanceStagger = 250;
257 private long mAutoAdvanceSentTime;
258 private long mAutoAdvanceTimeLeft = -1;
259 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
260 new HashMap<View, AppWidgetProviderInfo>();
261
Michael Jurka4ef207b2010-11-29 17:05:45 -0800262 // External icons saved in case of resource changes, orientation, etc.
263 private static Drawable sGlobalSearchIcon;
264 private static Drawable sVoiceSearchIcon;
265 private static Drawable sAppMarketIcon;
266
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 @Override
268 protected void onCreate(Bundle savedInstanceState) {
269 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700270
Winson Chungaafa03c2010-06-11 17:34:16 -0700271 if (LauncherApplication.isInPlaceRotationEnabled()) {
272 // hide the status bar (temporary until we get the status bar design figured out)
273 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
274 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
275 }
276
Joe Onorato0589f0f2010-02-08 13:44:00 -0800277 LauncherApplication app = ((LauncherApplication)getApplication());
278 mModel = app.setLauncher(this);
279 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400280 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800281 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700282
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700283 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700284 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
285 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700286
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200288 android.os.Debug.startMethodTracing(
289 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800290 }
291
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400292 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800293 checkForLocaleChange();
294 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700296 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
297 if (mHomeCustomizationDrawer != null) {
298 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700299
Winson Chung80baf5a2010-08-09 16:03:15 -0700300 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700301 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
302 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700303 TabContentFactory contentFactory = new TabContentFactory() {
304 public View createTabContent(String tag) {
305 return mCustomizePagedView;
306 }
307 };
308
Michael Jurka946ad472010-07-09 18:05:18 -0700309 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700310 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
311 .setIndicator(widgetsLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700312 String applicationsLabel = getString(R.string.applications_tab_label);
313 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
314 .setIndicator(applicationsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700315 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700316 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
317 .setIndicator(wallpapersLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700318 String shortcutsLabel = getString(R.string.shortcuts_tab_label);
319 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
320 .setIndicator(shortcutsLabel).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700321 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
322 public void onTabChanged(String tabId) {
323 // animate the changing of the tab content by fading pages in and out
Winson Chungbbc60d82010-11-11 16:34:41 -0800324 final Resources res = getResources();
325 final int duration = res.getInteger(R.integer.config_tabTransitionTime);
Winson Chung80baf5a2010-08-09 16:03:15 -0700326 final float alpha = mCustomizePagedView.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700327 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700328 "alpha", alpha, 0.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700329 alphaAnim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700330 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700331 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700332 public void onAnimationEndOrCancel(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700333 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
334 if (tag == WIDGETS_TAG) {
335 mCustomizePagedView.setCustomizationFilter(
336 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700337 } else if (tag == APPLICATIONS_TAG) {
338 mCustomizePagedView.setCustomizationFilter(
339 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700340 } else if (tag == WALLPAPERS_TAG) {
341 mCustomizePagedView.setCustomizationFilter(
342 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700343 } else if (tag == SHORTCUTS_TAG) {
344 mCustomizePagedView.setCustomizationFilter(
345 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700346 }
347
348 final float alpha = mCustomizePagedView.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700349 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700350 mCustomizePagedView, "alpha", alpha, 1.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700351 alphaAnim.setDuration(duration);
Winson Chung80baf5a2010-08-09 16:03:15 -0700352 alphaAnim.start();
353 }
354 });
355 alphaAnim.start();
356 }
357 });
Michael Jurka946ad472010-07-09 18:05:18 -0700358 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359 setupViews();
360
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800361 registerContentObservers();
362
Joe Onorato7c312c12009-08-13 21:36:53 -0700363 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700364
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800365 mSavedState = savedInstanceState;
366 restoreState(mSavedState);
367
368 if (PROFILE_STARTUP) {
369 android.os.Debug.stopMethodTracing();
370 }
371
372 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400373 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800374 }
375
376 // For handling default keys
377 mDefaultKeySsb = new SpannableStringBuilder();
378 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800379
380 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
381 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800382
383 // If we have a saved version of these external icons, we load them up immediately
384 if (LauncherApplication.isScreenXLarge()) {
385 if (sGlobalSearchIcon != null) {
386 updateGlobalSearchIcon(sGlobalSearchIcon);
387 }
388 if (sVoiceSearchIcon != null) {
389 updateVoiceSearchIcon(sVoiceSearchIcon);
390 }
391 if (sAppMarketIcon != null) {
392 updateAppMarketIcon(sAppMarketIcon);
393 }
394 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800395 }
Romain Guycbb89e42009-06-08 15:52:54 -0700396
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800397 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700398 if (sLocaleConfiguration == null) {
399 new AsyncTask<Void, Void, LocaleConfiguration>() {
400 @Override
401 protected LocaleConfiguration doInBackground(Void... unused) {
402 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
403 readConfiguration(Launcher.this, localeConfiguration);
404 return localeConfiguration;
405 }
406
407 @Override
408 protected void onPostExecute(LocaleConfiguration result) {
409 sLocaleConfiguration = result;
410 checkForLocaleChange(); // recursive, but now with a locale configuration
411 }
412 }.execute();
413 return;
414 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700415
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800416 final Configuration configuration = getResources().getConfiguration();
417
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700418 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 final String locale = configuration.locale.toString();
420
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700421 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 final int mcc = configuration.mcc;
423
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700424 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 final int mnc = configuration.mnc;
426
Romain Guy84f296c2009-11-04 15:00:44 -0800427 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428
Romain Guy84f296c2009-11-04 15:00:44 -0800429 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700430 sLocaleConfiguration.locale = locale;
431 sLocaleConfiguration.mcc = mcc;
432 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700433
Joe Onorato0589f0f2010-02-08 13:44:00 -0800434 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400435 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700436
437 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
438 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700439 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700440 public void run() {
441 writeConfiguration(Launcher.this, localeConfiguration);
442 }
443 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700444 }
445 }
446
447 private static class LocaleConfiguration {
448 public String locale;
449 public int mcc = -1;
450 public int mnc = -1;
451 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700452
Romain Guy98d01652009-06-30 16:21:04 -0700453 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
454 DataInputStream in = null;
455 try {
456 in = new DataInputStream(context.openFileInput(PREFERENCES));
457 configuration.locale = in.readUTF();
458 configuration.mcc = in.readInt();
459 configuration.mnc = in.readInt();
460 } catch (FileNotFoundException e) {
461 // Ignore
462 } catch (IOException e) {
463 // Ignore
464 } finally {
465 if (in != null) {
466 try {
467 in.close();
468 } catch (IOException e) {
469 // Ignore
470 }
471 }
472 }
473 }
474
475 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
476 DataOutputStream out = null;
477 try {
478 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
479 out.writeUTF(configuration.locale);
480 out.writeInt(configuration.mcc);
481 out.writeInt(configuration.mnc);
482 out.flush();
483 } catch (FileNotFoundException e) {
484 // Ignore
485 } catch (IOException e) {
486 //noinspection ResultOfMethodCallIgnored
487 context.getFileStreamPath(PREFERENCES).delete();
488 } finally {
489 if (out != null) {
490 try {
491 out.close();
492 } catch (IOException e) {
493 // Ignore
494 }
495 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800496 }
497 }
498
499 static int getScreen() {
500 synchronized (sLock) {
501 return sScreen;
502 }
503 }
504
505 static void setScreen(int screen) {
506 synchronized (sLock) {
507 sScreen = screen;
508 }
509 }
510
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800511 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700512 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800513
514 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700515 // TODO: Put back when we decide about scrolling the wallpaper
516 // boolean isPortrait = display.getWidth() < display.getHeight();
517 // final int width = isPortrait ? display.getWidth() : display.getHeight();
518 // final int height = isPortrait ? display.getHeight() : display.getWidth();
519 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
520 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800521 }
522
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400523 // Note: This doesn't do all the client-id magic that BrowserProvider does
524 // in Browser. (http://b/2425179)
525 private Uri getDefaultBrowserUri() {
526 String url = getString(R.string.default_browser_url);
527 if (url.indexOf("{CID}") != -1) {
528 url = url.replace("{CID}", "android-google");
529 }
530 return Uri.parse(url);
531 }
532
533 // Load the Intent templates from arrays.xml to populate the hotseats. For
534 // each Intent, if it resolves to a single app, use that as the launch
535 // intent & use that app's label as the contentDescription. Otherwise,
536 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400537 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400538 if (mHotseatConfig == null) {
539 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
540 if (mHotseatConfig.length > 0) {
541 mHotseats = new Intent[mHotseatConfig.length];
542 mHotseatLabels = new CharSequence[mHotseatConfig.length];
543 mHotseatIcons = new Drawable[mHotseatConfig.length];
544 } else {
545 mHotseats = null;
546 mHotseatIcons = null;
547 mHotseatLabels = null;
548 }
549
550 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
551 for (int i=0; i<mHotseatConfig.length; i++) {
552 // load icon for this slot; currently unrelated to the actual activity
553 try {
554 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
555 } catch (ArrayIndexOutOfBoundsException ex) {
556 Log.w(TAG, "Missing hotseat_icons array item #" + i);
557 mHotseatIcons[i] = null;
558 }
559 }
560 hotseatIconDrawables.recycle();
561 }
562
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400563 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400564 for (int i=0; i<mHotseatConfig.length; i++) {
565 Intent intent = null;
566 if (mHotseatConfig[i].equals("*BROWSER*")) {
567 // magic value meaning "launch user's default web browser"
568 // replace it with a generic web request so we can see if there is indeed a default
569 String defaultUri = getString(R.string.default_browser_url);
570 intent = new Intent(
571 Intent.ACTION_VIEW,
572 ((defaultUri != null)
573 ? Uri.parse(defaultUri)
574 : getDefaultBrowserUri())
575 ).addCategory(Intent.CATEGORY_BROWSABLE);
576 // note: if the user launches this without a default set, she
577 // will always be taken to the default URL above; this is
578 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700579 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400580 // URL is unavoidably sent to the chosen app.
581 } else {
582 try {
583 intent = Intent.parseUri(mHotseatConfig[i], 0);
584 } catch (java.net.URISyntaxException ex) {
585 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
586 // bogus; leave intent=null
587 }
588 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700589
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400590 if (intent == null) {
591 mHotseats[i] = null;
592 mHotseatLabels[i] = getText(R.string.activity_not_found);
593 continue;
594 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400595
596 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700597 Log.d(TAG, "loadHotseats: hotseat " + i
598 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400599 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400600 + "]");
601 }
602
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400603 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
604 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700605 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400606 Log.d(TAG, "Best match for intent: " + bestMatch);
607 Log.d(TAG, "All matches: ");
608 for (ResolveInfo ri : allMatches) {
609 Log.d(TAG, " --> " + ri);
610 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400611 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400612 // did this resolve to a single app, or the resolver?
613 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700614 // can't find any activity to handle this. let's leave the
615 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400616 // to launch.
617 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400618
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400619 // set accessibility text to "Not installed"
620 mHotseatLabels[i] = getText(R.string.activity_not_found);
621 } else {
622 boolean found = false;
623 for (ResolveInfo ri : allMatches) {
624 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
625 && bestMatch.activityInfo.applicationInfo.packageName
626 .equals(ri.activityInfo.applicationInfo.packageName)) {
627 found = true;
628 break;
629 }
630 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700631
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400632 if (!found) {
633 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
634 // the bestMatch is probably the ResolveActivity, meaning the
635 // user has not yet selected a default
636 // so: we'll keep the original intent for now
637 mHotseats[i] = intent;
638
639 // set the accessibility text to "Select shortcut"
640 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
641 } else {
642 // we have an app!
643 // now reconstruct the intent to launch it through the front
644 // door
645 ComponentName com = new ComponentName(
646 bestMatch.activityInfo.applicationInfo.packageName,
647 bestMatch.activityInfo.name);
648 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
649
650 // load the app label for accessibility
651 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
652 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400653 }
654
655 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700656 Log.d(TAG, "loadHotseats: hotseat " + i
657 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400658 + ((mHotseats[i] == null)
659 ? "null"
660 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400661 + "] label=[" + mHotseatLabels[i]
662 + "]"
663 );
664 }
665 }
666 }
667
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800668 @Override
669 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700670 mWaitingForResult = false;
671
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 // The pattern used here is that a user PICKs a specific application,
673 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700674
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
676 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700677
Michael Jurka0280c3b2010-09-17 15:00:07 -0700678 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800679 switch (requestCode) {
680 case REQUEST_PICK_APPLICATION:
Michael Jurka28750fb2010-09-24 17:43:49 -0700681 completeAddApplication(
682 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800683 break;
684 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800685 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800686 break;
687 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700688 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 break;
690 case REQUEST_PICK_LIVE_FOLDER:
691 addLiveFolder(data);
692 break;
693 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700694 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800695 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700696 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700697 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800698 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700699 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700700 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700701 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800702 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700703 case REQUEST_PICK_WALLPAPER:
704 // We just wanted the activity result here so we can clear mWaitingForResult
705 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706 }
Romain Guy18042c82009-11-06 11:44:55 -0800707 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
708 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
709 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700710 // Clean up the appWidgetId if we canceled
711 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
712 if (appWidgetId != -1) {
713 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800714 }
715 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800716 }
717
718 @Override
719 protected void onResume() {
720 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800721 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700722 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400723 mWorkspaceLoading = true;
724 mModel.startLoader(this, true);
725 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700726 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800727 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700728 // When we resume Launcher, a different Activity might be responsible for the app
729 // market intent, so refresh the icon
730 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800731 }
732
733 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700734 protected void onPause() {
735 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700736 // Some launcher layouts don't have a previous and next view
737 if (mPreviousView != null) {
738 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700739 }
740 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700741 dismissPreview(mNextView);
742 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700743 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800744 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700745 }
Romain Guycbb89e42009-06-08 15:52:54 -0700746
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700747 @Override
748 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400749 // Flag the loader to stop early before switching
750 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800751 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800752 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700753 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700754
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800755 // We can't hide the IME if it was forced open. So don't bother
756 /*
757 @Override
758 public void onWindowFocusChanged(boolean hasFocus) {
759 super.onWindowFocusChanged(hasFocus);
760
761 if (hasFocus) {
762 final InputMethodManager inputManager = (InputMethodManager)
763 getSystemService(Context.INPUT_METHOD_SERVICE);
764 WindowManager.LayoutParams lp = getWindow().getAttributes();
765 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
766 android.os.Handler()) {
767 protected void onReceiveResult(int resultCode, Bundle resultData) {
768 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
769 }
770 });
771 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
772 }
773 }
774 */
775
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800776 private boolean acceptFilter() {
777 final InputMethodManager inputManager = (InputMethodManager)
778 getSystemService(Context.INPUT_METHOD_SERVICE);
779 return !inputManager.isFullscreenMode();
780 }
781
782 @Override
783 public boolean onKeyDown(int keyCode, KeyEvent event) {
784 boolean handled = super.onKeyDown(keyCode, event);
785 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
786 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
787 keyCode, event);
788 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700789 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700790 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700791 // showSearchDialog()
792 // If there are multiple keystrokes before the search dialog takes focus,
793 // onSearchRequested() will be called for every keystroke,
794 // but it is idempotent, so it's fine.
795 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800796 }
797 }
798
Joe Onorato8a9625e2010-01-28 15:55:35 -0800799 // Eat the long press event so the keyboard doesn't come up.
800 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
801 return true;
802 }
803
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800804 return handled;
805 }
806
Karl Rosaen138a0412009-04-23 19:00:21 -0700807 private String getTypedText() {
808 return mDefaultKeySsb.toString();
809 }
810
811 private void clearTypedText() {
812 mDefaultKeySsb.clear();
813 mDefaultKeySsb.clearSpans();
814 Selection.setSelection(mDefaultKeySsb, 0);
815 }
816
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700818 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
819 * State
820 */
821 private static State intToState(int stateOrdinal) {
822 State state = State.WORKSPACE;
823 final State[] stateValues = State.values();
824 for (int i = 0; i < stateValues.length; i++) {
825 if (stateValues[i].ordinal() == stateOrdinal) {
826 state = stateValues[i];
827 break;
828 }
829 }
830 return state;
831 }
832
833 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800834 * Restores the previous state, if it exists.
835 *
836 * @param savedState The previous state.
837 */
838 private void restoreState(Bundle savedState) {
839 if (savedState == null) {
840 return;
841 }
842
Michael Jurka883f55b2010-10-21 15:47:14 -0700843 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
844
845 if (state == State.ALL_APPS) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800846 showAllApps(false);
Michael Jurka883f55b2010-10-21 15:47:14 -0700847 } else if (state == State.CUSTOMIZE) {
848 showCustomizationDrawer(false);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800849 }
850
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800851 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
852 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700853 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 }
855
856 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700857
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800858 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700859 mAddScreen = addScreen;
860 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
861 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800862 mRestoring = true;
863 }
864
865 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
866 if (renameFolder) {
867 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700868 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800869 mRestoring = true;
870 }
871 }
872
873 /**
874 * Finds all the views we need and configure them properly.
875 */
876 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700877 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400878
Romain Guyb1b69f52009-08-10 15:10:15 -0700879 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400880 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800881
Joe Onorato7c312c12009-08-13 21:36:53 -0700882 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700883 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700884 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800885 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700886 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700887 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700888
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700889 if (LauncherApplication.isScreenXLarge()) {
890 // They need to be INVISIBLE initially so that they will be measured in the layout.
891 // Otherwise the animations are messed up when we show them for the first time.
892 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
893 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
894 }
895
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
Adam Lesinski6b879f02010-11-04 16:15:23 -0700897
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500899 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700900
Joe Onorato7c312c12009-08-13 21:36:53 -0700901 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
902 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800903
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700904 View handleView = findViewById(R.id.all_apps_button);
905 if (handleView != null && handleView instanceof HandleView) {
906 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700907 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700908 mHandleView.setLauncher(this);
909 mHandleView.setOnClickListener(this);
910 mHandleView.setOnLongClickListener(this);
911 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800912
Winson Chung80baf5a2010-08-09 16:03:15 -0700913 if (mCustomizePagedView != null) {
914 mCustomizePagedView.setLauncher(this);
915 mCustomizePagedView.setDragController(dragController);
916 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700917 } else {
918 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
919 hotseatLeft.setContentDescription(mHotseatLabels[0]);
920 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
921 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
922 hotseatRight.setContentDescription(mHotseatLabels[1]);
923 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400924
Michael Jurkaaf442092010-06-10 17:01:57 -0700925 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
926 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800927
Michael Jurkaaf442092010-06-10 17:01:57 -0700928 Drawable previous = mPreviousView.getDrawable();
929 Drawable next = mNextView.getDrawable();
930 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800931
Michael Jurkaaf442092010-06-10 17:01:57 -0700932 mPreviousView.setHapticFeedbackEnabled(false);
933 mPreviousView.setOnLongClickListener(this);
934 mNextView.setHapticFeedbackEnabled(false);
935 mNextView.setOnLongClickListener(this);
936 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800937
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800938 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400939 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800940 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800941
942 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400943 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700944 int deleteZoneHandleId;
945 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700946 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700947 } else {
948 deleteZoneHandleId = R.id.all_apps_button_cluster;
949 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700950 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700951 dragController.addDragListener(deleteZone);
952
953 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
954 if (infoButton != null) {
955 infoButton.setLauncher(this);
956 infoButton.setHandle(findViewById(R.id.configure_button));
957 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
958 dragController.addDragListener(infoButton);
959 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800960
Joe Onorato00acb122009-08-04 16:04:30 -0400961 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400962 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800963 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700964
Joe Onorato00acb122009-08-04 16:04:30 -0400965 // The order here is bottom to top.
966 dragController.addDropTarget(workspace);
967 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700968 if (infoButton != null) {
969 dragController.addDropTarget(infoButton);
970 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800971 }
972
Romain Guy8a73c512009-11-09 19:19:59 -0800973 @SuppressWarnings({"UnusedDeclaration"})
974 public void previousScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700975 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800976 mWorkspace.scrollLeft();
977 }
Romain Guy8a73c512009-11-09 19:19:59 -0800978 }
979
980 @SuppressWarnings({"UnusedDeclaration"})
981 public void nextScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700982 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800983 mWorkspace.scrollRight();
984 }
Romain Guy8a73c512009-11-09 19:19:59 -0800985 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400986
987 @SuppressWarnings({"UnusedDeclaration"})
988 public void launchHotSeat(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700989 if (mState == State.ALL_APPS) return;
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400990
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400991 int index = -1;
992 if (v.getId() == R.id.hotseat_left) {
993 index = 0;
994 } else if (v.getId() == R.id.hotseat_right) {
995 index = 1;
996 }
997
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400998 // reload these every tap; you never know when they might change
999 loadHotseats();
1000 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
1001 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001002 startActivitySafely(
1003 mHotseats[index],
1004 "hotseat"
1005 );
1006 }
1007 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001008
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001009 /**
1010 * Creates a view representing a shortcut.
1011 *
1012 * @param info The data structure describing the shortcut.
1013 *
1014 * @return A View inflated from R.layout.application.
1015 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001016 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001017 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001018 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001019 }
1020
1021 /**
1022 * Creates a view representing a shortcut inflated from the specified resource.
1023 *
1024 * @param layoutResId The id of the XML layout used to create the shortcut.
1025 * @param parent The group the shortcut belongs to.
1026 * @param info The data structure describing the shortcut.
1027 *
1028 * @return A View inflated from layoutResId.
1029 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001030 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001031 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
1032
Patrick Dubroy9e482382010-11-01 15:16:13 -07001033 Bitmap b = info.getIcon(mIconCache);
1034
Joe Onorato0589f0f2010-02-08 13:44:00 -08001035 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
Winson Chung0e41ae62010-10-27 18:10:32 -07001036 new FastBitmapDrawable(b),
Joe Onorato0589f0f2010-02-08 13:44:00 -08001037 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001038 favorite.setText(info.title);
1039 favorite.setTag(info);
1040 favorite.setOnClickListener(this);
1041
1042 return favorite;
1043 }
1044
1045 /**
1046 * Add an application shortcut to the workspace.
1047 *
1048 * @param data The intent describing the application.
1049 * @param cellInfo The position on screen where to create the shortcut.
1050 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001051 void completeAddApplication(Context context, Intent data, int screen,
1052 int intersectCellX, int intersectCellY) {
1053 final int[] cellXY = mTmpAddItemCellCoordinates;
1054 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1055
1056 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1057 showOutOfSpaceMessage();
1058 return;
1059 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060
Joe Onorato0589f0f2010-02-08 13:44:00 -08001061 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1062 data, context);
1063
Romain Guy73b979d2009-06-09 12:57:21 -07001064 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001065 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001066 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001067 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001068 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1069 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001070 } else {
1071 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001072 }
1073 }
Romain Guycbb89e42009-06-08 15:52:54 -07001074
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001075 /**
1076 * Add a shortcut to the workspace.
1077 *
1078 * @param data The intent describing the shortcut.
1079 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001081 private void completeAddShortcut(Intent data, int screen,
1082 int intersectCellX, int intersectCellY) {
1083 final int[] cellXY = mTmpAddItemCellCoordinates;
1084 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001085
Michael Jurka0280c3b2010-09-17 15:00:07 -07001086 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1087 showOutOfSpaceMessage();
1088 return;
1089 }
1090
1091 final ShortcutInfo info = mModel.addShortcut(
1092 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001093
1094 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001095 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001096 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001097 }
1098 }
1099
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001100 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001101 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001102 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001103 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001104 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001106 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001107 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001108
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001109 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001110 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1111 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001112
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001114 // We have saved the position to which the widget was dragged-- this really only matters
1115 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001116 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001117
1118 // For now, we don't save the coordinate where we dropped the icon because we're not
1119 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1120 // a widget on the home screen in case we want to add it in the future
Winson Chung55cef262010-10-28 14:14:18 -07001121 int[] touchXY = null;
Michael Jurka9c6de3d2010-11-23 16:23:58 -08001122 if (mAddDropPosition != null && mAddDropPosition[0] > -1 && mAddDropPosition[1] > -1) {
Winson Chung55cef262010-10-28 14:14:18 -07001123 touchXY = mAddDropPosition;
1124 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001125 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001126 boolean foundCellSpan = false;
1127 if (touchXY != null) {
1128 // when dragging and dropping, just find the closest free spot
1129 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1130 int[] result = screenLayout.findNearestVacantArea(
1131 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001132 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001133 foundCellSpan = !findNearestVacantAreaFailed;
1134 } else {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08001135 // if we long pressed on an empty cell to bring up a menu,
1136 // make sure we intersect the empty cell
1137 // if mAddIntersectCellX/Y are -1 (e.g. we used menu -> add) then
1138 // findCellForSpanThatIntersects will just ignore them
1139 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1140 mAddIntersectCellX, mAddIntersectCellY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001141 }
1142
Michael Jurka0280c3b2010-09-17 15:00:07 -07001143 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001144 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001145 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001146 return;
1147 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001148
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001149 // Build Launcher-specific widget info and save to database
1150 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001151 launcherInfo.spanX = spanXY[0];
1152 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001153
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001154 LauncherModel.addItemToDatabase(this, launcherInfo,
1155 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001156 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001157
1158 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001159 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001160
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001162 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001163
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001164 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001166
Michael Jurka0280c3b2010-09-17 15:00:07 -07001167 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001168 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001169
1170 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001171 }
1172 }
Romain Guycbb89e42009-06-08 15:52:54 -07001173
Adam Cohended9f8d2010-11-03 13:25:16 -07001174 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1175 @Override
1176 public void onReceive(Context context, Intent intent) {
1177 final String action = intent.getAction();
1178 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1179 mUserPresent = false;
1180 updateRunning();
1181 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1182 mUserPresent = true;
1183 updateRunning();
1184 }
1185 }
1186 };
1187
1188 @Override
1189 public void onAttachedToWindow() {
1190 super.onAttachedToWindow();
1191
1192 // Listen for broadcasts related to user-presence
1193 final IntentFilter filter = new IntentFilter();
1194 filter.addAction(Intent.ACTION_SCREEN_OFF);
1195 filter.addAction(Intent.ACTION_USER_PRESENT);
1196 registerReceiver(mReceiver, filter);
1197
Adam Cohend113e0c2010-11-11 10:48:05 -08001198 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001199 mVisible = true;
1200 }
1201
1202 @Override
1203 public void onDetachedFromWindow() {
1204 super.onDetachedFromWindow();
1205 mVisible = false;
1206
Adam Cohend113e0c2010-11-11 10:48:05 -08001207 if (mAttached) {
1208 unregisterReceiver(mReceiver);
1209 mAttached = false;
1210 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001211 updateRunning();
1212 }
1213
1214 public void onWindowVisibilityChanged(int visibility) {
1215 mVisible = visibility == View.VISIBLE;
1216 updateRunning();
1217 }
1218
1219 private void sendAdvanceMessage(long delay) {
1220 mHandler.removeMessages(ADVANCE_MSG);
1221 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1222 mHandler.sendMessageDelayed(msg, delay);
1223 mAutoAdvanceSentTime = System.currentTimeMillis();
1224 }
1225
1226 private void updateRunning() {
1227 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1228 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1229 mAutoAdvanceRunning = autoAdvanceRunning;
1230 if (autoAdvanceRunning) {
1231 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1232 sendAdvanceMessage(delay);
1233 } else {
1234 if (!mWidgetsToAdvance.isEmpty()) {
1235 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1236 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1237 }
1238 mHandler.removeMessages(ADVANCE_MSG);
1239 }
1240 }
1241 }
1242
1243 private final Handler mHandler = new Handler() {
1244 @Override
1245 public void handleMessage(Message msg) {
1246 if (msg.what == ADVANCE_MSG) {
1247 int i = 0;
1248 for (View key: mWidgetsToAdvance.keySet()) {
1249 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1250 final int delay = mAdvanceStagger * i;
1251 if (v instanceof Advanceable) {
1252 postDelayed(new Runnable() {
1253 public void run() {
1254 ((Advanceable) v).advance();
1255 }
1256 }, delay);
1257 }
1258 i++;
1259 }
1260 sendAdvanceMessage(mAdvanceInterval);
1261 }
1262 }
1263 };
1264
1265 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
1266 if (appWidgetInfo.autoAdvanceViewId == -1) return;
1267 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1268 if (v instanceof Advanceable) {
1269 mWidgetsToAdvance.put(hostView, appWidgetInfo);
1270 ((Advanceable) v).willBeAdvancedByHost();
1271 updateRunning();
1272 }
1273 }
1274
1275 void removeWidgetToAutoAdvance(View hostView) {
1276 if (mWidgetsToAdvance.containsKey(hostView)) {
1277 mWidgetsToAdvance.remove(hostView);
1278 updateRunning();
1279 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001280 }
1281
Joe Onorato9c1289c2009-08-17 11:03:03 -04001282 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1283 mDesktopItems.remove(launcherInfo);
Adam Cohended9f8d2010-11-03 13:25:16 -07001284 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001285 launcherInfo.hostView = null;
1286 }
1287
Adam Cohended9f8d2010-11-03 13:25:16 -07001288 void showOutOfSpaceMessage() {
1289 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1290 }
1291
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001292 public LauncherAppWidgetHost getAppWidgetHost() {
1293 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001294 }
Romain Guycbb89e42009-06-08 15:52:54 -07001295
Winson Chunga9abd0e2010-10-27 17:18:37 -07001296 public LauncherModel getModel() {
1297 return mModel;
1298 }
1299
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001300 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001301 getWindow().closeAllPanels();
1302
1303 try {
1304 dismissDialog(DIALOG_CREATE_SHORTCUT);
1305 // Unlock the workspace if the dialog was showing
1306 } catch (Exception e) {
1307 // An exception is thrown if the dialog is not visible, which is fine
1308 }
1309
1310 try {
1311 dismissDialog(DIALOG_RENAME_FOLDER);
1312 // Unlock the workspace if the dialog was showing
1313 } catch (Exception e) {
1314 // An exception is thrown if the dialog is not visible, which is fine
1315 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001316
1317 // Whatever we were doing is hereby canceled.
1318 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001319 }
1320
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 @Override
1322 protected void onNewIntent(Intent intent) {
1323 super.onNewIntent(intent);
1324
1325 // Close the menu
1326 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001327 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001328 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001329
Joe Onorato14f122b2009-11-19 14:06:36 -08001330 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1331 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001332
Michael Jurka4cb37242010-08-09 21:05:32 -07001333 // in all these cases, only animate if we're already on home
1334 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001335 mWorkspace.unshrink(alreadyOnHome);
1336 }
1337 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001338 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001339 mWorkspace.moveToDefaultScreen(alreadyOnHome &&
1340 (LauncherApplication.isScreenXLarge() || mState != State.ALL_APPS));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001341 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001342 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001343
Joe Onorato3a8820b2009-11-10 15:06:42 -08001344 final View v = getWindow().peekDecorView();
1345 if (v != null && v.getWindowToken() != null) {
1346 InputMethodManager imm = (InputMethodManager)getSystemService(
1347 INPUT_METHOD_SERVICE);
1348 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001349 }
1350 }
1351 }
1352
1353 @Override
1354 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1355 // Do not call super here
1356 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001357
1358 if (mHomeCustomizationDrawer != null) {
1359 String cur = savedInstanceState.getString("currentTab");
1360 if (cur != null) {
1361 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1362 }
1363 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001364 }
1365
1366 @Override
1367 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001368 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369
1370 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1371 if (folders.size() > 0) {
1372 final int count = folders.size();
1373 long[] ids = new long[count];
1374 for (int i = 0; i < count; i++) {
1375 final FolderInfo info = folders.get(i).getInfo();
1376 ids[i] = info.id;
1377 }
1378 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1379 } else {
1380 super.onSaveInstanceState(outState);
1381 }
1382
Michael Jurka883f55b2010-10-21 15:47:14 -07001383 outState.putInt(RUNTIME_STATE, mState.ordinal());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001384
Michael Jurka0280c3b2010-09-17 15:00:07 -07001385 if (mAddScreen > -1 && mWaitingForResult) {
1386 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1387 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1388 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389 }
1390
1391 if (mFolderInfo != null && mWaitingForResult) {
1392 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1393 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1394 }
Michael Jurka946ad472010-07-09 18:05:18 -07001395
1396 if (mHomeCustomizationDrawer != null) {
1397 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1398 if (currentTabTag != null) {
1399 outState.putString("currentTab", currentTabTag);
1400 }
1401 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001402 }
1403
1404 @Override
1405 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001406 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001407
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001409 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001411 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412 }
1413
1414 TextKeyListener.getInstance().release();
1415
Joe Onorato9c1289c2009-08-17 11:03:03 -04001416 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417
Joe Onorato9c1289c2009-08-17 11:03:03 -04001418 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001419
1420 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001421
Patrick Dubroyab962b72010-07-26 12:10:10 -07001422 // Some launcher layouts don't have a previous and next view
1423 if (mPreviousView != null) {
1424 dismissPreview(mPreviousView);
1425 }
1426 if (mNextView != null) {
1427 dismissPreview(mNextView);
1428 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001429
1430 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 }
1432
1433 @Override
1434 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001435 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 super.startActivityForResult(intent, requestCode);
1437 }
1438
1439 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001440 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001441 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001442
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001443 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001444
Karl Rosaen138a0412009-04-23 19:00:21 -07001445 if (initialQuery == null) {
1446 // Use any text typed in the launcher as the initial query
1447 initialQuery = getTypedText();
1448 clearTypedText();
1449 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001450 if (appSearchData == null) {
1451 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001452 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453 }
Romain Guycbb89e42009-06-08 15:52:54 -07001454
Karl Rosaen138a0412009-04-23 19:00:21 -07001455 final SearchManager searchManager =
1456 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001457 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001458 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001459 }
1460
1461 @Override
1462 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001463 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001464 return false;
1465 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466
1467 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001468
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001469 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1470 .setIcon(android.R.drawable.ic_menu_add)
1471 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001472 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1473 .setIcon(android.R.drawable.ic_menu_manage)
1474 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001475 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 .setIcon(android.R.drawable.ic_menu_gallery)
1477 .setAlphabeticShortcut('W');
1478 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1479 .setIcon(android.R.drawable.ic_search_category_default)
1480 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1481 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1482 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1483 .setAlphabeticShortcut('N');
1484
1485 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001486 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1487 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001488
1489 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1490 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1491 .setIntent(settings);
1492
1493 return true;
1494 }
1495
1496 @Override
1497 public boolean onPrepareOptionsMenu(Menu menu) {
1498 super.onPrepareOptionsMenu(menu);
1499
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001500 // If all apps is animating, don't show the menu, because we don't know
1501 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001502 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001503 return false;
1504 }
1505
1506 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001507 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001508 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1509 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1510
1511 // Disable add if the workspace is full.
1512 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001513 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1514 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001515 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516
1517 return true;
1518 }
1519
1520 @Override
1521 public boolean onOptionsItemSelected(MenuItem item) {
1522 switch (item.getItemId()) {
1523 case MENU_ADD:
1524 addItems();
1525 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001526 case MENU_MANAGE_APPS:
1527 manageApps();
1528 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001529 case MENU_WALLPAPER_SETTINGS:
1530 startWallpaper();
1531 return true;
1532 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001533 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001534 return true;
1535 case MENU_NOTIFICATIONS:
1536 showNotifications();
1537 return true;
1538 }
1539
1540 return super.onOptionsItemSelected(item);
1541 }
Romain Guycbb89e42009-06-08 15:52:54 -07001542
Karl Rosaen138a0412009-04-23 19:00:21 -07001543 /**
1544 * Indicates that we want global search for this activity by setting the globalSearch
1545 * argument for {@link #startSearch} to true.
1546 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001548 @Override
1549 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001550 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001551 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001552 }
1553
Joe Onorato9c1289c2009-08-17 11:03:03 -04001554 public boolean isWorkspaceLocked() {
1555 return mWorkspaceLoading || mWaitingForResult;
1556 }
1557
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001559 if (LauncherApplication.isScreenXLarge()) {
1560 // Animate the widget chooser up from the bottom of the screen
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001561 if (mState != State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001562 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001563 }
1564 } else {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001565 showWorkspace(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001566 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001567 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001568 }
1569
Michael Jurka0280c3b2010-09-17 15:00:07 -07001570 private void resetAddInfo() {
1571 mAddScreen = -1;
1572 mAddIntersectCellX = -1;
1573 mAddIntersectCellY = -1;
1574 mAddDropPosition = null;
1575 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001576
Winson Chung55cef262010-10-28 14:14:18 -07001577 void addAppWidgetFromDrop(PendingAddWidgetInfo info, int screen, int[] position) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001578 resetAddInfo();
1579 mAddScreen = screen;
1580
1581 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1582 mAddDropPosition = position;
1583
Michael Jurkaaf442092010-06-10 17:01:57 -07001584 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Winson Chung55cef262010-10-28 14:14:18 -07001585 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1586 addAppWidgetImpl(appWidgetId, info);
Michael Jurkaaf442092010-06-10 17:01:57 -07001587 }
1588
Winson Chung7ad01412010-09-27 11:33:03 -07001589 private void manageApps() {
1590 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1591 }
1592
Michael Jurkaaf442092010-06-10 17:01:57 -07001593 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001594 // TODO: catch bad widget exception when sent
1595 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001596 // TODO: Is this log message meaningful?
1597 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001598 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001599 }
1600
Winson Chung55cef262010-10-28 14:14:18 -07001601 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001602 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603
Bjorn Bringert7984c942009-12-09 15:38:25 +00001604 if (appWidget.configure != null) {
1605 // Launch over to configure widget, if needed
1606 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1607 intent.setComponent(appWidget.configure);
1608 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001609 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001610 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1611 intent.putExtra(
1612 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1613 info.mimeType);
1614
1615 final String mimeType = info.mimeType;
1616 final ClipData clipData = (ClipData) info.configurationData;
1617 final ClipDescription clipDesc = clipData.getDescription();
1618 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1619 if (clipDesc.getMimeType(i).equals(mimeType)) {
1620 final ClipData.Item item = clipData.getItem(i);
1621 final CharSequence stringData = item.getText();
1622 final Uri uriData = item.getUri();
1623 final Intent intentData = item.getIntent();
1624 final String key =
1625 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1626 if (uriData != null) {
1627 intent.putExtra(key, uriData);
1628 } else if (intentData != null) {
1629 intent.putExtra(key, intentData);
1630 } else if (stringData != null) {
1631 intent.putExtra(key, stringData);
1632 }
1633 break;
1634 }
1635 }
1636 }
Winson Chung55cef262010-10-28 14:14:18 -07001637 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001638
Romain Guy8e633c52010-03-04 12:51:36 -08001639 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001640 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001641 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001642 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001643 }
1644 }
Romain Guycbb89e42009-06-08 15:52:54 -07001645
Michael Jurka0280c3b2010-09-17 15:00:07 -07001646 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1647 resetAddInfo();
1648 mAddScreen = screen;
1649 mAddDropPosition = position;
1650
1651 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1652 createShortcutIntent.setComponent(componentName);
1653 processShortcut(createShortcutIntent);
1654 }
1655
Joe Onoratodeb98af2010-02-19 14:59:39 -08001656 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001657 // Handle case where user selected "Applications"
1658 String applicationName = getResources().getString(R.string.group_applications);
1659 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001660
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001661 if (applicationName != null && applicationName.equals(shortcutName)) {
1662 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1663 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001664
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001665 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1666 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001667 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001668 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001669 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001670 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001671 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001672 }
1673
Winson Chung24ab2f12010-09-16 14:10:47 -07001674 void processWallpaper(Intent intent) {
1675 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1676 }
1677
Michael Jurka0280c3b2010-09-17 15:00:07 -07001678 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1679 resetAddInfo();
1680 mAddScreen = screen;
1681 mAddDropPosition = position;
1682
1683 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1684 createFolderIntent.setComponent(componentName);
1685
1686 addLiveFolder(createFolderIntent);
1687 }
1688
1689 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001690 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001691 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001692 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001693
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001694 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001695 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001696 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001697 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001698 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001699 }
1700
Michael Jurka0280c3b2010-09-17 15:00:07 -07001701 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001702 UserFolderInfo folderInfo = new UserFolderInfo();
1703 folderInfo.title = getText(R.string.folder_name);
1704
Michael Jurka0280c3b2010-09-17 15:00:07 -07001705 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1706 final int[] cellXY = mTmpAddItemCellCoordinates;
1707 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1708 showOutOfSpaceMessage();
1709 return;
1710 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711
1712 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001713 LauncherModel.addItemToDatabase(this, folderInfo,
1714 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001715 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001716 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717
1718 // Create the view
1719 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurkac9a96192010-11-01 11:52:08 -07001720 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()),
1721 folderInfo, mIconCache);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001722 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001723 }
Romain Guycbb89e42009-06-08 15:52:54 -07001724
Joe Onorato9c1289c2009-08-17 11:03:03 -04001725 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001726 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001727 }
1728
Michael Jurka28750fb2010-09-24 17:43:49 -07001729 private void completeAddLiveFolder(
1730 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001731 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1732 final int[] cellXY = mTmpAddItemCellCoordinates;
1733 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1734 showOutOfSpaceMessage();
1735 return;
1736 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737
Michael Jurka0280c3b2010-09-17 15:00:07 -07001738 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001739
1740 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001741 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001742 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001743 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 }
1745 }
1746
1747 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001748 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001749
1750 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1751 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1752
1753 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001754 Intent.ShortcutIconResource iconResource = null;
1755
1756 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1757 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1758 try {
1759 iconResource = (Intent.ShortcutIconResource) extra;
1760 final PackageManager packageManager = context.getPackageManager();
1761 Resources resources = packageManager.getResourcesForApplication(
1762 iconResource.packageName);
1763 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1764 icon = resources.getDrawable(id);
1765 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001766 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001767 }
1768 }
1769
1770 if (icon == null) {
1771 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1772 }
1773
1774 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001775 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001776 info.title = name;
1777 info.iconResource = iconResource;
1778 info.uri = data.getData();
1779 info.baseIntent = baseIntent;
1780 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1781 LiveFolders.DISPLAY_MODE_GRID);
1782
1783 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001784 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001785 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001786
1787 return info;
1788 }
1789
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001790 private void showNotifications() {
1791 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1792 if (statusBar != null) {
1793 statusBar.expand();
1794 }
1795 }
1796
1797 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001798 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001799 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001800 Intent chooser = Intent.createChooser(pickWallpaper,
1801 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001802 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1803 // Removed in Eclair MR1
1804// WallpaperManager wm = (WallpaperManager)
1805// getSystemService(Context.WALLPAPER_SERVICE);
1806// WallpaperInfo wi = wm.getWallpaperInfo();
1807// if (wi != null && wi.getSettingsActivity() != null) {
1808// LabeledIntent li = new LabeledIntent(getPackageName(),
1809// R.string.configure_wallpaper, 0);
1810// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1811// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1812// }
Mike Clerona0618e42009-10-22 13:55:21 -07001813 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 }
1815
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001816 /**
1817 * Registers various content observers. The current implementation registers
1818 * only a favorites observer to keep track of the favorites applications.
1819 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001820 private void registerContentObservers() {
1821 ContentResolver resolver = getContentResolver();
1822 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1823 true, mWidgetObserver);
1824 }
1825
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001826 @Override
1827 public boolean dispatchKeyEvent(KeyEvent event) {
1828 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1829 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001831 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001832 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001833 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001834 dumpState();
1835 return true;
1836 }
1837 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001838 }
1839 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1840 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001841 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001842 return true;
1843 }
1844 }
1845
1846 return super.dispatchKeyEvent(event);
1847 }
1848
Joe Onorato88ec0992009-11-19 13:16:06 -08001849 @Override
1850 public void onBackPressed() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001851 if (mState == State.ALL_APPS || mState == State.CUSTOMIZE) {
1852 showWorkspace(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001853 } else {
1854 closeFolder();
1855 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001856 // Some launcher layouts don't have a previous and next view
1857 if (mPreviousView != null) {
1858 dismissPreview(mPreviousView);
1859 dismissPreview(mNextView);
1860 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001861 }
1862
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001863 private void closeFolder() {
1864 Folder folder = mWorkspace.getOpenFolder();
1865 if (folder != null) {
1866 closeFolder(folder);
1867 }
1868 }
1869
1870 void closeFolder(Folder folder) {
1871 folder.getInfo().opened = false;
1872 ViewGroup parent = (ViewGroup) folder.getParent();
1873 if (parent != null) {
Michael Jurkaf3ca3ab2010-10-20 17:08:24 -07001874 CellLayout cl = (CellLayout) parent;
1875 cl.removeViewWithoutMarkingCells(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001876 if (folder instanceof DropTarget) {
1877 // Live folders aren't DropTargets.
1878 mDragController.removeDropTarget((DropTarget)folder);
1879 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880 }
1881 folder.onClose();
1882 }
1883
1884 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001885 * Re-listen when widgets are reset.
1886 */
1887 private void onAppWidgetReset() {
1888 mAppWidgetHost.startListening();
1889 }
1890
1891 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001892 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1893 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001894 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001895 private void unbindDesktopItems() {
1896 for (ItemInfo item: mDesktopItems) {
1897 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001898 }
1899 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001900
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001901 /**
1902 * Launches the intent referred by the clicked shortcut.
1903 *
1904 * @param v The view representing the clicked shortcut.
1905 */
1906 public void onClick(View v) {
1907 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001908 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001910 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001911 int[] pos = new int[2];
1912 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001913 intent.setSourceBounds(new Rect(pos[0], pos[1],
1914 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001915 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001916 } else if (tag instanceof FolderInfo) {
1917 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001918 } else if (v == mHandleView) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001919 if (mState == State.ALL_APPS) {
1920 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001921 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001922 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001923 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001924 }
1925 }
1926
Michael Jurka0e260592010-06-30 17:07:39 -07001927 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001928 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001929 // clicking anywhere on the workspace causes the customization drawer to slide down
1930 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001931 return false;
1932 }
1933
Michael Jurkaaf442092010-06-10 17:01:57 -07001934 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001935 * Event handler for the search button
1936 *
1937 * @param v The view that was clicked.
1938 */
1939 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001940 startSearch(null, false, null, true);
Amith Yamasani1f878a12010-11-22 14:58:22 -08001941 // Use a custom animation for launching search
1942 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001943 }
1944
1945 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001946 * Event handler for the voice button
1947 *
1948 * @param v The view that was clicked.
1949 */
1950 public void onClickVoiceButton(View v) {
1951 startVoiceSearch();
1952 }
1953
1954 private void startVoiceSearch() {
1955 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1956 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1957 startActivity(intent);
1958 }
1959
1960 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001961 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001962 * enters home screen customization mode.
1963 *
1964 * @param v The view that was clicked.
1965 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001966 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001967 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001968 }
1969
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001970 /**
1971 * Event handler for the "grid" button that appears on the home screen, which
1972 * enters all apps mode.
1973 *
1974 * @param v The view that was clicked.
1975 */
1976 public void onClickAllAppsButton(View v) {
1977 showAllApps(true);
1978 }
1979
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001980 public void onClickAppMarketButton(View v) {
1981 if (mAppMarketIntent != null) {
1982 startActivitySafely(mAppMarketIntent, "app market");
1983 }
1984 }
1985
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001986 void startApplicationDetailsActivity(ComponentName componentName) {
1987 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001988 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1989 Uri.fromParts("package", packageName, null));
1990 startActivity(intent);
1991 }
1992
Patrick Dubroy5539af72010-09-07 15:22:01 -07001993 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1994 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1995 // System applications cannot be installed. For now, show a toast explaining that.
1996 // We may give them the option of disabling apps this way.
1997 int messageId = R.string.uninstall_system_app_text;
1998 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1999 } else {
2000 String packageName = appInfo.componentName.getPackageName();
2001 String className = appInfo.componentName.getClassName();
2002 Intent intent = new Intent(
2003 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
2004 startActivity(intent);
2005 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002006 }
2007
Joe Onoratof984e852010-03-25 09:47:45 -07002008 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002009 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2010 try {
2011 startActivity(intent);
2012 } catch (ActivityNotFoundException e) {
2013 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04002014 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002015 } catch (SecurityException e) {
2016 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002017 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002019 "or use the exported attribute for this activity. "
2020 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002021 }
2022 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002023
Romain Guy8e633c52010-03-04 12:51:36 -08002024 void startActivityForResultSafely(Intent intent, int requestCode) {
2025 try {
2026 startActivityForResult(intent, requestCode);
2027 } catch (ActivityNotFoundException e) {
2028 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2029 } catch (SecurityException e) {
2030 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2031 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2032 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2033 "or use the exported attribute for this activity.", e);
2034 }
2035 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002036
2037 private void handleFolderClick(FolderInfo folderInfo) {
2038 if (!folderInfo.opened) {
2039 // Close any open folder
2040 closeFolder();
2041 // Open the requested folder
2042 openFolder(folderInfo);
2043 } else {
2044 // Find the open folder...
2045 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
2046 int folderScreen;
2047 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002048 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049 // .. and close it
2050 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002051 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 // Close any folder open on the current screen
2053 closeFolder();
2054 // Pull the folder onto this screen
2055 openFolder(folderInfo);
2056 }
2057 }
2058 }
2059 }
2060
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002062 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 * is animated relative to the specified View. If the View is null, no animation
2064 * is played.
2065 *
2066 * @param folderInfo The FolderInfo describing the folder to open.
2067 */
Winson Chungaafa03c2010-06-11 17:34:16 -07002068 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002069 Folder openFolder;
2070
2071 if (folderInfo instanceof UserFolderInfo) {
2072 openFolder = UserFolder.fromXml(this);
2073 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07002074 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 } else {
2076 return;
2077 }
2078
Joe Onorato00acb122009-08-04 16:04:30 -04002079 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002080 openFolder.setLauncher(this);
2081
2082 openFolder.bind(folderInfo);
2083 folderInfo.opened = true;
2084
Winson Chungaafa03c2010-06-11 17:34:16 -07002085 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
2086
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002087 openFolder.onOpen();
2088 }
2089
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002090 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08002091 switch (v.getId()) {
2092 case R.id.previous_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002093 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08002094 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2095 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08002096 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08002097 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002098 return true;
2099 case R.id.next_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002100 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08002101 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2102 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08002103 showPreviews(v);
2104 }
2105 return true;
2106 case R.id.all_apps_button:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002107 if (mState != State.ALL_APPS) {
Romain Guyf8e6a802009-12-07 17:48:02 -08002108 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2109 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2110 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08002111 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002112 return true;
2113 }
2114
Joe Onorato9c1289c2009-08-17 11:03:03 -04002115 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002116 return false;
2117 }
2118
2119 if (!(v instanceof CellLayout)) {
2120 v = (View) v.getParent();
2121 }
2122
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123
Michael Jurka0280c3b2010-09-17 15:00:07 -07002124 resetAddInfo();
2125 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002126 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07002127 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 return true;
2129 }
2130
Michael Jurka0280c3b2010-09-17 15:00:07 -07002131 final View itemUnderLongClick = longClickCellInfo.cell;
2132
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002133 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002134 if (itemUnderLongClick == null) {
2135 // User long pressed on empty space
2136 mWorkspace.setAllowLongPress(false);
2137 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2138 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka56170562010-10-05 14:14:56 -07002139 if (!LauncherApplication.isScreenXLarge()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002140 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002141 }
2142 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002143 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002144 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08002145 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2146 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002147 mAddIntersectCellX = longClickCellInfo.cellX;
2148 mAddIntersectCellY = longClickCellInfo.cellY;
2149 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002150 }
2151 }
2152 }
2153 return true;
2154 }
2155
Romain Guye6b8e2f2009-11-10 11:56:55 -08002156 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08002157 private void dismissPreview(final View v) {
2158 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08002159 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08002160 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
2161 public void onDismiss() {
2162 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
2163 int count = group.getChildCount();
2164 for (int i = 0; i < count; i++) {
2165 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
2166 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08002167 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
2168 for (Bitmap bitmap : bitmaps) bitmap.recycle();
2169
2170 v.setTag(R.id.workspace, null);
2171 v.setTag(R.id.icon, null);
2172 window.setOnDismissListener(null);
2173 }
2174 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002175 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08002176 }
2177 v.setTag(null);
2178 }
2179
Romain Guyf8e6a802009-12-07 17:48:02 -08002180 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08002181 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08002182 }
2183
Romain Guya6abce82009-11-10 02:54:41 -08002184 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08002185 final Resources resources = getResources();
2186 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002187
Romain Guya6abce82009-11-10 02:54:41 -08002188 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07002189
Romain Guy9d31e9f2009-11-11 18:54:28 -08002190 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07002191
Romain Guyf8e6a802009-12-07 17:48:02 -08002192 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08002193 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002194 int extraW = (int) ((r.left + r.right) * max);
2195 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08002196
2197 int aW = cell.getWidth() - extraW;
2198 float w = aW / max;
2199
2200 int width = cell.getWidth();
2201 int height = cell.getHeight();
2202 int x = cell.getLeftPadding();
2203 int y = cell.getTopPadding();
2204 width -= (x + cell.getRightPadding());
2205 height -= (y + cell.getBottomPadding());
2206
2207 float scale = w / width;
2208
2209 int count = end - start;
2210
2211 final float sWidth = width * scale;
2212 float sHeight = height * scale;
2213
Romain Guye6b8e2f2009-11-10 11:56:55 -08002214 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002215
Romain Guye6b8e2f2009-11-10 11:56:55 -08002216 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2217 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002218
2219 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002220 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002221 cell = (CellLayout) workspace.getChildAt(i);
2222
Romain Guyf8e6a802009-12-07 17:48:02 -08002223 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002224 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002225
2226 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002227 c.scale(scale, scale);
2228 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
Patrick Dubroy1262e362010-10-06 15:49:50 -07002229 cell.drawChildren(c);
Romain Guya6abce82009-11-10 02:54:41 -08002230
Romain Guy9d31e9f2009-11-11 18:54:28 -08002231 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002232 image.setImageBitmap(bitmap);
2233 image.setTag(i);
2234 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002235 image.setOnFocusChangeListener(handler);
2236 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002237 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002238
2239 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002240 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2241
Winson Chungaafa03c2010-06-11 17:34:16 -07002242 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002243 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002244
2245 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002246 p.setContentView(preview);
2247 p.setWidth((int) (sWidth * count + extraW));
2248 p.setHeight((int) (sHeight + extraH));
2249 p.setAnimationStyle(R.style.AnimationPreview);
2250 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002251 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002252 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002253 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002254
Romain Guye6b8e2f2009-11-10 11:56:55 -08002255 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2256 public void onDismiss() {
2257 dismissPreview(anchor);
2258 }
2259 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002260
2261 anchor.setTag(p);
2262 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002263 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002264 }
2265
Romain Guy9d31e9f2009-11-11 18:54:28 -08002266 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002267 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002268
Romain Guye6b8e2f2009-11-10 11:56:55 -08002269 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002270 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002271 }
2272
2273 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002274 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002275 v.post(this);
2276 }
2277
2278 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002279 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002280 }
2281
2282 public void onFocusChange(View v, boolean hasFocus) {
2283 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002284 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002285 }
Romain Guya6abce82009-11-10 02:54:41 -08002286 }
2287 }
2288
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002289 Workspace getWorkspace() {
2290 return mWorkspace;
2291 }
2292
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002293 @Override
2294 protected Dialog onCreateDialog(int id) {
2295 switch (id) {
2296 case DIALOG_CREATE_SHORTCUT:
2297 return new CreateShortcut().createDialog();
2298 case DIALOG_RENAME_FOLDER:
2299 return new RenameFolder().createDialog();
2300 }
2301
2302 return super.onCreateDialog(id);
2303 }
2304
2305 @Override
2306 protected void onPrepareDialog(int id, Dialog dialog) {
2307 switch (id) {
2308 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002309 break;
2310 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002311 if (mFolderInfo != null) {
2312 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2313 final CharSequence text = mFolderInfo.title;
2314 input.setText(text);
2315 input.setSelection(0, text.length());
2316 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002317 break;
2318 }
2319 }
2320
2321 void showRenameDialog(FolderInfo info) {
2322 mFolderInfo = info;
2323 mWaitingForResult = true;
2324 showDialog(DIALOG_RENAME_FOLDER);
2325 }
2326
Michael Jurka0280c3b2010-09-17 15:00:07 -07002327 private void showAddDialog(int intersectX, int intersectY) {
2328 resetAddInfo();
2329 mAddIntersectCellX = intersectX;
2330 mAddIntersectCellY = intersectY;
2331 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002332 mWaitingForResult = true;
2333 showDialog(DIALOG_CREATE_SHORTCUT);
2334 }
2335
Joe Onoratodeb98af2010-02-19 14:59:39 -08002336 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002337 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002338 Bundle bundle = new Bundle();
2339
2340 ArrayList<String> shortcutNames = new ArrayList<String>();
2341 shortcutNames.add(getString(R.string.group_applications));
2342 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2343
2344 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2345 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2346 R.drawable.ic_launcher_application));
2347 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2348
2349 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2350 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002351 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002352 pickIntent.putExtras(bundle);
2353
Joe Onoratodeb98af2010-02-19 14:59:39 -08002354 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002355 }
2356
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002357 private class RenameFolder {
2358 private EditText mInput;
2359
2360 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002361 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2362 mInput = (EditText) layout.findViewById(R.id.folder_name);
2363
2364 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2365 builder.setIcon(0);
2366 builder.setTitle(getString(R.string.rename_folder_title));
2367 builder.setCancelable(true);
2368 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2369 public void onCancel(DialogInterface dialog) {
2370 cleanup();
2371 }
2372 });
2373 builder.setNegativeButton(getString(R.string.cancel_action),
2374 new Dialog.OnClickListener() {
2375 public void onClick(DialogInterface dialog, int which) {
2376 cleanup();
2377 }
2378 }
2379 );
2380 builder.setPositiveButton(getString(R.string.rename_action),
2381 new Dialog.OnClickListener() {
2382 public void onClick(DialogInterface dialog, int which) {
2383 changeFolderName();
2384 }
2385 }
2386 );
2387 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002388
2389 final AlertDialog dialog = builder.create();
2390 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2391 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002392 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002393 mInput.requestFocus();
2394 InputMethodManager inputManager = (InputMethodManager)
2395 getSystemService(Context.INPUT_METHOD_SERVICE);
2396 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002397 }
2398 });
2399
2400 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002401 }
2402
2403 private void changeFolderName() {
2404 final String name = mInput.getText().toString();
2405 if (!TextUtils.isEmpty(name)) {
2406 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002407 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002408 mFolderInfo.title = name;
2409 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2410
Joe Onorato9c1289c2009-08-17 11:03:03 -04002411 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002412 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002413 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002414 } else {
2415 final FolderIcon folderIcon = (FolderIcon)
2416 mWorkspace.getViewForTag(mFolderInfo);
2417 if (folderIcon != null) {
2418 folderIcon.setText(name);
2419 getWorkspace().requestLayout();
2420 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002421 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002422 mWorkspaceLoading = true;
2423 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002424 }
2425 }
2426 }
2427 cleanup();
2428 }
2429
2430 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002431 dismissDialog(DIALOG_RENAME_FOLDER);
2432 mWaitingForResult = false;
2433 mFolderInfo = null;
2434 }
2435 }
2436
Daniel Sandler843e8602010-06-07 14:59:01 -04002437 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2438 public boolean isAllAppsVisible() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002439 return mState == State.ALL_APPS;
Joe Onoratofb0ca672009-09-14 17:55:46 -04002440 }
2441
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002442 // AllAppsView.Watcher
2443 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002444 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2445 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002446 mWorkspace.setVisibility(View.GONE);
2447 }
2448 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002449
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002450 private void showToolbarButton(View button) {
2451 button.setAlpha(1.0f);
2452 button.setVisibility(View.VISIBLE);
2453 button.setFocusable(true);
2454 button.setClickable(true);
2455 }
2456
2457 private void hideToolbarButton(View button) {
2458 button.setAlpha(0.0f);
2459 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2460 button.setVisibility(View.INVISIBLE);
2461 button.setFocusable(false);
2462 button.setClickable(false);
2463 }
2464
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002465 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002466 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002467 *
2468 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2469 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002470 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002471 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002472 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002473 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002474 final boolean showing = show;
2475 final boolean hiding = !show;
2476
2477 final int duration = show ?
2478 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2479 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2480
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002481 if (seq != null) {
Chet Haase472b2812010-10-14 07:02:04 -07002482 Animator anim = ObjectAnimator.ofFloat(view, "alpha", show ? 1.0f : 0.0f);
2483 anim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002484 anim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002485 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002486 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002487 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002488 }
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002489 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002490 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002491 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002492 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002493 });
2494 seq.play(anim);
2495 } else {
2496 if (showing) {
2497 showToolbarButton(view);
2498 } else {
2499 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002500 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002501 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002502 }
2503
2504 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002505 * Show/hide the appropriate toolbar buttons for newState.
2506 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002507 *
2508 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002509 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2510 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002511 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002512 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002513 final View searchButton = findViewById(R.id.search_button_cluster);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002514 final View allAppsButton = findViewById(R.id.all_apps_button);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002515 final View configureButton = findViewById(R.id.configure_button);
2516
2517 switch (newState) {
2518 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002519 hideOrShowToolbarButton(true, searchButton, showSeq);
2520 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2521 hideOrShowToolbarButton(true, configureButton, showSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002522 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002523 break;
2524 case ALL_APPS:
Adam Lesinski6b879f02010-11-04 16:15:23 -07002525 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002526 hideOrShowToolbarButton(false, searchButton, hideSeq);
2527 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002528 break;
2529 case CUSTOMIZE:
Adam Lesinski6b879f02010-11-04 16:15:23 -07002530 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002531 hideOrShowToolbarButton(false, searchButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002532 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002533 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002534 break;
2535 }
2536 }
2537
2538 /**
2539 * Helper method for the cameraZoomIn/cameraZoomOut animations
2540 * @param view The view being animated
2541 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2542 * @param scaleFactor The scale factor used for the zoom
2543 */
2544 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2545 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002546
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002547 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002548 // Set pivotY so that at the starting zoom factor, the view is partially
2549 // visible. Modifying initialHeightFactor changes how much of the view is
2550 // initially showing, and hence the perceived angle from which the view enters.
2551 final float initialHeightFactor = 0.2f;
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002552 if (state == State.ALL_APPS) {
Adam Cohen61033d32010-11-15 18:29:44 -08002553 view.setPivotY((1 + initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002554 } else {
Adam Cohen61033d32010-11-15 18:29:44 -08002555 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002556 }
2557 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002558
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002559 /**
2560 * Zoom the camera out from the workspace to reveal 'toView'.
2561 * Assumes that the view to show is anchored at either the very top or very bottom
2562 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002563 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002564 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002565 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002566 final Resources res = getResources();
2567 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2568 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002569 final boolean toAllApps = (toState == State.ALL_APPS);
2570 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002571
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002572 setPivotsForZoom(toView, toState, scale);
2573
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002574 if (toAllApps) {
Adam Lesinski6b879f02010-11-04 16:15:23 -07002575 mWorkspace.shrinkToBottomHidden(animated);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002576 } else {
2577 mWorkspace.shrinkToTop(animated);
2578 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002579
2580 if (animated) {
Chet Haase472b2812010-10-14 07:02:04 -07002581 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2582 PropertyValuesHolder.ofFloat("scaleX", scale, 1.0f),
2583 PropertyValuesHolder.ofFloat("scaleY", scale, 1.0f));
2584 scaleAnim.setDuration(duration);
Adam Cohen61033d32010-11-15 18:29:44 -08002585
2586 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002587 scaleAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002588 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002589 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002590 // Prepare the position
2591 toView.setTranslationX(0.0f);
2592 toView.setTranslationY(0.0f);
2593 toView.setVisibility(View.VISIBLE);
Adam Cohen61033d32010-11-15 18:29:44 -08002594 toView.setAlpha(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002595 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002596 @Override
2597 public void onAnimationEndOrCancel(Animator animation) {
2598 // If we don't set the final scale values here, if this animation is cancelled
2599 // it will have the wrong scale value and subsequent cameraPan animations will
2600 // not fix that
2601 toView.setScaleX(1.0f);
2602 toView.setScaleY(1.0f);
2603 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002604 });
2605
Chet Haaseb1254a62010-09-07 13:35:00 -07002606 AnimatorSet toolbarHideAnim = new AnimatorSet();
2607 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002608 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2609
2610 // toView should appear right at the end of the workspace shrink animation
2611 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2612
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002613 if (mStateAnimation != null) mStateAnimation.cancel();
2614 mStateAnimation = new AnimatorSet();
2615 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
2616 mStateAnimation.play(scaleAnim).after(startDelay);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002617
2618 // Show the new toolbar buttons just as the main animation is ending
2619 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002620 mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2621 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002622 } else {
2623 toView.setTranslationX(0.0f);
2624 toView.setTranslationY(0.0f);
2625 toView.setScaleX(1.0f);
2626 toView.setScaleY(1.0f);
2627 toView.setVisibility(View.VISIBLE);
2628 hideAndShowToolbarButtons(toState, null, null);
2629 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002630 }
2631
2632 /**
2633 * Zoom the camera back into the workspace, hiding 'fromView'.
2634 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002635 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2636 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002637 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002638 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002639 Resources res = getResources();
2640 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2641 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002642 final View fromView =
2643 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2644
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002645 mCustomizePagedView.endChoiceMode();
2646 mAllAppsPagedView.endChoiceMode();
2647
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002648 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002649
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002650 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002651
2652 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002653 if (mStateAnimation != null) mStateAnimation.cancel();
2654 mStateAnimation = new AnimatorSet();
Chet Haase472b2812010-10-14 07:02:04 -07002655 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2656 PropertyValuesHolder.ofFloat("scaleX", scaleFactor),
2657 PropertyValuesHolder.ofFloat("scaleY", scaleFactor));
2658 scaleAnim.setDuration(duration);
Adam Cohen61033d32010-11-15 18:29:44 -08002659 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
2660
2661 ValueAnimator alphaAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2662 PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f));
2663 alphaAnim.setDuration(res.getInteger(R.integer.config_allAppsFadeOutTime));
2664 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002665 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002666 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002667 fromView.setVisibility(View.GONE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002668 }
2669 });
2670
Chet Haaseb1254a62010-09-07 13:35:00 -07002671 AnimatorSet toolbarHideAnim = new AnimatorSet();
2672 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002673 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2674
Adam Cohen61033d32010-11-15 18:29:44 -08002675 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim, alphaAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002676
2677 // Show the new toolbar buttons at the very end of the whole animation
2678 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2679 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002680 mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2681 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002682 } else {
2683 fromView.setVisibility(View.GONE);
2684 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2685 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002686 }
2687
2688 /**
2689 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2690 * This is the transition used on xlarge screens to go between all apps and
2691 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002692 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2693 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2694 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002695 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002696 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002697 final Resources res = getResources();
2698 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002699 final int workspaceHeight = mWorkspace.getHeight();
2700
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002701 final boolean fromAllApps = (fromState == State.ALL_APPS);
2702 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2703 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002704
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002705 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2706 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2707 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2708 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002709
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002710 mCustomizePagedView.endChoiceMode();
2711 mAllAppsPagedView.endChoiceMode();
2712
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002713 if (toState == State.ALL_APPS) {
Adam Lesinski6b879f02010-11-04 16:15:23 -07002714 mWorkspace.shrinkToBottomHidden(animated);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002715 } else {
2716 mWorkspace.shrinkToTop(animated);
2717 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002718
2719 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002720 if (mStateAnimation != null) mStateAnimation.cancel();
2721 mStateAnimation = new AnimatorSet();
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002722 mStateAnimation.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002723 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002724 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002725 toView.setVisibility(View.VISIBLE);
2726 toView.setY(toViewStartY);
Adam Cohen61033d32010-11-15 18:29:44 -08002727 toView.setAlpha(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002728 }
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002729 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002730 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002731 fromView.setVisibility(View.GONE);
2732 }
2733 });
2734
Chet Haaseb1254a62010-09-07 13:35:00 -07002735 AnimatorSet toolbarHideAnim = new AnimatorSet();
2736 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002737 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2738
Chet Haase472b2812010-10-14 07:02:04 -07002739 ObjectAnimator fromAnim = ObjectAnimator.ofFloat(fromView, "y",
2740 fromViewStartY, fromViewEndY);
2741 fromAnim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002742 ObjectAnimator toAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2743 PropertyValuesHolder.ofFloat("y", toViewStartY, toViewEndY),
2744 PropertyValuesHolder.ofFloat("scaleX", toView.getScaleX(), 1.0f),
2745 PropertyValuesHolder.ofFloat("scaleY", toView.getScaleY(), 1.0f)
2746 );
Chet Haase472b2812010-10-14 07:02:04 -07002747 fromAnim.setDuration(duration);
2748 mStateAnimation.playTogether(toolbarHideAnim, fromAnim, toAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002749
2750 // Show the new toolbar buttons just as the main animation is ending
2751 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002752 mStateAnimation.play(toolbarShowAnim).after(duration - fadeInTime);
2753 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002754 } else {
2755 fromView.setY(fromViewEndY);
2756 fromView.setVisibility(View.GONE);
2757 toView.setY(toViewEndY);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002758 toView.setScaleX(1.0f);
2759 toView.setScaleY(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002760 toView.setVisibility(View.VISIBLE);
2761 hideAndShowToolbarButtons(toState, null, null);
2762 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002763 }
2764
2765 void showAllApps(boolean animated) {
Michael Jurka883f55b2010-10-21 15:47:14 -07002766 if (mState == State.ALL_APPS) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002767 return;
Michael Jurka883f55b2010-10-21 15:47:14 -07002768 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002769
Michael Jurka79212d82010-07-30 16:36:20 -07002770 if (LauncherApplication.isScreenXLarge()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002771 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002772 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002773 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002774 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002775 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002776 } else {
2777 mAllAppsGrid.zoom(1.0f, animated);
2778 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002779
Romain Guyc16fea72010-03-12 17:17:56 -08002780 ((View) mAllAppsGrid).setFocusable(true);
2781 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002782
Joe Onorato7c312c12009-08-13 21:36:53 -07002783 // TODO: fade these two too
2784 mDeleteZone.setVisibility(View.GONE);
Adam Lesinski6b879f02010-11-04 16:15:23 -07002785
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002786 // Change the state *after* we've called all the transition code
2787 mState = State.ALL_APPS;
2788 }
2789
2790
2791 void showWorkspace(boolean animated) {
2792 showWorkspace(animated, null);
2793 }
2794
2795 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002796 if (layout != null) {
2797 // always animated, but that's ok since we never specify a layout and
2798 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002799 mWorkspace.unshrink(layout);
2800 } else {
2801 mWorkspace.unshrink(animated);
2802 }
2803 if (mState == State.ALL_APPS) {
2804 closeAllApps(animated);
2805 } else if (mState == State.CUSTOMIZE) {
2806 hideCustomizationDrawer(animated);
2807 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002808
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002809 // Change the state *after* we've called all the transition code
2810 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04002811 }
2812
Joe Onoratob2061212009-11-24 16:13:54 -05002813 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002814 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002815 * - Home from workspace
2816 * - from center screen
2817 * - from other screens
2818 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002819 * - from center screen
2820 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002821 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002822 * - from center screen
2823 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002824 * - Launch app from workspace and quit
2825 * - with back
2826 * - with home
2827 * - Launch app from all apps and quit
2828 * - with back
2829 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002830 * - Go to a screen that's not the default, then all
2831 * apps, and launch and app, and go back
2832 * - with back
2833 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002834 * - On workspace, long press power and go back
2835 * - with back
2836 * - with home
2837 * - On all apps, long press power and go back
2838 * - with back
2839 * - with home
2840 * - On workspace, power off
2841 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002842 * - Launch an app and turn off the screen while in that app
2843 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002844 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002845 * - From all apps
2846 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002847 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2848 * - From all apps
2849 * - From the center workspace
2850 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002851 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002852 void closeAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002853 if (mState == State.ALL_APPS) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002854 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002855 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002856 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002857 } else {
2858 mAllAppsGrid.zoom(0.0f, animated);
2859 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002860 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002861 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002862 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002863 }
2864
Joe Onorato7c312c12009-08-13 21:36:53 -07002865 void lockAllApps() {
2866 // TODO
2867 }
2868
2869 void unlockAllApps() {
2870 // TODO
2871 }
2872
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002873 // Show the customization drawer (only exists in x-large configuration)
2874 private void showCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002875 if (mState == State.ALL_APPS) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002876 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002877 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002878 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002879 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002880 // Change the state *after* we've called all the transition code
2881 mState = State.CUSTOMIZE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002882 }
2883
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002884 // Hide the customization drawer (only exists in x-large configuration)
2885 void hideCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002886 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002887 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002888 }
2889 }
2890
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002891 void addExternalItemToScreen(ItemInfo itemInfo, CellLayout layout) {
2892 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2893 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002894 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002895 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002896
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002897 void onWorkspaceClick(CellLayout layout) {
2898 showWorkspace(true, layout);
Michael Jurka213d9632010-07-28 11:29:25 -07002899 }
2900
Michael Jurka4ef207b2010-11-29 17:05:45 -08002901 // if successful in getting icon, return it; otherwise, set button to use default drawable
2902 private Drawable updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002903 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2904 ImageView button = (ImageView) findViewById(buttonId);
2905 Drawable toolbarIcon = null;
2906 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002907 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002908 // Look for the toolbar icon specified in the activity meta-data
2909 Bundle metaData = packageManager.getActivityInfo(
2910 activityName, PackageManager.GET_META_DATA).metaData;
2911 if (metaData != null) {
2912 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2913 if (iconResId != 0) {
2914 Resources res = packageManager.getResourcesForActivity(activityName);
2915 toolbarIcon = res.getDrawable(iconResId);
2916 }
2917 }
2918 } catch (NameNotFoundException e) {
2919 // Do nothing
2920 }
2921 // If we were unable to find the icon via the meta-data, use a generic one
2922 if (toolbarIcon == null) {
2923 button.setImageResource(fallbackDrawableId);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002924 return null;
Michael Jurka0423dcf2010-10-05 14:56:18 -07002925 } else {
2926 button.setImageDrawable(toolbarIcon);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002927 return toolbarIcon;
Michael Jurka0423dcf2010-10-05 14:56:18 -07002928 }
2929 }
2930
Michael Jurka4ef207b2010-11-29 17:05:45 -08002931 private void updateButtonWithDrawable(int buttonId, Drawable d) {
2932 ImageView button = (ImageView) findViewById(buttonId);
2933 button.setImageDrawable(d);
2934 }
2935
Michael Jurka0423dcf2010-10-05 14:56:18 -07002936 private void updateGlobalSearchIcon() {
2937 if (LauncherApplication.isScreenXLarge()) {
2938 final SearchManager searchManager =
2939 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2940 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002941 if (activityName != null) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002942 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002943 R.id.search_button, activityName, R.drawable.search_button_generic);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002944 } else {
2945 findViewById(R.id.search_button).setVisibility(View.GONE);
2946 }
2947 }
2948 }
2949
Michael Jurka4ef207b2010-11-29 17:05:45 -08002950 private void updateGlobalSearchIcon(Drawable d) {
2951 updateButtonWithDrawable(R.id.search_button, d);
2952 }
2953
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002954 private void updateVoiceSearchIcon() {
2955 if (LauncherApplication.isScreenXLarge()) {
2956 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2957 ComponentName activityName = intent.resolveActivity(getPackageManager());
2958 if (activityName != null) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002959 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002960 R.id.voice_button, activityName, R.drawable.ic_voice_search);
2961 } else {
2962 findViewById(R.id.voice_button).setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002963 }
2964 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002965 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002966
Michael Jurka4ef207b2010-11-29 17:05:45 -08002967 private void updateVoiceSearchIcon(Drawable d) {
2968 updateButtonWithDrawable(R.id.voice_button, d);
2969 }
2970
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002971 /**
2972 * Sets the app market icon (shown when all apps is visible on x-large screens)
2973 */
2974 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002975 if (LauncherApplication.isScreenXLarge()) {
2976 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2977 // Find the app market activity by resolving an intent.
2978 // (If multiple app markets are installed, it will return the ResolverActivity.)
2979 ComponentName activityName = intent.resolveActivity(getPackageManager());
2980 if (activityName != null) {
2981 mAppMarketIntent = intent;
Michael Jurka4ef207b2010-11-29 17:05:45 -08002982 sAppMarketIcon = updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002983 R.id.market_button, activityName, R.drawable.app_market_generic);
2984 }
2985 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002986 }
2987
Michael Jurka4ef207b2010-11-29 17:05:45 -08002988 private void updateAppMarketIcon(Drawable d) {
2989 updateButtonWithDrawable(R.id.market_button, d);
2990 }
2991
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002992 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002993 * Displays the shortcut creation dialog and launches, if necessary, the
2994 * appropriate activity.
2995 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002996 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002997 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2998 DialogInterface.OnShowListener {
2999
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003000 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07003001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003002 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003003 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07003004
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003005 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
3006 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003007 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07003008
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003009 builder.setInverseBackgroundForced(true);
3010
3011 AlertDialog dialog = builder.create();
3012 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07003013 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07003014 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003015
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003016 return dialog;
3017 }
3018
3019 public void onCancel(DialogInterface dialog) {
3020 mWaitingForResult = false;
3021 cleanup();
3022 }
3023
Romain Guycbb89e42009-06-08 15:52:54 -07003024 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07003025 }
3026
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003027 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08003028 try {
3029 dismissDialog(DIALOG_CREATE_SHORTCUT);
3030 } catch (Exception e) {
3031 // An exception is thrown if the dialog is not visible, which is fine
3032 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003033 }
3034
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003035 /**
3036 * Handle the action clicked in the "Add to home" dialog.
3037 */
3038 public void onClick(DialogInterface dialog, int which) {
3039 Resources res = getResources();
3040 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07003041
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003042 switch (which) {
3043 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08003044 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003045 break;
3046 }
Romain Guycbb89e42009-06-08 15:52:54 -07003047
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003048 case AddAdapter.ITEM_APPWIDGET: {
3049 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07003050
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003051 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
3052 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003053 // start the pick activity
3054 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
3055 break;
3056 }
Romain Guycbb89e42009-06-08 15:52:54 -07003057
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003058 case AddAdapter.ITEM_LIVE_FOLDER: {
3059 // Insert extra item to handle inserting folder
3060 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07003061
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003062 ArrayList<String> shortcutNames = new ArrayList<String>();
3063 shortcutNames.add(res.getString(R.string.group_folder));
3064 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07003065
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003066 ArrayList<ShortcutIconResource> shortcutIcons =
3067 new ArrayList<ShortcutIconResource>();
3068 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
3069 R.drawable.ic_launcher_folder));
3070 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
3071
3072 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
3073 pickIntent.putExtra(Intent.EXTRA_INTENT,
3074 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
3075 pickIntent.putExtra(Intent.EXTRA_TITLE,
3076 getText(R.string.title_select_live_folder));
3077 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07003078
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003079 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
3080 break;
3081 }
3082
3083 case AddAdapter.ITEM_WALLPAPER: {
3084 startWallpaper();
3085 break;
3086 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003087 }
3088 }
Romain Guy7b4ef332009-07-14 13:58:08 -07003089
3090 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07003091 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07003092 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003093 }
3094
3095 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003096 * Receives notifications when applications are added/removed.
3097 */
3098 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3099 @Override
3100 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003101 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05003102 String reason = intent.getStringExtra("reason");
3103 if (!"homekey".equals(reason)) {
3104 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08003105 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05003106 animate = false;
3107 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003108 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05003109 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003110 }
3111 }
3112
3113 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003114 * Receives notifications whenever the appwidgets are reset.
3115 */
3116 private class AppWidgetResetObserver extends ContentObserver {
3117 public AppWidgetResetObserver() {
3118 super(new Handler());
3119 }
3120
3121 @Override
3122 public void onChange(boolean selfChange) {
3123 onAppWidgetReset();
3124 }
3125 }
3126
3127 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003128 * If the activity is currently paused, signal that we need to re-run the loader
3129 * in onResume.
3130 *
3131 * This needs to be called from incoming places where resources might have been loaded
3132 * while we are paused. That is becaues the Configuration might be wrong
3133 * when we're not running, and if it comes back to what it was when we
3134 * were paused, we are not restarted.
3135 *
3136 * Implementation of the method from LauncherModel.Callbacks.
3137 *
3138 * @return true if we are currently paused. The caller might be able to
3139 * skip some work in that case since we will come back again.
3140 */
3141 public boolean setLoadOnResume() {
3142 if (mPaused) {
3143 Log.i(TAG, "setLoadOnResume");
3144 mOnResumeNeedsLoad = true;
3145 return true;
3146 } else {
3147 return false;
3148 }
3149 }
3150
3151 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003152 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003153 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003154 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003155 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003156 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003157 } else {
3158 return SCREEN_COUNT / 2;
3159 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003160 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003161
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003162 void setAllAppsPagedView(PagedView view) {
3163 mAllAppsPagedView = view;
3164 }
3165
Joe Onorato9c1289c2009-08-17 11:03:03 -04003166 /**
3167 * Refreshes the shortcuts shown on the workspace.
3168 *
3169 * Implementation of the method from LauncherModel.Callbacks.
3170 */
3171 public void startBinding() {
3172 final Workspace workspace = mWorkspace;
3173 int count = workspace.getChildCount();
3174 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003175 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04003176 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
3177 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003178
Joe Onorato9c1289c2009-08-17 11:03:03 -04003179 if (DEBUG_USER_INTERFACE) {
3180 android.widget.Button finishButton = new android.widget.Button(this);
3181 finishButton.setText("Finish");
3182 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
3183
3184 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
3185 public void onClick(View v) {
3186 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003187 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003188 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003189 }
3190 }
3191
3192 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003193 * Bind the items start-end from the list.
3194 *
3195 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003196 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003197 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
3198
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003199 setLoadOnResume();
3200
Joe Onorato9c1289c2009-08-17 11:03:03 -04003201 final Workspace workspace = mWorkspace;
3202
3203 for (int i=start; i<end; i++) {
3204 final ItemInfo item = shortcuts.get(i);
3205 mDesktopItems.add(item);
3206 switch (item.itemType) {
3207 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3208 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08003209 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003210 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
3211 false);
3212 break;
3213 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
3214 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003215 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Michael Jurkac9a96192010-11-01 11:52:08 -07003216 (UserFolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003217 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
3218 false);
3219 break;
3220 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
3221 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
3222 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003223 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04003224 (LiveFolderInfo) item);
3225 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
3226 false);
3227 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003228 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003229 }
3230
Joe Onorato9c1289c2009-08-17 11:03:03 -04003231 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003232 }
3233
Joe Onorato9c1289c2009-08-17 11:03:03 -04003234 /**
3235 * Implementation of the method from LauncherModel.Callbacks.
3236 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003237 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003238 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003239 sFolders.clear();
3240 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003241 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003242
3243 /**
3244 * Add the views for a widget to the workspace.
3245 *
3246 * Implementation of the method from LauncherModel.Callbacks.
3247 */
3248 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003249 setLoadOnResume();
3250
Daniel Sandler843e8602010-06-07 14:59:01 -04003251 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3252 if (DEBUG_WIDGETS) {
3253 Log.d(TAG, "bindAppWidget: " + item);
3254 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003255 final Workspace workspace = mWorkspace;
3256
3257 final int appWidgetId = item.appWidgetId;
3258 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003259 if (DEBUG_WIDGETS) {
3260 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3261 }
3262
Joe Onorato9c1289c2009-08-17 11:03:03 -04003263 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3264
Joe Onorato9c1289c2009-08-17 11:03:03 -04003265 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3266 item.hostView.setTag(item);
3267
3268 workspace.addInScreen(item.hostView, item.screen, item.cellX,
3269 item.cellY, item.spanX, item.spanY, false);
3270
Adam Cohended9f8d2010-11-03 13:25:16 -07003271 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3272
Joe Onorato9c1289c2009-08-17 11:03:03 -04003273 workspace.requestLayout();
3274
3275 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04003276
3277 if (DEBUG_WIDGETS) {
3278 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3279 + (SystemClock.uptimeMillis()-start) + "ms");
3280 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003281 }
3282
3283 /**
3284 * Callback saying that there aren't any more items to bind.
3285 *
3286 * Implementation of the method from LauncherModel.Callbacks.
3287 */
3288 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003289 setLoadOnResume();
3290
Joe Onorato9c1289c2009-08-17 11:03:03 -04003291 if (mSavedState != null) {
3292 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003293 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003294 }
3295
3296 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
3297 if (userFolders != null) {
3298 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003299 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003300 if (info != null) {
3301 openFolder(info);
3302 }
3303 }
3304 final Folder openFolder = mWorkspace.getOpenFolder();
3305 if (openFolder != null) {
3306 openFolder.requestFocus();
3307 }
3308 }
3309
Joe Onorato9c1289c2009-08-17 11:03:03 -04003310 mSavedState = null;
3311 }
3312
3313 if (mSavedInstanceState != null) {
3314 super.onRestoreInstanceState(mSavedInstanceState);
3315 mSavedInstanceState = null;
3316 }
3317
Joe Onorato9c1289c2009-08-17 11:03:03 -04003318 mWorkspaceLoading = false;
3319 }
3320
3321 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003322 * Updates the icons on the launcher that are affected by changes to the package list
3323 * on the device.
3324 */
3325 private void updateIconsAffectedByPackageManagerChanges() {
3326 updateAppMarketIcon();
3327 updateGlobalSearchIcon();
3328 updateVoiceSearchIcon();
3329 }
3330
3331 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003332 * Add the icons for all apps.
3333 *
3334 * Implementation of the method from LauncherModel.Callbacks.
3335 */
3336 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003337 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003338 if (mCustomizePagedView != null) {
3339 mCustomizePagedView.setApps(apps);
3340 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003341 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003342 }
3343
3344 /**
3345 * A package was installed.
3346 *
3347 * Implementation of the method from LauncherModel.Callbacks.
3348 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003349 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003350 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003351 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003352 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003353 if (mCustomizePagedView != null) {
3354 mCustomizePagedView.addApps(apps);
3355 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003356 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003357 }
3358
3359 /**
3360 * A package was updated.
3361 *
3362 * Implementation of the method from LauncherModel.Callbacks.
3363 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003364 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003365 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003366 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003367 mWorkspace.updateShortcuts(apps);
3368 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003369 if (mCustomizePagedView != null) {
3370 mCustomizePagedView.updateApps(apps);
3371 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003372 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003373 }
3374
3375 /**
3376 * A package was uninstalled.
3377 *
3378 * Implementation of the method from LauncherModel.Callbacks.
3379 */
Joe Onorato36115782010-06-17 13:28:48 -04003380 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003381 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003382 if (permanent) {
3383 mWorkspace.removeItems(apps);
3384 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003385 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003386 if (mCustomizePagedView != null) {
3387 mCustomizePagedView.removeApps(apps);
3388 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003389 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003390 }
Joe Onoratobe386092009-11-17 17:32:16 -08003391
3392 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003393 * A number of packages were updated.
3394 */
3395 public void bindPackagesUpdated() {
3396 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003397 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003398 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003399 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003400 }
3401
3402 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003403 * Prints out out state for debugging.
3404 */
3405 public void dumpState() {
3406 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003407 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003408 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3409 Log.d(TAG, "mRestoring=" + mRestoring);
3410 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3411 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3412 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003413 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003414 mModel.dumpState();
3415 mAllAppsGrid.dumpState();
3416 Log.d(TAG, "END launcher2 dump state");
3417 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003418}