blob: 41fb185d5ed455153bb3c72abae1bccfe84f1a9d [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;
Winson Chung82f55532011-08-09 14:14:23 -070043import android.content.SharedPreferences;
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 Cohen860f4c52011-01-27 20:16:13 -080076import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070077import android.view.ViewGroup;
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;
Adam Cohen558baaf2011-08-15 15:22:57 -070089import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080090
Adam Cohenc0dcf592011-06-01 15:30:43 -070091import java.io.DataInputStream;
92import java.io.DataOutputStream;
93import java.io.FileNotFoundException;
94import java.io.IOException;
95import java.util.ArrayList;
96import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -070097
The Android Open Source Project31dd5032009-03-03 19:32:27 -080098/**
99 * Default launcher application.
100 */
Michael Jurka946ad472010-07-09 18:05:18 -0700101public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700102 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
103 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800104 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700105 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800106
Joe Onorato9c1289c2009-08-17 11:03:03 -0400107 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400108 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700109
Winson Chung70d72102011-08-12 11:24:35 -0700110 private static final int MENU_GROUP_WALLPAPER = 1;
111 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
112 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
113 private static final int MENU_HELP = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800114
115 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700116 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117 private static final int REQUEST_PICK_APPLICATION = 6;
118 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700119 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700120 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121
122 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
123
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800124 static final int SCREEN_COUNT = 5;
125 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800126
Joe Onorato7c312c12009-08-13 21:36:53 -0700127 static final int DIALOG_CREATE_SHORTCUT = 1;
128 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129
Romain Guy98d01652009-06-30 16:21:04 -0700130 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131
132 // Type: int
133 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700134 // Type: int
135 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700137 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
138 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
140 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700141 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700143 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144 // Type: boolean
145 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
146 // Type: long
147 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
148
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700149 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
150
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700151 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700152 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700153 private State mState = State.WORKSPACE;
154 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700155
Joe Onorato9c1289c2009-08-17 11:03:03 -0400156 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700157 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
158 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung82f55532011-08-09 14:14:23 -0700159 private static final int DISMISS_CLING_DURATION = 300;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800162 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800164 private final BroadcastReceiver mCloseSystemDialogsReceiver
165 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800166 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
167
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 private LayoutInflater mInflater;
169
Joe Onorato00acb122009-08-04 16:04:30 -0400170 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700172
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700173 private AppWidgetManager mAppWidgetManager;
174 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700175
Winson Chung3d503fb2011-07-13 17:25:49 -0700176 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700177 private int[] mTmpAddItemCellCoordinates = new int[2];
178
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 private FolderInfo mFolderInfo;
180
Winson Chung3d503fb2011-07-13 17:25:49 -0700181 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800182 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700183
Winson Chungf0ea4d32011-06-06 14:27:16 -0700184 private SearchDropTargetBar mSearchDeleteBar;
185 private AppsCustomizeTabHost mAppsCustomizeTabHost;
186 private AppsCustomizePagedView mAppsCustomizeContent;
187 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189 private Bundle mSavedState;
190
191 private SpannableStringBuilder mDefaultKeySsb = null;
192
Joe Onorato9c1289c2009-08-17 11:03:03 -0400193 private boolean mWorkspaceLoading = true;
194
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800195 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196 private boolean mRestoring;
197 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700198 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199
200 private Bundle mSavedInstanceState;
201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800203 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800204 private boolean mUserPresent = true;
205 private boolean mVisible = false;
206 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400207
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700208 private static LocaleConfiguration sLocaleConfiguration = null;
209
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700210 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700211
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700212 private Intent mAppMarketIntent = null;
213
Adam Cohended9f8d2010-11-03 13:25:16 -0700214 // Related to the auto-advancing of widgets
215 private final int ADVANCE_MSG = 1;
216 private final int mAdvanceInterval = 20000;
217 private final int mAdvanceStagger = 250;
218 private long mAutoAdvanceSentTime;
219 private long mAutoAdvanceTimeLeft = -1;
220 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
221 new HashMap<View, AppWidgetProviderInfo>();
222
Winson Chung400438b2011-01-16 17:53:48 -0800223 // Determines how long to wait after a rotation before restoring the screen orientation to
224 // match the sensor state.
225 private final int mRestoreScreenOrientationDelay = 500;
226
Michael Jurka4ef207b2010-11-29 17:05:45 -0800227 // External icons saved in case of resource changes, orientation, etc.
Michael Jurkae7bf83b2010-12-14 18:02:21 -0800228 private static Drawable.ConstantState sGlobalSearchIcon;
229 private static Drawable.ConstantState sVoiceSearchIcon;
230 private static Drawable.ConstantState sAppMarketIcon;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800231
Adam Cohen2801caf2011-05-13 20:57:39 -0700232 private DragLayer mDragLayer;
233
Michael Jurkaddd62e92011-02-16 17:49:14 -0800234 private BubbleTextView mWaitingForResume;
235
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800236 private static ArrayList<PendingAddArguments> sPendingAddList
237 = new ArrayList<PendingAddArguments>();
238
239 private static class PendingAddArguments {
240 int requestCode;
241 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700242 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800243 int screen;
244 int cellX;
245 int cellY;
246 }
247
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 @Override
249 protected void onCreate(Bundle savedInstanceState) {
250 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800251 LauncherApplication app = ((LauncherApplication)getApplication());
252 mModel = app.setLauncher(this);
253 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400254 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700256
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700257 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700258 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
259 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700260
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800261 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200262 android.os.Debug.startMethodTracing(
263 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 }
265
266 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 setContentView(R.layout.launcher);
268 setupViews();
Winson Chung82f55532011-08-09 14:14:23 -0700269 enableClingsIfNecessary();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800271 registerContentObservers();
272
Joe Onorato7c312c12009-08-13 21:36:53 -0700273 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700274
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 mSavedState = savedInstanceState;
276 restoreState(mSavedState);
277
Winson Chunga12a2502010-12-20 14:41:35 -0800278 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700279 if (mAppsCustomizeContent != null) {
280 mAppsCustomizeContent.onPackagesUpdated();
281 }
Winson Chunga12a2502010-12-20 14:41:35 -0800282
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283 if (PROFILE_STARTUP) {
284 android.os.Debug.stopMethodTracing();
285 }
286
287 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400288 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289 }
290
Michael Jurkac57b7a82011-08-09 22:02:20 -0700291 if (!mModel.isAllAppsLoaded()) {
292 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
293 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
294 }
295
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800296 // For handling default keys
297 mDefaultKeySsb = new SpannableStringBuilder();
298 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800299
300 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
301 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800302
303 // If we have a saved version of these external icons, we load them up immediately
Winson Chungf0ea4d32011-06-06 14:27:16 -0700304 if (sGlobalSearchIcon == null || sVoiceSearchIcon == null || sAppMarketIcon == null) {
305 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100306 updateGlobalSearchIcon();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700307 }
308 if (sGlobalSearchIcon != null) {
309 updateGlobalSearchIcon(sGlobalSearchIcon);
310 }
311 if (sVoiceSearchIcon != null) {
312 updateVoiceSearchIcon(sVoiceSearchIcon);
313 }
314 if (sAppMarketIcon != null) {
315 updateAppMarketIcon(sAppMarketIcon);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800316 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800317 }
Romain Guycbb89e42009-06-08 15:52:54 -0700318
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800319 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700320 if (sLocaleConfiguration == null) {
321 new AsyncTask<Void, Void, LocaleConfiguration>() {
322 @Override
323 protected LocaleConfiguration doInBackground(Void... unused) {
324 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
325 readConfiguration(Launcher.this, localeConfiguration);
326 return localeConfiguration;
327 }
328
329 @Override
330 protected void onPostExecute(LocaleConfiguration result) {
331 sLocaleConfiguration = result;
332 checkForLocaleChange(); // recursive, but now with a locale configuration
333 }
334 }.execute();
335 return;
336 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700337
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800338 final Configuration configuration = getResources().getConfiguration();
339
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700340 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 final String locale = configuration.locale.toString();
342
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700343 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800344 final int mcc = configuration.mcc;
345
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700346 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347 final int mnc = configuration.mnc;
348
Romain Guy84f296c2009-11-04 15:00:44 -0800349 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350
Romain Guy84f296c2009-11-04 15:00:44 -0800351 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700352 sLocaleConfiguration.locale = locale;
353 sLocaleConfiguration.mcc = mcc;
354 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700355
Joe Onorato0589f0f2010-02-08 13:44:00 -0800356 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700357
358 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
359 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700360 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700361 public void run() {
362 writeConfiguration(Launcher.this, localeConfiguration);
363 }
364 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700365 }
366 }
367
368 private static class LocaleConfiguration {
369 public String locale;
370 public int mcc = -1;
371 public int mnc = -1;
372 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700373
Romain Guy98d01652009-06-30 16:21:04 -0700374 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
375 DataInputStream in = null;
376 try {
377 in = new DataInputStream(context.openFileInput(PREFERENCES));
378 configuration.locale = in.readUTF();
379 configuration.mcc = in.readInt();
380 configuration.mnc = in.readInt();
381 } catch (FileNotFoundException e) {
382 // Ignore
383 } catch (IOException e) {
384 // Ignore
385 } finally {
386 if (in != null) {
387 try {
388 in.close();
389 } catch (IOException e) {
390 // Ignore
391 }
392 }
393 }
394 }
395
396 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
397 DataOutputStream out = null;
398 try {
399 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
400 out.writeUTF(configuration.locale);
401 out.writeInt(configuration.mcc);
402 out.writeInt(configuration.mnc);
403 out.flush();
404 } catch (FileNotFoundException e) {
405 // Ignore
406 } catch (IOException e) {
407 //noinspection ResultOfMethodCallIgnored
408 context.getFileStreamPath(PREFERENCES).delete();
409 } finally {
410 if (out != null) {
411 try {
412 out.close();
413 } catch (IOException e) {
414 // Ignore
415 }
416 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800417 }
418 }
419
Adam Cohen716b51e2011-06-30 12:09:54 -0700420 public DragLayer getDragLayer() {
421 return mDragLayer;
422 }
423
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800424 static int getScreen() {
425 synchronized (sLock) {
426 return sScreen;
427 }
428 }
429
430 static void setScreen(int screen) {
431 synchronized (sLock) {
432 sScreen = screen;
433 }
434 }
435
Winson Chung557d6ed2011-07-08 15:34:52 -0700436 /**
437 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
438 * a configuration step, this allows the proper animations to run after other transitions.
439 */
440 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700441 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800442 switch (args.requestCode) {
443 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700444 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
445 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800446 break;
447 case REQUEST_PICK_SHORTCUT:
448 processShortcut(args.intent);
449 break;
450 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700451 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
452 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700453 result = true;
454 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800455 case REQUEST_PICK_APPWIDGET:
456 addAppWidgetFromPick(args.intent);
457 break;
458 case REQUEST_CREATE_APPWIDGET:
459 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Winson Chung3d503fb2011-07-13 17:25:49 -0700460 completeAddAppWidget(appWidgetId, args.container, args.screen);
Winson Chungb8472bb2011-08-05 13:49:21 -0700461 result = true;
462 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800463 case REQUEST_PICK_WALLPAPER:
464 // We just wanted the activity result here so we can clear mWaitingForResult
465 break;
466 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700467 // In any situation where we have a multi-step drop, we should reset the add info only after
468 // we complete the drop
469 resetAddInfo();
470 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800471 }
472
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800473 @Override
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800474 protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700475 boolean delayExitSpringLoadedMode = false;
Romain Guyaad5ef42009-06-10 02:48:37 -0700476 mWaitingForResult = false;
477
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800478 // The pattern used here is that a user PICKs a specific application,
479 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700480
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800481 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
482 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700483 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800484 final PendingAddArguments args = new PendingAddArguments();
485 args.requestCode = requestCode;
486 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700487 args.container = mPendingAddInfo.container;
488 args.screen = mPendingAddInfo.screen;
489 args.cellX = mPendingAddInfo.cellX;
490 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800491
492 // If the loader is still running, defer the add until it is done.
493 if (isWorkspaceLocked()) {
494 sPendingAddList.add(args);
495 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700496 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800497 }
Romain Guy18042c82009-11-06 11:44:55 -0800498 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
Winson Chung557d6ed2011-07-08 15:34:52 -0700499 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED) {
500 if (data != null) {
501 // Clean up the appWidgetId if we canceled
502 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
503 if (appWidgetId != -1) {
504 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
505 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800506 }
507 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700508
509 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700510 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800511 }
512
513 @Override
514 protected void onResume() {
515 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800516 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700517 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400518 mWorkspaceLoading = true;
519 mModel.startLoader(this, true);
520 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700521 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800522 }
Michael Jurkaddd62e92011-02-16 17:49:14 -0800523 if (mWaitingForResume != null) {
524 mWaitingForResume.setStayPressed(false);
525 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700526 // When we resume Launcher, a different Activity might be responsible for the app
527 // market intent, so refresh the icon
528 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800529 }
530
531 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700532 protected void onPause() {
533 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700534 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800535 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700536 }
Romain Guycbb89e42009-06-08 15:52:54 -0700537
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700538 @Override
539 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400540 // Flag the loader to stop early before switching
541 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700542 if (mAppsCustomizeContent != null) {
543 mAppsCustomizeContent.surrender();
544 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800545 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700546 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700547
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800548 // We can't hide the IME if it was forced open. So don't bother
549 /*
550 @Override
551 public void onWindowFocusChanged(boolean hasFocus) {
552 super.onWindowFocusChanged(hasFocus);
553
554 if (hasFocus) {
555 final InputMethodManager inputManager = (InputMethodManager)
556 getSystemService(Context.INPUT_METHOD_SERVICE);
557 WindowManager.LayoutParams lp = getWindow().getAttributes();
558 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
559 android.os.Handler()) {
560 protected void onReceiveResult(int resultCode, Bundle resultData) {
561 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
562 }
563 });
564 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
565 }
566 }
567 */
568
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800569 private boolean acceptFilter() {
570 final InputMethodManager inputManager = (InputMethodManager)
571 getSystemService(Context.INPUT_METHOD_SERVICE);
572 return !inputManager.isFullscreenMode();
573 }
574
575 @Override
576 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700577 final int uniChar = event.getUnicodeChar();
578 final boolean handled = super.onKeyDown(keyCode, event);
579 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
580 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800581 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
582 keyCode, event);
583 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700584 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700585 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700586 // showSearchDialog()
587 // If there are multiple keystrokes before the search dialog takes focus,
588 // onSearchRequested() will be called for every keystroke,
589 // but it is idempotent, so it's fine.
590 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800591 }
592 }
593
Joe Onorato8a9625e2010-01-28 15:55:35 -0800594 // Eat the long press event so the keyboard doesn't come up.
595 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
596 return true;
597 }
598
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800599 return handled;
600 }
601
Karl Rosaen138a0412009-04-23 19:00:21 -0700602 private String getTypedText() {
603 return mDefaultKeySsb.toString();
604 }
605
606 private void clearTypedText() {
607 mDefaultKeySsb.clear();
608 mDefaultKeySsb.clearSpans();
609 Selection.setSelection(mDefaultKeySsb, 0);
610 }
611
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800612 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700613 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
614 * State
615 */
616 private static State intToState(int stateOrdinal) {
617 State state = State.WORKSPACE;
618 final State[] stateValues = State.values();
619 for (int i = 0; i < stateValues.length; i++) {
620 if (stateValues[i].ordinal() == stateOrdinal) {
621 state = stateValues[i];
622 break;
623 }
624 }
625 return state;
626 }
627
628 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800629 * Restores the previous state, if it exists.
630 *
631 * @param savedState The previous state.
632 */
633 private void restoreState(Bundle savedState) {
634 if (savedState == null) {
635 return;
636 }
637
Michael Jurka883f55b2010-10-21 15:47:14 -0700638 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700639 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800640 showAllApps(false);
641 }
642
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800643 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
644 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700645 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800646 }
647
Winson Chung3d503fb2011-07-13 17:25:49 -0700648 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
649 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700650
Winson Chung3d503fb2011-07-13 17:25:49 -0700651 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
652 mPendingAddInfo.container = pendingAddContainer;
653 mPendingAddInfo.screen = pendingAddScreen;
654 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
655 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800656 mRestoring = true;
657 }
658
659 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
660 if (renameFolder) {
661 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700662 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 mRestoring = true;
664 }
Winson Chunga12a2502010-12-20 14:41:35 -0800665
Winson Chung785d2eb2011-04-14 16:08:02 -0700666
667 // Restore the AppsCustomize tab
668 if (mAppsCustomizeTabHost != null) {
669 String curTab = savedState.getString("apps_customize_currentTab");
670 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700671 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700672 mAppsCustomizeContent.setContentType(
673 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
674 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700675 mAppsCustomizeContent.loadAssociatedPages(
676 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700677 }
678
Winson Chung5afbf7b2011-07-25 11:53:08 -0700679 int currentIndex = savedState.getInt("apps_customize_currentIndex");
680 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700681 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 }
683
684 /**
685 * Finds all the views we need and configure them properly.
686 */
687 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700688 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400689
Winson Chung4c98d922011-05-31 16:50:48 -0700690 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
691 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692
Winson Chung4c98d922011-05-31 16:50:48 -0700693 // Setup the drag layer
694 mDragLayer.setup(this, dragController);
695
Winson Chung3d503fb2011-07-13 17:25:49 -0700696 // Setup the hotseat
697 mHotseat = (Hotseat) findViewById(R.id.hotseat);
698 if (mHotseat != null) {
699 mHotseat.setup(this);
700 }
701
Winson Chung4c98d922011-05-31 16:50:48 -0700702 // Setup the workspace
703 mWorkspace.setHapticFeedbackEnabled(false);
704 mWorkspace.setOnLongClickListener(this);
705 mWorkspace.setup(this, dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700706 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700707
Winson Chungf0ea4d32011-06-06 14:27:16 -0700708 // Get the search/delete bar
709 mSearchDeleteBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700710
Winson Chungf0ea4d32011-06-06 14:27:16 -0700711 // Setup AppsCustomize
712 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
713 findViewById(R.id.apps_customize_pane);
714 mAppsCustomizeContent = (AppsCustomizePagedView)
715 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
716 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400717
Romain Guy1fbc1c82009-11-09 20:43:08 -0800718
Winson Chung4c98d922011-05-31 16:50:48 -0700719
Winson Chung3d503fb2011-07-13 17:25:49 -0700720 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700721 dragController.setDragScoller(mWorkspace);
722 dragController.setScrollView(mDragLayer);
723 dragController.setMoveTarget(mWorkspace);
724 dragController.addDropTarget(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700725 if (mSearchDeleteBar != null) {
726 mSearchDeleteBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800727 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800728 }
729
Romain Guy8a73c512009-11-09 19:19:59 -0800730
Winson Chungaafa03c2010-06-11 17:34:16 -0700731
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800732 /**
733 * Creates a view representing a shortcut.
734 *
735 * @param info The data structure describing the shortcut.
736 *
737 * @return A View inflated from R.layout.application.
738 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800739 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800740 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700741 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800742 }
743
744 /**
745 * Creates a view representing a shortcut inflated from the specified resource.
746 *
747 * @param layoutResId The id of the XML layout used to create the shortcut.
748 * @param parent The group the shortcut belongs to.
749 * @param info The data structure describing the shortcut.
750 *
751 * @return A View inflated from layoutResId.
752 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800753 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800754 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
755 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800757 return favorite;
758 }
759
760 /**
761 * Add an application shortcut to the workspace.
762 *
763 * @param data The intent describing the application.
764 * @param cellInfo The position on screen where to create the shortcut.
765 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700766 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700767 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700768 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700769
Adam Cohenfbba09b2011-07-18 21:43:05 -0700770 // First we check if we already know the exact location where we want to add this item.
771 if (cellX >= 0 && cellY >= 0) {
772 cellXY[0] = cellX;
773 cellXY[1] = cellY;
774 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700775 showOutOfSpaceMessage();
776 return;
777 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800778
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800779 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800780
Romain Guy73b979d2009-06-09 12:57:21 -0700781 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800782 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800783 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800784 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700785 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700786 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800787 } else {
788 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800789 }
790 }
Romain Guycbb89e42009-06-08 15:52:54 -0700791
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800792 /**
793 * Add a shortcut to the workspace.
794 *
795 * @param data The intent describing the shortcut.
796 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800797 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700798 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
799 int cellY) {
800 int[] cellXY = mTmpAddItemCellCoordinates;
801 int[] touchXY = mPendingAddInfo.dropPos;
802 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700803
Michael Jurkad3ef3062010-11-23 16:23:58 -0800804 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700805
Adam Cohen558baaf2011-08-15 15:22:57 -0700806 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
807 final View view = createShortcut(info);
808
Adam Cohenfbba09b2011-07-18 21:43:05 -0700809 // First we check if we already know the exact location where we want to add this item.
810 if (cellX >= 0 && cellY >= 0) {
811 cellXY[0] = cellX;
812 cellXY[1] = cellY;
813 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700814
815 // If appropriate, either create a folder or add to an existing folder
816 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
817 true, null,null)) {
818 return;
819 }
820 DragObject dragObject = new DragObject();
821 dragObject.dragInfo = info;
822 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
823 return;
824 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700825 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800826 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700827 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800828 foundCellSpan = (result != null);
829 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700830 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800831 }
832
833 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700834 showOutOfSpaceMessage();
835 return;
836 }
837
Adam Cohen558baaf2011-08-15 15:22:57 -0700838 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800839
840 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700841 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
842 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 }
844 }
845
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800846 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700847 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800848 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700849 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700850 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800851 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700852 private void completeAddAppWidget(final int appWidgetId, long container, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700853 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700854
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700855 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700856 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700857
858 // We want to account for the extra amount of padding that we are adding to the widget
859 // to ensure that it gets the full amount of space that it has requested
860 Resources r = getResources();
861 int requiredWidth = appWidgetInfo.minWidth +
862 r.getDimensionPixelSize(R.dimen.app_widget_padding_left) +
863 r.getDimensionPixelSize(R.dimen.app_widget_padding_right);
864 int requiredHeight = appWidgetInfo.minHeight +
865 r.getDimensionPixelSize(R.dimen.app_widget_padding_top) +
866 r.getDimensionPixelSize(R.dimen.app_widget_padding_bottom);
867 int[] spanXY = layout.rectToCell(requiredWidth, requiredHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700868
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800869 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700870 // We have saved the position to which the widget was dragged-- this really only matters
871 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700872 int[] cellXY = mTmpAddItemCellCoordinates;
873 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700874 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700875 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
876 cellXY[0] = mPendingAddInfo.cellX;
877 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700878 foundCellSpan = true;
879 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700880 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700881 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700882 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800883 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700884 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700885 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700886 }
887
Michael Jurka0280c3b2010-09-17 15:00:07 -0700888 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -0800889 if (appWidgetId != -1) {
890 // Deleting an app widget ID is a void call but writes to disk before returning
891 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -0800892 new Thread("deleteAppWidgetId") {
893 public void run() {
894 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
895 }
896 }.start();
897 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700898 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -0800899 return;
900 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700902 // Build Launcher-specific widget info and save to database
903 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700904 launcherInfo.spanX = spanXY[0];
905 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700906
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800907 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -0700908 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800909
910 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800911 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700912 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700913
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700914 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800915 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700916
Winson Chung3d503fb2011-07-13 17:25:49 -0700917 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400918 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -0700919
920 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800921 }
922 }
Romain Guycbb89e42009-06-08 15:52:54 -0700923
Adam Cohended9f8d2010-11-03 13:25:16 -0700924 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
925 @Override
926 public void onReceive(Context context, Intent intent) {
927 final String action = intent.getAction();
928 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
929 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -0700930 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -0700931 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -0700932
Winson Chungc100e8e2011-08-09 16:02:43 -0700933 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -0700934 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -0700935 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
936 mAppsCustomizeTabHost.reset();
937 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -0700938 }
Adam Cohended9f8d2010-11-03 13:25:16 -0700939 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
940 mUserPresent = true;
941 updateRunning();
942 }
943 }
944 };
945
946 @Override
947 public void onAttachedToWindow() {
948 super.onAttachedToWindow();
949
950 // Listen for broadcasts related to user-presence
951 final IntentFilter filter = new IntentFilter();
952 filter.addAction(Intent.ACTION_SCREEN_OFF);
953 filter.addAction(Intent.ACTION_USER_PRESENT);
954 registerReceiver(mReceiver, filter);
955
Adam Cohend113e0c2010-11-11 10:48:05 -0800956 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -0700957 mVisible = true;
958 }
959
960 @Override
961 public void onDetachedFromWindow() {
962 super.onDetachedFromWindow();
963 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -0700964 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -0700965
Adam Cohend113e0c2010-11-11 10:48:05 -0800966 if (mAttached) {
967 unregisterReceiver(mReceiver);
968 mAttached = false;
969 }
Adam Cohended9f8d2010-11-03 13:25:16 -0700970 updateRunning();
971 }
972
973 public void onWindowVisibilityChanged(int visibility) {
974 mVisible = visibility == View.VISIBLE;
975 updateRunning();
976 }
977
978 private void sendAdvanceMessage(long delay) {
979 mHandler.removeMessages(ADVANCE_MSG);
980 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
981 mHandler.sendMessageDelayed(msg, delay);
982 mAutoAdvanceSentTime = System.currentTimeMillis();
983 }
984
985 private void updateRunning() {
986 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
987 if (autoAdvanceRunning != mAutoAdvanceRunning) {
988 mAutoAdvanceRunning = autoAdvanceRunning;
989 if (autoAdvanceRunning) {
990 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
991 sendAdvanceMessage(delay);
992 } else {
993 if (!mWidgetsToAdvance.isEmpty()) {
994 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
995 (System.currentTimeMillis() - mAutoAdvanceSentTime));
996 }
997 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -0800998 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -0700999 }
1000 }
1001 }
1002
1003 private final Handler mHandler = new Handler() {
1004 @Override
1005 public void handleMessage(Message msg) {
1006 if (msg.what == ADVANCE_MSG) {
1007 int i = 0;
1008 for (View key: mWidgetsToAdvance.keySet()) {
1009 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1010 final int delay = mAdvanceStagger * i;
1011 if (v instanceof Advanceable) {
1012 postDelayed(new Runnable() {
1013 public void run() {
1014 ((Advanceable) v).advance();
1015 }
1016 }, delay);
1017 }
1018 i++;
1019 }
1020 sendAdvanceMessage(mAdvanceInterval);
1021 }
1022 }
1023 };
1024
1025 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001026 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001027 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1028 if (v instanceof Advanceable) {
1029 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001030 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001031 updateRunning();
1032 }
1033 }
1034
1035 void removeWidgetToAutoAdvance(View hostView) {
1036 if (mWidgetsToAdvance.containsKey(hostView)) {
1037 mWidgetsToAdvance.remove(hostView);
1038 updateRunning();
1039 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001040 }
1041
Joe Onorato9c1289c2009-08-17 11:03:03 -04001042 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001043 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001044 launcherInfo.hostView = null;
1045 }
1046
Adam Cohended9f8d2010-11-03 13:25:16 -07001047 void showOutOfSpaceMessage() {
1048 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1049 }
1050
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001051 public LauncherAppWidgetHost getAppWidgetHost() {
1052 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053 }
Romain Guycbb89e42009-06-08 15:52:54 -07001054
Winson Chunga9abd0e2010-10-27 17:18:37 -07001055 public LauncherModel getModel() {
1056 return mModel;
1057 }
1058
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001059 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001060 getWindow().closeAllPanels();
1061
1062 try {
1063 dismissDialog(DIALOG_CREATE_SHORTCUT);
1064 // Unlock the workspace if the dialog was showing
1065 } catch (Exception e) {
1066 // An exception is thrown if the dialog is not visible, which is fine
1067 }
1068
1069 try {
1070 dismissDialog(DIALOG_RENAME_FOLDER);
1071 // Unlock the workspace if the dialog was showing
1072 } catch (Exception e) {
1073 // An exception is thrown if the dialog is not visible, which is fine
1074 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001075
1076 // Whatever we were doing is hereby canceled.
1077 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001078 }
1079
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 @Override
1081 protected void onNewIntent(Intent intent) {
1082 super.onNewIntent(intent);
1083
1084 // Close the menu
1085 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001086 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001087 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001088
Adam Cohen95bb8002011-07-03 23:40:28 -07001089 closeFolder();
1090
Joe Onorato14f122b2009-11-19 14:06:36 -08001091 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1092 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001093
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001094 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001095 mWorkspace.exitWidgetResizeMode();
Patrick Dubroya0aa0122011-02-24 11:42:23 -08001096 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001097 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001098 }
Winson Chungde1af762011-07-21 16:44:07 -07001099 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001100 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001101
Joe Onorato3a8820b2009-11-10 15:06:42 -08001102 final View v = getWindow().peekDecorView();
1103 if (v != null && v.getWindowToken() != null) {
1104 InputMethodManager imm = (InputMethodManager)getSystemService(
1105 INPUT_METHOD_SERVICE);
1106 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001108
Michael Jurka35aa14d2011-07-07 17:01:08 -07001109 // Reset AllApps to its initial state
Winson Chungc100e8e2011-08-09 16:02:43 -07001110 if (mAppsCustomizeTabHost != null) {
1111 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001112 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 }
1114 }
1115
1116 @Override
1117 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1118 // Do not call super here
1119 mSavedInstanceState = savedInstanceState;
1120 }
1121
1122 @Override
1123 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001124 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001125 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001126
Michael Jurka883f55b2010-10-21 15:47:14 -07001127 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001128 // We close any open folder since it will not be re-opened, and we need to make sure
1129 // this state is reflected.
1130 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001131
Winson Chung3d503fb2011-07-13 17:25:49 -07001132 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1133 mWaitingForResult) {
1134 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1135 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1136 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1137 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001138 }
1139
1140 if (mFolderInfo != null && mWaitingForResult) {
1141 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1142 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1143 }
Michael Jurka946ad472010-07-09 18:05:18 -07001144
Winson Chung785d2eb2011-04-14 16:08:02 -07001145 // Save the current AppsCustomize tab
1146 if (mAppsCustomizeTabHost != null) {
1147 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1148 if (currentTabTag != null) {
1149 outState.putString("apps_customize_currentTab", currentTabTag);
1150 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001151 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1152 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001153 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001154 }
1155
1156 @Override
1157 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001158 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001159
Winson Chunge7a03942011-08-05 15:05:12 -07001160 // Remove all pending runnables
1161 mHandler.removeMessages(ADVANCE_MSG);
1162 mHandler.removeMessages(0);
1163
Winson Chungcd2b0142011-06-08 16:02:26 -07001164 // Stop callbacks from LauncherModel
1165 LauncherApplication app = ((LauncherApplication) getApplication());
1166 mModel.stopLoader();
1167 app.setLauncher(null);
1168
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001169 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001170 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001171 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001172 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001174 mAppWidgetHost = null;
1175
1176 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177
1178 TextKeyListener.getInstance().release();
1179
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001180
Winson Chung3d503fb2011-07-13 17:25:49 -07001181 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001182
1183 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001184 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001185
1186 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1187 mWorkspace.removeAllViews();
1188 mWorkspace = null;
1189 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001190
1191 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001192 }
1193
Adam Cohena9cf38f2011-05-02 15:36:58 -07001194 public DragController getDragController() {
1195 return mDragController;
1196 }
1197
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001198 @Override
1199 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001200 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001201 super.startActivityForResult(intent, requestCode);
1202 }
1203
Winson Chung70d72102011-08-12 11:24:35 -07001204 /**
1205 * Indicates that we want global search for this activity by setting the globalSearch
1206 * argument for {@link #startSearch} to true.
1207 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001209 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001211
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001212 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001213
Karl Rosaen138a0412009-04-23 19:00:21 -07001214 if (initialQuery == null) {
1215 // Use any text typed in the launcher as the initial query
1216 initialQuery = getTypedText();
1217 clearTypedText();
1218 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219 if (appSearchData == null) {
1220 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001221 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001222 }
Romain Guycbb89e42009-06-08 15:52:54 -07001223
Karl Rosaen138a0412009-04-23 19:00:21 -07001224 final SearchManager searchManager =
1225 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001226 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001227 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 }
1229
Winson Chung70d72102011-08-12 11:24:35 -07001230 @Override
1231 public boolean onCreateOptionsMenu(Menu menu) {
1232 if (isWorkspaceLocked()) {
1233 return false;
1234 }
1235
1236 super.onCreateOptionsMenu(menu);
1237 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1238 .setIcon(android.R.drawable.ic_menu_gallery)
1239 .setAlphabeticShortcut('W');
1240 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1241 .setIcon(android.R.drawable.ic_menu_manage)
1242 .setAlphabeticShortcut('M');
1243 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1244 .setIcon(android.R.drawable.ic_menu_help)
1245 .setAlphabeticShortcut('H');
1246 return true;
1247 }
1248
1249 @Override
1250 public boolean onPrepareOptionsMenu(Menu menu) {
1251 super.onPrepareOptionsMenu(menu);
1252
1253 if (mAppsCustomizeTabHost.isTransitioning()) {
1254 return false;
1255 }
1256 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1257 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1258
1259 return true;
1260 }
1261
1262 @Override
1263 public boolean onOptionsItemSelected(MenuItem item) {
1264 switch (item.getItemId()) {
1265 case MENU_WALLPAPER_SETTINGS:
1266 startWallpaper();
1267 return true;
1268 case MENU_MANAGE_APPS:
1269 manageApps();
1270 return true;
1271 case MENU_HELP:
1272 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.help_url))));
1273 return true;
1274 }
1275
1276 return super.onOptionsItemSelected(item);
1277 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001278
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001279 @Override
1280 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001281 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001282 // Use a custom animation for launching search
1283 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001284 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001285 }
1286
Joe Onorato9c1289c2009-08-17 11:03:03 -04001287 public boolean isWorkspaceLocked() {
1288 return mWorkspaceLoading || mWaitingForResult;
1289 }
1290
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001291 private void addItems() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001292 showWorkspace(true);
Adam Cohenfbba09b2011-07-18 21:43:05 -07001293 showAddDialog();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001294 }
1295
Michael Jurka0280c3b2010-09-17 15:00:07 -07001296 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001297 mPendingAddInfo.container = ItemInfo.NO_ID;
1298 mPendingAddInfo.screen = -1;
1299 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1300 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1301 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001302 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001303
Winson Chung7ad01412010-09-27 11:33:03 -07001304 private void manageApps() {
1305 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1306 }
1307
Michael Jurkaaf442092010-06-10 17:01:57 -07001308 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001309 // TODO: catch bad widget exception when sent
1310 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001311 // TODO: Is this log message meaningful?
1312 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001313 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001314 }
1315
Winson Chung55cef262010-10-28 14:14:18 -07001316 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001317 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318
Bjorn Bringert7984c942009-12-09 15:38:25 +00001319 if (appWidget.configure != null) {
1320 // Launch over to configure widget, if needed
1321 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1322 intent.setComponent(appWidget.configure);
1323 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001324 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001325 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1326 intent.putExtra(
1327 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1328 info.mimeType);
1329
1330 final String mimeType = info.mimeType;
1331 final ClipData clipData = (ClipData) info.configurationData;
1332 final ClipDescription clipDesc = clipData.getDescription();
1333 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1334 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001335 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001336 final CharSequence stringData = item.getText();
1337 final Uri uriData = item.getUri();
1338 final Intent intentData = item.getIntent();
1339 final String key =
1340 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1341 if (uriData != null) {
1342 intent.putExtra(key, uriData);
1343 } else if (intentData != null) {
1344 intent.putExtra(key, intentData);
1345 } else if (stringData != null) {
1346 intent.putExtra(key, stringData);
1347 }
1348 break;
1349 }
1350 }
1351 }
Winson Chung55cef262010-10-28 14:14:18 -07001352 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001353
Romain Guy8e633c52010-03-04 12:51:36 -08001354 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001356 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001357 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001358
1359 // Exit spring loaded mode if necessary after adding the widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001360 exitSpringLoadedDragModeDelayed(true, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 }
1362 }
Romain Guycbb89e42009-06-08 15:52:54 -07001363
Adam Cohenfbba09b2011-07-18 21:43:05 -07001364 /**
1365 * Process a shortcut drop.
1366 *
1367 * @param componentName The name of the component
1368 * @param screen The screen where it should be added
1369 * @param cell The cell it should be added to, optional
1370 * @param position The location on the screen where it was dropped, optional
1371 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001372 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1373 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001374 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001375 mPendingAddInfo.container = container;
1376 mPendingAddInfo.screen = screen;
1377 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001378
1379 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001380 mPendingAddInfo.cellX = cell[0];
1381 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001382 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001383
1384 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1385 createShortcutIntent.setComponent(componentName);
1386 processShortcut(createShortcutIntent);
1387 }
1388
Adam Cohenfbba09b2011-07-18 21:43:05 -07001389 /**
1390 * Process a widget drop.
1391 *
1392 * @param info The PendingAppWidgetInfo of the widget being added.
1393 * @param screen The screen where it should be added
1394 * @param cell The cell it should be added to, optional
1395 * @param position The location on the screen where it was dropped, optional
1396 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001397 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1398 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001399 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001400 mPendingAddInfo.container = info.container = container;
1401 mPendingAddInfo.screen = info.screen = screen;
1402 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001403 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001404 mPendingAddInfo.cellX = cell[0];
1405 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001406 }
1407
1408 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1409 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1410 addAppWidgetImpl(appWidgetId, info);
1411 }
1412
Joe Onoratodeb98af2010-02-19 14:59:39 -08001413 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001414 // Handle case where user selected "Applications"
1415 String applicationName = getResources().getString(R.string.group_applications);
1416 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001417
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001418 if (applicationName != null && applicationName.equals(shortcutName)) {
1419 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1420 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001421
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001422 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1423 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001424 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001425 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001426 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001427 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001428 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001429 }
1430
Winson Chung24ab2f12010-09-16 14:10:47 -07001431 void processWallpaper(Intent intent) {
1432 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1433 }
1434
Winson Chung3d503fb2011-07-13 17:25:49 -07001435 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1436 int cellY) {
Adam Cohend0445262011-07-04 23:53:22 -07001437 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438 folderInfo.title = getText(R.string.folder_name);
1439
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001441 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1442 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001443 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444
1445 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001446 FolderIcon newFolder =
1447 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1448 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1449 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001450 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451 }
Romain Guycbb89e42009-06-08 15:52:54 -07001452
Joe Onorato9c1289c2009-08-17 11:03:03 -04001453 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001454 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001455 }
1456
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001457 private void showNotifications() {
1458 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1459 if (statusBar != null) {
1460 statusBar.expand();
1461 }
1462 }
1463
1464 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001465 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001467 Intent chooser = Intent.createChooser(pickWallpaper,
1468 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001469 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1470 // Removed in Eclair MR1
1471// WallpaperManager wm = (WallpaperManager)
1472// getSystemService(Context.WALLPAPER_SERVICE);
1473// WallpaperInfo wi = wm.getWallpaperInfo();
1474// if (wi != null && wi.getSettingsActivity() != null) {
1475// LabeledIntent li = new LabeledIntent(getPackageName(),
1476// R.string.configure_wallpaper, 0);
1477// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1478// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1479// }
Mike Clerona0618e42009-10-22 13:55:21 -07001480 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001481 }
1482
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001483 /**
1484 * Registers various content observers. The current implementation registers
1485 * only a favorites observer to keep track of the favorites applications.
1486 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001487 private void registerContentObservers() {
1488 ContentResolver resolver = getContentResolver();
1489 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1490 true, mWidgetObserver);
1491 }
1492
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493 @Override
1494 public boolean dispatchKeyEvent(KeyEvent event) {
1495 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1496 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001497 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001498 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001499 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001500 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001501 dumpState();
1502 return true;
1503 }
1504 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001505 }
1506 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1507 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001508 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 return true;
1510 }
1511 }
1512
1513 return super.dispatchKeyEvent(event);
1514 }
1515
Joe Onorato88ec0992009-11-19 13:16:06 -08001516 @Override
1517 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001518 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001519 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001520 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001521 Folder openFolder = mWorkspace.getOpenFolder();
1522 if (openFolder.isEditingName()) {
1523 openFolder.dismissEditingName();
1524 } else {
1525 closeFolder();
1526 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001527 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001528 mWorkspace.exitWidgetResizeMode();
1529
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001530 // Back button is a no-op here, but give at least some feedback for the button press
1531 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001532 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001533 }
1534
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001535 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001536 * Re-listen when widgets are reset.
1537 */
1538 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001539 if (mAppWidgetHost != null) {
1540 mAppWidgetHost.startListening();
1541 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001542 }
1543
1544 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001545 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1546 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001548 private void unbindWorkspaceAndHotseatItems() {
Adam Cohen4eac29a2011-07-11 17:53:37 -07001549 LauncherModel.unbindWorkspaceItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001550 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001551
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001552 /**
1553 * Launches the intent referred by the clicked shortcut.
1554 *
1555 * @param v The view representing the clicked shortcut.
1556 */
1557 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001558 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1559 // view has detached (it's possible for this to happen if the view is removed mid touch).
1560 if (v.getWindowToken() == null) {
1561 return;
1562 }
1563
1564 if (mWorkspace.isSwitchingState()) {
1565 return;
1566 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001567
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001568 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001569 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001570 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001571 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001572 int[] pos = new int[2];
1573 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001574 intent.setSourceBounds(new Rect(pos[0], pos[1],
1575 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001576 boolean success = startActivitySafely(intent, tag);
1577
1578 if (success && v instanceof BubbleTextView) {
1579 mWaitingForResume = (BubbleTextView) v;
1580 mWaitingForResume.setStayPressed(true);
1581 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001582 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001583 if (v instanceof FolderIcon) {
1584 FolderIcon fi = (FolderIcon) v;
1585 handleFolderClick(fi);
1586 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001587 } else if (v == mAllAppsButton) {
1588 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001589 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001590 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001591 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001592 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001593 }
1594 }
1595
Michael Jurka0e260592010-06-30 17:07:39 -07001596 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001597 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001598 // clicking anywhere on the workspace causes the customization drawer to slide down
1599 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001600 return false;
1601 }
1602
Michael Jurkaaf442092010-06-10 17:01:57 -07001603 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001604 * Event handler for the search button
1605 *
1606 * @param v The view that was clicked.
1607 */
1608 public void onClickSearchButton(View v) {
Amith Yamasania135ba82011-08-09 17:42:01 -07001609 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001610 }
1611
1612 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001613 * Event handler for the voice button
1614 *
1615 * @param v The view that was clicked.
1616 */
1617 public void onClickVoiceButton(View v) {
1618 startVoiceSearch();
1619 }
1620
1621 private void startVoiceSearch() {
1622 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1623 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1624 startActivity(intent);
1625 }
1626
1627 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001628 * Event handler for the "grid" button that appears on the home screen, which
1629 * enters all apps mode.
1630 *
1631 * @param v The view that was clicked.
1632 */
1633 public void onClickAllAppsButton(View v) {
1634 showAllApps(true);
1635 }
1636
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001637 public void onClickAppMarketButton(View v) {
1638 if (mAppMarketIntent != null) {
1639 startActivitySafely(mAppMarketIntent, "app market");
1640 }
1641 }
1642
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001643 void startApplicationDetailsActivity(ComponentName componentName) {
1644 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001645 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1646 Uri.fromParts("package", packageName, null));
1647 startActivity(intent);
1648 }
1649
Patrick Dubroy5539af72010-09-07 15:22:01 -07001650 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1651 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1652 // System applications cannot be installed. For now, show a toast explaining that.
1653 // We may give them the option of disabling apps this way.
1654 int messageId = R.string.uninstall_system_app_text;
1655 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1656 } else {
1657 String packageName = appInfo.componentName.getPackageName();
1658 String className = appInfo.componentName.getClassName();
1659 Intent intent = new Intent(
1660 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1661 startActivity(intent);
1662 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001663 }
1664
Michael Jurkaddd62e92011-02-16 17:49:14 -08001665 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001666 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1667 try {
1668 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001669 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001670 } catch (ActivityNotFoundException e) {
1671 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001672 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001673 } catch (SecurityException e) {
1674 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001675 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001676 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001677 "or use the exported attribute for this activity. "
1678 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001679 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001680 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001681 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001682
Romain Guy8e633c52010-03-04 12:51:36 -08001683 void startActivityForResultSafely(Intent intent, int requestCode) {
1684 try {
1685 startActivityForResult(intent, requestCode);
1686 } catch (ActivityNotFoundException e) {
1687 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1688 } catch (SecurityException e) {
1689 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1690 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1691 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1692 "or use the exported attribute for this activity.", e);
1693 }
1694 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001695
Adam Cohena9cf38f2011-05-02 15:36:58 -07001696 private void handleFolderClick(FolderIcon folderIcon) {
1697 final FolderInfo info = folderIcon.mInfo;
1698 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001699 // Close any open folder
1700 closeFolder();
1701 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001702 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001703 } else {
1704 // Find the open folder...
Adam Cohena9cf38f2011-05-02 15:36:58 -07001705 Folder openFolder = mWorkspace.getFolderForTag(info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001706 int folderScreen;
1707 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001708 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001709 // .. and close it
1710 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001711 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712 // Close any folder open on the current screen
1713 closeFolder();
1714 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001715 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716 }
1717 }
1718 }
1719 }
1720
Adam Cohen2801caf2011-05-13 20:57:39 -07001721 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001722 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001723 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1724 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1725 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1726
Adam Cohenc51934b2011-07-26 21:07:43 -07001727 FolderInfo info = (FolderInfo) fi.getTag();
1728 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1729 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001730 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1731 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001732 }
1733
Adam Cohen2801caf2011-05-13 20:57:39 -07001734 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1735 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1736 oa.start();
1737 }
1738
1739 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001740 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001741 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1742 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1743 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1744
Adam Cohenc51934b2011-07-26 21:07:43 -07001745 FolderInfo info = (FolderInfo) fi.getTag();
1746 CellLayout cl = null;
1747 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1748 cl = (CellLayout) fi.getParent().getParent();
1749 }
1750
1751 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001752 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1753 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001754 oa.addListener(new AnimatorListenerAdapter() {
1755 @Override
1756 public void onAnimationEnd(Animator animation) {
1757 if (layout != null) {
1758 layout.clearFolderLeaveBehind();
1759 }
1760 }
1761 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001762 oa.start();
1763 }
1764
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001765 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001766 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001767 * is animated relative to the specified View. If the View is null, no animation
1768 * is played.
1769 *
1770 * @param folderInfo The FolderInfo describing the folder to open.
1771 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001772 public void openFolder(FolderIcon folderIcon) {
1773 Folder folder = folderIcon.mFolder;
1774 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001775
Adam Cohen2801caf2011-05-13 20:57:39 -07001776 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001777 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001778
Adam Cohen4554ee12011-08-03 16:13:21 -07001779 // Just verify that the folder hasn't already been added to the DragLayer.
1780 // There was a one-off crash where the folder had a parent already.
1781 if (folder.getParent() == null) {
1782 mDragLayer.addView(folder);
1783 mDragController.addDropTarget((DropTarget) folder);
1784 } else {
1785 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1786 folder.getParent() + ").");
1787 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001788 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001789 }
1790
1791 public void closeFolder() {
1792 Folder folder = mWorkspace.getOpenFolder();
1793 if (folder != null) {
1794 closeFolder(folder);
1795 }
1796 }
1797
1798 void closeFolder(Folder folder) {
1799 folder.getInfo().opened = false;
1800
1801 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1802 if (parent != null) {
1803 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1804 shrinkAndFadeInFolderIcon(fi);
1805 }
1806 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807 }
1808
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001810 if (mState != State.WORKSPACE) {
1811 return false;
1812 }
1813
Joe Onorato9c1289c2009-08-17 11:03:03 -04001814 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 return false;
1816 }
1817
1818 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001819 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 }
1821
Michael Jurka0280c3b2010-09-17 15:00:07 -07001822 resetAddInfo();
1823 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001825 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001826 return true;
1827 }
1828
Winson Chung3d503fb2011-07-13 17:25:49 -07001829 // The hotseat touch handling does not go through Workspace, and we always allow long press
1830 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001831 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001832 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1833 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001834 if (itemUnderLongClick == null) {
1835 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001836 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1837 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001838 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001839 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001840 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001841 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07001842 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001843 }
1844 }
1845 }
1846 return true;
1847 }
1848
Winson Chung3d503fb2011-07-13 17:25:49 -07001849 boolean isHotseatLayout(View layout) {
1850 return mHotseat != null && layout != null &&
1851 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1852 }
1853 Hotseat getHotseat() {
1854 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001855 }
1856
Winson Chung3d503fb2011-07-13 17:25:49 -07001857 /**
1858 * Returns the CellLayout of the specified container at the specified screen.
1859 */
1860 CellLayout getCellLayout(long container, int screen) {
1861 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1862 if (mHotseat != null) {
1863 return mHotseat.getLayout();
1864 } else {
1865 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001866 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001867 } else {
1868 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001869 }
1870 }
1871
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001872 Workspace getWorkspace() {
1873 return mWorkspace;
1874 }
1875
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001876 @Override
1877 protected Dialog onCreateDialog(int id) {
1878 switch (id) {
1879 case DIALOG_CREATE_SHORTCUT:
1880 return new CreateShortcut().createDialog();
1881 case DIALOG_RENAME_FOLDER:
1882 return new RenameFolder().createDialog();
1883 }
1884
1885 return super.onCreateDialog(id);
1886 }
1887
1888 @Override
1889 protected void onPrepareDialog(int id, Dialog dialog) {
1890 switch (id) {
1891 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892 break;
1893 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001894 if (mFolderInfo != null) {
1895 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1896 final CharSequence text = mFolderInfo.title;
1897 input.setText(text);
1898 input.setSelection(0, text.length());
1899 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001900 break;
1901 }
1902 }
1903
1904 void showRenameDialog(FolderInfo info) {
1905 mFolderInfo = info;
1906 mWaitingForResult = true;
1907 showDialog(DIALOG_RENAME_FOLDER);
1908 }
1909
Adam Cohenfbba09b2011-07-18 21:43:05 -07001910 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001911 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001912 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
1913 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914 mWaitingForResult = true;
1915 showDialog(DIALOG_CREATE_SHORTCUT);
1916 }
1917
1918 private class RenameFolder {
1919 private EditText mInput;
1920
1921 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001922 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1923 mInput = (EditText) layout.findViewById(R.id.folder_name);
1924
1925 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1926 builder.setIcon(0);
1927 builder.setTitle(getString(R.string.rename_folder_title));
1928 builder.setCancelable(true);
1929 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1930 public void onCancel(DialogInterface dialog) {
1931 cleanup();
1932 }
1933 });
1934 builder.setNegativeButton(getString(R.string.cancel_action),
1935 new Dialog.OnClickListener() {
1936 public void onClick(DialogInterface dialog, int which) {
1937 cleanup();
1938 }
1939 }
1940 );
1941 builder.setPositiveButton(getString(R.string.rename_action),
1942 new Dialog.OnClickListener() {
1943 public void onClick(DialogInterface dialog, int which) {
1944 changeFolderName();
1945 }
1946 }
1947 );
1948 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001949
1950 final AlertDialog dialog = builder.create();
1951 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1952 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07001953 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05001954 mInput.requestFocus();
1955 InputMethodManager inputManager = (InputMethodManager)
1956 getSystemService(Context.INPUT_METHOD_SERVICE);
1957 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001958 }
1959 });
1960
1961 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 }
1963
1964 private void changeFolderName() {
1965 final String name = mInput.getText().toString();
1966 if (!TextUtils.isEmpty(name)) {
1967 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001968 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 mFolderInfo.title = name;
1970 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1971
Joe Onorato9c1289c2009-08-17 11:03:03 -04001972 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001973 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001974 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975 } else {
1976 final FolderIcon folderIcon = (FolderIcon)
1977 mWorkspace.getViewForTag(mFolderInfo);
1978 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001979 // TODO: At some point we'll probably want some version of setting
1980 // the text for a folder icon.
1981 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001982 getWorkspace().requestLayout();
1983 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001984 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001985 mWorkspaceLoading = true;
1986 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001987 }
1988 }
1989 }
1990 cleanup();
1991 }
1992
1993 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 dismissDialog(DIALOG_RENAME_FOLDER);
1995 mWaitingForResult = false;
1996 mFolderInfo = null;
1997 }
1998 }
1999
Daniel Sandler843e8602010-06-07 14:59:01 -04002000 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2001 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002002 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002003 }
2004
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002005 // AllAppsView.Watcher
2006 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002007 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002008 mWorkspace.setVisibility(View.GONE);
2009 }
2010 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002011
2012 /**
2013 * Helper method for the cameraZoomIn/cameraZoomOut animations
2014 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002015 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002016 * @param scaleFactor The scale factor used for the zoom
2017 */
2018 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2019 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002020
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002021 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002022 // Set pivotY so that at the starting zoom factor, the view is partially
2023 // visible. Modifying initialHeightFactor changes how much of the view is
2024 // initially showing, and hence the perceived angle from which the view enters.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002025 if (state == State.APPS_CUSTOMIZE) {
Michael Jurkaea573482011-02-03 19:48:18 -08002026 final float initialHeightFactor = 0.175f;
Adam Cohenf16e5712011-01-13 13:31:45 -08002027 view.setPivotY((1 - initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002028 } else {
Adam Cohenf16e5712011-01-13 13:31:45 -08002029 final float initialHeightFactor = 0.2f;
Adam Cohen61033d32010-11-15 18:29:44 -08002030 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002031 }
2032 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002033
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002034 /**
2035 * Zoom the camera out from the workspace to reveal 'toView'.
2036 * Assumes that the view to show is anchored at either the very top or very bottom
2037 * of the screen.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002038 * @param toState The state to zoom out to. Must be APPS_CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002039 */
Winson Chungc07918d2011-07-01 15:35:26 -07002040 private void cameraZoomOut(State toState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002041 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002042
Winson Chungf0ea4d32011-06-06 14:27:16 -07002043 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2044 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2045 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2046 final View toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002047
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002048 setPivotsForZoom(toView, toState, scale);
2049
Michael Jurkad74c9842011-07-10 12:44:21 -07002050 // Shrink workspaces away if going to AppsCustomize from workspace
2051 mWorkspace.shrink(Workspace.State.SMALL, animated);
Winson Chung4afe9b32011-07-27 17:46:20 -07002052 hideHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002053
2054 if (animated) {
Michael Jurkaabded662011-03-04 12:06:57 -08002055 final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
Michael Jurka742574b2011-02-02 23:51:01 -08002056 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002057 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2058 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002059 ((View) toView.getParent()).fastInvalidate();
Michael Jurka11148e52011-02-03 18:20:25 -08002060 toView.setFastScaleX(a * scale + b * 1f);
2061 toView.setFastScaleY(a * scale + b * 1f);
Michael Jurka742574b2011-02-02 23:51:01 -08002062 }
2063 });
Adam Cohen61033d32010-11-15 18:29:44 -08002064
Winson Chungf0ea4d32011-06-06 14:27:16 -07002065 toView.setVisibility(View.VISIBLE);
2066 toView.setFastAlpha(0f);
2067 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2068 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2069 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2070 public void onAnimationUpdate(float a, float b) {
2071 // don't need to invalidate because we do so above
2072 toView.setFastAlpha(a * 0f + b * 1f);
2073 }
2074 });
2075 alphaAnim.start();
Adam Cohenf16e5712011-01-13 13:31:45 -08002076
Michael Jurkaabded662011-03-04 12:06:57 -08002077 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002078 ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim, false);
Michael Jurkabfadaad2011-01-31 21:35:39 -08002079 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002080 scaleAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002081 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002082 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002083 // Prepare the position
2084 toView.setTranslationX(0.0f);
2085 toView.setTranslationY(0.0f);
2086 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002087 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002088 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002089 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002090 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002091 // If we don't set the final scale values here, if this animation is cancelled
2092 // it will have the wrong scale value and subsequent cameraPan animations will
2093 // not fix that
2094 toView.setScaleX(1.0f);
2095 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002096 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002097 ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002098 }
Winson Chung32174c82011-07-19 15:47:55 -07002099
2100 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2101 // Hide the workspace scrollbar
2102 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002103 mWorkspace.hideDockDivider(true);
Winson Chung32174c82011-07-19 15:47:55 -07002104 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002105 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002106 });
2107
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002108 // toView should appear right at the end of the workspace shrink animation
Adam Cohenf16e5712011-01-13 13:31:45 -08002109 final int startDelay = 0;
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002110
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002111 if (mStateAnimation != null) mStateAnimation.cancel();
2112 mStateAnimation = new AnimatorSet();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002113 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002114 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002115 } else {
2116 toView.setTranslationX(0.0f);
2117 toView.setTranslationY(0.0f);
2118 toView.setScaleX(1.0f);
2119 toView.setScaleY(1.0f);
2120 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002121 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002122 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002123 ((LauncherTransitionable) toView).onLauncherTransitionStart(null, false);
2124 ((LauncherTransitionable) toView).onLauncherTransitionEnd(null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002125
Winson Chungc07918d2011-07-01 15:35:26 -07002126 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2127 // Hide the workspace scrollbar
2128 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002129 mWorkspace.hideDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002130 }
Michael Jurkaabded662011-03-04 12:06:57 -08002131 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002132 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002133 }
2134
2135 /**
2136 * Zoom the camera back into the workspace, hiding 'fromView'.
2137 * This is the opposite of cameraZoomOut.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002138 * @param fromState The current state (must be APPS_CUSTOMIZE).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002139 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002140 */
Winson Chungc07918d2011-07-01 15:35:26 -07002141 private void cameraZoomIn(State fromState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002142 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002143
Winson Chungf0ea4d32011-06-06 14:27:16 -07002144 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2145 final float scaleFactor = (float)
2146 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2147 final View fromView = mAppsCustomizeTabHost;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002148
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002149 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002150
Michael Jurkad3ef3062010-11-23 16:23:58 -08002151 if (!springLoaded) {
2152 mWorkspace.unshrink(animated);
2153 }
Winson Chung4afe9b32011-07-27 17:46:20 -07002154 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002155 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002156 if (mStateAnimation != null) mStateAnimation.cancel();
2157 mStateAnimation = new AnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08002158
Michael Jurka742574b2011-02-02 23:51:01 -08002159 final float oldScaleX = fromView.getScaleX();
2160 final float oldScaleY = fromView.getScaleY();
2161
2162 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2163 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002164 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2165 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002166 ((View)fromView.getParent()).fastInvalidate();
2167 fromView.setFastScaleX(a * oldScaleX + b * scaleFactor);
2168 fromView.setFastScaleY(a * oldScaleY + b * scaleFactor);
2169 }
2170 });
Michael Jurkaabded662011-03-04 12:06:57 -08002171 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002172 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Michael Jurkaea573482011-02-03 19:48:18 -08002173 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Michael Jurkac2e26a02011-03-24 15:20:26 -07002174 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2175 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002176 // don't need to invalidate because we do so above
2177 fromView.setFastAlpha(a * 1f + b * 0f);
2178 }
2179 });
Michael Jurkaabded662011-03-04 12:06:57 -08002180 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002181 ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002182 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002183 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002184 @Override
Winson Chungbb6f6a52011-07-25 17:55:44 -07002185 public void onAnimationStart(android.animation.Animator animation) {
2186 if (!springLoaded) {
2187 mWorkspace.showDockDivider(false);
2188 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002189 mWorkspace.showScrollingIndicator(false);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002190 }
2191 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002192 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002193 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002194 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002195 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim,true);
Michael Jurka2763be32011-02-24 11:19:57 -08002196 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002197 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002198 }
2199 });
2200
Winson Chungf0ea4d32011-06-06 14:27:16 -07002201 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002202 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002203 } else {
2204 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002205 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002206 ((LauncherTransitionable) fromView).onLauncherTransitionStart(null, true);
2207 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null, true);
Winson Chung3ac74c52011-06-30 17:39:37 -07002208
Winson Chungc07918d2011-07-01 15:35:26 -07002209 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chungf5f8cef2011-07-22 11:16:13 -07002210 // Flash the workspace scrollbar
Winson Chungbb6f6a52011-07-25 17:55:44 -07002211 mWorkspace.showDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002212 mWorkspace.flashScrollingIndicator();
2213 }
Michael Jurkaabded662011-03-04 12:06:57 -08002214 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002215 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002216 }
2217
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002218 void showWorkspace(boolean animated) {
2219 showWorkspace(animated, null);
2220 }
2221
2222 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002223 if (layout != null) {
2224 // always animated, but that's ok since we never specify a layout and
2225 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002226 mWorkspace.unshrink(layout);
2227 } else {
2228 mWorkspace.unshrink(animated);
2229 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002230 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002231 closeAllApps(animated);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002232 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002233
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002234 // Change the state *after* we've called all the transition code
2235 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002236
Winson Chung5fb63472011-02-02 17:03:37 -08002237 // Resume the auto-advance of widgets
2238 mUserPresent = true;
2239 updateRunning();
2240
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002241 // send an accessibility event to announce the context change
2242 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002243 }
2244
Michael Jurkad3ef3062010-11-23 16:23:58 -08002245 void enterSpringLoadedDragMode(CellLayout layout) {
Winson Chungb26f3d62011-06-02 10:49:29 -07002246 if (mState == State.APPS_CUSTOMIZE) {
Winson Chungc07918d2011-07-01 15:35:26 -07002247 mWorkspace.enterSpringLoadedDragMode(layout);
Winson Chungb26f3d62011-06-02 10:49:29 -07002248 cameraZoomIn(State.APPS_CUSTOMIZE, true, true);
Winson Chungc07918d2011-07-01 15:35:26 -07002249 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002250 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002251 // Otherwise, we are not in spring loaded mode, so don't do anything.
Michael Jurkad3ef3062010-11-23 16:23:58 -08002252 }
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002253 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
Winson Chunge7a03942011-08-05 15:05:12 -07002254 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002255 @Override
2256 public void run() {
2257 exitSpringLoadedDragMode();
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002258
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002259 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002260 // Before we show workspace, hide all apps again because
2261 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2262 // clean up our state transition functions
2263 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002264 showWorkspace(true);
2265 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002266 }
2267 }, (extendedDelay ?
2268 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2269 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2270 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002271 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002272 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkad74c9842011-07-10 12:44:21 -07002273 mWorkspace.exitSpringLoadedDragMode(Workspace.State.SMALL);
Winson Chungb26f3d62011-06-02 10:49:29 -07002274 cameraZoomOut(State.APPS_CUSTOMIZE, true, true);
2275 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002276 }
2277 // Otherwise, we are not in spring loaded mode, so don't do anything.
2278 }
2279
Adam Cohenfc53cd22011-07-20 15:45:11 -07002280 public boolean isAllAppsCustomizeOpen() {
2281 return mState == State.APPS_CUSTOMIZE;
2282 }
2283
Winson Chungf0ea4d32011-06-06 14:27:16 -07002284 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002285 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002286 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002287 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002288 if (!LauncherApplication.isScreenLarge()) {
2289 if (animated) {
2290 int duration = mSearchDeleteBar.getTransitionInDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002291 mHotseat.animate().alpha(1f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002292 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002293 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002294 }
2295 }
2296 }
2297
2298 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002299 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002300 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002301 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002302 if (!LauncherApplication.isScreenLarge()) {
2303 if (animated) {
2304 int duration = mSearchDeleteBar.getTransitionOutDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002305 mHotseat.animate().alpha(0f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002306 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002307 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002308 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002309 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002310 }
2311
Winson Chung785d2eb2011-04-14 16:08:02 -07002312 void showAllApps(boolean animated) {
2313 if (mState != State.WORKSPACE) return;
Winson Chung785d2eb2011-04-14 16:08:02 -07002314
Winson Chungf0ea4d32011-06-06 14:27:16 -07002315 cameraZoomOut(State.APPS_CUSTOMIZE, animated, false);
2316 mAppsCustomizeTabHost.requestFocus();
Winson Chung785d2eb2011-04-14 16:08:02 -07002317
Winson Chung3d503fb2011-07-13 17:25:49 -07002318 // Hide the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002319 mSearchDeleteBar.hideSearchBar(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002320
Winson Chungf0ea4d32011-06-06 14:27:16 -07002321 // Change the state *after* we've called all the transition code
2322 mState = State.APPS_CUSTOMIZE;
Winson Chung785d2eb2011-04-14 16:08:02 -07002323
2324 // Pause the auto-advance of widgets until we are out of AllApps
2325 mUserPresent = false;
2326 updateRunning();
Adam Cohen2f84ef22011-07-26 17:16:44 -07002327 closeFolder();
Winson Chung785d2eb2011-04-14 16:08:02 -07002328
2329 // Send an accessibility event to announce the context change
2330 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2331 }
2332
Joe Onoratob2061212009-11-24 16:13:54 -05002333 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002334 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002335 * - Home from workspace
2336 * - from center screen
2337 * - from other screens
2338 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002339 * - from center screen
2340 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002341 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002342 * - from center screen
2343 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002344 * - Launch app from workspace and quit
2345 * - with back
2346 * - with home
2347 * - Launch app from all apps and quit
2348 * - with back
2349 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002350 * - Go to a screen that's not the default, then all
2351 * apps, and launch and app, and go back
2352 * - with back
2353 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002354 * - On workspace, long press power and go back
2355 * - with back
2356 * - with home
2357 * - On all apps, long press power and go back
2358 * - with back
2359 * - with home
2360 * - On workspace, power off
2361 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002362 * - Launch an app and turn off the screen while in that app
2363 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002364 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002365 * - From all apps
2366 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002367 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2368 * - From all apps
2369 * - From the center workspace
2370 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002371 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002372 void closeAllApps(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002373 if (mState == State.APPS_CUSTOMIZE || mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2374 mWorkspace.setVisibility(View.VISIBLE);
2375 cameraZoomIn(State.APPS_CUSTOMIZE, animated, false);
Winson Chung785d2eb2011-04-14 16:08:02 -07002376
Winson Chung3d503fb2011-07-13 17:25:49 -07002377 // Show the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002378 mSearchDeleteBar.showSearchBar(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002379
Winson Chungf0ea4d32011-06-06 14:27:16 -07002380 // Set focus to the AppsCustomize button
Winson Chung3d503fb2011-07-13 17:25:49 -07002381 if (mAllAppsButton != null) {
2382 mAllAppsButton.requestFocus();
2383 }
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002384 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002385 }
2386
Joe Onorato7c312c12009-08-13 21:36:53 -07002387 void lockAllApps() {
2388 // TODO
2389 }
2390
2391 void unlockAllApps() {
2392 // TODO
2393 }
2394
Patrick Dubroy5f445422011-02-18 14:35:21 -08002395 /**
2396 * Add an item from all apps or customize onto the given workspace screen.
2397 * If layout is null, add to the current screen.
2398 */
2399 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002400 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2401 showOutOfSpaceMessage();
Patrick Dubroy5f445422011-02-18 14:35:21 -08002402 } else {
2403 layout.animateDrop();
Michael Jurka213d9632010-07-28 11:29:25 -07002404 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002405 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002406
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002407 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002408 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002409 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002410 // Look for the toolbar icon specified in the activity meta-data
2411 Bundle metaData = packageManager.getActivityInfo(
2412 activityName, PackageManager.GET_META_DATA).metaData;
2413 if (metaData != null) {
2414 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2415 if (iconResId != 0) {
2416 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002417 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002418 }
2419 }
2420 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002421 // This can happen if the activity defines an invalid drawable
2422 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2423 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002424 } catch (Resources.NotFoundException nfe) {
2425 // This can happen if the activity defines an invalid drawable
2426 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2427 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002428 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002429 return null;
2430 }
2431
2432 // if successful in getting icon, return it; otherwise, set button to use default drawable
2433 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2434 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2435 TextView button = (TextView) findViewById(buttonId);
2436 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2437
2438 // If we were unable to find the icon via the meta-data, use a generic one
2439 if (toolbarIcon == null) {
2440 button.setCompoundDrawablesWithIntrinsicBounds(fallbackDrawableId, 0, 0, 0);
2441 return null;
2442 } else {
2443 button.setCompoundDrawablesWithIntrinsicBounds(toolbarIcon, null, null, null);
2444 return toolbarIcon.getConstantState();
2445 }
2446 }
2447
2448 // if successful in getting icon, return it; otherwise, set button to use default drawable
2449 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2450 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2451 ImageView button = (ImageView) findViewById(buttonId);
2452 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2453
Michael Jurka19e0fc52011-07-22 18:00:21 -07002454 if (button != null) {
2455 // If we were unable to find the icon via the meta-data, use a
2456 // generic one
2457 if (toolbarIcon == null) {
2458 button.setImageResource(fallbackDrawableId);
2459 } else {
2460 button.setImageDrawable(toolbarIcon);
2461 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002462 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002463
2464 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2465
Michael Jurka0423dcf2010-10-05 14:56:18 -07002466 }
2467
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002468 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2469 TextView button = (TextView) findViewById(buttonId);
2470 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2471 }
2472
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002473 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002474 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002475 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002476 }
2477
Michael Jurka0423dcf2010-10-05 14:56:18 -07002478 private void updateGlobalSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002479 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2480 final View searchDivider = findViewById(R.id.search_divider);
Winson Chung97d85d22011-04-13 11:27:36 -07002481
Winson Chung1cad91e2011-05-25 17:41:01 -07002482 final SearchManager searchManager =
2483 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2484 ComponentName activityName = searchManager.getGlobalSearchActivity();
2485 if (activityName != null) {
Mathew Inwood68524cd2011-07-01 13:59:38 +01002486 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002487 R.id.search_button, activityName, R.drawable.ic_search_normal_holo);
Winson Chung1cad91e2011-05-25 17:41:01 -07002488 searchButton.setVisibility(View.VISIBLE);
Winson Chung649723c2011-07-06 20:41:23 -07002489 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002490 } else {
2491 searchButton.setVisibility(View.GONE);
Winson Chung649723c2011-07-06 20:41:23 -07002492 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002493 }
2494 }
2495
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002496 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002497 updateButtonWithDrawable(R.id.search_button, d);
2498 }
2499
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002500 private void updateVoiceSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002501 final View searchDivider = findViewById(R.id.search_divider);
2502 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002503
Winson Chung1cad91e2011-05-25 17:41:01 -07002504 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2505 ComponentName activityName = intent.resolveActivity(getPackageManager());
2506 if (activityName != null) {
2507 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002508 R.id.voice_button, activityName, R.drawable.ic_voice_search_holo);
2509 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002510 voiceButton.setVisibility(View.VISIBLE);
2511 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002512 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002513 voiceButton.setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002514 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002515 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002516
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002517 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002518 updateButtonWithDrawable(R.id.voice_button, d);
2519 }
2520
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002521 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002522 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002523 */
2524 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002525 final View marketButton = findViewById(R.id.market_button);
2526 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2527 // Find the app market activity by resolving an intent.
2528 // (If multiple app markets are installed, it will return the ResolverActivity.)
2529 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002530 if (activityName != null) {
Winson Chung785d2eb2011-04-14 16:08:02 -07002531 mAppMarketIntent = intent;
2532 sAppMarketIcon = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002533 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002534 marketButton.setVisibility(View.VISIBLE);
2535 } else {
2536 // We should hide and disable the view so that we don't try and restore the visibility
2537 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2538 marketButton.setVisibility(View.GONE);
2539 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002540 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002541 }
2542
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002543 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002544 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002545 }
2546
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002547 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002548 * Displays the shortcut creation dialog and launches, if necessary, the
2549 * appropriate activity.
2550 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002551 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002552 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2553 DialogInterface.OnShowListener {
2554
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002555 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002556
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002558 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002559
Winson Chung55b65502011-05-26 12:03:43 -07002560 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2561 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002562 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002563
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002564 AlertDialog dialog = builder.create();
2565 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002566 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002567 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002568
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002569 return dialog;
2570 }
2571
2572 public void onCancel(DialogInterface dialog) {
2573 mWaitingForResult = false;
2574 cleanup();
2575 }
2576
Romain Guycbb89e42009-06-08 15:52:54 -07002577 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002578 mWaitingForResult = false;
2579 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002580 }
2581
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002582 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002583 try {
2584 dismissDialog(DIALOG_CREATE_SHORTCUT);
2585 } catch (Exception e) {
2586 // An exception is thrown if the dialog is not visible, which is fine
2587 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002588 }
2589
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002590 /**
2591 * Handle the action clicked in the "Add to home" dialog.
2592 */
2593 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002594 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002595
Winson Chung55b65502011-05-26 12:03:43 -07002596 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2597 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002598 case AddAdapter.ITEM_APPLICATION: {
2599 if (mAppsCustomizeTabHost != null) {
2600 mAppsCustomizeTabHost.selectAppsTab();
2601 }
2602 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002603 break;
2604 }
Winson Chung55b65502011-05-26 12:03:43 -07002605 case AddAdapter.ITEM_APPWIDGET: {
2606 if (mAppsCustomizeTabHost != null) {
2607 mAppsCustomizeTabHost.selectWidgetsTab();
2608 }
2609 showAllApps(true);
2610 break;
2611 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002612 case AddAdapter.ITEM_WALLPAPER: {
2613 startWallpaper();
2614 break;
2615 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002616 }
2617 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002618
2619 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002620 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002621 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002622 }
2623
2624 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002625 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002626 */
2627 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2628 @Override
2629 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002630 closeSystemDialogs();
2631 }
2632 }
2633
2634 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002635 * Receives notifications whenever the appwidgets are reset.
2636 */
2637 private class AppWidgetResetObserver extends ContentObserver {
2638 public AppWidgetResetObserver() {
2639 super(new Handler());
2640 }
2641
2642 @Override
2643 public void onChange(boolean selfChange) {
2644 onAppWidgetReset();
2645 }
2646 }
2647
2648 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002649 * If the activity is currently paused, signal that we need to re-run the loader
2650 * in onResume.
2651 *
2652 * This needs to be called from incoming places where resources might have been loaded
2653 * while we are paused. That is becaues the Configuration might be wrong
2654 * when we're not running, and if it comes back to what it was when we
2655 * were paused, we are not restarted.
2656 *
2657 * Implementation of the method from LauncherModel.Callbacks.
2658 *
2659 * @return true if we are currently paused. The caller might be able to
2660 * skip some work in that case since we will come back again.
2661 */
2662 public boolean setLoadOnResume() {
2663 if (mPaused) {
2664 Log.i(TAG, "setLoadOnResume");
2665 mOnResumeNeedsLoad = true;
2666 return true;
2667 } else {
2668 return false;
2669 }
2670 }
2671
2672 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002673 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002674 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002675 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002676 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002677 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002678 } else {
2679 return SCREEN_COUNT / 2;
2680 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002681 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002682
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002683
Joe Onorato9c1289c2009-08-17 11:03:03 -04002684 /**
2685 * Refreshes the shortcuts shown on the workspace.
2686 *
2687 * Implementation of the method from LauncherModel.Callbacks.
2688 */
2689 public void startBinding() {
2690 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002691
2692 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002693 int count = workspace.getChildCount();
2694 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002695 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002696 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2697 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002698 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002699 if (mHotseat != null) {
2700 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002701 }
Adam Cohenf5d77c92011-02-03 12:55:38 -08002702
Adam Cohen4eac29a2011-07-11 17:53:37 -07002703 // This wasn't being called before which resulted in a leak of AppWidgetHostViews
Winson Chung3d503fb2011-07-13 17:25:49 -07002704 unbindWorkspaceAndHotseatItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002705 }
2706
2707 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002708 * Bind the items start-end from the list.
2709 *
2710 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002711 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002712 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002713 setLoadOnResume();
2714
Joe Onorato9c1289c2009-08-17 11:03:03 -04002715 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002716 for (int i=start; i<end; i++) {
2717 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002718
2719 // Short circuit if we are loading dock items for a configuration which has no dock
2720 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2721 mHotseat == null) {
2722 continue;
2723 }
2724
Joe Onorato9c1289c2009-08-17 11:03:03 -04002725 switch (item.itemType) {
2726 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2727 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002728 View shortcut = createShortcut((ShortcutInfo)item);
2729 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
2730 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002731 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07002732 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07002733 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002734 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07002735 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07002736 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
2737 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002738 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002739 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002740 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002741 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002742 }
2743
Joe Onorato9c1289c2009-08-17 11:03:03 -04002744 /**
2745 * Implementation of the method from LauncherModel.Callbacks.
2746 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002747 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002748 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002749 sFolders.clear();
2750 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002751 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002752
2753 /**
2754 * Add the views for a widget to the workspace.
2755 *
2756 * Implementation of the method from LauncherModel.Callbacks.
2757 */
2758 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002759 setLoadOnResume();
2760
Daniel Sandler843e8602010-06-07 14:59:01 -04002761 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2762 if (DEBUG_WIDGETS) {
2763 Log.d(TAG, "bindAppWidget: " + item);
2764 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002765 final Workspace workspace = mWorkspace;
2766
2767 final int appWidgetId = item.appWidgetId;
2768 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002769 if (DEBUG_WIDGETS) {
2770 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2771 }
2772
Joe Onorato9c1289c2009-08-17 11:03:03 -04002773 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2774
Joe Onorato9c1289c2009-08-17 11:03:03 -04002775 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2776 item.hostView.setTag(item);
2777
Winson Chung3d503fb2011-07-13 17:25:49 -07002778 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04002779 item.cellY, item.spanX, item.spanY, false);
2780
Adam Cohended9f8d2010-11-03 13:25:16 -07002781 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
2782
Joe Onorato9c1289c2009-08-17 11:03:03 -04002783 workspace.requestLayout();
2784
Daniel Sandler843e8602010-06-07 14:59:01 -04002785 if (DEBUG_WIDGETS) {
2786 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2787 + (SystemClock.uptimeMillis()-start) + "ms");
2788 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002789 }
2790
2791 /**
2792 * Callback saying that there aren't any more items to bind.
2793 *
2794 * Implementation of the method from LauncherModel.Callbacks.
2795 */
2796 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002797 setLoadOnResume();
2798
Joe Onorato9c1289c2009-08-17 11:03:03 -04002799 if (mSavedState != null) {
2800 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002801 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002802 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002803 mSavedState = null;
2804 }
2805
2806 if (mSavedInstanceState != null) {
2807 super.onRestoreInstanceState(mSavedInstanceState);
2808 mSavedInstanceState = null;
2809 }
2810
Joe Onorato9c1289c2009-08-17 11:03:03 -04002811 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08002812
2813 // If we received the result of any pending adds while the loader was running (e.g. the
2814 // widget configuration forced an orientation change), process them now.
2815 for (int i = 0; i < sPendingAddList.size(); i++) {
2816 completeAdd(sPendingAddList.get(i));
2817 }
2818 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002819 }
2820
2821 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002822 * Updates the icons on the launcher that are affected by changes to the package list
2823 * on the device.
2824 */
2825 private void updateIconsAffectedByPackageManagerChanges() {
2826 updateAppMarketIcon();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002827 updateVoiceSearchIcon();
2828 }
2829
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002830 @Override
2831 public void bindSearchablesChanged() {
2832 updateGlobalSearchIcon();
2833 }
2834
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002835 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002836 * Add the icons for all apps.
2837 *
2838 * Implementation of the method from LauncherModel.Callbacks.
2839 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07002840 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
2841 // Remove the progress bar entirely; we could also make it GONE
2842 // but better to remove it since we know it's not going to be used
2843 View progressBar = mAppsCustomizeTabHost.
2844 findViewById(R.id.apps_customize_progress_bar);
2845 if (progressBar != null) {
2846 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07002847 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07002848 // We just post the call to setApps so the user sees the progress bar
2849 // disappear-- otherwise, it just looks like the progress bar froze
2850 // which doesn't look great
2851 mAppsCustomizeTabHost.post(new Runnable() {
2852 public void run() {
2853 if (mAppsCustomizeContent != null) {
2854 mAppsCustomizeContent.setApps(apps);
2855 }
2856 }
2857 });
2858
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002859 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002860 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002861 }
2862
2863 /**
2864 * A package was installed.
2865 *
2866 * Implementation of the method from LauncherModel.Callbacks.
2867 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002868 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002869 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002870 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002871
Winson Chung785d2eb2011-04-14 16:08:02 -07002872 if (mAppsCustomizeContent != null) {
2873 mAppsCustomizeContent.addApps(apps);
2874 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002875 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002876 }
2877
2878 /**
2879 * A package was updated.
2880 *
2881 * Implementation of the method from LauncherModel.Callbacks.
2882 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002883 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002884 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002885 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08002886 if (mWorkspace != null) {
2887 mWorkspace.updateShortcuts(apps);
2888 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002889
Winson Chung785d2eb2011-04-14 16:08:02 -07002890 if (mAppsCustomizeContent != null) {
2891 mAppsCustomizeContent.updateApps(apps);
2892 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002893 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002894 }
2895
2896 /**
2897 * A package was uninstalled.
2898 *
2899 * Implementation of the method from LauncherModel.Callbacks.
2900 */
Joe Onorato36115782010-06-17 13:28:48 -04002901 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002902 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04002903 if (permanent) {
2904 mWorkspace.removeItems(apps);
2905 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002906
Winson Chung785d2eb2011-04-14 16:08:02 -07002907 if (mAppsCustomizeContent != null) {
2908 mAppsCustomizeContent.removeApps(apps);
2909 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002910 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002911 }
Joe Onoratobe386092009-11-17 17:32:16 -08002912
2913 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07002914 * A number of packages were updated.
2915 */
2916 public void bindPackagesUpdated() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002917
Winson Chung785d2eb2011-04-14 16:08:02 -07002918 if (mAppsCustomizeContent != null) {
2919 mAppsCustomizeContent.onPackagesUpdated();
2920 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002921 }
2922
Winson Chung400438b2011-01-16 17:53:48 -08002923 private int mapConfigurationOriActivityInfoOri(int configOri) {
2924 final Display d = getWindowManager().getDefaultDisplay();
2925 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
2926 switch (d.getRotation()) {
2927 case Surface.ROTATION_0:
2928 case Surface.ROTATION_180:
2929 // We are currently in the same basic orientation as the natural orientation
2930 naturalOri = configOri;
2931 break;
2932 case Surface.ROTATION_90:
2933 case Surface.ROTATION_270:
2934 // We are currently in the other basic orientation to the natural orientation
2935 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
2936 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
2937 break;
2938 }
2939
2940 int[] oriMap = {
2941 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
2942 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
2943 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
2944 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
2945 };
2946 // Since the map starts at portrait, we need to offset if this device's natural orientation
2947 // is landscape.
2948 int indexOffset = 0;
2949 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
2950 indexOffset = 1;
2951 }
2952 return oriMap[(d.getRotation() + indexOffset) % 4];
2953 }
2954 public void lockScreenOrientation() {
2955 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
2956 .getConfiguration().orientation));
2957 }
2958 public void unlockScreenOrientation() {
2959 mHandler.postDelayed(new Runnable() {
2960 public void run() {
2961 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2962 }
2963 }, mRestoreScreenOrientationDelay);
2964 }
2965
Winson Chung82f55532011-08-09 14:14:23 -07002966 /* Cling related */
2967 private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling.workspace.dismissed";
2968 private static final String ALLAPPS_CLING_DISMISSED_KEY = "cling.allapps.dismissed";
2969 private void enableClingsIfNecessary() {
2970 // TEMPORARY: DISABLE CLINGS ON LARGE UI
2971 if (LauncherApplication.isScreenLarge()) return;
2972
2973 // Enable the clings only if they have not been dismissed before
2974 SharedPreferences prefs =
2975 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
2976 if (!prefs.getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false)) {
2977 Cling cling = (Cling) findViewById(R.id.workspace_cling);
2978 cling.init(this);
2979 cling.setVisibility(View.VISIBLE);
2980 }
2981 if (!prefs.getBoolean(ALLAPPS_CLING_DISMISSED_KEY, false)) {
2982 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
2983 cling.init(this);
2984 cling.setVisibility(View.VISIBLE);
2985 }
2986 }
2987 private void dismissCling(final Cling cling, final String flag) {
2988 if (cling != null) {
2989 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
2990 anim.setDuration(DISMISS_CLING_DURATION);
2991 anim.addListener(new AnimatorListenerAdapter() {
2992 public void onAnimationEnd(Animator animation) {
2993 cling.setVisibility(View.GONE);
2994 cling.cleanup();
2995 SharedPreferences prefs =
2996 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
2997 SharedPreferences.Editor editor = prefs.edit();
2998 editor.putBoolean(flag, true);
2999 editor.commit();
3000 };
3001 });
3002 anim.start();
3003 }
3004 }
3005 public void dismissWorkspaceCling(View v) {
3006 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3007 dismissCling(cling, WORKSPACE_CLING_DISMISSED_KEY);
3008 }
3009 public void dismissAllAppsCling(View v) {
3010 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
3011 dismissCling(cling, ALLAPPS_CLING_DISMISSED_KEY);
3012 }
3013
Winson Chung80baf5a2010-08-09 16:03:15 -07003014 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003015 * Prints out out state for debugging.
3016 */
3017 public void dumpState() {
3018 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003019 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003020 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3021 Log.d(TAG, "mRestoring=" + mRestoring);
3022 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3023 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003024 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003025 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003026
Winson Chung785d2eb2011-04-14 16:08:02 -07003027 if (mAppsCustomizeContent != null) {
3028 mAppsCustomizeContent.dumpState();
3029 }
Joe Onoratobe386092009-11-17 17:32:16 -08003030 Log.d(TAG, "END launcher2 dump state");
3031 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003032}
Michael Jurka2763be32011-02-24 11:19:57 -08003033
Michael Jurkaabded662011-03-04 12:06:57 -08003034interface LauncherTransitionable {
Winson Chung5a808352011-06-27 19:08:49 -07003035 void onLauncherTransitionStart(Animator animation, boolean toWorkspace);
3036 void onLauncherTransitionEnd(Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003037}