blob: 62e05e8d8e910560e0d71da8ae317493d775ff95 [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
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
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;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700205 private static final int SHOW_CLING_DURATION = 250;
206 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800209 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
Winson Chunga2413752012-04-03 14:22:34 -0700211 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700212 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
213 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700214 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700215
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800216 private final BroadcastReceiver mCloseSystemDialogsReceiver
217 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800218 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
219
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 private LayoutInflater mInflater;
221
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700223 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800224 private DragLayer mDragLayer;
225 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700226 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700227
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700228 private AppWidgetManager mAppWidgetManager;
229 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700230
Michael Jurkac9d95c52011-08-29 14:03:34 -0700231 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700232 private AppWidgetProviderInfo mPendingAddWidgetInfo;
233
Michael Jurka0280c3b2010-09-17 15:00:07 -0700234 private int[] mTmpAddItemCellCoordinates = new int[2];
235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 private FolderInfo mFolderInfo;
237
Winson Chung3d503fb2011-07-13 17:25:49 -0700238 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700239 private View mOverviewPanel;
240
Michael Jurka838a4ca2011-02-07 13:33:06 -0800241 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700242
Winson Chungc51db6a2011-10-05 11:44:49 -0700243 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700244 private AppsCustomizeTabHost mAppsCustomizeTabHost;
245 private AppsCustomizePagedView mAppsCustomizeContent;
246 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100247 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700250 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
251 // scroll issues (because the workspace may not have been measured yet) and extra work.
252 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
253 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254
255 private SpannableStringBuilder mDefaultKeySsb = null;
256
Joe Onorato9c1289c2009-08-17 11:03:03 -0400257 private boolean mWorkspaceLoading = true;
258
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800259 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260 private boolean mRestoring;
261 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700262 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
Michael Jurka1e2f4652013-07-08 18:03:46 -0700264 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700265 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
266
Winson Chung4a2afa32012-07-19 14:53:05 -0700267 // Keep track of whether the user has left launcher
268 private static boolean sPausedFromUserAction = false;
269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 private Bundle mSavedInstanceState;
271
Joe Onorato9c1289c2009-08-17 11:03:03 -0400272 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800273 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800274 private boolean mUserPresent = true;
275 private boolean mVisible = false;
276 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700277 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700278 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static LocaleConfiguration sLocaleConfiguration = null;
281
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700282 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700283
Adam Cohen61f560d2013-09-30 15:58:20 -0700284 private View.OnTouchListener mHapticFeedbackTouchListener;
285
Adam Cohended9f8d2010-11-03 13:25:16 -0700286 // Related to the auto-advancing of widgets
287 private final int ADVANCE_MSG = 1;
288 private final int mAdvanceInterval = 20000;
289 private final int mAdvanceStagger = 250;
290 private long mAutoAdvanceSentTime;
291 private long mAutoAdvanceTimeLeft = -1;
292 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
293 new HashMap<View, AppWidgetProviderInfo>();
294
Winson Chung400438b2011-01-16 17:53:48 -0800295 // Determines how long to wait after a rotation before restoring the screen orientation to
296 // match the sensor state.
297 private final int mRestoreScreenOrientationDelay = 500;
298
Michael Jurka4ef207b2010-11-29 17:05:45 -0800299 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700300 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
301 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
302 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800303
Winson Chungd64a6662013-09-30 11:06:59 -0700304 private Intent mAppMarketIntent = null;
305 private static final boolean DISABLE_MARKET_BUTTON = true;
306
Craig Mautner360310b2012-10-26 15:13:08 -0700307 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700308
Adam Cohen1462de32012-07-24 22:34:36 -0700309 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
310
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700311 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700312 static Date sDateStamp = new Date();
313 static DateFormat sDateFormat =
314 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
315 static long sRunStart = System.currentTimeMillis();
316 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700317
Winson Chung46353de2012-02-16 14:05:10 -0800318 // We only want to get the SharedPreferences once since it does an FS stat each time we get
319 // it from the context.
320 private SharedPreferences mSharedPrefs;
321
Adam Cohene25af792013-06-06 23:08:25 -0700322 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
323
Winson Chungf0c6ae02012-03-21 16:10:31 -0700324 // Holds the page that we need to animate to, and the icon views that we need to animate up
325 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700326 private ImageView mFolderIconImageView;
327 private Bitmap mFolderIconBitmap;
328 private Canvas mFolderIconCanvas;
329 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700330
Michael Jurkaddd62e92011-02-16 17:49:14 -0800331 private BubbleTextView mWaitingForResume;
332
Michael Jurka22143132012-10-04 17:42:38 +0200333 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
334 = new HideFromAccessibilityHelper();
335
Michael Jurkac1f5d262011-09-30 19:32:27 -0700336 private Runnable mBuildLayersRunnable = new Runnable() {
337 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700338 if (mWorkspace != null) {
339 mWorkspace.buildPageHardwareLayers();
340 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700341 }
342 };
343
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800344 private static ArrayList<PendingAddArguments> sPendingAddList
345 = new ArrayList<PendingAddArguments>();
346
Michael Jurka0a457bf2012-11-19 14:05:05 -0800347 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
348
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800349 private static class PendingAddArguments {
350 int requestCode;
351 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700352 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700353 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800354 int cellX;
355 int cellY;
356 }
357
Daniel Sandlerff02d492013-08-05 02:12:05 -0400358 private Stats mStats;
359
Michael Jurka0a457bf2012-11-19 14:05:05 -0800360 private static boolean isPropertyEnabled(String propertyName) {
361 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700362 }
363
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 @Override
365 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700366 if (DEBUG_STRICT_MODE) {
367 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
368 .detectDiskReads()
369 .detectDiskWrites()
370 .detectNetwork() // or .detectAll() for all detectable problems
371 .penaltyLog()
372 .build());
373 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
374 .detectLeakedSqlLiteObjects()
375 .detectLeakedClosableObjects()
376 .penaltyLog()
377 .penaltyDeath()
378 .build());
379 }
380
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400382
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400383 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400384 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700385
386 // Determine the dynamic grid properties
387 Point smallestSize = new Point();
388 Point largestSize = new Point();
389 Point realSize = new Point();
390 Display display = getWindowManager().getDefaultDisplay();
391 display.getCurrentSizeRange(smallestSize, largestSize);
392 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700393 DisplayMetrics dm = new DisplayMetrics();
394 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700395 // Lazy-initialize the dynamic grid
396 DeviceProfile grid = app.initDynamicGrid(this,
397 Math.min(smallestSize.x, smallestSize.y),
398 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700399 realSize.x, realSize.y,
400 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700401
402 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400403 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700404 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800405 mModel = app.setLauncher(this);
406 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400407 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700409
Daniel Sandlerff02d492013-08-05 02:12:05 -0400410 mStats = new Stats(this);
411
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700412 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700413 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
414 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700415
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700416 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
417 // this also ensures that any synchronous binding below doesn't re-trigger another
418 // LauncherModel load.
419 mPaused = false;
420
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200422 android.os.Debug.startMethodTracing(
423 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800424 }
425
426 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 setContentView(R.layout.launcher);
428 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100429 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800430
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800431 registerContentObservers();
432
Joe Onorato7c312c12009-08-13 21:36:53 -0700433 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700434
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435 mSavedState = savedInstanceState;
436 restoreState(mSavedState);
437
Winson Chunga12a2502010-12-20 14:41:35 -0800438 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700439 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200440 mAppsCustomizeContent.onPackagesUpdated(
441 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700442 }
Winson Chunga12a2502010-12-20 14:41:35 -0800443
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444 if (PROFILE_STARTUP) {
445 android.os.Debug.stopMethodTracing();
446 }
447
448 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700449 if (sPausedFromUserAction) {
450 // If the user leaves launcher, then we should just load items asynchronously when
451 // they return.
452 mModel.startLoader(true, -1);
453 } else {
454 // We only load the page synchronously if the user rotates (or triggers a
455 // configuration change) while launcher is in the foreground
456 mModel.startLoader(true, mWorkspace.getCurrentPage());
457 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 }
459
460 // For handling default keys
461 mDefaultKeySsb = new SpannableStringBuilder();
462 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800463
464 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
465 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800466
Adam Cohenf9426d52012-06-04 17:26:21 -0700467 updateGlobalIcons();
468
469 // On large interfaces, we want the screen to auto-rotate based on the current orientation
470 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700471
472 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700473 }
474
Winson Chung4a2afa32012-07-19 14:53:05 -0700475 protected void onUserLeaveHint() {
476 super.onUserLeaveHint();
477 sPausedFromUserAction = true;
478 }
479
Winson Chung98ca0f72013-07-29 12:58:51 -0700480 /** To be overriden by subclasses to hint to Launcher that we have custom content */
481 protected boolean hasCustomContentToLeft() {
482 return false;
483 }
484
Dave Hawkeya8881582013-09-17 15:55:33 -0600485 /**
486 * To be overridden by subclasses to create the custom content and call
487 * {@link #addToCustomContentPage}. This will only be invoked if
488 * {@link #hasCustomContentToLeft()} is {@code true}.
489 */
490 protected void addCustomContentToLeft() {
491 }
492
493 /**
494 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
495 * ensure the custom content page is added or removed if necessary.
496 */
497 protected void invalidateHasCustomContentToLeft() {
498 if (mWorkspace.getScreenOrder().isEmpty()) {
499 // Not bound yet, wait for bindScreens to be called.
500 return;
501 }
502
503 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
504 // Create the custom content page and call the subclass to populate it.
505 mWorkspace.createCustomContentPage();
506 addCustomContentToLeft();
507 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
508 mWorkspace.removeCustomContentPage();
509 }
510 }
511
Adam Cohenf9426d52012-06-04 17:26:21 -0700512 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700513 boolean searchVisible = false;
514 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800515 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700516 int coi = getCurrentOrientationIndexForGlobalIcons();
517 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
518 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700519 if (!DISABLE_MARKET_BUTTON) {
520 updateAppMarketIcon();
521 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700522 searchVisible = updateGlobalSearchIcon();
523 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700524 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700525 if (sGlobalSearchIcon[coi] != null) {
526 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700527 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700528 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700529 if (sVoiceSearchIcon[coi] != null) {
530 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700531 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700532 }
Winson Chungd64a6662013-09-30 11:06:59 -0700533 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700534 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800535 }
Winson Chungadf0c182012-08-23 14:59:07 -0700536 if (mSearchDropTargetBar != null) {
537 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
538 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800539 }
Romain Guycbb89e42009-06-08 15:52:54 -0700540
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800541 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700542 if (sLocaleConfiguration == null) {
543 new AsyncTask<Void, Void, LocaleConfiguration>() {
544 @Override
545 protected LocaleConfiguration doInBackground(Void... unused) {
546 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
547 readConfiguration(Launcher.this, localeConfiguration);
548 return localeConfiguration;
549 }
550
551 @Override
552 protected void onPostExecute(LocaleConfiguration result) {
553 sLocaleConfiguration = result;
554 checkForLocaleChange(); // recursive, but now with a locale configuration
555 }
556 }.execute();
557 return;
558 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700559
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800560 final Configuration configuration = getResources().getConfiguration();
561
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700562 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 final String locale = configuration.locale.toString();
564
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700565 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566 final int mcc = configuration.mcc;
567
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700568 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800569 final int mnc = configuration.mnc;
570
Romain Guy84f296c2009-11-04 15:00:44 -0800571 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800572
Romain Guy84f296c2009-11-04 15:00:44 -0800573 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574 sLocaleConfiguration.locale = locale;
575 sLocaleConfiguration.mcc = mcc;
576 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700577
Joe Onorato0589f0f2010-02-08 13:44:00 -0800578 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700579
580 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
581 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700582 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700583 public void run() {
584 writeConfiguration(Launcher.this, localeConfiguration);
585 }
586 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700587 }
588 }
589
590 private static class LocaleConfiguration {
591 public String locale;
592 public int mcc = -1;
593 public int mnc = -1;
594 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700595
Romain Guy98d01652009-06-30 16:21:04 -0700596 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
597 DataInputStream in = null;
598 try {
599 in = new DataInputStream(context.openFileInput(PREFERENCES));
600 configuration.locale = in.readUTF();
601 configuration.mcc = in.readInt();
602 configuration.mnc = in.readInt();
603 } catch (FileNotFoundException e) {
604 // Ignore
605 } catch (IOException e) {
606 // Ignore
607 } finally {
608 if (in != null) {
609 try {
610 in.close();
611 } catch (IOException e) {
612 // Ignore
613 }
614 }
615 }
616 }
617
618 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
619 DataOutputStream out = null;
620 try {
621 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
622 out.writeUTF(configuration.locale);
623 out.writeInt(configuration.mcc);
624 out.writeInt(configuration.mnc);
625 out.flush();
626 } catch (FileNotFoundException e) {
627 // Ignore
628 } catch (IOException e) {
629 //noinspection ResultOfMethodCallIgnored
630 context.getFileStreamPath(PREFERENCES).delete();
631 } finally {
632 if (out != null) {
633 try {
634 out.close();
635 } catch (IOException e) {
636 // Ignore
637 }
638 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800639 }
640 }
641
Anton Hanssona2f665f2013-09-26 12:18:32 +0100642 public Stats getStats() {
643 return mStats;
644 }
645
Bjorn Bringertc459e522013-06-07 19:36:01 +0100646 public LayoutInflater getInflater() {
647 return mInflater;
648 }
649
Adam Cohen716b51e2011-06-30 12:09:54 -0700650 public DragLayer getDragLayer() {
651 return mDragLayer;
652 }
653
Winson Chung36a62fe2012-05-06 18:04:42 -0700654 boolean isDraggingEnabled() {
655 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
656 // that is subsequently removed from the workspace in startBinding().
657 return !mModel.isLoadingWorkspace();
658 }
659
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800660 static int getScreen() {
661 synchronized (sLock) {
662 return sScreen;
663 }
664 }
665
666 static void setScreen(int screen) {
667 synchronized (sLock) {
668 sScreen = screen;
669 }
670 }
671
Winson Chung557d6ed2011-07-08 15:34:52 -0700672 /**
673 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
674 * a configuration step, this allows the proper animations to run after other transitions.
675 */
676 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700677 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800678 switch (args.requestCode) {
679 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700680 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700681 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800682 break;
683 case REQUEST_PICK_SHORTCUT:
684 processShortcut(args.intent);
685 break;
686 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700687 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700688 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700689 result = true;
690 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800691 case REQUEST_CREATE_APPWIDGET:
692 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700693 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700694 result = true;
695 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800696 }
Michael Jurka27614d22012-04-02 06:40:22 -0700697 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
698 // if you turned the screen off and then back while in All Apps, Launcher would not
699 // return to the workspace. Clearing mAddInfo.container here fixes this issue
700 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700701 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800702 }
703
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800704 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 protected void onActivityResult(
706 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700707 // Reset the startActivity waiting flag
708 mWaitingForResult = false;
709
Michael Jurka8b805b12012-04-18 14:23:14 -0700710 if (requestCode == REQUEST_BIND_APPWIDGET) {
711 int appWidgetId = data != null ?
712 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
713 if (resultCode == RESULT_CANCELED) {
714 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
715 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700716 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700717 }
718 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200719 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
720 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
721 mWorkspace.exitOverviewMode(false);
722 }
723 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700724 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200725
Winson Chung557d6ed2011-07-08 15:34:52 -0700726 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800727 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
728 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700729
Adam Cohened66b2b2012-01-23 17:28:51 -0800730 // We have special handling for widgets
731 if (isWidgetDrop) {
732 int appWidgetId = data != null ?
733 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700734 if (appWidgetId < 0) {
735 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
736 "widget configuration activity.");
737 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
738 } else {
739 completeTwoStageWidgetDrop(resultCode, appWidgetId);
740 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800741 return;
742 }
743
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800744 // The pattern used here is that a user PICKs a specific application,
745 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700746
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800747 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
748 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700749 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800750 final PendingAddArguments args = new PendingAddArguments();
751 args.requestCode = requestCode;
752 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700753 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700754 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700755 args.cellX = mPendingAddInfo.cellX;
756 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800757 if (isWorkspaceLocked()) {
758 sPendingAddList.add(args);
759 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700760 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800761 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800763 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700764 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800765 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
766 null);
767 }
768
769 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700770 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700771 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800772 Runnable onCompleteRunnable = null;
773 int animationType = 0;
774
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700775 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 if (resultCode == RESULT_OK) {
777 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
778 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700779 mPendingAddWidgetInfo);
780 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800781 onCompleteRunnable = new Runnable() {
782 @Override
783 public void run() {
784 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700785 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800786 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
787 null);
788 }
789 };
790 } else if (resultCode == RESULT_CANCELED) {
791 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
792 onCompleteRunnable = new Runnable() {
793 @Override
794 public void run() {
795 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
796 null);
797 }
798 };
799 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700800 if (mDragLayer.getAnimatedView() != null) {
801 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
802 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
803 animationType, boundWidget, true);
804 } else {
805 // The animated view may be null in the case of a rotation during widget configuration
806 onCompleteRunnable.run();
807 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800808 }
809
810 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700811 protected void onStop() {
812 super.onStop();
813 FirstFrameAnimatorHelper.setIsVisible(false);
814 }
815
816 @Override
817 protected void onStart() {
818 super.onStart();
819 FirstFrameAnimatorHelper.setIsVisible(true);
820 }
821
822 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800823 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200824 long startTime = 0;
825 if (DEBUG_RESUME_TIME) {
826 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400827 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200828 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800829 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700830
Winson Chung4a2afa32012-07-19 14:53:05 -0700831 // Restore the previous launcher state
832 if (mOnResumeState == State.WORKSPACE) {
833 showWorkspace(false);
834 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700835 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700836 }
837 mOnResumeState = State.NONE;
838
Craig Mautner360310b2012-10-26 15:13:08 -0700839 // Background was set to gradient in onPause(), restore to black if in all apps.
840 setWorkspaceBackground(mState == State.WORKSPACE);
841
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800842 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700843 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700844 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400845 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700846 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400847 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700848 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700850 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200851 // We might have postponed some bind calls until onResume (see waitUntilResume) --
852 // execute them here
853 long startTimeCallbacks = 0;
854 if (DEBUG_RESUME_TIME) {
855 startTimeCallbacks = System.currentTimeMillis();
856 }
857
858 if (mAppsCustomizeContent != null) {
859 mAppsCustomizeContent.setBulkBind(true);
860 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700861 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
862 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200863 }
864 if (mAppsCustomizeContent != null) {
865 mAppsCustomizeContent.setBulkBind(false);
866 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700867 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200868 if (DEBUG_RESUME_TIME) {
869 Log.d(TAG, "Time spent processing callbacks in onResume: " +
870 (System.currentTimeMillis() - startTimeCallbacks));
871 }
Michael Jurka447bf842013-05-15 14:52:15 +0200872 }
Michael Jurka54554252013-08-01 12:52:23 +0200873 if (mOnResumeCallbacks.size() > 0) {
874 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
875 mOnResumeCallbacks.get(i).run();
876 }
877 mOnResumeCallbacks.clear();
878 }
Winson Chunge4e50662012-01-23 14:45:13 -0800879
880 // Reset the pressed state of icons that were locked in the press state while activities
881 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800882 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800883 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800884 mWaitingForResume.setStayPressed(false);
885 }
Winson Chunge4e50662012-01-23 14:45:13 -0800886 if (mAppsCustomizeContent != null) {
887 // Resets the previous all apps icon press state
888 mAppsCustomizeContent.resetDrawableState();
889 }
Winson Chung780fe592013-09-26 14:48:44 -0700890 // Reset AllApps to its initial state
891 if (mAppsCustomizeTabHost != null) {
892 mAppsCustomizeTabHost.reset();
893 }
Adam Cohen06dff352012-06-01 17:17:08 -0700894 // It is possible that widgets can receive updates while launcher is not in the foreground.
895 // Consequently, the widgets will be inflated in the orientation of the foreground activity
896 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
897 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700898 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700899
Winson Chung780fe592013-09-26 14:48:44 -0700900 // Process any items that were added while Launcher was away.
901 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
902
Adam Cohenf9426d52012-06-04 17:26:21 -0700903 // Again, as with the above scenario, it's possible that one or more of the global icons
904 // were updated in the wrong orientation.
905 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200906 if (DEBUG_RESUME_TIME) {
907 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
908 }
Adam Cohen06dff352012-06-01 17:17:08 -0700909 }
910
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800911 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700912 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700913 // Ensure that items added to Launcher are queued until Launcher returns
914 InstallShortcutReceiver.enableInstallQueue();
915
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700916 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700917 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800918 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700919 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700920 }
Romain Guycbb89e42009-06-08 15:52:54 -0700921
Adam Cohen66a01fd2013-06-11 12:48:00 -0700922 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -0700923 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600924 addCustomContentToLeft();
925 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700926 }
927
Adam Cohenbffe7452013-07-22 18:21:45 -0700928 QSBScroller mQsbScroller = new QSBScroller() {
929 int scrollY = 0;
930
931 @Override
932 public void setScrollY(int scroll) {
933 scrollY = scroll;
934
935 if (mWorkspace.isOnOrMovingToCustomContent()) {
936 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100937 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700938 }
939 }
940 };
941
942 public void resetQSBScroll() {
943 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100944 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700945 }
946
947 public interface CustomContentCallbacks {
948 // Custom content is completely shown
949 public void onShow();
950
951 // Custom content is completely hidden
952 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700953
954 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
955 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700956 }
957
Adam Cohen30bacb22013-08-29 14:25:25 -0700958 protected void startSettings() {
959 }
960
Adam Cohenbffe7452013-07-22 18:21:45 -0700961 public interface QSBScroller {
962 public void setScrollY(int scrollY);
963 }
964
Adam Cohen66a01fd2013-06-11 12:48:00 -0700965 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700966 public QSBScroller addToCustomContentPage(View customContent) {
967 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700968 }
969
Winson Chung98ca0f72013-07-29 12:58:51 -0700970 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700971 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700972 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700973 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700974 }
975
Adam Cohenedb40762013-07-18 16:45:45 -0700976 // The custom content needs to offset its content to account for the QSB
977 public int getTopOffsetForCustomContent() {
978 return mWorkspace.getPaddingTop();
979 }
980
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700981 @Override
982 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400983 // Flag the loader to stop early before switching
984 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700985 if (mAppsCustomizeContent != null) {
986 mAppsCustomizeContent.surrender();
987 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800988 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700989 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700990
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800991 // We can't hide the IME if it was forced open. So don't bother
992 /*
993 @Override
994 public void onWindowFocusChanged(boolean hasFocus) {
995 super.onWindowFocusChanged(hasFocus);
996
997 if (hasFocus) {
998 final InputMethodManager inputManager = (InputMethodManager)
999 getSystemService(Context.INPUT_METHOD_SERVICE);
1000 WindowManager.LayoutParams lp = getWindow().getAttributes();
1001 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
1002 android.os.Handler()) {
1003 protected void onReceiveResult(int resultCode, Bundle resultData) {
1004 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1005 }
1006 });
1007 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1008 }
1009 }
1010 */
1011
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001012 private boolean acceptFilter() {
1013 final InputMethodManager inputManager = (InputMethodManager)
1014 getSystemService(Context.INPUT_METHOD_SERVICE);
1015 return !inputManager.isFullscreenMode();
1016 }
1017
1018 @Override
1019 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001020 final int uniChar = event.getUnicodeChar();
1021 final boolean handled = super.onKeyDown(keyCode, event);
1022 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1023 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001024 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1025 keyCode, event);
1026 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001027 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001028 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001029 // showSearchDialog()
1030 // If there are multiple keystrokes before the search dialog takes focus,
1031 // onSearchRequested() will be called for every keystroke,
1032 // but it is idempotent, so it's fine.
1033 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001034 }
1035 }
1036
Joe Onorato8a9625e2010-01-28 15:55:35 -08001037 // Eat the long press event so the keyboard doesn't come up.
1038 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1039 return true;
1040 }
1041
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001042 return handled;
1043 }
1044
Karl Rosaen138a0412009-04-23 19:00:21 -07001045 private String getTypedText() {
1046 return mDefaultKeySsb.toString();
1047 }
1048
1049 private void clearTypedText() {
1050 mDefaultKeySsb.clear();
1051 mDefaultKeySsb.clearSpans();
1052 Selection.setSelection(mDefaultKeySsb, 0);
1053 }
1054
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001056 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1057 * State
1058 */
1059 private static State intToState(int stateOrdinal) {
1060 State state = State.WORKSPACE;
1061 final State[] stateValues = State.values();
1062 for (int i = 0; i < stateValues.length; i++) {
1063 if (stateValues[i].ordinal() == stateOrdinal) {
1064 state = stateValues[i];
1065 break;
1066 }
1067 }
1068 return state;
1069 }
1070
1071 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001072 * Restores the previous state, if it exists.
1073 *
1074 * @param savedState The previous state.
1075 */
1076 private void restoreState(Bundle savedState) {
1077 if (savedState == null) {
1078 return;
1079 }
1080
Michael Jurka883f55b2010-10-21 15:47:14 -07001081 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001082 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001083 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001084 }
1085
Winson Chungf0c6ae02012-03-21 16:10:31 -07001086 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001087 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001088 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001089 }
1090
Winson Chung3d503fb2011-07-13 17:25:49 -07001091 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001092 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001093
Winson Chung3d503fb2011-07-13 17:25:49 -07001094 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1095 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001096 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001097 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1098 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001099 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1100 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1101 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001102 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001103 mRestoring = true;
1104 }
1105
1106 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1107 if (renameFolder) {
1108 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001109 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001110 mRestoring = true;
1111 }
Winson Chunga12a2502010-12-20 14:41:35 -08001112
Winson Chung785d2eb2011-04-14 16:08:02 -07001113 // Restore the AppsCustomize tab
1114 if (mAppsCustomizeTabHost != null) {
1115 String curTab = savedState.getString("apps_customize_currentTab");
1116 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001117 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001118 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001119 mAppsCustomizeContent.loadAssociatedPages(
1120 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001121 }
1122
Winson Chung5afbf7b2011-07-25 11:53:08 -07001123 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1124 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001125 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001126 }
1127
1128 /**
1129 * Finds all the views we need and configure them properly.
1130 */
1131 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001132 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001133
Craig Mautner360310b2012-10-26 15:13:08 -07001134 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001135 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1136 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001137
John Spurlock77e1f472013-09-11 10:09:51 -04001138 mLauncherView.setSystemUiVisibility(
1139 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001140 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001141
Winson Chung4c98d922011-05-31 16:50:48 -07001142 // Setup the drag layer
1143 mDragLayer.setup(this, dragController);
1144
Winson Chung3d503fb2011-07-13 17:25:49 -07001145 // Setup the hotseat
1146 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1147 if (mHotseat != null) {
1148 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001149 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001150 }
1151
Adam Cohenf358a4b2013-07-23 16:47:31 -07001152 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001153 View widgetButton = findViewById(R.id.widget_button);
1154 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001155 @Override
1156 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001157 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001158 }
1159 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001160 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1161
1162 View wallpaperButton = findViewById(R.id.wallpaper_button);
1163 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001164 @Override
1165 public void onClick(View arg0) {
1166 startWallpaper();
1167 }
1168 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001169 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1170
1171 View settingsButton = findViewById(R.id.settings_button);
1172 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001173 @Override
1174 public void onClick(View arg0) {
1175 startSettings();
1176 }
1177 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001178 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001179 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001180
Winson Chung4c98d922011-05-31 16:50:48 -07001181 // Setup the workspace
1182 mWorkspace.setHapticFeedbackEnabled(false);
1183 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001184 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001185 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001186
Winson Chungf0ea4d32011-06-06 14:27:16 -07001187 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001188 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001189
Winson Chungf0ea4d32011-06-06 14:27:16 -07001190 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001191 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001192 mAppsCustomizeContent = (AppsCustomizePagedView)
1193 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1194 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001195
Winson Chung3d503fb2011-07-13 17:25:49 -07001196 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001197 dragController.setDragScoller(mWorkspace);
1198 dragController.setScrollView(mDragLayer);
1199 dragController.setMoveTarget(mWorkspace);
1200 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001201 if (mSearchDropTargetBar != null) {
1202 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001203 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001204
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001205 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001206 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001207 mWeightWatcher = new WeightWatcher(this);
1208 mWeightWatcher.setAlpha(0.5f);
1209 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001210 new FrameLayout.LayoutParams(
1211 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001212 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001213 Gravity.BOTTOM)
1214 );
Adam Cohen39a06042013-07-19 14:30:12 -07001215
1216 boolean show = shouldShowWeightWatcher();
1217 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001218 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219 }
1220
1221 /**
1222 * Creates a view representing a shortcut.
1223 *
1224 * @param info The data structure describing the shortcut.
1225 *
1226 * @return A View inflated from R.layout.application.
1227 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001228 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001230 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001231 }
1232
1233 /**
1234 * Creates a view representing a shortcut inflated from the specified resource.
1235 *
1236 * @param layoutResId The id of the XML layout used to create the shortcut.
1237 * @param parent The group the shortcut belongs to.
1238 * @param info The data structure describing the shortcut.
1239 *
1240 * @return A View inflated from layoutResId.
1241 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001242 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001243 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1244 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001245 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001246 return favorite;
1247 }
1248
1249 /**
1250 * Add an application shortcut to the workspace.
1251 *
1252 * @param data The intent describing the application.
1253 * @param cellInfo The position on screen where to create the shortcut.
1254 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001255 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001256 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001257 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001258
Adam Cohenfbba09b2011-07-18 21:43:05 -07001259 // First we check if we already know the exact location where we want to add this item.
1260 if (cellX >= 0 && cellY >= 0) {
1261 cellXY[0] = cellX;
1262 cellXY[1] = cellY;
1263 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001264 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001265 return;
1266 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001268 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001269
Romain Guy73b979d2009-06-09 12:57:21 -07001270 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001271 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001273 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001274 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001275 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001276 } else {
1277 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001278 }
1279 }
Romain Guycbb89e42009-06-08 15:52:54 -07001280
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001281 /**
1282 * Add a shortcut to the workspace.
1283 *
1284 * @param data The intent describing the shortcut.
1285 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001287 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001288 int cellY) {
1289 int[] cellXY = mTmpAddItemCellCoordinates;
1290 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001291 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001292
Michael Jurkad3ef3062010-11-23 16:23:58 -08001293 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001294
Adam Cohen558baaf2011-08-15 15:22:57 -07001295 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001296 if (info == null) {
1297 return;
1298 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001299 final View view = createShortcut(info);
1300
Adam Cohenfbba09b2011-07-18 21:43:05 -07001301 // First we check if we already know the exact location where we want to add this item.
1302 if (cellX >= 0 && cellY >= 0) {
1303 cellXY[0] = cellX;
1304 cellXY[1] = cellY;
1305 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001306
1307 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001308 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001309 true, null,null)) {
1310 return;
1311 }
1312 DragObject dragObject = new DragObject();
1313 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001314 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1315 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001316 return;
1317 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001318 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001319 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001320 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001321 foundCellSpan = (result != null);
1322 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001323 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001324 }
1325
1326 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001327 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001328 return;
1329 }
1330
Adam Cohendcd297f2013-06-18 13:13:40 -07001331 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332
1333 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001334 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001335 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001336 }
1337 }
1338
Adam Cohen2f093b62012-04-30 18:59:53 -07001339 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1340 int minHeight) {
1341 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001342 // We want to account for the extra amount of padding that we are adding to the widget
1343 // to ensure that it gets the full amount of space that it has requested
1344 int requiredWidth = minWidth + padding.left + padding.right;
1345 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001346 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001347 }
1348
Adam Cohen2f093b62012-04-30 18:59:53 -07001349 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1350 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001351 }
1352
Adam Cohen2f093b62012-04-30 18:59:53 -07001353 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1354 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001355 }
1356
Adam Cohen2f093b62012-04-30 18:59:53 -07001357 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1358 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001359 }
1360
Adam Cohen2f093b62012-04-30 18:59:53 -07001361 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1362 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001363 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001364 }
1365
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001367 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001368 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001369 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001370 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001372 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001373 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1374 if (appWidgetInfo == null) {
1375 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1376 }
Romain Guycbb89e42009-06-08 15:52:54 -07001377
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001378 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001379 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001380
Adam Cohen2f093b62012-04-30 18:59:53 -07001381 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1382 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001383
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001384 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001385 // We have saved the position to which the widget was dragged-- this really only matters
1386 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001387 int[] cellXY = mTmpAddItemCellCoordinates;
1388 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001389 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001390 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001391 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1392 cellXY[0] = mPendingAddInfo.cellX;
1393 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001394 spanXY[0] = mPendingAddInfo.spanX;
1395 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001396 foundCellSpan = true;
1397 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001398 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001399 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001400 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1401 spanXY[1], cellXY, finalSpan);
1402 spanXY[0] = finalSpan[0];
1403 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001404 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001405 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001406 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001407 }
1408
Michael Jurka0280c3b2010-09-17 15:00:07 -07001409 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001410 if (appWidgetId != -1) {
1411 // Deleting an app widget ID is a void call but writes to disk before returning
1412 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001413 new Thread("deleteAppWidgetId") {
1414 public void run() {
1415 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1416 }
1417 }.start();
1418 }
Winson Chung93eef082012-03-23 15:59:27 -07001419 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001420 return;
1421 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001422
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001423 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001424 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1425 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001426 launcherInfo.spanX = spanXY[0];
1427 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001428 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1429 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001430
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001432 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001433
1434 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001435 if (hostView == null) {
1436 // Perform actual inflation because we're live
1437 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1438 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1439 } else {
1440 // The AppWidgetHostView has already been inflated and instantiated
1441 launcherInfo.hostView = hostView;
1442 }
Romain Guycbb89e42009-06-08 15:52:54 -07001443
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001445 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001446 launcherInfo.notifyWidgetSizeChanged(this);
1447
Adam Cohendcd297f2013-06-18 13:13:40 -07001448 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001449 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001450
1451 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001453 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001454 }
Romain Guycbb89e42009-06-08 15:52:54 -07001455
Adam Cohended9f8d2010-11-03 13:25:16 -07001456 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1457 @Override
1458 public void onReceive(Context context, Intent intent) {
1459 final String action = intent.getAction();
1460 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1461 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001462 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001463 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001464
Winson Chungc100e8e2011-08-09 16:02:43 -07001465 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001466 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001467 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001468 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001469 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001470 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1471 mUserPresent = true;
1472 updateRunning();
1473 }
1474 }
1475 };
1476
1477 @Override
1478 public void onAttachedToWindow() {
1479 super.onAttachedToWindow();
1480
1481 // Listen for broadcasts related to user-presence
1482 final IntentFilter filter = new IntentFilter();
1483 filter.addAction(Intent.ACTION_SCREEN_OFF);
1484 filter.addAction(Intent.ACTION_USER_PRESENT);
1485 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001486 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001487 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001488 mVisible = true;
1489 }
1490
1491 @Override
1492 public void onDetachedFromWindow() {
1493 super.onDetachedFromWindow();
1494 mVisible = false;
1495
Adam Cohend113e0c2010-11-11 10:48:05 -08001496 if (mAttached) {
1497 unregisterReceiver(mReceiver);
1498 mAttached = false;
1499 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001500 updateRunning();
1501 }
1502
1503 public void onWindowVisibilityChanged(int visibility) {
1504 mVisible = visibility == View.VISIBLE;
1505 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001506 // The following code used to be in onResume, but it turns out onResume is called when
1507 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1508 // is a more appropriate event to handle
1509 if (mVisible) {
1510 mAppsCustomizeTabHost.onWindowVisible();
1511 if (!mWorkspaceLoading) {
1512 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001513 // We want to let Launcher draw itself at least once before we force it to build
1514 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001515 // apps is nice and speedy.
1516 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001517 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001518 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001519 if (mStarted) return;
1520 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001521 // We delay the layer building a bit in order to give
1522 // other message processing a time to run. In particular
1523 // this avoids a delay in hiding the IME if it was
1524 // currently shown, because doing that may involve
1525 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001526 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001527 final ViewTreeObserver.OnDrawListener listener = this;
1528 mWorkspace.post(new Runnable() {
1529 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001530 if (mWorkspace != null &&
1531 mWorkspace.getViewTreeObserver() != null) {
1532 mWorkspace.getViewTreeObserver().
1533 removeOnDrawListener(listener);
1534 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001535 }
1536 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001537 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001538 }
1539 });
1540 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001541 // When Launcher comes back to foreground, a different Activity might be responsible for
1542 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001543 if (!DISABLE_MARKET_BUTTON) {
1544 updateAppMarketIcon();
1545 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001546 clearTypedText();
1547 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001548 }
1549
1550 private void sendAdvanceMessage(long delay) {
1551 mHandler.removeMessages(ADVANCE_MSG);
1552 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1553 mHandler.sendMessageDelayed(msg, delay);
1554 mAutoAdvanceSentTime = System.currentTimeMillis();
1555 }
1556
1557 private void updateRunning() {
1558 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1559 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1560 mAutoAdvanceRunning = autoAdvanceRunning;
1561 if (autoAdvanceRunning) {
1562 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1563 sendAdvanceMessage(delay);
1564 } else {
1565 if (!mWidgetsToAdvance.isEmpty()) {
1566 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1567 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1568 }
1569 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001570 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001571 }
1572 }
1573 }
1574
1575 private final Handler mHandler = new Handler() {
1576 @Override
1577 public void handleMessage(Message msg) {
1578 if (msg.what == ADVANCE_MSG) {
1579 int i = 0;
1580 for (View key: mWidgetsToAdvance.keySet()) {
1581 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1582 final int delay = mAdvanceStagger * i;
1583 if (v instanceof Advanceable) {
1584 postDelayed(new Runnable() {
1585 public void run() {
1586 ((Advanceable) v).advance();
1587 }
1588 }, delay);
1589 }
1590 i++;
1591 }
1592 sendAdvanceMessage(mAdvanceInterval);
1593 }
1594 }
1595 };
1596
1597 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001598 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001599 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1600 if (v instanceof Advanceable) {
1601 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001602 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001603 updateRunning();
1604 }
1605 }
1606
1607 void removeWidgetToAutoAdvance(View hostView) {
1608 if (mWidgetsToAdvance.containsKey(hostView)) {
1609 mWidgetsToAdvance.remove(hostView);
1610 updateRunning();
1611 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001612 }
1613
Joe Onorato9c1289c2009-08-17 11:03:03 -04001614 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001615 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001616 launcherInfo.hostView = null;
1617 }
1618
Winson Chung93eef082012-03-23 15:59:27 -07001619 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1620 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1621 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001622 }
1623
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001624 public LauncherAppWidgetHost getAppWidgetHost() {
1625 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001626 }
Romain Guycbb89e42009-06-08 15:52:54 -07001627
Winson Chunga9abd0e2010-10-27 17:18:37 -07001628 public LauncherModel getModel() {
1629 return mModel;
1630 }
1631
Bjorn Bringertc459e522013-06-07 19:36:01 +01001632 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001633 getWindow().closeAllPanels();
1634
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001635 // Whatever we were doing is hereby canceled.
1636 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001637 }
1638
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001639 @Override
1640 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001641 long startTime = 0;
1642 if (DEBUG_RESUME_TIME) {
1643 startTime = System.currentTimeMillis();
1644 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001645 super.onNewIntent(intent);
1646
1647 // Close the menu
1648 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001649 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001650 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001651
Jamie Genniscb222e82012-10-23 15:44:26 -07001652 final boolean alreadyOnHome =
1653 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001654 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001655
Jamie Genniscb222e82012-10-23 15:44:26 -07001656 Runnable processIntent = new Runnable() {
1657 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001658 if (mWorkspace == null) {
1659 // Can be cases where mWorkspace is null, this prevents a NPE
1660 return;
1661 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001662 Folder openFolder = mWorkspace.getOpenFolder();
1663 // In all these cases, only animate if we're already on home
1664 mWorkspace.exitWidgetResizeMode();
1665 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1666 openFolder == null) {
1667 mWorkspace.moveToDefaultScreen(true);
1668 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001669
Jamie Genniscb222e82012-10-23 15:44:26 -07001670 closeFolder();
1671 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001672
Jamie Genniscb222e82012-10-23 15:44:26 -07001673 // If we are already on home, then just animate back to the workspace,
1674 // otherwise, just wait until onResume to set the state back to Workspace
1675 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001676 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001677 } else {
1678 mOnResumeState = State.WORKSPACE;
1679 }
1680
1681 final View v = getWindow().peekDecorView();
1682 if (v != null && v.getWindowToken() != null) {
1683 InputMethodManager imm = (InputMethodManager)getSystemService(
1684 INPUT_METHOD_SERVICE);
1685 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1686 }
1687
Winson Chung7819a562013-09-19 15:55:45 -07001688 // Reset the apps customize page
1689 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001690 mAppsCustomizeTabHost.reset();
1691 }
1692 }
1693 };
1694
1695 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1696 // Delay processing of the intent to allow the status bar animation to finish
1697 // first in order to avoid janky animations.
1698 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001699 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001700 // Process the intent immediately.
1701 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001702 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001703
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704 }
Michael Jurka447bf842013-05-15 14:52:15 +02001705 if (DEBUG_RESUME_TIME) {
1706 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1707 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001708 }
1709
Adam Cohen040a5d22013-09-16 17:09:33 -07001710 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1711 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001712 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001713 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001714 }
1715 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001716 protected void showWorkspaceAndExitOverviewMode() {
1717 showWorkspaceAndExitOverviewMode(true);
1718 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001719
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001720 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001721 public void onRestoreInstanceState(Bundle state) {
1722 super.onRestoreInstanceState(state);
1723 for (int page: mSynchronouslyBoundPages) {
1724 mWorkspace.restoreInstanceStateForChild(page);
1725 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 }
1727
1728 @Override
1729 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001730 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001731 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732
Michael Jurka883f55b2010-10-21 15:47:14 -07001733 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001734 // We close any open folder since it will not be re-opened, and we need to make sure
1735 // this state is reflected.
1736 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737
Adam Cohendcd297f2013-06-18 13:13:40 -07001738 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001739 mWaitingForResult) {
1740 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001741 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001742 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1743 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001744 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1745 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1746 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747 }
1748
1749 if (mFolderInfo != null && mWaitingForResult) {
1750 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1751 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1752 }
Michael Jurka946ad472010-07-09 18:05:18 -07001753
Winson Chung785d2eb2011-04-14 16:08:02 -07001754 // Save the current AppsCustomize tab
1755 if (mAppsCustomizeTabHost != null) {
1756 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1757 if (currentTabTag != null) {
1758 outState.putString("apps_customize_currentTab", currentTabTag);
1759 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001760 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1761 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001762 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001763 }
1764
1765 @Override
1766 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001767 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001768
Winson Chunge7a03942011-08-05 15:05:12 -07001769 // Remove all pending runnables
1770 mHandler.removeMessages(ADVANCE_MSG);
1771 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001772 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001773
Winson Chungcd2b0142011-06-08 16:02:26 -07001774 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001775 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001776 mModel.stopLoader();
1777 app.setLauncher(null);
1778
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001779 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001780 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001781 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001782 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001783 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001784 mAppWidgetHost = null;
1785
1786 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787
1788 TextKeyListener.getInstance().release();
1789
Winson Chung81b52252012-08-27 15:34:29 -07001790 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1791 // to prevent leaking Launcher activities on orientation change.
1792 if (mModel != null) {
1793 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1794 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001795
1796 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001797 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001798
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001799 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001800 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1801 mWorkspace.removeAllViews();
1802 mWorkspace = null;
1803 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001804
Michael Jurka2ecf9952012-06-18 12:52:28 -07001805 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001806 }
1807
Adam Cohena9cf38f2011-05-02 15:36:58 -07001808 public DragController getDragController() {
1809 return mDragController;
1810 }
1811
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 @Override
1813 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001814 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 super.startActivityForResult(intent, requestCode);
1816 }
1817
Winson Chung70d72102011-08-12 11:24:35 -07001818 /**
1819 * Indicates that we want global search for this activity by setting the globalSearch
1820 * argument for {@link #startSearch} to true.
1821 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001822 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001823 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001825
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001826 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001827
Karl Rosaen138a0412009-04-23 19:00:21 -07001828 if (initialQuery == null) {
1829 // Use any text typed in the launcher as the initial query
1830 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001831 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 if (appSearchData == null) {
1833 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001834 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 }
Winson Chungadf0c182012-08-23 14:59:07 -07001836 Rect sourceBounds = new Rect();
1837 if (mSearchDropTargetBar != null) {
1838 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1839 }
Romain Guycbb89e42009-06-08 15:52:54 -07001840
Bjorn Bringertc459e522013-06-07 19:36:01 +01001841 startSearch(initialQuery, selectInitialQuery,
1842 appSearchData, sourceBounds);
1843 }
1844
1845 public void startSearch(String initialQuery,
1846 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001847 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001848 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001849 }
1850
1851 /**
1852 * Starts the global search activity. This code is a copied from SearchManager
1853 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001854 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001855 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001856 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001857 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1858 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1859 if (globalSearchActivity == null) {
1860 Log.w(TAG, "No global search activity found.");
1861 return;
1862 }
1863 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1864 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1865 intent.setComponent(globalSearchActivity);
1866 // Make sure that we have a Bundle to put source in
1867 if (appSearchData == null) {
1868 appSearchData = new Bundle();
1869 } else {
1870 appSearchData = new Bundle(appSearchData);
1871 }
1872 // Set source to package name of app that starts global search, if not set already.
1873 if (!appSearchData.containsKey("source")) {
1874 appSearchData.putString("source", getPackageName());
1875 }
1876 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1877 if (!TextUtils.isEmpty(initialQuery)) {
1878 intent.putExtra(SearchManager.QUERY, initialQuery);
1879 }
1880 if (selectInitialQuery) {
1881 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1882 }
1883 intent.setSourceBounds(sourceBounds);
1884 try {
1885 startActivity(intent);
1886 } catch (ActivityNotFoundException ex) {
1887 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1888 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889 }
1890
Winson Chung70d72102011-08-12 11:24:35 -07001891 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001892 public boolean onPrepareOptionsMenu(Menu menu) {
1893 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001894 if (!mWorkspace.isInOverviewMode()) {
1895 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001896 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001897 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001898 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001900 @Override
1901 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001902 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001903 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001904 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001905 }
1906
Joe Onorato9c1289c2009-08-17 11:03:03 -04001907 public boolean isWorkspaceLocked() {
1908 return mWorkspaceLoading || mWaitingForResult;
1909 }
1910
Michael Jurka0280c3b2010-09-17 15:00:07 -07001911 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001912 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001913 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001914 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1915 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001916 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001917 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001918 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001919
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001920 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1921 AppWidgetProviderInfo appWidgetInfo) {
1922 if (appWidgetInfo.configure != null) {
1923 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001924
Bjorn Bringert7984c942009-12-09 15:38:25 +00001925 // Launch over to configure widget, if needed
1926 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001927 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001928 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001929 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001930 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001931 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001932 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001933 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001934 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001935 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 }
1937 }
Romain Guycbb89e42009-06-08 15:52:54 -07001938
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001939 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07001940 // Close any folders that may be open.
1941 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001942 mWorkspace.moveToCustomContentScreen(animate);
1943 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001944 /**
1945 * Process a shortcut drop.
1946 *
1947 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001948 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001949 * @param cell The cell it should be added to, optional
1950 * @param position The location on the screen where it was dropped, optional
1951 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001952 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001953 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001954 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001955 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001956 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001957 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001958
1959 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001960 mPendingAddInfo.cellX = cell[0];
1961 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001962 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001963
1964 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1965 createShortcutIntent.setComponent(componentName);
1966 processShortcut(createShortcutIntent);
1967 }
1968
Adam Cohenfbba09b2011-07-18 21:43:05 -07001969 /**
1970 * Process a widget drop.
1971 *
1972 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001973 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001974 * @param cell The cell it should be added to, optional
1975 * @param position The location on the screen where it was dropped, optional
1976 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001977 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001978 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001979 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001980 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001981 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001982 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001983 mPendingAddInfo.minSpanX = info.minSpanX;
1984 mPendingAddInfo.minSpanY = info.minSpanY;
1985
Adam Cohenfbba09b2011-07-18 21:43:05 -07001986 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001987 mPendingAddInfo.cellX = cell[0];
1988 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001989 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001990 if (span != null) {
1991 mPendingAddInfo.spanX = span[0];
1992 mPendingAddInfo.spanY = span[1];
1993 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001994
Adam Cohened66b2b2012-01-23 17:28:51 -08001995 AppWidgetHostView hostView = info.boundWidget;
1996 int appWidgetId;
1997 if (hostView != null) {
1998 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001999 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002000 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002001 // In this case, we either need to start an activity to get permission to bind
2002 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002003 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002004 Bundle options = info.bindOptions;
2005
2006 boolean success = false;
2007 if (options != null) {
2008 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2009 info.componentName, options);
2010 } else {
2011 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2012 info.componentName);
2013 }
2014 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002015 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002016 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002017 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002018 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2019 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2020 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002021 // TODO: we need to make sure that this accounts for the options bundle.
2022 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002023 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2024 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002025 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002026 }
2027
Joe Onoratodeb98af2010-02-19 14:59:39 -08002028 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002029 // Handle case where user selected "Applications"
2030 String applicationName = getResources().getString(R.string.group_applications);
2031 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002032
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002033 if (applicationName != null && applicationName.equals(shortcutName)) {
2034 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2035 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002036
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002037 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2038 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002039 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002040 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002041 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002042 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002043 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 }
2045
Winson Chung24ab2f12010-09-16 14:10:47 -07002046 void processWallpaper(Intent intent) {
2047 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2048 }
2049
Adam Cohendcd297f2013-06-18 13:13:40 -07002050 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002051 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002052 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 folderInfo.title = getText(R.string.folder_name);
2054
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002056 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002057 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002058 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059
2060 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002061 FolderIcon newFolder =
2062 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002063 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002064 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002065 // Force measure the new folder icon
2066 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2067 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002068 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002069 }
Romain Guycbb89e42009-06-08 15:52:54 -07002070
Joe Onorato9c1289c2009-08-17 11:03:03 -04002071 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002072 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002073 }
2074
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002075 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002076 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002077 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002078 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002079 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002080 }
2081
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002082 protected ComponentName getWallpaperPickerComponent() {
2083 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2084 }
2085
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002086 /**
2087 * Registers various content observers. The current implementation registers
2088 * only a favorites observer to keep track of the favorites applications.
2089 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002090 private void registerContentObservers() {
2091 ContentResolver resolver = getContentResolver();
2092 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2093 true, mWidgetObserver);
2094 }
2095
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002096 @Override
2097 public boolean dispatchKeyEvent(KeyEvent event) {
2098 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2099 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002100 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002101 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002102 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002103 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002104 dumpState();
2105 return true;
2106 }
2107 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002108 }
2109 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2110 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002111 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 return true;
2113 }
2114 }
2115
2116 return super.dispatchKeyEvent(event);
2117 }
2118
Joe Onorato88ec0992009-11-19 13:16:06 -08002119 @Override
2120 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002121 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002122 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002123 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002124 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002125 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002126 Folder openFolder = mWorkspace.getOpenFolder();
2127 if (openFolder.isEditingName()) {
2128 openFolder.dismissEditingName();
2129 } else {
2130 closeFolder();
2131 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002132 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002133 mWorkspace.exitWidgetResizeMode();
2134
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002135 // Back button is a no-op here, but give at least some feedback for the button press
2136 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002137 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002138 }
2139
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002140 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002141 * Re-listen when widgets are reset.
2142 */
2143 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002144 if (mAppWidgetHost != null) {
2145 mAppWidgetHost.startListening();
2146 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002147 }
2148
2149 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002150 * Launches the intent referred by the clicked shortcut.
2151 *
2152 * @param v The view representing the clicked shortcut.
2153 */
2154 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002155 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2156 // view has detached (it's possible for this to happen if the view is removed mid touch).
2157 if (v.getWindowToken() == null) {
2158 return;
2159 }
2160
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002161 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002162 return;
2163 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002164
Adam Cohen1697b792013-09-17 19:08:21 -07002165 if (v instanceof Workspace) {
2166 if (mWorkspace.isInOverviewMode()) {
2167 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002168 }
2169 return;
2170 }
2171
2172 if (v instanceof CellLayout) {
2173 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002174 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002175 }
2176 }
2177
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002178 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002179 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002180 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002181 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2182 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002183
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002184 // Check for special shortcuts
2185 if (intent.getComponent() != null) {
2186 final String shortcutClass = intent.getComponent().getClassName();
2187
2188 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002189 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002190 return;
2191 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2192 MemoryDumpActivity.startDump(this);
2193 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002194 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2195 toggleShowWeightWatcher();
2196 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002197 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002198 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002199
2200 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002201 int[] pos = new int[2];
2202 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002203 intent.setSourceBounds(new Rect(pos[0], pos[1],
2204 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002205
2206 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002207
Daniel Sandlerff02d492013-08-05 02:12:05 -04002208 mStats.recordLaunch(intent, shortcut);
2209
Michael Jurkaddd62e92011-02-16 17:49:14 -08002210 if (success && v instanceof BubbleTextView) {
2211 mWaitingForResume = (BubbleTextView) v;
2212 mWaitingForResume.setStayPressed(true);
2213 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002214 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002215 if (v instanceof FolderIcon) {
2216 FolderIcon fi = (FolderIcon) v;
2217 handleFolderClick(fi);
2218 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002219 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002220 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002221 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002222 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002223 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002224 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002225 }
2226 }
2227
Michael Jurka0e260592010-06-30 17:07:39 -07002228 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002229 return false;
2230 }
2231
Michael Jurkaaf442092010-06-10 17:01:57 -07002232 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002233 * Event handler for the search button
2234 *
2235 * @param v The view that was clicked.
2236 */
2237 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002238 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2239
Amith Yamasania135ba82011-08-09 17:42:01 -07002240 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002241 }
2242
2243 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002244 * Event handler for the voice button
2245 *
2246 * @param v The view that was clicked.
2247 */
2248 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002249 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002250
Bjorn Bringertc459e522013-06-07 19:36:01 +01002251 startVoice();
2252 }
2253
2254 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002255 try {
2256 final SearchManager searchManager =
2257 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2258 ComponentName activityName = searchManager.getGlobalSearchActivity();
2259 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002260 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002261 if (activityName != null) {
2262 intent.setPackage(activityName.getPackageName());
2263 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002264 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002265 } catch (ActivityNotFoundException e) {
2266 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002267 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002268 startActivitySafely(null, intent, "onClickVoiceButton");
2269 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002270 }
2271
2272 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002273 * Event handler for the "grid" button that appears on the home screen, which
2274 * enters all apps mode.
2275 *
2276 * @param v The view that was clicked.
2277 */
2278 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002279 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002280 }
2281
2282 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002283 // Provide the same haptic feedback that the system offers for virtual keys.
2284 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002285 }
2286
Adam Cohen61f560d2013-09-30 15:58:20 -07002287 public void performHapticFeedbackOnTouchDown(View v) {
2288 // Provide the same haptic feedback that the system offers for virtual keys.
2289 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2290 }
2291
2292 public View.OnTouchListener getHapticFeedbackTouchListener() {
2293 if (mHapticFeedbackTouchListener == null) {
2294 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2295 @Override
2296 public boolean onTouch(View v, MotionEvent event) {
2297 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2298 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2299 }
2300 return false;
2301 }
2302 };
2303 }
2304 return mHapticFeedbackTouchListener;
2305 }
2306
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002307 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002308 if (!DISABLE_MARKET_BUTTON) {
2309 if (mAppMarketIntent != null) {
2310 startActivitySafely(v, mAppMarketIntent, "app market");
2311 } else {
2312 Log.e(TAG, "Invalid app market intent.");
2313 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002314 }
2315 }
2316
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002317 /**
2318 * Called when the user stops interacting with the launcher.
2319 * This implies that the user is now on the homescreen and is not doing housekeeping.
2320 */
2321 protected void onInteractionEnd() {}
2322
2323 /**
2324 * Called when the user starts interacting with the launcher.
2325 * The possible interactions are:
2326 * - open all apps
2327 * - reorder an app shortcut, or a widget
2328 * - open the overview mode.
2329 * This is a good time to stop doing things that only make sense
2330 * when the user is on the homescreen and not doing housekeeping.
2331 */
2332 protected void onInteractionBegin() {}
2333
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002334 void startApplicationDetailsActivity(ComponentName componentName) {
2335 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002336 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2337 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002338 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002339 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002340 }
2341
Michael Jurka1e2f4652013-07-08 18:03:46 -07002342 // returns true if the activity was started
2343 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002344 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002345 // System applications cannot be installed. For now, show a toast explaining that.
2346 // We may give them the option of disabling apps this way.
2347 int messageId = R.string.uninstall_system_app_text;
2348 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002349 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002350 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002351 String packageName = componentName.getPackageName();
2352 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002353 Intent intent = new Intent(
2354 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002355 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2356 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002357 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002358 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002359 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002360 }
2361
Michael Jurka86a720e2012-05-09 11:23:23 -07002362 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002363 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002364
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002365 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002366 // Only launch using the new animation if the shortcut has not opted out (this is a
2367 // private contract between launcher and may be ignored in the future).
2368 boolean useLaunchAnimation = (v != null) &&
2369 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2370 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002371 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2372 v.getMeasuredWidth(), v.getMeasuredHeight());
2373
2374 startActivity(intent, opts.toBundle());
2375 } else {
2376 startActivity(intent);
2377 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002378 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379 } catch (SecurityException e) {
2380 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002381 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002383 "or use the exported attribute for this activity. "
2384 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002386 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002388
Michael Jurka86a720e2012-05-09 11:23:23 -07002389 boolean startActivitySafely(View v, Intent intent, Object tag) {
2390 boolean success = false;
2391 try {
2392 success = startActivity(v, intent, tag);
2393 } catch (ActivityNotFoundException e) {
2394 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2395 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2396 }
2397 return success;
2398 }
2399
Adam Cohena9cf38f2011-05-02 15:36:58 -07002400 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002401 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002402 Folder openFolder = mWorkspace.getFolderForTag(info);
2403
2404 // If the folder info reports that the associated folder is open, then verify that
2405 // it is actually opened. There have been a few instances where this gets out of sync.
2406 if (info.opened && openFolder == null) {
2407 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002408 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002409 info.opened = false;
2410 }
2411
Adam Cohenfb91f302012-06-11 15:45:18 -07002412 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002413 // Close any open folder
2414 closeFolder();
2415 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002416 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002417 } else {
2418 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002419 int folderScreen;
2420 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002421 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002422 // .. and close it
2423 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002424 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002425 // Close any folder open on the current screen
2426 closeFolder();
2427 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002428 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002429 }
2430 }
2431 }
2432 }
2433
Adam Cohen268c4752012-06-06 17:47:33 -07002434 /**
2435 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2436 * in the DragLayer in the exact absolute location of the original FolderIcon.
2437 */
2438 private void copyFolderIconToImage(FolderIcon fi) {
2439 final int width = fi.getMeasuredWidth();
2440 final int height = fi.getMeasuredHeight();
2441
2442 // Lazy load ImageView, Bitmap and Canvas
2443 if (mFolderIconImageView == null) {
2444 mFolderIconImageView = new ImageView(this);
2445 }
2446 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2447 mFolderIconBitmap.getHeight() != height) {
2448 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2449 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2450 }
2451
2452 DragLayer.LayoutParams lp;
2453 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2454 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2455 } else {
2456 lp = new DragLayer.LayoutParams(width, height);
2457 }
2458
Adam Cohen307fe232012-08-16 17:55:58 -07002459 // The layout from which the folder is being opened may be scaled, adjust the starting
2460 // view size by this scale factor.
2461 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002462 lp.customPosition = true;
2463 lp.x = mRectForFolderAnimation.left;
2464 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002465 lp.width = (int) (scale * width);
2466 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002467
2468 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2469 fi.draw(mFolderIconCanvas);
2470 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002471 if (fi.getFolder() != null) {
2472 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2473 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002474 }
Adam Cohen268c4752012-06-06 17:47:33 -07002475 // Just in case this image view is still in the drag layer from a previous animation,
2476 // we remove it and re-add it.
2477 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2478 mDragLayer.removeView(mFolderIconImageView);
2479 }
2480 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002481 if (fi.getFolder() != null) {
2482 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002483 }
Adam Cohen268c4752012-06-06 17:47:33 -07002484 }
2485
Adam Cohen2801caf2011-05-13 20:57:39 -07002486 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002487 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002488 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2489 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2490 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2491
Adam Cohenc51934b2011-07-26 21:07:43 -07002492 FolderInfo info = (FolderInfo) fi.getTag();
2493 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2494 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002495 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2496 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002497 }
2498
Adam Cohen268c4752012-06-06 17:47:33 -07002499 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2500 copyFolderIconToImage(fi);
2501 fi.setVisibility(View.INVISIBLE);
2502
Michael Jurka2ecf9952012-06-18 12:52:28 -07002503 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002504 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002505 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2506 oa.start();
2507 }
2508
Adam Cohen268c4752012-06-06 17:47:33 -07002509 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002510 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002511 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2512 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2513 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2514
Adam Cohen268c4752012-06-06 17:47:33 -07002515 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002516
Adam Cohen268c4752012-06-06 17:47:33 -07002517 // We remove and re-draw the FolderIcon in-case it has changed
2518 mDragLayer.removeView(mFolderIconImageView);
2519 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002520 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002521 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002522 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002523 oa.addListener(new AnimatorListenerAdapter() {
2524 @Override
2525 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002526 if (cl != null) {
2527 cl.clearFolderLeaveBehind();
2528 // Remove the ImageView copy of the FolderIcon and make the original visible.
2529 mDragLayer.removeView(mFolderIconImageView);
2530 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002531 }
2532 }
2533 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002534 oa.start();
2535 }
2536
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002537 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002538 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002539 * is animated relative to the specified View. If the View is null, no animation
2540 * is played.
2541 *
2542 * @param folderInfo The FolderInfo describing the folder to open.
2543 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002544 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002545 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002546 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002547
Adam Cohena9cf38f2011-05-02 15:36:58 -07002548 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002549
Adam Cohen4554ee12011-08-03 16:13:21 -07002550 // Just verify that the folder hasn't already been added to the DragLayer.
2551 // There was a one-off crash where the folder had a parent already.
2552 if (folder.getParent() == null) {
2553 mDragLayer.addView(folder);
2554 mDragController.addDropTarget((DropTarget) folder);
2555 } else {
2556 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2557 folder.getParent() + ").");
2558 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002559 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002560 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002561
2562 // Notify the accessibility manager that this folder "window" has appeared and occluded
2563 // the workspace items
2564 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2565 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002566 }
2567
2568 public void closeFolder() {
2569 Folder folder = mWorkspace.getOpenFolder();
2570 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002571 if (folder.isEditingName()) {
2572 folder.dismissEditingName();
2573 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002574 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002575
2576 // Dismiss the folder cling
2577 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002578 }
2579 }
2580
2581 void closeFolder(Folder folder) {
2582 folder.getInfo().opened = false;
2583
2584 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2585 if (parent != null) {
2586 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2587 shrinkAndFadeInFolderIcon(fi);
2588 }
2589 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002590
2591 // Notify the accessibility manager that this folder "window" has disappeard and no
2592 // longer occludeds the workspace items
2593 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002594 }
2595
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002596 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002597 if (!isDraggingEnabled()) return false;
2598 if (isWorkspaceLocked()) return false;
2599 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002600
Adam Cohen1697b792013-09-17 19:08:21 -07002601 if (v instanceof Workspace) {
2602 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002603 if (mWorkspace.enterOverviewMode()) {
2604 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2605 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2606 return true;
2607 } else {
2608 return false;
2609 }
Adam Cohen1697b792013-09-17 19:08:21 -07002610 }
Adam Cohen1697b792013-09-17 19:08:21 -07002611 }
2612
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002613 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002614 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002615 }
2616
Michael Jurka0280c3b2010-09-17 15:00:07 -07002617 resetAddInfo();
2618 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002619 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002620 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002621 return true;
2622 }
2623
Winson Chung3d503fb2011-07-13 17:25:49 -07002624 // The hotseat touch handling does not go through Workspace, and we always allow long press
2625 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002626 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002627 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2628 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002629 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002630 // User long pressed on empty space
2631 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2632 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2633 // Disabling reordering until we sort out some issues.
2634 if (mWorkspace.isInOverviewMode()) {
2635 mWorkspace.startReordering(v);
2636 } else {
2637 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002638 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002639 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002640 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002641 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002642 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002643 }
2644 }
2645 }
2646 return true;
2647 }
2648
Winson Chung3d503fb2011-07-13 17:25:49 -07002649 boolean isHotseatLayout(View layout) {
2650 return mHotseat != null && layout != null &&
2651 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2652 }
2653 Hotseat getHotseat() {
2654 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002655 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002656 View getOverviewPanel() {
2657 return mOverviewPanel;
2658 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002659 SearchDropTargetBar getSearchBar() {
2660 return mSearchDropTargetBar;
2661 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002662
Winson Chung3d503fb2011-07-13 17:25:49 -07002663 /**
2664 * Returns the CellLayout of the specified container at the specified screen.
2665 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002666 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002667 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2668 if (mHotseat != null) {
2669 return mHotseat.getLayout();
2670 } else {
2671 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002672 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002673 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002674 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002675 }
2676 }
2677
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002678 Workspace getWorkspace() {
2679 return mWorkspace;
2680 }
2681
Daniel Sandler843e8602010-06-07 14:59:01 -04002682 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002683 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002684 }
2685
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002686 /**
2687 * Helper method for the cameraZoomIn/cameraZoomOut animations
2688 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002689 * @param scaleFactor The scale factor used for the zoom
2690 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002691 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002692 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002693 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002694 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002695
Craig Mautner360310b2012-10-26 15:13:08 -07002696 private void setWorkspaceBackground(boolean workspace) {
2697 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002698 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002699 }
2700
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002701 void updateWallpaperVisibility(boolean visible) {
2702 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2703 int curflags = getWindow().getAttributes().flags
2704 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2705 if (wpflags != curflags) {
2706 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2707 }
Craig Mautner360310b2012-10-26 15:13:08 -07002708 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002709 }
2710
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002711 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2712 if (v instanceof LauncherTransitionable) {
2713 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2714 }
2715 }
2716
Michael Jurkabed61d22012-02-14 22:51:29 -08002717 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2718 if (v instanceof LauncherTransitionable) {
2719 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2720 }
Winson Chung70442722012-02-10 15:43:22 -08002721
2722 // Update the workspace transition step as well
2723 dispatchOnLauncherTransitionStep(v, 0f);
2724 }
2725
2726 private void dispatchOnLauncherTransitionStep(View v, float t) {
2727 if (v instanceof LauncherTransitionable) {
2728 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2729 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002730 }
2731
2732 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2733 if (v instanceof LauncherTransitionable) {
2734 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2735 }
Winson Chung70442722012-02-10 15:43:22 -08002736
2737 // Update the workspace transition step as well
2738 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002739 }
2740
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002741 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002742 * Things to test when changing the following seven functions.
2743 * - Home from workspace
2744 * - from center screen
2745 * - from other screens
2746 * - Home from all apps
2747 * - from center screen
2748 * - from other screens
2749 * - Back from all apps
2750 * - from center screen
2751 * - from other screens
2752 * - Launch app from workspace and quit
2753 * - with back
2754 * - with home
2755 * - Launch app from all apps and quit
2756 * - with back
2757 * - with home
2758 * - Go to a screen that's not the default, then all
2759 * apps, and launch and app, and go back
2760 * - with back
2761 * -with home
2762 * - On workspace, long press power and go back
2763 * - with back
2764 * - with home
2765 * - On all apps, long press power and go back
2766 * - with back
2767 * - with home
2768 * - On workspace, power off
2769 * - On all apps, power off
2770 * - Launch an app and turn off the screen while in that app
2771 * - Go back with home key
2772 * - Go back with back key TODO: make this not go to workspace
2773 * - From all apps
2774 * - From workspace
2775 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2776 * - From all apps
2777 * - From the center workspace
2778 * - From another workspace
2779 */
2780
2781 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002782 * Zoom the camera out from the workspace to reveal 'toView'.
2783 * Assumes that the view to show is anchored at either the very top or very bottom
2784 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002785 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002786 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002787 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2788 showAppsCustomizeHelper(animated, springLoaded, contentType);
2789 }
2790 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2791 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002792 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002793 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002794 mStateAnimation.cancel();
2795 mStateAnimation = null;
2796 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002797 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002798
Winson Chungf0ea4d32011-06-06 14:27:16 -07002799 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2800 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2801 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002802 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002803 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002804 final int startDelay =
2805 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002806
Michael Jurkab3e22d92011-10-31 15:58:33 -07002807 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002808
Michael Jurkad74c9842011-07-10 12:44:21 -07002809 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002810 Animator workspaceAnim =
2811 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002812 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2813 // Set the content type for the all apps space
2814 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2815 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002816
2817 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002818 toView.setScaleX(scale);
2819 toView.setScaleY(scale);
2820 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2821 scaleAnim.
2822 scaleX(1f).scaleY(1f).
2823 setDuration(duration).
2824 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002825
Winson Chungf0ea4d32011-06-06 14:27:16 -07002826 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002827 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002828 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002829 .ofFloat(toView, "alpha", 0f, 1f)
2830 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002831 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002832 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2833 @Override
2834 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002835 if (animation == null) {
2836 throw new RuntimeException("animation is null");
2837 }
Winson Chung70442722012-02-10 15:43:22 -08002838 float t = (Float) animation.getAnimatedValue();
2839 dispatchOnLauncherTransitionStep(fromView, t);
2840 dispatchOnLauncherTransitionStep(toView, t);
2841 }
2842 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002843
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002844 // toView should appear right at the end of the workspace shrink
2845 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002846 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002847 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002848 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002849
2850 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002851 boolean animationCancelled = false;
2852
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002853 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002854 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002855 // Prepare the position
2856 toView.setTranslationX(0.0f);
2857 toView.setTranslationY(0.0f);
2858 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002859 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002860 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002861 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002862 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002863 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2864 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002865
Winson Chungc7d2b602012-05-16 17:02:20 -07002866 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002867 if (mSearchDropTargetBar != null) {
2868 mSearchDropTargetBar.hideSearchBar(false);
2869 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002870 }
2871
Adam Cohencff6af82011-09-13 14:51:53 -07002872 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002873 public void onAnimationCancel(Animator animation) {
2874 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002875 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002876 });
2877
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002878 if (workspaceAnim != null) {
2879 mStateAnimation.play(workspaceAnim);
2880 }
Michael Jurka1899a362011-11-03 13:50:45 -07002881
2882 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002883
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002884 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2885 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002886
2887 // If any of the objects being animated haven't been measured/laid out
2888 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002889 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002890 (mWorkspace.getMeasuredWidth() == 0) ||
2891 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002892 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002893 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002894
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002895 final AnimatorSet stateAnimation = mStateAnimation;
2896 final Runnable startAnimRunnable = new Runnable() {
2897 public void run() {
2898 // Check that mStateAnimation hasn't changed while
2899 // we waited for a layout/draw pass
2900 if (mStateAnimation != stateAnimation)
2901 return;
2902 setPivotsForZoom(toView, scale);
2903 dispatchOnLauncherTransitionStart(fromView, animated, false);
2904 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002905 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002906 }
2907 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002908 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002909 final ViewTreeObserver observer = toView.getViewTreeObserver();
2910 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2911 public void onGlobalLayout() {
2912 startAnimRunnable.run();
2913 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2914 }
2915 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002916 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002917 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002918 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002919 } else {
2920 toView.setTranslationX(0.0f);
2921 toView.setTranslationY(0.0f);
2922 toView.setScaleX(1.0f);
2923 toView.setScaleY(1.0f);
2924 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002925 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002926
Daniel Sandlere4f98912013-06-25 15:13:26 -04002927 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002928 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002929 if (mSearchDropTargetBar != null) {
2930 mSearchDropTargetBar.hideSearchBar(false);
2931 }
Michael Jurkaabded662011-03-04 12:06:57 -08002932 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002933 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002934 dispatchOnLauncherTransitionStart(fromView, animated, false);
2935 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002936 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002937 dispatchOnLauncherTransitionStart(toView, animated, false);
2938 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002939 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002940 }
2941
2942 /**
2943 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002944 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002945 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002946 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002947 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2948 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002949
Michael Jurkab3e22d92011-10-31 15:58:33 -07002950 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002951 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002952 mStateAnimation.cancel();
2953 mStateAnimation = null;
2954 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002955 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002956
Winson Chungf0ea4d32011-06-06 14:27:16 -07002957 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002958 final int fadeOutDuration =
2959 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002960 final float scaleFactor = (float)
2961 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2962 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002963 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002964 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002965 if (toState == State.WORKSPACE) {
2966 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2967 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002968 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002969 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2970 workspaceAnim = mWorkspace.getChangeStateAnimation(
2971 Workspace.State.SPRING_LOADED, animated);
2972 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002973
Michael Jurkab3e22d92011-10-31 15:58:33 -07002974 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002975 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002976 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002977 final LauncherViewPropertyAnimator scaleAnim =
2978 new LauncherViewPropertyAnimator(fromView);
2979 scaleAnim.
2980 scaleX(scaleFactor).scaleY(scaleFactor).
2981 setDuration(duration).
2982 setInterpolator(new Workspace.ZoomInInterpolator());
2983
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002984 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002985 .ofFloat(fromView, "alpha", 1f, 0f)
2986 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002987 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002988 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2989 @Override
2990 public void onAnimationUpdate(ValueAnimator animation) {
2991 float t = 1f - (Float) animation.getAnimatedValue();
2992 dispatchOnLauncherTransitionStep(fromView, t);
2993 dispatchOnLauncherTransitionStep(toView, t);
2994 }
2995 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002996
Michael Jurka2ecf9952012-06-18 12:52:28 -07002997 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002998
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002999 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3000 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003001 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003002
3003 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003004 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003005 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003006 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003007 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3008 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003009 if (onCompleteRunnable != null) {
3010 onCompleteRunnable.run();
3011 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003012 mAppsCustomizeContent.updateCurrentPageScroll();
3013 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003014 }
3015 });
3016
Winson Chungf0ea4d32011-06-06 14:27:16 -07003017 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003018 if (workspaceAnim != null) {
3019 mStateAnimation.play(workspaceAnim);
3020 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003021 dispatchOnLauncherTransitionStart(fromView, animated, true);
3022 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003023 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003024 } else {
3025 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003026 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003027 dispatchOnLauncherTransitionStart(fromView, animated, true);
3028 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003029 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003030 dispatchOnLauncherTransitionStart(toView, animated, true);
3031 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003032 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003033 }
3034
Michael Jurkae326f182011-11-21 14:05:46 -08003035 @Override
3036 public void onTrimMemory(int level) {
3037 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003038 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003039 mAppsCustomizeTabHost.onTrimMemory();
3040 }
3041 }
3042
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003043 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003044 showWorkspace(animated, null);
3045 }
3046
3047 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003048 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003049 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003050 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003051 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003052
Winson Chungc7d2b602012-05-16 17:02:20 -07003053 // Show the search bar (only animate if we were showing the drop target bar in spring
3054 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003055 if (mSearchDropTargetBar != null) {
3056 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3057 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003058
Michael Jurkab3e22d92011-10-31 15:58:33 -07003059 // Set focus to the AppsCustomize button
3060 if (mAllAppsButton != null) {
3061 mAllAppsButton.requestFocus();
3062 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003063 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003064
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003065 // Change the state *after* we've called all the transition code
3066 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003067
Winson Chung5fb63472011-02-02 17:03:37 -08003068 // Resume the auto-advance of widgets
3069 mUserPresent = true;
3070 updateRunning();
3071
alanv1d4fde62012-10-17 13:15:47 -07003072 // Send an accessibility event to announce the context change
3073 getWindow().getDecorView()
3074 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003075
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003076 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003077 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003078 }
3079
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003080 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003081 }
3082
Winson Chungc58497e2013-09-03 17:48:37 -07003083 void showAllApps(boolean animated,
3084 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003085 if (mState != State.WORKSPACE) return;
3086
Winson Chungc58497e2013-09-03 17:48:37 -07003087 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003088 mAppsCustomizeTabHost.requestFocus();
3089
Michael Jurkab3e22d92011-10-31 15:58:33 -07003090 // Change the state *after* we've called all the transition code
3091 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003092 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003093
3094 // Pause the auto-advance of widgets until we are out of AllApps
3095 mUserPresent = false;
3096 updateRunning();
3097 closeFolder();
3098
3099 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003100 getWindow().getDecorView()
3101 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003102 }
3103
Adam Cohen7777d962011-08-18 18:58:38 -07003104 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003105 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003106 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003107 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003108 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003109 }
Adam Cohen7777d962011-08-18 18:58:38 -07003110
Adam Cohened66b2b2012-01-23 17:28:51 -08003111 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3112 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003113 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3114
Winson Chunge7a03942011-08-05 15:05:12 -07003115 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003116 @Override
3117 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003118 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003119 // Before we show workspace, hide all apps again because
3120 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3121 // clean up our state transition functions
3122 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003123 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003124 } else {
3125 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003126 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003127 }
3128 }, (extendedDelay ?
3129 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3130 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3131 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003132
Michael Jurkad3ef3062010-11-23 16:23:58 -08003133 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003134 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003135 final boolean animated = true;
3136 final boolean springLoaded = true;
3137 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003138 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003139 }
3140 // Otherwise, we are not in spring loaded mode, so don't do anything.
3141 }
3142
Michael Jurkab3e22d92011-10-31 15:58:33 -07003143 void lockAllApps() {
3144 // TODO
3145 }
3146
3147 void unlockAllApps() {
3148 // TODO
3149 }
3150
Winson Chungf0ea4d32011-06-06 14:27:16 -07003151 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003152 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003153 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003154 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003155 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003156 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003157 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003158 int duration = 0;
3159 if (mSearchDropTargetBar != null) {
3160 duration = mSearchDropTargetBar.getTransitionInDuration();
3161 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003162 mHotseat.animate().alpha(1f).setDuration(duration);
3163 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003164 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003165 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003166 }
3167 }
3168 }
3169
3170 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003171 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003172 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003173 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003174 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003175 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003176 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003177 int duration = 0;
3178 if (mSearchDropTargetBar != null) {
3179 duration = mSearchDropTargetBar.getTransitionOutDuration();
3180 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003181 mHotseat.animate().alpha(0f).setDuration(duration);
3182 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003183 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003184 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003185 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003186 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003187 }
3188
Patrick Dubroy5f445422011-02-18 14:35:21 -08003189 /**
3190 * Add an item from all apps or customize onto the given workspace screen.
3191 * If layout is null, add to the current screen.
3192 */
3193 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003194 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003195 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003196 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003197 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003198
Winson Chungdff8ebb2011-09-08 17:25:31 -07003199 /** Maps the current orientation to an index for referencing orientation correct global icons */
3200 private int getCurrentOrientationIndexForGlobalIcons() {
3201 // default - 0, landscape - 1
3202 switch (getResources().getConfiguration().orientation) {
3203 case Configuration.ORIENTATION_LANDSCAPE:
3204 return 1;
3205 default:
3206 return 0;
3207 }
3208 }
3209
Michael Jurkaae65ee32012-04-30 11:45:54 -07003210 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003211 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003212 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003213 // Look for the toolbar icon specified in the activity meta-data
3214 Bundle metaData = packageManager.getActivityInfo(
3215 activityName, PackageManager.GET_META_DATA).metaData;
3216 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003217 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003218 if (iconResId != 0) {
3219 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003220 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003221 }
3222 }
3223 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003224 // This can happen if the activity defines an invalid drawable
3225 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3226 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003227 } catch (Resources.NotFoundException nfe) {
3228 // This can happen if the activity defines an invalid drawable
3229 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3230 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003231 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003232 return null;
3233 }
3234
3235 // if successful in getting icon, return it; otherwise, set button to use default drawable
3236 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003237 int buttonId, ComponentName activityName, int fallbackDrawableId,
3238 String toolbarResourceName) {
3239 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003240 Resources r = getResources();
3241 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3242 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003243
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003244 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003245 // If we were unable to find the icon via the meta-data, use a generic one
3246 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003247 toolbarIcon = r.getDrawable(fallbackDrawableId);
3248 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003249 if (button != null) {
3250 button.setCompoundDrawables(toolbarIcon, null, null, null);
3251 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003252 return null;
3253 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003254 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003255 if (button != null) {
3256 button.setCompoundDrawables(toolbarIcon, null, null, null);
3257 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003258 return toolbarIcon.getConstantState();
3259 }
3260 }
3261
3262 // if successful in getting icon, return it; otherwise, set button to use default drawable
3263 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003264 int buttonId, ComponentName activityName, int fallbackDrawableId,
3265 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003266 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003267 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003268
Michael Jurka19e0fc52011-07-22 18:00:21 -07003269 if (button != null) {
3270 // If we were unable to find the icon via the meta-data, use a
3271 // generic one
3272 if (toolbarIcon == null) {
3273 button.setImageResource(fallbackDrawableId);
3274 } else {
3275 button.setImageDrawable(toolbarIcon);
3276 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003277 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003278
3279 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3280
Michael Jurka0423dcf2010-10-05 14:56:18 -07003281 }
3282
Winson Chung1b884092012-06-08 17:13:02 -07003283 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003284 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003285 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003286 }
3287
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003288 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003289 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003290 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003291 }
3292
Winson Chungbb185bd2011-11-21 12:31:42 -08003293 private void invalidatePressedFocusedStates(View container, View button) {
3294 if (container instanceof HolographicLinearLayout) {
3295 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3296 layout.invalidatePressedFocusedStates();
3297 } else if (button instanceof HolographicImageView) {
3298 HolographicImageView view = (HolographicImageView) button;
3299 view.invalidatePressedFocusedStates();
3300 }
3301 }
3302
Cristina Stancu476493b2013-08-07 17:20:14 +01003303 public View getQsbBar() {
3304 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003305 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3306 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003307 }
3308 return mQsbBar;
3309 }
3310
3311 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003312 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003313 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003314 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003315 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003316
Winson Chung1cad91e2011-05-25 17:41:01 -07003317 final SearchManager searchManager =
3318 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3319 ComponentName activityName = searchManager.getGlobalSearchActivity();
3320 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003321 int coi = getCurrentOrientationIndexForGlobalIcons();
3322 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003323 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3324 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3325 if (sGlobalSearchIcon[coi] == null) {
3326 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3327 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3328 TOOLBAR_ICON_METADATA_NAME);
3329 }
3330
Winson Chungc51db6a2011-10-05 11:44:49 -07003331 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3332 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003333 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003334 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003335 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003336 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003337 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3338 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003339 if (searchButton != null) searchButton.setVisibility(View.GONE);
3340 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003341 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003342 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003343 }
3344 }
3345
Cristina Stancu476493b2013-08-07 17:20:14 +01003346 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003347 final View searchButtonContainer = findViewById(R.id.search_button_container);
3348 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003349 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003350 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003351 }
3352
Cristina Stancu476493b2013-08-07 17:20:14 +01003353 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003354 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003355 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003356
Winson Chungc51db6a2011-10-05 11:44:49 -07003357 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003358 final SearchManager searchManager =
3359 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3360 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3361
3362 ComponentName activityName = null;
3363 if (globalSearchActivity != null) {
3364 // Check if the global search activity handles voice search
3365 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3366 intent.setPackage(globalSearchActivity.getPackageName());
3367 activityName = intent.resolveActivity(getPackageManager());
3368 }
3369
3370 if (activityName == null) {
3371 // Fallback: check if an activity other than the global search activity
3372 // resolves this
3373 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3374 activityName = intent.resolveActivity(getPackageManager());
3375 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003376 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003377 int coi = getCurrentOrientationIndexForGlobalIcons();
3378 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003379 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3380 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3381 if (sVoiceSearchIcon[coi] == null) {
3382 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3383 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3384 TOOLBAR_ICON_METADATA_NAME);
3385 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003386 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003387 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003388 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003389 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003390 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003391 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003392 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003393 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003394 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003395 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003396 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003397 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003398
Cristina Stancu476493b2013-08-07 17:20:14 +01003399 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003400 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3401 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003402 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003403 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003404 }
3405
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003406 public void setVoiceButtonProxyVisible(boolean visible) {
3407 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3408 if (voiceButtonProxy != null) {
3409 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3410 }
3411 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003412 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003413 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003414 */
3415 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003416 if (!DISABLE_MARKET_BUTTON) {
3417 final View marketButton = findViewById(R.id.market_button);
3418 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3419 // Find the app market activity by resolving an intent.
3420 // (If multiple app markets are installed, it will return the ResolverActivity.)
3421 ComponentName activityName = intent.resolveActivity(getPackageManager());
3422 if (activityName != null) {
3423 int coi = getCurrentOrientationIndexForGlobalIcons();
3424 mAppMarketIntent = intent;
3425 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3426 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3427 TOOLBAR_ICON_METADATA_NAME);
3428 marketButton.setVisibility(View.VISIBLE);
3429 } else {
3430 // We should hide and disable the view so that we don't try and restore the visibility
3431 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3432 marketButton.setVisibility(View.GONE);
3433 marketButton.setEnabled(false);
3434 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003435 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003436 }
3437
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003438 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003439 if (!DISABLE_MARKET_BUTTON) {
3440 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3441 Resources r = getResources();
3442 Drawable marketIconDrawable = d.newDrawable(r);
3443 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3444 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3445 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003446
Winson Chungd64a6662013-09-30 11:06:59 -07003447 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3448 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003449 }
3450
Michael Jurkad7c28052012-04-27 15:43:36 -07003451 @Override
3452 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003453 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003454 final List<CharSequence> text = event.getText();
3455 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003456 // Populate event with a fake title based on the current state.
3457 if (mState == State.APPS_CUSTOMIZE) {
3458 text.add(getString(R.string.all_apps_button_label));
3459 } else {
3460 text.add(getString(R.string.all_apps_home_button_label));
3461 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003462 return result;
3463 }
3464
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003465 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003466 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003467 */
3468 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3469 @Override
3470 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003471 closeSystemDialogs();
3472 }
3473 }
3474
3475 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003476 * Receives notifications whenever the appwidgets are reset.
3477 */
3478 private class AppWidgetResetObserver extends ContentObserver {
3479 public AppWidgetResetObserver() {
3480 super(new Handler());
3481 }
3482
3483 @Override
3484 public void onChange(boolean selfChange) {
3485 onAppWidgetReset();
3486 }
3487 }
3488
3489 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003490 * If the activity is currently paused, signal that we need to run the passed Runnable
3491 * in onResume.
3492 *
3493 * This needs to be called from incoming places where resources might have been loaded
3494 * while we are paused. That is becaues the Configuration might be wrong
3495 * when we're not running, and if it comes back to what it was when we
3496 * were paused, we are not restarted.
3497 *
3498 * Implementation of the method from LauncherModel.Callbacks.
3499 *
3500 * @return true if we are currently paused. The caller might be able to
3501 * skip some work in that case since we will come back again.
3502 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003503 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003504 if (mPaused) {
3505 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003506 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003507 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003508 }
3509 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003510 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003511 return true;
3512 } else {
3513 return false;
3514 }
3515 }
3516
Michael Jurkac402cd92013-05-20 15:49:32 +02003517 private boolean waitUntilResume(Runnable run) {
3518 return waitUntilResume(run, false);
3519 }
3520
Michael Jurka1e2f4652013-07-08 18:03:46 -07003521 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003522 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003523 }
3524
Michael Jurka7607c2f2013-04-03 14:33:19 -07003525 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003526 * If the activity is currently paused, signal that we need to re-run the loader
3527 * in onResume.
3528 *
3529 * This needs to be called from incoming places where resources might have been loaded
3530 * while we are paused. That is becaues the Configuration might be wrong
3531 * when we're not running, and if it comes back to what it was when we
3532 * were paused, we are not restarted.
3533 *
3534 * Implementation of the method from LauncherModel.Callbacks.
3535 *
3536 * @return true if we are currently paused. The caller might be able to
3537 * skip some work in that case since we will come back again.
3538 */
3539 public boolean setLoadOnResume() {
3540 if (mPaused) {
3541 Log.i(TAG, "setLoadOnResume");
3542 mOnResumeNeedsLoad = true;
3543 return true;
3544 } else {
3545 return false;
3546 }
3547 }
3548
3549 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003550 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003551 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003552 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003553 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003554 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003555 } else {
3556 return SCREEN_COUNT / 2;
3557 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003558 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003559
Joe Onorato9c1289c2009-08-17 11:03:03 -04003560 /**
3561 * Refreshes the shortcuts shown on the workspace.
3562 *
3563 * Implementation of the method from LauncherModel.Callbacks.
3564 */
3565 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003566 // If we're starting binding all over again, clear any bind calls we'd postponed in
3567 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3568 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003569 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003570
Winson Chungd64d1762013-08-20 14:37:16 -07003571 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003572 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003573 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003574
Michael Jurka05bf644e2011-11-30 20:28:53 -08003575 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003576 if (mHotseat != null) {
3577 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003578 }
3579 }
3580
Adam Cohendcd297f2013-06-18 13:13:40 -07003581 @Override
3582 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003583 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003584
Adam Cohen5084cba2013-09-03 12:01:16 -07003585 // If there are no screens, we need to have an empty screen
3586 if (orderedScreenIds.size() == 0) {
3587 mWorkspace.addExtraEmptyScreen();
3588 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003589
3590 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003591 // setCurrentPage() so ensure that all pages are added before calling this).
3592 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003593 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3594 mWorkspace.createCustomContentPage();
3595 }
Winson Chung64359a52013-07-08 17:17:08 -07003596 }
3597
3598 @Override
3599 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003600 int count = orderedScreenIds.size();
3601 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003602 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003603 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003604 }
3605
Adam Cohen39a06042013-07-19 14:30:12 -07003606 private boolean shouldShowWeightWatcher() {
3607 String spKey = LauncherAppState.getSharedPreferencesKey();
3608 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003609 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003610
3611 return show;
3612 }
3613
Adam Cohen4caf2982013-08-20 18:54:31 -07003614 private boolean emailSent() {
3615 String spKey = LauncherAppState.getSharedPreferencesKey();
3616 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3617 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3618 return show;
3619 }
3620
3621 private void setEmailSent(boolean sent) {
3622 String spKey = LauncherAppState.getSharedPreferencesKey();
3623 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3624
3625 SharedPreferences.Editor editor = sp.edit();
3626 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3627 editor.commit();
3628 }
3629
Adam Cohen39a06042013-07-19 14:30:12 -07003630 private void toggleShowWeightWatcher() {
3631 String spKey = LauncherAppState.getSharedPreferencesKey();
3632 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3633 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3634
3635 show = !show;
3636
3637 SharedPreferences.Editor editor = sp.edit();
3638 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3639 editor.commit();
3640
3641 if (mWeightWatcher != null) {
3642 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3643 }
3644 }
3645
Winson Chungd64d1762013-08-20 14:37:16 -07003646 public void bindAppsAdded(final ArrayList<Long> newScreens,
3647 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003648 final ArrayList<ItemInfo> addAnimated,
3649 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003650 Runnable r = new Runnable() {
3651 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003652 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003653 }
3654 };
3655 if (waitUntilResume(r)) {
3656 return;
3657 }
3658
Winson Chungd64d1762013-08-20 14:37:16 -07003659 // Add the new screens
3660 bindAddScreens(newScreens);
3661
3662 // We add the items without animation on non-visible pages, and with
3663 // animations on the new page (which we will try and snap to).
3664 if (!addNotAnimated.isEmpty()) {
3665 bindItems(addNotAnimated, 0,
3666 addNotAnimated.size(), false);
3667 }
3668 if (!addAnimated.isEmpty()) {
3669 bindItems(addAnimated, 0,
3670 addAnimated.size(), true);
3671 }
Winson Chungc58497e2013-09-03 17:48:37 -07003672
3673 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3674 addedApps != null && mAppsCustomizeContent != null) {
3675 mAppsCustomizeContent.addApps(addedApps);
3676 }
Winson Chungd64d1762013-08-20 14:37:16 -07003677 }
3678
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003679 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003680 * Bind the items start-end from the list.
3681 *
3682 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003683 */
Winson Chung64359a52013-07-08 17:17:08 -07003684 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3685 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003686 Runnable r = new Runnable() {
3687 public void run() {
3688 bindItems(shortcuts, start, end, forceAnimateIcons);
3689 }
3690 };
3691 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003692 return;
3693 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003694
Winson Chungf0c6ae02012-03-21 16:10:31 -07003695 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003696 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3697 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003698 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003699 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003700 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003701 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003702 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003703
3704 // Short circuit if we are loading dock items for a configuration which has no dock
3705 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3706 mHotseat == null) {
3707 continue;
3708 }
3709
Joe Onorato9c1289c2009-08-17 11:03:03 -04003710 switch (item.itemType) {
3711 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3712 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003713 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003714 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003715
Winson Chung64359a52013-07-08 17:17:08 -07003716 /*
3717 * TODO: FIX collision case
3718 */
Winson Chungce376632013-07-11 16:12:41 -07003719 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3720 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3721 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3722 throw new RuntimeException("OCCUPIED");
3723 }
Winson Chung64359a52013-07-08 17:17:08 -07003724 }
3725
Adam Cohendcd297f2013-06-18 13:13:40 -07003726 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3727 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003728 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003729 // Animate all the applications up now
3730 shortcut.setAlpha(0f);
3731 shortcut.setScaleX(0f);
3732 shortcut.setScaleY(0f);
3733 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003734 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003735 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003736 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003737 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003738 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003739 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003740 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003741 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3742 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003743 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003744 default:
3745 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003746 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003747 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003748
Winson Chung997a9232013-07-24 15:33:46 -07003749 if (animateIcons) {
3750 // Animate to the correct page
3751 if (newShortcutsScreenId > -1) {
3752 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003753 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003754 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003755 // We post the animation slightly delayed to prevent slowdowns
3756 // when we are loading right after we return to launcher.
3757 mWorkspace.postDelayed(new Runnable() {
3758 public void run() {
3759 mWorkspace.snapToPage(newScreenIndex);
3760 mWorkspace.postDelayed(new Runnable() {
3761 public void run() {
3762 anim.playTogether(bounceAnims);
3763 anim.start();
3764 }
3765 }, NEW_APPS_ANIMATION_DELAY);
3766 }
3767 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003768 }
3769 }
Winson Chung64359a52013-07-08 17:17:08 -07003770 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003771 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003772 }
3773
Joe Onorato9c1289c2009-08-17 11:03:03 -04003774 /**
3775 * Implementation of the method from LauncherModel.Callbacks.
3776 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003777 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003778 Runnable r = new Runnable() {
3779 public void run() {
3780 bindFolders(folders);
3781 }
3782 };
3783 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003784 return;
3785 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003786 sFolders.clear();
3787 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003788 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003789
3790 /**
3791 * Add the views for a widget to the workspace.
3792 *
3793 * Implementation of the method from LauncherModel.Callbacks.
3794 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003795 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003796 Runnable r = new Runnable() {
3797 public void run() {
3798 bindAppWidget(item);
3799 }
3800 };
3801 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003802 return;
3803 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003804
Daniel Sandler843e8602010-06-07 14:59:01 -04003805 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3806 if (DEBUG_WIDGETS) {
3807 Log.d(TAG, "bindAppWidget: " + item);
3808 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003809 final Workspace workspace = mWorkspace;
3810
3811 final int appWidgetId = item.appWidgetId;
3812 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003813 if (DEBUG_WIDGETS) {
3814 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3815 }
3816
Joe Onorato9c1289c2009-08-17 11:03:03 -04003817 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3818
Joe Onorato9c1289c2009-08-17 11:03:03 -04003819 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003820 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003821
Adam Cohendcd297f2013-06-18 13:13:40 -07003822 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003823 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003824 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3825
Joe Onorato9c1289c2009-08-17 11:03:03 -04003826 workspace.requestLayout();
3827
Daniel Sandler843e8602010-06-07 14:59:01 -04003828 if (DEBUG_WIDGETS) {
3829 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3830 + (SystemClock.uptimeMillis()-start) + "ms");
3831 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003832 }
3833
Adam Cohen1462de32012-07-24 22:34:36 -07003834 public void onPageBoundSynchronously(int page) {
3835 mSynchronouslyBoundPages.add(page);
3836 }
3837
Joe Onorato9c1289c2009-08-17 11:03:03 -04003838 /**
3839 * Callback saying that there aren't any more items to bind.
3840 *
3841 * Implementation of the method from LauncherModel.Callbacks.
3842 */
Adam Cohene25af792013-06-06 23:08:25 -07003843 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003844 Runnable r = new Runnable() {
3845 public void run() {
3846 finishBindingItems(upgradePath);
3847 }
3848 };
3849 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003850 return;
3851 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003852 if (mSavedState != null) {
3853 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003854 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003855 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003856 mSavedState = null;
3857 }
3858
Adam Cohen1462de32012-07-24 22:34:36 -07003859 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003860
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003861 // If we received the result of any pending adds while the loader was running (e.g. the
3862 // widget configuration forced an orientation change), process them now.
3863 for (int i = 0; i < sPendingAddList.size(); i++) {
3864 completeAdd(sPendingAddList.get(i));
3865 }
3866 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003867
Winson Chungc51db6a2011-10-05 11:44:49 -07003868 // Update the market app icon as necessary (the other icons will be managed in response to
3869 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003870 if (!DISABLE_MARKET_BUTTON) {
3871 updateAppMarketIcon();
3872 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003873
Winson Chungf0c6ae02012-03-21 16:10:31 -07003874 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003875 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003876 mWorkspace.getUniqueComponents(true, null);
3877 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003878 }
Adam Cohen99894d92013-06-14 11:22:59 -07003879
Adam Cohen66a01fd2013-06-11 12:48:00 -07003880 mWorkspace.post(new Runnable() {
3881 @Override
3882 public void run() {
3883 onFinishBindingItems();
3884 }
3885 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003886 }
3887
Winson Chunga0b7e862013-09-05 16:03:15 -07003888 public boolean isAllAppsButtonRank(int rank) {
3889 if (mHotseat != null) {
3890 return mHotseat.isAllAppsButtonRank(rank);
3891 }
3892 return false;
3893 }
3894
Winson Chunga2413752012-04-03 14:22:34 -07003895 private boolean canRunNewAppsAnimation() {
3896 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3897 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3898 }
3899
Winson Chungc9168342013-06-26 14:54:55 -07003900 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3901 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3902 PropertyValuesHolder.ofFloat("alpha", 1f),
3903 PropertyValuesHolder.ofFloat("scaleX", 1f),
3904 PropertyValuesHolder.ofFloat("scaleY", 1f));
3905 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3906 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3907 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3908 return bounceAnim;
3909 }
3910
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003911 @Override
3912 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003913 boolean searchVisible = updateGlobalSearchIcon();
3914 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003915 if (mSearchDropTargetBar != null) {
3916 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3917 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003918 }
3919
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003920 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003921 * Add the icons for all apps.
3922 *
3923 * Implementation of the method from LauncherModel.Callbacks.
3924 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003925 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003926 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3927 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3928 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3929 getHotseat().addAllAppsFolder(mIconCache, apps,
3930 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3931 }
3932 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003933 }
Winson Chungc58497e2013-09-03 17:48:37 -07003934 } else {
3935 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3936 mAppsCustomizeContent != null) {
3937 mAppsCustomizeContent.setApps(apps);
3938 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003939 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003940 }
3941
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003942 @Override
3943 public boolean shouldShowApp(ResolveInfo app) {
3944 return true;
3945 }
3946
Joe Onorato9c1289c2009-08-17 11:03:03 -04003947 /**
3948 * A package was updated.
3949 *
3950 * Implementation of the method from LauncherModel.Callbacks.
3951 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003952 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003953 Runnable r = new Runnable() {
3954 public void run() {
3955 bindAppsUpdated(apps);
3956 }
3957 };
3958 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003959 return;
3960 }
3961
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003962 if (mWorkspace != null) {
3963 mWorkspace.updateShortcuts(apps);
3964 }
Winson Chungc58497e2013-09-03 17:48:37 -07003965
3966 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3967 mAppsCustomizeContent != null) {
3968 mAppsCustomizeContent.updateApps(apps);
3969 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003970 }
3971
3972 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003973 * A package was uninstalled. We take both the super set of packageNames
3974 * in addition to specific applications to remove, the reason being that
3975 * this can be called when a package is updated as well. In that scenario,
3976 * we only remove specific components from the workspace, where as
3977 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003978 *
3979 * Implementation of the method from LauncherModel.Callbacks.
3980 */
Winson Chung83892cc2013-05-01 16:53:33 -07003981 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003982 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003983 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003984 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003985 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003986 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003987 }
Winson Chungd64d1762013-08-20 14:37:16 -07003988 };
3989 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003990 return;
3991 }
3992
Winson Chung64359a52013-07-08 17:17:08 -07003993 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003994 mWorkspace.removeItemsByPackageName(packageNames);
3995 } else {
3996 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003997 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003998
Winson Chunga1820962011-10-03 16:31:06 -07003999 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07004000 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07004001
4002 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4003 mAppsCustomizeContent != null) {
4004 mAppsCustomizeContent.removeApps(appInfos);
4005 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004006 }
Joe Onoratobe386092009-11-17 17:32:16 -08004007
4008 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004009 * A number of packages were updated.
4010 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004011 private ArrayList<Object> mWidgetsAndShortcuts;
4012 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004013 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004014 bindPackagesUpdated(mWidgetsAndShortcuts);
4015 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004016 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004017 };
4018
4019 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4020 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4021 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004022 return;
4023 }
4024
Winson Chung64359a52013-07-08 17:17:08 -07004025 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07004026 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4027 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004028 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004029 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004030 }
4031
Winson Chung400438b2011-01-16 17:53:48 -08004032 private int mapConfigurationOriActivityInfoOri(int configOri) {
4033 final Display d = getWindowManager().getDefaultDisplay();
4034 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4035 switch (d.getRotation()) {
4036 case Surface.ROTATION_0:
4037 case Surface.ROTATION_180:
4038 // We are currently in the same basic orientation as the natural orientation
4039 naturalOri = configOri;
4040 break;
4041 case Surface.ROTATION_90:
4042 case Surface.ROTATION_270:
4043 // We are currently in the other basic orientation to the natural orientation
4044 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4045 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4046 break;
4047 }
4048
4049 int[] oriMap = {
4050 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4051 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4052 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4053 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4054 };
4055 // Since the map starts at portrait, we need to offset if this device's natural orientation
4056 // is landscape.
4057 int indexOffset = 0;
4058 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4059 indexOffset = 1;
4060 }
4061 return oriMap[(d.getRotation() + indexOffset) % 4];
4062 }
Adam Cohen446e9402011-09-15 18:21:21 -07004063
Winson Chung4b919f82012-05-01 10:44:08 -07004064 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004065 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004066 getResources().getBoolean(R.bool.allow_rotation);
4067 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004068 }
Winson Chung4b919f82012-05-01 10:44:08 -07004069 public void lockScreenOrientation() {
4070 if (isRotationEnabled()) {
4071 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4072 .getConfiguration().orientation));
4073 }
4074 }
4075 public void unlockScreenOrientation(boolean immediate) {
4076 if (isRotationEnabled()) {
4077 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004078 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004079 } else {
4080 mHandler.postDelayed(new Runnable() {
4081 public void run() {
4082 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4083 }
4084 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004085 }
Winson Chung4b919f82012-05-01 10:44:08 -07004086 }
Winson Chung400438b2011-01-16 17:53:48 -08004087 }
4088
Winson Chung82f55532011-08-09 14:14:23 -07004089 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004090 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004091 if (DISABLE_CLINGS) {
4092 return false;
4093 }
4094
Brett Chabot2a9e2282011-08-23 15:03:13 -07004095 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004096 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004097
Michael Jurkae233a8b2013-03-19 13:49:20 +01004098 // Restricted secondary users (child mode) will potentially have very few apps
4099 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004100// boolean supportsLimitedUsers =
4101// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4102// Account[] accounts = AccountManager.get(this).getAccounts();
4103// if (supportsLimitedUsers && accounts.length == 0) {
4104// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4105// Bundle restrictions = um.getUserRestrictions();
4106// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4107// return false;
4108// }
4109// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004110 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004111 }
Michael Jurka22143132012-10-04 17:42:38 +02004112
Winson Chungfa545132013-09-26 17:45:32 -07004113 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004114 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004115 Cling cling = (Cling) findViewById(clingId);
4116 View scrim = null;
4117 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004118 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004119 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004120 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004121 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004122 cling.show(animate, SHOW_CLING_DURATION);
4123
4124 if (dimNavBarVisibilty) {
4125 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4126 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004127 }
4128 }
4129 return cling;
4130 }
Michael Jurka22143132012-10-04 17:42:38 +02004131
Winson Chungaf40f202013-09-18 18:26:31 -07004132 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4133 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004134 // To catch cases where siblings of top-level views are made invisible, just check whether
4135 // the cling is directly set to GONE before dismissing it.
4136 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004137 final Runnable cleanUpClingCb = new Runnable() {
4138 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004139 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004140 // We should update the shared preferences on a background thread
4141 new Thread("dismissClingThread") {
4142 public void run() {
4143 SharedPreferences.Editor editor = mSharedPrefs.edit();
4144 editor.putBoolean(flag, true);
4145 editor.commit();
4146 }
4147 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004148 if (postAnimationCb != null) {
4149 postAnimationCb.run();
4150 }
4151 }
4152 };
4153 if (duration <= 0) {
4154 cleanUpClingCb.run();
4155 } else {
4156 cling.hide(duration, cleanUpClingCb);
4157 }
Michael Jurka22143132012-10-04 17:42:38 +02004158 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004159
4160 if (restoreNavBarVisibilty) {
4161 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4162 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4163 }
Winson Chung82f55532011-08-09 14:14:23 -07004164 }
4165 }
Michael Jurka22143132012-10-04 17:42:38 +02004166
Winson Chung9d9d74f2011-09-19 11:49:12 -07004167 private void removeCling(int id) {
4168 final View cling = findViewById(id);
4169 if (cling != null) {
4170 final ViewGroup parent = (ViewGroup) cling.getParent();
4171 parent.post(new Runnable() {
4172 @Override
4173 public void run() {
4174 parent.removeView(cling);
4175 }
4176 });
Michael Jurka22143132012-10-04 17:42:38 +02004177 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004178 }
4179 }
Michael Jurka974c3862012-05-22 22:00:31 -07004180
4181 private boolean skipCustomClingIfNoAccounts() {
4182 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4183 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4184 if (customCling) {
4185 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004186 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004187 Account[] accounts = am.getAccountsByType("com.google");
4188 return accounts.length == 0;
4189 }
4190 return false;
4191 }
4192
Winson Chungaf40f202013-09-18 18:26:31 -07004193 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004194 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004195 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004196 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004197 // If we're not using the default workspace layout, replace workspace cling
4198 // with a custom workspace cling (usually specified in an overlay)
4199 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004200 if (!DISABLE_CUSTOM_CLINGS) {
4201 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4202 getResources().getBoolean(R.bool.config_useCustomClings)) {
4203 // Use a custom cling
4204 View cling = findViewById(R.id.workspace_cling);
4205 ViewGroup clingParent = (ViewGroup) cling.getParent();
4206 int clingIndex = clingParent.indexOfChild(cling);
4207 clingParent.removeViewAt(clingIndex);
4208 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4209 clingParent.addView(customCling, clingIndex);
4210 customCling.setId(R.id.workspace_cling);
4211 }
4212 }
4213 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4214 if (cling != null) {
4215 String sbHintStr = getFirstRunClingSearchBarHint();
4216 String ccHintStr = getFirstRunCustomContentHint();
4217 if (!sbHintStr.isEmpty()) {
4218 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4219 sbHint.setText(sbHintStr);
4220 sbHint.setVisibility(View.VISIBLE);
4221 }
4222 if (!ccHintStr.isEmpty()) {
4223 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4224 ccHint.setText(ccHintStr);
4225 ccHint.setVisibility(View.VISIBLE);
4226 }
Michael Jurka45355c42012-10-08 13:21:35 +02004227 }
Winson Chungfa545132013-09-26 17:45:32 -07004228 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004229 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004230 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004231 }
4232 }
Winson Chungaf40f202013-09-18 18:26:31 -07004233
Winson Chunge6eabff2013-09-24 11:01:23 -07004234 protected String getFirstRunClingSearchBarHint() {
4235 return "";
4236 }
4237 protected String getFirstRunCustomContentHint() {
4238 return "";
4239 }
4240
Winson Chungaf40f202013-09-18 18:26:31 -07004241 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004242 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004243 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004244 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004245 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004246 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004247 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004248 }
4249 }
4250 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004251 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004252 if (isClingsEnabled() &&
4253 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004254 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4255 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004256 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004257 } else {
4258 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004259 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004260 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004261 }
Michael Jurka104c4562013-07-08 18:03:46 -07004262 protected SharedPreferences getSharedPrefs() {
4263 return mSharedPrefs;
4264 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004265 public boolean isFolderClingVisible() {
4266 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004267 if (cling != null) {
4268 return cling.getVisibility() == View.VISIBLE;
4269 }
4270 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004271 }
Winson Chungaf40f202013-09-18 18:26:31 -07004272 public void dismissFirstRunCling(View v) {
4273 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4274 Runnable cb = new Runnable() {
4275 public void run() {
4276 // Show the workspace cling next
4277 showFirstRunWorkspaceCling();
4278 }
4279 };
4280 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4281 DISMISS_CLING_DURATION, false);
4282 }
Winson Chung82f55532011-08-09 14:14:23 -07004283 public void dismissWorkspaceCling(View v) {
4284 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004285 Runnable cb = null;
4286 if (v == null) {
4287 cb = new Runnable() {
4288 public void run() {
4289 mWorkspace.enterOverviewMode();
4290 }
4291 };
4292 }
4293 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4294 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004295 }
4296 public void dismissFolderCling(View v) {
4297 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004298 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4299 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004300 }
4301
Winson Chung80baf5a2010-08-09 16:03:15 -07004302 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004303 * Prints out out state for debugging.
4304 */
4305 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004306 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004307 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004308 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4309 Log.d(TAG, "mRestoring=" + mRestoring);
4310 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4311 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004312 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004313 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004314
Winson Chung785d2eb2011-04-14 16:08:02 -07004315 if (mAppsCustomizeContent != null) {
4316 mAppsCustomizeContent.dumpState();
4317 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004318 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004319 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004320
4321 @Override
4322 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4323 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004324 synchronized (sDumpLogs) {
4325 writer.println(" ");
4326 writer.println("Debug logs: ");
4327 for (int i = 0; i < sDumpLogs.size(); i++) {
4328 writer.println(" " + sDumpLogs.get(i));
4329 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004330 }
4331 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004332
4333 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004334 if (DEBUG_DUMP_LOG) {
4335 synchronized (sDumpLogs) {
4336 Log.d(TAG, "");
4337 Log.d(TAG, "*********************");
4338 Log.d(TAG, "Launcher debug logs: ");
4339 for (int i = 0; i < sDumpLogs.size(); i++) {
4340 Log.d(TAG, " " + sDumpLogs.get(i));
4341 }
4342 Log.d(TAG, "*********************");
4343 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004344 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004345 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004346 }
4347
4348 public static void addDumpLog(String tag, String log, boolean debugLog) {
4349 if (debugLog) {
4350 Log.d(tag, log);
4351 }
Winson Chungede41292013-09-19 16:27:36 -07004352 if (DEBUG_DUMP_LOG) {
4353 sDateStamp.setTime(System.currentTimeMillis());
4354 synchronized (sDumpLogs) {
4355 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004356 }
Winson Chungede41292013-09-19 16:27:36 -07004357 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004358 }
4359
Winson Chungede41292013-09-19 16:27:36 -07004360 public void dumpLogsToLocalData() {
4361 if (DEBUG_DUMP_LOG) {
4362 new Thread("DumpLogsToLocalData") {
4363 @Override
4364 public void run() {
4365 boolean success = false;
4366 sDateStamp.setTime(sRunStart);
4367 String FILENAME = sDateStamp.getMonth() + "-"
4368 + sDateStamp.getDay() + "_"
4369 + sDateStamp.getHours() + "-"
4370 + sDateStamp.getMinutes() + "_"
4371 + sDateStamp.getSeconds() + ".txt";
4372
4373 FileOutputStream fos = null;
4374 File outFile = null;
4375 try {
4376 outFile = new File(getFilesDir(), FILENAME);
4377 outFile.createNewFile();
4378 fos = new FileOutputStream(outFile);
4379 } catch (Exception e) {
4380 e.printStackTrace();
4381 }
4382 if (fos != null) {
4383 PrintWriter writer = new PrintWriter(fos);
4384
4385 writer.println(" ");
4386 writer.println("Debug logs: ");
4387 synchronized (sDumpLogs) {
4388 for (int i = 0; i < sDumpLogs.size(); i++) {
4389 writer.println(" " + sDumpLogs.get(i));
4390 }
4391 }
4392 writer.close();
4393 }
4394 try {
4395 if (fos != null) {
4396 fos.close();
4397 success = true;
4398 }
4399 } catch (IOException e) {
4400 e.printStackTrace();
4401 }
4402 }
4403 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004404 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004405 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004406}
Michael Jurka2763be32011-02-24 11:19:57 -08004407
Michael Jurkaabded662011-03-04 12:06:57 -08004408interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004409 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004410 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004411 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004412 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004413 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004414}