blob: 0f302a012706e5be209876f0bf512115477197c5 [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
Adam Cohenc51934b2011-07-26 21:07:43 -07001757 FolderInfo info = (FolderInfo) fi.getTag();
1758 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1759 CellLayout cl = (CellLayout) fi.getParent().getParent();
1760 cl.setFolderLeaveBehindCell(info.cellX, info.cellY);
1761 }
1762
Adam Cohen2801caf2011-05-13 20:57:39 -07001763 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1764 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1765 oa.start();
1766 }
1767
1768 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
1769 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1770 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1771 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1772
Adam Cohenc51934b2011-07-26 21:07:43 -07001773 FolderInfo info = (FolderInfo) fi.getTag();
1774 CellLayout cl = null;
1775 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1776 cl = (CellLayout) fi.getParent().getParent();
1777 }
1778
1779 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001780 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1781 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001782 oa.addListener(new AnimatorListenerAdapter() {
1783 @Override
1784 public void onAnimationEnd(Animator animation) {
1785 if (layout != null) {
1786 layout.clearFolderLeaveBehind();
1787 }
1788 }
1789 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001790 oa.start();
1791 }
1792
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001794 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795 * is animated relative to the specified View. If the View is null, no animation
1796 * is played.
1797 *
1798 * @param folderInfo The FolderInfo describing the folder to open.
1799 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001800 public void openFolder(FolderIcon folderIcon) {
1801 Folder folder = folderIcon.mFolder;
1802 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001803
Adam Cohen2801caf2011-05-13 20:57:39 -07001804 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001805 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001806
Adam Cohen8e776a62011-06-28 18:10:06 -07001807 mDragLayer.addView(folder);
1808 mDragController.addDropTarget((DropTarget) folder);
1809
Adam Cohena9cf38f2011-05-02 15:36:58 -07001810 folder.animateOpen();
1811 folder.onOpen();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 }
1813
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001815 if (mState != State.WORKSPACE) {
1816 return false;
1817 }
1818
Joe Onorato9c1289c2009-08-17 11:03:03 -04001819 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 return false;
1821 }
1822
1823 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001824 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 }
1826
Michael Jurka0280c3b2010-09-17 15:00:07 -07001827 resetAddInfo();
1828 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001829 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001830 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001831 return true;
1832 }
1833
Winson Chung3d503fb2011-07-13 17:25:49 -07001834 // The hotseat touch handling does not go through Workspace, and we always allow long press
1835 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001836 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001837 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1838 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001839 if (itemUnderLongClick == null) {
1840 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001841 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1842 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung55b65502011-05-26 12:03:43 -07001843 addItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001845 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001846 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001847 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1848 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001849 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001850 }
1851 }
1852 }
1853 return true;
1854 }
1855
Winson Chung3d503fb2011-07-13 17:25:49 -07001856 boolean isHotseatLayout(View layout) {
1857 return mHotseat != null && layout != null &&
1858 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1859 }
1860 Hotseat getHotseat() {
1861 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001862 }
1863
Winson Chung3d503fb2011-07-13 17:25:49 -07001864 /**
1865 * Returns the CellLayout of the specified container at the specified screen.
1866 */
1867 CellLayout getCellLayout(long container, int screen) {
1868 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1869 if (mHotseat != null) {
1870 return mHotseat.getLayout();
1871 } else {
1872 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001873 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001874 } else {
1875 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001876 }
1877 }
1878
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001879 Workspace getWorkspace() {
1880 return mWorkspace;
1881 }
1882
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 @Override
1884 protected Dialog onCreateDialog(int id) {
1885 switch (id) {
1886 case DIALOG_CREATE_SHORTCUT:
1887 return new CreateShortcut().createDialog();
1888 case DIALOG_RENAME_FOLDER:
1889 return new RenameFolder().createDialog();
1890 }
1891
1892 return super.onCreateDialog(id);
1893 }
1894
1895 @Override
1896 protected void onPrepareDialog(int id, Dialog dialog) {
1897 switch (id) {
1898 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899 break;
1900 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001901 if (mFolderInfo != null) {
1902 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1903 final CharSequence text = mFolderInfo.title;
1904 input.setText(text);
1905 input.setSelection(0, text.length());
1906 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001907 break;
1908 }
1909 }
1910
1911 void showRenameDialog(FolderInfo info) {
1912 mFolderInfo = info;
1913 mWaitingForResult = true;
1914 showDialog(DIALOG_RENAME_FOLDER);
1915 }
1916
Adam Cohenfbba09b2011-07-18 21:43:05 -07001917 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001918 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001919 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
1920 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001921 mWaitingForResult = true;
1922 showDialog(DIALOG_CREATE_SHORTCUT);
1923 }
1924
Joe Onoratodeb98af2010-02-19 14:59:39 -08001925 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07001926 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07001927 Bundle bundle = new Bundle();
1928
1929 ArrayList<String> shortcutNames = new ArrayList<String>();
1930 shortcutNames.add(getString(R.string.group_applications));
1931 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
1932
1933 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
1934 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
1935 R.drawable.ic_launcher_application));
1936 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
1937
1938 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1939 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08001940 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07001941 pickIntent.putExtras(bundle);
1942
Joe Onoratodeb98af2010-02-19 14:59:39 -08001943 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07001944 }
1945
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001946 private class RenameFolder {
1947 private EditText mInput;
1948
1949 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1951 mInput = (EditText) layout.findViewById(R.id.folder_name);
1952
1953 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1954 builder.setIcon(0);
1955 builder.setTitle(getString(R.string.rename_folder_title));
1956 builder.setCancelable(true);
1957 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1958 public void onCancel(DialogInterface dialog) {
1959 cleanup();
1960 }
1961 });
1962 builder.setNegativeButton(getString(R.string.cancel_action),
1963 new Dialog.OnClickListener() {
1964 public void onClick(DialogInterface dialog, int which) {
1965 cleanup();
1966 }
1967 }
1968 );
1969 builder.setPositiveButton(getString(R.string.rename_action),
1970 new Dialog.OnClickListener() {
1971 public void onClick(DialogInterface dialog, int which) {
1972 changeFolderName();
1973 }
1974 }
1975 );
1976 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001977
1978 final AlertDialog dialog = builder.create();
1979 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1980 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07001981 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05001982 mInput.requestFocus();
1983 InputMethodManager inputManager = (InputMethodManager)
1984 getSystemService(Context.INPUT_METHOD_SERVICE);
1985 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001986 }
1987 });
1988
1989 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001990 }
1991
1992 private void changeFolderName() {
1993 final String name = mInput.getText().toString();
1994 if (!TextUtils.isEmpty(name)) {
1995 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001996 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 mFolderInfo.title = name;
1998 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1999
Joe Onorato9c1289c2009-08-17 11:03:03 -04002000 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002001 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002002 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 } else {
2004 final FolderIcon folderIcon = (FolderIcon)
2005 mWorkspace.getViewForTag(mFolderInfo);
2006 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002007 // TODO: At some point we'll probably want some version of setting
2008 // the text for a folder icon.
2009 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 getWorkspace().requestLayout();
2011 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002012 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002013 mWorkspaceLoading = true;
2014 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002015 }
2016 }
2017 }
2018 cleanup();
2019 }
2020
2021 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 dismissDialog(DIALOG_RENAME_FOLDER);
2023 mWaitingForResult = false;
2024 mFolderInfo = null;
2025 }
2026 }
2027
Daniel Sandler843e8602010-06-07 14:59:01 -04002028 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2029 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002030 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002031 }
2032
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002033 // AllAppsView.Watcher
2034 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002035 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002036 mWorkspace.setVisibility(View.GONE);
2037 }
2038 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002039
2040 /**
2041 * Helper method for the cameraZoomIn/cameraZoomOut animations
2042 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002043 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002044 * @param scaleFactor The scale factor used for the zoom
2045 */
2046 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2047 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002048
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002049 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002050 // Set pivotY so that at the starting zoom factor, the view is partially
2051 // visible. Modifying initialHeightFactor changes how much of the view is
2052 // initially showing, and hence the perceived angle from which the view enters.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002053 if (state == State.APPS_CUSTOMIZE) {
Michael Jurkaea573482011-02-03 19:48:18 -08002054 final float initialHeightFactor = 0.175f;
Adam Cohenf16e5712011-01-13 13:31:45 -08002055 view.setPivotY((1 - initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002056 } else {
Adam Cohenf16e5712011-01-13 13:31:45 -08002057 final float initialHeightFactor = 0.2f;
Adam Cohen61033d32010-11-15 18:29:44 -08002058 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002059 }
2060 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002061
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002062 /**
2063 * Zoom the camera out from the workspace to reveal 'toView'.
2064 * Assumes that the view to show is anchored at either the very top or very bottom
2065 * of the screen.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002066 * @param toState The state to zoom out to. Must be APPS_CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002067 */
Winson Chungc07918d2011-07-01 15:35:26 -07002068 private void cameraZoomOut(State toState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002069 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002070
Winson Chungf0ea4d32011-06-06 14:27:16 -07002071 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2072 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2073 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2074 final View toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002075
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002076 setPivotsForZoom(toView, toState, scale);
2077
Michael Jurkad74c9842011-07-10 12:44:21 -07002078 // Shrink workspaces away if going to AppsCustomize from workspace
2079 mWorkspace.shrink(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002080
2081 if (animated) {
Michael Jurkaabded662011-03-04 12:06:57 -08002082 final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
Michael Jurka742574b2011-02-02 23:51:01 -08002083 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002084 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2085 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002086 ((View) toView.getParent()).fastInvalidate();
Michael Jurka11148e52011-02-03 18:20:25 -08002087 toView.setFastScaleX(a * scale + b * 1f);
2088 toView.setFastScaleY(a * scale + b * 1f);
Michael Jurka742574b2011-02-02 23:51:01 -08002089 }
2090 });
Adam Cohen61033d32010-11-15 18:29:44 -08002091
Winson Chungf0ea4d32011-06-06 14:27:16 -07002092 toView.setVisibility(View.VISIBLE);
2093 toView.setFastAlpha(0f);
2094 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2095 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2096 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2097 public void onAnimationUpdate(float a, float b) {
2098 // don't need to invalidate because we do so above
2099 toView.setFastAlpha(a * 0f + b * 1f);
2100 }
2101 });
2102 alphaAnim.start();
Adam Cohenf16e5712011-01-13 13:31:45 -08002103
Michael Jurkaabded662011-03-04 12:06:57 -08002104 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002105 ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim, false);
Michael Jurkabfadaad2011-01-31 21:35:39 -08002106 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002107 scaleAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002108 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002109 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002110 // Prepare the position
2111 toView.setTranslationX(0.0f);
2112 toView.setTranslationY(0.0f);
2113 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002114 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002115 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002116 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002117 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002118 // If we don't set the final scale values here, if this animation is cancelled
2119 // it will have the wrong scale value and subsequent cameraPan animations will
2120 // not fix that
2121 toView.setScaleX(1.0f);
2122 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002123 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002124 ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002125 }
Winson Chung32174c82011-07-19 15:47:55 -07002126
2127 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2128 // Hide the workspace scrollbar
2129 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002130 mWorkspace.hideDockDivider(true);
Winson Chung32174c82011-07-19 15:47:55 -07002131 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002132 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002133 });
2134
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002135 // toView should appear right at the end of the workspace shrink animation
Adam Cohenf16e5712011-01-13 13:31:45 -08002136 final int startDelay = 0;
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002137
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002138 if (mStateAnimation != null) mStateAnimation.cancel();
2139 mStateAnimation = new AnimatorSet();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002140 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002141 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002142 } else {
2143 toView.setTranslationX(0.0f);
2144 toView.setTranslationY(0.0f);
2145 toView.setScaleX(1.0f);
2146 toView.setScaleY(1.0f);
2147 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002148 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002149 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002150 ((LauncherTransitionable) toView).onLauncherTransitionStart(null, false);
2151 ((LauncherTransitionable) toView).onLauncherTransitionEnd(null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002152
Winson Chungc07918d2011-07-01 15:35:26 -07002153 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2154 // Hide the workspace scrollbar
2155 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002156 mWorkspace.hideDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002157 }
Michael Jurkaabded662011-03-04 12:06:57 -08002158 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002159 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002160 }
2161
2162 /**
2163 * Zoom the camera back into the workspace, hiding 'fromView'.
2164 * This is the opposite of cameraZoomOut.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002165 * @param fromState The current state (must be APPS_CUSTOMIZE).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002166 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002167 */
Winson Chungc07918d2011-07-01 15:35:26 -07002168 private void cameraZoomIn(State fromState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002169 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002170
Winson Chungf0ea4d32011-06-06 14:27:16 -07002171 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2172 final float scaleFactor = (float)
2173 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2174 final View fromView = mAppsCustomizeTabHost;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002175
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002176 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002177
Michael Jurkad3ef3062010-11-23 16:23:58 -08002178 if (!springLoaded) {
2179 mWorkspace.unshrink(animated);
2180 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002181 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002182 if (mStateAnimation != null) mStateAnimation.cancel();
2183 mStateAnimation = new AnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08002184
Michael Jurka742574b2011-02-02 23:51:01 -08002185 final float oldScaleX = fromView.getScaleX();
2186 final float oldScaleY = fromView.getScaleY();
2187
2188 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2189 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002190 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2191 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002192 ((View)fromView.getParent()).fastInvalidate();
2193 fromView.setFastScaleX(a * oldScaleX + b * scaleFactor);
2194 fromView.setFastScaleY(a * oldScaleY + b * scaleFactor);
2195 }
2196 });
Michael Jurkaabded662011-03-04 12:06:57 -08002197 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002198 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Michael Jurkaea573482011-02-03 19:48:18 -08002199 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Michael Jurkac2e26a02011-03-24 15:20:26 -07002200 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2201 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002202 // don't need to invalidate because we do so above
2203 fromView.setFastAlpha(a * 1f + b * 0f);
2204 }
2205 });
Michael Jurkaabded662011-03-04 12:06:57 -08002206 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002207 ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002208 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002209 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002210 @Override
Winson Chungbb6f6a52011-07-25 17:55:44 -07002211 public void onAnimationStart(android.animation.Animator animation) {
2212 if (!springLoaded) {
2213 mWorkspace.showDockDivider(false);
2214 }
2215 }
2216 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002217 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002218 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002219 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002220 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim,true);
Michael Jurka2763be32011-02-24 11:19:57 -08002221 }
Winson Chung5a808352011-06-27 19:08:49 -07002222 mWorkspace.flashScrollingIndicator();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002223 }
2224 });
2225
Winson Chungf0ea4d32011-06-06 14:27:16 -07002226 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002227 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002228 } else {
2229 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002230 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002231 ((LauncherTransitionable) fromView).onLauncherTransitionStart(null, true);
2232 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null, true);
Winson Chung3ac74c52011-06-30 17:39:37 -07002233
Winson Chungc07918d2011-07-01 15:35:26 -07002234 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chungf5f8cef2011-07-22 11:16:13 -07002235 // Flash the workspace scrollbar
Winson Chungbb6f6a52011-07-25 17:55:44 -07002236 mWorkspace.showDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002237 mWorkspace.flashScrollingIndicator();
2238 }
Michael Jurkaabded662011-03-04 12:06:57 -08002239 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002240 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002241 }
2242
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002243 void showWorkspace(boolean animated) {
2244 showWorkspace(animated, null);
2245 }
2246
2247 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002248 if (layout != null) {
2249 // always animated, but that's ok since we never specify a layout and
2250 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002251 mWorkspace.unshrink(layout);
2252 } else {
2253 mWorkspace.unshrink(animated);
2254 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002255 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002256 closeAllApps(animated);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002257 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002258
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002259 // Change the state *after* we've called all the transition code
2260 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002261
Winson Chung5fb63472011-02-02 17:03:37 -08002262 // Resume the auto-advance of widgets
2263 mUserPresent = true;
2264 updateRunning();
2265
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002266 // send an accessibility event to announce the context change
2267 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002268 }
2269
Michael Jurkad3ef3062010-11-23 16:23:58 -08002270 void enterSpringLoadedDragMode(CellLayout layout) {
Winson Chungb26f3d62011-06-02 10:49:29 -07002271 if (mState == State.APPS_CUSTOMIZE) {
Winson Chungc07918d2011-07-01 15:35:26 -07002272 mWorkspace.enterSpringLoadedDragMode(layout);
Winson Chungb26f3d62011-06-02 10:49:29 -07002273 cameraZoomIn(State.APPS_CUSTOMIZE, true, true);
Winson Chungc07918d2011-07-01 15:35:26 -07002274 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002275 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002276 // Otherwise, we are not in spring loaded mode, so don't do anything.
Michael Jurkad3ef3062010-11-23 16:23:58 -08002277 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002278 void exitSpringLoadedDragModeDelayed(boolean extendedDelay) {
2279 mWorkspace.postDelayed(new Runnable() {
2280 @Override
2281 public void run() {
2282 exitSpringLoadedDragMode();
2283 }
2284 }, (extendedDelay ?
2285 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2286 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2287 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002288 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002289 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkad74c9842011-07-10 12:44:21 -07002290 mWorkspace.exitSpringLoadedDragMode(Workspace.State.SMALL);
Winson Chungb26f3d62011-06-02 10:49:29 -07002291 cameraZoomOut(State.APPS_CUSTOMIZE, true, true);
2292 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002293 }
2294 // Otherwise, we are not in spring loaded mode, so don't do anything.
2295 }
2296
Adam Cohenfc53cd22011-07-20 15:45:11 -07002297 public boolean isAllAppsCustomizeOpen() {
2298 return mState == State.APPS_CUSTOMIZE;
2299 }
2300
Winson Chungf0ea4d32011-06-06 14:27:16 -07002301 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002302 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002303 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002304 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002305 if (!LauncherApplication.isScreenLarge()) {
2306 if (animated) {
2307 int duration = mSearchDeleteBar.getTransitionInDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002308 mHotseat.animate().alpha(1f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002309 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002310 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002311 }
2312 }
2313 }
2314
2315 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002316 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002317 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002318 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002319 if (!LauncherApplication.isScreenLarge()) {
2320 if (animated) {
2321 int duration = mSearchDeleteBar.getTransitionOutDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002322 mHotseat.animate().alpha(0f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002323 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002324 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002325 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002326 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002327 }
2328
Winson Chung785d2eb2011-04-14 16:08:02 -07002329 void showAllApps(boolean animated) {
2330 if (mState != State.WORKSPACE) return;
Winson Chung785d2eb2011-04-14 16:08:02 -07002331
Winson Chungf0ea4d32011-06-06 14:27:16 -07002332 cameraZoomOut(State.APPS_CUSTOMIZE, animated, false);
2333 mAppsCustomizeTabHost.requestFocus();
Winson Chung785d2eb2011-04-14 16:08:02 -07002334
Winson Chung3d503fb2011-07-13 17:25:49 -07002335 // Hide the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002336 mSearchDeleteBar.hideSearchBar(animated);
Winson Chung3d503fb2011-07-13 17:25:49 -07002337 hideHotseat(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002338
Winson Chungf0ea4d32011-06-06 14:27:16 -07002339 // Change the state *after* we've called all the transition code
2340 mState = State.APPS_CUSTOMIZE;
Winson Chung785d2eb2011-04-14 16:08:02 -07002341
2342 // Pause the auto-advance of widgets until we are out of AllApps
2343 mUserPresent = false;
2344 updateRunning();
Adam Cohen2f84ef22011-07-26 17:16:44 -07002345 closeFolder();
Winson Chung785d2eb2011-04-14 16:08:02 -07002346
2347 // Send an accessibility event to announce the context change
2348 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2349 }
2350
Joe Onoratob2061212009-11-24 16:13:54 -05002351 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002352 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002353 * - Home from workspace
2354 * - from center screen
2355 * - from other screens
2356 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002357 * - from center screen
2358 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002359 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002360 * - from center screen
2361 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002362 * - Launch app from workspace and quit
2363 * - with back
2364 * - with home
2365 * - Launch app from all apps and quit
2366 * - with back
2367 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002368 * - Go to a screen that's not the default, then all
2369 * apps, and launch and app, and go back
2370 * - with back
2371 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002372 * - On workspace, long press power and go back
2373 * - with back
2374 * - with home
2375 * - On all apps, long press power and go back
2376 * - with back
2377 * - with home
2378 * - On workspace, power off
2379 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002380 * - Launch an app and turn off the screen while in that app
2381 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002382 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002383 * - From all apps
2384 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002385 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2386 * - From all apps
2387 * - From the center workspace
2388 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002389 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002390 void closeAllApps(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002391 if (mState == State.APPS_CUSTOMIZE || mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2392 mWorkspace.setVisibility(View.VISIBLE);
2393 cameraZoomIn(State.APPS_CUSTOMIZE, animated, false);
Winson Chung785d2eb2011-04-14 16:08:02 -07002394
Winson Chung3d503fb2011-07-13 17:25:49 -07002395 // Show the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002396 mSearchDeleteBar.showSearchBar(animated);
Winson Chung3d503fb2011-07-13 17:25:49 -07002397 showHotseat(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002398
Winson Chungf0ea4d32011-06-06 14:27:16 -07002399 // Set focus to the AppsCustomize button
Winson Chung3d503fb2011-07-13 17:25:49 -07002400 if (mAllAppsButton != null) {
2401 mAllAppsButton.requestFocus();
2402 }
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002403 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002404 }
2405
Joe Onorato7c312c12009-08-13 21:36:53 -07002406 void lockAllApps() {
2407 // TODO
2408 }
2409
2410 void unlockAllApps() {
2411 // TODO
2412 }
2413
Patrick Dubroy5f445422011-02-18 14:35:21 -08002414 /**
2415 * Add an item from all apps or customize onto the given workspace screen.
2416 * If layout is null, add to the current screen.
2417 */
2418 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002419 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2420 showOutOfSpaceMessage();
Patrick Dubroy5f445422011-02-18 14:35:21 -08002421 } else {
2422 layout.animateDrop();
Michael Jurka213d9632010-07-28 11:29:25 -07002423 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002424 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002425
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002426 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002427 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002428 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002429 // Look for the toolbar icon specified in the activity meta-data
2430 Bundle metaData = packageManager.getActivityInfo(
2431 activityName, PackageManager.GET_META_DATA).metaData;
2432 if (metaData != null) {
2433 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2434 if (iconResId != 0) {
2435 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002436 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002437 }
2438 }
2439 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002440 // This can happen if the activity defines an invalid drawable
2441 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2442 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002443 } catch (Resources.NotFoundException nfe) {
2444 // This can happen if the activity defines an invalid drawable
2445 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2446 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002447 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002448 return null;
2449 }
2450
2451 // if successful in getting icon, return it; otherwise, set button to use default drawable
2452 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2453 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2454 TextView button = (TextView) findViewById(buttonId);
2455 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2456
2457 // If we were unable to find the icon via the meta-data, use a generic one
2458 if (toolbarIcon == null) {
2459 button.setCompoundDrawablesWithIntrinsicBounds(fallbackDrawableId, 0, 0, 0);
2460 return null;
2461 } else {
2462 button.setCompoundDrawablesWithIntrinsicBounds(toolbarIcon, null, null, null);
2463 return toolbarIcon.getConstantState();
2464 }
2465 }
2466
2467 // if successful in getting icon, return it; otherwise, set button to use default drawable
2468 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2469 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2470 ImageView button = (ImageView) findViewById(buttonId);
2471 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2472
Michael Jurka19e0fc52011-07-22 18:00:21 -07002473 if (button != null) {
2474 // If we were unable to find the icon via the meta-data, use a
2475 // generic one
2476 if (toolbarIcon == null) {
2477 button.setImageResource(fallbackDrawableId);
2478 } else {
2479 button.setImageDrawable(toolbarIcon);
2480 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002481 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002482
2483 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2484
Michael Jurka0423dcf2010-10-05 14:56:18 -07002485 }
2486
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002487 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2488 TextView button = (TextView) findViewById(buttonId);
2489 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2490 }
2491
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002492 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002493 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002494 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002495 }
2496
Michael Jurka0423dcf2010-10-05 14:56:18 -07002497 private void updateGlobalSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002498 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2499 final View searchDivider = findViewById(R.id.search_divider);
Winson Chung97d85d22011-04-13 11:27:36 -07002500
Winson Chung1cad91e2011-05-25 17:41:01 -07002501 final SearchManager searchManager =
2502 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2503 ComponentName activityName = searchManager.getGlobalSearchActivity();
2504 if (activityName != null) {
Mathew Inwood68524cd2011-07-01 13:59:38 +01002505 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002506 R.id.search_button, activityName, R.drawable.ic_search_normal_holo);
Winson Chung1cad91e2011-05-25 17:41:01 -07002507 searchButton.setVisibility(View.VISIBLE);
Winson Chung649723c2011-07-06 20:41:23 -07002508 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002509 } else {
2510 searchButton.setVisibility(View.GONE);
Winson Chung649723c2011-07-06 20:41:23 -07002511 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002512 }
2513 }
2514
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002515 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002516 updateButtonWithDrawable(R.id.search_button, d);
2517 }
2518
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002519 private void updateVoiceSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002520 final View searchDivider = findViewById(R.id.search_divider);
2521 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002522
Winson Chung1cad91e2011-05-25 17:41:01 -07002523 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2524 ComponentName activityName = intent.resolveActivity(getPackageManager());
2525 if (activityName != null) {
2526 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002527 R.id.voice_button, activityName, R.drawable.ic_voice_search_holo);
2528 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002529 voiceButton.setVisibility(View.VISIBLE);
2530 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002531 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002532 voiceButton.setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002533 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002534 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002535
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002536 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002537 updateButtonWithDrawable(R.id.voice_button, d);
2538 }
2539
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002540 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002541 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002542 */
2543 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002544 final View marketButton = findViewById(R.id.market_button);
2545 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2546 // Find the app market activity by resolving an intent.
2547 // (If multiple app markets are installed, it will return the ResolverActivity.)
2548 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002549 if (activityName != null) {
Winson Chung785d2eb2011-04-14 16:08:02 -07002550 mAppMarketIntent = intent;
2551 sAppMarketIcon = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002552 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002553 marketButton.setVisibility(View.VISIBLE);
Winson Chungeb66b142011-06-16 13:14:22 -07002554
2555 // Remove the shop icon text in the Phone UI
2556 if (!LauncherApplication.isScreenLarge()) {
2557 ((TextView) marketButton).setText("");
2558 }
Winson Chung785d2eb2011-04-14 16:08:02 -07002559 } else {
2560 // We should hide and disable the view so that we don't try and restore the visibility
2561 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2562 marketButton.setVisibility(View.GONE);
2563 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002564 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002565 }
2566
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002567 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002568 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002569 }
2570
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002571 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002572 * Displays the shortcut creation dialog and launches, if necessary, the
2573 * appropriate activity.
2574 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002575 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002576 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2577 DialogInterface.OnShowListener {
2578
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002579 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002580
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002581 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002582 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002583
Winson Chung55b65502011-05-26 12:03:43 -07002584 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2585 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002586 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002587
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002588 AlertDialog dialog = builder.create();
2589 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002590 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002591 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002592
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002593 return dialog;
2594 }
2595
2596 public void onCancel(DialogInterface dialog) {
2597 mWaitingForResult = false;
2598 cleanup();
2599 }
2600
Romain Guycbb89e42009-06-08 15:52:54 -07002601 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002602 mWaitingForResult = false;
2603 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002604 }
2605
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002606 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002607 try {
2608 dismissDialog(DIALOG_CREATE_SHORTCUT);
2609 } catch (Exception e) {
2610 // An exception is thrown if the dialog is not visible, which is fine
2611 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002612 }
2613
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002614 /**
2615 * Handle the action clicked in the "Add to home" dialog.
2616 */
2617 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002618 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002619
Winson Chung55b65502011-05-26 12:03:43 -07002620 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2621 switch (item.actionTag) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002622 case AddAdapter.ITEM_SHORTCUT: {
Winson Chungd2945262011-06-24 15:22:14 -07002623 if (mAppsCustomizeTabHost != null) {
Winson Chung5a808352011-06-27 19:08:49 -07002624 mAppsCustomizeTabHost.selectShortcutsTab();
Winson Chungd2945262011-06-24 15:22:14 -07002625 }
2626 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002627 break;
2628 }
Winson Chung55b65502011-05-26 12:03:43 -07002629 case AddAdapter.ITEM_APPLICATION: {
2630 if (mAppsCustomizeTabHost != null) {
2631 mAppsCustomizeTabHost.selectAppsTab();
2632 }
2633 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002634 break;
2635 }
Winson Chung55b65502011-05-26 12:03:43 -07002636 case AddAdapter.ITEM_APPWIDGET: {
2637 if (mAppsCustomizeTabHost != null) {
2638 mAppsCustomizeTabHost.selectWidgetsTab();
2639 }
2640 showAllApps(true);
2641 break;
2642 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002643 case AddAdapter.ITEM_WALLPAPER: {
2644 startWallpaper();
2645 break;
2646 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002647 }
2648 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002649
2650 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002651 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002652 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002653 }
2654
2655 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002656 * Receives notifications when applications are added/removed.
2657 */
2658 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2659 @Override
2660 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002661 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002662 String reason = intent.getStringExtra("reason");
2663 if (!"homekey".equals(reason)) {
2664 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002665 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002666 animate = false;
2667 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002668 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002669 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002670 }
2671 }
2672
2673 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002674 * Receives notifications whenever the appwidgets are reset.
2675 */
2676 private class AppWidgetResetObserver extends ContentObserver {
2677 public AppWidgetResetObserver() {
2678 super(new Handler());
2679 }
2680
2681 @Override
2682 public void onChange(boolean selfChange) {
2683 onAppWidgetReset();
2684 }
2685 }
2686
2687 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002688 * If the activity is currently paused, signal that we need to re-run the loader
2689 * in onResume.
2690 *
2691 * This needs to be called from incoming places where resources might have been loaded
2692 * while we are paused. That is becaues the Configuration might be wrong
2693 * when we're not running, and if it comes back to what it was when we
2694 * were paused, we are not restarted.
2695 *
2696 * Implementation of the method from LauncherModel.Callbacks.
2697 *
2698 * @return true if we are currently paused. The caller might be able to
2699 * skip some work in that case since we will come back again.
2700 */
2701 public boolean setLoadOnResume() {
2702 if (mPaused) {
2703 Log.i(TAG, "setLoadOnResume");
2704 mOnResumeNeedsLoad = true;
2705 return true;
2706 } else {
2707 return false;
2708 }
2709 }
2710
2711 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002712 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002713 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002714 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002715 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002716 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002717 } else {
2718 return SCREEN_COUNT / 2;
2719 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002720 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002721
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002722
Joe Onorato9c1289c2009-08-17 11:03:03 -04002723 /**
2724 * Refreshes the shortcuts shown on the workspace.
2725 *
2726 * Implementation of the method from LauncherModel.Callbacks.
2727 */
2728 public void startBinding() {
2729 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002730
2731 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002732 int count = workspace.getChildCount();
2733 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002734 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002735 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2736 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002737 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002738 if (mHotseat != null) {
2739 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002740 }
Adam Cohenf5d77c92011-02-03 12:55:38 -08002741
Adam Cohen4eac29a2011-07-11 17:53:37 -07002742 // This wasn't being called before which resulted in a leak of AppWidgetHostViews
Winson Chung3d503fb2011-07-13 17:25:49 -07002743 unbindWorkspaceAndHotseatItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002744 }
2745
2746 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002747 * Bind the items start-end from the list.
2748 *
2749 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002750 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002751 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002752 setLoadOnResume();
2753
Joe Onorato9c1289c2009-08-17 11:03:03 -04002754 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002755 for (int i=start; i<end; i++) {
2756 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002757
2758 // Short circuit if we are loading dock items for a configuration which has no dock
2759 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2760 mHotseat == null) {
2761 continue;
2762 }
2763
Joe Onorato9c1289c2009-08-17 11:03:03 -04002764 switch (item.itemType) {
2765 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2766 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002767 View shortcut = createShortcut((ShortcutInfo)item);
2768 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
2769 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002770 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07002771 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07002772 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002773 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07002774 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07002775 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
2776 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002777 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002778 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002779 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002780 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002781 }
2782
Joe Onorato9c1289c2009-08-17 11:03:03 -04002783 /**
2784 * Implementation of the method from LauncherModel.Callbacks.
2785 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002786 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002787 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002788 sFolders.clear();
2789 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002790 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002791
2792 /**
2793 * Add the views for a widget to the workspace.
2794 *
2795 * Implementation of the method from LauncherModel.Callbacks.
2796 */
2797 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002798 setLoadOnResume();
2799
Daniel Sandler843e8602010-06-07 14:59:01 -04002800 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2801 if (DEBUG_WIDGETS) {
2802 Log.d(TAG, "bindAppWidget: " + item);
2803 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002804 final Workspace workspace = mWorkspace;
2805
2806 final int appWidgetId = item.appWidgetId;
2807 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002808 if (DEBUG_WIDGETS) {
2809 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2810 }
2811
Joe Onorato9c1289c2009-08-17 11:03:03 -04002812 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2813
Joe Onorato9c1289c2009-08-17 11:03:03 -04002814 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2815 item.hostView.setTag(item);
2816
Winson Chung3d503fb2011-07-13 17:25:49 -07002817 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04002818 item.cellY, item.spanX, item.spanY, false);
2819
Adam Cohended9f8d2010-11-03 13:25:16 -07002820 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
2821
Joe Onorato9c1289c2009-08-17 11:03:03 -04002822 workspace.requestLayout();
2823
Daniel Sandler843e8602010-06-07 14:59:01 -04002824 if (DEBUG_WIDGETS) {
2825 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2826 + (SystemClock.uptimeMillis()-start) + "ms");
2827 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002828 }
2829
2830 /**
2831 * Callback saying that there aren't any more items to bind.
2832 *
2833 * Implementation of the method from LauncherModel.Callbacks.
2834 */
2835 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002836 setLoadOnResume();
2837
Joe Onorato9c1289c2009-08-17 11:03:03 -04002838 if (mSavedState != null) {
2839 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002840 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002841 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002842 mSavedState = null;
2843 }
2844
2845 if (mSavedInstanceState != null) {
2846 super.onRestoreInstanceState(mSavedInstanceState);
2847 mSavedInstanceState = null;
2848 }
2849
Joe Onorato9c1289c2009-08-17 11:03:03 -04002850 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08002851
2852 // If we received the result of any pending adds while the loader was running (e.g. the
2853 // widget configuration forced an orientation change), process them now.
2854 for (int i = 0; i < sPendingAddList.size(); i++) {
2855 completeAdd(sPendingAddList.get(i));
2856 }
2857 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002858 }
2859
2860 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002861 * Updates the icons on the launcher that are affected by changes to the package list
2862 * on the device.
2863 */
2864 private void updateIconsAffectedByPackageManagerChanges() {
2865 updateAppMarketIcon();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002866 updateVoiceSearchIcon();
2867 }
2868
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002869 @Override
2870 public void bindSearchablesChanged() {
2871 updateGlobalSearchIcon();
2872 }
2873
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002874 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002875 * Add the icons for all apps.
2876 *
2877 * Implementation of the method from LauncherModel.Callbacks.
2878 */
2879 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Winson Chung785d2eb2011-04-14 16:08:02 -07002880 if (mAppsCustomizeContent != null) {
2881 mAppsCustomizeContent.setApps(apps);
2882 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002883 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002884 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002885 }
2886
2887 /**
2888 * A package was installed.
2889 *
2890 * Implementation of the method from LauncherModel.Callbacks.
2891 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002892 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002893 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002894 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002895
Winson Chung785d2eb2011-04-14 16:08:02 -07002896 if (mAppsCustomizeContent != null) {
2897 mAppsCustomizeContent.addApps(apps);
2898 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002899 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002900 }
2901
2902 /**
2903 * A package was updated.
2904 *
2905 * Implementation of the method from LauncherModel.Callbacks.
2906 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002907 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002908 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002909 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08002910 if (mWorkspace != null) {
2911 mWorkspace.updateShortcuts(apps);
2912 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002913
Winson Chung785d2eb2011-04-14 16:08:02 -07002914 if (mAppsCustomizeContent != null) {
2915 mAppsCustomizeContent.updateApps(apps);
2916 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002917 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002918 }
2919
2920 /**
2921 * A package was uninstalled.
2922 *
2923 * Implementation of the method from LauncherModel.Callbacks.
2924 */
Joe Onorato36115782010-06-17 13:28:48 -04002925 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002926 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04002927 if (permanent) {
2928 mWorkspace.removeItems(apps);
2929 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002930
Winson Chung785d2eb2011-04-14 16:08:02 -07002931 if (mAppsCustomizeContent != null) {
2932 mAppsCustomizeContent.removeApps(apps);
2933 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002934 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002935 }
Joe Onoratobe386092009-11-17 17:32:16 -08002936
2937 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07002938 * A number of packages were updated.
2939 */
2940 public void bindPackagesUpdated() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002941
Winson Chung785d2eb2011-04-14 16:08:02 -07002942 if (mAppsCustomizeContent != null) {
2943 mAppsCustomizeContent.onPackagesUpdated();
2944 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002945 }
2946
Winson Chung400438b2011-01-16 17:53:48 -08002947 private int mapConfigurationOriActivityInfoOri(int configOri) {
2948 final Display d = getWindowManager().getDefaultDisplay();
2949 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
2950 switch (d.getRotation()) {
2951 case Surface.ROTATION_0:
2952 case Surface.ROTATION_180:
2953 // We are currently in the same basic orientation as the natural orientation
2954 naturalOri = configOri;
2955 break;
2956 case Surface.ROTATION_90:
2957 case Surface.ROTATION_270:
2958 // We are currently in the other basic orientation to the natural orientation
2959 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
2960 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
2961 break;
2962 }
2963
2964 int[] oriMap = {
2965 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
2966 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
2967 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
2968 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
2969 };
2970 // Since the map starts at portrait, we need to offset if this device's natural orientation
2971 // is landscape.
2972 int indexOffset = 0;
2973 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
2974 indexOffset = 1;
2975 }
2976 return oriMap[(d.getRotation() + indexOffset) % 4];
2977 }
2978 public void lockScreenOrientation() {
2979 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
2980 .getConfiguration().orientation));
2981 }
2982 public void unlockScreenOrientation() {
2983 mHandler.postDelayed(new Runnable() {
2984 public void run() {
2985 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2986 }
2987 }, mRestoreScreenOrientationDelay);
2988 }
2989
Winson Chung80baf5a2010-08-09 16:03:15 -07002990 /**
Joe Onoratobe386092009-11-17 17:32:16 -08002991 * Prints out out state for debugging.
2992 */
2993 public void dumpState() {
2994 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08002995 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08002996 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
2997 Log.d(TAG, "mRestoring=" + mRestoring);
2998 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
2999 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003000 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003001 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003002
Winson Chung785d2eb2011-04-14 16:08:02 -07003003 if (mAppsCustomizeContent != null) {
3004 mAppsCustomizeContent.dumpState();
3005 }
Joe Onoratobe386092009-11-17 17:32:16 -08003006 Log.d(TAG, "END launcher2 dump state");
3007 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003008}
Michael Jurka2763be32011-02-24 11:19:57 -08003009
Michael Jurkaabded662011-03-04 12:06:57 -08003010interface LauncherTransitionable {
Winson Chung5a808352011-06-27 19:08:49 -07003011 void onLauncherTransitionStart(Animator animation, boolean toWorkspace);
3012 void onLauncherTransitionEnd(Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003013}