blob: 0b93b66e1ba5568f3989ed64ac9029d6724d2bd0 [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";
Adam Cohen23a4d302011-12-01 17:26:44 -0800142 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
144 // Type: int
145 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700146 // Type: int
147 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700149 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
150 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
152 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700153 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700155 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156 // Type: boolean
157 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
158 // Type: long
159 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
160
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700161 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
162
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700163 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700164 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700165 private State mState = State.WORKSPACE;
166 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800167 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700168
Joe Onorato9c1289c2009-08-17 11:03:03 -0400169 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700170 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
171 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700172 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700173 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800176 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800178 private final BroadcastReceiver mCloseSystemDialogsReceiver
179 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800180 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 private LayoutInflater mInflater;
183
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800185 private View mQsbDivider;
186 private View mDockDivider;
187 private DragLayer mDragLayer;
188 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700189
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700190 private AppWidgetManager mAppWidgetManager;
191 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700192
Michael Jurkac9d95c52011-08-29 14:03:34 -0700193 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700194 private int[] mTmpAddItemCellCoordinates = new int[2];
195
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196 private FolderInfo mFolderInfo;
197
Winson Chung3d503fb2011-07-13 17:25:49 -0700198 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800199 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700200
Winson Chungc51db6a2011-10-05 11:44:49 -0700201 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700202 private AppsCustomizeTabHost mAppsCustomizeTabHost;
203 private AppsCustomizePagedView mAppsCustomizeContent;
204 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206 private Bundle mSavedState;
207
208 private SpannableStringBuilder mDefaultKeySsb = null;
209
Joe Onorato9c1289c2009-08-17 11:03:03 -0400210 private boolean mWorkspaceLoading = true;
211
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800212 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213 private boolean mRestoring;
214 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700215 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216
217 private Bundle mSavedInstanceState;
218
Joe Onorato9c1289c2009-08-17 11:03:03 -0400219 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800220 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800221 private boolean mUserPresent = true;
222 private boolean mVisible = false;
223 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400224
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700225 private static LocaleConfiguration sLocaleConfiguration = null;
226
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700227 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700228
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700229 private Intent mAppMarketIntent = null;
230
Adam Cohended9f8d2010-11-03 13:25:16 -0700231 // Related to the auto-advancing of widgets
232 private final int ADVANCE_MSG = 1;
233 private final int mAdvanceInterval = 20000;
234 private final int mAdvanceStagger = 250;
235 private long mAutoAdvanceSentTime;
236 private long mAutoAdvanceTimeLeft = -1;
237 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
238 new HashMap<View, AppWidgetProviderInfo>();
239
Winson Chung400438b2011-01-16 17:53:48 -0800240 // Determines how long to wait after a rotation before restoring the screen orientation to
241 // match the sensor state.
242 private final int mRestoreScreenOrientationDelay = 500;
243
Michael Jurka4ef207b2010-11-29 17:05:45 -0800244 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700245 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
246 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
247 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800248
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700249 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
250
Adam Cohen2801caf2011-05-13 20:57:39 -0700251
Michael Jurkaddd62e92011-02-16 17:49:14 -0800252 private BubbleTextView mWaitingForResume;
253
Michael Jurkac1f5d262011-09-30 19:32:27 -0700254 private Runnable mBuildLayersRunnable = new Runnable() {
255 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700256 if (mWorkspace != null) {
257 mWorkspace.buildPageHardwareLayers();
258 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700259 }
260 };
261
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800262 private static ArrayList<PendingAddArguments> sPendingAddList
263 = new ArrayList<PendingAddArguments>();
264
265 private static class PendingAddArguments {
266 int requestCode;
267 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700268 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800269 int screen;
270 int cellX;
271 int cellY;
272 }
273
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800274 @Override
275 protected void onCreate(Bundle savedInstanceState) {
276 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800277 LauncherApplication app = ((LauncherApplication)getApplication());
278 mModel = app.setLauncher(this);
279 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400280 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800281 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700282
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700283 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700284 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
285 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700286
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200288 android.os.Debug.startMethodTracing(
289 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800290 }
291
292 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800293 setContentView(R.layout.launcher);
294 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700295 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800296
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800297 registerContentObservers();
298
Joe Onorato7c312c12009-08-13 21:36:53 -0700299 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700300
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800301 mSavedState = savedInstanceState;
302 restoreState(mSavedState);
303
Winson Chunga12a2502010-12-20 14:41:35 -0800304 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700305 if (mAppsCustomizeContent != null) {
306 mAppsCustomizeContent.onPackagesUpdated();
307 }
Winson Chunga12a2502010-12-20 14:41:35 -0800308
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800309 if (PROFILE_STARTUP) {
310 android.os.Debug.stopMethodTracing();
311 }
312
313 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400314 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800315 }
316
Michael Jurkac57b7a82011-08-09 22:02:20 -0700317 if (!mModel.isAllAppsLoaded()) {
318 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
319 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
320 }
321
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800322 // For handling default keys
323 mDefaultKeySsb = new SpannableStringBuilder();
324 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800325
326 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
327 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800328
Winson Chungc51db6a2011-10-05 11:44:49 -0700329 boolean searchVisible = false;
330 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800331 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700332 int coi = getCurrentOrientationIndexForGlobalIcons();
333 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
334 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700335 updateAppMarketIcon();
336 searchVisible = updateGlobalSearchIcon();
337 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700338 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700339 if (sGlobalSearchIcon[coi] != null) {
340 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700341 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700342 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700343 if (sVoiceSearchIcon[coi] != null) {
344 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700345 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700346 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700347 if (sAppMarketIcon[coi] != null) {
348 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800349 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700350 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Adam Cohen446e9402011-09-15 18:21:21 -0700351
Adam Cohen23a4d302011-12-01 17:26:44 -0800352 final String forceEnableRotation =
353 SystemProperties.get(FORCE_ENABLE_ROTATION_PROPERTY, "false");
354
Adam Cohen446e9402011-09-15 18:21:21 -0700355 // On large interfaces, we want the screen to auto-rotate based on the current orientation
Adam Cohen23a4d302011-12-01 17:26:44 -0800356 if (LauncherApplication.isScreenLarge() || "true".equalsIgnoreCase(forceEnableRotation)) {
Adam Cohen446e9402011-09-15 18:21:21 -0700357 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
358 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359 }
Romain Guycbb89e42009-06-08 15:52:54 -0700360
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700362 if (sLocaleConfiguration == null) {
363 new AsyncTask<Void, Void, LocaleConfiguration>() {
364 @Override
365 protected LocaleConfiguration doInBackground(Void... unused) {
366 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
367 readConfiguration(Launcher.this, localeConfiguration);
368 return localeConfiguration;
369 }
370
371 @Override
372 protected void onPostExecute(LocaleConfiguration result) {
373 sLocaleConfiguration = result;
374 checkForLocaleChange(); // recursive, but now with a locale configuration
375 }
376 }.execute();
377 return;
378 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700379
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380 final Configuration configuration = getResources().getConfiguration();
381
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700382 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800383 final String locale = configuration.locale.toString();
384
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700385 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800386 final int mcc = configuration.mcc;
387
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700388 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800389 final int mnc = configuration.mnc;
390
Romain Guy84f296c2009-11-04 15:00:44 -0800391 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800392
Romain Guy84f296c2009-11-04 15:00:44 -0800393 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700394 sLocaleConfiguration.locale = locale;
395 sLocaleConfiguration.mcc = mcc;
396 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700397
Joe Onorato0589f0f2010-02-08 13:44:00 -0800398 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700399
400 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
401 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700402 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700403 public void run() {
404 writeConfiguration(Launcher.this, localeConfiguration);
405 }
406 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700407 }
408 }
409
410 private static class LocaleConfiguration {
411 public String locale;
412 public int mcc = -1;
413 public int mnc = -1;
414 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700415
Romain Guy98d01652009-06-30 16:21:04 -0700416 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
417 DataInputStream in = null;
418 try {
419 in = new DataInputStream(context.openFileInput(PREFERENCES));
420 configuration.locale = in.readUTF();
421 configuration.mcc = in.readInt();
422 configuration.mnc = in.readInt();
423 } catch (FileNotFoundException e) {
424 // Ignore
425 } catch (IOException e) {
426 // Ignore
427 } finally {
428 if (in != null) {
429 try {
430 in.close();
431 } catch (IOException e) {
432 // Ignore
433 }
434 }
435 }
436 }
437
438 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
439 DataOutputStream out = null;
440 try {
441 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
442 out.writeUTF(configuration.locale);
443 out.writeInt(configuration.mcc);
444 out.writeInt(configuration.mnc);
445 out.flush();
446 } catch (FileNotFoundException e) {
447 // Ignore
448 } catch (IOException e) {
449 //noinspection ResultOfMethodCallIgnored
450 context.getFileStreamPath(PREFERENCES).delete();
451 } finally {
452 if (out != null) {
453 try {
454 out.close();
455 } catch (IOException e) {
456 // Ignore
457 }
458 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459 }
460 }
461
Adam Cohen716b51e2011-06-30 12:09:54 -0700462 public DragLayer getDragLayer() {
463 return mDragLayer;
464 }
465
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800466 static int getScreen() {
467 synchronized (sLock) {
468 return sScreen;
469 }
470 }
471
472 static void setScreen(int screen) {
473 synchronized (sLock) {
474 sScreen = screen;
475 }
476 }
477
Winson Chung557d6ed2011-07-08 15:34:52 -0700478 /**
479 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
480 * a configuration step, this allows the proper animations to run after other transitions.
481 */
482 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700483 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800484 switch (args.requestCode) {
485 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700486 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
487 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800488 break;
489 case REQUEST_PICK_SHORTCUT:
490 processShortcut(args.intent);
491 break;
492 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700493 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
494 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700495 result = true;
496 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800497 case REQUEST_PICK_APPWIDGET:
498 addAppWidgetFromPick(args.intent);
499 break;
500 case REQUEST_CREATE_APPWIDGET:
501 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Winson Chung3d503fb2011-07-13 17:25:49 -0700502 completeAddAppWidget(appWidgetId, args.container, args.screen);
Winson Chungb8472bb2011-08-05 13:49:21 -0700503 result = true;
504 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800505 case REQUEST_PICK_WALLPAPER:
506 // We just wanted the activity result here so we can clear mWaitingForResult
507 break;
508 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700509 // In any situation where we have a multi-step drop, we should reset the add info only after
510 // we complete the drop
511 resetAddInfo();
512 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800513 }
514
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800515 @Override
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800516 protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700517 boolean delayExitSpringLoadedMode = false;
Romain Guyaad5ef42009-06-10 02:48:37 -0700518 mWaitingForResult = false;
519
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800520 // The pattern used here is that a user PICKs a specific application,
521 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700522
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800523 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
524 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700525 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800526 final PendingAddArguments args = new PendingAddArguments();
527 args.requestCode = requestCode;
528 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700529 args.container = mPendingAddInfo.container;
530 args.screen = mPendingAddInfo.screen;
531 args.cellX = mPendingAddInfo.cellX;
532 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800533
534 // If the loader is still running, defer the add until it is done.
535 if (isWorkspaceLocked()) {
536 sPendingAddList.add(args);
537 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700538 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800539 }
Romain Guy18042c82009-11-06 11:44:55 -0800540 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
Winson Chung557d6ed2011-07-08 15:34:52 -0700541 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED) {
542 if (data != null) {
543 // Clean up the appWidgetId if we canceled
544 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
545 if (appWidgetId != -1) {
546 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
547 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800548 }
549 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700550
551 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700552 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800553 }
554
555 @Override
556 protected void onResume() {
557 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800558 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700559 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400560 mWorkspaceLoading = true;
561 mModel.startLoader(this, true);
562 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700563 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 }
Michael Jurkaddd62e92011-02-16 17:49:14 -0800565 if (mWaitingForResume != null) {
566 mWaitingForResume.setStayPressed(false);
567 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700568 // When we resume Launcher, a different Activity might be responsible for the app
569 // market intent, so refresh the icon
570 updateAppMarketIcon();
Michael Jurkae326f182011-11-21 14:05:46 -0800571 mAppsCustomizeTabHost.onResume();
Michael Jurkac1f5d262011-09-30 19:32:27 -0700572 if (!mWorkspaceLoading) {
Michael Jurkab737ee62011-11-15 15:57:22 -0800573 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
574 final Workspace workspace = mWorkspace;
575 // We want to let Launcher draw itself at least once before we force it to build
576 // layers on all the workspace pages, so that transitioning to Launcher from other
577 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
578 // a true draw so we wait until the second preDraw call to be safe
579 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
580 boolean mFirstTime = true;
581 public boolean onPreDraw() {
582 if (mFirstTime) {
583 mFirstTime = false;
584 } else {
585 workspace.post(mBuildLayersRunnable);
586 observer.removeOnPreDrawListener(this);
587 }
588 return true;
589 }
590 });
Michael Jurkac1f5d262011-09-30 19:32:27 -0700591 }
Mathew Inwood8193f692011-10-12 17:30:58 +0100592 clearTypedText();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800593 }
594
595 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700596 protected void onPause() {
597 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700598 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800599 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700600 }
Romain Guycbb89e42009-06-08 15:52:54 -0700601
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700602 @Override
603 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400604 // Flag the loader to stop early before switching
605 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700606 if (mAppsCustomizeContent != null) {
607 mAppsCustomizeContent.surrender();
608 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800609 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700610 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700611
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800612 // We can't hide the IME if it was forced open. So don't bother
613 /*
614 @Override
615 public void onWindowFocusChanged(boolean hasFocus) {
616 super.onWindowFocusChanged(hasFocus);
617
618 if (hasFocus) {
619 final InputMethodManager inputManager = (InputMethodManager)
620 getSystemService(Context.INPUT_METHOD_SERVICE);
621 WindowManager.LayoutParams lp = getWindow().getAttributes();
622 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
623 android.os.Handler()) {
624 protected void onReceiveResult(int resultCode, Bundle resultData) {
625 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
626 }
627 });
628 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
629 }
630 }
631 */
632
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800633 private boolean acceptFilter() {
634 final InputMethodManager inputManager = (InputMethodManager)
635 getSystemService(Context.INPUT_METHOD_SERVICE);
636 return !inputManager.isFullscreenMode();
637 }
638
639 @Override
640 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700641 final int uniChar = event.getUnicodeChar();
642 final boolean handled = super.onKeyDown(keyCode, event);
643 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
644 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800645 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
646 keyCode, event);
647 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700648 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700649 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700650 // showSearchDialog()
651 // If there are multiple keystrokes before the search dialog takes focus,
652 // onSearchRequested() will be called for every keystroke,
653 // but it is idempotent, so it's fine.
654 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 }
656 }
657
Joe Onorato8a9625e2010-01-28 15:55:35 -0800658 // Eat the long press event so the keyboard doesn't come up.
659 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
660 return true;
661 }
662
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 return handled;
664 }
665
Karl Rosaen138a0412009-04-23 19:00:21 -0700666 private String getTypedText() {
667 return mDefaultKeySsb.toString();
668 }
669
670 private void clearTypedText() {
671 mDefaultKeySsb.clear();
672 mDefaultKeySsb.clearSpans();
673 Selection.setSelection(mDefaultKeySsb, 0);
674 }
675
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800676 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700677 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
678 * State
679 */
680 private static State intToState(int stateOrdinal) {
681 State state = State.WORKSPACE;
682 final State[] stateValues = State.values();
683 for (int i = 0; i < stateValues.length; i++) {
684 if (stateValues[i].ordinal() == stateOrdinal) {
685 state = stateValues[i];
686 break;
687 }
688 }
689 return state;
690 }
691
692 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 * Restores the previous state, if it exists.
694 *
695 * @param savedState The previous state.
696 */
697 private void restoreState(Bundle savedState) {
698 if (savedState == null) {
699 return;
700 }
701
Michael Jurka883f55b2010-10-21 15:47:14 -0700702 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700703 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800704 showAllApps(false);
705 }
706
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800707 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
708 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700709 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800710 }
711
Winson Chung3d503fb2011-07-13 17:25:49 -0700712 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
713 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700714
Winson Chung3d503fb2011-07-13 17:25:49 -0700715 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
716 mPendingAddInfo.container = pendingAddContainer;
717 mPendingAddInfo.screen = pendingAddScreen;
718 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
719 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800720 mRestoring = true;
721 }
722
723 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
724 if (renameFolder) {
725 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700726 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800727 mRestoring = true;
728 }
Winson Chunga12a2502010-12-20 14:41:35 -0800729
Winson Chung785d2eb2011-04-14 16:08:02 -0700730
731 // Restore the AppsCustomize tab
732 if (mAppsCustomizeTabHost != null) {
733 String curTab = savedState.getString("apps_customize_currentTab");
734 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700735 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700736 mAppsCustomizeContent.setContentType(
737 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
738 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700739 mAppsCustomizeContent.loadAssociatedPages(
740 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700741 }
742
Winson Chung5afbf7b2011-07-25 11:53:08 -0700743 int currentIndex = savedState.getInt("apps_customize_currentIndex");
744 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700745 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800746 }
747
748 /**
749 * Finds all the views we need and configure them properly.
750 */
751 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700752 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400753
Winson Chung4c98d922011-05-31 16:50:48 -0700754 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
755 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800756 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
757 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758
Winson Chung4c98d922011-05-31 16:50:48 -0700759 // Setup the drag layer
760 mDragLayer.setup(this, dragController);
761
Winson Chung3d503fb2011-07-13 17:25:49 -0700762 // Setup the hotseat
763 mHotseat = (Hotseat) findViewById(R.id.hotseat);
764 if (mHotseat != null) {
765 mHotseat.setup(this);
766 }
767
Winson Chung4c98d922011-05-31 16:50:48 -0700768 // Setup the workspace
769 mWorkspace.setHapticFeedbackEnabled(false);
770 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700771 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700772 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700773
Winson Chungf0ea4d32011-06-06 14:27:16 -0700774 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700775 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700776
Winson Chungf0ea4d32011-06-06 14:27:16 -0700777 // Setup AppsCustomize
778 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
779 findViewById(R.id.apps_customize_pane);
780 mAppsCustomizeContent = (AppsCustomizePagedView)
781 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
782 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400783
Michael Jurka5130e402011-10-13 04:55:35 -0700784 // Get the all apps button
785 mAllAppsButton = findViewById(R.id.all_apps_button);
786 if (mAllAppsButton != null) {
787 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
788 @Override
789 public boolean onTouch(View v, MotionEvent event) {
790 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
791 onTouchDownAllAppsButton(v);
792 }
793 return false;
794 }
795 });
796 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700797 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700798 dragController.setDragScoller(mWorkspace);
799 dragController.setScrollView(mDragLayer);
800 dragController.setMoveTarget(mWorkspace);
801 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700802 if (mSearchDropTargetBar != null) {
803 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800804 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800805 }
806
807 /**
808 * Creates a view representing a shortcut.
809 *
810 * @param info The data structure describing the shortcut.
811 *
812 * @return A View inflated from R.layout.application.
813 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800814 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800815 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700816 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 }
818
819 /**
820 * Creates a view representing a shortcut inflated from the specified resource.
821 *
822 * @param layoutResId The id of the XML layout used to create the shortcut.
823 * @param parent The group the shortcut belongs to.
824 * @param info The data structure describing the shortcut.
825 *
826 * @return A View inflated from layoutResId.
827 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800828 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800829 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
830 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800831 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800832 return favorite;
833 }
834
835 /**
836 * Add an application shortcut to the workspace.
837 *
838 * @param data The intent describing the application.
839 * @param cellInfo The position on screen where to create the shortcut.
840 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700841 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700842 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700843 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700844
Adam Cohenfbba09b2011-07-18 21:43:05 -0700845 // First we check if we already know the exact location where we want to add this item.
846 if (cellX >= 0 && cellY >= 0) {
847 cellXY[0] = cellX;
848 cellXY[1] = cellY;
849 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700850 showOutOfSpaceMessage();
851 return;
852 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800854 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800855
Romain Guy73b979d2009-06-09 12:57:21 -0700856 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800857 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800858 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800859 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700860 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700861 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800862 } else {
863 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800864 }
865 }
Romain Guycbb89e42009-06-08 15:52:54 -0700866
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 /**
868 * Add a shortcut to the workspace.
869 *
870 * @param data The intent describing the shortcut.
871 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800872 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700873 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
874 int cellY) {
875 int[] cellXY = mTmpAddItemCellCoordinates;
876 int[] touchXY = mPendingAddInfo.dropPos;
877 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700878
Michael Jurkad3ef3062010-11-23 16:23:58 -0800879 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700880
Adam Cohen558baaf2011-08-15 15:22:57 -0700881 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800882 if (info == null) {
883 return;
884 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700885 final View view = createShortcut(info);
886
Adam Cohenfbba09b2011-07-18 21:43:05 -0700887 // First we check if we already know the exact location where we want to add this item.
888 if (cellX >= 0 && cellY >= 0) {
889 cellXY[0] = cellX;
890 cellXY[1] = cellY;
891 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700892
893 // If appropriate, either create a folder or add to an existing folder
894 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
895 true, null,null)) {
896 return;
897 }
898 DragObject dragObject = new DragObject();
899 dragObject.dragInfo = info;
900 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
901 return;
902 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700903 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800904 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700905 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800906 foundCellSpan = (result != null);
907 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700908 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800909 }
910
911 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700912 showOutOfSpaceMessage();
913 return;
914 }
915
Adam Cohen558baaf2011-08-15 15:22:57 -0700916 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800917
918 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700919 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
920 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800921 }
922 }
923
Adam Cohenf814aa02011-09-01 13:48:05 -0700924 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
925 if (spanXY == null) {
926 spanXY = new int[2];
927 }
928
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800929 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700930 // We want to account for the extra amount of padding that we are adding to the widget
931 // to ensure that it gets the full amount of space that it has requested
932 int requiredWidth = minWidth + padding.left + padding.right;
933 int requiredHeight = minHeight + padding.top + padding.bottom;
934 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
935 }
936
937 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
938 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
939 }
940
Adam Cohencbf47e32011-09-16 17:32:37 -0700941 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
942 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
943 }
944
Adam Cohenf814aa02011-09-01 13:48:05 -0700945 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
946 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
947 }
948
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800949 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700950 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800951 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700952 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700953 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800954 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700955 private void completeAddAppWidget(final int appWidgetId, long container, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700956 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700957
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700958 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700959 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700960
Adam Cohenf814aa02011-09-01 13:48:05 -0700961 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700962
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800963 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700964 // We have saved the position to which the widget was dragged-- this really only matters
965 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700966 int[] cellXY = mTmpAddItemCellCoordinates;
967 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700968 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700969 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
970 cellXY[0] = mPendingAddInfo.cellX;
971 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700972 foundCellSpan = true;
973 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700974 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700975 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700976 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800977 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700978 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700979 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700980 }
981
Michael Jurka0280c3b2010-09-17 15:00:07 -0700982 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -0800983 if (appWidgetId != -1) {
984 // Deleting an app widget ID is a void call but writes to disk before returning
985 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -0800986 new Thread("deleteAppWidgetId") {
987 public void run() {
988 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
989 }
990 }.start();
991 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700992 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -0800993 return;
994 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800995
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700996 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -0700997 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700998 launcherInfo.spanX = spanXY[0];
999 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001000
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001001 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001002 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001003
1004 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001005 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001006 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001007
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001008 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001009 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001010
Winson Chung3d503fb2011-07-13 17:25:49 -07001011 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001012 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001013
1014 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001015 }
1016 }
Romain Guycbb89e42009-06-08 15:52:54 -07001017
Adam Cohended9f8d2010-11-03 13:25:16 -07001018 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1019 @Override
1020 public void onReceive(Context context, Intent intent) {
1021 final String action = intent.getAction();
1022 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1023 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001024 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001025 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001026
Winson Chungc100e8e2011-08-09 16:02:43 -07001027 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001028 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001029 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1030 mAppsCustomizeTabHost.reset();
1031 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001032 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001033 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1034 mUserPresent = true;
1035 updateRunning();
1036 }
1037 }
1038 };
1039
1040 @Override
1041 public void onAttachedToWindow() {
1042 super.onAttachedToWindow();
1043
1044 // Listen for broadcasts related to user-presence
1045 final IntentFilter filter = new IntentFilter();
1046 filter.addAction(Intent.ACTION_SCREEN_OFF);
1047 filter.addAction(Intent.ACTION_USER_PRESENT);
1048 registerReceiver(mReceiver, filter);
1049
Adam Cohend113e0c2010-11-11 10:48:05 -08001050 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001051 mVisible = true;
1052 }
1053
1054 @Override
1055 public void onDetachedFromWindow() {
1056 super.onDetachedFromWindow();
1057 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001058 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001059
Adam Cohend113e0c2010-11-11 10:48:05 -08001060 if (mAttached) {
1061 unregisterReceiver(mReceiver);
1062 mAttached = false;
1063 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001064 updateRunning();
1065 }
1066
1067 public void onWindowVisibilityChanged(int visibility) {
1068 mVisible = visibility == View.VISIBLE;
1069 updateRunning();
1070 }
1071
1072 private void sendAdvanceMessage(long delay) {
1073 mHandler.removeMessages(ADVANCE_MSG);
1074 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1075 mHandler.sendMessageDelayed(msg, delay);
1076 mAutoAdvanceSentTime = System.currentTimeMillis();
1077 }
1078
1079 private void updateRunning() {
1080 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1081 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1082 mAutoAdvanceRunning = autoAdvanceRunning;
1083 if (autoAdvanceRunning) {
1084 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1085 sendAdvanceMessage(delay);
1086 } else {
1087 if (!mWidgetsToAdvance.isEmpty()) {
1088 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1089 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1090 }
1091 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001092 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001093 }
1094 }
1095 }
1096
1097 private final Handler mHandler = new Handler() {
1098 @Override
1099 public void handleMessage(Message msg) {
1100 if (msg.what == ADVANCE_MSG) {
1101 int i = 0;
1102 for (View key: mWidgetsToAdvance.keySet()) {
1103 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1104 final int delay = mAdvanceStagger * i;
1105 if (v instanceof Advanceable) {
1106 postDelayed(new Runnable() {
1107 public void run() {
1108 ((Advanceable) v).advance();
1109 }
1110 }, delay);
1111 }
1112 i++;
1113 }
1114 sendAdvanceMessage(mAdvanceInterval);
1115 }
1116 }
1117 };
1118
1119 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001120 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001121 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1122 if (v instanceof Advanceable) {
1123 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001124 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001125 updateRunning();
1126 }
1127 }
1128
1129 void removeWidgetToAutoAdvance(View hostView) {
1130 if (mWidgetsToAdvance.containsKey(hostView)) {
1131 mWidgetsToAdvance.remove(hostView);
1132 updateRunning();
1133 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001134 }
1135
Joe Onorato9c1289c2009-08-17 11:03:03 -04001136 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001137 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001138 launcherInfo.hostView = null;
1139 }
1140
Adam Cohended9f8d2010-11-03 13:25:16 -07001141 void showOutOfSpaceMessage() {
1142 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1143 }
1144
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001145 public LauncherAppWidgetHost getAppWidgetHost() {
1146 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147 }
Romain Guycbb89e42009-06-08 15:52:54 -07001148
Winson Chunga9abd0e2010-10-27 17:18:37 -07001149 public LauncherModel getModel() {
1150 return mModel;
1151 }
1152
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001153 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001154 getWindow().closeAllPanels();
1155
Winson Chung87acb482011-08-23 17:28:05 -07001156 /**
1157 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001158 try {
1159 dismissDialog(DIALOG_CREATE_SHORTCUT);
1160 // Unlock the workspace if the dialog was showing
1161 } catch (Exception e) {
1162 // An exception is thrown if the dialog is not visible, which is fine
1163 }
1164
1165 try {
1166 dismissDialog(DIALOG_RENAME_FOLDER);
1167 // Unlock the workspace if the dialog was showing
1168 } catch (Exception e) {
1169 // An exception is thrown if the dialog is not visible, which is fine
1170 }
Winson Chung87acb482011-08-23 17:28:05 -07001171 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001172
1173 // Whatever we were doing is hereby canceled.
1174 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001175 }
1176
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 @Override
1178 protected void onNewIntent(Intent intent) {
1179 super.onNewIntent(intent);
1180
1181 // Close the menu
1182 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001183 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001184 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001185
Joe Onorato14f122b2009-11-19 14:06:36 -08001186 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1187 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001188
Adam Cohenac56cff2011-09-28 20:45:37 -07001189 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001190 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001191 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001192 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1193 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001194 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001195 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001196
1197 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001198 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001199 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001200
Joe Onorato3a8820b2009-11-10 15:06:42 -08001201 final View v = getWindow().peekDecorView();
1202 if (v != null && v.getWindowToken() != null) {
1203 InputMethodManager imm = (InputMethodManager)getSystemService(
1204 INPUT_METHOD_SERVICE);
1205 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001206 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001207
Michael Jurka35aa14d2011-07-07 17:01:08 -07001208 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001209 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001210 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001211 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 }
1213 }
1214
1215 @Override
1216 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1217 // Do not call super here
1218 mSavedInstanceState = savedInstanceState;
1219 }
1220
1221 @Override
1222 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001223 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001224 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001225
Michael Jurka883f55b2010-10-21 15:47:14 -07001226 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001227 // We close any open folder since it will not be re-opened, and we need to make sure
1228 // this state is reflected.
1229 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230
Winson Chung3d503fb2011-07-13 17:25:49 -07001231 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1232 mWaitingForResult) {
1233 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1234 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1235 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1236 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237 }
1238
1239 if (mFolderInfo != null && mWaitingForResult) {
1240 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1241 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1242 }
Michael Jurka946ad472010-07-09 18:05:18 -07001243
Winson Chung785d2eb2011-04-14 16:08:02 -07001244 // Save the current AppsCustomize tab
1245 if (mAppsCustomizeTabHost != null) {
1246 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1247 if (currentTabTag != null) {
1248 outState.putString("apps_customize_currentTab", currentTabTag);
1249 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001250 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1251 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001252 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253 }
1254
1255 @Override
1256 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001258
Winson Chunge7a03942011-08-05 15:05:12 -07001259 // Remove all pending runnables
1260 mHandler.removeMessages(ADVANCE_MSG);
1261 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001262 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001263
Winson Chungcd2b0142011-06-08 16:02:26 -07001264 // Stop callbacks from LauncherModel
1265 LauncherApplication app = ((LauncherApplication) getApplication());
1266 mModel.stopLoader();
1267 app.setLauncher(null);
1268
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001269 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001270 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001271 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001272 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001273 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001274 mAppWidgetHost = null;
1275
1276 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001277
1278 TextKeyListener.getInstance().release();
1279
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001280
Winson Chung3d503fb2011-07-13 17:25:49 -07001281 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001282
1283 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001284 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001285
1286 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1287 mWorkspace.removeAllViews();
1288 mWorkspace = null;
1289 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001290
1291 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001292 }
1293
Adam Cohena9cf38f2011-05-02 15:36:58 -07001294 public DragController getDragController() {
1295 return mDragController;
1296 }
1297
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001298 @Override
1299 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001300 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301 super.startActivityForResult(intent, requestCode);
1302 }
1303
Winson Chung70d72102011-08-12 11:24:35 -07001304 /**
1305 * Indicates that we want global search for this activity by setting the globalSearch
1306 * argument for {@link #startSearch} to true.
1307 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001308 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001309 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001311
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001312 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001313
Karl Rosaen138a0412009-04-23 19:00:21 -07001314 if (initialQuery == null) {
1315 // Use any text typed in the launcher as the initial query
1316 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001317 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 if (appSearchData == null) {
1319 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001320 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001322 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001323
Karl Rosaen138a0412009-04-23 19:00:21 -07001324 final SearchManager searchManager =
1325 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001326 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001327 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 }
1329
Winson Chung70d72102011-08-12 11:24:35 -07001330 @Override
1331 public boolean onCreateOptionsMenu(Menu menu) {
1332 if (isWorkspaceLocked()) {
1333 return false;
1334 }
1335
1336 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001337
1338 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1339 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1340 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001341 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1342 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1343 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001344 String helpUrl = getString(R.string.help_url);
1345 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001346 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1347 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1348
Winson Chung70d72102011-08-12 11:24:35 -07001349 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1350 .setIcon(android.R.drawable.ic_menu_gallery)
1351 .setAlphabeticShortcut('W');
1352 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1353 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001354 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001355 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001356 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1357 .setIcon(android.R.drawable.ic_menu_preferences)
1358 .setIntent(settings)
1359 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001360 if (!helpUrl.isEmpty()) {
1361 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1362 .setIcon(android.R.drawable.ic_menu_help)
1363 .setIntent(help)
1364 .setAlphabeticShortcut('H');
1365 }
Winson Chung70d72102011-08-12 11:24:35 -07001366 return true;
1367 }
1368
1369 @Override
1370 public boolean onPrepareOptionsMenu(Menu menu) {
1371 super.onPrepareOptionsMenu(menu);
1372
1373 if (mAppsCustomizeTabHost.isTransitioning()) {
1374 return false;
1375 }
1376 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1377 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1378
1379 return true;
1380 }
1381
1382 @Override
1383 public boolean onOptionsItemSelected(MenuItem item) {
1384 switch (item.getItemId()) {
1385 case MENU_WALLPAPER_SETTINGS:
1386 startWallpaper();
1387 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001388 }
1389
1390 return super.onOptionsItemSelected(item);
1391 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001392
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001393 @Override
1394 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001395 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001396 // Use a custom animation for launching search
1397 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001398 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001399 }
1400
Joe Onorato9c1289c2009-08-17 11:03:03 -04001401 public boolean isWorkspaceLocked() {
1402 return mWorkspaceLoading || mWaitingForResult;
1403 }
1404
Michael Jurka0280c3b2010-09-17 15:00:07 -07001405 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001406 mPendingAddInfo.container = ItemInfo.NO_ID;
1407 mPendingAddInfo.screen = -1;
1408 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1409 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1410 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001411 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001412
Michael Jurkaaf442092010-06-10 17:01:57 -07001413 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001414 // TODO: catch bad widget exception when sent
1415 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001416 // TODO: Is this log message meaningful?
1417 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001418 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001419 }
1420
Winson Chung55cef262010-10-28 14:14:18 -07001421 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001422 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423
Bjorn Bringert7984c942009-12-09 15:38:25 +00001424 if (appWidget.configure != null) {
1425 // Launch over to configure widget, if needed
1426 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1427 intent.setComponent(appWidget.configure);
1428 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001429 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001430 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1431 intent.putExtra(
1432 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1433 info.mimeType);
1434
1435 final String mimeType = info.mimeType;
1436 final ClipData clipData = (ClipData) info.configurationData;
1437 final ClipDescription clipDesc = clipData.getDescription();
1438 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1439 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001440 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001441 final CharSequence stringData = item.getText();
1442 final Uri uriData = item.getUri();
1443 final Intent intentData = item.getIntent();
1444 final String key =
1445 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1446 if (uriData != null) {
1447 intent.putExtra(key, uriData);
1448 } else if (intentData != null) {
1449 intent.putExtra(key, intentData);
1450 } else if (stringData != null) {
1451 intent.putExtra(key, stringData);
1452 }
1453 break;
1454 }
1455 }
1456 }
Winson Chung55cef262010-10-28 14:14:18 -07001457 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001458
Romain Guy8e633c52010-03-04 12:51:36 -08001459 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001460 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001461 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001462 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001463
1464 // Exit spring loaded mode if necessary after adding the widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001465 exitSpringLoadedDragModeDelayed(true, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 }
1467 }
Romain Guycbb89e42009-06-08 15:52:54 -07001468
Adam Cohenfbba09b2011-07-18 21:43:05 -07001469 /**
1470 * Process a shortcut drop.
1471 *
1472 * @param componentName The name of the component
1473 * @param screen The screen where it should be added
1474 * @param cell The cell it should be added to, optional
1475 * @param position The location on the screen where it was dropped, optional
1476 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001477 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1478 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001479 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001480 mPendingAddInfo.container = container;
1481 mPendingAddInfo.screen = screen;
1482 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001483
1484 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001485 mPendingAddInfo.cellX = cell[0];
1486 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001487 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001488
1489 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1490 createShortcutIntent.setComponent(componentName);
1491 processShortcut(createShortcutIntent);
1492 }
1493
Adam Cohenfbba09b2011-07-18 21:43:05 -07001494 /**
1495 * Process a widget drop.
1496 *
1497 * @param info The PendingAppWidgetInfo of the widget being added.
1498 * @param screen The screen where it should be added
1499 * @param cell The cell it should be added to, optional
1500 * @param position The location on the screen where it was dropped, optional
1501 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001502 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1503 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001504 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001505 mPendingAddInfo.container = info.container = container;
1506 mPendingAddInfo.screen = info.screen = screen;
1507 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001508 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001509 mPendingAddInfo.cellX = cell[0];
1510 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001511 }
1512
1513 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1514 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1515 addAppWidgetImpl(appWidgetId, info);
1516 }
1517
Joe Onoratodeb98af2010-02-19 14:59:39 -08001518 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001519 // Handle case where user selected "Applications"
1520 String applicationName = getResources().getString(R.string.group_applications);
1521 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001522
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001523 if (applicationName != null && applicationName.equals(shortcutName)) {
1524 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1525 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001526
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001527 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1528 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001529 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001530 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001531 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001532 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001533 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001534 }
1535
Winson Chung24ab2f12010-09-16 14:10:47 -07001536 void processWallpaper(Intent intent) {
1537 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1538 }
1539
Winson Chung3d503fb2011-07-13 17:25:49 -07001540 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1541 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001542 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543 folderInfo.title = getText(R.string.folder_name);
1544
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001546 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1547 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001548 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549
1550 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001551 FolderIcon newFolder =
1552 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1553 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1554 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001555 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556 }
Romain Guycbb89e42009-06-08 15:52:54 -07001557
Joe Onorato9c1289c2009-08-17 11:03:03 -04001558 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001559 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001560 }
1561
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001562 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001563 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001564 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001565 Intent chooser = Intent.createChooser(pickWallpaper,
1566 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001567 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1568 // Removed in Eclair MR1
1569// WallpaperManager wm = (WallpaperManager)
1570// getSystemService(Context.WALLPAPER_SERVICE);
1571// WallpaperInfo wi = wm.getWallpaperInfo();
1572// if (wi != null && wi.getSettingsActivity() != null) {
1573// LabeledIntent li = new LabeledIntent(getPackageName(),
1574// R.string.configure_wallpaper, 0);
1575// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1576// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1577// }
Mike Clerona0618e42009-10-22 13:55:21 -07001578 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001579 }
1580
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001581 /**
1582 * Registers various content observers. The current implementation registers
1583 * only a favorites observer to keep track of the favorites applications.
1584 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001585 private void registerContentObservers() {
1586 ContentResolver resolver = getContentResolver();
1587 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1588 true, mWidgetObserver);
1589 }
1590
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001591 @Override
1592 public boolean dispatchKeyEvent(KeyEvent event) {
1593 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1594 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001596 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001597 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001598 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001599 dumpState();
1600 return true;
1601 }
1602 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001603 }
1604 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1605 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001606 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001607 return true;
1608 }
1609 }
1610
1611 return super.dispatchKeyEvent(event);
1612 }
1613
Joe Onorato88ec0992009-11-19 13:16:06 -08001614 @Override
1615 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001616 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001617 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001618 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001619 Folder openFolder = mWorkspace.getOpenFolder();
1620 if (openFolder.isEditingName()) {
1621 openFolder.dismissEditingName();
1622 } else {
1623 closeFolder();
1624 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001625 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001626 mWorkspace.exitWidgetResizeMode();
1627
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001628 // Back button is a no-op here, but give at least some feedback for the button press
1629 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001630 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001631 }
1632
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001633 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001634 * Re-listen when widgets are reset.
1635 */
1636 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001637 if (mAppWidgetHost != null) {
1638 mAppWidgetHost.startListening();
1639 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001640 }
1641
1642 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001643 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1644 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001645 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001646 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001647 if (mModel != null) {
1648 mModel.unbindWorkspaceItems();
1649 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001650 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001651
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001652 /**
1653 * Launches the intent referred by the clicked shortcut.
1654 *
1655 * @param v The view representing the clicked shortcut.
1656 */
1657 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001658 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1659 // view has detached (it's possible for this to happen if the view is removed mid touch).
1660 if (v.getWindowToken() == null) {
1661 return;
1662 }
1663
1664 if (mWorkspace.isSwitchingState()) {
1665 return;
1666 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001667
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001668 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001669 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001670 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001671 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001672 int[] pos = new int[2];
1673 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001674 intent.setSourceBounds(new Rect(pos[0], pos[1],
1675 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001676 boolean success = startActivitySafely(intent, tag);
1677
1678 if (success && v instanceof BubbleTextView) {
1679 mWaitingForResume = (BubbleTextView) v;
1680 mWaitingForResume.setStayPressed(true);
1681 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001682 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001683 if (v instanceof FolderIcon) {
1684 FolderIcon fi = (FolderIcon) v;
1685 handleFolderClick(fi);
1686 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001687 } else if (v == mAllAppsButton) {
1688 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001689 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001690 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001691 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001692 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001693 }
1694 }
1695
Michael Jurka0e260592010-06-30 17:07:39 -07001696 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001697 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001698 // clicking anywhere on the workspace causes the customization drawer to slide down
1699 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001700 return false;
1701 }
1702
Michael Jurkaaf442092010-06-10 17:01:57 -07001703 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001704 * Event handler for the search button
1705 *
1706 * @param v The view that was clicked.
1707 */
1708 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001709 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1710
Amith Yamasania135ba82011-08-09 17:42:01 -07001711 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001712 }
1713
1714 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001715 * Event handler for the voice button
1716 *
1717 * @param v The view that was clicked.
1718 */
1719 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001720 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001721
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001722 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001723 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001724 startActivity(intent);
1725 }
1726
1727 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001728 * Event handler for the "grid" button that appears on the home screen, which
1729 * enters all apps mode.
1730 *
1731 * @param v The view that was clicked.
1732 */
1733 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001734 showAllApps(true);
1735 }
1736
1737 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001738 // Provide the same haptic feedback that the system offers for virtual keys.
1739 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001740 }
1741
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001742 public void onClickAppMarketButton(View v) {
1743 if (mAppMarketIntent != null) {
1744 startActivitySafely(mAppMarketIntent, "app market");
1745 }
1746 }
1747
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001748 void startApplicationDetailsActivity(ComponentName componentName) {
1749 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001750 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1751 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001752 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001753 startActivity(intent);
1754 }
1755
Patrick Dubroy5539af72010-09-07 15:22:01 -07001756 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1757 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1758 // System applications cannot be installed. For now, show a toast explaining that.
1759 // We may give them the option of disabling apps this way.
1760 int messageId = R.string.uninstall_system_app_text;
1761 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1762 } else {
1763 String packageName = appInfo.componentName.getPackageName();
1764 String className = appInfo.componentName.getClassName();
1765 Intent intent = new Intent(
1766 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001767 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1768 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001769 startActivity(intent);
1770 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001771 }
1772
Michael Jurkaddd62e92011-02-16 17:49:14 -08001773 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1775 try {
1776 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001777 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001778 } catch (ActivityNotFoundException e) {
1779 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001780 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001781 } catch (SecurityException e) {
1782 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001783 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001784 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001785 "or use the exported attribute for this activity. "
1786 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001788 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001790
Romain Guy8e633c52010-03-04 12:51:36 -08001791 void startActivityForResultSafely(Intent intent, int requestCode) {
1792 try {
1793 startActivityForResult(intent, requestCode);
1794 } catch (ActivityNotFoundException e) {
1795 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1796 } catch (SecurityException e) {
1797 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1798 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1799 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1800 "or use the exported attribute for this activity.", e);
1801 }
1802 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001803
Adam Cohena9cf38f2011-05-02 15:36:58 -07001804 private void handleFolderClick(FolderIcon folderIcon) {
1805 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001806 Folder openFolder = mWorkspace.getFolderForTag(info);
1807
1808 // If the folder info reports that the associated folder is open, then verify that
1809 // it is actually opened. There have been a few instances where this gets out of sync.
1810 if (info.opened && openFolder == null) {
1811 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1812 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1813 info.opened = false;
1814 }
1815
Adam Cohena9cf38f2011-05-02 15:36:58 -07001816 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 // Close any open folder
1818 closeFolder();
1819 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001820 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001821 } else {
1822 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001823 int folderScreen;
1824 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001825 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001826 // .. and close it
1827 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001828 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001829 // Close any folder open on the current screen
1830 closeFolder();
1831 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001832 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001833 }
1834 }
1835 }
1836 }
1837
Adam Cohen2801caf2011-05-13 20:57:39 -07001838 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001839 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001840 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1841 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1842 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1843
Adam Cohenc51934b2011-07-26 21:07:43 -07001844 FolderInfo info = (FolderInfo) fi.getTag();
1845 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1846 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001847 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1848 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001849 }
1850
Adam Cohen2801caf2011-05-13 20:57:39 -07001851 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1852 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1853 oa.start();
1854 }
1855
1856 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001857 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001858 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1859 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1860 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1861
Adam Cohenc51934b2011-07-26 21:07:43 -07001862 FolderInfo info = (FolderInfo) fi.getTag();
1863 CellLayout cl = null;
1864 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1865 cl = (CellLayout) fi.getParent().getParent();
1866 }
1867
1868 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001869 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1870 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001871 oa.addListener(new AnimatorListenerAdapter() {
1872 @Override
1873 public void onAnimationEnd(Animator animation) {
1874 if (layout != null) {
1875 layout.clearFolderLeaveBehind();
1876 }
1877 }
1878 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001879 oa.start();
1880 }
1881
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001883 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884 * is animated relative to the specified View. If the View is null, no animation
1885 * is played.
1886 *
1887 * @param folderInfo The FolderInfo describing the folder to open.
1888 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001889 public void openFolder(FolderIcon folderIcon) {
1890 Folder folder = folderIcon.mFolder;
1891 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892
Adam Cohen2801caf2011-05-13 20:57:39 -07001893 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001894 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001895
Adam Cohen4554ee12011-08-03 16:13:21 -07001896 // Just verify that the folder hasn't already been added to the DragLayer.
1897 // There was a one-off crash where the folder had a parent already.
1898 if (folder.getParent() == null) {
1899 mDragLayer.addView(folder);
1900 mDragController.addDropTarget((DropTarget) folder);
1901 } else {
1902 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1903 folder.getParent() + ").");
1904 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001905 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001906 }
1907
1908 public void closeFolder() {
1909 Folder folder = mWorkspace.getOpenFolder();
1910 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001911 if (folder.isEditingName()) {
1912 folder.dismissEditingName();
1913 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001914 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001915
1916 // Dismiss the folder cling
1917 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001918 }
1919 }
1920
1921 void closeFolder(Folder folder) {
1922 folder.getInfo().opened = false;
1923
1924 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1925 if (parent != null) {
1926 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1927 shrinkAndFadeInFolderIcon(fi);
1928 }
1929 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001930 }
1931
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001932 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001933 if (mState != State.WORKSPACE) {
1934 return false;
1935 }
1936
Joe Onorato9c1289c2009-08-17 11:03:03 -04001937 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001938 return false;
1939 }
1940
1941 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001942 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 }
1944
Michael Jurka0280c3b2010-09-17 15:00:07 -07001945 resetAddInfo();
1946 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001948 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001949 return true;
1950 }
1951
Winson Chung3d503fb2011-07-13 17:25:49 -07001952 // The hotseat touch handling does not go through Workspace, and we always allow long press
1953 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001954 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001955 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1956 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001957 if (itemUnderLongClick == null) {
1958 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001959 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1960 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001961 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001963 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07001965 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001966 }
1967 }
1968 }
1969 return true;
1970 }
1971
Winson Chung3d503fb2011-07-13 17:25:49 -07001972 boolean isHotseatLayout(View layout) {
1973 return mHotseat != null && layout != null &&
1974 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1975 }
1976 Hotseat getHotseat() {
1977 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001978 }
Adam Cohenebea84d2011-11-09 17:20:41 -08001979 SearchDropTargetBar getSearchBar() {
1980 return mSearchDropTargetBar;
1981 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001982
Winson Chung3d503fb2011-07-13 17:25:49 -07001983 /**
1984 * Returns the CellLayout of the specified container at the specified screen.
1985 */
1986 CellLayout getCellLayout(long container, int screen) {
1987 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1988 if (mHotseat != null) {
1989 return mHotseat.getLayout();
1990 } else {
1991 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001992 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001993 } else {
1994 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001995 }
1996 }
1997
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001998 Workspace getWorkspace() {
1999 return mWorkspace;
2000 }
2001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002002 @Override
2003 protected Dialog onCreateDialog(int id) {
2004 switch (id) {
2005 case DIALOG_CREATE_SHORTCUT:
2006 return new CreateShortcut().createDialog();
2007 case DIALOG_RENAME_FOLDER:
2008 return new RenameFolder().createDialog();
2009 }
2010
2011 return super.onCreateDialog(id);
2012 }
2013
2014 @Override
2015 protected void onPrepareDialog(int id, Dialog dialog) {
2016 switch (id) {
2017 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018 break;
2019 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002020 if (mFolderInfo != null) {
2021 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2022 final CharSequence text = mFolderInfo.title;
2023 input.setText(text);
2024 input.setSelection(0, text.length());
2025 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002026 break;
2027 }
2028 }
2029
2030 void showRenameDialog(FolderInfo info) {
2031 mFolderInfo = info;
2032 mWaitingForResult = true;
2033 showDialog(DIALOG_RENAME_FOLDER);
2034 }
2035
Adam Cohenfbba09b2011-07-18 21:43:05 -07002036 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002037 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002038 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2039 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 mWaitingForResult = true;
2041 showDialog(DIALOG_CREATE_SHORTCUT);
2042 }
2043
2044 private class RenameFolder {
2045 private EditText mInput;
2046
2047 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002048 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2049 mInput = (EditText) layout.findViewById(R.id.folder_name);
2050
2051 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2052 builder.setIcon(0);
2053 builder.setTitle(getString(R.string.rename_folder_title));
2054 builder.setCancelable(true);
2055 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2056 public void onCancel(DialogInterface dialog) {
2057 cleanup();
2058 }
2059 });
2060 builder.setNegativeButton(getString(R.string.cancel_action),
2061 new Dialog.OnClickListener() {
2062 public void onClick(DialogInterface dialog, int which) {
2063 cleanup();
2064 }
2065 }
2066 );
2067 builder.setPositiveButton(getString(R.string.rename_action),
2068 new Dialog.OnClickListener() {
2069 public void onClick(DialogInterface dialog, int which) {
2070 changeFolderName();
2071 }
2072 }
2073 );
2074 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002075
2076 final AlertDialog dialog = builder.create();
2077 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2078 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002079 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002080 mInput.requestFocus();
2081 InputMethodManager inputManager = (InputMethodManager)
2082 getSystemService(Context.INPUT_METHOD_SERVICE);
2083 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002084 }
2085 });
2086
2087 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002088 }
2089
2090 private void changeFolderName() {
2091 final String name = mInput.getText().toString();
2092 if (!TextUtils.isEmpty(name)) {
2093 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002094 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002095 mFolderInfo.title = name;
2096 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2097
Joe Onorato9c1289c2009-08-17 11:03:03 -04002098 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002099 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002100 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002101 } else {
2102 final FolderIcon folderIcon = (FolderIcon)
2103 mWorkspace.getViewForTag(mFolderInfo);
2104 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002105 // TODO: At some point we'll probably want some version of setting
2106 // the text for a folder icon.
2107 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002108 getWorkspace().requestLayout();
2109 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002110 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002111 mWorkspaceLoading = true;
2112 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002113 }
2114 }
2115 }
2116 cleanup();
2117 }
2118
2119 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002120 dismissDialog(DIALOG_RENAME_FOLDER);
2121 mWaitingForResult = false;
2122 mFolderInfo = null;
2123 }
2124 }
2125
Daniel Sandler843e8602010-06-07 14:59:01 -04002126 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2127 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002128 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002129 }
2130
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002131 // AllAppsView.Watcher
2132 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002133 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002134 mWorkspace.setVisibility(View.GONE);
2135 }
2136 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002137
2138 /**
2139 * Helper method for the cameraZoomIn/cameraZoomOut animations
2140 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002141 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002142 * @param scaleFactor The scale factor used for the zoom
2143 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002144 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002145 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002146 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002147 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002148
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002149 void updateWallpaperVisibility(boolean visible) {
2150 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2151 int curflags = getWindow().getAttributes().flags
2152 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2153 if (wpflags != curflags) {
2154 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2155 }
2156 }
2157
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002158 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002159 * Things to test when changing the following seven functions.
2160 * - Home from workspace
2161 * - from center screen
2162 * - from other screens
2163 * - Home from all apps
2164 * - from center screen
2165 * - from other screens
2166 * - Back from all apps
2167 * - from center screen
2168 * - from other screens
2169 * - Launch app from workspace and quit
2170 * - with back
2171 * - with home
2172 * - Launch app from all apps and quit
2173 * - with back
2174 * - with home
2175 * - Go to a screen that's not the default, then all
2176 * apps, and launch and app, and go back
2177 * - with back
2178 * -with home
2179 * - On workspace, long press power and go back
2180 * - with back
2181 * - with home
2182 * - On all apps, long press power and go back
2183 * - with back
2184 * - with home
2185 * - On workspace, power off
2186 * - On all apps, power off
2187 * - Launch an app and turn off the screen while in that app
2188 * - Go back with home key
2189 * - Go back with back key TODO: make this not go to workspace
2190 * - From all apps
2191 * - From workspace
2192 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2193 * - From all apps
2194 * - From the center workspace
2195 * - From another workspace
2196 */
2197
2198 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002199 * Zoom the camera out from the workspace to reveal 'toView'.
2200 * Assumes that the view to show is anchored at either the very top or very bottom
2201 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002202 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002203 private void showAppsCustomizeHelper(boolean animated, final boolean springLoaded) {
2204 if (mStateAnimation != null) {
2205 mStateAnimation.cancel();
2206 mStateAnimation = null;
2207 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002208 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002209 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002210
Winson Chungf0ea4d32011-06-06 14:27:16 -07002211 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2212 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2213 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2214 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002215 final int startDelay =
2216 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002217
Michael Jurkab3e22d92011-10-31 15:58:33 -07002218 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002219
Michael Jurkad74c9842011-07-10 12:44:21 -07002220 // Shrink workspaces away if going to AppsCustomize from workspace
Adam Cohen7777d962011-08-18 18:58:38 -07002221 mWorkspace.changeState(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002222
2223 if (animated) {
Michael Jurkaabded662011-03-04 12:06:57 -08002224 final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
Michael Jurka742574b2011-02-02 23:51:01 -08002225 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002226 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2227 public void onAnimationUpdate(float a, float b) {
Adam Cohen7777d962011-08-18 18:58:38 -07002228 ((View) toView.getParent()).invalidate();
2229 toView.fastInvalidate();
Michael Jurka11148e52011-02-03 18:20:25 -08002230 toView.setFastScaleX(a * scale + b * 1f);
2231 toView.setFastScaleY(a * scale + b * 1f);
Michael Jurka742574b2011-02-02 23:51:01 -08002232 }
2233 });
Adam Cohen61033d32010-11-15 18:29:44 -08002234
Winson Chungf0ea4d32011-06-06 14:27:16 -07002235 toView.setVisibility(View.VISIBLE);
2236 toView.setFastAlpha(0f);
2237 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2238 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2239 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2240 public void onAnimationUpdate(float a, float b) {
2241 // don't need to invalidate because we do so above
2242 toView.setFastAlpha(a * 0f + b * 1f);
2243 }
2244 });
Adam Cohencff6af82011-09-13 14:51:53 -07002245 alphaAnim.setStartDelay(startDelay);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002246 alphaAnim.start();
Adam Cohenf16e5712011-01-13 13:31:45 -08002247
Michael Jurka8edd75c2010-12-17 20:15:06 -08002248 scaleAnim.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002249 boolean animationCancelled = false;
2250
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002251 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002252 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002253 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002254 // Prepare the position
2255 toView.setTranslationX(0.0f);
2256 toView.setTranslationY(0.0f);
2257 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002258 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002259 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002260 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002261 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002262 // If we don't set the final scale values here, if this animation is cancelled
2263 // it will have the wrong scale value and subsequent cameraPan animations will
2264 // not fix that
2265 toView.setScaleX(1.0f);
2266 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002267 if (toView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002268 ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance,
2269 scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002270 }
Winson Chung32174c82011-07-19 15:47:55 -07002271
2272 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2273 // Hide the workspace scrollbar
2274 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002275 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002276 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002277 if (!animationCancelled) {
2278 updateWallpaperVisibility(false);
2279 }
2280 }
2281
Adam Cohencff6af82011-09-13 14:51:53 -07002282 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002283 public void onAnimationCancel(Animator animation) {
2284 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002285 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002286 });
2287
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002288 // toView should appear right at the end of the workspace shrink animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002289 mStateAnimation = new AnimatorSet();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002290 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka1899a362011-11-03 13:50:45 -07002291
2292 boolean delayAnim = false;
2293 if (toView instanceof LauncherTransitionable) {
2294 LauncherTransitionable lt = (LauncherTransitionable) toView;
2295 delayAnim = lt.onLauncherTransitionStart(instance, mStateAnimation, false);
2296 }
2297 // if the anim is delayed, the LauncherTransitionable is responsible for starting it
2298 if (!delayAnim) {
2299 // TODO: q-- what if this anim is cancelled before being started? or started after
2300 // being cancelled?
2301 mStateAnimation.start();
2302 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002303 } else {
2304 toView.setTranslationX(0.0f);
2305 toView.setTranslationY(0.0f);
2306 toView.setScaleX(1.0f);
2307 toView.setScaleY(1.0f);
2308 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002309 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002310 if (toView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002311 ((LauncherTransitionable) toView).onLauncherTransitionStart(instance, null, false);
2312 ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance, null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002313
Winson Chungc07918d2011-07-01 15:35:26 -07002314 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2315 // Hide the workspace scrollbar
2316 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002317 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002318 }
Michael Jurkaabded662011-03-04 12:06:57 -08002319 }
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002320 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002321 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002322 }
2323
2324 /**
2325 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002326 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002327 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002328 */
Michael Jurkab737ee62011-11-15 15:57:22 -08002329 private void hideAppsCustomizeHelper(boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002330 if (mStateAnimation != null) {
2331 mStateAnimation.cancel();
2332 mStateAnimation = null;
2333 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002334 Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002335 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002336
Winson Chungf0ea4d32011-06-06 14:27:16 -07002337 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2338 final float scaleFactor = (float)
2339 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2340 final View fromView = mAppsCustomizeTabHost;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002341
Michael Jurkab3e22d92011-10-31 15:58:33 -07002342 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002343 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002344 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002345 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002346 final float oldScaleX = fromView.getScaleX();
2347 final float oldScaleY = fromView.getScaleY();
2348
2349 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2350 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002351 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2352 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002353 ((View)fromView.getParent()).fastInvalidate();
2354 fromView.setFastScaleX(a * oldScaleX + b * scaleFactor);
2355 fromView.setFastScaleY(a * oldScaleY + b * scaleFactor);
2356 }
2357 });
Michael Jurkaabded662011-03-04 12:06:57 -08002358 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002359 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Adam Cohencff6af82011-09-13 14:51:53 -07002360 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002361 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2362 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002363 // don't need to invalidate because we do so above
2364 fromView.setFastAlpha(a * 1f + b * 0f);
2365 }
2366 });
Michael Jurkaabded662011-03-04 12:06:57 -08002367 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002368 ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, alphaAnim,
2369 true);
Michael Jurka2763be32011-02-24 11:19:57 -08002370 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002371 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002372 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002373 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002374 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002375 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002376 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002377 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance,
2378 alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002379 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002380 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002381 }
2382 });
2383
Michael Jurkab3e22d92011-10-31 15:58:33 -07002384 mStateAnimation = new AnimatorSet();
Winson Chungf0ea4d32011-06-06 14:27:16 -07002385 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002386 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002387 } else {
2388 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002389 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002390 ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, null, true);
2391 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance, null, true);
Michael Jurkaabded662011-03-04 12:06:57 -08002392 }
Michael Jurkab737ee62011-11-15 15:57:22 -08002393 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002394 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002395 }
2396
Michael Jurkae326f182011-11-21 14:05:46 -08002397 @Override
2398 public void onTrimMemory(int level) {
2399 super.onTrimMemory(level);
2400 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2401 mAppsCustomizeTabHost.onTrimMemory();
2402 }
2403 }
2404
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002405 void showWorkspace(boolean animated) {
Adam Cohencff6af82011-09-13 14:51:53 -07002406 Resources res = getResources();
2407 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2408
2409 mWorkspace.changeState(Workspace.State.NORMAL, animated, stagger);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002410 if (mState != State.WORKSPACE) {
2411 mWorkspace.setVisibility(View.VISIBLE);
Michael Jurkab737ee62011-11-15 15:57:22 -08002412 hideAppsCustomizeHelper(animated, false);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002413
2414 // Show the search bar and hotseat
2415 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002416 // We only need to animate in the dock divider if we're going from spring loaded mode
2417 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002418
2419 // Set focus to the AppsCustomize button
2420 if (mAllAppsButton != null) {
2421 mAllAppsButton.requestFocus();
2422 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002423 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002424
Michael Jurkab737ee62011-11-15 15:57:22 -08002425 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002426
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002427 // Change the state *after* we've called all the transition code
2428 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002429
Winson Chung5fb63472011-02-02 17:03:37 -08002430 // Resume the auto-advance of widgets
2431 mUserPresent = true;
2432 updateRunning();
2433
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002434 // send an accessibility event to announce the context change
2435 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002436 }
2437
Michael Jurkab3e22d92011-10-31 15:58:33 -07002438 void showAllApps(boolean animated) {
2439 if (mState != State.WORKSPACE) return;
2440
2441 showAppsCustomizeHelper(animated, false);
2442 mAppsCustomizeTabHost.requestFocus();
2443
2444 // Hide the search bar and hotseat
2445 mSearchDropTargetBar.hideSearchBar(animated);
2446
2447 // Change the state *after* we've called all the transition code
2448 mState = State.APPS_CUSTOMIZE;
2449
2450 // Pause the auto-advance of widgets until we are out of AllApps
2451 mUserPresent = false;
2452 updateRunning();
2453 closeFolder();
2454
2455 // Send an accessibility event to announce the context change
2456 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2457 }
2458
Adam Cohen7777d962011-08-18 18:58:38 -07002459 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002460 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen7777d962011-08-18 18:58:38 -07002461 mWorkspace.changeState(Workspace.State.SPRING_LOADED);
Michael Jurkab737ee62011-11-15 15:57:22 -08002462 hideAppsCustomizeHelper(true, true);
2463 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002464 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002465 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002466 }
Adam Cohen7777d962011-08-18 18:58:38 -07002467
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002468 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
Winson Chung09bfc452011-09-09 11:30:20 -07002469 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2470
Winson Chunge7a03942011-08-05 15:05:12 -07002471 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002472 @Override
2473 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002474 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002475 // Before we show workspace, hide all apps again because
2476 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2477 // clean up our state transition functions
2478 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002479 mSearchDropTargetBar.showSearchBar(true);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002480 showWorkspace(true);
Adam Cohen7777d962011-08-18 18:58:38 -07002481 } else {
2482 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002483 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002484 }
2485 }, (extendedDelay ?
2486 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2487 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2488 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002489
Michael Jurkad3ef3062010-11-23 16:23:58 -08002490 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002491 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002492 final boolean animated = true;
2493 final boolean springLoaded = true;
2494 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002495 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002496 }
2497 // Otherwise, we are not in spring loaded mode, so don't do anything.
2498 }
2499
Michael Jurkab737ee62011-11-15 15:57:22 -08002500 void hideDockDivider() {
2501 if (mQsbDivider != null && mDockDivider != null) {
2502 mQsbDivider.setVisibility(View.INVISIBLE);
2503 mDockDivider.setVisibility(View.INVISIBLE);
2504 }
2505 }
2506
2507 void showDockDivider(boolean animated) {
2508 if (mQsbDivider != null && mDockDivider != null) {
2509 mQsbDivider.setVisibility(View.VISIBLE);
2510 mDockDivider.setVisibility(View.VISIBLE);
2511 if (mDividerAnimator != null) {
2512 mDividerAnimator.cancel();
2513 mQsbDivider.setAlpha(1f);
2514 mDockDivider.setAlpha(1f);
2515 mDividerAnimator = null;
2516 }
2517 if (animated) {
2518 mDividerAnimator = new AnimatorSet();
2519 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2520 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2521 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2522 mDividerAnimator.start();
2523 }
2524 }
2525 }
2526
Michael Jurkab3e22d92011-10-31 15:58:33 -07002527 void lockAllApps() {
2528 // TODO
2529 }
2530
2531 void unlockAllApps() {
2532 // TODO
2533 }
2534
Adam Cohenfc53cd22011-07-20 15:45:11 -07002535 public boolean isAllAppsCustomizeOpen() {
2536 return mState == State.APPS_CUSTOMIZE;
2537 }
2538
Winson Chungf0ea4d32011-06-06 14:27:16 -07002539 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002540 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002541 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002542 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002543 if (!LauncherApplication.isScreenLarge()) {
2544 if (animated) {
Winson Chungc51db6a2011-10-05 11:44:49 -07002545 int duration = mSearchDropTargetBar.getTransitionInDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002546 mHotseat.animate().alpha(1f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002547 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002548 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002549 }
2550 }
2551 }
2552
2553 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002554 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002555 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002556 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002557 if (!LauncherApplication.isScreenLarge()) {
2558 if (animated) {
Winson Chungc51db6a2011-10-05 11:44:49 -07002559 int duration = mSearchDropTargetBar.getTransitionOutDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002560 mHotseat.animate().alpha(0f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002561 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002562 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002563 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002564 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002565 }
2566
Patrick Dubroy5f445422011-02-18 14:35:21 -08002567 /**
2568 * Add an item from all apps or customize onto the given workspace screen.
2569 * If layout is null, add to the current screen.
2570 */
2571 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002572 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2573 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002574 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002575 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002576
Winson Chungdff8ebb2011-09-08 17:25:31 -07002577 /** Maps the current orientation to an index for referencing orientation correct global icons */
2578 private int getCurrentOrientationIndexForGlobalIcons() {
2579 // default - 0, landscape - 1
2580 switch (getResources().getConfiguration().orientation) {
2581 case Configuration.ORIENTATION_LANDSCAPE:
2582 return 1;
2583 default:
2584 return 0;
2585 }
2586 }
2587
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002588 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002589 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002590 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002591 // Look for the toolbar icon specified in the activity meta-data
2592 Bundle metaData = packageManager.getActivityInfo(
2593 activityName, PackageManager.GET_META_DATA).metaData;
2594 if (metaData != null) {
2595 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2596 if (iconResId != 0) {
2597 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002598 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002599 }
2600 }
2601 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002602 // This can happen if the activity defines an invalid drawable
2603 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2604 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002605 } catch (Resources.NotFoundException nfe) {
2606 // This can happen if the activity defines an invalid drawable
2607 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2608 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002609 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002610 return null;
2611 }
2612
2613 // if successful in getting icon, return it; otherwise, set button to use default drawable
2614 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2615 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002616 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002617 Resources r = getResources();
2618 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2619 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002620
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002621 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002622 // If we were unable to find the icon via the meta-data, use a generic one
2623 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002624 toolbarIcon = r.getDrawable(fallbackDrawableId);
2625 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002626 if (button != null) {
2627 button.setCompoundDrawables(toolbarIcon, null, null, null);
2628 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002629 return null;
2630 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002631 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002632 if (button != null) {
2633 button.setCompoundDrawables(toolbarIcon, null, null, null);
2634 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002635 return toolbarIcon.getConstantState();
2636 }
2637 }
2638
2639 // if successful in getting icon, return it; otherwise, set button to use default drawable
2640 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2641 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2642 ImageView button = (ImageView) findViewById(buttonId);
2643 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2644
Michael Jurka19e0fc52011-07-22 18:00:21 -07002645 if (button != null) {
2646 // If we were unable to find the icon via the meta-data, use a
2647 // generic one
2648 if (toolbarIcon == null) {
2649 button.setImageResource(fallbackDrawableId);
2650 } else {
2651 button.setImageDrawable(toolbarIcon);
2652 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002653 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002654
2655 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2656
Michael Jurka0423dcf2010-10-05 14:56:18 -07002657 }
2658
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002659 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2660 TextView button = (TextView) findViewById(buttonId);
2661 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2662 }
2663
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002664 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002665 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002666 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002667 }
2668
Winson Chungbb185bd2011-11-21 12:31:42 -08002669 private void invalidatePressedFocusedStates(View container, View button) {
2670 if (container instanceof HolographicLinearLayout) {
2671 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2672 layout.invalidatePressedFocusedStates();
2673 } else if (button instanceof HolographicImageView) {
2674 HolographicImageView view = (HolographicImageView) button;
2675 view.invalidatePressedFocusedStates();
2676 }
2677 }
2678
Winson Chungc51db6a2011-10-05 11:44:49 -07002679 private boolean updateGlobalSearchIcon() {
2680 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002681 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2682 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002683 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002684 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002685
Winson Chung1cad91e2011-05-25 17:41:01 -07002686 final SearchManager searchManager =
2687 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2688 ComponentName activityName = searchManager.getGlobalSearchActivity();
2689 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002690 int coi = getCurrentOrientationIndexForGlobalIcons();
2691 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002692 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002693 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002694 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2695 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002696 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002697 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002698 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002699 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002700 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002701 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2702 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2703 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002704 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002705 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002706 }
2707 }
2708
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002709 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002710 final View searchButtonContainer = findViewById(R.id.search_button_container);
2711 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002712 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002713 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002714 }
2715
Winson Chungc51db6a2011-10-05 11:44:49 -07002716 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002717 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002718 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002719 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002720
Winson Chungc51db6a2011-10-05 11:44:49 -07002721 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002722 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2723 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002724 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002725 int coi = getCurrentOrientationIndexForGlobalIcons();
2726 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002727 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002728 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002729 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002730 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002731 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002732 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002733 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002734 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002735 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002736 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002737 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002738 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002739 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002740
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002741 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002742 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2743 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002744 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002745 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002746 }
2747
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002748 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002749 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002750 */
2751 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002752 final View marketButton = findViewById(R.id.market_button);
2753 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2754 // Find the app market activity by resolving an intent.
2755 // (If multiple app markets are installed, it will return the ResolverActivity.)
2756 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002757 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002758 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002759 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002760 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002761 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002762 marketButton.setVisibility(View.VISIBLE);
2763 } else {
2764 // We should hide and disable the view so that we don't try and restore the visibility
2765 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2766 marketButton.setVisibility(View.GONE);
2767 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002768 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002769 }
2770
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002771 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002772 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002773 }
2774
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002775 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002776 * Displays the shortcut creation dialog and launches, if necessary, the
2777 * appropriate activity.
2778 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002779 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002780 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2781 DialogInterface.OnShowListener {
2782
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002783 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002784
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002785 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002786 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002787
Winson Chung55b65502011-05-26 12:03:43 -07002788 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2789 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002790 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002791
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002792 AlertDialog dialog = builder.create();
2793 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002794 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002795 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002796
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002797 return dialog;
2798 }
2799
2800 public void onCancel(DialogInterface dialog) {
2801 mWaitingForResult = false;
2802 cleanup();
2803 }
2804
Romain Guycbb89e42009-06-08 15:52:54 -07002805 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002806 mWaitingForResult = false;
2807 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002808 }
2809
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002810 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002811 try {
2812 dismissDialog(DIALOG_CREATE_SHORTCUT);
2813 } catch (Exception e) {
2814 // An exception is thrown if the dialog is not visible, which is fine
2815 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002816 }
2817
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002818 /**
2819 * Handle the action clicked in the "Add to home" dialog.
2820 */
2821 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002822 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002823
Winson Chung55b65502011-05-26 12:03:43 -07002824 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2825 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002826 case AddAdapter.ITEM_APPLICATION: {
2827 if (mAppsCustomizeTabHost != null) {
2828 mAppsCustomizeTabHost.selectAppsTab();
2829 }
2830 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002831 break;
2832 }
Winson Chung55b65502011-05-26 12:03:43 -07002833 case AddAdapter.ITEM_APPWIDGET: {
2834 if (mAppsCustomizeTabHost != null) {
2835 mAppsCustomizeTabHost.selectWidgetsTab();
2836 }
2837 showAllApps(true);
2838 break;
2839 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002840 case AddAdapter.ITEM_WALLPAPER: {
2841 startWallpaper();
2842 break;
2843 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002844 }
2845 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002846
2847 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002848 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002849 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002850 }
2851
2852 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002853 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002854 */
2855 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2856 @Override
2857 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002858 closeSystemDialogs();
2859 }
2860 }
2861
2862 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002863 * Receives notifications whenever the appwidgets are reset.
2864 */
2865 private class AppWidgetResetObserver extends ContentObserver {
2866 public AppWidgetResetObserver() {
2867 super(new Handler());
2868 }
2869
2870 @Override
2871 public void onChange(boolean selfChange) {
2872 onAppWidgetReset();
2873 }
2874 }
2875
2876 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002877 * If the activity is currently paused, signal that we need to re-run the loader
2878 * in onResume.
2879 *
2880 * This needs to be called from incoming places where resources might have been loaded
2881 * while we are paused. That is becaues the Configuration might be wrong
2882 * when we're not running, and if it comes back to what it was when we
2883 * were paused, we are not restarted.
2884 *
2885 * Implementation of the method from LauncherModel.Callbacks.
2886 *
2887 * @return true if we are currently paused. The caller might be able to
2888 * skip some work in that case since we will come back again.
2889 */
2890 public boolean setLoadOnResume() {
2891 if (mPaused) {
2892 Log.i(TAG, "setLoadOnResume");
2893 mOnResumeNeedsLoad = true;
2894 return true;
2895 } else {
2896 return false;
2897 }
2898 }
2899
2900 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002901 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002902 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002903 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002904 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002905 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002906 } else {
2907 return SCREEN_COUNT / 2;
2908 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002909 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002910
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002911
Joe Onorato9c1289c2009-08-17 11:03:03 -04002912 /**
2913 * Refreshes the shortcuts shown on the workspace.
2914 *
2915 * Implementation of the method from LauncherModel.Callbacks.
2916 */
2917 public void startBinding() {
2918 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002919
2920 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002921 int count = workspace.getChildCount();
2922 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002923 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002924 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2925 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002926 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08002927 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07002928 if (mHotseat != null) {
2929 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002930 }
2931 }
2932
2933 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002934 * Bind the items start-end from the list.
2935 *
2936 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002937 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002938 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002939 setLoadOnResume();
2940
Joe Onorato9c1289c2009-08-17 11:03:03 -04002941 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002942 for (int i=start; i<end; i++) {
2943 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002944
2945 // Short circuit if we are loading dock items for a configuration which has no dock
2946 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2947 mHotseat == null) {
2948 continue;
2949 }
2950
Joe Onorato9c1289c2009-08-17 11:03:03 -04002951 switch (item.itemType) {
2952 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2953 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002954 View shortcut = createShortcut((ShortcutInfo)item);
2955 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
2956 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002957 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07002958 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07002959 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002960 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07002961 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07002962 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
2963 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002964 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002965 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002966 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002967 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002968 }
2969
Joe Onorato9c1289c2009-08-17 11:03:03 -04002970 /**
2971 * Implementation of the method from LauncherModel.Callbacks.
2972 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002973 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002974 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002975 sFolders.clear();
2976 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002977 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002978
2979 /**
2980 * Add the views for a widget to the workspace.
2981 *
2982 * Implementation of the method from LauncherModel.Callbacks.
2983 */
2984 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002985 setLoadOnResume();
2986
Daniel Sandler843e8602010-06-07 14:59:01 -04002987 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2988 if (DEBUG_WIDGETS) {
2989 Log.d(TAG, "bindAppWidget: " + item);
2990 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002991 final Workspace workspace = mWorkspace;
2992
2993 final int appWidgetId = item.appWidgetId;
2994 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002995 if (DEBUG_WIDGETS) {
2996 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2997 }
2998
Joe Onorato9c1289c2009-08-17 11:03:03 -04002999 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3000
Joe Onorato9c1289c2009-08-17 11:03:03 -04003001 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3002 item.hostView.setTag(item);
3003
Winson Chung3d503fb2011-07-13 17:25:49 -07003004 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003005 item.cellY, item.spanX, item.spanY, false);
3006
Adam Cohended9f8d2010-11-03 13:25:16 -07003007 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3008
Joe Onorato9c1289c2009-08-17 11:03:03 -04003009 workspace.requestLayout();
3010
Daniel Sandler843e8602010-06-07 14:59:01 -04003011 if (DEBUG_WIDGETS) {
3012 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3013 + (SystemClock.uptimeMillis()-start) + "ms");
3014 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003015 }
3016
3017 /**
3018 * Callback saying that there aren't any more items to bind.
3019 *
3020 * Implementation of the method from LauncherModel.Callbacks.
3021 */
3022 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003023 setLoadOnResume();
3024
Joe Onorato9c1289c2009-08-17 11:03:03 -04003025 if (mSavedState != null) {
3026 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003027 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003028 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003029 mSavedState = null;
3030 }
3031
3032 if (mSavedInstanceState != null) {
3033 super.onRestoreInstanceState(mSavedInstanceState);
3034 mSavedInstanceState = null;
3035 }
3036
Joe Onorato9c1289c2009-08-17 11:03:03 -04003037 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003038
3039 // If we received the result of any pending adds while the loader was running (e.g. the
3040 // widget configuration forced an orientation change), process them now.
3041 for (int i = 0; i < sPendingAddList.size(); i++) {
3042 completeAdd(sPendingAddList.get(i));
3043 }
3044 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003045
Winson Chungc51db6a2011-10-05 11:44:49 -07003046 // Update the market app icon as necessary (the other icons will be managed in response to
3047 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003048 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003049
3050 mWorkspace.post(mBuildLayersRunnable);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003051 }
3052
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003053 @Override
3054 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003055 boolean searchVisible = updateGlobalSearchIcon();
3056 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3057 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003058 }
3059
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003060 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003061 * Add the icons for all apps.
3062 *
3063 * Implementation of the method from LauncherModel.Callbacks.
3064 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003065 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3066 // Remove the progress bar entirely; we could also make it GONE
3067 // but better to remove it since we know it's not going to be used
3068 View progressBar = mAppsCustomizeTabHost.
3069 findViewById(R.id.apps_customize_progress_bar);
3070 if (progressBar != null) {
3071 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003072 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003073 // We just post the call to setApps so the user sees the progress bar
3074 // disappear-- otherwise, it just looks like the progress bar froze
3075 // which doesn't look great
3076 mAppsCustomizeTabHost.post(new Runnable() {
3077 public void run() {
3078 if (mAppsCustomizeContent != null) {
3079 mAppsCustomizeContent.setApps(apps);
3080 }
3081 }
3082 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003083 }
3084
3085 /**
3086 * A package was installed.
3087 *
3088 * Implementation of the method from LauncherModel.Callbacks.
3089 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003090 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003091 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003092 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003093
Winson Chung785d2eb2011-04-14 16:08:02 -07003094 if (mAppsCustomizeContent != null) {
3095 mAppsCustomizeContent.addApps(apps);
3096 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003097 }
3098
3099 /**
3100 * A package was updated.
3101 *
3102 * Implementation of the method from LauncherModel.Callbacks.
3103 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003104 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003105 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003106 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003107 if (mWorkspace != null) {
3108 mWorkspace.updateShortcuts(apps);
3109 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003110
Winson Chung785d2eb2011-04-14 16:08:02 -07003111 if (mAppsCustomizeContent != null) {
3112 mAppsCustomizeContent.updateApps(apps);
3113 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003114 }
3115
3116 /**
3117 * A package was uninstalled.
3118 *
3119 * Implementation of the method from LauncherModel.Callbacks.
3120 */
Joe Onorato36115782010-06-17 13:28:48 -04003121 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003122 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003123 if (permanent) {
3124 mWorkspace.removeItems(apps);
3125 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003126
Winson Chung785d2eb2011-04-14 16:08:02 -07003127 if (mAppsCustomizeContent != null) {
3128 mAppsCustomizeContent.removeApps(apps);
3129 }
Winson Chunga1820962011-10-03 16:31:06 -07003130
3131 // Notify the drag controller
3132 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003133 }
Joe Onoratobe386092009-11-17 17:32:16 -08003134
3135 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003136 * A number of packages were updated.
3137 */
3138 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003139 if (mAppsCustomizeContent != null) {
3140 mAppsCustomizeContent.onPackagesUpdated();
3141 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003142 }
3143
Winson Chung400438b2011-01-16 17:53:48 -08003144 private int mapConfigurationOriActivityInfoOri(int configOri) {
3145 final Display d = getWindowManager().getDefaultDisplay();
3146 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3147 switch (d.getRotation()) {
3148 case Surface.ROTATION_0:
3149 case Surface.ROTATION_180:
3150 // We are currently in the same basic orientation as the natural orientation
3151 naturalOri = configOri;
3152 break;
3153 case Surface.ROTATION_90:
3154 case Surface.ROTATION_270:
3155 // We are currently in the other basic orientation to the natural orientation
3156 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3157 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3158 break;
3159 }
3160
3161 int[] oriMap = {
3162 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3163 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3164 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3165 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3166 };
3167 // Since the map starts at portrait, we need to offset if this device's natural orientation
3168 // is landscape.
3169 int indexOffset = 0;
3170 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3171 indexOffset = 1;
3172 }
3173 return oriMap[(d.getRotation() + indexOffset) % 4];
3174 }
Adam Cohen446e9402011-09-15 18:21:21 -07003175
3176 public void lockScreenOrientationOnLargeUI() {
3177 if (LauncherApplication.isScreenLarge()) {
3178 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3179 .getConfiguration().orientation));
3180 }
Winson Chung400438b2011-01-16 17:53:48 -08003181 }
Adam Cohen446e9402011-09-15 18:21:21 -07003182 public void unlockScreenOrientationOnLargeUI() {
3183 if (LauncherApplication.isScreenLarge()) {
3184 mHandler.postDelayed(new Runnable() {
3185 public void run() {
3186 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3187 }
3188 }, mRestoreScreenOrientationDelay);
3189 }
Winson Chung400438b2011-01-16 17:53:48 -08003190 }
3191
Winson Chung82f55532011-08-09 14:14:23 -07003192 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003193 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3194 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003195 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003196 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003197
Winson Chung7d7541e2011-09-16 20:14:36 -07003198 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003199 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003200 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3201 Cling cling = (Cling) findViewById(clingId);
3202 if (cling != null) {
3203 cling.init(this, positionData);
3204 cling.setVisibility(View.VISIBLE);
3205 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3206 if (animate) {
3207 cling.buildLayer();
3208 cling.setAlpha(0f);
3209 cling.animate()
3210 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003211 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003212 .setDuration(SHOW_CLING_DURATION)
3213 .setStartDelay(delay)
3214 .start();
3215 } else {
3216 cling.setAlpha(1f);
3217 }
3218 }
3219 return cling;
3220 }
3221 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003222 if (cling != null) {
3223 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003224 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003225 anim.addListener(new AnimatorListenerAdapter() {
3226 public void onAnimationEnd(Animator animation) {
3227 cling.setVisibility(View.GONE);
3228 cling.cleanup();
3229 SharedPreferences prefs =
3230 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3231 SharedPreferences.Editor editor = prefs.edit();
3232 editor.putBoolean(flag, true);
3233 editor.commit();
3234 };
3235 });
3236 anim.start();
3237 }
3238 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003239 private void removeCling(int id) {
3240 final View cling = findViewById(id);
3241 if (cling != null) {
3242 final ViewGroup parent = (ViewGroup) cling.getParent();
3243 parent.post(new Runnable() {
3244 @Override
3245 public void run() {
3246 parent.removeView(cling);
3247 }
3248 });
3249 }
3250 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003251 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003252 // Enable the clings only if they have not been dismissed before
3253 SharedPreferences prefs =
3254 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003255 if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003256 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003257 } else {
3258 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003259 }
3260 }
3261 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003262 // Enable the clings only if they have not been dismissed before
3263 SharedPreferences prefs =
3264 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003265 if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003266 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003267 } else {
3268 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003269 }
3270 }
3271 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003272 // Enable the clings only if they have not been dismissed before
3273 SharedPreferences prefs =
3274 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
3275 Cling cling = null;
Winson Chung9d9d74f2011-09-19 11:49:12 -07003276 if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003277 cling = initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003278 } else {
3279 removeCling(R.id.folder_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003280 }
3281 return cling;
3282 }
3283 public boolean isFolderClingVisible() {
3284 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003285 if (cling != null) {
3286 return cling.getVisibility() == View.VISIBLE;
3287 }
3288 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003289 }
Winson Chung82f55532011-08-09 14:14:23 -07003290 public void dismissWorkspaceCling(View v) {
3291 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003292 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003293 }
3294 public void dismissAllAppsCling(View v) {
3295 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003296 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3297 }
3298 public void dismissFolderCling(View v) {
3299 Cling cling = (Cling) findViewById(R.id.folder_cling);
3300 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003301 }
3302
Winson Chung80baf5a2010-08-09 16:03:15 -07003303 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003304 * Prints out out state for debugging.
3305 */
3306 public void dumpState() {
3307 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003308 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003309 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3310 Log.d(TAG, "mRestoring=" + mRestoring);
3311 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3312 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003313 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003314 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003315
Winson Chung785d2eb2011-04-14 16:08:02 -07003316 if (mAppsCustomizeContent != null) {
3317 mAppsCustomizeContent.dumpState();
3318 }
Joe Onoratobe386092009-11-17 17:32:16 -08003319 Log.d(TAG, "END launcher2 dump state");
3320 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003321
3322 @Override
3323 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3324 super.dump(prefix, fd, writer, args);
3325 writer.println(" ");
3326 writer.println("Debug logs: ");
3327 for (int i = 0; i < sDumpLogs.size(); i++) {
3328 writer.println(" " + sDumpLogs.get(i));
3329 }
3330 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003331}
Michael Jurka2763be32011-02-24 11:19:57 -08003332
Michael Jurkaabded662011-03-04 12:06:57 -08003333interface LauncherTransitionable {
Michael Jurka1899a362011-11-03 13:50:45 -07003334 // return true if the callee will take care of start the animation by itself
3335 boolean onLauncherTransitionStart(Launcher l, Animator animation, boolean toWorkspace);
Winson Chung7d7541e2011-09-16 20:14:36 -07003336 void onLauncherTransitionEnd(Launcher l, Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003337}