blob: bc341ef813893cb2a4b2e1608f9193f099af6455 [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
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Michael Jurka946ad472010-07-09 18:05:18 -070026import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.app.Dialog;
29import android.app.SearchManager;
30import android.app.StatusBarManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070031import android.appwidget.AppWidgetManager;
32import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080033import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080034import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070035import android.content.ClipData;
36import android.content.ClipDescription;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040037import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080038import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.Context;
40import android.content.DialogInterface;
41import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070042import android.content.IntentFilter;
Adam Cohen716b51e2011-06-30 12:09:54 -070043import android.content.Intent.ShortcutIconResource;
Winson Chungaafa03c2010-06-11 17:34:16 -070044import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070046import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070048import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080049import android.database.ContentObserver;
Michael Jurkaaf442092010-06-10 17:01:57 -070050import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070051import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040052import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070053import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020055import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080056import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070057import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040058import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080059import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070060import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080061import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.text.Selection;
63import android.text.SpannableStringBuilder;
64import android.text.TextUtils;
65import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070066import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080067import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080068import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.view.KeyEvent;
70import android.view.LayoutInflater;
71import android.view.Menu;
72import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070073import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080074import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075import android.view.View;
Adam Cohen716b51e2011-06-30 12:09:54 -070076import android.view.ViewGroup;
Adam Cohen860f4c52011-01-27 20:16:13 -080077import android.view.View.OnLongClickListener;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080078import android.view.accessibility.AccessibilityEvent;
Adam Cohenf16e5712011-01-13 13:31:45 -080079import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070081import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070083import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070084import android.widget.TextView;
85import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070086
Adam Cohendf2cc412011-04-27 16:56:57 -070087import com.android.common.Search;
88import com.android.launcher.R;
Romain Guyedcce092010-03-04 13:03:17 -080089
Adam Cohenc0dcf592011-06-01 15:30:43 -070090import java.io.DataInputStream;
91import java.io.DataOutputStream;
92import java.io.FileNotFoundException;
93import java.io.IOException;
94import java.util.ArrayList;
95import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -070096
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097/**
98 * Default launcher application.
99 */
Michael Jurka946ad472010-07-09 18:05:18 -0700100public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700101 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
102 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800103 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700104 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800105
Joe Onorato9c1289c2009-08-17 11:03:03 -0400106 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400107 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700108
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800110 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
111
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800112 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700113 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
114 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
116 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700117 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800118
119 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700120 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 private static final int REQUEST_PICK_APPLICATION = 6;
122 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700123 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700124 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
126 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
127
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800128 static final int SCREEN_COUNT = 5;
129 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130
Joe Onorato7c312c12009-08-13 21:36:53 -0700131 static final int DIALOG_CREATE_SHORTCUT = 1;
132 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133
Romain Guy98d01652009-06-30 16:21:04 -0700134 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135
136 // Type: int
137 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700138 // Type: int
139 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700141 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
142 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
144 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700145 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700147 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 // Type: boolean
149 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
150 // Type: long
151 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
152
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700153 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
154
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700155 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700156 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700157 private State mState = State.WORKSPACE;
158 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700159
Joe Onorato9c1289c2009-08-17 11:03:03 -0400160 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700161 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
162 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800165 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800167 private final BroadcastReceiver mCloseSystemDialogsReceiver
168 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800169 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
170
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 private LayoutInflater mInflater;
172
Joe Onorato00acb122009-08-04 16:04:30 -0400173 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700175
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700176 private AppWidgetManager mAppWidgetManager;
177 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700178
Winson Chung3d503fb2011-07-13 17:25:49 -0700179 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700180 private int[] mTmpAddItemCellCoordinates = new int[2];
181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 private FolderInfo mFolderInfo;
183
Winson Chung3d503fb2011-07-13 17:25:49 -0700184 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800185 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700186
Winson Chungf0ea4d32011-06-06 14:27:16 -0700187 private SearchDropTargetBar mSearchDeleteBar;
188 private AppsCustomizeTabHost mAppsCustomizeTabHost;
189 private AppsCustomizePagedView mAppsCustomizeContent;
190 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 private Bundle mSavedState;
193
194 private SpannableStringBuilder mDefaultKeySsb = null;
195
Joe Onorato9c1289c2009-08-17 11:03:03 -0400196 private boolean mWorkspaceLoading = true;
197
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800198 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199 private boolean mRestoring;
200 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700201 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202
203 private Bundle mSavedInstanceState;
204
Joe Onorato9c1289c2009-08-17 11:03:03 -0400205 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800206 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800207 private boolean mUserPresent = true;
208 private boolean mVisible = false;
209 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400210
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700211 private static LocaleConfiguration sLocaleConfiguration = null;
212
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700213 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700214
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400215 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400216 private String[] mHotseatConfig = null;
217 private Intent[] mHotseats = null;
218 private Drawable[] mHotseatIcons = null;
219 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400220
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700221 private Intent mAppMarketIntent = null;
222
Adam Cohended9f8d2010-11-03 13:25:16 -0700223 // Related to the auto-advancing of widgets
224 private final int ADVANCE_MSG = 1;
225 private final int mAdvanceInterval = 20000;
226 private final int mAdvanceStagger = 250;
227 private long mAutoAdvanceSentTime;
228 private long mAutoAdvanceTimeLeft = -1;
229 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
230 new HashMap<View, AppWidgetProviderInfo>();
231
Winson Chung400438b2011-01-16 17:53:48 -0800232 // Determines how long to wait after a rotation before restoring the screen orientation to
233 // match the sensor state.
234 private final int mRestoreScreenOrientationDelay = 500;
235
Michael Jurka4ef207b2010-11-29 17:05:45 -0800236 // External icons saved in case of resource changes, orientation, etc.
Michael Jurkae7bf83b2010-12-14 18:02:21 -0800237 private static Drawable.ConstantState sGlobalSearchIcon;
238 private static Drawable.ConstantState sVoiceSearchIcon;
239 private static Drawable.ConstantState sAppMarketIcon;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800240
Adam Cohen2801caf2011-05-13 20:57:39 -0700241 private DragLayer mDragLayer;
242
Michael Jurkaddd62e92011-02-16 17:49:14 -0800243 private BubbleTextView mWaitingForResume;
244
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800245 private static ArrayList<PendingAddArguments> sPendingAddList
246 = new ArrayList<PendingAddArguments>();
247
248 private static class PendingAddArguments {
249 int requestCode;
250 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700251 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800252 int screen;
253 int cellX;
254 int cellY;
255 }
256
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257 @Override
258 protected void onCreate(Bundle savedInstanceState) {
259 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800260 LauncherApplication app = ((LauncherApplication)getApplication());
261 mModel = app.setLauncher(this);
262 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400263 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700265
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700266 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700267 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
268 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200271 android.os.Debug.startMethodTracing(
272 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 }
274
275 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276 setContentView(R.layout.launcher);
277 setupViews();
278
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800279 registerContentObservers();
280
Joe Onorato7c312c12009-08-13 21:36:53 -0700281 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700282
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283 mSavedState = savedInstanceState;
284 restoreState(mSavedState);
285
Winson Chunga12a2502010-12-20 14:41:35 -0800286 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700287 if (mAppsCustomizeContent != null) {
288 mAppsCustomizeContent.onPackagesUpdated();
289 }
Winson Chunga12a2502010-12-20 14:41:35 -0800290
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800291 if (PROFILE_STARTUP) {
292 android.os.Debug.stopMethodTracing();
293 }
294
295 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400296 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297 }
298
299 // For handling default keys
300 mDefaultKeySsb = new SpannableStringBuilder();
301 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800302
303 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
304 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800305
306 // If we have a saved version of these external icons, we load them up immediately
Winson Chungf0ea4d32011-06-06 14:27:16 -0700307 if (sGlobalSearchIcon == null || sVoiceSearchIcon == null || sAppMarketIcon == null) {
308 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100309 updateGlobalSearchIcon();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700310 }
311 if (sGlobalSearchIcon != null) {
312 updateGlobalSearchIcon(sGlobalSearchIcon);
313 }
314 if (sVoiceSearchIcon != null) {
315 updateVoiceSearchIcon(sVoiceSearchIcon);
316 }
317 if (sAppMarketIcon != null) {
318 updateAppMarketIcon(sAppMarketIcon);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800319 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800320 }
Romain Guycbb89e42009-06-08 15:52:54 -0700321
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800322 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700323 if (sLocaleConfiguration == null) {
324 new AsyncTask<Void, Void, LocaleConfiguration>() {
325 @Override
326 protected LocaleConfiguration doInBackground(Void... unused) {
327 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
328 readConfiguration(Launcher.this, localeConfiguration);
329 return localeConfiguration;
330 }
331
332 @Override
333 protected void onPostExecute(LocaleConfiguration result) {
334 sLocaleConfiguration = result;
335 checkForLocaleChange(); // recursive, but now with a locale configuration
336 }
337 }.execute();
338 return;
339 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700340
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 final Configuration configuration = getResources().getConfiguration();
342
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700343 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800344 final String locale = configuration.locale.toString();
345
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700346 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347 final int mcc = configuration.mcc;
348
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700349 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350 final int mnc = configuration.mnc;
351
Romain Guy84f296c2009-11-04 15:00:44 -0800352 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800353
Romain Guy84f296c2009-11-04 15:00:44 -0800354 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700355 sLocaleConfiguration.locale = locale;
356 sLocaleConfiguration.mcc = mcc;
357 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700358
Joe Onorato0589f0f2010-02-08 13:44:00 -0800359 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700360
361 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
362 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700363 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700364 public void run() {
365 writeConfiguration(Launcher.this, localeConfiguration);
366 }
367 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700368 }
369 }
370
371 private static class LocaleConfiguration {
372 public String locale;
373 public int mcc = -1;
374 public int mnc = -1;
375 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700376
Romain Guy98d01652009-06-30 16:21:04 -0700377 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
378 DataInputStream in = null;
379 try {
380 in = new DataInputStream(context.openFileInput(PREFERENCES));
381 configuration.locale = in.readUTF();
382 configuration.mcc = in.readInt();
383 configuration.mnc = in.readInt();
384 } catch (FileNotFoundException e) {
385 // Ignore
386 } catch (IOException e) {
387 // Ignore
388 } finally {
389 if (in != null) {
390 try {
391 in.close();
392 } catch (IOException e) {
393 // Ignore
394 }
395 }
396 }
397 }
398
399 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
400 DataOutputStream out = null;
401 try {
402 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
403 out.writeUTF(configuration.locale);
404 out.writeInt(configuration.mcc);
405 out.writeInt(configuration.mnc);
406 out.flush();
407 } catch (FileNotFoundException e) {
408 // Ignore
409 } catch (IOException e) {
410 //noinspection ResultOfMethodCallIgnored
411 context.getFileStreamPath(PREFERENCES).delete();
412 } finally {
413 if (out != null) {
414 try {
415 out.close();
416 } catch (IOException e) {
417 // Ignore
418 }
419 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800420 }
421 }
422
Adam Cohen716b51e2011-06-30 12:09:54 -0700423 public DragLayer getDragLayer() {
424 return mDragLayer;
425 }
426
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 static int getScreen() {
428 synchronized (sLock) {
429 return sScreen;
430 }
431 }
432
433 static void setScreen(int screen) {
434 synchronized (sLock) {
435 sScreen = screen;
436 }
437 }
438
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400439 // Note: This doesn't do all the client-id magic that BrowserProvider does
440 // in Browser. (http://b/2425179)
441 private Uri getDefaultBrowserUri() {
442 String url = getString(R.string.default_browser_url);
443 if (url.indexOf("{CID}") != -1) {
444 url = url.replace("{CID}", "android-google");
445 }
446 return Uri.parse(url);
447 }
448
Winson Chung557d6ed2011-07-08 15:34:52 -0700449 /**
450 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
451 * a configuration step, this allows the proper animations to run after other transitions.
452 */
453 private boolean completeAdd(PendingAddArguments args) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800454 switch (args.requestCode) {
455 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700456 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
457 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800458 break;
459 case REQUEST_PICK_SHORTCUT:
460 processShortcut(args.intent);
461 break;
462 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700463 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
464 args.cellY);
Winson Chung557d6ed2011-07-08 15:34:52 -0700465 return true;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800466 case REQUEST_PICK_APPWIDGET:
467 addAppWidgetFromPick(args.intent);
468 break;
469 case REQUEST_CREATE_APPWIDGET:
470 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Winson Chung3d503fb2011-07-13 17:25:49 -0700471 completeAddAppWidget(appWidgetId, args.container, args.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -0700472 return true;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800473 case REQUEST_PICK_WALLPAPER:
474 // We just wanted the activity result here so we can clear mWaitingForResult
475 break;
476 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700477 return false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800478 }
479
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800480 @Override
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800481 protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700482 boolean delayExitSpringLoadedMode = false;
Romain Guyaad5ef42009-06-10 02:48:37 -0700483 mWaitingForResult = false;
484
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800485 // The pattern used here is that a user PICKs a specific application,
486 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700487
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800488 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
489 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chung3d503fb2011-07-13 17:25:49 -0700490 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID &&
491 mPendingAddInfo.screen > -1) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800492 final PendingAddArguments args = new PendingAddArguments();
493 args.requestCode = requestCode;
494 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700495 args.container = mPendingAddInfo.container;
496 args.screen = mPendingAddInfo.screen;
497 args.cellX = mPendingAddInfo.cellX;
498 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800499
500 // If the loader is still running, defer the add until it is done.
501 if (isWorkspaceLocked()) {
502 sPendingAddList.add(args);
503 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700504 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800505 }
Romain Guy18042c82009-11-06 11:44:55 -0800506 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
Winson Chung557d6ed2011-07-08 15:34:52 -0700507 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED) {
508 if (data != null) {
509 // Clean up the appWidgetId if we canceled
510 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
511 if (appWidgetId != -1) {
512 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
513 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800514 }
515 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700516
517 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
518 exitSpringLoadedDragModeDelayed(delayExitSpringLoadedMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800519 }
520
521 @Override
522 protected void onResume() {
523 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800524 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700525 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400526 mWorkspaceLoading = true;
527 mModel.startLoader(this, true);
528 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700529 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800530 }
Michael Jurkaddd62e92011-02-16 17:49:14 -0800531 if (mWaitingForResume != null) {
532 mWaitingForResume.setStayPressed(false);
533 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700534 // When we resume Launcher, a different Activity might be responsible for the app
535 // market intent, so refresh the icon
536 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800537 }
538
539 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700540 protected void onPause() {
541 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700542 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800543 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700544 }
Romain Guycbb89e42009-06-08 15:52:54 -0700545
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700546 @Override
547 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400548 // Flag the loader to stop early before switching
549 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700550 if (mAppsCustomizeContent != null) {
551 mAppsCustomizeContent.surrender();
552 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800553 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700554 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700555
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800556 // We can't hide the IME if it was forced open. So don't bother
557 /*
558 @Override
559 public void onWindowFocusChanged(boolean hasFocus) {
560 super.onWindowFocusChanged(hasFocus);
561
562 if (hasFocus) {
563 final InputMethodManager inputManager = (InputMethodManager)
564 getSystemService(Context.INPUT_METHOD_SERVICE);
565 WindowManager.LayoutParams lp = getWindow().getAttributes();
566 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
567 android.os.Handler()) {
568 protected void onReceiveResult(int resultCode, Bundle resultData) {
569 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
570 }
571 });
572 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
573 }
574 }
575 */
576
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577 private boolean acceptFilter() {
578 final InputMethodManager inputManager = (InputMethodManager)
579 getSystemService(Context.INPUT_METHOD_SERVICE);
580 return !inputManager.isFullscreenMode();
581 }
582
583 @Override
584 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700585 final int uniChar = event.getUnicodeChar();
586 final boolean handled = super.onKeyDown(keyCode, event);
587 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
588 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800589 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
590 keyCode, event);
591 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700592 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700593 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700594 // showSearchDialog()
595 // If there are multiple keystrokes before the search dialog takes focus,
596 // onSearchRequested() will be called for every keystroke,
597 // but it is idempotent, so it's fine.
598 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800599 }
600 }
601
Joe Onorato8a9625e2010-01-28 15:55:35 -0800602 // Eat the long press event so the keyboard doesn't come up.
603 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
604 return true;
605 }
606
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800607 return handled;
608 }
609
Karl Rosaen138a0412009-04-23 19:00:21 -0700610 private String getTypedText() {
611 return mDefaultKeySsb.toString();
612 }
613
614 private void clearTypedText() {
615 mDefaultKeySsb.clear();
616 mDefaultKeySsb.clearSpans();
617 Selection.setSelection(mDefaultKeySsb, 0);
618 }
619
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800620 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700621 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
622 * State
623 */
624 private static State intToState(int stateOrdinal) {
625 State state = State.WORKSPACE;
626 final State[] stateValues = State.values();
627 for (int i = 0; i < stateValues.length; i++) {
628 if (stateValues[i].ordinal() == stateOrdinal) {
629 state = stateValues[i];
630 break;
631 }
632 }
633 return state;
634 }
635
636 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800637 * Restores the previous state, if it exists.
638 *
639 * @param savedState The previous state.
640 */
641 private void restoreState(Bundle savedState) {
642 if (savedState == null) {
643 return;
644 }
645
Michael Jurka883f55b2010-10-21 15:47:14 -0700646 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
647
Winson Chungf0ea4d32011-06-06 14:27:16 -0700648 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800649 showAllApps(false);
650 }
651
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800652 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
653 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700654 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 }
656
Winson Chung3d503fb2011-07-13 17:25:49 -0700657 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
658 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700659
Winson Chung3d503fb2011-07-13 17:25:49 -0700660
661 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
662 mPendingAddInfo.container = pendingAddContainer;
663 mPendingAddInfo.screen = pendingAddScreen;
664 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
665 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 mRestoring = true;
667 }
668
669 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
670 if (renameFolder) {
671 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700672 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 mRestoring = true;
674 }
Winson Chunga12a2502010-12-20 14:41:35 -0800675
Winson Chung785d2eb2011-04-14 16:08:02 -0700676
677 // Restore the AppsCustomize tab
678 if (mAppsCustomizeTabHost != null) {
679 String curTab = savedState.getString("apps_customize_currentTab");
680 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700681 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700682 mAppsCustomizeContent.setContentType(
683 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
684 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
685 }
686
687 // Note: currently we do not restore the page for the AppsCustomize pane because the
688 // change in layout can drastically affect the saved page index
689 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800690 }
691
692 /**
693 * Finds all the views we need and configure them properly.
694 */
695 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700696 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400697
Winson Chung4c98d922011-05-31 16:50:48 -0700698 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
699 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800700
Winson Chung4c98d922011-05-31 16:50:48 -0700701 // Setup the drag layer
702 mDragLayer.setup(this, dragController);
703
Winson Chung3d503fb2011-07-13 17:25:49 -0700704 // Setup the hotseat
705 mHotseat = (Hotseat) findViewById(R.id.hotseat);
706 if (mHotseat != null) {
707 mHotseat.setup(this);
708 }
709
Winson Chung4c98d922011-05-31 16:50:48 -0700710 // Setup the workspace
711 mWorkspace.setHapticFeedbackEnabled(false);
712 mWorkspace.setOnLongClickListener(this);
713 mWorkspace.setup(this, dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700714 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700715
Winson Chungf0ea4d32011-06-06 14:27:16 -0700716 // Get the search/delete bar
717 mSearchDeleteBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700718
Winson Chungf0ea4d32011-06-06 14:27:16 -0700719 // Setup AppsCustomize
720 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
721 findViewById(R.id.apps_customize_pane);
722 mAppsCustomizeContent = (AppsCustomizePagedView)
723 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
724 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400725
Romain Guy1fbc1c82009-11-09 20:43:08 -0800726
Winson Chung4c98d922011-05-31 16:50:48 -0700727
Winson Chung3d503fb2011-07-13 17:25:49 -0700728 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700729 dragController.setDragScoller(mWorkspace);
730 dragController.setScrollView(mDragLayer);
731 dragController.setMoveTarget(mWorkspace);
732 dragController.addDropTarget(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700733 if (mSearchDeleteBar != null) {
734 mSearchDeleteBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800735 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800736 }
737
Romain Guy8a73c512009-11-09 19:19:59 -0800738
Winson Chungaafa03c2010-06-11 17:34:16 -0700739
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800740 /**
741 * Creates a view representing a shortcut.
742 *
743 * @param info The data structure describing the shortcut.
744 *
745 * @return A View inflated from R.layout.application.
746 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800747 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800748 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700749 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 }
751
752 /**
753 * Creates a view representing a shortcut inflated from the specified resource.
754 *
755 * @param layoutResId The id of the XML layout used to create the shortcut.
756 * @param parent The group the shortcut belongs to.
757 * @param info The data structure describing the shortcut.
758 *
759 * @return A View inflated from layoutResId.
760 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800761 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800762 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
763 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800764 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800765 return favorite;
766 }
767
768 /**
769 * Add an application shortcut to the workspace.
770 *
771 * @param data The intent describing the application.
772 * @param cellInfo The position on screen where to create the shortcut.
773 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700774 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700775 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700776 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700777
Adam Cohenfbba09b2011-07-18 21:43:05 -0700778 // First we check if we already know the exact location where we want to add this item.
779 if (cellX >= 0 && cellY >= 0) {
780 cellXY[0] = cellX;
781 cellXY[1] = cellY;
782 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700783 showOutOfSpaceMessage();
784 return;
785 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800786
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800787 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800788
Romain Guy73b979d2009-06-09 12:57:21 -0700789 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800790 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800791 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800792 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700793 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700794 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800795 } else {
796 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800797 }
798 }
Romain Guycbb89e42009-06-08 15:52:54 -0700799
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800800 /**
801 * Add a shortcut to the workspace.
802 *
803 * @param data The intent describing the shortcut.
804 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800805 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700806 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
807 int cellY) {
808 int[] cellXY = mTmpAddItemCellCoordinates;
809 int[] touchXY = mPendingAddInfo.dropPos;
810 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700811
Michael Jurkad3ef3062010-11-23 16:23:58 -0800812 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700813
814 // First we check if we already know the exact location where we want to add this item.
815 if (cellX >= 0 && cellY >= 0) {
816 cellXY[0] = cellX;
817 cellXY[1] = cellY;
818 foundCellSpan = true;
819 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800820 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700821 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800822 foundCellSpan = (result != null);
823 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700824 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800825 }
826
827 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700828 showOutOfSpaceMessage();
829 return;
830 }
831
832 final ShortcutInfo info = mModel.addShortcut(
Winson Chung3d503fb2011-07-13 17:25:49 -0700833 this, data, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800834
835 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800836 final View view = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -0700837 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
838 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800839 }
840 }
841
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700843 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700845 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700846 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700848 private void completeAddAppWidget(final int appWidgetId, long container, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700849 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700850
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700851 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700852 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700853
854 // We want to account for the extra amount of padding that we are adding to the widget
855 // to ensure that it gets the full amount of space that it has requested
856 Resources r = getResources();
857 int requiredWidth = appWidgetInfo.minWidth +
858 r.getDimensionPixelSize(R.dimen.app_widget_padding_left) +
859 r.getDimensionPixelSize(R.dimen.app_widget_padding_right);
860 int requiredHeight = appWidgetInfo.minHeight +
861 r.getDimensionPixelSize(R.dimen.app_widget_padding_top) +
862 r.getDimensionPixelSize(R.dimen.app_widget_padding_bottom);
863 int[] spanXY = layout.rectToCell(requiredWidth, requiredHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700864
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700866 // We have saved the position to which the widget was dragged-- this really only matters
867 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700868 int[] cellXY = mTmpAddItemCellCoordinates;
869 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700870 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700871 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
872 cellXY[0] = mPendingAddInfo.cellX;
873 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700874 foundCellSpan = true;
875 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700876 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700877 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700878 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800879 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700880 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700881 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700882 }
883
Michael Jurka0280c3b2010-09-17 15:00:07 -0700884 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -0800885 if (appWidgetId != -1) {
886 // Deleting an app widget ID is a void call but writes to disk before returning
887 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -0800888 new Thread("deleteAppWidgetId") {
889 public void run() {
890 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
891 }
892 }.start();
893 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700894 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -0800895 return;
896 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800897
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700898 // Build Launcher-specific widget info and save to database
899 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700900 launcherInfo.spanX = spanXY[0];
901 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700902
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800903 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -0700904 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800905
906 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800907 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700908 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700909
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700910 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800911 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700912
Winson Chung3d503fb2011-07-13 17:25:49 -0700913 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400914 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -0700915
916 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800917 }
918 }
Romain Guycbb89e42009-06-08 15:52:54 -0700919
Adam Cohended9f8d2010-11-03 13:25:16 -0700920 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
921 @Override
922 public void onReceive(Context context, Intent intent) {
923 final String action = intent.getAction();
924 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
925 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -0700926 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -0700927 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -0700928
929 // Reset AllApps to it's initial state
Winson Chung785d2eb2011-04-14 16:08:02 -0700930 if (mAppsCustomizeContent != null) {
931 mAppsCustomizeContent.reset();
932 }
Adam Cohended9f8d2010-11-03 13:25:16 -0700933 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
934 mUserPresent = true;
935 updateRunning();
936 }
937 }
938 };
939
940 @Override
941 public void onAttachedToWindow() {
942 super.onAttachedToWindow();
943
944 // Listen for broadcasts related to user-presence
945 final IntentFilter filter = new IntentFilter();
946 filter.addAction(Intent.ACTION_SCREEN_OFF);
947 filter.addAction(Intent.ACTION_USER_PRESENT);
948 registerReceiver(mReceiver, filter);
949
Adam Cohend113e0c2010-11-11 10:48:05 -0800950 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -0700951 mVisible = true;
952 }
953
954 @Override
955 public void onDetachedFromWindow() {
956 super.onDetachedFromWindow();
957 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -0700958 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -0700959
Adam Cohend113e0c2010-11-11 10:48:05 -0800960 if (mAttached) {
961 unregisterReceiver(mReceiver);
962 mAttached = false;
963 }
Adam Cohended9f8d2010-11-03 13:25:16 -0700964 updateRunning();
965 }
966
967 public void onWindowVisibilityChanged(int visibility) {
968 mVisible = visibility == View.VISIBLE;
969 updateRunning();
970 }
971
972 private void sendAdvanceMessage(long delay) {
973 mHandler.removeMessages(ADVANCE_MSG);
974 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
975 mHandler.sendMessageDelayed(msg, delay);
976 mAutoAdvanceSentTime = System.currentTimeMillis();
977 }
978
979 private void updateRunning() {
980 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
981 if (autoAdvanceRunning != mAutoAdvanceRunning) {
982 mAutoAdvanceRunning = autoAdvanceRunning;
983 if (autoAdvanceRunning) {
984 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
985 sendAdvanceMessage(delay);
986 } else {
987 if (!mWidgetsToAdvance.isEmpty()) {
988 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
989 (System.currentTimeMillis() - mAutoAdvanceSentTime));
990 }
991 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -0800992 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -0700993 }
994 }
995 }
996
997 private final Handler mHandler = new Handler() {
998 @Override
999 public void handleMessage(Message msg) {
1000 if (msg.what == ADVANCE_MSG) {
1001 int i = 0;
1002 for (View key: mWidgetsToAdvance.keySet()) {
1003 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1004 final int delay = mAdvanceStagger * i;
1005 if (v instanceof Advanceable) {
1006 postDelayed(new Runnable() {
1007 public void run() {
1008 ((Advanceable) v).advance();
1009 }
1010 }, delay);
1011 }
1012 i++;
1013 }
1014 sendAdvanceMessage(mAdvanceInterval);
1015 }
1016 }
1017 };
1018
1019 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001020 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001021 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1022 if (v instanceof Advanceable) {
1023 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001024 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001025 updateRunning();
1026 }
1027 }
1028
1029 void removeWidgetToAutoAdvance(View hostView) {
1030 if (mWidgetsToAdvance.containsKey(hostView)) {
1031 mWidgetsToAdvance.remove(hostView);
1032 updateRunning();
1033 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001034 }
1035
Joe Onorato9c1289c2009-08-17 11:03:03 -04001036 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001037 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001038 launcherInfo.hostView = null;
1039 }
1040
Adam Cohended9f8d2010-11-03 13:25:16 -07001041 void showOutOfSpaceMessage() {
1042 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1043 }
1044
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001045 public LauncherAppWidgetHost getAppWidgetHost() {
1046 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047 }
Romain Guycbb89e42009-06-08 15:52:54 -07001048
Winson Chunga9abd0e2010-10-27 17:18:37 -07001049 public LauncherModel getModel() {
1050 return mModel;
1051 }
1052
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001053 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001054 getWindow().closeAllPanels();
1055
1056 try {
1057 dismissDialog(DIALOG_CREATE_SHORTCUT);
1058 // Unlock the workspace if the dialog was showing
1059 } catch (Exception e) {
1060 // An exception is thrown if the dialog is not visible, which is fine
1061 }
1062
1063 try {
1064 dismissDialog(DIALOG_RENAME_FOLDER);
1065 // Unlock the workspace if the dialog was showing
1066 } catch (Exception e) {
1067 // An exception is thrown if the dialog is not visible, which is fine
1068 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001069
1070 // Whatever we were doing is hereby canceled.
1071 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001072 }
1073
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 @Override
1075 protected void onNewIntent(Intent intent) {
1076 super.onNewIntent(intent);
1077
1078 // Close the menu
1079 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001080 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001081 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001082
Adam Cohen95bb8002011-07-03 23:40:28 -07001083 closeFolder();
1084
Joe Onorato14f122b2009-11-19 14:06:36 -08001085 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1086 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001087
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001088 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001089 mWorkspace.exitWidgetResizeMode();
Patrick Dubroya0aa0122011-02-24 11:42:23 -08001090 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001091 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001092 }
Winson Chungde1af762011-07-21 16:44:07 -07001093 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001094 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001095
Joe Onorato3a8820b2009-11-10 15:06:42 -08001096 final View v = getWindow().peekDecorView();
1097 if (v != null && v.getWindowToken() != null) {
1098 InputMethodManager imm = (InputMethodManager)getSystemService(
1099 INPUT_METHOD_SERVICE);
1100 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001102
Michael Jurka35aa14d2011-07-07 17:01:08 -07001103 // Reset AllApps to its initial state
Winson Chung785d2eb2011-04-14 16:08:02 -07001104 if (mAppsCustomizeContent != null) {
1105 mAppsCustomizeContent.reset();
1106 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107 }
1108 }
1109
1110 @Override
1111 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1112 // Do not call super here
1113 mSavedInstanceState = savedInstanceState;
1114 }
1115
1116 @Override
1117 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001118 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001119 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001120
Michael Jurka883f55b2010-10-21 15:47:14 -07001121 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001122 // We close any open folder since it will not be re-opened, and we need to make sure
1123 // this state is reflected.
1124 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001125
Winson Chung3d503fb2011-07-13 17:25:49 -07001126 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1127 mWaitingForResult) {
1128 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1129 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1130 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1131 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132 }
1133
1134 if (mFolderInfo != null && mWaitingForResult) {
1135 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1136 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1137 }
Michael Jurka946ad472010-07-09 18:05:18 -07001138
Winson Chung785d2eb2011-04-14 16:08:02 -07001139 // Save the current AppsCustomize tab
1140 if (mAppsCustomizeTabHost != null) {
1141 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1142 if (currentTabTag != null) {
1143 outState.putString("apps_customize_currentTab", currentTabTag);
1144 }
1145 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001146 }
1147
1148 @Override
1149 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001150 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001151
Winson Chungcd2b0142011-06-08 16:02:26 -07001152 // Stop callbacks from LauncherModel
1153 LauncherApplication app = ((LauncherApplication) getApplication());
1154 mModel.stopLoader();
1155 app.setLauncher(null);
1156
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001157 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001158 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001159 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001160 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001162 mAppWidgetHost = null;
1163
1164 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165
1166 TextKeyListener.getInstance().release();
1167
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001168
Winson Chung3d503fb2011-07-13 17:25:49 -07001169 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001170
1171 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001172 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001173
1174 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1175 mWorkspace.removeAllViews();
1176 mWorkspace = null;
1177 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001178
1179 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001180 }
1181
Adam Cohena9cf38f2011-05-02 15:36:58 -07001182 public DragController getDragController() {
1183 return mDragController;
1184 }
1185
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001186 @Override
1187 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001188 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001189 super.startActivityForResult(intent, requestCode);
1190 }
1191
1192 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001193 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001195
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001196 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001197
Karl Rosaen138a0412009-04-23 19:00:21 -07001198 if (initialQuery == null) {
1199 // Use any text typed in the launcher as the initial query
1200 initialQuery = getTypedText();
1201 clearTypedText();
1202 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001203 if (appSearchData == null) {
1204 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001205 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001206 }
Romain Guycbb89e42009-06-08 15:52:54 -07001207
Karl Rosaen138a0412009-04-23 19:00:21 -07001208 final SearchManager searchManager =
1209 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001210 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001211 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 }
1213
1214 @Override
1215 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001216 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001217 return false;
1218 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219
1220 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001221
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001222 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1223 .setIcon(android.R.drawable.ic_menu_add)
1224 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001225 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1226 .setIcon(android.R.drawable.ic_menu_manage)
1227 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001228 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 .setIcon(android.R.drawable.ic_menu_gallery)
1230 .setAlphabeticShortcut('W');
1231 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1232 .setIcon(android.R.drawable.ic_search_category_default)
1233 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1234 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1235 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1236 .setAlphabeticShortcut('N');
1237
1238 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001239 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1240 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241
1242 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1243 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1244 .setIntent(settings);
1245
1246 return true;
1247 }
1248
1249 @Override
1250 public boolean onPrepareOptionsMenu(Menu menu) {
1251 super.onPrepareOptionsMenu(menu);
1252
Winson Chung785d2eb2011-04-14 16:08:02 -07001253 // TODO-APPS_CUSTOMIZE: Remove this for the phone UI at some point, along with all the menu
1254 // related code?
1255 if (mAppsCustomizeContent != null && mAppsCustomizeContent.isAnimating()) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256
1257 return true;
1258 }
1259
1260 @Override
1261 public boolean onOptionsItemSelected(MenuItem item) {
1262 switch (item.getItemId()) {
1263 case MENU_ADD:
1264 addItems();
1265 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001266 case MENU_MANAGE_APPS:
1267 manageApps();
1268 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001269 case MENU_WALLPAPER_SETTINGS:
1270 startWallpaper();
1271 return true;
1272 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001273 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001274 return true;
1275 case MENU_NOTIFICATIONS:
1276 showNotifications();
1277 return true;
1278 }
1279
1280 return super.onOptionsItemSelected(item);
1281 }
Romain Guycbb89e42009-06-08 15:52:54 -07001282
Karl Rosaen138a0412009-04-23 19:00:21 -07001283 /**
1284 * Indicates that we want global search for this activity by setting the globalSearch
1285 * argument for {@link #startSearch} to true.
1286 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001287
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001288 @Override
1289 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001290 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001291 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001292 }
1293
Joe Onorato9c1289c2009-08-17 11:03:03 -04001294 public boolean isWorkspaceLocked() {
1295 return mWorkspaceLoading || mWaitingForResult;
1296 }
1297
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001298 private void addItems() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001299 showWorkspace(true);
Adam Cohenfbba09b2011-07-18 21:43:05 -07001300 showAddDialog();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301 }
1302
Michael Jurka0280c3b2010-09-17 15:00:07 -07001303 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001304 mPendingAddInfo.container = ItemInfo.NO_ID;
1305 mPendingAddInfo.screen = -1;
1306 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1307 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1308 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001309 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001310
Winson Chung7ad01412010-09-27 11:33:03 -07001311 private void manageApps() {
1312 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1313 }
1314
Michael Jurkaaf442092010-06-10 17:01:57 -07001315 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001316 // TODO: catch bad widget exception when sent
1317 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001318 // TODO: Is this log message meaningful?
1319 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001320 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001321 }
1322
Winson Chung55cef262010-10-28 14:14:18 -07001323 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001324 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325
Bjorn Bringert7984c942009-12-09 15:38:25 +00001326 if (appWidget.configure != null) {
1327 // Launch over to configure widget, if needed
1328 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1329 intent.setComponent(appWidget.configure);
1330 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001331 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001332 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1333 intent.putExtra(
1334 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1335 info.mimeType);
1336
1337 final String mimeType = info.mimeType;
1338 final ClipData clipData = (ClipData) info.configurationData;
1339 final ClipDescription clipDesc = clipData.getDescription();
1340 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1341 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001342 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001343 final CharSequence stringData = item.getText();
1344 final Uri uriData = item.getUri();
1345 final Intent intentData = item.getIntent();
1346 final String key =
1347 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1348 if (uriData != null) {
1349 intent.putExtra(key, uriData);
1350 } else if (intentData != null) {
1351 intent.putExtra(key, intentData);
1352 } else if (stringData != null) {
1353 intent.putExtra(key, stringData);
1354 }
1355 break;
1356 }
1357 }
1358 }
Winson Chung55cef262010-10-28 14:14:18 -07001359 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001360
Romain Guy8e633c52010-03-04 12:51:36 -08001361 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001362 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001363 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001364 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001365
1366 // Exit spring loaded mode if necessary after adding the widget
1367 exitSpringLoadedDragModeDelayed(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001368 }
1369 }
Romain Guycbb89e42009-06-08 15:52:54 -07001370
Adam Cohenfbba09b2011-07-18 21:43:05 -07001371 /**
1372 * Process a shortcut drop.
1373 *
1374 * @param componentName The name of the component
1375 * @param screen The screen where it should be added
1376 * @param cell The cell it should be added to, optional
1377 * @param position The location on the screen where it was dropped, optional
1378 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001379 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1380 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001381 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001382 mPendingAddInfo.container = container;
1383 mPendingAddInfo.screen = screen;
1384 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001385
1386 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001387 mPendingAddInfo.cellX = cell[0];
1388 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001389 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001390
1391 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1392 createShortcutIntent.setComponent(componentName);
1393 processShortcut(createShortcutIntent);
1394 }
1395
Adam Cohenfbba09b2011-07-18 21:43:05 -07001396 /**
1397 * Process a widget drop.
1398 *
1399 * @param info The PendingAppWidgetInfo of the widget being added.
1400 * @param screen The screen where it should be added
1401 * @param cell The cell it should be added to, optional
1402 * @param position The location on the screen where it was dropped, optional
1403 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001404 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1405 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001406 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001407 mPendingAddInfo.container = info.container = container;
1408 mPendingAddInfo.screen = info.screen = screen;
1409 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001410 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001411 mPendingAddInfo.cellX = cell[0];
1412 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001413 }
1414
1415 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1416 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1417 addAppWidgetImpl(appWidgetId, info);
1418 }
1419
Joe Onoratodeb98af2010-02-19 14:59:39 -08001420 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001421 // Handle case where user selected "Applications"
1422 String applicationName = getResources().getString(R.string.group_applications);
1423 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001424
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001425 if (applicationName != null && applicationName.equals(shortcutName)) {
1426 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1427 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001428
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001429 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1430 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001431 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001432 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001433 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001434 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001435 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 }
1437
Winson Chung24ab2f12010-09-16 14:10:47 -07001438 void processWallpaper(Intent intent) {
1439 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1440 }
1441
Winson Chung3d503fb2011-07-13 17:25:49 -07001442 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1443 int cellY) {
Adam Cohend0445262011-07-04 23:53:22 -07001444 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001445 folderInfo.title = getText(R.string.folder_name);
1446
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001448 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1449 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001450 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451
1452 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001453 FolderIcon newFolder =
1454 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1455 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1456 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001457 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458 }
Romain Guycbb89e42009-06-08 15:52:54 -07001459
Joe Onorato9c1289c2009-08-17 11:03:03 -04001460 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001461 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001462 }
1463
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001464 private void showNotifications() {
1465 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1466 if (statusBar != null) {
1467 statusBar.expand();
1468 }
1469 }
1470
1471 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001472 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001474 Intent chooser = Intent.createChooser(pickWallpaper,
1475 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001476 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1477 // Removed in Eclair MR1
1478// WallpaperManager wm = (WallpaperManager)
1479// getSystemService(Context.WALLPAPER_SERVICE);
1480// WallpaperInfo wi = wm.getWallpaperInfo();
1481// if (wi != null && wi.getSettingsActivity() != null) {
1482// LabeledIntent li = new LabeledIntent(getPackageName(),
1483// R.string.configure_wallpaper, 0);
1484// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1485// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1486// }
Mike Clerona0618e42009-10-22 13:55:21 -07001487 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001488 }
1489
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001490 /**
1491 * Registers various content observers. The current implementation registers
1492 * only a favorites observer to keep track of the favorites applications.
1493 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001494 private void registerContentObservers() {
1495 ContentResolver resolver = getContentResolver();
1496 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1497 true, mWidgetObserver);
1498 }
1499
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001500 @Override
1501 public boolean dispatchKeyEvent(KeyEvent event) {
1502 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1503 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001505 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001506 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001507 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001508 dumpState();
1509 return true;
1510 }
1511 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001512 }
1513 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1514 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001515 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516 return true;
1517 }
1518 }
1519
1520 return super.dispatchKeyEvent(event);
1521 }
1522
Joe Onorato88ec0992009-11-19 13:16:06 -08001523 @Override
1524 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001525 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001526 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001527 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001528 Folder openFolder = mWorkspace.getOpenFolder();
1529 if (openFolder.isEditingName()) {
1530 openFolder.dismissEditingName();
1531 } else {
1532 closeFolder();
1533 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001534 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001535 mWorkspace.exitWidgetResizeMode();
1536
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001537 // Back button is a no-op here, but give at least some feedback for the button press
1538 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001539 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001540 }
1541
Adam Cohen2801caf2011-05-13 20:57:39 -07001542 public void closeFolder() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543 Folder folder = mWorkspace.getOpenFolder();
1544 if (folder != null) {
1545 closeFolder(folder);
1546 }
1547 }
1548
1549 void closeFolder(Folder folder) {
1550 folder.getInfo().opened = false;
Adam Cohen7f4eabe2011-04-21 16:19:16 -07001551
Michael Jurka8c920dd2011-01-20 14:16:56 -08001552 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 if (parent != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001554 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Adam Cohen2801caf2011-05-13 20:57:39 -07001555 shrinkAndFadeInFolderIcon(fi);
Adam Cohendf2cc412011-04-27 16:56:57 -07001556 mDragController.removeDropTarget((DropTarget)folder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557 }
Adam Cohendf2cc412011-04-27 16:56:57 -07001558 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559 }
1560
1561 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001562 * Re-listen when widgets are reset.
1563 */
1564 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001565 if (mAppWidgetHost != null) {
1566 mAppWidgetHost.startListening();
1567 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001568 }
1569
1570 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001571 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1572 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001573 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001574 private void unbindWorkspaceAndHotseatItems() {
Adam Cohen4eac29a2011-07-11 17:53:37 -07001575 LauncherModel.unbindWorkspaceItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001577
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001578 /**
1579 * Launches the intent referred by the clicked shortcut.
1580 *
1581 * @param v The view representing the clicked shortcut.
1582 */
1583 public void onClick(View v) {
Adam Cohen2f84ef22011-07-26 17:16:44 -07001584 // Make sure that rogue clicks don't get through while allapps is launching
1585 if (mWorkspace.isSwitchingState()) return;
1586
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001588 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001589 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001590 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001591 int[] pos = new int[2];
1592 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001593 intent.setSourceBounds(new Rect(pos[0], pos[1],
1594 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001595 boolean success = startActivitySafely(intent, tag);
1596
1597 if (success && v instanceof BubbleTextView) {
1598 mWaitingForResume = (BubbleTextView) v;
1599 mWaitingForResume.setStayPressed(true);
1600 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001602 if (v instanceof FolderIcon) {
1603 FolderIcon fi = (FolderIcon) v;
1604 handleFolderClick(fi);
1605 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001606 } else if (v == mAllAppsButton) {
1607 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001608 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001609 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001610 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001611 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 }
1613 }
1614
Michael Jurka0e260592010-06-30 17:07:39 -07001615 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001616 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001617 // clicking anywhere on the workspace causes the customization drawer to slide down
1618 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001619 return false;
1620 }
1621
Michael Jurkaaf442092010-06-10 17:01:57 -07001622 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001623 * Event handler for the search button
1624 *
1625 * @param v The view that was clicked.
1626 */
1627 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001628 startSearch(null, false, null, true);
Amith Yamasani1f878a12010-11-22 14:58:22 -08001629 // Use a custom animation for launching search
1630 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001631 }
1632
1633 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001634 * Event handler for the voice button
1635 *
1636 * @param v The view that was clicked.
1637 */
1638 public void onClickVoiceButton(View v) {
1639 startVoiceSearch();
1640 }
1641
1642 private void startVoiceSearch() {
1643 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1644 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1645 startActivity(intent);
1646 }
1647
1648 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001649 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001650 * enters home screen customization mode.
1651 *
1652 * @param v The view that was clicked.
1653 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001654 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001655 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001656 }
1657
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001658 /**
1659 * Event handler for the "grid" button that appears on the home screen, which
1660 * enters all apps mode.
1661 *
1662 * @param v The view that was clicked.
1663 */
1664 public void onClickAllAppsButton(View v) {
1665 showAllApps(true);
1666 }
1667
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001668 public void onClickAppMarketButton(View v) {
1669 if (mAppMarketIntent != null) {
1670 startActivitySafely(mAppMarketIntent, "app market");
1671 }
1672 }
1673
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001674 void startApplicationDetailsActivity(ComponentName componentName) {
1675 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001676 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1677 Uri.fromParts("package", packageName, null));
1678 startActivity(intent);
1679 }
1680
Patrick Dubroy5539af72010-09-07 15:22:01 -07001681 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1682 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1683 // System applications cannot be installed. For now, show a toast explaining that.
1684 // We may give them the option of disabling apps this way.
1685 int messageId = R.string.uninstall_system_app_text;
1686 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1687 } else {
1688 String packageName = appInfo.componentName.getPackageName();
1689 String className = appInfo.componentName.getClassName();
1690 Intent intent = new Intent(
1691 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1692 startActivity(intent);
1693 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001694 }
1695
Michael Jurkaddd62e92011-02-16 17:49:14 -08001696 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001697 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1698 try {
1699 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001700 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001701 } catch (ActivityNotFoundException e) {
1702 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001703 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704 } catch (SecurityException e) {
1705 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001706 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001708 "or use the exported attribute for this activity. "
1709 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001711 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001713
Romain Guy8e633c52010-03-04 12:51:36 -08001714 void startActivityForResultSafely(Intent intent, int requestCode) {
1715 try {
1716 startActivityForResult(intent, requestCode);
1717 } catch (ActivityNotFoundException e) {
1718 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1719 } catch (SecurityException e) {
1720 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1721 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1722 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1723 "or use the exported attribute for this activity.", e);
1724 }
1725 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726
Adam Cohena9cf38f2011-05-02 15:36:58 -07001727 private void handleFolderClick(FolderIcon folderIcon) {
1728 final FolderInfo info = folderIcon.mInfo;
1729 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001730 // Close any open folder
1731 closeFolder();
1732 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001733 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001734 } else {
1735 // Find the open folder...
Adam Cohena9cf38f2011-05-02 15:36:58 -07001736 Folder openFolder = mWorkspace.getFolderForTag(info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737 int folderScreen;
1738 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001739 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001740 // .. and close it
1741 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001742 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001743 // Close any folder open on the current screen
1744 closeFolder();
1745 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001746 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747 }
1748 }
1749 }
1750 }
1751
Adam Cohen2801caf2011-05-13 20:57:39 -07001752 private void growAndFadeOutFolderIcon(FolderIcon fi) {
1753 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1754 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1755 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1756
1757 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1758 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1759 oa.start();
1760 }
1761
1762 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
1763 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1764 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1765 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1766
1767 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1768 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1769 oa.start();
1770 }
1771
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001773 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 * is animated relative to the specified View. If the View is null, no animation
1775 * is played.
1776 *
1777 * @param folderInfo The FolderInfo describing the folder to open.
1778 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001779 public void openFolder(FolderIcon folderIcon) {
1780 Folder folder = folderIcon.mFolder;
1781 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001782
Adam Cohen2801caf2011-05-13 20:57:39 -07001783 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001784 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001785
Adam Cohen8e776a62011-06-28 18:10:06 -07001786 mDragLayer.addView(folder);
1787 mDragController.addDropTarget((DropTarget) folder);
1788
Adam Cohena9cf38f2011-05-02 15:36:58 -07001789 folder.animateOpen();
1790 folder.onOpen();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001791 }
1792
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001794 if (mState != State.WORKSPACE) {
1795 return false;
1796 }
1797
Joe Onorato9c1289c2009-08-17 11:03:03 -04001798 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001799 return false;
1800 }
1801
1802 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001803 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001804 }
1805
Michael Jurka0280c3b2010-09-17 15:00:07 -07001806 resetAddInfo();
1807 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001808 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001809 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001810 return true;
1811 }
1812
Winson Chung3d503fb2011-07-13 17:25:49 -07001813 // The hotseat touch handling does not go through Workspace, and we always allow long press
1814 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001815 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001816 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1817 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001818 if (itemUnderLongClick == null) {
1819 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001820 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1821 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung55b65502011-05-26 12:03:43 -07001822 addItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001823 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001824 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001826 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1827 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001828 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001829 }
1830 }
1831 }
1832 return true;
1833 }
1834
Winson Chung3d503fb2011-07-13 17:25:49 -07001835 boolean isHotseatLayout(View layout) {
1836 return mHotseat != null && layout != null &&
1837 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1838 }
1839 Hotseat getHotseat() {
1840 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001841 }
1842
Winson Chung3d503fb2011-07-13 17:25:49 -07001843 /**
1844 * Returns the CellLayout of the specified container at the specified screen.
1845 */
1846 CellLayout getCellLayout(long container, int screen) {
1847 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1848 if (mHotseat != null) {
1849 return mHotseat.getLayout();
1850 } else {
1851 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001852 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001853 } else {
1854 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001855 }
1856 }
1857
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001858 Workspace getWorkspace() {
1859 return mWorkspace;
1860 }
1861
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001862 @Override
1863 protected Dialog onCreateDialog(int id) {
1864 switch (id) {
1865 case DIALOG_CREATE_SHORTCUT:
1866 return new CreateShortcut().createDialog();
1867 case DIALOG_RENAME_FOLDER:
1868 return new RenameFolder().createDialog();
1869 }
1870
1871 return super.onCreateDialog(id);
1872 }
1873
1874 @Override
1875 protected void onPrepareDialog(int id, Dialog dialog) {
1876 switch (id) {
1877 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001878 break;
1879 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001880 if (mFolderInfo != null) {
1881 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1882 final CharSequence text = mFolderInfo.title;
1883 input.setText(text);
1884 input.setSelection(0, text.length());
1885 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 break;
1887 }
1888 }
1889
1890 void showRenameDialog(FolderInfo info) {
1891 mFolderInfo = info;
1892 mWaitingForResult = true;
1893 showDialog(DIALOG_RENAME_FOLDER);
1894 }
1895
Adam Cohenfbba09b2011-07-18 21:43:05 -07001896 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001897 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001898 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
1899 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001900 mWaitingForResult = true;
1901 showDialog(DIALOG_CREATE_SHORTCUT);
1902 }
1903
Joe Onoratodeb98af2010-02-19 14:59:39 -08001904 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07001905 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07001906 Bundle bundle = new Bundle();
1907
1908 ArrayList<String> shortcutNames = new ArrayList<String>();
1909 shortcutNames.add(getString(R.string.group_applications));
1910 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
1911
1912 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
1913 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1914 R.drawable.ic_launcher_application));
1915 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1916
1917 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1918 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08001919 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07001920 pickIntent.putExtras(bundle);
1921
Joe Onoratodeb98af2010-02-19 14:59:39 -08001922 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07001923 }
1924
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925 private class RenameFolder {
1926 private EditText mInput;
1927
1928 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001929 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1930 mInput = (EditText) layout.findViewById(R.id.folder_name);
1931
1932 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1933 builder.setIcon(0);
1934 builder.setTitle(getString(R.string.rename_folder_title));
1935 builder.setCancelable(true);
1936 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1937 public void onCancel(DialogInterface dialog) {
1938 cleanup();
1939 }
1940 });
1941 builder.setNegativeButton(getString(R.string.cancel_action),
1942 new Dialog.OnClickListener() {
1943 public void onClick(DialogInterface dialog, int which) {
1944 cleanup();
1945 }
1946 }
1947 );
1948 builder.setPositiveButton(getString(R.string.rename_action),
1949 new Dialog.OnClickListener() {
1950 public void onClick(DialogInterface dialog, int which) {
1951 changeFolderName();
1952 }
1953 }
1954 );
1955 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001956
1957 final AlertDialog dialog = builder.create();
1958 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1959 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07001960 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05001961 mInput.requestFocus();
1962 InputMethodManager inputManager = (InputMethodManager)
1963 getSystemService(Context.INPUT_METHOD_SERVICE);
1964 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001965 }
1966 });
1967
1968 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 }
1970
1971 private void changeFolderName() {
1972 final String name = mInput.getText().toString();
1973 if (!TextUtils.isEmpty(name)) {
1974 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001975 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 mFolderInfo.title = name;
1977 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1978
Joe Onorato9c1289c2009-08-17 11:03:03 -04001979 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001980 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001981 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001982 } else {
1983 final FolderIcon folderIcon = (FolderIcon)
1984 mWorkspace.getViewForTag(mFolderInfo);
1985 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001986 // TODO: At some point we'll probably want some version of setting
1987 // the text for a folder icon.
1988 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 getWorkspace().requestLayout();
1990 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001991 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001992 mWorkspaceLoading = true;
1993 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 }
1995 }
1996 }
1997 cleanup();
1998 }
1999
2000 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 dismissDialog(DIALOG_RENAME_FOLDER);
2002 mWaitingForResult = false;
2003 mFolderInfo = null;
2004 }
2005 }
2006
Daniel Sandler843e8602010-06-07 14:59:01 -04002007 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2008 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002009 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002010 }
2011
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002012 // AllAppsView.Watcher
2013 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002014 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002015 mWorkspace.setVisibility(View.GONE);
2016 }
2017 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002018
2019 /**
2020 * Helper method for the cameraZoomIn/cameraZoomOut animations
2021 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002022 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002023 * @param scaleFactor The scale factor used for the zoom
2024 */
2025 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2026 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002027
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002028 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002029 // Set pivotY so that at the starting zoom factor, the view is partially
2030 // visible. Modifying initialHeightFactor changes how much of the view is
2031 // initially showing, and hence the perceived angle from which the view enters.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002032 if (state == State.APPS_CUSTOMIZE) {
Michael Jurkaea573482011-02-03 19:48:18 -08002033 final float initialHeightFactor = 0.175f;
Adam Cohenf16e5712011-01-13 13:31:45 -08002034 view.setPivotY((1 - initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002035 } else {
Adam Cohenf16e5712011-01-13 13:31:45 -08002036 final float initialHeightFactor = 0.2f;
Adam Cohen61033d32010-11-15 18:29:44 -08002037 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002038 }
2039 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002040
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002041 /**
2042 * Zoom the camera out from the workspace to reveal 'toView'.
2043 * Assumes that the view to show is anchored at either the very top or very bottom
2044 * of the screen.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002045 * @param toState The state to zoom out to. Must be APPS_CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002046 */
Winson Chungc07918d2011-07-01 15:35:26 -07002047 private void cameraZoomOut(State toState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002048 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002049
Winson Chungf0ea4d32011-06-06 14:27:16 -07002050 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2051 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2052 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2053 final View toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002054
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002055 setPivotsForZoom(toView, toState, scale);
2056
Michael Jurkad74c9842011-07-10 12:44:21 -07002057 // Shrink workspaces away if going to AppsCustomize from workspace
2058 mWorkspace.shrink(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002059
2060 if (animated) {
Michael Jurkaabded662011-03-04 12:06:57 -08002061 final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
Michael Jurka742574b2011-02-02 23:51:01 -08002062 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002063 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2064 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002065 ((View) toView.getParent()).fastInvalidate();
Michael Jurka11148e52011-02-03 18:20:25 -08002066 toView.setFastScaleX(a * scale + b * 1f);
2067 toView.setFastScaleY(a * scale + b * 1f);
Michael Jurka742574b2011-02-02 23:51:01 -08002068 }
2069 });
Adam Cohen61033d32010-11-15 18:29:44 -08002070
Winson Chungf0ea4d32011-06-06 14:27:16 -07002071 toView.setVisibility(View.VISIBLE);
2072 toView.setFastAlpha(0f);
2073 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2074 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2075 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2076 public void onAnimationUpdate(float a, float b) {
2077 // don't need to invalidate because we do so above
2078 toView.setFastAlpha(a * 0f + b * 1f);
2079 }
2080 });
2081 alphaAnim.start();
Adam Cohenf16e5712011-01-13 13:31:45 -08002082
Michael Jurkaabded662011-03-04 12:06:57 -08002083 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002084 ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim, false);
Michael Jurkabfadaad2011-01-31 21:35:39 -08002085 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002086 scaleAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002087 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002088 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002089 // Prepare the position
2090 toView.setTranslationX(0.0f);
2091 toView.setTranslationY(0.0f);
2092 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002093 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002094 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002095 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002096 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002097 // If we don't set the final scale values here, if this animation is cancelled
2098 // it will have the wrong scale value and subsequent cameraPan animations will
2099 // not fix that
2100 toView.setScaleX(1.0f);
2101 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002102 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002103 ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002104 }
Winson Chung32174c82011-07-19 15:47:55 -07002105
2106 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2107 // Hide the workspace scrollbar
2108 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002109 mWorkspace.hideDockDivider(true);
Winson Chung32174c82011-07-19 15:47:55 -07002110 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002111 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002112 });
2113
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002114 // toView should appear right at the end of the workspace shrink animation
Adam Cohenf16e5712011-01-13 13:31:45 -08002115 final int startDelay = 0;
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002116
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002117 if (mStateAnimation != null) mStateAnimation.cancel();
2118 mStateAnimation = new AnimatorSet();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002119 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002120 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002121 } else {
2122 toView.setTranslationX(0.0f);
2123 toView.setTranslationY(0.0f);
2124 toView.setScaleX(1.0f);
2125 toView.setScaleY(1.0f);
2126 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002127 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002128 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002129 ((LauncherTransitionable) toView).onLauncherTransitionStart(null, false);
2130 ((LauncherTransitionable) toView).onLauncherTransitionEnd(null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002131
Winson Chungc07918d2011-07-01 15:35:26 -07002132 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2133 // Hide the workspace scrollbar
2134 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002135 mWorkspace.hideDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002136 }
Michael Jurkaabded662011-03-04 12:06:57 -08002137 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002138 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002139 }
2140
2141 /**
2142 * Zoom the camera back into the workspace, hiding 'fromView'.
2143 * This is the opposite of cameraZoomOut.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002144 * @param fromState The current state (must be APPS_CUSTOMIZE).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002145 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002146 */
Winson Chungc07918d2011-07-01 15:35:26 -07002147 private void cameraZoomIn(State fromState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002148 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002149
Winson Chungf0ea4d32011-06-06 14:27:16 -07002150 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2151 final float scaleFactor = (float)
2152 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2153 final View fromView = mAppsCustomizeTabHost;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002154
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002155 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002156
Michael Jurkad3ef3062010-11-23 16:23:58 -08002157 if (!springLoaded) {
2158 mWorkspace.unshrink(animated);
2159 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002160 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002161 if (mStateAnimation != null) mStateAnimation.cancel();
2162 mStateAnimation = new AnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08002163
Michael Jurka742574b2011-02-02 23:51:01 -08002164 final float oldScaleX = fromView.getScaleX();
2165 final float oldScaleY = fromView.getScaleY();
2166
2167 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2168 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002169 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2170 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002171 ((View)fromView.getParent()).fastInvalidate();
2172 fromView.setFastScaleX(a * oldScaleX + b * scaleFactor);
2173 fromView.setFastScaleY(a * oldScaleY + b * scaleFactor);
2174 }
2175 });
Michael Jurkaabded662011-03-04 12:06:57 -08002176 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002177 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Michael Jurkaea573482011-02-03 19:48:18 -08002178 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Michael Jurkac2e26a02011-03-24 15:20:26 -07002179 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2180 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002181 // don't need to invalidate because we do so above
2182 fromView.setFastAlpha(a * 1f + b * 0f);
2183 }
2184 });
Michael Jurkaabded662011-03-04 12:06:57 -08002185 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002186 ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002187 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002188 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002189 @Override
Winson Chungbb6f6a52011-07-25 17:55:44 -07002190 public void onAnimationStart(android.animation.Animator animation) {
2191 if (!springLoaded) {
2192 mWorkspace.showDockDivider(false);
2193 }
2194 }
2195 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002196 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002197 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002198 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002199 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim,true);
Michael Jurka2763be32011-02-24 11:19:57 -08002200 }
Winson Chung5a808352011-06-27 19:08:49 -07002201 mWorkspace.flashScrollingIndicator();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002202 }
2203 });
2204
Winson Chungf0ea4d32011-06-06 14:27:16 -07002205 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002206 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002207 } else {
2208 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002209 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002210 ((LauncherTransitionable) fromView).onLauncherTransitionStart(null, true);
2211 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null, true);
Winson Chung3ac74c52011-06-30 17:39:37 -07002212
Winson Chungc07918d2011-07-01 15:35:26 -07002213 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chungf5f8cef2011-07-22 11:16:13 -07002214 // Flash the workspace scrollbar
Winson Chungbb6f6a52011-07-25 17:55:44 -07002215 mWorkspace.showDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002216 mWorkspace.flashScrollingIndicator();
2217 }
Michael Jurkaabded662011-03-04 12:06:57 -08002218 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002219 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002220 }
2221
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002222 void showWorkspace(boolean animated) {
2223 showWorkspace(animated, null);
2224 }
2225
2226 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002227 if (layout != null) {
2228 // always animated, but that's ok since we never specify a layout and
2229 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002230 mWorkspace.unshrink(layout);
2231 } else {
2232 mWorkspace.unshrink(animated);
2233 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002234 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002235 closeAllApps(animated);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002236 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002237
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002238 // Change the state *after* we've called all the transition code
2239 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002240
Winson Chung5fb63472011-02-02 17:03:37 -08002241 // Resume the auto-advance of widgets
2242 mUserPresent = true;
2243 updateRunning();
2244
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002245 // send an accessibility event to announce the context change
2246 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002247 }
2248
Michael Jurkad3ef3062010-11-23 16:23:58 -08002249 void enterSpringLoadedDragMode(CellLayout layout) {
Winson Chungb26f3d62011-06-02 10:49:29 -07002250 if (mState == State.APPS_CUSTOMIZE) {
Winson Chungc07918d2011-07-01 15:35:26 -07002251 mWorkspace.enterSpringLoadedDragMode(layout);
Winson Chungb26f3d62011-06-02 10:49:29 -07002252 cameraZoomIn(State.APPS_CUSTOMIZE, true, true);
Winson Chungc07918d2011-07-01 15:35:26 -07002253 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002254 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002255 // Otherwise, we are not in spring loaded mode, so don't do anything.
Michael Jurkad3ef3062010-11-23 16:23:58 -08002256 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002257 void exitSpringLoadedDragModeDelayed(boolean extendedDelay) {
2258 mWorkspace.postDelayed(new Runnable() {
2259 @Override
2260 public void run() {
2261 exitSpringLoadedDragMode();
2262 }
2263 }, (extendedDelay ?
2264 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2265 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2266 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002267 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002268 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkad74c9842011-07-10 12:44:21 -07002269 mWorkspace.exitSpringLoadedDragMode(Workspace.State.SMALL);
Winson Chungb26f3d62011-06-02 10:49:29 -07002270 cameraZoomOut(State.APPS_CUSTOMIZE, true, true);
2271 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002272 }
2273 // Otherwise, we are not in spring loaded mode, so don't do anything.
2274 }
2275
Adam Cohenfc53cd22011-07-20 15:45:11 -07002276 public boolean isAllAppsCustomizeOpen() {
2277 return mState == State.APPS_CUSTOMIZE;
2278 }
2279
Winson Chungf0ea4d32011-06-06 14:27:16 -07002280 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002281 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002282 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002283 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002284 if (!LauncherApplication.isScreenLarge()) {
2285 if (animated) {
2286 int duration = mSearchDeleteBar.getTransitionInDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002287 mHotseat.animate().alpha(1f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002288 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002289 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002290 }
2291 }
2292 }
2293
2294 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002295 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002296 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002297 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002298 if (!LauncherApplication.isScreenLarge()) {
2299 if (animated) {
2300 int duration = mSearchDeleteBar.getTransitionOutDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002301 mHotseat.animate().alpha(0f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002302 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002303 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002304 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002305 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002306 }
2307
Winson Chung785d2eb2011-04-14 16:08:02 -07002308 void showAllApps(boolean animated) {
2309 if (mState != State.WORKSPACE) return;
Winson Chung785d2eb2011-04-14 16:08:02 -07002310
Winson Chungf0ea4d32011-06-06 14:27:16 -07002311 cameraZoomOut(State.APPS_CUSTOMIZE, animated, false);
2312 mAppsCustomizeTabHost.requestFocus();
Winson Chung785d2eb2011-04-14 16:08:02 -07002313
Winson Chung3d503fb2011-07-13 17:25:49 -07002314 // Hide the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002315 mSearchDeleteBar.hideSearchBar(animated);
Winson Chung3d503fb2011-07-13 17:25:49 -07002316 hideHotseat(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002317
Winson Chungf0ea4d32011-06-06 14:27:16 -07002318 // Change the state *after* we've called all the transition code
2319 mState = State.APPS_CUSTOMIZE;
Winson Chung785d2eb2011-04-14 16:08:02 -07002320
2321 // Pause the auto-advance of widgets until we are out of AllApps
2322 mUserPresent = false;
2323 updateRunning();
Adam Cohen2f84ef22011-07-26 17:16:44 -07002324 closeFolder();
Winson Chung785d2eb2011-04-14 16:08:02 -07002325
2326 // Send an accessibility event to announce the context change
2327 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2328 }
2329
Joe Onoratob2061212009-11-24 16:13:54 -05002330 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002331 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002332 * - Home from workspace
2333 * - from center screen
2334 * - from other screens
2335 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002336 * - from center screen
2337 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002338 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002339 * - from center screen
2340 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002341 * - Launch app from workspace and quit
2342 * - with back
2343 * - with home
2344 * - Launch app from all apps and quit
2345 * - with back
2346 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002347 * - Go to a screen that's not the default, then all
2348 * apps, and launch and app, and go back
2349 * - with back
2350 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002351 * - On workspace, long press power and go back
2352 * - with back
2353 * - with home
2354 * - On all apps, long press power and go back
2355 * - with back
2356 * - with home
2357 * - On workspace, power off
2358 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002359 * - Launch an app and turn off the screen while in that app
2360 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002361 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002362 * - From all apps
2363 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002364 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2365 * - From all apps
2366 * - From the center workspace
2367 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002368 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002369 void closeAllApps(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002370 if (mState == State.APPS_CUSTOMIZE || mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2371 mWorkspace.setVisibility(View.VISIBLE);
2372 cameraZoomIn(State.APPS_CUSTOMIZE, animated, false);
Winson Chung785d2eb2011-04-14 16:08:02 -07002373
Winson Chung3d503fb2011-07-13 17:25:49 -07002374 // Show the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002375 mSearchDeleteBar.showSearchBar(animated);
Winson Chung3d503fb2011-07-13 17:25:49 -07002376 showHotseat(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002377
Winson Chungf0ea4d32011-06-06 14:27:16 -07002378 // Set focus to the AppsCustomize button
Winson Chung3d503fb2011-07-13 17:25:49 -07002379 if (mAllAppsButton != null) {
2380 mAllAppsButton.requestFocus();
2381 }
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002382 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002383 }
2384
Joe Onorato7c312c12009-08-13 21:36:53 -07002385 void lockAllApps() {
2386 // TODO
2387 }
2388
2389 void unlockAllApps() {
2390 // TODO
2391 }
2392
Patrick Dubroy5f445422011-02-18 14:35:21 -08002393 /**
2394 * Add an item from all apps or customize onto the given workspace screen.
2395 * If layout is null, add to the current screen.
2396 */
2397 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002398 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2399 showOutOfSpaceMessage();
Patrick Dubroy5f445422011-02-18 14:35:21 -08002400 } else {
2401 layout.animateDrop();
Michael Jurka213d9632010-07-28 11:29:25 -07002402 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002403 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002404
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002405 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002406 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002407 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002408 // Look for the toolbar icon specified in the activity meta-data
2409 Bundle metaData = packageManager.getActivityInfo(
2410 activityName, PackageManager.GET_META_DATA).metaData;
2411 if (metaData != null) {
2412 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2413 if (iconResId != 0) {
2414 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002415 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002416 }
2417 }
2418 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002419 // This can happen if the activity defines an invalid drawable
2420 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2421 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002422 } catch (Resources.NotFoundException nfe) {
2423 // This can happen if the activity defines an invalid drawable
2424 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2425 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002426 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002427 return null;
2428 }
2429
2430 // if successful in getting icon, return it; otherwise, set button to use default drawable
2431 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2432 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2433 TextView button = (TextView) findViewById(buttonId);
2434 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2435
2436 // If we were unable to find the icon via the meta-data, use a generic one
2437 if (toolbarIcon == null) {
2438 button.setCompoundDrawablesWithIntrinsicBounds(fallbackDrawableId, 0, 0, 0);
2439 return null;
2440 } else {
2441 button.setCompoundDrawablesWithIntrinsicBounds(toolbarIcon, null, null, null);
2442 return toolbarIcon.getConstantState();
2443 }
2444 }
2445
2446 // if successful in getting icon, return it; otherwise, set button to use default drawable
2447 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2448 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2449 ImageView button = (ImageView) findViewById(buttonId);
2450 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2451
Michael Jurka19e0fc52011-07-22 18:00:21 -07002452 if (button != null) {
2453 // If we were unable to find the icon via the meta-data, use a
2454 // generic one
2455 if (toolbarIcon == null) {
2456 button.setImageResource(fallbackDrawableId);
2457 } else {
2458 button.setImageDrawable(toolbarIcon);
2459 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002460 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002461
2462 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2463
Michael Jurka0423dcf2010-10-05 14:56:18 -07002464 }
2465
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002466 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2467 TextView button = (TextView) findViewById(buttonId);
2468 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2469 }
2470
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002471 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002472 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002473 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002474 }
2475
Michael Jurka0423dcf2010-10-05 14:56:18 -07002476 private void updateGlobalSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002477 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2478 final View searchDivider = findViewById(R.id.search_divider);
Winson Chung97d85d22011-04-13 11:27:36 -07002479
Winson Chung1cad91e2011-05-25 17:41:01 -07002480 final SearchManager searchManager =
2481 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2482 ComponentName activityName = searchManager.getGlobalSearchActivity();
2483 if (activityName != null) {
Mathew Inwood68524cd2011-07-01 13:59:38 +01002484 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002485 R.id.search_button, activityName, R.drawable.ic_search_normal_holo);
Winson Chung1cad91e2011-05-25 17:41:01 -07002486 searchButton.setVisibility(View.VISIBLE);
Winson Chung649723c2011-07-06 20:41:23 -07002487 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002488 } else {
2489 searchButton.setVisibility(View.GONE);
Winson Chung649723c2011-07-06 20:41:23 -07002490 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002491 }
2492 }
2493
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002494 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002495 updateButtonWithDrawable(R.id.search_button, d);
2496 }
2497
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002498 private void updateVoiceSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002499 final View searchDivider = findViewById(R.id.search_divider);
2500 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002501
Winson Chung1cad91e2011-05-25 17:41:01 -07002502 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2503 ComponentName activityName = intent.resolveActivity(getPackageManager());
2504 if (activityName != null) {
2505 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002506 R.id.voice_button, activityName, R.drawable.ic_voice_search_holo);
2507 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002508 voiceButton.setVisibility(View.VISIBLE);
2509 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002510 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002511 voiceButton.setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002512 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002513 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002514
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002515 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002516 updateButtonWithDrawable(R.id.voice_button, d);
2517 }
2518
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002519 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002520 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002521 */
2522 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002523 final View marketButton = findViewById(R.id.market_button);
2524 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2525 // Find the app market activity by resolving an intent.
2526 // (If multiple app markets are installed, it will return the ResolverActivity.)
2527 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002528 if (activityName != null) {
Winson Chung785d2eb2011-04-14 16:08:02 -07002529 mAppMarketIntent = intent;
2530 sAppMarketIcon = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002531 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002532 marketButton.setVisibility(View.VISIBLE);
Winson Chungeb66b142011-06-16 13:14:22 -07002533
2534 // Remove the shop icon text in the Phone UI
2535 if (!LauncherApplication.isScreenLarge()) {
2536 ((TextView) marketButton).setText("");
2537 }
Winson Chung785d2eb2011-04-14 16:08:02 -07002538 } else {
2539 // We should hide and disable the view so that we don't try and restore the visibility
2540 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2541 marketButton.setVisibility(View.GONE);
2542 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002543 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002544 }
2545
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002546 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002547 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002548 }
2549
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002550 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002551 * Displays the shortcut creation dialog and launches, if necessary, the
2552 * appropriate activity.
2553 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002554 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002555 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2556 DialogInterface.OnShowListener {
2557
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002558 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002559
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002560 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002561 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002562
Winson Chung55b65502011-05-26 12:03:43 -07002563 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2564 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002565 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002566
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002567 AlertDialog dialog = builder.create();
2568 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002569 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002570 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002571
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002572 return dialog;
2573 }
2574
2575 public void onCancel(DialogInterface dialog) {
2576 mWaitingForResult = false;
2577 cleanup();
2578 }
2579
Romain Guycbb89e42009-06-08 15:52:54 -07002580 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002581 mWaitingForResult = false;
2582 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002583 }
2584
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002585 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002586 try {
2587 dismissDialog(DIALOG_CREATE_SHORTCUT);
2588 } catch (Exception e) {
2589 // An exception is thrown if the dialog is not visible, which is fine
2590 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002591 }
2592
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002593 /**
2594 * Handle the action clicked in the "Add to home" dialog.
2595 */
2596 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002597 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002598
Winson Chung55b65502011-05-26 12:03:43 -07002599 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2600 switch (item.actionTag) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002601 case AddAdapter.ITEM_SHORTCUT: {
Winson Chungd2945262011-06-24 15:22:14 -07002602 if (mAppsCustomizeTabHost != null) {
Winson Chung5a808352011-06-27 19:08:49 -07002603 mAppsCustomizeTabHost.selectShortcutsTab();
Winson Chungd2945262011-06-24 15:22:14 -07002604 }
2605 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002606 break;
2607 }
Winson Chung55b65502011-05-26 12:03:43 -07002608 case AddAdapter.ITEM_APPLICATION: {
2609 if (mAppsCustomizeTabHost != null) {
2610 mAppsCustomizeTabHost.selectAppsTab();
2611 }
2612 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002613 break;
2614 }
Winson Chung55b65502011-05-26 12:03:43 -07002615 case AddAdapter.ITEM_APPWIDGET: {
2616 if (mAppsCustomizeTabHost != null) {
2617 mAppsCustomizeTabHost.selectWidgetsTab();
2618 }
2619 showAllApps(true);
2620 break;
2621 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002622 case AddAdapter.ITEM_WALLPAPER: {
2623 startWallpaper();
2624 break;
2625 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002626 }
2627 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002628
2629 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002630 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002631 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002632 }
2633
2634 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002635 * Receives notifications when applications are added/removed.
2636 */
2637 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2638 @Override
2639 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002640 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002641 String reason = intent.getStringExtra("reason");
2642 if (!"homekey".equals(reason)) {
2643 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002644 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002645 animate = false;
2646 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002647 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002648 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002649 }
2650 }
2651
2652 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002653 * Receives notifications whenever the appwidgets are reset.
2654 */
2655 private class AppWidgetResetObserver extends ContentObserver {
2656 public AppWidgetResetObserver() {
2657 super(new Handler());
2658 }
2659
2660 @Override
2661 public void onChange(boolean selfChange) {
2662 onAppWidgetReset();
2663 }
2664 }
2665
2666 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002667 * If the activity is currently paused, signal that we need to re-run the loader
2668 * in onResume.
2669 *
2670 * This needs to be called from incoming places where resources might have been loaded
2671 * while we are paused. That is becaues the Configuration might be wrong
2672 * when we're not running, and if it comes back to what it was when we
2673 * were paused, we are not restarted.
2674 *
2675 * Implementation of the method from LauncherModel.Callbacks.
2676 *
2677 * @return true if we are currently paused. The caller might be able to
2678 * skip some work in that case since we will come back again.
2679 */
2680 public boolean setLoadOnResume() {
2681 if (mPaused) {
2682 Log.i(TAG, "setLoadOnResume");
2683 mOnResumeNeedsLoad = true;
2684 return true;
2685 } else {
2686 return false;
2687 }
2688 }
2689
2690 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002691 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002692 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002693 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002694 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002695 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002696 } else {
2697 return SCREEN_COUNT / 2;
2698 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002699 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002700
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002701
Joe Onorato9c1289c2009-08-17 11:03:03 -04002702 /**
2703 * Refreshes the shortcuts shown on the workspace.
2704 *
2705 * Implementation of the method from LauncherModel.Callbacks.
2706 */
2707 public void startBinding() {
2708 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002709
2710 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002711 int count = workspace.getChildCount();
2712 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002713 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002714 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2715 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002716 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002717 if (mHotseat != null) {
2718 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002719 }
Adam Cohenf5d77c92011-02-03 12:55:38 -08002720
Adam Cohen4eac29a2011-07-11 17:53:37 -07002721 // This wasn't being called before which resulted in a leak of AppWidgetHostViews
Winson Chung3d503fb2011-07-13 17:25:49 -07002722 unbindWorkspaceAndHotseatItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002723 }
2724
2725 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002726 * Bind the items start-end from the list.
2727 *
2728 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002729 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002730 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002731 setLoadOnResume();
2732
Joe Onorato9c1289c2009-08-17 11:03:03 -04002733 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002734 for (int i=start; i<end; i++) {
2735 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002736
2737 // Short circuit if we are loading dock items for a configuration which has no dock
2738 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2739 mHotseat == null) {
2740 continue;
2741 }
2742
Joe Onorato9c1289c2009-08-17 11:03:03 -04002743 switch (item.itemType) {
2744 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2745 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002746 View shortcut = createShortcut((ShortcutInfo)item);
2747 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
2748 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002749 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07002750 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07002751 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002752 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07002753 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07002754 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
2755 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002756 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002757 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002758 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002759 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002760 }
2761
Joe Onorato9c1289c2009-08-17 11:03:03 -04002762 /**
2763 * Implementation of the method from LauncherModel.Callbacks.
2764 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002765 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002766 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002767 sFolders.clear();
2768 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002769 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002770
2771 /**
2772 * Add the views for a widget to the workspace.
2773 *
2774 * Implementation of the method from LauncherModel.Callbacks.
2775 */
2776 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002777 setLoadOnResume();
2778
Daniel Sandler843e8602010-06-07 14:59:01 -04002779 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2780 if (DEBUG_WIDGETS) {
2781 Log.d(TAG, "bindAppWidget: " + item);
2782 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002783 final Workspace workspace = mWorkspace;
2784
2785 final int appWidgetId = item.appWidgetId;
2786 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002787 if (DEBUG_WIDGETS) {
2788 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2789 }
2790
Joe Onorato9c1289c2009-08-17 11:03:03 -04002791 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2792
Joe Onorato9c1289c2009-08-17 11:03:03 -04002793 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2794 item.hostView.setTag(item);
2795
Winson Chung3d503fb2011-07-13 17:25:49 -07002796 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04002797 item.cellY, item.spanX, item.spanY, false);
2798
Adam Cohended9f8d2010-11-03 13:25:16 -07002799 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
2800
Joe Onorato9c1289c2009-08-17 11:03:03 -04002801 workspace.requestLayout();
2802
Daniel Sandler843e8602010-06-07 14:59:01 -04002803 if (DEBUG_WIDGETS) {
2804 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2805 + (SystemClock.uptimeMillis()-start) + "ms");
2806 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002807 }
2808
2809 /**
2810 * Callback saying that there aren't any more items to bind.
2811 *
2812 * Implementation of the method from LauncherModel.Callbacks.
2813 */
2814 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002815 setLoadOnResume();
2816
Joe Onorato9c1289c2009-08-17 11:03:03 -04002817 if (mSavedState != null) {
2818 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002819 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002820 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002821 mSavedState = null;
2822 }
2823
2824 if (mSavedInstanceState != null) {
2825 super.onRestoreInstanceState(mSavedInstanceState);
2826 mSavedInstanceState = null;
2827 }
2828
Joe Onorato9c1289c2009-08-17 11:03:03 -04002829 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08002830
2831 // If we received the result of any pending adds while the loader was running (e.g. the
2832 // widget configuration forced an orientation change), process them now.
2833 for (int i = 0; i < sPendingAddList.size(); i++) {
2834 completeAdd(sPendingAddList.get(i));
2835 }
2836 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002837 }
2838
2839 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002840 * Updates the icons on the launcher that are affected by changes to the package list
2841 * on the device.
2842 */
2843 private void updateIconsAffectedByPackageManagerChanges() {
2844 updateAppMarketIcon();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002845 updateVoiceSearchIcon();
2846 }
2847
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002848 @Override
2849 public void bindSearchablesChanged() {
2850 updateGlobalSearchIcon();
2851 }
2852
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002853 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002854 * Add the icons for all apps.
2855 *
2856 * Implementation of the method from LauncherModel.Callbacks.
2857 */
2858 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Winson Chung785d2eb2011-04-14 16:08:02 -07002859 if (mAppsCustomizeContent != null) {
2860 mAppsCustomizeContent.setApps(apps);
2861 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002862 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002863 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002864 }
2865
2866 /**
2867 * A package was installed.
2868 *
2869 * Implementation of the method from LauncherModel.Callbacks.
2870 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002871 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002872 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002873 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002874
Winson Chung785d2eb2011-04-14 16:08:02 -07002875 if (mAppsCustomizeContent != null) {
2876 mAppsCustomizeContent.addApps(apps);
2877 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002878 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002879 }
2880
2881 /**
2882 * A package was updated.
2883 *
2884 * Implementation of the method from LauncherModel.Callbacks.
2885 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002886 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002887 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002888 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08002889 if (mWorkspace != null) {
2890 mWorkspace.updateShortcuts(apps);
2891 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002892
Winson Chung785d2eb2011-04-14 16:08:02 -07002893 if (mAppsCustomizeContent != null) {
2894 mAppsCustomizeContent.updateApps(apps);
2895 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002896 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002897 }
2898
2899 /**
2900 * A package was uninstalled.
2901 *
2902 * Implementation of the method from LauncherModel.Callbacks.
2903 */
Joe Onorato36115782010-06-17 13:28:48 -04002904 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002905 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04002906 if (permanent) {
2907 mWorkspace.removeItems(apps);
2908 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002909
Winson Chung785d2eb2011-04-14 16:08:02 -07002910 if (mAppsCustomizeContent != null) {
2911 mAppsCustomizeContent.removeApps(apps);
2912 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002913 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002914 }
Joe Onoratobe386092009-11-17 17:32:16 -08002915
2916 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07002917 * A number of packages were updated.
2918 */
2919 public void bindPackagesUpdated() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002920
Winson Chung785d2eb2011-04-14 16:08:02 -07002921 if (mAppsCustomizeContent != null) {
2922 mAppsCustomizeContent.onPackagesUpdated();
2923 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002924 }
2925
Winson Chung400438b2011-01-16 17:53:48 -08002926 private int mapConfigurationOriActivityInfoOri(int configOri) {
2927 final Display d = getWindowManager().getDefaultDisplay();
2928 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
2929 switch (d.getRotation()) {
2930 case Surface.ROTATION_0:
2931 case Surface.ROTATION_180:
2932 // We are currently in the same basic orientation as the natural orientation
2933 naturalOri = configOri;
2934 break;
2935 case Surface.ROTATION_90:
2936 case Surface.ROTATION_270:
2937 // We are currently in the other basic orientation to the natural orientation
2938 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
2939 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
2940 break;
2941 }
2942
2943 int[] oriMap = {
2944 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
2945 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
2946 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
2947 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
2948 };
2949 // Since the map starts at portrait, we need to offset if this device's natural orientation
2950 // is landscape.
2951 int indexOffset = 0;
2952 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
2953 indexOffset = 1;
2954 }
2955 return oriMap[(d.getRotation() + indexOffset) % 4];
2956 }
2957 public void lockScreenOrientation() {
2958 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
2959 .getConfiguration().orientation));
2960 }
2961 public void unlockScreenOrientation() {
2962 mHandler.postDelayed(new Runnable() {
2963 public void run() {
2964 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2965 }
2966 }, mRestoreScreenOrientationDelay);
2967 }
2968
Winson Chung80baf5a2010-08-09 16:03:15 -07002969 /**
Joe Onoratobe386092009-11-17 17:32:16 -08002970 * Prints out out state for debugging.
2971 */
2972 public void dumpState() {
2973 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08002974 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08002975 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
2976 Log.d(TAG, "mRestoring=" + mRestoring);
2977 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
2978 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002979 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08002980 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07002981
Winson Chung785d2eb2011-04-14 16:08:02 -07002982 if (mAppsCustomizeContent != null) {
2983 mAppsCustomizeContent.dumpState();
2984 }
Joe Onoratobe386092009-11-17 17:32:16 -08002985 Log.d(TAG, "END launcher2 dump state");
2986 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002987}
Michael Jurka2763be32011-02-24 11:19:57 -08002988
Michael Jurkaabded662011-03-04 12:06:57 -08002989interface LauncherTransitionable {
Winson Chung5a808352011-06-27 19:08:49 -07002990 void onLauncherTransitionStart(Animator animation, boolean toWorkspace);
2991 void onLauncherTransitionEnd(Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08002992}