blob: 8e074b53fd9a4626772ba5480454ff32a2926853 [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;
Brett Chabot2a9e2282011-08-23 15:03:13 -070027import android.app.ActivityManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.app.Dialog;
30import android.app.SearchManager;
31import android.app.StatusBarManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070037import android.content.ClipData;
38import android.content.ClipDescription;
Michael Jurkae326f182011-11-21 14:05:46 -080039import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040040import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080041import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Context;
43import android.content.DialogInterface;
44import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070045import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070046import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070047import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070049import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080052import android.database.ContentObserver;
Michael Jurkaaf442092010-06-10 17:01:57 -070053import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070054import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040055import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070056import android.os.AsyncTask;
Adam Cohen50370f32011-08-25 18:57:14 -070057import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020059import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080060import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070061import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040062import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080063import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070064import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080065import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066import android.text.Selection;
67import android.text.SpannableStringBuilder;
68import android.text.TextUtils;
69import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070070import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080071import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080072import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.view.KeyEvent;
74import android.view.LayoutInflater;
75import android.view.Menu;
76import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070077import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080078import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080080import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070081import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080082import android.view.ViewTreeObserver;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070083import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080084import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070085import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070086import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080087import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070089import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070091import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070092import android.widget.TextView;
93import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070094
Adam Cohendf2cc412011-04-27 16:56:57 -070095import com.android.common.Search;
96import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070097import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080098
Adam Cohenc0dcf592011-06-01 15:30:43 -070099import java.io.DataInputStream;
100import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700101import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.FileNotFoundException;
103import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.util.ArrayList;
106import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108/**
109 * Default launcher application.
110 */
Michael Jurka946ad472010-07-09 18:05:18 -0700111public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700112 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
113 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800114 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700115 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
Joe Onorato9c1289c2009-08-17 11:03:03 -0400117 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400118 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700119
Winson Chung70d72102011-08-12 11:24:35 -0700120 private static final int MENU_GROUP_WALLPAPER = 1;
121 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
122 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700123 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
124 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
126 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700127 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 private static final int REQUEST_PICK_APPLICATION = 6;
129 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700130 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700131 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132
133 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
134
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800135 static final int SCREEN_COUNT = 5;
136 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137
Joe Onorato7c312c12009-08-13 21:36:53 -0700138 static final int DIALOG_CREATE_SHORTCUT = 1;
139 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
Romain Guy98d01652009-06-30 16:21:04 -0700141 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142
143 // Type: int
144 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700145 // Type: int
146 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700148 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
149 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
151 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700152 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700154 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 // Type: boolean
156 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
157 // Type: long
158 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
159
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700160 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
161
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700162 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700163 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700164 private State mState = State.WORKSPACE;
165 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800166 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700167
Joe Onorato9c1289c2009-08-17 11:03:03 -0400168 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700169 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
170 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700171 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700172 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800175 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800177 private final BroadcastReceiver mCloseSystemDialogsReceiver
178 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800179 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private LayoutInflater mInflater;
182
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800184 private View mQsbDivider;
185 private View mDockDivider;
186 private DragLayer mDragLayer;
187 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700188
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700189 private AppWidgetManager mAppWidgetManager;
190 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700191
Michael Jurkac9d95c52011-08-29 14:03:34 -0700192 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700193 private int[] mTmpAddItemCellCoordinates = new int[2];
194
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private FolderInfo mFolderInfo;
196
Winson Chung3d503fb2011-07-13 17:25:49 -0700197 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800198 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700199
Winson Chungc51db6a2011-10-05 11:44:49 -0700200 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700201 private AppsCustomizeTabHost mAppsCustomizeTabHost;
202 private AppsCustomizePagedView mAppsCustomizeContent;
203 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private Bundle mSavedState;
206
207 private SpannableStringBuilder mDefaultKeySsb = null;
208
Joe Onorato9c1289c2009-08-17 11:03:03 -0400209 private boolean mWorkspaceLoading = true;
210
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800211 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private boolean mRestoring;
213 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700214 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215
216 private Bundle mSavedInstanceState;
217
Joe Onorato9c1289c2009-08-17 11:03:03 -0400218 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800219 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800220 private boolean mUserPresent = true;
221 private boolean mVisible = false;
222 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400223
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700224 private static LocaleConfiguration sLocaleConfiguration = null;
225
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700226 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700227
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700228 private Intent mAppMarketIntent = null;
229
Adam Cohended9f8d2010-11-03 13:25:16 -0700230 // Related to the auto-advancing of widgets
231 private final int ADVANCE_MSG = 1;
232 private final int mAdvanceInterval = 20000;
233 private final int mAdvanceStagger = 250;
234 private long mAutoAdvanceSentTime;
235 private long mAutoAdvanceTimeLeft = -1;
236 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
237 new HashMap<View, AppWidgetProviderInfo>();
238
Winson Chung400438b2011-01-16 17:53:48 -0800239 // Determines how long to wait after a rotation before restoring the screen orientation to
240 // match the sensor state.
241 private final int mRestoreScreenOrientationDelay = 500;
242
Michael Jurka4ef207b2010-11-29 17:05:45 -0800243 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700244 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
245 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
246 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800247
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700248 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
249
Adam Cohen2801caf2011-05-13 20:57:39 -0700250
Michael Jurkaddd62e92011-02-16 17:49:14 -0800251 private BubbleTextView mWaitingForResume;
252
Michael Jurkac1f5d262011-09-30 19:32:27 -0700253 private Runnable mBuildLayersRunnable = new Runnable() {
254 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700255 if (mWorkspace != null) {
256 mWorkspace.buildPageHardwareLayers();
257 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700258 }
259 };
260
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800261 private static ArrayList<PendingAddArguments> sPendingAddList
262 = new ArrayList<PendingAddArguments>();
263
264 private static class PendingAddArguments {
265 int requestCode;
266 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700267 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800268 int screen;
269 int cellX;
270 int cellY;
271 }
272
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 @Override
274 protected void onCreate(Bundle savedInstanceState) {
275 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800276 LauncherApplication app = ((LauncherApplication)getApplication());
277 mModel = app.setLauncher(this);
278 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400279 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700281
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700282 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700283 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
284 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700285
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800286 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200287 android.os.Debug.startMethodTracing(
288 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289 }
290
291 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800292 setContentView(R.layout.launcher);
293 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700294 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800296 registerContentObservers();
297
Joe Onorato7c312c12009-08-13 21:36:53 -0700298 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700299
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300 mSavedState = savedInstanceState;
301 restoreState(mSavedState);
302
Winson Chunga12a2502010-12-20 14:41:35 -0800303 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700304 if (mAppsCustomizeContent != null) {
305 mAppsCustomizeContent.onPackagesUpdated();
306 }
Winson Chunga12a2502010-12-20 14:41:35 -0800307
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800308 if (PROFILE_STARTUP) {
309 android.os.Debug.stopMethodTracing();
310 }
311
312 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400313 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800314 }
315
Michael Jurkac57b7a82011-08-09 22:02:20 -0700316 if (!mModel.isAllAppsLoaded()) {
317 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
318 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
319 }
320
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 // For handling default keys
322 mDefaultKeySsb = new SpannableStringBuilder();
323 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800324
325 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
326 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800327
Winson Chungc51db6a2011-10-05 11:44:49 -0700328 boolean searchVisible = false;
329 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800330 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700331 int coi = getCurrentOrientationIndexForGlobalIcons();
332 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
333 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700334 updateAppMarketIcon();
335 searchVisible = updateGlobalSearchIcon();
336 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700337 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700338 if (sGlobalSearchIcon[coi] != null) {
339 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700340 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700341 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700342 if (sVoiceSearchIcon[coi] != null) {
343 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700344 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700345 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700346 if (sAppMarketIcon[coi] != null) {
347 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800348 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700349 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Adam Cohen446e9402011-09-15 18:21:21 -0700350
351 // On large interfaces, we want the screen to auto-rotate based on the current orientation
Adam Cohendc16b602011-09-26 15:12:33 -0700352 if (LauncherApplication.isScreenLarge() || Build.TYPE.contentEquals("eng")) {
Adam Cohen446e9402011-09-15 18:21:21 -0700353 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
354 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800355 }
Romain Guycbb89e42009-06-08 15:52:54 -0700356
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800357 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700358 if (sLocaleConfiguration == null) {
359 new AsyncTask<Void, Void, LocaleConfiguration>() {
360 @Override
361 protected LocaleConfiguration doInBackground(Void... unused) {
362 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
363 readConfiguration(Launcher.this, localeConfiguration);
364 return localeConfiguration;
365 }
366
367 @Override
368 protected void onPostExecute(LocaleConfiguration result) {
369 sLocaleConfiguration = result;
370 checkForLocaleChange(); // recursive, but now with a locale configuration
371 }
372 }.execute();
373 return;
374 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 final Configuration configuration = getResources().getConfiguration();
377
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700378 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 final String locale = configuration.locale.toString();
380
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700381 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 final int mcc = configuration.mcc;
383
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700384 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 final int mnc = configuration.mnc;
386
Romain Guy84f296c2009-11-04 15:00:44 -0800387 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388
Romain Guy84f296c2009-11-04 15:00:44 -0800389 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700390 sLocaleConfiguration.locale = locale;
391 sLocaleConfiguration.mcc = mcc;
392 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700393
Joe Onorato0589f0f2010-02-08 13:44:00 -0800394 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700395
396 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
397 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700398 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700399 public void run() {
400 writeConfiguration(Launcher.this, localeConfiguration);
401 }
402 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700403 }
404 }
405
406 private static class LocaleConfiguration {
407 public String locale;
408 public int mcc = -1;
409 public int mnc = -1;
410 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700411
Romain Guy98d01652009-06-30 16:21:04 -0700412 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
413 DataInputStream in = null;
414 try {
415 in = new DataInputStream(context.openFileInput(PREFERENCES));
416 configuration.locale = in.readUTF();
417 configuration.mcc = in.readInt();
418 configuration.mnc = in.readInt();
419 } catch (FileNotFoundException e) {
420 // Ignore
421 } catch (IOException e) {
422 // Ignore
423 } finally {
424 if (in != null) {
425 try {
426 in.close();
427 } catch (IOException e) {
428 // Ignore
429 }
430 }
431 }
432 }
433
434 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
435 DataOutputStream out = null;
436 try {
437 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
438 out.writeUTF(configuration.locale);
439 out.writeInt(configuration.mcc);
440 out.writeInt(configuration.mnc);
441 out.flush();
442 } catch (FileNotFoundException e) {
443 // Ignore
444 } catch (IOException e) {
445 //noinspection ResultOfMethodCallIgnored
446 context.getFileStreamPath(PREFERENCES).delete();
447 } finally {
448 if (out != null) {
449 try {
450 out.close();
451 } catch (IOException e) {
452 // Ignore
453 }
454 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 }
456 }
457
Adam Cohen716b51e2011-06-30 12:09:54 -0700458 public DragLayer getDragLayer() {
459 return mDragLayer;
460 }
461
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 static int getScreen() {
463 synchronized (sLock) {
464 return sScreen;
465 }
466 }
467
468 static void setScreen(int screen) {
469 synchronized (sLock) {
470 sScreen = screen;
471 }
472 }
473
Winson Chung557d6ed2011-07-08 15:34:52 -0700474 /**
475 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
476 * a configuration step, this allows the proper animations to run after other transitions.
477 */
478 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700479 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800480 switch (args.requestCode) {
481 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700482 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
483 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800484 break;
485 case REQUEST_PICK_SHORTCUT:
486 processShortcut(args.intent);
487 break;
488 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700489 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
490 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700491 result = true;
492 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800493 case REQUEST_PICK_APPWIDGET:
494 addAppWidgetFromPick(args.intent);
495 break;
496 case REQUEST_CREATE_APPWIDGET:
497 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Winson Chung3d503fb2011-07-13 17:25:49 -0700498 completeAddAppWidget(appWidgetId, args.container, args.screen);
Winson Chungb8472bb2011-08-05 13:49:21 -0700499 result = true;
500 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800501 case REQUEST_PICK_WALLPAPER:
502 // We just wanted the activity result here so we can clear mWaitingForResult
503 break;
504 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700505 // In any situation where we have a multi-step drop, we should reset the add info only after
506 // we complete the drop
507 resetAddInfo();
508 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800509 }
510
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800511 @Override
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800512 protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700513 boolean delayExitSpringLoadedMode = false;
Romain Guyaad5ef42009-06-10 02:48:37 -0700514 mWaitingForResult = false;
515
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800516 // The pattern used here is that a user PICKs a specific application,
517 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700518
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800519 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
520 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700521 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800522 final PendingAddArguments args = new PendingAddArguments();
523 args.requestCode = requestCode;
524 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700525 args.container = mPendingAddInfo.container;
526 args.screen = mPendingAddInfo.screen;
527 args.cellX = mPendingAddInfo.cellX;
528 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800529
530 // If the loader is still running, defer the add until it is done.
531 if (isWorkspaceLocked()) {
532 sPendingAddList.add(args);
533 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700534 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800535 }
Romain Guy18042c82009-11-06 11:44:55 -0800536 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
Winson Chung557d6ed2011-07-08 15:34:52 -0700537 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED) {
538 if (data != null) {
539 // Clean up the appWidgetId if we canceled
540 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
541 if (appWidgetId != -1) {
542 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
543 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800544 }
545 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700546
547 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700548 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800549 }
550
551 @Override
552 protected void onResume() {
553 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800554 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700555 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400556 mWorkspaceLoading = true;
557 mModel.startLoader(this, true);
558 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700559 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800560 }
Michael Jurkaddd62e92011-02-16 17:49:14 -0800561 if (mWaitingForResume != null) {
562 mWaitingForResume.setStayPressed(false);
563 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700564 // When we resume Launcher, a different Activity might be responsible for the app
565 // market intent, so refresh the icon
566 updateAppMarketIcon();
Michael Jurkae326f182011-11-21 14:05:46 -0800567 mAppsCustomizeTabHost.onResume();
Michael Jurkac1f5d262011-09-30 19:32:27 -0700568 if (!mWorkspaceLoading) {
Michael Jurkab737ee62011-11-15 15:57:22 -0800569 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
570 final Workspace workspace = mWorkspace;
571 // We want to let Launcher draw itself at least once before we force it to build
572 // layers on all the workspace pages, so that transitioning to Launcher from other
573 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
574 // a true draw so we wait until the second preDraw call to be safe
575 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
576 boolean mFirstTime = true;
577 public boolean onPreDraw() {
578 if (mFirstTime) {
579 mFirstTime = false;
580 } else {
Dianne Hackborn98b69dc2012-02-15 18:29:29 -0800581 // We delay the layer building a bit in order to give
582 // other message processing a time to run. In particular
583 // this avoids a delay in hiding the IME if it was
584 // currently shown, because doing that may involve
585 // some communication back with the app.
586 workspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkab737ee62011-11-15 15:57:22 -0800587 observer.removeOnPreDrawListener(this);
588 }
589 return true;
590 }
591 });
Michael Jurkac1f5d262011-09-30 19:32:27 -0700592 }
Mathew Inwood8193f692011-10-12 17:30:58 +0100593 clearTypedText();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800594 }
595
596 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700597 protected void onPause() {
598 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700599 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800600 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700601 }
Romain Guycbb89e42009-06-08 15:52:54 -0700602
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700603 @Override
604 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400605 // Flag the loader to stop early before switching
606 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700607 if (mAppsCustomizeContent != null) {
608 mAppsCustomizeContent.surrender();
609 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800610 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700611 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700612
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800613 // We can't hide the IME if it was forced open. So don't bother
614 /*
615 @Override
616 public void onWindowFocusChanged(boolean hasFocus) {
617 super.onWindowFocusChanged(hasFocus);
618
619 if (hasFocus) {
620 final InputMethodManager inputManager = (InputMethodManager)
621 getSystemService(Context.INPUT_METHOD_SERVICE);
622 WindowManager.LayoutParams lp = getWindow().getAttributes();
623 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
624 android.os.Handler()) {
625 protected void onReceiveResult(int resultCode, Bundle resultData) {
626 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
627 }
628 });
629 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
630 }
631 }
632 */
633
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800634 private boolean acceptFilter() {
635 final InputMethodManager inputManager = (InputMethodManager)
636 getSystemService(Context.INPUT_METHOD_SERVICE);
637 return !inputManager.isFullscreenMode();
638 }
639
640 @Override
641 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700642 final int uniChar = event.getUnicodeChar();
643 final boolean handled = super.onKeyDown(keyCode, event);
644 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
645 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800646 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
647 keyCode, event);
648 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700649 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700650 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700651 // showSearchDialog()
652 // If there are multiple keystrokes before the search dialog takes focus,
653 // onSearchRequested() will be called for every keystroke,
654 // but it is idempotent, so it's fine.
655 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800656 }
657 }
658
Joe Onorato8a9625e2010-01-28 15:55:35 -0800659 // Eat the long press event so the keyboard doesn't come up.
660 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
661 return true;
662 }
663
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800664 return handled;
665 }
666
Karl Rosaen138a0412009-04-23 19:00:21 -0700667 private String getTypedText() {
668 return mDefaultKeySsb.toString();
669 }
670
671 private void clearTypedText() {
672 mDefaultKeySsb.clear();
673 mDefaultKeySsb.clearSpans();
674 Selection.setSelection(mDefaultKeySsb, 0);
675 }
676
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800677 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700678 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
679 * State
680 */
681 private static State intToState(int stateOrdinal) {
682 State state = State.WORKSPACE;
683 final State[] stateValues = State.values();
684 for (int i = 0; i < stateValues.length; i++) {
685 if (stateValues[i].ordinal() == stateOrdinal) {
686 state = stateValues[i];
687 break;
688 }
689 }
690 return state;
691 }
692
693 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694 * Restores the previous state, if it exists.
695 *
696 * @param savedState The previous state.
697 */
698 private void restoreState(Bundle savedState) {
699 if (savedState == null) {
700 return;
701 }
702
Michael Jurka883f55b2010-10-21 15:47:14 -0700703 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700704 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800705 showAllApps(false);
706 }
707
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800708 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
709 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700710 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800711 }
712
Winson Chung3d503fb2011-07-13 17:25:49 -0700713 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
714 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700715
Winson Chung3d503fb2011-07-13 17:25:49 -0700716 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
717 mPendingAddInfo.container = pendingAddContainer;
718 mPendingAddInfo.screen = pendingAddScreen;
719 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
720 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800721 mRestoring = true;
722 }
723
724 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
725 if (renameFolder) {
726 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700727 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800728 mRestoring = true;
729 }
Winson Chunga12a2502010-12-20 14:41:35 -0800730
Winson Chung785d2eb2011-04-14 16:08:02 -0700731
732 // Restore the AppsCustomize tab
733 if (mAppsCustomizeTabHost != null) {
734 String curTab = savedState.getString("apps_customize_currentTab");
735 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700736 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700737 mAppsCustomizeContent.setContentType(
738 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
739 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700740 mAppsCustomizeContent.loadAssociatedPages(
741 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700742 }
743
Winson Chung5afbf7b2011-07-25 11:53:08 -0700744 int currentIndex = savedState.getInt("apps_customize_currentIndex");
745 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700746 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800747 }
748
749 /**
750 * Finds all the views we need and configure them properly.
751 */
752 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700753 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400754
Winson Chung4c98d922011-05-31 16:50:48 -0700755 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
756 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800757 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
758 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800759
Winson Chung4c98d922011-05-31 16:50:48 -0700760 // Setup the drag layer
761 mDragLayer.setup(this, dragController);
762
Winson Chung3d503fb2011-07-13 17:25:49 -0700763 // Setup the hotseat
764 mHotseat = (Hotseat) findViewById(R.id.hotseat);
765 if (mHotseat != null) {
766 mHotseat.setup(this);
767 }
768
Winson Chung4c98d922011-05-31 16:50:48 -0700769 // Setup the workspace
770 mWorkspace.setHapticFeedbackEnabled(false);
771 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700772 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700773 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700774
Winson Chungf0ea4d32011-06-06 14:27:16 -0700775 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700776 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700777
Winson Chungf0ea4d32011-06-06 14:27:16 -0700778 // Setup AppsCustomize
779 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
780 findViewById(R.id.apps_customize_pane);
781 mAppsCustomizeContent = (AppsCustomizePagedView)
782 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
783 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400784
Michael Jurka5130e402011-10-13 04:55:35 -0700785 // Get the all apps button
786 mAllAppsButton = findViewById(R.id.all_apps_button);
787 if (mAllAppsButton != null) {
788 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
789 @Override
790 public boolean onTouch(View v, MotionEvent event) {
791 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
792 onTouchDownAllAppsButton(v);
793 }
794 return false;
795 }
796 });
797 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700798 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700799 dragController.setDragScoller(mWorkspace);
800 dragController.setScrollView(mDragLayer);
801 dragController.setMoveTarget(mWorkspace);
802 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700803 if (mSearchDropTargetBar != null) {
804 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800805 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800806 }
807
808 /**
809 * Creates a view representing a shortcut.
810 *
811 * @param info The data structure describing the shortcut.
812 *
813 * @return A View inflated from R.layout.application.
814 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800815 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800816 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700817 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800818 }
819
820 /**
821 * Creates a view representing a shortcut inflated from the specified resource.
822 *
823 * @param layoutResId The id of the XML layout used to create the shortcut.
824 * @param parent The group the shortcut belongs to.
825 * @param info The data structure describing the shortcut.
826 *
827 * @return A View inflated from layoutResId.
828 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800829 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800830 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
831 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800832 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800833 return favorite;
834 }
835
836 /**
837 * Add an application shortcut to the workspace.
838 *
839 * @param data The intent describing the application.
840 * @param cellInfo The position on screen where to create the shortcut.
841 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700842 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700843 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700844 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700845
Adam Cohenfbba09b2011-07-18 21:43:05 -0700846 // First we check if we already know the exact location where we want to add this item.
847 if (cellX >= 0 && cellY >= 0) {
848 cellXY[0] = cellX;
849 cellXY[1] = cellY;
850 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700851 showOutOfSpaceMessage();
852 return;
853 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800855 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800856
Romain Guy73b979d2009-06-09 12:57:21 -0700857 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800858 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800859 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800860 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700861 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700862 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800863 } else {
864 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865 }
866 }
Romain Guycbb89e42009-06-08 15:52:54 -0700867
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 /**
869 * Add a shortcut to the workspace.
870 *
871 * @param data The intent describing the shortcut.
872 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800873 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700874 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
875 int cellY) {
876 int[] cellXY = mTmpAddItemCellCoordinates;
877 int[] touchXY = mPendingAddInfo.dropPos;
878 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700879
Michael Jurkad3ef3062010-11-23 16:23:58 -0800880 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700881
Adam Cohen558baaf2011-08-15 15:22:57 -0700882 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800883 if (info == null) {
884 return;
885 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700886 final View view = createShortcut(info);
887
Adam Cohenfbba09b2011-07-18 21:43:05 -0700888 // First we check if we already know the exact location where we want to add this item.
889 if (cellX >= 0 && cellY >= 0) {
890 cellXY[0] = cellX;
891 cellXY[1] = cellY;
892 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700893
894 // If appropriate, either create a folder or add to an existing folder
895 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
896 true, null,null)) {
897 return;
898 }
899 DragObject dragObject = new DragObject();
900 dragObject.dragInfo = info;
901 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
902 return;
903 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700904 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800905 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700906 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800907 foundCellSpan = (result != null);
908 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700909 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800910 }
911
912 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700913 showOutOfSpaceMessage();
914 return;
915 }
916
Adam Cohen558baaf2011-08-15 15:22:57 -0700917 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800918
919 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700920 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
921 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922 }
923 }
924
Adam Cohenf814aa02011-09-01 13:48:05 -0700925 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
926 if (spanXY == null) {
927 spanXY = new int[2];
928 }
929
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800930 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700931 // We want to account for the extra amount of padding that we are adding to the widget
932 // to ensure that it gets the full amount of space that it has requested
933 int requiredWidth = minWidth + padding.left + padding.right;
934 int requiredHeight = minHeight + padding.top + padding.bottom;
935 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
936 }
937
938 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
939 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
940 }
941
Adam Cohencbf47e32011-09-16 17:32:37 -0700942 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
943 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
944 }
945
Adam Cohenf814aa02011-09-01 13:48:05 -0700946 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
947 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
948 }
949
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700951 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800952 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700953 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700954 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800955 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700956 private void completeAddAppWidget(final int appWidgetId, long container, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700957 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700958
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700959 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700960 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700961
Adam Cohenf814aa02011-09-01 13:48:05 -0700962 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700963
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800964 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700965 // We have saved the position to which the widget was dragged-- this really only matters
966 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700967 int[] cellXY = mTmpAddItemCellCoordinates;
968 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700969 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700970 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
971 cellXY[0] = mPendingAddInfo.cellX;
972 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700973 foundCellSpan = true;
974 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700975 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700976 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700977 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800978 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700979 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700980 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700981 }
982
Michael Jurka0280c3b2010-09-17 15:00:07 -0700983 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -0800984 if (appWidgetId != -1) {
985 // Deleting an app widget ID is a void call but writes to disk before returning
986 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -0800987 new Thread("deleteAppWidgetId") {
988 public void run() {
989 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
990 }
991 }.start();
992 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700993 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -0800994 return;
995 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800996
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700997 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -0700998 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700999 launcherInfo.spanX = spanXY[0];
1000 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001002 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001003 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001004
1005 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001006 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001007 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001008
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001009 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001011
Winson Chung3d503fb2011-07-13 17:25:49 -07001012 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001013 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001014
1015 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001016 }
1017 }
Romain Guycbb89e42009-06-08 15:52:54 -07001018
Adam Cohended9f8d2010-11-03 13:25:16 -07001019 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1020 @Override
1021 public void onReceive(Context context, Intent intent) {
1022 final String action = intent.getAction();
1023 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1024 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001025 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001026 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001027
Winson Chungc100e8e2011-08-09 16:02:43 -07001028 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001029 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001030 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1031 mAppsCustomizeTabHost.reset();
1032 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001033 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001034 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1035 mUserPresent = true;
1036 updateRunning();
1037 }
1038 }
1039 };
1040
1041 @Override
1042 public void onAttachedToWindow() {
1043 super.onAttachedToWindow();
1044
1045 // Listen for broadcasts related to user-presence
1046 final IntentFilter filter = new IntentFilter();
1047 filter.addAction(Intent.ACTION_SCREEN_OFF);
1048 filter.addAction(Intent.ACTION_USER_PRESENT);
1049 registerReceiver(mReceiver, filter);
1050
Adam Cohend113e0c2010-11-11 10:48:05 -08001051 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001052 mVisible = true;
1053 }
1054
1055 @Override
1056 public void onDetachedFromWindow() {
1057 super.onDetachedFromWindow();
1058 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001059 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001060
Adam Cohend113e0c2010-11-11 10:48:05 -08001061 if (mAttached) {
1062 unregisterReceiver(mReceiver);
1063 mAttached = false;
1064 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001065 updateRunning();
1066 }
1067
1068 public void onWindowVisibilityChanged(int visibility) {
1069 mVisible = visibility == View.VISIBLE;
1070 updateRunning();
1071 }
1072
1073 private void sendAdvanceMessage(long delay) {
1074 mHandler.removeMessages(ADVANCE_MSG);
1075 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1076 mHandler.sendMessageDelayed(msg, delay);
1077 mAutoAdvanceSentTime = System.currentTimeMillis();
1078 }
1079
1080 private void updateRunning() {
1081 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1082 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1083 mAutoAdvanceRunning = autoAdvanceRunning;
1084 if (autoAdvanceRunning) {
1085 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1086 sendAdvanceMessage(delay);
1087 } else {
1088 if (!mWidgetsToAdvance.isEmpty()) {
1089 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1090 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1091 }
1092 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001093 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001094 }
1095 }
1096 }
1097
1098 private final Handler mHandler = new Handler() {
1099 @Override
1100 public void handleMessage(Message msg) {
1101 if (msg.what == ADVANCE_MSG) {
1102 int i = 0;
1103 for (View key: mWidgetsToAdvance.keySet()) {
1104 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1105 final int delay = mAdvanceStagger * i;
1106 if (v instanceof Advanceable) {
1107 postDelayed(new Runnable() {
1108 public void run() {
1109 ((Advanceable) v).advance();
1110 }
1111 }, delay);
1112 }
1113 i++;
1114 }
1115 sendAdvanceMessage(mAdvanceInterval);
1116 }
1117 }
1118 };
1119
1120 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001121 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001122 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1123 if (v instanceof Advanceable) {
1124 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001125 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001126 updateRunning();
1127 }
1128 }
1129
1130 void removeWidgetToAutoAdvance(View hostView) {
1131 if (mWidgetsToAdvance.containsKey(hostView)) {
1132 mWidgetsToAdvance.remove(hostView);
1133 updateRunning();
1134 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001135 }
1136
Joe Onorato9c1289c2009-08-17 11:03:03 -04001137 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001138 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001139 launcherInfo.hostView = null;
1140 }
1141
Adam Cohended9f8d2010-11-03 13:25:16 -07001142 void showOutOfSpaceMessage() {
1143 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1144 }
1145
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001146 public LauncherAppWidgetHost getAppWidgetHost() {
1147 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001148 }
Romain Guycbb89e42009-06-08 15:52:54 -07001149
Winson Chunga9abd0e2010-10-27 17:18:37 -07001150 public LauncherModel getModel() {
1151 return mModel;
1152 }
1153
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001154 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001155 getWindow().closeAllPanels();
1156
Winson Chung87acb482011-08-23 17:28:05 -07001157 /**
1158 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001159 try {
1160 dismissDialog(DIALOG_CREATE_SHORTCUT);
1161 // Unlock the workspace if the dialog was showing
1162 } catch (Exception e) {
1163 // An exception is thrown if the dialog is not visible, which is fine
1164 }
1165
1166 try {
1167 dismissDialog(DIALOG_RENAME_FOLDER);
1168 // Unlock the workspace if the dialog was showing
1169 } catch (Exception e) {
1170 // An exception is thrown if the dialog is not visible, which is fine
1171 }
Winson Chung87acb482011-08-23 17:28:05 -07001172 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001173
1174 // Whatever we were doing is hereby canceled.
1175 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001176 }
1177
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001178 @Override
1179 protected void onNewIntent(Intent intent) {
1180 super.onNewIntent(intent);
1181
1182 // Close the menu
1183 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001184 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001185 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001186
Joe Onorato14f122b2009-11-19 14:06:36 -08001187 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1188 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001189
Adam Cohenac56cff2011-09-28 20:45:37 -07001190 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001191 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001192 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001193 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1194 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001195 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001196 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001197
1198 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001199 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001200 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001201
Joe Onorato3a8820b2009-11-10 15:06:42 -08001202 final View v = getWindow().peekDecorView();
1203 if (v != null && v.getWindowToken() != null) {
1204 InputMethodManager imm = (InputMethodManager)getSystemService(
1205 INPUT_METHOD_SERVICE);
1206 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001207 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001208
Michael Jurka35aa14d2011-07-07 17:01:08 -07001209 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001210 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001211 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001212 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213 }
1214 }
1215
1216 @Override
1217 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1218 // Do not call super here
1219 mSavedInstanceState = savedInstanceState;
1220 }
1221
1222 @Override
1223 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001224 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001225 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226
Michael Jurka883f55b2010-10-21 15:47:14 -07001227 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001228 // We close any open folder since it will not be re-opened, and we need to make sure
1229 // this state is reflected.
1230 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001231
Winson Chung3d503fb2011-07-13 17:25:49 -07001232 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1233 mWaitingForResult) {
1234 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1235 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1236 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1237 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001238 }
1239
1240 if (mFolderInfo != null && mWaitingForResult) {
1241 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1242 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1243 }
Michael Jurka946ad472010-07-09 18:05:18 -07001244
Winson Chung785d2eb2011-04-14 16:08:02 -07001245 // Save the current AppsCustomize tab
1246 if (mAppsCustomizeTabHost != null) {
1247 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1248 if (currentTabTag != null) {
1249 outState.putString("apps_customize_currentTab", currentTabTag);
1250 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001251 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1252 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001253 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254 }
1255
1256 @Override
1257 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001259
Winson Chunge7a03942011-08-05 15:05:12 -07001260 // Remove all pending runnables
1261 mHandler.removeMessages(ADVANCE_MSG);
1262 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001263 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001264
Winson Chungcd2b0142011-06-08 16:02:26 -07001265 // Stop callbacks from LauncherModel
1266 LauncherApplication app = ((LauncherApplication) getApplication());
1267 mModel.stopLoader();
1268 app.setLauncher(null);
1269
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001270 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001271 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001273 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001274 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001275 mAppWidgetHost = null;
1276
1277 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001278
1279 TextKeyListener.getInstance().release();
1280
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001281
Winson Chung3d503fb2011-07-13 17:25:49 -07001282 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001283
1284 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001285 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001286
1287 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1288 mWorkspace.removeAllViews();
1289 mWorkspace = null;
1290 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001291
1292 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001293 }
1294
Adam Cohena9cf38f2011-05-02 15:36:58 -07001295 public DragController getDragController() {
1296 return mDragController;
1297 }
1298
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001299 @Override
1300 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001301 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001302 super.startActivityForResult(intent, requestCode);
1303 }
1304
Winson Chung70d72102011-08-12 11:24:35 -07001305 /**
1306 * Indicates that we want global search for this activity by setting the globalSearch
1307 * argument for {@link #startSearch} to true.
1308 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001310 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001311 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001312
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001313 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001314
Karl Rosaen138a0412009-04-23 19:00:21 -07001315 if (initialQuery == null) {
1316 // Use any text typed in the launcher as the initial query
1317 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001318 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 if (appSearchData == null) {
1320 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001321 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001323 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001324
Karl Rosaen138a0412009-04-23 19:00:21 -07001325 final SearchManager searchManager =
1326 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001327 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001328 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329 }
1330
Winson Chung70d72102011-08-12 11:24:35 -07001331 @Override
1332 public boolean onCreateOptionsMenu(Menu menu) {
1333 if (isWorkspaceLocked()) {
1334 return false;
1335 }
1336
1337 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001338
1339 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1340 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1341 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001342 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1343 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1344 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001345 String helpUrl = getString(R.string.help_url);
1346 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001347 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1348 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1349
Winson Chung70d72102011-08-12 11:24:35 -07001350 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1351 .setIcon(android.R.drawable.ic_menu_gallery)
1352 .setAlphabeticShortcut('W');
1353 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1354 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001355 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001356 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001357 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1358 .setIcon(android.R.drawable.ic_menu_preferences)
1359 .setIntent(settings)
1360 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001361 if (!helpUrl.isEmpty()) {
1362 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1363 .setIcon(android.R.drawable.ic_menu_help)
1364 .setIntent(help)
1365 .setAlphabeticShortcut('H');
1366 }
Winson Chung70d72102011-08-12 11:24:35 -07001367 return true;
1368 }
1369
1370 @Override
1371 public boolean onPrepareOptionsMenu(Menu menu) {
1372 super.onPrepareOptionsMenu(menu);
1373
1374 if (mAppsCustomizeTabHost.isTransitioning()) {
1375 return false;
1376 }
1377 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1378 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1379
1380 return true;
1381 }
1382
1383 @Override
1384 public boolean onOptionsItemSelected(MenuItem item) {
1385 switch (item.getItemId()) {
1386 case MENU_WALLPAPER_SETTINGS:
1387 startWallpaper();
1388 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001389 }
1390
1391 return super.onOptionsItemSelected(item);
1392 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001393
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001394 @Override
1395 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001396 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001397 // Use a custom animation for launching search
1398 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001399 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001400 }
1401
Joe Onorato9c1289c2009-08-17 11:03:03 -04001402 public boolean isWorkspaceLocked() {
1403 return mWorkspaceLoading || mWaitingForResult;
1404 }
1405
Michael Jurka0280c3b2010-09-17 15:00:07 -07001406 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001407 mPendingAddInfo.container = ItemInfo.NO_ID;
1408 mPendingAddInfo.screen = -1;
1409 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1410 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1411 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001412 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001413
Michael Jurkaaf442092010-06-10 17:01:57 -07001414 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001415 // TODO: catch bad widget exception when sent
1416 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001417 // TODO: Is this log message meaningful?
1418 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001419 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001420 }
1421
Winson Chung55cef262010-10-28 14:14:18 -07001422 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001423 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424
Bjorn Bringert7984c942009-12-09 15:38:25 +00001425 if (appWidget.configure != null) {
1426 // Launch over to configure widget, if needed
1427 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1428 intent.setComponent(appWidget.configure);
1429 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001430 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001431 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1432 intent.putExtra(
1433 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1434 info.mimeType);
1435
1436 final String mimeType = info.mimeType;
1437 final ClipData clipData = (ClipData) info.configurationData;
1438 final ClipDescription clipDesc = clipData.getDescription();
1439 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1440 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001441 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001442 final CharSequence stringData = item.getText();
1443 final Uri uriData = item.getUri();
1444 final Intent intentData = item.getIntent();
1445 final String key =
1446 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1447 if (uriData != null) {
1448 intent.putExtra(key, uriData);
1449 } else if (intentData != null) {
1450 intent.putExtra(key, intentData);
1451 } else if (stringData != null) {
1452 intent.putExtra(key, stringData);
1453 }
1454 break;
1455 }
1456 }
1457 }
Winson Chung55cef262010-10-28 14:14:18 -07001458 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001459
Romain Guy8e633c52010-03-04 12:51:36 -08001460 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001462 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001463 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001464
1465 // Exit spring loaded mode if necessary after adding the widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001466 exitSpringLoadedDragModeDelayed(true, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001467 }
1468 }
Romain Guycbb89e42009-06-08 15:52:54 -07001469
Adam Cohenfbba09b2011-07-18 21:43:05 -07001470 /**
1471 * Process a shortcut drop.
1472 *
1473 * @param componentName The name of the component
1474 * @param screen The screen where it should be added
1475 * @param cell The cell it should be added to, optional
1476 * @param position The location on the screen where it was dropped, optional
1477 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001478 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1479 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001480 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001481 mPendingAddInfo.container = container;
1482 mPendingAddInfo.screen = screen;
1483 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001484
1485 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001486 mPendingAddInfo.cellX = cell[0];
1487 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001488 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001489
1490 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1491 createShortcutIntent.setComponent(componentName);
1492 processShortcut(createShortcutIntent);
1493 }
1494
Adam Cohenfbba09b2011-07-18 21:43:05 -07001495 /**
1496 * Process a widget drop.
1497 *
1498 * @param info The PendingAppWidgetInfo of the widget being added.
1499 * @param screen The screen where it should be added
1500 * @param cell The cell it should be added to, optional
1501 * @param position The location on the screen where it was dropped, optional
1502 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001503 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1504 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001505 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001506 mPendingAddInfo.container = info.container = container;
1507 mPendingAddInfo.screen = info.screen = screen;
1508 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001509 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001510 mPendingAddInfo.cellX = cell[0];
1511 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001512 }
1513
1514 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1515 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1516 addAppWidgetImpl(appWidgetId, info);
1517 }
1518
Joe Onoratodeb98af2010-02-19 14:59:39 -08001519 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001520 // Handle case where user selected "Applications"
1521 String applicationName = getResources().getString(R.string.group_applications);
1522 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001523
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001524 if (applicationName != null && applicationName.equals(shortcutName)) {
1525 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1526 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001527
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001528 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1529 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001530 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001531 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001532 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001533 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001534 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001535 }
1536
Winson Chung24ab2f12010-09-16 14:10:47 -07001537 void processWallpaper(Intent intent) {
1538 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1539 }
1540
Winson Chung3d503fb2011-07-13 17:25:49 -07001541 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1542 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001543 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 folderInfo.title = getText(R.string.folder_name);
1545
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001546 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001547 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1548 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001549 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001550
1551 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001552 FolderIcon newFolder =
1553 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1554 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1555 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001556 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557 }
Romain Guycbb89e42009-06-08 15:52:54 -07001558
Joe Onorato9c1289c2009-08-17 11:03:03 -04001559 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001560 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001561 }
1562
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001564 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001565 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001566 Intent chooser = Intent.createChooser(pickWallpaper,
1567 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001568 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1569 // Removed in Eclair MR1
1570// WallpaperManager wm = (WallpaperManager)
1571// getSystemService(Context.WALLPAPER_SERVICE);
1572// WallpaperInfo wi = wm.getWallpaperInfo();
1573// if (wi != null && wi.getSettingsActivity() != null) {
1574// LabeledIntent li = new LabeledIntent(getPackageName(),
1575// R.string.configure_wallpaper, 0);
1576// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1577// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1578// }
Mike Clerona0618e42009-10-22 13:55:21 -07001579 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001580 }
1581
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001582 /**
1583 * Registers various content observers. The current implementation registers
1584 * only a favorites observer to keep track of the favorites applications.
1585 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001586 private void registerContentObservers() {
1587 ContentResolver resolver = getContentResolver();
1588 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1589 true, mWidgetObserver);
1590 }
1591
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 @Override
1593 public boolean dispatchKeyEvent(KeyEvent event) {
1594 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1595 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001597 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001598 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001599 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001600 dumpState();
1601 return true;
1602 }
1603 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001604 }
1605 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1606 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001607 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 return true;
1609 }
1610 }
1611
1612 return super.dispatchKeyEvent(event);
1613 }
1614
Joe Onorato88ec0992009-11-19 13:16:06 -08001615 @Override
1616 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001617 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001618 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001619 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001620 Folder openFolder = mWorkspace.getOpenFolder();
1621 if (openFolder.isEditingName()) {
1622 openFolder.dismissEditingName();
1623 } else {
1624 closeFolder();
1625 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001626 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001627 mWorkspace.exitWidgetResizeMode();
1628
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001629 // Back button is a no-op here, but give at least some feedback for the button press
1630 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001631 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001632 }
1633
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001634 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001635 * Re-listen when widgets are reset.
1636 */
1637 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001638 if (mAppWidgetHost != null) {
1639 mAppWidgetHost.startListening();
1640 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001641 }
1642
1643 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001644 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1645 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001646 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001647 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001648 if (mModel != null) {
1649 mModel.unbindWorkspaceItems();
1650 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001651 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001652
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001653 /**
1654 * Launches the intent referred by the clicked shortcut.
1655 *
1656 * @param v The view representing the clicked shortcut.
1657 */
1658 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001659 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1660 // view has detached (it's possible for this to happen if the view is removed mid touch).
1661 if (v.getWindowToken() == null) {
1662 return;
1663 }
1664
1665 if (mWorkspace.isSwitchingState()) {
1666 return;
1667 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001668
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001669 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001670 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001671 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001672 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001673 int[] pos = new int[2];
1674 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001675 intent.setSourceBounds(new Rect(pos[0], pos[1],
1676 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001677 boolean success = startActivitySafely(intent, tag);
1678
1679 if (success && v instanceof BubbleTextView) {
1680 mWaitingForResume = (BubbleTextView) v;
1681 mWaitingForResume.setStayPressed(true);
1682 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001683 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001684 if (v instanceof FolderIcon) {
1685 FolderIcon fi = (FolderIcon) v;
1686 handleFolderClick(fi);
1687 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001688 } else if (v == mAllAppsButton) {
1689 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001690 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001691 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001692 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001693 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001694 }
1695 }
1696
Michael Jurka0e260592010-06-30 17:07:39 -07001697 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001698 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001699 // clicking anywhere on the workspace causes the customization drawer to slide down
1700 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001701 return false;
1702 }
1703
Michael Jurkaaf442092010-06-10 17:01:57 -07001704 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001705 * Event handler for the search button
1706 *
1707 * @param v The view that was clicked.
1708 */
1709 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001710 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1711
Amith Yamasania135ba82011-08-09 17:42:01 -07001712 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001713 }
1714
1715 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001716 * Event handler for the voice button
1717 *
1718 * @param v The view that was clicked.
1719 */
1720 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001721 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001722
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001723 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001724 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001725 startActivity(intent);
1726 }
1727
1728 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001729 * Event handler for the "grid" button that appears on the home screen, which
1730 * enters all apps mode.
1731 *
1732 * @param v The view that was clicked.
1733 */
1734 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001735 showAllApps(true);
1736 }
1737
1738 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001739 // Provide the same haptic feedback that the system offers for virtual keys.
1740 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001741 }
1742
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001743 public void onClickAppMarketButton(View v) {
1744 if (mAppMarketIntent != null) {
1745 startActivitySafely(mAppMarketIntent, "app market");
1746 }
1747 }
1748
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001749 void startApplicationDetailsActivity(ComponentName componentName) {
1750 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001751 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1752 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001753 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001754 startActivity(intent);
1755 }
1756
Patrick Dubroy5539af72010-09-07 15:22:01 -07001757 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1758 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1759 // System applications cannot be installed. For now, show a toast explaining that.
1760 // We may give them the option of disabling apps this way.
1761 int messageId = R.string.uninstall_system_app_text;
1762 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1763 } else {
1764 String packageName = appInfo.componentName.getPackageName();
1765 String className = appInfo.componentName.getClassName();
1766 Intent intent = new Intent(
1767 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001768 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1769 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001770 startActivity(intent);
1771 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001772 }
1773
Michael Jurkaddd62e92011-02-16 17:49:14 -08001774 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001775 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1776 try {
1777 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001778 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001779 } catch (ActivityNotFoundException e) {
1780 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001781 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001782 } catch (SecurityException e) {
1783 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001784 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001785 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001786 "or use the exported attribute for this activity. "
1787 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001789 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001790 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001791
Romain Guy8e633c52010-03-04 12:51:36 -08001792 void startActivityForResultSafely(Intent intent, int requestCode) {
1793 try {
1794 startActivityForResult(intent, requestCode);
1795 } catch (ActivityNotFoundException e) {
1796 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1797 } catch (SecurityException e) {
1798 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1799 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1800 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1801 "or use the exported attribute for this activity.", e);
1802 }
1803 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001804
Adam Cohena9cf38f2011-05-02 15:36:58 -07001805 private void handleFolderClick(FolderIcon folderIcon) {
1806 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001807 Folder openFolder = mWorkspace.getFolderForTag(info);
1808
1809 // If the folder info reports that the associated folder is open, then verify that
1810 // it is actually opened. There have been a few instances where this gets out of sync.
1811 if (info.opened && openFolder == null) {
1812 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1813 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1814 info.opened = false;
1815 }
1816
Adam Cohena9cf38f2011-05-02 15:36:58 -07001817 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 // Close any open folder
1819 closeFolder();
1820 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001821 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001822 } else {
1823 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 int folderScreen;
1825 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001826 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001827 // .. and close it
1828 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001829 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830 // Close any folder open on the current screen
1831 closeFolder();
1832 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001833 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834 }
1835 }
1836 }
1837 }
1838
Adam Cohen2801caf2011-05-13 20:57:39 -07001839 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001840 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001841 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1842 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1843 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1844
Adam Cohenc51934b2011-07-26 21:07:43 -07001845 FolderInfo info = (FolderInfo) fi.getTag();
1846 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1847 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001848 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1849 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001850 }
1851
Adam Cohen2801caf2011-05-13 20:57:39 -07001852 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1853 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1854 oa.start();
1855 }
1856
1857 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001858 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001859 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1860 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1861 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1862
Adam Cohenc51934b2011-07-26 21:07:43 -07001863 FolderInfo info = (FolderInfo) fi.getTag();
1864 CellLayout cl = null;
1865 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1866 cl = (CellLayout) fi.getParent().getParent();
1867 }
1868
1869 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001870 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1871 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001872 oa.addListener(new AnimatorListenerAdapter() {
1873 @Override
1874 public void onAnimationEnd(Animator animation) {
1875 if (layout != null) {
1876 layout.clearFolderLeaveBehind();
1877 }
1878 }
1879 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001880 oa.start();
1881 }
1882
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001884 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001885 * is animated relative to the specified View. If the View is null, no animation
1886 * is played.
1887 *
1888 * @param folderInfo The FolderInfo describing the folder to open.
1889 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001890 public void openFolder(FolderIcon folderIcon) {
1891 Folder folder = folderIcon.mFolder;
1892 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001893
Adam Cohen2801caf2011-05-13 20:57:39 -07001894 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001895 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001896
Adam Cohen4554ee12011-08-03 16:13:21 -07001897 // Just verify that the folder hasn't already been added to the DragLayer.
1898 // There was a one-off crash where the folder had a parent already.
1899 if (folder.getParent() == null) {
1900 mDragLayer.addView(folder);
1901 mDragController.addDropTarget((DropTarget) folder);
1902 } else {
1903 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1904 folder.getParent() + ").");
1905 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001906 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001907 }
1908
1909 public void closeFolder() {
1910 Folder folder = mWorkspace.getOpenFolder();
1911 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001912 if (folder.isEditingName()) {
1913 folder.dismissEditingName();
1914 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001915 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001916
1917 // Dismiss the folder cling
1918 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001919 }
1920 }
1921
1922 void closeFolder(Folder folder) {
1923 folder.getInfo().opened = false;
1924
1925 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1926 if (parent != null) {
1927 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1928 shrinkAndFadeInFolderIcon(fi);
1929 }
1930 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001931 }
1932
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001933 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001934 if (mState != State.WORKSPACE) {
1935 return false;
1936 }
1937
Joe Onorato9c1289c2009-08-17 11:03:03 -04001938 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 return false;
1940 }
1941
1942 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001943 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001944 }
1945
Michael Jurka0280c3b2010-09-17 15:00:07 -07001946 resetAddInfo();
1947 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001949 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950 return true;
1951 }
1952
Winson Chung3d503fb2011-07-13 17:25:49 -07001953 // The hotseat touch handling does not go through Workspace, and we always allow long press
1954 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001955 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001956 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1957 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001958 if (itemUnderLongClick == null) {
1959 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001960 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1961 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001962 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001963 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001964 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001965 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07001966 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001967 }
1968 }
1969 }
1970 return true;
1971 }
1972
Winson Chung3d503fb2011-07-13 17:25:49 -07001973 boolean isHotseatLayout(View layout) {
1974 return mHotseat != null && layout != null &&
1975 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1976 }
1977 Hotseat getHotseat() {
1978 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001979 }
Adam Cohenebea84d2011-11-09 17:20:41 -08001980 SearchDropTargetBar getSearchBar() {
1981 return mSearchDropTargetBar;
1982 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001983
Winson Chung3d503fb2011-07-13 17:25:49 -07001984 /**
1985 * Returns the CellLayout of the specified container at the specified screen.
1986 */
1987 CellLayout getCellLayout(long container, int screen) {
1988 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1989 if (mHotseat != null) {
1990 return mHotseat.getLayout();
1991 } else {
1992 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001993 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001994 } else {
1995 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001996 }
1997 }
1998
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999 Workspace getWorkspace() {
2000 return mWorkspace;
2001 }
2002
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 @Override
2004 protected Dialog onCreateDialog(int id) {
2005 switch (id) {
2006 case DIALOG_CREATE_SHORTCUT:
2007 return new CreateShortcut().createDialog();
2008 case DIALOG_RENAME_FOLDER:
2009 return new RenameFolder().createDialog();
2010 }
2011
2012 return super.onCreateDialog(id);
2013 }
2014
2015 @Override
2016 protected void onPrepareDialog(int id, Dialog dialog) {
2017 switch (id) {
2018 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 break;
2020 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002021 if (mFolderInfo != null) {
2022 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2023 final CharSequence text = mFolderInfo.title;
2024 input.setText(text);
2025 input.setSelection(0, text.length());
2026 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 break;
2028 }
2029 }
2030
2031 void showRenameDialog(FolderInfo info) {
2032 mFolderInfo = info;
2033 mWaitingForResult = true;
2034 showDialog(DIALOG_RENAME_FOLDER);
2035 }
2036
Adam Cohenfbba09b2011-07-18 21:43:05 -07002037 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002038 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002039 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2040 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002041 mWaitingForResult = true;
2042 showDialog(DIALOG_CREATE_SHORTCUT);
2043 }
2044
2045 private class RenameFolder {
2046 private EditText mInput;
2047
2048 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2050 mInput = (EditText) layout.findViewById(R.id.folder_name);
2051
2052 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2053 builder.setIcon(0);
2054 builder.setTitle(getString(R.string.rename_folder_title));
2055 builder.setCancelable(true);
2056 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2057 public void onCancel(DialogInterface dialog) {
2058 cleanup();
2059 }
2060 });
2061 builder.setNegativeButton(getString(R.string.cancel_action),
2062 new Dialog.OnClickListener() {
2063 public void onClick(DialogInterface dialog, int which) {
2064 cleanup();
2065 }
2066 }
2067 );
2068 builder.setPositiveButton(getString(R.string.rename_action),
2069 new Dialog.OnClickListener() {
2070 public void onClick(DialogInterface dialog, int which) {
2071 changeFolderName();
2072 }
2073 }
2074 );
2075 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002076
2077 final AlertDialog dialog = builder.create();
2078 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2079 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002080 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002081 mInput.requestFocus();
2082 InputMethodManager inputManager = (InputMethodManager)
2083 getSystemService(Context.INPUT_METHOD_SERVICE);
2084 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002085 }
2086 });
2087
2088 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002089 }
2090
2091 private void changeFolderName() {
2092 final String name = mInput.getText().toString();
2093 if (!TextUtils.isEmpty(name)) {
2094 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002095 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002096 mFolderInfo.title = name;
2097 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2098
Joe Onorato9c1289c2009-08-17 11:03:03 -04002099 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002100 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002101 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002102 } else {
2103 final FolderIcon folderIcon = (FolderIcon)
2104 mWorkspace.getViewForTag(mFolderInfo);
2105 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002106 // TODO: At some point we'll probably want some version of setting
2107 // the text for a folder icon.
2108 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002109 getWorkspace().requestLayout();
2110 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002111 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002112 mWorkspaceLoading = true;
2113 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002114 }
2115 }
2116 }
2117 cleanup();
2118 }
2119
2120 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002121 dismissDialog(DIALOG_RENAME_FOLDER);
2122 mWaitingForResult = false;
2123 mFolderInfo = null;
2124 }
2125 }
2126
Daniel Sandler843e8602010-06-07 14:59:01 -04002127 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2128 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002129 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002130 }
2131
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002132 // AllAppsView.Watcher
2133 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002134 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002135 mWorkspace.setVisibility(View.GONE);
2136 }
2137 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002138
2139 /**
2140 * Helper method for the cameraZoomIn/cameraZoomOut animations
2141 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002142 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002143 * @param scaleFactor The scale factor used for the zoom
2144 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002145 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002146 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002147 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002148 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002149
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002150 void updateWallpaperVisibility(boolean visible) {
2151 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2152 int curflags = getWindow().getAttributes().flags
2153 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2154 if (wpflags != curflags) {
2155 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2156 }
2157 }
2158
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002159 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002160 * Things to test when changing the following seven functions.
2161 * - Home from workspace
2162 * - from center screen
2163 * - from other screens
2164 * - Home from all apps
2165 * - from center screen
2166 * - from other screens
2167 * - Back from all apps
2168 * - from center screen
2169 * - from other screens
2170 * - Launch app from workspace and quit
2171 * - with back
2172 * - with home
2173 * - Launch app from all apps and quit
2174 * - with back
2175 * - with home
2176 * - Go to a screen that's not the default, then all
2177 * apps, and launch and app, and go back
2178 * - with back
2179 * -with home
2180 * - On workspace, long press power and go back
2181 * - with back
2182 * - with home
2183 * - On all apps, long press power and go back
2184 * - with back
2185 * - with home
2186 * - On workspace, power off
2187 * - On all apps, power off
2188 * - Launch an app and turn off the screen while in that app
2189 * - Go back with home key
2190 * - Go back with back key TODO: make this not go to workspace
2191 * - From all apps
2192 * - From workspace
2193 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2194 * - From all apps
2195 * - From the center workspace
2196 * - From another workspace
2197 */
2198
2199 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002200 * Zoom the camera out from the workspace to reveal 'toView'.
2201 * Assumes that the view to show is anchored at either the very top or very bottom
2202 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002203 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002204 private void showAppsCustomizeHelper(boolean animated, final boolean springLoaded) {
2205 if (mStateAnimation != null) {
2206 mStateAnimation.cancel();
2207 mStateAnimation = null;
2208 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002209 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002210 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002211
Winson Chungf0ea4d32011-06-06 14:27:16 -07002212 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2213 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2214 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2215 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002216 final int startDelay =
2217 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002218
Michael Jurkab3e22d92011-10-31 15:58:33 -07002219 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002220
Michael Jurkad74c9842011-07-10 12:44:21 -07002221 // Shrink workspaces away if going to AppsCustomize from workspace
Adam Cohen7777d962011-08-18 18:58:38 -07002222 mWorkspace.changeState(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002223
2224 if (animated) {
Michael Jurkaabded662011-03-04 12:06:57 -08002225 final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
Michael Jurka742574b2011-02-02 23:51:01 -08002226 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002227 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2228 public void onAnimationUpdate(float a, float b) {
Adam Cohenc00f0b92011-12-06 19:45:06 -08002229 toView.setScaleX(a * scale + b * 1f);
2230 toView.setScaleY(a * scale + b * 1f);
Michael Jurka742574b2011-02-02 23:51:01 -08002231 }
2232 });
Adam Cohen61033d32010-11-15 18:29:44 -08002233
Winson Chungf0ea4d32011-06-06 14:27:16 -07002234 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002235 toView.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002236 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2237 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2238 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2239 public void onAnimationUpdate(float a, float b) {
2240 // don't need to invalidate because we do so above
Adam Cohenc00f0b92011-12-06 19:45:06 -08002241 toView.setAlpha(a * 0f + b * 1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002242 }
2243 });
Adam Cohencff6af82011-09-13 14:51:53 -07002244 alphaAnim.setStartDelay(startDelay);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002245 alphaAnim.start();
Adam Cohenf16e5712011-01-13 13:31:45 -08002246
Michael Jurka8edd75c2010-12-17 20:15:06 -08002247 scaleAnim.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002248 boolean animationCancelled = false;
2249
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002250 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002251 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002252 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002253 // Prepare the position
2254 toView.setTranslationX(0.0f);
2255 toView.setTranslationY(0.0f);
2256 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002257 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002258 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002259 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002260 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002261 // If we don't set the final scale values here, if this animation is cancelled
2262 // it will have the wrong scale value and subsequent cameraPan animations will
2263 // not fix that
2264 toView.setScaleX(1.0f);
2265 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002266 if (toView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002267 ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance,
2268 scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002269 }
Winson Chung32174c82011-07-19 15:47:55 -07002270
2271 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2272 // Hide the workspace scrollbar
2273 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002274 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002275 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002276 if (!animationCancelled) {
2277 updateWallpaperVisibility(false);
2278 }
2279 }
2280
Adam Cohencff6af82011-09-13 14:51:53 -07002281 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002282 public void onAnimationCancel(Animator animation) {
2283 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002284 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002285 });
2286
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002287 // toView should appear right at the end of the workspace shrink animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002288 mStateAnimation = new AnimatorSet();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002289 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka1899a362011-11-03 13:50:45 -07002290
2291 boolean delayAnim = false;
2292 if (toView instanceof LauncherTransitionable) {
2293 LauncherTransitionable lt = (LauncherTransitionable) toView;
2294 delayAnim = lt.onLauncherTransitionStart(instance, mStateAnimation, false);
2295 }
2296 // if the anim is delayed, the LauncherTransitionable is responsible for starting it
2297 if (!delayAnim) {
2298 // TODO: q-- what if this anim is cancelled before being started? or started after
2299 // being cancelled?
2300 mStateAnimation.start();
2301 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002302 } else {
2303 toView.setTranslationX(0.0f);
2304 toView.setTranslationY(0.0f);
2305 toView.setScaleX(1.0f);
2306 toView.setScaleY(1.0f);
2307 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002308 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002309 if (toView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002310 ((LauncherTransitionable) toView).onLauncherTransitionStart(instance, null, false);
2311 ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance, null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002312
Winson Chungc07918d2011-07-01 15:35:26 -07002313 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2314 // Hide the workspace scrollbar
2315 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002316 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002317 }
Michael Jurkaabded662011-03-04 12:06:57 -08002318 }
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002319 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002320 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002321 }
2322
2323 /**
2324 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002325 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002326 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002327 */
Michael Jurkab737ee62011-11-15 15:57:22 -08002328 private void hideAppsCustomizeHelper(boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002329 if (mStateAnimation != null) {
2330 mStateAnimation.cancel();
2331 mStateAnimation = null;
2332 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002333 Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002334 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002335
Winson Chungf0ea4d32011-06-06 14:27:16 -07002336 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2337 final float scaleFactor = (float)
2338 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2339 final View fromView = mAppsCustomizeTabHost;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002340
Michael Jurkab3e22d92011-10-31 15:58:33 -07002341 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002342 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002343 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002344 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002345 final float oldScaleX = fromView.getScaleX();
2346 final float oldScaleY = fromView.getScaleY();
2347
2348 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2349 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002350 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2351 public void onAnimationUpdate(float a, float b) {
Adam Cohenc00f0b92011-12-06 19:45:06 -08002352 fromView.setScaleX(a * oldScaleX + b * scaleFactor);
2353 fromView.setScaleY(a * oldScaleY + b * scaleFactor);
Michael Jurka742574b2011-02-02 23:51:01 -08002354 }
2355 });
Michael Jurkaabded662011-03-04 12:06:57 -08002356 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002357 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Adam Cohencff6af82011-09-13 14:51:53 -07002358 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002359 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2360 public void onAnimationUpdate(float a, float b) {
Adam Cohenc00f0b92011-12-06 19:45:06 -08002361 fromView.setAlpha(a * 1f + b * 0f);
Michael Jurka742574b2011-02-02 23:51:01 -08002362 }
2363 });
Michael Jurkaabded662011-03-04 12:06:57 -08002364 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002365 ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, alphaAnim,
2366 true);
Michael Jurka2763be32011-02-24 11:19:57 -08002367 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002368 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002369 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002370 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002371 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002372 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002373 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002374 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance,
2375 alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002376 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002377 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002378 }
2379 });
2380
Michael Jurkab3e22d92011-10-31 15:58:33 -07002381 mStateAnimation = new AnimatorSet();
Winson Chungf0ea4d32011-06-06 14:27:16 -07002382 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002383 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002384 } else {
2385 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002386 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002387 ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, null, true);
2388 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance, null, true);
Michael Jurkaabded662011-03-04 12:06:57 -08002389 }
Michael Jurkab737ee62011-11-15 15:57:22 -08002390 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002391 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002392 }
2393
Michael Jurkae326f182011-11-21 14:05:46 -08002394 @Override
2395 public void onTrimMemory(int level) {
2396 super.onTrimMemory(level);
2397 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2398 mAppsCustomizeTabHost.onTrimMemory();
2399 }
2400 }
2401
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002402 void showWorkspace(boolean animated) {
Adam Cohencff6af82011-09-13 14:51:53 -07002403 Resources res = getResources();
2404 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2405
2406 mWorkspace.changeState(Workspace.State.NORMAL, animated, stagger);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002407 if (mState != State.WORKSPACE) {
2408 mWorkspace.setVisibility(View.VISIBLE);
Michael Jurkab737ee62011-11-15 15:57:22 -08002409 hideAppsCustomizeHelper(animated, false);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002410
2411 // Show the search bar and hotseat
2412 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002413 // We only need to animate in the dock divider if we're going from spring loaded mode
2414 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002415
2416 // Set focus to the AppsCustomize button
2417 if (mAllAppsButton != null) {
2418 mAllAppsButton.requestFocus();
2419 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002420 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002421
Michael Jurkab737ee62011-11-15 15:57:22 -08002422 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002423
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002424 // Change the state *after* we've called all the transition code
2425 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002426
Winson Chung5fb63472011-02-02 17:03:37 -08002427 // Resume the auto-advance of widgets
2428 mUserPresent = true;
2429 updateRunning();
2430
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002431 // send an accessibility event to announce the context change
2432 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002433 }
2434
Michael Jurkab3e22d92011-10-31 15:58:33 -07002435 void showAllApps(boolean animated) {
2436 if (mState != State.WORKSPACE) return;
2437
2438 showAppsCustomizeHelper(animated, false);
2439 mAppsCustomizeTabHost.requestFocus();
2440
2441 // Hide the search bar and hotseat
2442 mSearchDropTargetBar.hideSearchBar(animated);
2443
2444 // Change the state *after* we've called all the transition code
2445 mState = State.APPS_CUSTOMIZE;
2446
2447 // Pause the auto-advance of widgets until we are out of AllApps
2448 mUserPresent = false;
2449 updateRunning();
2450 closeFolder();
2451
2452 // Send an accessibility event to announce the context change
2453 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2454 }
2455
Adam Cohen7777d962011-08-18 18:58:38 -07002456 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002457 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen7777d962011-08-18 18:58:38 -07002458 mWorkspace.changeState(Workspace.State.SPRING_LOADED);
Michael Jurkab737ee62011-11-15 15:57:22 -08002459 hideAppsCustomizeHelper(true, true);
2460 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002461 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002462 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002463 }
Adam Cohen7777d962011-08-18 18:58:38 -07002464
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002465 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
Winson Chung09bfc452011-09-09 11:30:20 -07002466 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2467
Winson Chunge7a03942011-08-05 15:05:12 -07002468 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002469 @Override
2470 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002471 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002472 // Before we show workspace, hide all apps again because
2473 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2474 // clean up our state transition functions
2475 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002476 mSearchDropTargetBar.showSearchBar(true);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002477 showWorkspace(true);
Adam Cohen7777d962011-08-18 18:58:38 -07002478 } else {
2479 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002480 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002481 }
2482 }, (extendedDelay ?
2483 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2484 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2485 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002486
Michael Jurkad3ef3062010-11-23 16:23:58 -08002487 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002488 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002489 final boolean animated = true;
2490 final boolean springLoaded = true;
2491 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002492 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002493 }
2494 // Otherwise, we are not in spring loaded mode, so don't do anything.
2495 }
2496
Michael Jurkab737ee62011-11-15 15:57:22 -08002497 void hideDockDivider() {
2498 if (mQsbDivider != null && mDockDivider != null) {
2499 mQsbDivider.setVisibility(View.INVISIBLE);
2500 mDockDivider.setVisibility(View.INVISIBLE);
2501 }
2502 }
2503
2504 void showDockDivider(boolean animated) {
2505 if (mQsbDivider != null && mDockDivider != null) {
2506 mQsbDivider.setVisibility(View.VISIBLE);
2507 mDockDivider.setVisibility(View.VISIBLE);
2508 if (mDividerAnimator != null) {
2509 mDividerAnimator.cancel();
2510 mQsbDivider.setAlpha(1f);
2511 mDockDivider.setAlpha(1f);
2512 mDividerAnimator = null;
2513 }
2514 if (animated) {
2515 mDividerAnimator = new AnimatorSet();
2516 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2517 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2518 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2519 mDividerAnimator.start();
2520 }
2521 }
2522 }
2523
Michael Jurkab3e22d92011-10-31 15:58:33 -07002524 void lockAllApps() {
2525 // TODO
2526 }
2527
2528 void unlockAllApps() {
2529 // TODO
2530 }
2531
Adam Cohenfc53cd22011-07-20 15:45:11 -07002532 public boolean isAllAppsCustomizeOpen() {
2533 return mState == State.APPS_CUSTOMIZE;
2534 }
2535
Winson Chungf0ea4d32011-06-06 14:27:16 -07002536 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002537 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002538 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002539 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002540 if (!LauncherApplication.isScreenLarge()) {
2541 if (animated) {
Winson Chungc51db6a2011-10-05 11:44:49 -07002542 int duration = mSearchDropTargetBar.getTransitionInDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002543 mHotseat.animate().alpha(1f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002544 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002545 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002546 }
2547 }
2548 }
2549
2550 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002551 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002552 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002553 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002554 if (!LauncherApplication.isScreenLarge()) {
2555 if (animated) {
Winson Chungc51db6a2011-10-05 11:44:49 -07002556 int duration = mSearchDropTargetBar.getTransitionOutDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002557 mHotseat.animate().alpha(0f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002558 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002559 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002560 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002561 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002562 }
2563
Patrick Dubroy5f445422011-02-18 14:35:21 -08002564 /**
2565 * Add an item from all apps or customize onto the given workspace screen.
2566 * If layout is null, add to the current screen.
2567 */
2568 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002569 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2570 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002571 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002572 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002573
Winson Chungdff8ebb2011-09-08 17:25:31 -07002574 /** Maps the current orientation to an index for referencing orientation correct global icons */
2575 private int getCurrentOrientationIndexForGlobalIcons() {
2576 // default - 0, landscape - 1
2577 switch (getResources().getConfiguration().orientation) {
2578 case Configuration.ORIENTATION_LANDSCAPE:
2579 return 1;
2580 default:
2581 return 0;
2582 }
2583 }
2584
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002585 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002586 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002587 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002588 // Look for the toolbar icon specified in the activity meta-data
2589 Bundle metaData = packageManager.getActivityInfo(
2590 activityName, PackageManager.GET_META_DATA).metaData;
2591 if (metaData != null) {
2592 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2593 if (iconResId != 0) {
2594 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002595 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002596 }
2597 }
2598 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002599 // This can happen if the activity defines an invalid drawable
2600 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2601 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002602 } catch (Resources.NotFoundException nfe) {
2603 // This can happen if the activity defines an invalid drawable
2604 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2605 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002606 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002607 return null;
2608 }
2609
2610 // if successful in getting icon, return it; otherwise, set button to use default drawable
2611 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2612 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002613 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002614 Resources r = getResources();
2615 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2616 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002617
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002618 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002619 // If we were unable to find the icon via the meta-data, use a generic one
2620 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002621 toolbarIcon = r.getDrawable(fallbackDrawableId);
2622 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002623 if (button != null) {
2624 button.setCompoundDrawables(toolbarIcon, null, null, null);
2625 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002626 return null;
2627 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002628 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002629 if (button != null) {
2630 button.setCompoundDrawables(toolbarIcon, null, null, null);
2631 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002632 return toolbarIcon.getConstantState();
2633 }
2634 }
2635
2636 // if successful in getting icon, return it; otherwise, set button to use default drawable
2637 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2638 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2639 ImageView button = (ImageView) findViewById(buttonId);
2640 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2641
Michael Jurka19e0fc52011-07-22 18:00:21 -07002642 if (button != null) {
2643 // If we were unable to find the icon via the meta-data, use a
2644 // generic one
2645 if (toolbarIcon == null) {
2646 button.setImageResource(fallbackDrawableId);
2647 } else {
2648 button.setImageDrawable(toolbarIcon);
2649 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002650 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002651
2652 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2653
Michael Jurka0423dcf2010-10-05 14:56:18 -07002654 }
2655
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002656 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2657 TextView button = (TextView) findViewById(buttonId);
2658 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2659 }
2660
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002661 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002662 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002663 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002664 }
2665
Winson Chungbb185bd2011-11-21 12:31:42 -08002666 private void invalidatePressedFocusedStates(View container, View button) {
2667 if (container instanceof HolographicLinearLayout) {
2668 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2669 layout.invalidatePressedFocusedStates();
2670 } else if (button instanceof HolographicImageView) {
2671 HolographicImageView view = (HolographicImageView) button;
2672 view.invalidatePressedFocusedStates();
2673 }
2674 }
2675
Winson Chungc51db6a2011-10-05 11:44:49 -07002676 private boolean updateGlobalSearchIcon() {
2677 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002678 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2679 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002680 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002681 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002682
Winson Chung1cad91e2011-05-25 17:41:01 -07002683 final SearchManager searchManager =
2684 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2685 ComponentName activityName = searchManager.getGlobalSearchActivity();
2686 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002687 int coi = getCurrentOrientationIndexForGlobalIcons();
2688 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002689 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002690 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002691 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2692 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002693 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002694 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002695 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002696 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002697 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002698 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2699 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2700 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002701 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002702 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002703 }
2704 }
2705
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002706 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002707 final View searchButtonContainer = findViewById(R.id.search_button_container);
2708 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002709 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002710 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002711 }
2712
Winson Chungc51db6a2011-10-05 11:44:49 -07002713 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002714 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002715 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002716 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002717
Winson Chungc51db6a2011-10-05 11:44:49 -07002718 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002719 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2720 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002721 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002722 int coi = getCurrentOrientationIndexForGlobalIcons();
2723 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002724 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002725 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002726 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002727 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002728 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002729 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002730 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002731 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002732 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002733 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002734 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002735 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002736 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002737
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002738 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002739 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2740 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002741 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002742 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002743 }
2744
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002745 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002746 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002747 */
2748 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002749 final View marketButton = findViewById(R.id.market_button);
2750 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2751 // Find the app market activity by resolving an intent.
2752 // (If multiple app markets are installed, it will return the ResolverActivity.)
2753 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002754 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002755 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002756 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002757 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002758 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002759 marketButton.setVisibility(View.VISIBLE);
2760 } else {
2761 // We should hide and disable the view so that we don't try and restore the visibility
2762 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2763 marketButton.setVisibility(View.GONE);
2764 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002765 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002766 }
2767
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002768 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002769 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002770 }
2771
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002772 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002773 * Displays the shortcut creation dialog and launches, if necessary, the
2774 * appropriate activity.
2775 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002776 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002777 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2778 DialogInterface.OnShowListener {
2779
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002780 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002781
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002782 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002783 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002784
Winson Chung55b65502011-05-26 12:03:43 -07002785 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2786 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002787 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002788
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002789 AlertDialog dialog = builder.create();
2790 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002791 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002792 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002793
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002794 return dialog;
2795 }
2796
2797 public void onCancel(DialogInterface dialog) {
2798 mWaitingForResult = false;
2799 cleanup();
2800 }
2801
Romain Guycbb89e42009-06-08 15:52:54 -07002802 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002803 mWaitingForResult = false;
2804 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002805 }
2806
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002807 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002808 try {
2809 dismissDialog(DIALOG_CREATE_SHORTCUT);
2810 } catch (Exception e) {
2811 // An exception is thrown if the dialog is not visible, which is fine
2812 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002813 }
2814
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002815 /**
2816 * Handle the action clicked in the "Add to home" dialog.
2817 */
2818 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002819 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002820
Winson Chung55b65502011-05-26 12:03:43 -07002821 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2822 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002823 case AddAdapter.ITEM_APPLICATION: {
2824 if (mAppsCustomizeTabHost != null) {
2825 mAppsCustomizeTabHost.selectAppsTab();
2826 }
2827 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002828 break;
2829 }
Winson Chung55b65502011-05-26 12:03:43 -07002830 case AddAdapter.ITEM_APPWIDGET: {
2831 if (mAppsCustomizeTabHost != null) {
2832 mAppsCustomizeTabHost.selectWidgetsTab();
2833 }
2834 showAllApps(true);
2835 break;
2836 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002837 case AddAdapter.ITEM_WALLPAPER: {
2838 startWallpaper();
2839 break;
2840 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002841 }
2842 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002843
2844 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002845 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002846 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002847 }
2848
2849 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002850 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002851 */
2852 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2853 @Override
2854 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002855 closeSystemDialogs();
2856 }
2857 }
2858
2859 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002860 * Receives notifications whenever the appwidgets are reset.
2861 */
2862 private class AppWidgetResetObserver extends ContentObserver {
2863 public AppWidgetResetObserver() {
2864 super(new Handler());
2865 }
2866
2867 @Override
2868 public void onChange(boolean selfChange) {
2869 onAppWidgetReset();
2870 }
2871 }
2872
2873 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002874 * If the activity is currently paused, signal that we need to re-run the loader
2875 * in onResume.
2876 *
2877 * This needs to be called from incoming places where resources might have been loaded
2878 * while we are paused. That is becaues the Configuration might be wrong
2879 * when we're not running, and if it comes back to what it was when we
2880 * were paused, we are not restarted.
2881 *
2882 * Implementation of the method from LauncherModel.Callbacks.
2883 *
2884 * @return true if we are currently paused. The caller might be able to
2885 * skip some work in that case since we will come back again.
2886 */
2887 public boolean setLoadOnResume() {
2888 if (mPaused) {
2889 Log.i(TAG, "setLoadOnResume");
2890 mOnResumeNeedsLoad = true;
2891 return true;
2892 } else {
2893 return false;
2894 }
2895 }
2896
2897 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002898 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002899 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002900 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002901 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002902 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002903 } else {
2904 return SCREEN_COUNT / 2;
2905 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002906 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002907
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002908
Joe Onorato9c1289c2009-08-17 11:03:03 -04002909 /**
2910 * Refreshes the shortcuts shown on the workspace.
2911 *
2912 * Implementation of the method from LauncherModel.Callbacks.
2913 */
2914 public void startBinding() {
2915 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002916
2917 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002918 int count = workspace.getChildCount();
2919 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002920 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002921 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2922 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002923 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08002924 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07002925 if (mHotseat != null) {
2926 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002927 }
2928 }
2929
2930 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002931 * Bind the items start-end from the list.
2932 *
2933 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002934 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002935 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002936 setLoadOnResume();
2937
Joe Onorato9c1289c2009-08-17 11:03:03 -04002938 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002939 for (int i=start; i<end; i++) {
2940 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002941
2942 // Short circuit if we are loading dock items for a configuration which has no dock
2943 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2944 mHotseat == null) {
2945 continue;
2946 }
2947
Joe Onorato9c1289c2009-08-17 11:03:03 -04002948 switch (item.itemType) {
2949 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2950 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002951 View shortcut = createShortcut((ShortcutInfo)item);
2952 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
2953 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002954 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07002955 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07002956 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002957 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07002958 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07002959 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
2960 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002961 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002962 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002963 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002964 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002965 }
2966
Joe Onorato9c1289c2009-08-17 11:03:03 -04002967 /**
2968 * Implementation of the method from LauncherModel.Callbacks.
2969 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002970 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002971 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002972 sFolders.clear();
2973 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002974 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002975
2976 /**
2977 * Add the views for a widget to the workspace.
2978 *
2979 * Implementation of the method from LauncherModel.Callbacks.
2980 */
2981 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002982 setLoadOnResume();
2983
Daniel Sandler843e8602010-06-07 14:59:01 -04002984 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2985 if (DEBUG_WIDGETS) {
2986 Log.d(TAG, "bindAppWidget: " + item);
2987 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002988 final Workspace workspace = mWorkspace;
2989
2990 final int appWidgetId = item.appWidgetId;
2991 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002992 if (DEBUG_WIDGETS) {
2993 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2994 }
2995
Joe Onorato9c1289c2009-08-17 11:03:03 -04002996 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2997
Joe Onorato9c1289c2009-08-17 11:03:03 -04002998 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2999 item.hostView.setTag(item);
3000
Winson Chung3d503fb2011-07-13 17:25:49 -07003001 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003002 item.cellY, item.spanX, item.spanY, false);
3003
Adam Cohended9f8d2010-11-03 13:25:16 -07003004 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3005
Joe Onorato9c1289c2009-08-17 11:03:03 -04003006 workspace.requestLayout();
3007
Daniel Sandler843e8602010-06-07 14:59:01 -04003008 if (DEBUG_WIDGETS) {
3009 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3010 + (SystemClock.uptimeMillis()-start) + "ms");
3011 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003012 }
3013
3014 /**
3015 * Callback saying that there aren't any more items to bind.
3016 *
3017 * Implementation of the method from LauncherModel.Callbacks.
3018 */
3019 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003020 setLoadOnResume();
3021
Joe Onorato9c1289c2009-08-17 11:03:03 -04003022 if (mSavedState != null) {
3023 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003024 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003025 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003026 mSavedState = null;
3027 }
3028
3029 if (mSavedInstanceState != null) {
3030 super.onRestoreInstanceState(mSavedInstanceState);
3031 mSavedInstanceState = null;
3032 }
3033
Joe Onorato9c1289c2009-08-17 11:03:03 -04003034 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003035
3036 // If we received the result of any pending adds while the loader was running (e.g. the
3037 // widget configuration forced an orientation change), process them now.
3038 for (int i = 0; i < sPendingAddList.size(); i++) {
3039 completeAdd(sPendingAddList.get(i));
3040 }
3041 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003042
Winson Chungc51db6a2011-10-05 11:44:49 -07003043 // Update the market app icon as necessary (the other icons will be managed in response to
3044 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003045 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003046
3047 mWorkspace.post(mBuildLayersRunnable);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003048 }
3049
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003050 @Override
3051 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003052 boolean searchVisible = updateGlobalSearchIcon();
3053 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3054 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003055 }
3056
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003057 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003058 * Add the icons for all apps.
3059 *
3060 * Implementation of the method from LauncherModel.Callbacks.
3061 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003062 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3063 // Remove the progress bar entirely; we could also make it GONE
3064 // but better to remove it since we know it's not going to be used
3065 View progressBar = mAppsCustomizeTabHost.
3066 findViewById(R.id.apps_customize_progress_bar);
3067 if (progressBar != null) {
3068 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003069 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003070 // We just post the call to setApps so the user sees the progress bar
3071 // disappear-- otherwise, it just looks like the progress bar froze
3072 // which doesn't look great
3073 mAppsCustomizeTabHost.post(new Runnable() {
3074 public void run() {
3075 if (mAppsCustomizeContent != null) {
3076 mAppsCustomizeContent.setApps(apps);
3077 }
3078 }
3079 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003080 }
3081
3082 /**
3083 * A package was installed.
3084 *
3085 * Implementation of the method from LauncherModel.Callbacks.
3086 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003087 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003088 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003089 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003090
Winson Chung785d2eb2011-04-14 16:08:02 -07003091 if (mAppsCustomizeContent != null) {
3092 mAppsCustomizeContent.addApps(apps);
3093 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003094 }
3095
3096 /**
3097 * A package was updated.
3098 *
3099 * Implementation of the method from LauncherModel.Callbacks.
3100 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003101 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003102 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003103 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003104 if (mWorkspace != null) {
3105 mWorkspace.updateShortcuts(apps);
3106 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003107
Winson Chung785d2eb2011-04-14 16:08:02 -07003108 if (mAppsCustomizeContent != null) {
3109 mAppsCustomizeContent.updateApps(apps);
3110 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003111 }
3112
3113 /**
3114 * A package was uninstalled.
3115 *
3116 * Implementation of the method from LauncherModel.Callbacks.
3117 */
Joe Onorato36115782010-06-17 13:28:48 -04003118 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003119 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003120 if (permanent) {
3121 mWorkspace.removeItems(apps);
3122 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003123
Winson Chung785d2eb2011-04-14 16:08:02 -07003124 if (mAppsCustomizeContent != null) {
3125 mAppsCustomizeContent.removeApps(apps);
3126 }
Winson Chunga1820962011-10-03 16:31:06 -07003127
3128 // Notify the drag controller
3129 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003130 }
Joe Onoratobe386092009-11-17 17:32:16 -08003131
3132 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003133 * A number of packages were updated.
3134 */
3135 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003136 if (mAppsCustomizeContent != null) {
3137 mAppsCustomizeContent.onPackagesUpdated();
3138 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003139 }
3140
Winson Chung400438b2011-01-16 17:53:48 -08003141 private int mapConfigurationOriActivityInfoOri(int configOri) {
3142 final Display d = getWindowManager().getDefaultDisplay();
3143 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3144 switch (d.getRotation()) {
3145 case Surface.ROTATION_0:
3146 case Surface.ROTATION_180:
3147 // We are currently in the same basic orientation as the natural orientation
3148 naturalOri = configOri;
3149 break;
3150 case Surface.ROTATION_90:
3151 case Surface.ROTATION_270:
3152 // We are currently in the other basic orientation to the natural orientation
3153 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3154 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3155 break;
3156 }
3157
3158 int[] oriMap = {
3159 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3160 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3161 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3162 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3163 };
3164 // Since the map starts at portrait, we need to offset if this device's natural orientation
3165 // is landscape.
3166 int indexOffset = 0;
3167 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3168 indexOffset = 1;
3169 }
3170 return oriMap[(d.getRotation() + indexOffset) % 4];
3171 }
Adam Cohen446e9402011-09-15 18:21:21 -07003172
3173 public void lockScreenOrientationOnLargeUI() {
3174 if (LauncherApplication.isScreenLarge()) {
3175 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3176 .getConfiguration().orientation));
3177 }
Winson Chung400438b2011-01-16 17:53:48 -08003178 }
Adam Cohen446e9402011-09-15 18:21:21 -07003179 public void unlockScreenOrientationOnLargeUI() {
3180 if (LauncherApplication.isScreenLarge()) {
3181 mHandler.postDelayed(new Runnable() {
3182 public void run() {
3183 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3184 }
3185 }, mRestoreScreenOrientationDelay);
3186 }
Winson Chung400438b2011-01-16 17:53:48 -08003187 }
3188
Winson Chung82f55532011-08-09 14:14:23 -07003189 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003190 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3191 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003192 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003193 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003194
Winson Chung7d7541e2011-09-16 20:14:36 -07003195 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003196 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003197 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3198 Cling cling = (Cling) findViewById(clingId);
3199 if (cling != null) {
3200 cling.init(this, positionData);
3201 cling.setVisibility(View.VISIBLE);
3202 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3203 if (animate) {
3204 cling.buildLayer();
3205 cling.setAlpha(0f);
3206 cling.animate()
3207 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003208 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003209 .setDuration(SHOW_CLING_DURATION)
3210 .setStartDelay(delay)
3211 .start();
3212 } else {
3213 cling.setAlpha(1f);
3214 }
3215 }
3216 return cling;
3217 }
3218 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003219 if (cling != null) {
3220 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003221 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003222 anim.addListener(new AnimatorListenerAdapter() {
3223 public void onAnimationEnd(Animator animation) {
3224 cling.setVisibility(View.GONE);
3225 cling.cleanup();
3226 SharedPreferences prefs =
3227 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3228 SharedPreferences.Editor editor = prefs.edit();
3229 editor.putBoolean(flag, true);
3230 editor.commit();
3231 };
3232 });
3233 anim.start();
3234 }
3235 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003236 private void removeCling(int id) {
3237 final View cling = findViewById(id);
3238 if (cling != null) {
3239 final ViewGroup parent = (ViewGroup) cling.getParent();
3240 parent.post(new Runnable() {
3241 @Override
3242 public void run() {
3243 parent.removeView(cling);
3244 }
3245 });
3246 }
3247 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003248 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003249 // Enable the clings only if they have not been dismissed before
3250 SharedPreferences prefs =
3251 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003252 if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003253 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003254 } else {
3255 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003256 }
3257 }
3258 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003259 // Enable the clings only if they have not been dismissed before
3260 SharedPreferences prefs =
3261 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003262 if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003263 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003264 } else {
3265 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003266 }
3267 }
3268 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003269 // Enable the clings only if they have not been dismissed before
3270 SharedPreferences prefs =
3271 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
3272 Cling cling = null;
Winson Chung9d9d74f2011-09-19 11:49:12 -07003273 if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003274 cling = initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003275 } else {
3276 removeCling(R.id.folder_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003277 }
3278 return cling;
3279 }
3280 public boolean isFolderClingVisible() {
3281 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003282 if (cling != null) {
3283 return cling.getVisibility() == View.VISIBLE;
3284 }
3285 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003286 }
Winson Chung82f55532011-08-09 14:14:23 -07003287 public void dismissWorkspaceCling(View v) {
3288 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003289 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003290 }
3291 public void dismissAllAppsCling(View v) {
3292 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003293 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3294 }
3295 public void dismissFolderCling(View v) {
3296 Cling cling = (Cling) findViewById(R.id.folder_cling);
3297 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003298 }
3299
Winson Chung80baf5a2010-08-09 16:03:15 -07003300 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003301 * Prints out out state for debugging.
3302 */
3303 public void dumpState() {
3304 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003305 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003306 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3307 Log.d(TAG, "mRestoring=" + mRestoring);
3308 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3309 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003310 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003311 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003312
Winson Chung785d2eb2011-04-14 16:08:02 -07003313 if (mAppsCustomizeContent != null) {
3314 mAppsCustomizeContent.dumpState();
3315 }
Joe Onoratobe386092009-11-17 17:32:16 -08003316 Log.d(TAG, "END launcher2 dump state");
3317 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003318
3319 @Override
3320 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3321 super.dump(prefix, fd, writer, args);
3322 writer.println(" ");
3323 writer.println("Debug logs: ");
3324 for (int i = 0; i < sDumpLogs.size(); i++) {
3325 writer.println(" " + sDumpLogs.get(i));
3326 }
3327 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003328}
Michael Jurka2763be32011-02-24 11:19:57 -08003329
Michael Jurkaabded662011-03-04 12:06:57 -08003330interface LauncherTransitionable {
Michael Jurka1899a362011-11-03 13:50:45 -07003331 // return true if the callee will take care of start the animation by itself
3332 boolean onLauncherTransitionStart(Launcher l, Animator animation, boolean toWorkspace);
Winson Chung7d7541e2011-09-16 20:14:36 -07003333 void onLauncherTransitionEnd(Launcher l, Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003334}