blob: e156c989538a44bba23ad4fbd0686822f7be3bfd [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
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Michael Jurkaaf442092010-06-10 17:01:57 -070051import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070052import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040053import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070054import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020056import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080057import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070058import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070059import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040060import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080061import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070062import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080063import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.text.Selection;
65import android.text.SpannableStringBuilder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070067import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080068import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080069import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.view.KeyEvent;
71import android.view.LayoutInflater;
72import android.view.Menu;
73import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070074import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080075import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080077import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070078import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080079import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080080import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070081import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080082import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070083import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070084import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080085import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080086import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070087import android.widget.Advanceable;
Michael Jurkaaf442092010-06-10 17:01:57 -070088import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070089import android.widget.TextView;
90import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070091
Adam Cohendf2cc412011-04-27 16:56:57 -070092import com.android.common.Search;
93import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070094import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080095
Adam Cohenc0dcf592011-06-01 15:30:43 -070096import java.io.DataInputStream;
97import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -070098import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -070099import java.io.FileNotFoundException;
100import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700101import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700103import java.util.Collection;
104import java.util.Collections;
105import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700106import java.util.HashMap;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700107import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700108import java.util.List;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700109import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111/**
112 * Default launcher application.
113 */
Michael Jurka946ad472010-07-09 18:05:18 -0700114public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700115 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
116 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800117 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700118 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119
Joe Onorato9c1289c2009-08-17 11:03:03 -0400120 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400121 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700122 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700123
Winson Chung70d72102011-08-12 11:24:35 -0700124 private static final int MENU_GROUP_WALLPAPER = 1;
125 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
126 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700127 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
128 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129
130 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700131 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132 private static final int REQUEST_PICK_APPLICATION = 6;
133 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700135 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136
Michael Jurka8b805b12012-04-18 14:23:14 -0700137 private static final int REQUEST_BIND_APPWIDGET = 11;
138
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
140
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800141 static final int SCREEN_COUNT = 5;
142 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
Romain Guy98d01652009-06-30 16:21:04 -0700144 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800145 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146
Winson Chung2672ff92012-05-04 16:22:30 -0700147 // The Intent extra that defines whether to ignore the launch animation
148 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
149 "com.android.launcher.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
150
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 // Type: int
152 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700153 // Type: int
154 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700156 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
157 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
159 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700160 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700162 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 // Type: boolean
164 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
165 // Type: long
166 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700167 // Type: int
168 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
169 // Type: int
170 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
171 // Type: parcelable
172 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700174 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700175 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
176 "com.android.launcher.toolbar_search_icon";
177 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
178 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700179
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700180 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700181 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700182 private State mState = State.WORKSPACE;
183 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800184 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700185
Joe Onorato9c1289c2009-08-17 11:03:03 -0400186 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700187 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
188 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700189 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700190 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800193 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194
Winson Chunga2413752012-04-03 14:22:34 -0700195 // How long to wait before the new-shortcut animation automatically pans the workspace
196 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
197
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800198 private final BroadcastReceiver mCloseSystemDialogsReceiver
199 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800200 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
201
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 private LayoutInflater mInflater;
203
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800205 private View mQsbDivider;
206 private View mDockDivider;
207 private DragLayer mDragLayer;
208 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700209
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700210 private AppWidgetManager mAppWidgetManager;
211 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700212
Michael Jurkac9d95c52011-08-29 14:03:34 -0700213 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700214 private AppWidgetProviderInfo mPendingAddWidgetInfo;
215
Michael Jurka0280c3b2010-09-17 15:00:07 -0700216 private int[] mTmpAddItemCellCoordinates = new int[2];
217
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218 private FolderInfo mFolderInfo;
219
Winson Chung3d503fb2011-07-13 17:25:49 -0700220 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800221 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700222
Winson Chungc51db6a2011-10-05 11:44:49 -0700223 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700224 private AppsCustomizeTabHost mAppsCustomizeTabHost;
225 private AppsCustomizePagedView mAppsCustomizeContent;
226 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800227
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228 private Bundle mSavedState;
229
230 private SpannableStringBuilder mDefaultKeySsb = null;
231
Joe Onorato9c1289c2009-08-17 11:03:03 -0400232 private boolean mWorkspaceLoading = true;
233
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800234 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private boolean mRestoring;
236 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700237 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238
239 private Bundle mSavedInstanceState;
240
Joe Onorato9c1289c2009-08-17 11:03:03 -0400241 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800242 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800243 private boolean mUserPresent = true;
244 private boolean mVisible = false;
245 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400246
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700247 private static LocaleConfiguration sLocaleConfiguration = null;
248
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700249 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700250
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700251 private Intent mAppMarketIntent = null;
252
Adam Cohended9f8d2010-11-03 13:25:16 -0700253 // Related to the auto-advancing of widgets
254 private final int ADVANCE_MSG = 1;
255 private final int mAdvanceInterval = 20000;
256 private final int mAdvanceStagger = 250;
257 private long mAutoAdvanceSentTime;
258 private long mAutoAdvanceTimeLeft = -1;
259 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
260 new HashMap<View, AppWidgetProviderInfo>();
261
Winson Chung400438b2011-01-16 17:53:48 -0800262 // Determines how long to wait after a rotation before restoring the screen orientation to
263 // match the sensor state.
264 private final int mRestoreScreenOrientationDelay = 500;
265
Michael Jurka4ef207b2010-11-29 17:05:45 -0800266 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700267 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
268 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
269 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800270
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700271 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
272
Winson Chung46353de2012-02-16 14:05:10 -0800273 // We only want to get the SharedPreferences once since it does an FS stat each time we get
274 // it from the context.
275 private SharedPreferences mSharedPrefs;
276
Winson Chungf0c6ae02012-03-21 16:10:31 -0700277 // Holds the page that we need to animate to, and the icon views that we need to animate up
278 // when we scroll to that page on resume.
279 private int mNewShortcutAnimatePage = -1;
280 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen2801caf2011-05-13 20:57:39 -0700281
Michael Jurkaddd62e92011-02-16 17:49:14 -0800282 private BubbleTextView mWaitingForResume;
283
Michael Jurkac1f5d262011-09-30 19:32:27 -0700284 private Runnable mBuildLayersRunnable = new Runnable() {
285 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700286 if (mWorkspace != null) {
287 mWorkspace.buildPageHardwareLayers();
288 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700289 }
290 };
291
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800292 private static ArrayList<PendingAddArguments> sPendingAddList
293 = new ArrayList<PendingAddArguments>();
294
295 private static class PendingAddArguments {
296 int requestCode;
297 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700298 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800299 int screen;
300 int cellX;
301 int cellY;
302 }
303
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800304 @Override
305 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700306 if (DEBUG_STRICT_MODE) {
307 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
308 .detectDiskReads()
309 .detectDiskWrites()
310 .detectNetwork() // or .detectAll() for all detectable problems
311 .penaltyLog()
312 .build());
313 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
314 .detectLeakedSqlLiteObjects()
315 .detectLeakedClosableObjects()
316 .penaltyLog()
317 .penaltyDeath()
318 .build());
319 }
320
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800322 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700323 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
324 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800325 mModel = app.setLauncher(this);
326 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400327 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800328 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700329
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700330 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700331 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
332 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700333
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800334 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200335 android.os.Debug.startMethodTracing(
336 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800337 }
338
339 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800340 setContentView(R.layout.launcher);
341 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700342 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800344 registerContentObservers();
345
Joe Onorato7c312c12009-08-13 21:36:53 -0700346 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700347
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800348 mSavedState = savedInstanceState;
349 restoreState(mSavedState);
350
Winson Chunga12a2502010-12-20 14:41:35 -0800351 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700352 if (mAppsCustomizeContent != null) {
Winson Chung7c7a22d2012-06-01 13:46:48 -0700353 Log.d(TAG, "6549598 Launcher.onCreate()");
Winson Chung785d2eb2011-04-14 16:08:02 -0700354 mAppsCustomizeContent.onPackagesUpdated();
355 }
Winson Chunga12a2502010-12-20 14:41:35 -0800356
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800357 if (PROFILE_STARTUP) {
358 android.os.Debug.stopMethodTracing();
359 }
360
361 if (!mRestoring) {
Winson Chungf0c6ae02012-03-21 16:10:31 -0700362 mModel.startLoader(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800363 }
364
Michael Jurkac57b7a82011-08-09 22:02:20 -0700365 if (!mModel.isAllAppsLoaded()) {
366 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
367 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
368 }
369
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 // For handling default keys
371 mDefaultKeySsb = new SpannableStringBuilder();
372 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800373
374 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
375 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800376
Adam Cohenf9426d52012-06-04 17:26:21 -0700377 updateGlobalIcons();
378
379 // On large interfaces, we want the screen to auto-rotate based on the current orientation
380 unlockScreenOrientation(true);
381 }
382
383 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700384 boolean searchVisible = false;
385 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800386 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700387 int coi = getCurrentOrientationIndexForGlobalIcons();
388 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
389 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700390 updateAppMarketIcon();
391 searchVisible = updateGlobalSearchIcon();
392 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700393 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700394 if (sGlobalSearchIcon[coi] != null) {
395 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700396 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700397 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700398 if (sVoiceSearchIcon[coi] != null) {
399 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700400 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700401 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700402 if (sAppMarketIcon[coi] != null) {
403 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800404 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700405 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 }
Romain Guycbb89e42009-06-08 15:52:54 -0700407
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700409 if (sLocaleConfiguration == null) {
410 new AsyncTask<Void, Void, LocaleConfiguration>() {
411 @Override
412 protected LocaleConfiguration doInBackground(Void... unused) {
413 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
414 readConfiguration(Launcher.this, localeConfiguration);
415 return localeConfiguration;
416 }
417
418 @Override
419 protected void onPostExecute(LocaleConfiguration result) {
420 sLocaleConfiguration = result;
421 checkForLocaleChange(); // recursive, but now with a locale configuration
422 }
423 }.execute();
424 return;
425 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700426
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 final Configuration configuration = getResources().getConfiguration();
428
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700429 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800430 final String locale = configuration.locale.toString();
431
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700432 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 final int mcc = configuration.mcc;
434
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700435 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 final int mnc = configuration.mnc;
437
Romain Guy84f296c2009-11-04 15:00:44 -0800438 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439
Romain Guy84f296c2009-11-04 15:00:44 -0800440 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700441 sLocaleConfiguration.locale = locale;
442 sLocaleConfiguration.mcc = mcc;
443 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700444
Joe Onorato0589f0f2010-02-08 13:44:00 -0800445 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700446
447 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
448 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700449 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700450 public void run() {
451 writeConfiguration(Launcher.this, localeConfiguration);
452 }
453 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700454 }
455 }
456
457 private static class LocaleConfiguration {
458 public String locale;
459 public int mcc = -1;
460 public int mnc = -1;
461 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700462
Romain Guy98d01652009-06-30 16:21:04 -0700463 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
464 DataInputStream in = null;
465 try {
466 in = new DataInputStream(context.openFileInput(PREFERENCES));
467 configuration.locale = in.readUTF();
468 configuration.mcc = in.readInt();
469 configuration.mnc = in.readInt();
470 } catch (FileNotFoundException e) {
471 // Ignore
472 } catch (IOException e) {
473 // Ignore
474 } finally {
475 if (in != null) {
476 try {
477 in.close();
478 } catch (IOException e) {
479 // Ignore
480 }
481 }
482 }
483 }
484
485 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
486 DataOutputStream out = null;
487 try {
488 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
489 out.writeUTF(configuration.locale);
490 out.writeInt(configuration.mcc);
491 out.writeInt(configuration.mnc);
492 out.flush();
493 } catch (FileNotFoundException e) {
494 // Ignore
495 } catch (IOException e) {
496 //noinspection ResultOfMethodCallIgnored
497 context.getFileStreamPath(PREFERENCES).delete();
498 } finally {
499 if (out != null) {
500 try {
501 out.close();
502 } catch (IOException e) {
503 // Ignore
504 }
505 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800506 }
507 }
508
Adam Cohen716b51e2011-06-30 12:09:54 -0700509 public DragLayer getDragLayer() {
510 return mDragLayer;
511 }
512
Winson Chung36a62fe2012-05-06 18:04:42 -0700513 boolean isDraggingEnabled() {
514 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
515 // that is subsequently removed from the workspace in startBinding().
516 return !mModel.isLoadingWorkspace();
517 }
518
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800519 static int getScreen() {
520 synchronized (sLock) {
521 return sScreen;
522 }
523 }
524
525 static void setScreen(int screen) {
526 synchronized (sLock) {
527 sScreen = screen;
528 }
529 }
530
Winson Chung557d6ed2011-07-08 15:34:52 -0700531 /**
532 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
533 * a configuration step, this allows the proper animations to run after other transitions.
534 */
535 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700536 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800537 switch (args.requestCode) {
538 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700539 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
540 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800541 break;
542 case REQUEST_PICK_SHORTCUT:
543 processShortcut(args.intent);
544 break;
545 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700546 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
547 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700548 result = true;
549 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800550 case REQUEST_CREATE_APPWIDGET:
551 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800552 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700553 result = true;
554 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800555 case REQUEST_PICK_WALLPAPER:
556 // We just wanted the activity result here so we can clear mWaitingForResult
557 break;
558 }
Michael Jurka27614d22012-04-02 06:40:22 -0700559 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
560 // if you turned the screen off and then back while in All Apps, Launcher would not
561 // return to the workspace. Clearing mAddInfo.container here fixes this issue
562 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700563 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800564 }
565
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700567 protected void onActivityResult(
568 final int requestCode, final int resultCode, final Intent data) {
569 if (requestCode == REQUEST_BIND_APPWIDGET) {
570 int appWidgetId = data != null ?
571 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
572 if (resultCode == RESULT_CANCELED) {
573 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
574 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700575 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700576 }
577 return;
578 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700579 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800580 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
581 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700582 mWaitingForResult = false;
583
Adam Cohened66b2b2012-01-23 17:28:51 -0800584 // We have special handling for widgets
585 if (isWidgetDrop) {
586 int appWidgetId = data != null ?
587 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700588 if (appWidgetId < 0) {
589 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
590 "widget configuration activity.");
591 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
592 } else {
593 completeTwoStageWidgetDrop(resultCode, appWidgetId);
594 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800595 return;
596 }
597
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800598 // The pattern used here is that a user PICKs a specific application,
599 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700600
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800601 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
602 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700603 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800604 final PendingAddArguments args = new PendingAddArguments();
605 args.requestCode = requestCode;
606 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700607 args.container = mPendingAddInfo.container;
608 args.screen = mPendingAddInfo.screen;
609 args.cellX = mPendingAddInfo.cellX;
610 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800611 if (isWorkspaceLocked()) {
612 sPendingAddList.add(args);
613 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700614 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800615 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800616 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800617 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700618 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800619 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
620 null);
621 }
622
623 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700624 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700625 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800626 Runnable onCompleteRunnable = null;
627 int animationType = 0;
628
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700629 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800630 if (resultCode == RESULT_OK) {
631 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
632 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700633 mPendingAddWidgetInfo);
634 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800635 onCompleteRunnable = new Runnable() {
636 @Override
637 public void run() {
638 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
639 mPendingAddInfo.screen, layout, null);
640 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
641 null);
642 }
643 };
644 } else if (resultCode == RESULT_CANCELED) {
645 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
646 onCompleteRunnable = new Runnable() {
647 @Override
648 public void run() {
649 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
650 null);
651 }
652 };
653 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700654 if (mDragLayer.getAnimatedView() != null) {
655 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
656 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
657 animationType, boundWidget, true);
658 } else {
659 // The animated view may be null in the case of a rotation during widget configuration
660 onCompleteRunnable.run();
661 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 }
663
664 @Override
665 protected void onResume() {
666 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700667
Winson Chungde0fb8f2012-05-08 14:37:08 -0700668 // Process any items that were added while Launcher was away
669 InstallShortcutReceiver.flushInstallQueue(this);
670
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800671 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700672 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400673 mWorkspaceLoading = true;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700674 mModel.startLoader(true);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400675 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700676 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800677 }
Winson Chunge4e50662012-01-23 14:45:13 -0800678
679 // Reset the pressed state of icons that were locked in the press state while activities
680 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800681 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800682 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800683 mWaitingForResume.setStayPressed(false);
684 }
Winson Chunge4e50662012-01-23 14:45:13 -0800685 if (mAppsCustomizeContent != null) {
686 // Resets the previous all apps icon press state
687 mAppsCustomizeContent.resetDrawableState();
688 }
Adam Cohen06dff352012-06-01 17:17:08 -0700689 // It is possible that widgets can receive updates while launcher is not in the foreground.
690 // Consequently, the widgets will be inflated in the orientation of the foreground activity
691 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
692 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700693 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700694
695 // Again, as with the above scenario, it's possible that one or more of the global icons
696 // were updated in the wrong orientation.
697 updateGlobalIcons();
Adam Cohen06dff352012-06-01 17:17:08 -0700698 }
699
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800700 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700701 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700702 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
703 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
704 // when Launcher resumes and we are still in AllApps.
705 updateWallpaperVisibility(true);
706
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700707 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700708 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800709 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700710 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700711 }
Romain Guycbb89e42009-06-08 15:52:54 -0700712
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700713 @Override
714 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400715 // Flag the loader to stop early before switching
716 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700717 if (mAppsCustomizeContent != null) {
718 mAppsCustomizeContent.surrender();
719 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800720 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700721 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700722
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800723 // We can't hide the IME if it was forced open. So don't bother
724 /*
725 @Override
726 public void onWindowFocusChanged(boolean hasFocus) {
727 super.onWindowFocusChanged(hasFocus);
728
729 if (hasFocus) {
730 final InputMethodManager inputManager = (InputMethodManager)
731 getSystemService(Context.INPUT_METHOD_SERVICE);
732 WindowManager.LayoutParams lp = getWindow().getAttributes();
733 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
734 android.os.Handler()) {
735 protected void onReceiveResult(int resultCode, Bundle resultData) {
736 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
737 }
738 });
739 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
740 }
741 }
742 */
743
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800744 private boolean acceptFilter() {
745 final InputMethodManager inputManager = (InputMethodManager)
746 getSystemService(Context.INPUT_METHOD_SERVICE);
747 return !inputManager.isFullscreenMode();
748 }
749
750 @Override
751 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700752 final int uniChar = event.getUnicodeChar();
753 final boolean handled = super.onKeyDown(keyCode, event);
754 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
755 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
757 keyCode, event);
758 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700759 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700760 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700761 // showSearchDialog()
762 // If there are multiple keystrokes before the search dialog takes focus,
763 // onSearchRequested() will be called for every keystroke,
764 // but it is idempotent, so it's fine.
765 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800766 }
767 }
768
Joe Onorato8a9625e2010-01-28 15:55:35 -0800769 // Eat the long press event so the keyboard doesn't come up.
770 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
771 return true;
772 }
773
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800774 return handled;
775 }
776
Karl Rosaen138a0412009-04-23 19:00:21 -0700777 private String getTypedText() {
778 return mDefaultKeySsb.toString();
779 }
780
781 private void clearTypedText() {
782 mDefaultKeySsb.clear();
783 mDefaultKeySsb.clearSpans();
784 Selection.setSelection(mDefaultKeySsb, 0);
785 }
786
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800787 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700788 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
789 * State
790 */
791 private static State intToState(int stateOrdinal) {
792 State state = State.WORKSPACE;
793 final State[] stateValues = State.values();
794 for (int i = 0; i < stateValues.length; i++) {
795 if (stateValues[i].ordinal() == stateOrdinal) {
796 state = stateValues[i];
797 break;
798 }
799 }
800 return state;
801 }
802
803 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800804 * Restores the previous state, if it exists.
805 *
806 * @param savedState The previous state.
807 */
808 private void restoreState(Bundle savedState) {
809 if (savedState == null) {
810 return;
811 }
812
Michael Jurka883f55b2010-10-21 15:47:14 -0700813 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700814 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800815 showAllApps(false);
816 }
817
Winson Chungf0c6ae02012-03-21 16:10:31 -0700818 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800819 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700820 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800821 }
822
Winson Chung3d503fb2011-07-13 17:25:49 -0700823 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
824 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700825
Winson Chung3d503fb2011-07-13 17:25:49 -0700826 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
827 mPendingAddInfo.container = pendingAddContainer;
828 mPendingAddInfo.screen = pendingAddScreen;
829 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
830 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700831 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
832 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
833 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700834 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800835 mRestoring = true;
836 }
837
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700838
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800839 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
840 if (renameFolder) {
841 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700842 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 mRestoring = true;
844 }
Winson Chunga12a2502010-12-20 14:41:35 -0800845
Winson Chung785d2eb2011-04-14 16:08:02 -0700846
847 // Restore the AppsCustomize tab
848 if (mAppsCustomizeTabHost != null) {
849 String curTab = savedState.getString("apps_customize_currentTab");
850 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700851 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700852 mAppsCustomizeContent.setContentType(
853 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
854 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700855 mAppsCustomizeContent.loadAssociatedPages(
856 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700857 }
858
Winson Chung5afbf7b2011-07-25 11:53:08 -0700859 int currentIndex = savedState.getInt("apps_customize_currentIndex");
860 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700861 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800862 }
863
864 /**
865 * Finds all the views we need and configure them properly.
866 */
867 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700868 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400869
Winson Chung4c98d922011-05-31 16:50:48 -0700870 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
871 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800872 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
873 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800874
Winson Chung4c98d922011-05-31 16:50:48 -0700875 // Setup the drag layer
876 mDragLayer.setup(this, dragController);
877
Winson Chung3d503fb2011-07-13 17:25:49 -0700878 // Setup the hotseat
879 mHotseat = (Hotseat) findViewById(R.id.hotseat);
880 if (mHotseat != null) {
881 mHotseat.setup(this);
882 }
883
Winson Chung4c98d922011-05-31 16:50:48 -0700884 // Setup the workspace
885 mWorkspace.setHapticFeedbackEnabled(false);
886 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700887 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700888 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700889
Winson Chungf0ea4d32011-06-06 14:27:16 -0700890 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700891 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700892
Winson Chungf0ea4d32011-06-06 14:27:16 -0700893 // Setup AppsCustomize
894 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
895 findViewById(R.id.apps_customize_pane);
896 mAppsCustomizeContent = (AppsCustomizePagedView)
897 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
Winson Chungc7450e32012-04-17 17:34:08 -0700898 mAppsCustomizeTabHost.setup(this);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700899 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400900
Michael Jurka5130e402011-10-13 04:55:35 -0700901 // Get the all apps button
902 mAllAppsButton = findViewById(R.id.all_apps_button);
903 if (mAllAppsButton != null) {
904 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
905 @Override
906 public boolean onTouch(View v, MotionEvent event) {
907 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
908 onTouchDownAllAppsButton(v);
909 }
910 return false;
911 }
912 });
913 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700914 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700915 dragController.setDragScoller(mWorkspace);
916 dragController.setScrollView(mDragLayer);
917 dragController.setMoveTarget(mWorkspace);
918 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700919 if (mSearchDropTargetBar != null) {
920 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800921 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922 }
923
924 /**
925 * Creates a view representing a shortcut.
926 *
927 * @param info The data structure describing the shortcut.
928 *
929 * @return A View inflated from R.layout.application.
930 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800931 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800932 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700933 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800934 }
935
936 /**
937 * Creates a view representing a shortcut inflated from the specified resource.
938 *
939 * @param layoutResId The id of the XML layout used to create the shortcut.
940 * @param parent The group the shortcut belongs to.
941 * @param info The data structure describing the shortcut.
942 *
943 * @return A View inflated from layoutResId.
944 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800945 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800946 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
947 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800948 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800949 return favorite;
950 }
951
952 /**
953 * Add an application shortcut to the workspace.
954 *
955 * @param data The intent describing the application.
956 * @param cellInfo The position on screen where to create the shortcut.
957 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700958 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700959 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700960 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700961
Adam Cohenfbba09b2011-07-18 21:43:05 -0700962 // First we check if we already know the exact location where we want to add this item.
963 if (cellX >= 0 && cellY >= 0) {
964 cellXY[0] = cellX;
965 cellXY[1] = cellY;
966 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -0700967 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700968 return;
969 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800970
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800971 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800972
Romain Guy73b979d2009-06-09 12:57:21 -0700973 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800974 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800975 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800976 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700977 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700978 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800979 } else {
980 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981 }
982 }
Romain Guycbb89e42009-06-08 15:52:54 -0700983
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800984 /**
985 * Add a shortcut to the workspace.
986 *
987 * @param data The intent describing the shortcut.
988 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800989 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700990 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
991 int cellY) {
992 int[] cellXY = mTmpAddItemCellCoordinates;
993 int[] touchXY = mPendingAddInfo.dropPos;
994 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700995
Michael Jurkad3ef3062010-11-23 16:23:58 -0800996 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700997
Adam Cohen558baaf2011-08-15 15:22:57 -0700998 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800999 if (info == null) {
1000 return;
1001 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001002 final View view = createShortcut(info);
1003
Adam Cohenfbba09b2011-07-18 21:43:05 -07001004 // First we check if we already know the exact location where we want to add this item.
1005 if (cellX >= 0 && cellY >= 0) {
1006 cellXY[0] = cellX;
1007 cellXY[1] = cellY;
1008 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001009
1010 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001011 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001012 true, null,null)) {
1013 return;
1014 }
1015 DragObject dragObject = new DragObject();
1016 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001017 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1018 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001019 return;
1020 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001021 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001022 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001023 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001024 foundCellSpan = (result != null);
1025 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001026 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001027 }
1028
1029 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001030 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001031 return;
1032 }
1033
Adam Cohen558baaf2011-08-15 15:22:57 -07001034 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001035
1036 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001037 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1038 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001039 }
1040 }
1041
Adam Cohen2f093b62012-04-30 18:59:53 -07001042 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1043 int minHeight) {
1044 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001045 // We want to account for the extra amount of padding that we are adding to the widget
1046 // to ensure that it gets the full amount of space that it has requested
1047 int requiredWidth = minWidth + padding.left + padding.right;
1048 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001049 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001050 }
1051
Adam Cohen2f093b62012-04-30 18:59:53 -07001052 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1053 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001054 }
1055
Adam Cohen2f093b62012-04-30 18:59:53 -07001056 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1057 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001058 }
1059
Adam Cohen2f093b62012-04-30 18:59:53 -07001060 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1061 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001062 }
1063
Adam Cohen2f093b62012-04-30 18:59:53 -07001064 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1065 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001066 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001067 }
1068
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001069 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001070 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001072 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001073 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001075 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1076 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1077 if (appWidgetInfo == null) {
1078 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1079 }
Romain Guycbb89e42009-06-08 15:52:54 -07001080
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001081 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001082 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001083
Adam Cohen2f093b62012-04-30 18:59:53 -07001084 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1085 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001086
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001087 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001088 // We have saved the position to which the widget was dragged-- this really only matters
1089 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001090 int[] cellXY = mTmpAddItemCellCoordinates;
1091 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001092 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001093 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001094 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1095 cellXY[0] = mPendingAddInfo.cellX;
1096 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001097 spanXY[0] = mPendingAddInfo.spanX;
1098 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001099 foundCellSpan = true;
1100 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001101 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001102 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001103 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1104 spanXY[1], cellXY, finalSpan);
1105 spanXY[0] = finalSpan[0];
1106 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001107 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001108 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001109 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001110 }
1111
Michael Jurka0280c3b2010-09-17 15:00:07 -07001112 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001113 if (appWidgetId != -1) {
1114 // Deleting an app widget ID is a void call but writes to disk before returning
1115 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001116 new Thread("deleteAppWidgetId") {
1117 public void run() {
1118 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1119 }
1120 }.start();
1121 }
Winson Chung93eef082012-03-23 15:59:27 -07001122 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001123 return;
1124 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001125
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001126 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001127 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1128 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001129 launcherInfo.spanX = spanXY[0];
1130 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001131 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1132 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001133
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001134 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001135 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001136
1137 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001138 if (hostView == null) {
1139 // Perform actual inflation because we're live
1140 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1141 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1142 } else {
1143 // The AppWidgetHostView has already been inflated and instantiated
1144 launcherInfo.hostView = hostView;
1145 }
Romain Guycbb89e42009-06-08 15:52:54 -07001146
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001148 launcherInfo.hostView.setVisibility(View.VISIBLE);
Winson Chung211bac32012-05-15 13:43:57 -07001149 launcherInfo.notifyWidgetSizeChanged(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001150 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001151 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001152
1153 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001154 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001155 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001156 }
Romain Guycbb89e42009-06-08 15:52:54 -07001157
Adam Cohended9f8d2010-11-03 13:25:16 -07001158 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1159 @Override
1160 public void onReceive(Context context, Intent intent) {
1161 final String action = intent.getAction();
1162 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1163 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001164 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001165 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001166
Winson Chungc100e8e2011-08-09 16:02:43 -07001167 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001168 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001169 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1170 mAppsCustomizeTabHost.reset();
1171 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001172 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001173 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1174 mUserPresent = true;
1175 updateRunning();
1176 }
1177 }
1178 };
1179
1180 @Override
1181 public void onAttachedToWindow() {
1182 super.onAttachedToWindow();
1183
1184 // Listen for broadcasts related to user-presence
1185 final IntentFilter filter = new IntentFilter();
1186 filter.addAction(Intent.ACTION_SCREEN_OFF);
1187 filter.addAction(Intent.ACTION_USER_PRESENT);
1188 registerReceiver(mReceiver, filter);
1189
Adam Cohend113e0c2010-11-11 10:48:05 -08001190 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001191 mVisible = true;
1192 }
1193
1194 @Override
1195 public void onDetachedFromWindow() {
1196 super.onDetachedFromWindow();
1197 mVisible = false;
1198
Adam Cohend113e0c2010-11-11 10:48:05 -08001199 if (mAttached) {
1200 unregisterReceiver(mReceiver);
1201 mAttached = false;
1202 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001203 updateRunning();
1204 }
1205
1206 public void onWindowVisibilityChanged(int visibility) {
1207 mVisible = visibility == View.VISIBLE;
1208 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001209 // The following code used to be in onResume, but it turns out onResume is called when
1210 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1211 // is a more appropriate event to handle
1212 if (mVisible) {
1213 mAppsCustomizeTabHost.onWindowVisible();
1214 if (!mWorkspaceLoading) {
1215 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001216 // We want to let Launcher draw itself at least once before we force it to build
1217 // layers on all the workspace pages, so that transitioning to Launcher from other
1218 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1219 // a true draw so we wait until the second preDraw call to be safe
1220 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001221 public boolean onPreDraw() {
Michael Jurka6ee21d22012-02-21 18:20:27 -08001222 // We delay the layer building a bit in order to give
1223 // other message processing a time to run. In particular
1224 // this avoids a delay in hiding the IME if it was
1225 // currently shown, because doing that may involve
1226 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001227 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Winson Chung31ce0732012-05-06 13:36:43 -07001228
1229 // We had to enable the wallpaper visibility when launching apps from all
1230 // apps (so that the transitions would be the same as when launching from
1231 // workspace) so take this time to see if we need to re-disable the
1232 // wallpaper visibility to ensure performance.
1233 mWorkspace.post(new Runnable() {
1234 @Override
1235 public void run() {
Winson Chung18f41f82012-05-09 13:28:10 -07001236 disableWallpaperIfInAllApps();
Winson Chung31ce0732012-05-06 13:36:43 -07001237 }
1238 });
1239
Michael Jurka6ee21d22012-02-21 18:20:27 -08001240 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001241 return true;
1242 }
1243 });
1244 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001245 // When Launcher comes back to foreground, a different Activity might be responsible for
1246 // the app market intent, so refresh the icon
1247 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001248 clearTypedText();
1249 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001250 }
1251
1252 private void sendAdvanceMessage(long delay) {
1253 mHandler.removeMessages(ADVANCE_MSG);
1254 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1255 mHandler.sendMessageDelayed(msg, delay);
1256 mAutoAdvanceSentTime = System.currentTimeMillis();
1257 }
1258
1259 private void updateRunning() {
1260 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1261 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1262 mAutoAdvanceRunning = autoAdvanceRunning;
1263 if (autoAdvanceRunning) {
1264 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1265 sendAdvanceMessage(delay);
1266 } else {
1267 if (!mWidgetsToAdvance.isEmpty()) {
1268 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1269 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1270 }
1271 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001272 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001273 }
1274 }
1275 }
1276
1277 private final Handler mHandler = new Handler() {
1278 @Override
1279 public void handleMessage(Message msg) {
1280 if (msg.what == ADVANCE_MSG) {
1281 int i = 0;
1282 for (View key: mWidgetsToAdvance.keySet()) {
1283 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1284 final int delay = mAdvanceStagger * i;
1285 if (v instanceof Advanceable) {
1286 postDelayed(new Runnable() {
1287 public void run() {
1288 ((Advanceable) v).advance();
1289 }
1290 }, delay);
1291 }
1292 i++;
1293 }
1294 sendAdvanceMessage(mAdvanceInterval);
1295 }
1296 }
1297 };
1298
1299 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001300 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001301 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1302 if (v instanceof Advanceable) {
1303 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001304 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001305 updateRunning();
1306 }
1307 }
1308
1309 void removeWidgetToAutoAdvance(View hostView) {
1310 if (mWidgetsToAdvance.containsKey(hostView)) {
1311 mWidgetsToAdvance.remove(hostView);
1312 updateRunning();
1313 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001314 }
1315
Joe Onorato9c1289c2009-08-17 11:03:03 -04001316 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001317 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001318 launcherInfo.hostView = null;
1319 }
1320
Winson Chung93eef082012-03-23 15:59:27 -07001321 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1322 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1323 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001324 }
1325
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001326 public LauncherAppWidgetHost getAppWidgetHost() {
1327 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 }
Romain Guycbb89e42009-06-08 15:52:54 -07001329
Winson Chunga9abd0e2010-10-27 17:18:37 -07001330 public LauncherModel getModel() {
1331 return mModel;
1332 }
1333
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001334 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001335 getWindow().closeAllPanels();
1336
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001337 // Whatever we were doing is hereby canceled.
1338 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001339 }
1340
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001341 @Override
1342 protected void onNewIntent(Intent intent) {
1343 super.onNewIntent(intent);
1344
1345 // Close the menu
1346 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001347 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001348 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001349
Joe Onorato14f122b2009-11-19 14:06:36 -08001350 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1351 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001352
Adam Cohenac56cff2011-09-28 20:45:37 -07001353 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001354 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001355 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001356 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1357 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001358 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001359 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001360
1361 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001362 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001363 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001364
Joe Onorato3a8820b2009-11-10 15:06:42 -08001365 final View v = getWindow().peekDecorView();
1366 if (v != null && v.getWindowToken() != null) {
1367 InputMethodManager imm = (InputMethodManager)getSystemService(
1368 INPUT_METHOD_SERVICE);
1369 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001371
Michael Jurka35aa14d2011-07-07 17:01:08 -07001372 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001373 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001374 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001375 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001376 }
1377 }
1378
1379 @Override
1380 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1381 // Do not call super here
1382 mSavedInstanceState = savedInstanceState;
1383 }
1384
1385 @Override
1386 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001387 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001388 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389
Michael Jurka883f55b2010-10-21 15:47:14 -07001390 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001391 // We close any open folder since it will not be re-opened, and we need to make sure
1392 // this state is reflected.
1393 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394
Winson Chung3d503fb2011-07-13 17:25:49 -07001395 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1396 mWaitingForResult) {
1397 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1398 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1399 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1400 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001401 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1402 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1403 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 }
1405
1406 if (mFolderInfo != null && mWaitingForResult) {
1407 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1408 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1409 }
Michael Jurka946ad472010-07-09 18:05:18 -07001410
Winson Chung785d2eb2011-04-14 16:08:02 -07001411 // Save the current AppsCustomize tab
1412 if (mAppsCustomizeTabHost != null) {
1413 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1414 if (currentTabTag != null) {
1415 outState.putString("apps_customize_currentTab", currentTabTag);
1416 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001417 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1418 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001419 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 }
1421
1422 @Override
1423 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001425
Winson Chunge7a03942011-08-05 15:05:12 -07001426 // Remove all pending runnables
1427 mHandler.removeMessages(ADVANCE_MSG);
1428 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001429 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001430
Winson Chungcd2b0142011-06-08 16:02:26 -07001431 // Stop callbacks from LauncherModel
1432 LauncherApplication app = ((LauncherApplication) getApplication());
1433 mModel.stopLoader();
1434 app.setLauncher(null);
1435
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001437 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001439 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001441 mAppWidgetHost = null;
1442
1443 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444
1445 TextKeyListener.getInstance().release();
1446
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447
Winson Chung3d503fb2011-07-13 17:25:49 -07001448 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001449
1450 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001451 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001452
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001453 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001454 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1455 mWorkspace.removeAllViews();
1456 mWorkspace = null;
1457 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001458
1459 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001460 }
1461
Adam Cohena9cf38f2011-05-02 15:36:58 -07001462 public DragController getDragController() {
1463 return mDragController;
1464 }
1465
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 @Override
1467 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001468 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001469 super.startActivityForResult(intent, requestCode);
1470 }
1471
Winson Chung70d72102011-08-12 11:24:35 -07001472 /**
1473 * Indicates that we want global search for this activity by setting the globalSearch
1474 * argument for {@link #startSearch} to true.
1475 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001477 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001479
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001480 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001481
Karl Rosaen138a0412009-04-23 19:00:21 -07001482 if (initialQuery == null) {
1483 // Use any text typed in the launcher as the initial query
1484 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001485 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001486 if (appSearchData == null) {
1487 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001488 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001490 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001491
Karl Rosaen138a0412009-04-23 19:00:21 -07001492 final SearchManager searchManager =
1493 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001494 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001495 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 }
1497
Winson Chung70d72102011-08-12 11:24:35 -07001498 @Override
1499 public boolean onCreateOptionsMenu(Menu menu) {
1500 if (isWorkspaceLocked()) {
1501 return false;
1502 }
1503
1504 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001505
1506 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1507 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1508 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001509 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1510 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1511 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001512 String helpUrl = getString(R.string.help_url);
1513 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001514 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1515 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1516
Winson Chung70d72102011-08-12 11:24:35 -07001517 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1518 .setIcon(android.R.drawable.ic_menu_gallery)
1519 .setAlphabeticShortcut('W');
1520 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1521 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001522 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001523 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001524 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1525 .setIcon(android.R.drawable.ic_menu_preferences)
1526 .setIntent(settings)
1527 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001528 if (!helpUrl.isEmpty()) {
1529 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1530 .setIcon(android.R.drawable.ic_menu_help)
1531 .setIntent(help)
1532 .setAlphabeticShortcut('H');
1533 }
Winson Chung70d72102011-08-12 11:24:35 -07001534 return true;
1535 }
1536
1537 @Override
1538 public boolean onPrepareOptionsMenu(Menu menu) {
1539 super.onPrepareOptionsMenu(menu);
1540
1541 if (mAppsCustomizeTabHost.isTransitioning()) {
1542 return false;
1543 }
1544 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1545 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1546
1547 return true;
1548 }
1549
1550 @Override
1551 public boolean onOptionsItemSelected(MenuItem item) {
1552 switch (item.getItemId()) {
1553 case MENU_WALLPAPER_SETTINGS:
1554 startWallpaper();
1555 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001556 }
1557
1558 return super.onOptionsItemSelected(item);
1559 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001561 @Override
1562 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001563 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001564 // Use a custom animation for launching search
1565 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001566 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001567 }
1568
Joe Onorato9c1289c2009-08-17 11:03:03 -04001569 public boolean isWorkspaceLocked() {
1570 return mWorkspaceLoading || mWaitingForResult;
1571 }
1572
Michael Jurka0280c3b2010-09-17 15:00:07 -07001573 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001574 mPendingAddInfo.container = ItemInfo.NO_ID;
1575 mPendingAddInfo.screen = -1;
1576 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1577 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001578 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001579 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001580 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001581
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001582 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1583 AppWidgetProviderInfo appWidgetInfo) {
1584 if (appWidgetInfo.configure != null) {
1585 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001586
Bjorn Bringert7984c942009-12-09 15:38:25 +00001587 // Launch over to configure widget, if needed
1588 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001589 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001590 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001591 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001593 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001594 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1595 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001596 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001597 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001598 }
1599 }
Romain Guycbb89e42009-06-08 15:52:54 -07001600
Adam Cohenfbba09b2011-07-18 21:43:05 -07001601 /**
1602 * Process a shortcut drop.
1603 *
1604 * @param componentName The name of the component
1605 * @param screen The screen where it should be added
1606 * @param cell The cell it should be added to, optional
1607 * @param position The location on the screen where it was dropped, optional
1608 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001609 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1610 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001611 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001612 mPendingAddInfo.container = container;
1613 mPendingAddInfo.screen = screen;
1614 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001615
1616 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001617 mPendingAddInfo.cellX = cell[0];
1618 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001619 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001620
1621 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1622 createShortcutIntent.setComponent(componentName);
1623 processShortcut(createShortcutIntent);
1624 }
1625
Adam Cohenfbba09b2011-07-18 21:43:05 -07001626 /**
1627 * Process a widget drop.
1628 *
1629 * @param info The PendingAppWidgetInfo of the widget being added.
1630 * @param screen The screen where it should be added
1631 * @param cell The cell it should be added to, optional
1632 * @param position The location on the screen where it was dropped, optional
1633 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001634 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001635 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001636 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001637 mPendingAddInfo.container = info.container = container;
1638 mPendingAddInfo.screen = info.screen = screen;
1639 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001640 mPendingAddInfo.minSpanX = info.minSpanX;
1641 mPendingAddInfo.minSpanY = info.minSpanY;
1642
Adam Cohenfbba09b2011-07-18 21:43:05 -07001643 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001644 mPendingAddInfo.cellX = cell[0];
1645 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001646 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001647 if (span != null) {
1648 mPendingAddInfo.spanX = span[0];
1649 mPendingAddInfo.spanY = span[1];
1650 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001651
Adam Cohened66b2b2012-01-23 17:28:51 -08001652 AppWidgetHostView hostView = info.boundWidget;
1653 int appWidgetId;
1654 if (hostView != null) {
1655 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001656 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001657 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001658 // In this case, we either need to start an activity to get permission to bind
1659 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001660 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Michael Jurka8b805b12012-04-18 14:23:14 -07001661 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001662 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001663 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001664 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001665 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1666 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1667 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
1668 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1669 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001670 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001671 }
1672
Joe Onoratodeb98af2010-02-19 14:59:39 -08001673 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001674 // Handle case where user selected "Applications"
1675 String applicationName = getResources().getString(R.string.group_applications);
1676 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001677
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001678 if (applicationName != null && applicationName.equals(shortcutName)) {
1679 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1680 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001681
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001682 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1683 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001684 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001685 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001686 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001687 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001688 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 }
1690
Winson Chung24ab2f12010-09-16 14:10:47 -07001691 void processWallpaper(Intent intent) {
1692 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1693 }
1694
Winson Chung3d503fb2011-07-13 17:25:49 -07001695 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1696 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001697 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001698 folderInfo.title = getText(R.string.folder_name);
1699
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001701 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1702 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001703 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704
1705 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001706 FolderIcon newFolder =
1707 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1708 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1709 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001710 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 }
Romain Guycbb89e42009-06-08 15:52:54 -07001712
Joe Onorato9c1289c2009-08-17 11:03:03 -04001713 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001714 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001715 }
1716
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001718 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001719 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001720 Intent chooser = Intent.createChooser(pickWallpaper,
1721 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001722 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1723 // Removed in Eclair MR1
1724// WallpaperManager wm = (WallpaperManager)
1725// getSystemService(Context.WALLPAPER_SERVICE);
1726// WallpaperInfo wi = wm.getWallpaperInfo();
1727// if (wi != null && wi.getSettingsActivity() != null) {
1728// LabeledIntent li = new LabeledIntent(getPackageName(),
1729// R.string.configure_wallpaper, 0);
1730// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1731// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1732// }
Mike Clerona0618e42009-10-22 13:55:21 -07001733 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001734 }
1735
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001736 /**
1737 * Registers various content observers. The current implementation registers
1738 * only a favorites observer to keep track of the favorites applications.
1739 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001740 private void registerContentObservers() {
1741 ContentResolver resolver = getContentResolver();
1742 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1743 true, mWidgetObserver);
1744 }
1745
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001746 @Override
1747 public boolean dispatchKeyEvent(KeyEvent event) {
1748 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1749 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001750 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001751 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001752 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001753 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001754 dumpState();
1755 return true;
1756 }
1757 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001758 }
1759 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1760 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001761 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 return true;
1763 }
1764 }
1765
1766 return super.dispatchKeyEvent(event);
1767 }
1768
Joe Onorato88ec0992009-11-19 13:16:06 -08001769 @Override
1770 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001771 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001772 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001773 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001774 Folder openFolder = mWorkspace.getOpenFolder();
1775 if (openFolder.isEditingName()) {
1776 openFolder.dismissEditingName();
1777 } else {
1778 closeFolder();
1779 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001780 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001781 mWorkspace.exitWidgetResizeMode();
1782
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001783 // Back button is a no-op here, but give at least some feedback for the button press
1784 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001785 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001786 }
1787
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001789 * Re-listen when widgets are reset.
1790 */
1791 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001792 if (mAppWidgetHost != null) {
1793 mAppWidgetHost.startListening();
1794 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001795 }
1796
1797 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001798 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1799 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001801 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001802 if (mModel != null) {
1803 mModel.unbindWorkspaceItems();
1804 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001805 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001806
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807 /**
1808 * Launches the intent referred by the clicked shortcut.
1809 *
1810 * @param v The view representing the clicked shortcut.
1811 */
1812 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001813 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1814 // view has detached (it's possible for this to happen if the view is removed mid touch).
1815 if (v.getWindowToken() == null) {
1816 return;
1817 }
1818
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001819 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001820 return;
1821 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001822
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001823 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001824 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001826 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001827 int[] pos = new int[2];
1828 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001829 intent.setSourceBounds(new Rect(pos[0], pos[1],
1830 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001831
1832 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001833
1834 if (success && v instanceof BubbleTextView) {
1835 mWaitingForResume = (BubbleTextView) v;
1836 mWaitingForResume.setStayPressed(true);
1837 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001838 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001839 if (v instanceof FolderIcon) {
1840 FolderIcon fi = (FolderIcon) v;
1841 handleFolderClick(fi);
1842 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001843 } else if (v == mAllAppsButton) {
1844 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001845 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001846 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001847 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001848 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 }
1850 }
1851
Michael Jurka0e260592010-06-30 17:07:39 -07001852 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001853 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001854 // clicking anywhere on the workspace causes the customization drawer to slide down
1855 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001856 return false;
1857 }
1858
Michael Jurkaaf442092010-06-10 17:01:57 -07001859 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001860 * Event handler for the search button
1861 *
1862 * @param v The view that was clicked.
1863 */
1864 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001865 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1866
Amith Yamasania135ba82011-08-09 17:42:01 -07001867 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001868 }
1869
1870 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001871 * Event handler for the voice button
1872 *
1873 * @param v The view that was clicked.
1874 */
1875 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001876 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001877
Michael Jurkaae65ee32012-04-30 11:45:54 -07001878 try {
1879 final SearchManager searchManager =
1880 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1881 ComponentName activityName = searchManager.getGlobalSearchActivity();
1882 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001883 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001884 if (activityName != null) {
1885 intent.setPackage(activityName.getPackageName());
1886 }
Michael Jurka86a720e2012-05-09 11:23:23 -07001887 startActivity(null, intent, "onClickVoiceButton");
Winson Chung01b0b632012-05-22 10:18:14 -07001888 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001889 } catch (ActivityNotFoundException e) {
1890 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001891 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001892 startActivitySafely(null, intent, "onClickVoiceButton");
1893 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001894 }
1895
1896 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001897 * Event handler for the "grid" button that appears on the home screen, which
1898 * enters all apps mode.
1899 *
1900 * @param v The view that was clicked.
1901 */
1902 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001903 showAllApps(true);
1904 }
1905
1906 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001907 // Provide the same haptic feedback that the system offers for virtual keys.
1908 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001909 }
1910
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001911 public void onClickAppMarketButton(View v) {
1912 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07001913 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07001914 } else {
1915 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001916 }
1917 }
1918
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001919 void startApplicationDetailsActivity(ComponentName componentName) {
1920 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001921 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1922 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001923 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07001924 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001925 }
1926
Patrick Dubroy5539af72010-09-07 15:22:01 -07001927 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1928 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1929 // System applications cannot be installed. For now, show a toast explaining that.
1930 // We may give them the option of disabling apps this way.
1931 int messageId = R.string.uninstall_system_app_text;
1932 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1933 } else {
1934 String packageName = appInfo.componentName.getPackageName();
1935 String className = appInfo.componentName.getClassName();
1936 Intent intent = new Intent(
1937 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001938 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1939 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001940 startActivity(intent);
1941 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001942 }
1943
Michael Jurka86a720e2012-05-09 11:23:23 -07001944 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001945 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07001946
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 try {
Winson Chung2672ff92012-05-04 16:22:30 -07001948 // Only launch using the new animation if the shortcut has not opted out (this is a
1949 // private contract between launcher and may be ignored in the future).
1950 boolean useLaunchAnimation = (v != null) &&
1951 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1952 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07001953 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
1954 v.getMeasuredWidth(), v.getMeasuredHeight());
1955
1956 startActivity(intent, opts.toBundle());
1957 } else {
1958 startActivity(intent);
1959 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001960 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961 } catch (SecurityException e) {
1962 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001963 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001965 "or use the exported attribute for this activity. "
1966 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001967 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001968 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001970
Michael Jurka86a720e2012-05-09 11:23:23 -07001971 boolean startActivitySafely(View v, Intent intent, Object tag) {
1972 boolean success = false;
1973 try {
1974 success = startActivity(v, intent, tag);
1975 } catch (ActivityNotFoundException e) {
1976 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1977 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
1978 }
1979 return success;
1980 }
1981
Romain Guy8e633c52010-03-04 12:51:36 -08001982 void startActivityForResultSafely(Intent intent, int requestCode) {
1983 try {
1984 startActivityForResult(intent, requestCode);
1985 } catch (ActivityNotFoundException e) {
1986 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1987 } catch (SecurityException e) {
1988 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1989 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1990 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1991 "or use the exported attribute for this activity.", e);
1992 }
1993 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994
Adam Cohena9cf38f2011-05-02 15:36:58 -07001995 private void handleFolderClick(FolderIcon folderIcon) {
1996 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001997 Folder openFolder = mWorkspace.getFolderForTag(info);
1998
1999 // If the folder info reports that the associated folder is open, then verify that
2000 // it is actually opened. There have been a few instances where this gets out of sync.
2001 if (info.opened && openFolder == null) {
2002 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2003 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2004 info.opened = false;
2005 }
2006
Adam Cohena9cf38f2011-05-02 15:36:58 -07002007 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002008 // Close any open folder
2009 closeFolder();
2010 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002011 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 } else {
2013 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 int folderScreen;
2015 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002016 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002017 // .. and close it
2018 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002019 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 // Close any folder open on the current screen
2021 closeFolder();
2022 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002023 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024 }
2025 }
2026 }
2027 }
2028
Adam Cohen2801caf2011-05-13 20:57:39 -07002029 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002030 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002031 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2032 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2033 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2034
Adam Cohenc51934b2011-07-26 21:07:43 -07002035 FolderInfo info = (FolderInfo) fi.getTag();
2036 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2037 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002038 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2039 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002040 }
2041
Adam Cohen2801caf2011-05-13 20:57:39 -07002042 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
2043 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2044 oa.start();
2045 }
2046
2047 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002048 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002049 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2050 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2051 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2052
Adam Cohenc51934b2011-07-26 21:07:43 -07002053 FolderInfo info = (FolderInfo) fi.getTag();
2054 CellLayout cl = null;
2055 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2056 cl = (CellLayout) fi.getParent().getParent();
2057 }
2058
2059 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07002060 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
2061 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002062 oa.addListener(new AnimatorListenerAdapter() {
2063 @Override
2064 public void onAnimationEnd(Animator animation) {
2065 if (layout != null) {
2066 layout.clearFolderLeaveBehind();
2067 }
2068 }
2069 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002070 oa.start();
2071 }
2072
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002073 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002074 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 * is animated relative to the specified View. If the View is null, no animation
2076 * is played.
2077 *
2078 * @param folderInfo The FolderInfo describing the folder to open.
2079 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002080 public void openFolder(FolderIcon folderIcon) {
2081 Folder folder = folderIcon.mFolder;
2082 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083
Adam Cohen2801caf2011-05-13 20:57:39 -07002084 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002085 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002086
Adam Cohen4554ee12011-08-03 16:13:21 -07002087 // Just verify that the folder hasn't already been added to the DragLayer.
2088 // There was a one-off crash where the folder had a parent already.
2089 if (folder.getParent() == null) {
2090 mDragLayer.addView(folder);
2091 mDragController.addDropTarget((DropTarget) folder);
2092 } else {
2093 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2094 folder.getParent() + ").");
2095 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002096 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07002097 }
2098
2099 public void closeFolder() {
2100 Folder folder = mWorkspace.getOpenFolder();
2101 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002102 if (folder.isEditingName()) {
2103 folder.dismissEditingName();
2104 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002105 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002106
2107 // Dismiss the folder cling
2108 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002109 }
2110 }
2111
2112 void closeFolder(Folder folder) {
2113 folder.getInfo().opened = false;
2114
2115 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2116 if (parent != null) {
2117 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2118 shrinkAndFadeInFolderIcon(fi);
2119 }
2120 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002121 }
2122
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002124 if (!isDraggingEnabled()) return false;
2125 if (isWorkspaceLocked()) return false;
2126 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002127
2128 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002129 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130 }
2131
Michael Jurka0280c3b2010-09-17 15:00:07 -07002132 resetAddInfo();
2133 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002134 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002135 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002136 return true;
2137 }
2138
Winson Chung3d503fb2011-07-13 17:25:49 -07002139 // The hotseat touch handling does not go through Workspace, and we always allow long press
2140 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002141 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002142 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2143 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002144 if (itemUnderLongClick == null) {
2145 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002146 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2147 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002148 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002149 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002150 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002151 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002152 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153 }
2154 }
2155 }
2156 return true;
2157 }
2158
Winson Chung3d503fb2011-07-13 17:25:49 -07002159 boolean isHotseatLayout(View layout) {
2160 return mHotseat != null && layout != null &&
2161 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2162 }
2163 Hotseat getHotseat() {
2164 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002165 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002166 SearchDropTargetBar getSearchBar() {
2167 return mSearchDropTargetBar;
2168 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002169
Winson Chung3d503fb2011-07-13 17:25:49 -07002170 /**
2171 * Returns the CellLayout of the specified container at the specified screen.
2172 */
2173 CellLayout getCellLayout(long container, int screen) {
2174 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2175 if (mHotseat != null) {
2176 return mHotseat.getLayout();
2177 } else {
2178 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002179 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002180 } else {
2181 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002182 }
2183 }
2184
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002185 Workspace getWorkspace() {
2186 return mWorkspace;
2187 }
2188
Daniel Sandler843e8602010-06-07 14:59:01 -04002189 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2190 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002191 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002192 }
2193
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002194 public boolean isAllAppsButtonRank(int rank) {
2195 return mHotseat.isAllAppsButtonRank(rank);
2196 }
2197
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002198 // AllAppsView.Watcher
2199 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002200 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002201 mWorkspace.setVisibility(View.GONE);
2202 }
2203 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002204
2205 /**
2206 * Helper method for the cameraZoomIn/cameraZoomOut animations
2207 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002208 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002209 * @param scaleFactor The scale factor used for the zoom
2210 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002211 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002212 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002213 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002214 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002215
Winson Chung18f41f82012-05-09 13:28:10 -07002216 void disableWallpaperIfInAllApps() {
2217 // Only disable it if we are in all apps
2218 if (mState == State.APPS_CUSTOMIZE) {
2219 if (mAppsCustomizeTabHost != null &&
2220 !mAppsCustomizeTabHost.isTransitioning()) {
2221 updateWallpaperVisibility(false);
2222 }
2223 }
2224 }
2225
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002226 void updateWallpaperVisibility(boolean visible) {
2227 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2228 int curflags = getWindow().getAttributes().flags
2229 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2230 if (wpflags != curflags) {
2231 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2232 }
2233 }
2234
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002235 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2236 if (v instanceof LauncherTransitionable) {
2237 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2238 }
2239 }
2240
Michael Jurkabed61d22012-02-14 22:51:29 -08002241 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002242 if (toWorkspace) {
2243 Log.d(TAG, "6549598 Start animation to workspace");
2244 } else {
2245 Log.d(TAG, "6549598 Start animation to all apps");
2246 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002247 if (v instanceof LauncherTransitionable) {
2248 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2249 }
Winson Chung70442722012-02-10 15:43:22 -08002250
2251 // Update the workspace transition step as well
2252 dispatchOnLauncherTransitionStep(v, 0f);
2253 }
2254
2255 private void dispatchOnLauncherTransitionStep(View v, float t) {
2256 if (v instanceof LauncherTransitionable) {
2257 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2258 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002259 }
2260
2261 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002262 if (toWorkspace) {
2263 Log.d(TAG, "6549598 End animation to workspace");
2264 } else {
2265 Log.d(TAG, "6549598 End animation to all apps");
2266 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002267 if (v instanceof LauncherTransitionable) {
2268 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2269 }
Winson Chung70442722012-02-10 15:43:22 -08002270
2271 // Update the workspace transition step as well
2272 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002273 }
2274
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002275 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002276 * Things to test when changing the following seven functions.
2277 * - Home from workspace
2278 * - from center screen
2279 * - from other screens
2280 * - Home from all apps
2281 * - from center screen
2282 * - from other screens
2283 * - Back from all apps
2284 * - from center screen
2285 * - from other screens
2286 * - Launch app from workspace and quit
2287 * - with back
2288 * - with home
2289 * - Launch app from all apps and quit
2290 * - with back
2291 * - with home
2292 * - Go to a screen that's not the default, then all
2293 * apps, and launch and app, and go back
2294 * - with back
2295 * -with home
2296 * - On workspace, long press power and go back
2297 * - with back
2298 * - with home
2299 * - On all apps, long press power and go back
2300 * - with back
2301 * - with home
2302 * - On workspace, power off
2303 * - On all apps, power off
2304 * - Launch an app and turn off the screen while in that app
2305 * - Go back with home key
2306 * - Go back with back key TODO: make this not go to workspace
2307 * - From all apps
2308 * - From workspace
2309 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2310 * - From all apps
2311 * - From the center workspace
2312 * - From another workspace
2313 */
2314
2315 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002316 * Zoom the camera out from the workspace to reveal 'toView'.
2317 * Assumes that the view to show is anchored at either the very top or very bottom
2318 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002319 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002320 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002321 if (mStateAnimation != null) {
2322 mStateAnimation.cancel();
2323 mStateAnimation = null;
2324 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002325 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002326
Winson Chungf0ea4d32011-06-06 14:27:16 -07002327 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2328 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2329 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002330 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002331 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002332 final int startDelay =
2333 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002334
Michael Jurkab3e22d92011-10-31 15:58:33 -07002335 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002336
Michael Jurkad74c9842011-07-10 12:44:21 -07002337 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002338 Animator workspaceAnim =
2339 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002340
2341 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002342 toView.setScaleX(scale);
2343 toView.setScaleY(scale);
2344 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2345 scaleAnim.
2346 scaleX(1f).scaleY(1f).
2347 setDuration(duration).
2348 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002349
Winson Chungf0ea4d32011-06-06 14:27:16 -07002350 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002351 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002352 final ObjectAnimator alphaAnim = ObjectAnimator
2353 .ofFloat(toView, "alpha", 0f, 1f)
2354 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002355 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002356 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2357 @Override
2358 public void onAnimationUpdate(ValueAnimator animation) {
2359 float t = (Float) animation.getAnimatedValue();
2360 dispatchOnLauncherTransitionStep(fromView, t);
2361 dispatchOnLauncherTransitionStep(toView, t);
2362 }
2363 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002364
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002365 // toView should appear right at the end of the workspace shrink
2366 // animation
2367 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002368 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002369 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002370
2371 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002372 boolean animationCancelled = false;
2373
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002374 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002375 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002376 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002377 // Prepare the position
2378 toView.setTranslationX(0.0f);
2379 toView.setTranslationY(0.0f);
2380 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002381 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002382 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002383 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002384 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002385 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2386 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002387
2388 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2389 // Hide the workspace scrollbar
2390 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002391 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002392 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002393 if (!animationCancelled) {
2394 updateWallpaperVisibility(false);
2395 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002396
2397 // Hide the search bar
2398 mSearchDropTargetBar.hideSearchBar(false);
Adam Cohenf4ddea32011-09-12 13:46:42 -07002399 }
2400
Adam Cohencff6af82011-09-13 14:51:53 -07002401 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002402 public void onAnimationCancel(Animator animation) {
2403 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002404 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002405 });
2406
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002407 if (workspaceAnim != null) {
2408 mStateAnimation.play(workspaceAnim);
2409 }
Michael Jurka1899a362011-11-03 13:50:45 -07002410
2411 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002412 final ViewTreeObserver observer;
2413
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002414 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2415 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002416
2417 // If any of the objects being animated haven't been measured/laid out
2418 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002419 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002420 (mWorkspace.getMeasuredWidth() == 0) ||
2421 (toView.getMeasuredWidth() == 0)) {
2422 observer = mWorkspace.getViewTreeObserver();
2423 delayAnim = true;
2424 } else {
2425 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002426 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002427
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002428 final AnimatorSet stateAnimation = mStateAnimation;
2429 final Runnable startAnimRunnable = new Runnable() {
2430 public void run() {
2431 // Check that mStateAnimation hasn't changed while
2432 // we waited for a layout/draw pass
2433 if (mStateAnimation != stateAnimation)
2434 return;
2435 setPivotsForZoom(toView, scale);
2436 dispatchOnLauncherTransitionStart(fromView, animated, false);
2437 dispatchOnLauncherTransitionStart(toView, animated, false);
2438 mWorkspace.post(new Runnable() {
2439 public void run() {
2440 // Check that mStateAnimation hasn't changed while
2441 // we waited for a layout/draw pass
2442 if (mStateAnimation != stateAnimation)
2443 return;
2444 mStateAnimation.start();
2445 }
2446 });
2447 }
2448 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002449 if (delayAnim) {
2450 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2451 public void onGlobalLayout() {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002452 mWorkspace.post(startAnimRunnable);
Michael Jurka3a9fced2012-04-13 14:44:29 -07002453 observer.removeOnGlobalLayoutListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002454 }
2455 };
2456 observer.addOnGlobalLayoutListener(delayedStart);
2457 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002458 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002459 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002460 } else {
2461 toView.setTranslationX(0.0f);
2462 toView.setTranslationY(0.0f);
2463 toView.setScaleX(1.0f);
2464 toView.setScaleY(1.0f);
2465 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002466 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002467
Michael Jurkabed61d22012-02-14 22:51:29 -08002468 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2469 // Hide the workspace scrollbar
2470 mWorkspace.hideScrollingIndicator(true);
2471 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002472
2473 // Hide the search bar
2474 mSearchDropTargetBar.hideSearchBar(false);
Michael Jurkaabded662011-03-04 12:06:57 -08002475 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002476 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002477 dispatchOnLauncherTransitionStart(fromView, animated, false);
2478 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002479 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002480 dispatchOnLauncherTransitionStart(toView, animated, false);
2481 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002482 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002483 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002484 }
2485
2486 /**
2487 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002488 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002489 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002490 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002491 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2492 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002493
Michael Jurkab3e22d92011-10-31 15:58:33 -07002494 if (mStateAnimation != null) {
2495 mStateAnimation.cancel();
2496 mStateAnimation = null;
2497 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002498 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002499
Winson Chungf0ea4d32011-06-06 14:27:16 -07002500 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002501 final int fadeOutDuration =
2502 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002503 final float scaleFactor = (float)
2504 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2505 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002506 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002507 Animator workspaceAnim = null;
2508
2509 if (toState == State.WORKSPACE) {
2510 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2511 workspaceAnim = mWorkspace.getChangeStateAnimation(
2512 Workspace.State.NORMAL, animated, stagger);
2513 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2514 workspaceAnim = mWorkspace.getChangeStateAnimation(
2515 Workspace.State.SPRING_LOADED, animated);
2516 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002517
Michael Jurkab3e22d92011-10-31 15:58:33 -07002518 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002519 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002520 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002521 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002522 final LauncherViewPropertyAnimator scaleAnim =
2523 new LauncherViewPropertyAnimator(fromView);
2524 scaleAnim.
2525 scaleX(scaleFactor).scaleY(scaleFactor).
2526 setDuration(duration).
2527 setInterpolator(new Workspace.ZoomInInterpolator());
2528
2529 final ObjectAnimator alphaAnim = ObjectAnimator
2530 .ofFloat(fromView, "alpha", 1f, 0f)
2531 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002532 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002533 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2534 @Override
2535 public void onAnimationUpdate(ValueAnimator animation) {
2536 float t = 1f - (Float) animation.getAnimatedValue();
2537 dispatchOnLauncherTransitionStep(fromView, t);
2538 dispatchOnLauncherTransitionStep(toView, t);
2539 }
2540 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002541
Michael Jurkabed61d22012-02-14 22:51:29 -08002542 mStateAnimation = new AnimatorSet();
2543
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002544 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2545 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002546
2547 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002548 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002549 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002550 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002551 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002552 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2553 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002554 if (mWorkspace != null) {
2555 mWorkspace.hideScrollingIndicator(false);
2556 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002557 if (onCompleteRunnable != null) {
2558 onCompleteRunnable.run();
2559 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002560 }
2561 });
2562
Winson Chungf0ea4d32011-06-06 14:27:16 -07002563 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002564 if (workspaceAnim != null) {
2565 mStateAnimation.play(workspaceAnim);
2566 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002567 dispatchOnLauncherTransitionStart(fromView, animated, true);
2568 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002569 final Animator stateAnimation = mStateAnimation;
2570 mWorkspace.post(new Runnable() {
2571 public void run() {
2572 if (stateAnimation != mStateAnimation)
2573 return;
2574 mStateAnimation.start();
2575 }
2576 });
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002577 } else {
2578 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002579 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002580 dispatchOnLauncherTransitionStart(fromView, animated, true);
2581 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002582 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002583 dispatchOnLauncherTransitionStart(toView, animated, true);
2584 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002585 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002586 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002587 }
2588
Michael Jurkae326f182011-11-21 14:05:46 -08002589 @Override
2590 public void onTrimMemory(int level) {
2591 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002592 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002593 mAppsCustomizeTabHost.onTrimMemory();
2594 }
2595 }
2596
Winson Chung18f41f82012-05-09 13:28:10 -07002597 @Override
2598 public void onWindowFocusChanged(boolean hasFocus) {
2599 if (!hasFocus) {
2600 // When another window occludes launcher (like the notification shade, or recents),
2601 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2602 updateWallpaperVisibility(true);
2603 } else {
2604 // When launcher has focus again, disable the wallpaper if we are in AllApps
2605 disableWallpaperIfInAllApps();
2606 }
2607 }
2608
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002609 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002610 showWorkspace(animated, null);
2611 }
2612
2613 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002614 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002615 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002616 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002617 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002618
Winson Chungc7d2b602012-05-16 17:02:20 -07002619 // Show the search bar (only animate if we were showing the drop target bar in spring
2620 // loaded mode)
2621 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2622
Michael Jurkab737ee62011-11-15 15:57:22 -08002623 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002624 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002625
2626 // Set focus to the AppsCustomize button
2627 if (mAllAppsButton != null) {
2628 mAllAppsButton.requestFocus();
2629 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002630 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002631
Michael Jurkab737ee62011-11-15 15:57:22 -08002632 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002633
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002634 // Change the state *after* we've called all the transition code
2635 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002636
Winson Chung5fb63472011-02-02 17:03:37 -08002637 // Resume the auto-advance of widgets
2638 mUserPresent = true;
2639 updateRunning();
2640
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002641 // send an accessibility event to announce the context change
2642 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002643 }
2644
Michael Jurkab3e22d92011-10-31 15:58:33 -07002645 void showAllApps(boolean animated) {
2646 if (mState != State.WORKSPACE) return;
2647
2648 showAppsCustomizeHelper(animated, false);
2649 mAppsCustomizeTabHost.requestFocus();
2650
Michael Jurkab3e22d92011-10-31 15:58:33 -07002651 // Change the state *after* we've called all the transition code
2652 mState = State.APPS_CUSTOMIZE;
2653
2654 // Pause the auto-advance of widgets until we are out of AllApps
2655 mUserPresent = false;
2656 updateRunning();
2657 closeFolder();
2658
2659 // Send an accessibility event to announce the context change
2660 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2661 }
2662
Adam Cohen7777d962011-08-18 18:58:38 -07002663 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002664 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002665 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002666 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002667 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002668 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002669 }
Adam Cohen7777d962011-08-18 18:58:38 -07002670
Adam Cohened66b2b2012-01-23 17:28:51 -08002671 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2672 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002673 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2674
Winson Chunge7a03942011-08-05 15:05:12 -07002675 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002676 @Override
2677 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002678 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002679 // Before we show workspace, hide all apps again because
2680 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2681 // clean up our state transition functions
2682 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002683 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002684 } else {
2685 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002686 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002687 }
2688 }, (extendedDelay ?
2689 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2690 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2691 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002692
Michael Jurkad3ef3062010-11-23 16:23:58 -08002693 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002694 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002695 final boolean animated = true;
2696 final boolean springLoaded = true;
2697 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002698 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002699 }
2700 // Otherwise, we are not in spring loaded mode, so don't do anything.
2701 }
2702
Michael Jurkab737ee62011-11-15 15:57:22 -08002703 void hideDockDivider() {
2704 if (mQsbDivider != null && mDockDivider != null) {
2705 mQsbDivider.setVisibility(View.INVISIBLE);
2706 mDockDivider.setVisibility(View.INVISIBLE);
2707 }
2708 }
2709
2710 void showDockDivider(boolean animated) {
2711 if (mQsbDivider != null && mDockDivider != null) {
2712 mQsbDivider.setVisibility(View.VISIBLE);
2713 mDockDivider.setVisibility(View.VISIBLE);
2714 if (mDividerAnimator != null) {
2715 mDividerAnimator.cancel();
2716 mQsbDivider.setAlpha(1f);
2717 mDockDivider.setAlpha(1f);
2718 mDividerAnimator = null;
2719 }
2720 if (animated) {
2721 mDividerAnimator = new AnimatorSet();
2722 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2723 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2724 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2725 mDividerAnimator.start();
2726 }
2727 }
2728 }
2729
Michael Jurkab3e22d92011-10-31 15:58:33 -07002730 void lockAllApps() {
2731 // TODO
2732 }
2733
2734 void unlockAllApps() {
2735 // TODO
2736 }
2737
Adam Cohenfc53cd22011-07-20 15:45:11 -07002738 public boolean isAllAppsCustomizeOpen() {
2739 return mState == State.APPS_CUSTOMIZE;
2740 }
2741
Winson Chungf0ea4d32011-06-06 14:27:16 -07002742 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002743 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002744 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002745 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002746 if (!LauncherApplication.isScreenLarge()) {
2747 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002748 if (mHotseat.getAlpha() != 1f) {
2749 int duration = mSearchDropTargetBar.getTransitionInDuration();
2750 mHotseat.animate().alpha(1f).setDuration(duration);
2751 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002752 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002753 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002754 }
2755 }
2756 }
2757
2758 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002759 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002760 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002761 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002762 if (!LauncherApplication.isScreenLarge()) {
2763 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002764 if (mHotseat.getAlpha() != 0f) {
2765 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2766 mHotseat.animate().alpha(0f).setDuration(duration);
2767 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002768 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002769 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002770 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002771 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002772 }
2773
Patrick Dubroy5f445422011-02-18 14:35:21 -08002774 /**
2775 * Add an item from all apps or customize onto the given workspace screen.
2776 * If layout is null, add to the current screen.
2777 */
2778 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002779 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07002780 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07002781 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002782 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002783
Winson Chungdff8ebb2011-09-08 17:25:31 -07002784 /** Maps the current orientation to an index for referencing orientation correct global icons */
2785 private int getCurrentOrientationIndexForGlobalIcons() {
2786 // default - 0, landscape - 1
2787 switch (getResources().getConfiguration().orientation) {
2788 case Configuration.ORIENTATION_LANDSCAPE:
2789 return 1;
2790 default:
2791 return 0;
2792 }
2793 }
2794
Michael Jurkaae65ee32012-04-30 11:45:54 -07002795 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002796 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002797 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002798 // Look for the toolbar icon specified in the activity meta-data
2799 Bundle metaData = packageManager.getActivityInfo(
2800 activityName, PackageManager.GET_META_DATA).metaData;
2801 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002802 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002803 if (iconResId != 0) {
2804 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002805 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002806 }
2807 }
2808 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002809 // This can happen if the activity defines an invalid drawable
2810 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2811 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002812 } catch (Resources.NotFoundException nfe) {
2813 // This can happen if the activity defines an invalid drawable
2814 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2815 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002816 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002817 return null;
2818 }
2819
2820 // if successful in getting icon, return it; otherwise, set button to use default drawable
2821 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002822 int buttonId, ComponentName activityName, int fallbackDrawableId,
2823 String toolbarResourceName) {
2824 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002825 Resources r = getResources();
2826 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2827 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002828
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002829 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002830 // If we were unable to find the icon via the meta-data, use a generic one
2831 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002832 toolbarIcon = r.getDrawable(fallbackDrawableId);
2833 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002834 if (button != null) {
2835 button.setCompoundDrawables(toolbarIcon, null, null, null);
2836 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002837 return null;
2838 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002839 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002840 if (button != null) {
2841 button.setCompoundDrawables(toolbarIcon, null, null, null);
2842 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002843 return toolbarIcon.getConstantState();
2844 }
2845 }
2846
2847 // if successful in getting icon, return it; otherwise, set button to use default drawable
2848 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002849 int buttonId, ComponentName activityName, int fallbackDrawableId,
2850 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002851 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002852 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002853
Michael Jurka19e0fc52011-07-22 18:00:21 -07002854 if (button != null) {
2855 // If we were unable to find the icon via the meta-data, use a
2856 // generic one
2857 if (toolbarIcon == null) {
2858 button.setImageResource(fallbackDrawableId);
2859 } else {
2860 button.setImageDrawable(toolbarIcon);
2861 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002862 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002863
2864 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2865
Michael Jurka0423dcf2010-10-05 14:56:18 -07002866 }
2867
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002868 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2869 TextView button = (TextView) findViewById(buttonId);
2870 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2871 }
2872
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002873 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002874 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002875 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002876 }
2877
Winson Chungbb185bd2011-11-21 12:31:42 -08002878 private void invalidatePressedFocusedStates(View container, View button) {
2879 if (container instanceof HolographicLinearLayout) {
2880 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2881 layout.invalidatePressedFocusedStates();
2882 } else if (button instanceof HolographicImageView) {
2883 HolographicImageView view = (HolographicImageView) button;
2884 view.invalidatePressedFocusedStates();
2885 }
2886 }
2887
Winson Chungc51db6a2011-10-05 11:44:49 -07002888 private boolean updateGlobalSearchIcon() {
2889 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002890 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2891 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002892 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002893 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002894 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002895
Winson Chung1cad91e2011-05-25 17:41:01 -07002896 final SearchManager searchManager =
2897 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2898 ComponentName activityName = searchManager.getGlobalSearchActivity();
2899 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002900 int coi = getCurrentOrientationIndexForGlobalIcons();
2901 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002902 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2903 TOOLBAR_SEARCH_ICON_METADATA_NAME);
2904 if (sGlobalSearchIcon[coi] == null) {
2905 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2906 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2907 TOOLBAR_ICON_METADATA_NAME);
2908 }
2909
Winson Chung649723c2011-07-06 20:41:23 -07002910 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002911 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2912 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002913 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002914 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002915 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002916 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002917 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002918 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2919 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2920 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002921 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07002922 if (voiceButtonProxy != null) {
2923 voiceButtonProxy.setVisibility(View.GONE);
2924 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002925 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002926 }
2927 }
2928
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002929 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002930 final View searchButtonContainer = findViewById(R.id.search_button_container);
2931 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002932 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002933 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002934 }
2935
Winson Chungc51db6a2011-10-05 11:44:49 -07002936 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002937 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002938 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002939 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002940 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002941
Winson Chungc51db6a2011-10-05 11:44:49 -07002942 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07002943 final SearchManager searchManager =
2944 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2945 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2946
2947 ComponentName activityName = null;
2948 if (globalSearchActivity != null) {
2949 // Check if the global search activity handles voice search
2950 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2951 intent.setPackage(globalSearchActivity.getPackageName());
2952 activityName = intent.resolveActivity(getPackageManager());
2953 }
2954
2955 if (activityName == null) {
2956 // Fallback: check if an activity other than the global search activity
2957 // resolves this
2958 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2959 activityName = intent.resolveActivity(getPackageManager());
2960 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002961 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002962 int coi = getCurrentOrientationIndexForGlobalIcons();
2963 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002964 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
2965 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
2966 if (sVoiceSearchIcon[coi] == null) {
2967 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2968 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
2969 TOOLBAR_ICON_METADATA_NAME);
2970 }
Winson Chung649723c2011-07-06 20:41:23 -07002971 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002972 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002973 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07002974 if (voiceButtonProxy != null) {
2975 voiceButtonProxy.setVisibility(View.VISIBLE);
2976 }
Winson Chungbb185bd2011-11-21 12:31:42 -08002977 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002978 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002979 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002980 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002981 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002982 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07002983 if (voiceButtonProxy != null) {
2984 voiceButtonProxy.setVisibility(View.GONE);
2985 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002986 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002987 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002988 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002989
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002990 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002991 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2992 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002993 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002994 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002995 }
2996
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002997 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002998 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002999 */
3000 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003001 final View marketButton = findViewById(R.id.market_button);
3002 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3003 // Find the app market activity by resolving an intent.
3004 // (If multiple app markets are installed, it will return the ResolverActivity.)
3005 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003006 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003007 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003008 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003009 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003010 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3011 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003012 marketButton.setVisibility(View.VISIBLE);
3013 } else {
3014 // We should hide and disable the view so that we don't try and restore the visibility
3015 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3016 marketButton.setVisibility(View.GONE);
3017 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003018 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003019 }
3020
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003021 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003022 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003023 }
3024
Michael Jurkad7c28052012-04-27 15:43:36 -07003025 @Override
3026 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
3027 boolean result = super.dispatchPopulateAccessibilityEvent(event);
3028 final List<CharSequence> text = event.getText();
3029 text.clear();
3030 text.add(getString(R.string.home));
3031 return result;
3032 }
3033
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003034 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003035 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003036 */
3037 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3038 @Override
3039 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003040 closeSystemDialogs();
3041 }
3042 }
3043
3044 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003045 * Receives notifications whenever the appwidgets are reset.
3046 */
3047 private class AppWidgetResetObserver extends ContentObserver {
3048 public AppWidgetResetObserver() {
3049 super(new Handler());
3050 }
3051
3052 @Override
3053 public void onChange(boolean selfChange) {
3054 onAppWidgetReset();
3055 }
3056 }
3057
3058 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003059 * If the activity is currently paused, signal that we need to re-run the loader
3060 * in onResume.
3061 *
3062 * This needs to be called from incoming places where resources might have been loaded
3063 * while we are paused. That is becaues the Configuration might be wrong
3064 * when we're not running, and if it comes back to what it was when we
3065 * were paused, we are not restarted.
3066 *
3067 * Implementation of the method from LauncherModel.Callbacks.
3068 *
3069 * @return true if we are currently paused. The caller might be able to
3070 * skip some work in that case since we will come back again.
3071 */
3072 public boolean setLoadOnResume() {
3073 if (mPaused) {
3074 Log.i(TAG, "setLoadOnResume");
3075 mOnResumeNeedsLoad = true;
3076 return true;
3077 } else {
3078 return false;
3079 }
3080 }
3081
3082 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003083 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003084 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003085 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003086 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003087 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003088 } else {
3089 return SCREEN_COUNT / 2;
3090 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003091 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003092
Joe Onorato9c1289c2009-08-17 11:03:03 -04003093 /**
3094 * Refreshes the shortcuts shown on the workspace.
3095 *
3096 * Implementation of the method from LauncherModel.Callbacks.
3097 */
3098 public void startBinding() {
3099 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003100
Winson Chungf0c6ae02012-03-21 16:10:31 -07003101 mNewShortcutAnimatePage = -1;
3102 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003103 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003104 int count = workspace.getChildCount();
3105 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003106 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003107 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3108 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003109 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003110 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003111 if (mHotseat != null) {
3112 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003113 }
3114 }
3115
3116 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003117 * Bind the items start-end from the list.
3118 *
3119 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003120 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003121 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003122 setLoadOnResume();
3123
Winson Chungf0c6ae02012-03-21 16:10:31 -07003124 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3125 Set<String> newApps = new HashSet<String>();
3126 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3127
3128 Workspace workspace = mWorkspace;
3129 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003130 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003131
3132 // Short circuit if we are loading dock items for a configuration which has no dock
3133 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3134 mHotseat == null) {
3135 continue;
3136 }
3137
Joe Onorato9c1289c2009-08-17 11:03:03 -04003138 switch (item.itemType) {
3139 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3140 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003141 ShortcutInfo info = (ShortcutInfo) item;
3142 String uri = info.intent.toUri(0).toString();
3143 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003144 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3145 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003146 boolean animateIconUp = false;
3147 synchronized (newApps) {
3148 if (newApps.contains(uri)) {
3149 animateIconUp = newApps.remove(uri);
3150 }
3151 }
3152 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003153 // Prepare the view to be animated up
3154 shortcut.setAlpha(0f);
3155 shortcut.setScaleX(0f);
3156 shortcut.setScaleY(0f);
3157 mNewShortcutAnimatePage = item.screen;
3158 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3159 mNewShortcutAnimateViews.add(shortcut);
3160 }
3161 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003162 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003163 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003164 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003165 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003166 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003167 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3168 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003169 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003170 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003171 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003172
Joe Onorato9c1289c2009-08-17 11:03:03 -04003173 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003174 }
3175
Joe Onorato9c1289c2009-08-17 11:03:03 -04003176 /**
3177 * Implementation of the method from LauncherModel.Callbacks.
3178 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003179 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003180 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003181 sFolders.clear();
3182 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003183 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003184
3185 /**
3186 * Add the views for a widget to the workspace.
3187 *
3188 * Implementation of the method from LauncherModel.Callbacks.
3189 */
3190 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003191 setLoadOnResume();
3192
Daniel Sandler843e8602010-06-07 14:59:01 -04003193 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3194 if (DEBUG_WIDGETS) {
3195 Log.d(TAG, "bindAppWidget: " + item);
3196 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003197 final Workspace workspace = mWorkspace;
3198
3199 final int appWidgetId = item.appWidgetId;
3200 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003201 if (DEBUG_WIDGETS) {
3202 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3203 }
3204
Joe Onorato9c1289c2009-08-17 11:03:03 -04003205 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3206
Joe Onorato9c1289c2009-08-17 11:03:03 -04003207 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003208 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003209
Winson Chung3d503fb2011-07-13 17:25:49 -07003210 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003211 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003212 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3213
Joe Onorato9c1289c2009-08-17 11:03:03 -04003214 workspace.requestLayout();
3215
Daniel Sandler843e8602010-06-07 14:59:01 -04003216 if (DEBUG_WIDGETS) {
3217 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3218 + (SystemClock.uptimeMillis()-start) + "ms");
3219 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003220 }
3221
3222 /**
3223 * Callback saying that there aren't any more items to bind.
3224 *
3225 * Implementation of the method from LauncherModel.Callbacks.
3226 */
3227 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003228 setLoadOnResume();
3229
Joe Onorato9c1289c2009-08-17 11:03:03 -04003230 if (mSavedState != null) {
3231 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003232 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003233 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003234 mSavedState = null;
3235 }
3236
3237 if (mSavedInstanceState != null) {
3238 super.onRestoreInstanceState(mSavedInstanceState);
3239 mSavedInstanceState = null;
3240 }
3241
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003242 // If we received the result of any pending adds while the loader was running (e.g. the
3243 // widget configuration forced an orientation change), process them now.
3244 for (int i = 0; i < sPendingAddList.size(); i++) {
3245 completeAdd(sPendingAddList.get(i));
3246 }
3247 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003248
Winson Chungc51db6a2011-10-05 11:44:49 -07003249 // Update the market app icon as necessary (the other icons will be managed in response to
3250 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003251 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003252
Winson Chungf0c6ae02012-03-21 16:10:31 -07003253 // Animate up any icons as necessary
3254 if (mVisible || mWorkspaceLoading) {
3255 Runnable newAppsRunnable = new Runnable() {
3256 @Override
3257 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003258 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003259 }
3260 };
Winson Chunga2413752012-04-03 14:22:34 -07003261
3262 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3263 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3264 if (canRunNewAppsAnimation()) {
3265 // If the user has not interacted recently, then either snap to the new page to show
3266 // the new-apps animation or just run them if they are to appear on the current page
3267 if (willSnapPage) {
3268 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3269 } else {
3270 runNewAppsAnimation(false);
3271 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003272 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003273 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003274 // are on another page (or just normally if they are added to the current page)
3275 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003276 }
3277 }
3278
3279 mWorkspaceLoading = false;
3280 }
3281
Winson Chunga2413752012-04-03 14:22:34 -07003282 private boolean canRunNewAppsAnimation() {
3283 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3284 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3285 }
3286
Winson Chungf0c6ae02012-03-21 16:10:31 -07003287 /**
3288 * Runs a new animation that scales up icons that were added while Launcher was in the
3289 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003290 *
3291 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003292 */
Winson Chunga2413752012-04-03 14:22:34 -07003293 private void runNewAppsAnimation(boolean immediate) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003294 AnimatorSet anim = new AnimatorSet();
3295 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003296
3297 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003298 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3299 @Override
3300 public int compare(View a, View b) {
3301 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3302 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3303 int cellCountX = LauncherModel.getCellCountX();
3304 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3305 }
3306 });
Winson Chunga2413752012-04-03 14:22:34 -07003307
3308 // Animate each of the views in place (or show them immediately if requested)
3309 if (immediate) {
3310 for (View v : mNewShortcutAnimateViews) {
3311 v.setAlpha(1f);
3312 v.setScaleX(1f);
3313 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003314 }
Winson Chunga2413752012-04-03 14:22:34 -07003315 } else {
3316 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3317 View v = mNewShortcutAnimateViews.get(i);
3318 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v,
3319 PropertyValuesHolder.ofFloat("alpha", 1f),
3320 PropertyValuesHolder.ofFloat("scaleX", 1f),
3321 PropertyValuesHolder.ofFloat("scaleY", 1f));
3322 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3323 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3324 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3325 bounceAnims.add(bounceAnim);
3326 }
3327 anim.playTogether(bounceAnims);
3328 anim.addListener(new AnimatorListenerAdapter() {
3329 @Override
3330 public void onAnimationEnd(Animator animation) {
3331 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3332 }
3333 });
3334 anim.start();
3335 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003336
3337 // Clean up
3338 mNewShortcutAnimatePage = -1;
3339 mNewShortcutAnimateViews.clear();
3340 new Thread("clearNewAppsThread") {
3341 public void run() {
3342 mSharedPrefs.edit()
3343 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3344 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3345 .commit();
3346 }
3347 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003348 }
3349
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003350 @Override
3351 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003352 boolean searchVisible = updateGlobalSearchIcon();
3353 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3354 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003355 }
3356
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003357 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003358 * Add the icons for all apps.
3359 *
3360 * Implementation of the method from LauncherModel.Callbacks.
3361 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003362 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3363 // Remove the progress bar entirely; we could also make it GONE
3364 // but better to remove it since we know it's not going to be used
3365 View progressBar = mAppsCustomizeTabHost.
3366 findViewById(R.id.apps_customize_progress_bar);
3367 if (progressBar != null) {
3368 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003369 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003370 // We just post the call to setApps so the user sees the progress bar
3371 // disappear-- otherwise, it just looks like the progress bar froze
3372 // which doesn't look great
3373 mAppsCustomizeTabHost.post(new Runnable() {
3374 public void run() {
3375 if (mAppsCustomizeContent != null) {
3376 mAppsCustomizeContent.setApps(apps);
3377 }
3378 }
3379 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003380 }
3381
3382 /**
3383 * A package was installed.
3384 *
3385 * Implementation of the method from LauncherModel.Callbacks.
3386 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003387 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003388 setLoadOnResume();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003389
Winson Chung785d2eb2011-04-14 16:08:02 -07003390 if (mAppsCustomizeContent != null) {
3391 mAppsCustomizeContent.addApps(apps);
3392 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003393 }
3394
3395 /**
3396 * A package was updated.
3397 *
3398 * Implementation of the method from LauncherModel.Callbacks.
3399 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003400 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003401 setLoadOnResume();
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003402 if (mWorkspace != null) {
3403 mWorkspace.updateShortcuts(apps);
3404 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003405
Winson Chung785d2eb2011-04-14 16:08:02 -07003406 if (mAppsCustomizeContent != null) {
3407 mAppsCustomizeContent.updateApps(apps);
3408 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003409 }
3410
3411 /**
3412 * A package was uninstalled.
3413 *
3414 * Implementation of the method from LauncherModel.Callbacks.
3415 */
Joe Onorato36115782010-06-17 13:28:48 -04003416 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato36115782010-06-17 13:28:48 -04003417 if (permanent) {
3418 mWorkspace.removeItems(apps);
3419 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003420
Winson Chung785d2eb2011-04-14 16:08:02 -07003421 if (mAppsCustomizeContent != null) {
3422 mAppsCustomizeContent.removeApps(apps);
3423 }
Winson Chunga1820962011-10-03 16:31:06 -07003424
3425 // Notify the drag controller
3426 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003427 }
Joe Onoratobe386092009-11-17 17:32:16 -08003428
3429 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003430 * A number of packages were updated.
3431 */
3432 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003433 if (mAppsCustomizeContent != null) {
3434 mAppsCustomizeContent.onPackagesUpdated();
3435 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003436 }
3437
Winson Chung400438b2011-01-16 17:53:48 -08003438 private int mapConfigurationOriActivityInfoOri(int configOri) {
3439 final Display d = getWindowManager().getDefaultDisplay();
3440 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3441 switch (d.getRotation()) {
3442 case Surface.ROTATION_0:
3443 case Surface.ROTATION_180:
3444 // We are currently in the same basic orientation as the natural orientation
3445 naturalOri = configOri;
3446 break;
3447 case Surface.ROTATION_90:
3448 case Surface.ROTATION_270:
3449 // We are currently in the other basic orientation to the natural orientation
3450 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3451 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3452 break;
3453 }
3454
3455 int[] oriMap = {
3456 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3457 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3458 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3459 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3460 };
3461 // Since the map starts at portrait, we need to offset if this device's natural orientation
3462 // is landscape.
3463 int indexOffset = 0;
3464 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3465 indexOffset = 1;
3466 }
3467 return oriMap[(d.getRotation() + indexOffset) % 4];
3468 }
Adam Cohen446e9402011-09-15 18:21:21 -07003469
Winson Chung4b919f82012-05-01 10:44:08 -07003470 public boolean isRotationEnabled() {
3471 boolean forceEnableRotation = "true".equalsIgnoreCase(SystemProperties.get(
3472 FORCE_ENABLE_ROTATION_PROPERTY, "false"));
3473 boolean enableRotation = forceEnableRotation ||
3474 getResources().getBoolean(R.bool.allow_rotation);
3475 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003476 }
Winson Chung4b919f82012-05-01 10:44:08 -07003477 public void lockScreenOrientation() {
3478 if (isRotationEnabled()) {
3479 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3480 .getConfiguration().orientation));
3481 }
3482 }
3483 public void unlockScreenOrientation(boolean immediate) {
3484 if (isRotationEnabled()) {
3485 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003486 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003487 } else {
3488 mHandler.postDelayed(new Runnable() {
3489 public void run() {
3490 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3491 }
3492 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003493 }
Winson Chung4b919f82012-05-01 10:44:08 -07003494 }
Winson Chung400438b2011-01-16 17:53:48 -08003495 }
3496
Winson Chung82f55532011-08-09 14:14:23 -07003497 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003498 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003499 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003500 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003501
Winson Chung7d7541e2011-09-16 20:14:36 -07003502 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003503 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003504 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3505 Cling cling = (Cling) findViewById(clingId);
3506 if (cling != null) {
3507 cling.init(this, positionData);
3508 cling.setVisibility(View.VISIBLE);
3509 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Svetoslav Ganov55d225d2012-05-22 15:19:14 -07003510 cling.requestAccessibilityFocus();
Winson Chung7d7541e2011-09-16 20:14:36 -07003511 if (animate) {
3512 cling.buildLayer();
3513 cling.setAlpha(0f);
3514 cling.animate()
3515 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003516 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003517 .setDuration(SHOW_CLING_DURATION)
3518 .setStartDelay(delay)
3519 .start();
3520 } else {
3521 cling.setAlpha(1f);
3522 }
3523 }
3524 return cling;
3525 }
3526 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003527 if (cling != null) {
3528 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003529 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003530 anim.addListener(new AnimatorListenerAdapter() {
3531 public void onAnimationEnd(Animator animation) {
3532 cling.setVisibility(View.GONE);
3533 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003534 // We should update the shared preferences on a background thread
3535 new Thread("dismissClingThread") {
3536 public void run() {
3537 SharedPreferences.Editor editor = mSharedPrefs.edit();
3538 editor.putBoolean(flag, true);
3539 editor.commit();
3540 }
3541 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003542 };
3543 });
3544 anim.start();
3545 }
3546 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003547 private void removeCling(int id) {
3548 final View cling = findViewById(id);
3549 if (cling != null) {
3550 final ViewGroup parent = (ViewGroup) cling.getParent();
3551 parent.post(new Runnable() {
3552 @Override
3553 public void run() {
3554 parent.removeView(cling);
3555 }
3556 });
3557 }
3558 }
Michael Jurka974c3862012-05-22 22:00:31 -07003559
3560 private boolean skipCustomClingIfNoAccounts() {
3561 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3562 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3563 if (customCling) {
3564 AccountManager am = AccountManager.get(this);
3565 Account[] accounts = am.getAccountsByType("com.google");
3566 return accounts.length == 0;
3567 }
3568 return false;
3569 }
3570
Winson Chung7d7541e2011-09-16 20:14:36 -07003571 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003572 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003573 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003574 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3575 !skipCustomClingIfNoAccounts() ) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003576 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003577 } else {
3578 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003579 }
3580 }
3581 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003582 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003583 if (isClingsEnabled() &&
3584 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003585 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003586 } else {
3587 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003588 }
3589 }
3590 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003591 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003592 if (isClingsEnabled() &&
3593 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3594 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003595 } else {
3596 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003597 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003598 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003599 }
3600 public boolean isFolderClingVisible() {
3601 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003602 if (cling != null) {
3603 return cling.getVisibility() == View.VISIBLE;
3604 }
3605 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003606 }
Winson Chung82f55532011-08-09 14:14:23 -07003607 public void dismissWorkspaceCling(View v) {
3608 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003609 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003610 }
3611 public void dismissAllAppsCling(View v) {
3612 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003613 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3614 }
3615 public void dismissFolderCling(View v) {
3616 Cling cling = (Cling) findViewById(R.id.folder_cling);
3617 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003618 }
3619
Winson Chung80baf5a2010-08-09 16:03:15 -07003620 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003621 * Prints out out state for debugging.
3622 */
3623 public void dumpState() {
3624 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003625 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003626 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3627 Log.d(TAG, "mRestoring=" + mRestoring);
3628 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3629 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003630 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003631 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003632
Winson Chung785d2eb2011-04-14 16:08:02 -07003633 if (mAppsCustomizeContent != null) {
3634 mAppsCustomizeContent.dumpState();
3635 }
Joe Onoratobe386092009-11-17 17:32:16 -08003636 Log.d(TAG, "END launcher2 dump state");
3637 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003638
3639 @Override
3640 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3641 super.dump(prefix, fd, writer, args);
3642 writer.println(" ");
3643 writer.println("Debug logs: ");
3644 for (int i = 0; i < sDumpLogs.size(); i++) {
3645 writer.println(" " + sDumpLogs.get(i));
3646 }
3647 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003648}
Michael Jurka2763be32011-02-24 11:19:57 -08003649
Michael Jurkaabded662011-03-04 12:06:57 -08003650interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003651 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003652 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08003653 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08003654 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08003655 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003656}