blob: cfa55451369df463aa4c37ec8896768f090f85ec [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;
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -070090import android.view.accessibility.AccessibilityManager;
Adam Cohencff6af82011-09-13 14:51:53 -070091import android.view.animation.AccelerateDecelerateInterpolator;
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 Cohenc0dcf592011-06-01 15:30:43 -0700106import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700107import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700108import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700109import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700112import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700115import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700116
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117/**
118 * Default launcher application.
119 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100120public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700121 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700122 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800123 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700124 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
Daniel Sandlerf061f822013-06-27 13:59:36 -0400126 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400127 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700128 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700130 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700131
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700133 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134 private static final int REQUEST_PICK_APPLICATION = 6;
135 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700137 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138
Michael Jurka8b805b12012-04-18 14:23:14 -0700139 private static final int REQUEST_BIND_APPWIDGET = 11;
140
Mathew Inwood876a8462013-06-14 14:12:41 +0100141 /**
142 * IntentStarter uses request codes starting with this. This must be greater than all activity
143 * request codes used internally.
144 */
145 protected static final int REQUEST_LAST = 100;
146
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
148
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800149 static final int SCREEN_COUNT = 5;
150 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151
Romain Guy98d01652009-06-30 16:21:04 -0700152 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800153 // To turn on these properties, type
154 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
155 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
156 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157
Winson Chung2672ff92012-05-04 16:22:30 -0700158 // The Intent extra that defines whether to ignore the launch animation
159 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400160 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700161
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 // Type: int
163 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700164 // Type: int
165 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700167 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
168 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
170 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700171 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700173 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 // Type: boolean
175 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
176 // Type: long
177 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700178 // Type: int
179 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
180 // Type: int
181 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
182 // Type: parcelable
183 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100185 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700186 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100187 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700188 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100189 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700190
Adam Cohen39a06042013-07-19 14:30:12 -0700191 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700192 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700193
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700194 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700195 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700196 private State mState = State.WORKSPACE;
197 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700198
Joe Onorato9c1289c2009-08-17 11:03:03 -0400199 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700200 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
201 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700202 private static final int SHOW_CLING_DURATION = 250;
203 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800206 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
Winson Chunga2413752012-04-03 14:22:34 -0700208 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700209 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
210 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700211 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700212
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800213 private final BroadcastReceiver mCloseSystemDialogsReceiver
214 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800215 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
216
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217 private LayoutInflater mInflater;
218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700220 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800221 private DragLayer mDragLayer;
222 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700223 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700224
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700225 private AppWidgetManager mAppWidgetManager;
226 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700227
Michael Jurkac9d95c52011-08-29 14:03:34 -0700228 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700229 private AppWidgetProviderInfo mPendingAddWidgetInfo;
230
Michael Jurka0280c3b2010-09-17 15:00:07 -0700231 private int[] mTmpAddItemCellCoordinates = new int[2];
232
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800233 private FolderInfo mFolderInfo;
234
Winson Chung3d503fb2011-07-13 17:25:49 -0700235 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700236 private View mOverviewPanel;
237
Michael Jurka838a4ca2011-02-07 13:33:06 -0800238 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700239
Winson Chungc51db6a2011-10-05 11:44:49 -0700240 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700241 private AppsCustomizeTabHost mAppsCustomizeTabHost;
242 private AppsCustomizePagedView mAppsCustomizeContent;
243 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100244 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800245
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700247 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
248 // scroll issues (because the workspace may not have been measured yet) and extra work.
249 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
250 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251
252 private SpannableStringBuilder mDefaultKeySsb = null;
253
Joe Onorato9c1289c2009-08-17 11:03:03 -0400254 private boolean mWorkspaceLoading = true;
255
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800256 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257 private boolean mRestoring;
258 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700259 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260
Michael Jurka1e2f4652013-07-08 18:03:46 -0700261 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700262 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
263
Winson Chung4a2afa32012-07-19 14:53:05 -0700264 // Keep track of whether the user has left launcher
265 private static boolean sPausedFromUserAction = false;
266
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 private Bundle mSavedInstanceState;
268
Joe Onorato9c1289c2009-08-17 11:03:03 -0400269 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800270 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800271 private boolean mUserPresent = true;
272 private boolean mVisible = false;
273 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700274 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700275 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400276
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700277 private static LocaleConfiguration sLocaleConfiguration = null;
278
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700279 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700280
Adam Cohen61f560d2013-09-30 15:58:20 -0700281 private View.OnTouchListener mHapticFeedbackTouchListener;
282
Adam Cohended9f8d2010-11-03 13:25:16 -0700283 // Related to the auto-advancing of widgets
284 private final int ADVANCE_MSG = 1;
285 private final int mAdvanceInterval = 20000;
286 private final int mAdvanceStagger = 250;
287 private long mAutoAdvanceSentTime;
288 private long mAutoAdvanceTimeLeft = -1;
289 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
290 new HashMap<View, AppWidgetProviderInfo>();
291
Winson Chung400438b2011-01-16 17:53:48 -0800292 // Determines how long to wait after a rotation before restoring the screen orientation to
293 // match the sensor state.
294 private final int mRestoreScreenOrientationDelay = 500;
295
Michael Jurka4ef207b2010-11-29 17:05:45 -0800296 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700297 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
298 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
299 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800300
Winson Chungd64a6662013-09-30 11:06:59 -0700301 private Intent mAppMarketIntent = null;
302 private static final boolean DISABLE_MARKET_BUTTON = true;
303
Craig Mautner360310b2012-10-26 15:13:08 -0700304 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700305
Adam Cohen1462de32012-07-24 22:34:36 -0700306 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
307
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700308 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700309 static Date sDateStamp = new Date();
310 static DateFormat sDateFormat =
311 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
312 static long sRunStart = System.currentTimeMillis();
313 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700314
Winson Chung46353de2012-02-16 14:05:10 -0800315 // We only want to get the SharedPreferences once since it does an FS stat each time we get
316 // it from the context.
317 private SharedPreferences mSharedPrefs;
318
Adam Cohene25af792013-06-06 23:08:25 -0700319 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
320
Winson Chungf0c6ae02012-03-21 16:10:31 -0700321 // Holds the page that we need to animate to, and the icon views that we need to animate up
322 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700323 private ImageView mFolderIconImageView;
324 private Bitmap mFolderIconBitmap;
325 private Canvas mFolderIconCanvas;
326 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700327
Michael Jurkaddd62e92011-02-16 17:49:14 -0800328 private BubbleTextView mWaitingForResume;
329
John Spurlockd4507ee2013-10-04 14:38:05 -0400330 protected TranslucentDecor mTransparentDecor;
Michael Jurka7267fa52013-09-26 15:29:57 -0700331
Michael Jurka22143132012-10-04 17:42:38 +0200332 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
333 = new HideFromAccessibilityHelper();
334
Michael Jurkac1f5d262011-09-30 19:32:27 -0700335 private Runnable mBuildLayersRunnable = new Runnable() {
336 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700337 if (mWorkspace != null) {
338 mWorkspace.buildPageHardwareLayers();
339 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700340 }
341 };
342
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800343 private static ArrayList<PendingAddArguments> sPendingAddList
344 = new ArrayList<PendingAddArguments>();
345
Michael Jurka7267fa52013-09-26 15:29:57 -0700346 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800347
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800348 private static class PendingAddArguments {
349 int requestCode;
350 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700351 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700352 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800353 int cellX;
354 int cellY;
355 }
356
Daniel Sandlerff02d492013-08-05 02:12:05 -0400357 private Stats mStats;
358
Michael Jurka0a457bf2012-11-19 14:05:05 -0800359 private static boolean isPropertyEnabled(String propertyName) {
360 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700361 }
362
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800363 @Override
364 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700365 if (DEBUG_STRICT_MODE) {
366 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
367 .detectDiskReads()
368 .detectDiskWrites()
369 .detectNetwork() // or .detectAll() for all detectable problems
370 .penaltyLog()
371 .build());
372 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
373 .detectLeakedSqlLiteObjects()
374 .detectLeakedClosableObjects()
375 .penaltyLog()
376 .penaltyDeath()
377 .build());
378 }
379
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400381
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400382 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400383 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700384
385 // Determine the dynamic grid properties
386 Point smallestSize = new Point();
387 Point largestSize = new Point();
388 Point realSize = new Point();
389 Display display = getWindowManager().getDefaultDisplay();
390 display.getCurrentSizeRange(smallestSize, largestSize);
391 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700392 DisplayMetrics dm = new DisplayMetrics();
393 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700394 // Lazy-initialize the dynamic grid
395 DeviceProfile grid = app.initDynamicGrid(this,
396 Math.min(smallestSize.x, smallestSize.y),
397 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700398 realSize.x, realSize.y,
399 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700400
401 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400402 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700403 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800404 mModel = app.setLauncher(this);
405 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400406 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700408
Daniel Sandlerff02d492013-08-05 02:12:05 -0400409 mStats = new Stats(this);
410
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700411 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700412
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
Adam Cohen53805212013-10-01 10:39:23 -0700426
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700429
John Spurlockd4507ee2013-10-04 14:38:05 -0400430 mTransparentDecor = new TranslucentDecor(findViewById(R.id.launcher));
431 mTransparentDecor.requestTranslucentDecor(true);
Michael Jurka7267fa52013-09-26 15:29:57 -0700432
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100434 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800436 registerContentObservers();
437
Joe Onorato7c312c12009-08-13 21:36:53 -0700438 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700439
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 mSavedState = savedInstanceState;
441 restoreState(mSavedState);
442
Winson Chunga12a2502010-12-20 14:41:35 -0800443 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700444 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200445 mAppsCustomizeContent.onPackagesUpdated(
446 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700447 }
Winson Chunga12a2502010-12-20 14:41:35 -0800448
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 if (PROFILE_STARTUP) {
450 android.os.Debug.stopMethodTracing();
451 }
452
453 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700454 if (sPausedFromUserAction) {
455 // If the user leaves launcher, then we should just load items asynchronously when
456 // they return.
457 mModel.startLoader(true, -1);
458 } else {
459 // We only load the page synchronously if the user rotates (or triggers a
460 // configuration change) while launcher is in the foreground
461 mModel.startLoader(true, mWorkspace.getCurrentPage());
462 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800463 }
464
465 // For handling default keys
466 mDefaultKeySsb = new SpannableStringBuilder();
467 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800468
469 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
470 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800471
Adam Cohenf9426d52012-06-04 17:26:21 -0700472 updateGlobalIcons();
473
474 // On large interfaces, we want the screen to auto-rotate based on the current orientation
475 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700476
477 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700478 }
479
Winson Chung4a2afa32012-07-19 14:53:05 -0700480 protected void onUserLeaveHint() {
481 super.onUserLeaveHint();
482 sPausedFromUserAction = true;
483 }
484
Winson Chung98ca0f72013-07-29 12:58:51 -0700485 /** To be overriden by subclasses to hint to Launcher that we have custom content */
486 protected boolean hasCustomContentToLeft() {
487 return false;
488 }
489
Dave Hawkeya8881582013-09-17 15:55:33 -0600490 /**
491 * To be overridden by subclasses to create the custom content and call
492 * {@link #addToCustomContentPage}. This will only be invoked if
493 * {@link #hasCustomContentToLeft()} is {@code true}.
494 */
495 protected void addCustomContentToLeft() {
496 }
497
498 /**
499 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
500 * ensure the custom content page is added or removed if necessary.
501 */
502 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600503 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600504 // Not bound yet, wait for bindScreens to be called.
505 return;
506 }
507
508 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
509 // Create the custom content page and call the subclass to populate it.
510 mWorkspace.createCustomContentPage();
511 addCustomContentToLeft();
512 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
513 mWorkspace.removeCustomContentPage();
514 }
515 }
516
Adam Cohenf9426d52012-06-04 17:26:21 -0700517 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700518 boolean searchVisible = false;
519 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800520 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700521 int coi = getCurrentOrientationIndexForGlobalIcons();
522 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
523 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700524 if (!DISABLE_MARKET_BUTTON) {
525 updateAppMarketIcon();
526 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700527 searchVisible = updateGlobalSearchIcon();
528 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700529 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700530 if (sGlobalSearchIcon[coi] != null) {
531 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700532 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700533 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700534 if (sVoiceSearchIcon[coi] != null) {
535 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700536 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700537 }
Winson Chungd64a6662013-09-30 11:06:59 -0700538 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700539 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800540 }
Winson Chungadf0c182012-08-23 14:59:07 -0700541 if (mSearchDropTargetBar != null) {
542 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
543 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800544 }
Romain Guycbb89e42009-06-08 15:52:54 -0700545
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800546 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700547 if (sLocaleConfiguration == null) {
548 new AsyncTask<Void, Void, LocaleConfiguration>() {
549 @Override
550 protected LocaleConfiguration doInBackground(Void... unused) {
551 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
552 readConfiguration(Launcher.this, localeConfiguration);
553 return localeConfiguration;
554 }
555
556 @Override
557 protected void onPostExecute(LocaleConfiguration result) {
558 sLocaleConfiguration = result;
559 checkForLocaleChange(); // recursive, but now with a locale configuration
560 }
561 }.execute();
562 return;
563 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700564
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800565 final Configuration configuration = getResources().getConfiguration();
566
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700567 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800568 final String locale = configuration.locale.toString();
569
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700570 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800571 final int mcc = configuration.mcc;
572
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700573 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800574 final int mnc = configuration.mnc;
575
Romain Guy84f296c2009-11-04 15:00:44 -0800576 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577
Romain Guy84f296c2009-11-04 15:00:44 -0800578 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700579 sLocaleConfiguration.locale = locale;
580 sLocaleConfiguration.mcc = mcc;
581 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700582
Joe Onorato0589f0f2010-02-08 13:44:00 -0800583 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700584
585 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
586 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700587 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700588 public void run() {
589 writeConfiguration(Launcher.this, localeConfiguration);
590 }
591 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700592 }
593 }
594
595 private static class LocaleConfiguration {
596 public String locale;
597 public int mcc = -1;
598 public int mnc = -1;
599 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700600
Romain Guy98d01652009-06-30 16:21:04 -0700601 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
602 DataInputStream in = null;
603 try {
604 in = new DataInputStream(context.openFileInput(PREFERENCES));
605 configuration.locale = in.readUTF();
606 configuration.mcc = in.readInt();
607 configuration.mnc = in.readInt();
608 } catch (FileNotFoundException e) {
609 // Ignore
610 } catch (IOException e) {
611 // Ignore
612 } finally {
613 if (in != null) {
614 try {
615 in.close();
616 } catch (IOException e) {
617 // Ignore
618 }
619 }
620 }
621 }
622
623 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
624 DataOutputStream out = null;
625 try {
626 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
627 out.writeUTF(configuration.locale);
628 out.writeInt(configuration.mcc);
629 out.writeInt(configuration.mnc);
630 out.flush();
631 } catch (FileNotFoundException e) {
632 // Ignore
633 } catch (IOException e) {
634 //noinspection ResultOfMethodCallIgnored
635 context.getFileStreamPath(PREFERENCES).delete();
636 } finally {
637 if (out != null) {
638 try {
639 out.close();
640 } catch (IOException e) {
641 // Ignore
642 }
643 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800644 }
645 }
646
Anton Hanssona2f665f2013-09-26 12:18:32 +0100647 public Stats getStats() {
648 return mStats;
649 }
650
Bjorn Bringertc459e522013-06-07 19:36:01 +0100651 public LayoutInflater getInflater() {
652 return mInflater;
653 }
654
Adam Cohen716b51e2011-06-30 12:09:54 -0700655 public DragLayer getDragLayer() {
656 return mDragLayer;
657 }
658
Winson Chung36a62fe2012-05-06 18:04:42 -0700659 boolean isDraggingEnabled() {
660 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
661 // that is subsequently removed from the workspace in startBinding().
662 return !mModel.isLoadingWorkspace();
663 }
664
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800665 static int getScreen() {
666 synchronized (sLock) {
667 return sScreen;
668 }
669 }
670
671 static void setScreen(int screen) {
672 synchronized (sLock) {
673 sScreen = screen;
674 }
675 }
676
Winson Chung557d6ed2011-07-08 15:34:52 -0700677 /**
678 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
679 * a configuration step, this allows the proper animations to run after other transitions.
680 */
681 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700682 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800683 switch (args.requestCode) {
684 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700685 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700686 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800687 break;
688 case REQUEST_PICK_SHORTCUT:
689 processShortcut(args.intent);
690 break;
691 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700692 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700693 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700694 result = true;
695 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800696 case REQUEST_CREATE_APPWIDGET:
697 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700698 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700699 result = true;
700 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800701 }
Michael Jurka27614d22012-04-02 06:40:22 -0700702 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
703 // if you turned the screen off and then back while in All Apps, Launcher would not
704 // return to the workspace. Clearing mAddInfo.container here fixes this issue
705 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700706 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800707 }
708
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800709 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700710 protected void onActivityResult(
711 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700712 // Reset the startActivity waiting flag
713 mWaitingForResult = false;
714
Michael Jurka8b805b12012-04-18 14:23:14 -0700715 if (requestCode == REQUEST_BIND_APPWIDGET) {
716 int appWidgetId = data != null ?
717 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
718 if (resultCode == RESULT_CANCELED) {
719 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
720 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700721 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700722 }
723 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200724 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
725 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
726 mWorkspace.exitOverviewMode(false);
727 }
728 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700729 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200730
Winson Chung557d6ed2011-07-08 15:34:52 -0700731 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800732 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
733 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700734
Adam Cohened66b2b2012-01-23 17:28:51 -0800735 // We have special handling for widgets
736 if (isWidgetDrop) {
737 int appWidgetId = data != null ?
738 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700739 if (appWidgetId < 0) {
740 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
741 "widget configuration activity.");
742 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
743 } else {
744 completeTwoStageWidgetDrop(resultCode, appWidgetId);
745 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800746 return;
747 }
748
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800749 // The pattern used here is that a user PICKs a specific application,
750 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700751
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800752 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
753 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700754 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800755 final PendingAddArguments args = new PendingAddArguments();
756 args.requestCode = requestCode;
757 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700758 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700759 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700760 args.cellX = mPendingAddInfo.cellX;
761 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800762 if (isWorkspaceLocked()) {
763 sPendingAddList.add(args);
764 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700765 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800766 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800767 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800768 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700769 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800770 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
771 null);
772 }
773
774 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700775 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700776 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800777 Runnable onCompleteRunnable = null;
778 int animationType = 0;
779
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700780 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800781 if (resultCode == RESULT_OK) {
782 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
783 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700784 mPendingAddWidgetInfo);
785 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800786 onCompleteRunnable = new Runnable() {
787 @Override
788 public void run() {
789 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700790 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800791 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
792 null);
793 }
794 };
795 } else if (resultCode == RESULT_CANCELED) {
796 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
797 onCompleteRunnable = new Runnable() {
798 @Override
799 public void run() {
800 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
801 null);
802 }
803 };
804 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700805 if (mDragLayer.getAnimatedView() != null) {
806 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
807 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
808 animationType, boundWidget, true);
809 } else {
810 // The animated view may be null in the case of a rotation during widget configuration
811 onCompleteRunnable.run();
812 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800813 }
814
815 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700816 protected void onStop() {
817 super.onStop();
818 FirstFrameAnimatorHelper.setIsVisible(false);
819 }
820
821 @Override
822 protected void onStart() {
823 super.onStart();
824 FirstFrameAnimatorHelper.setIsVisible(true);
825 }
826
827 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800828 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200829 long startTime = 0;
830 if (DEBUG_RESUME_TIME) {
831 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400832 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200833 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800834 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700835
Winson Chung4a2afa32012-07-19 14:53:05 -0700836 // Restore the previous launcher state
837 if (mOnResumeState == State.WORKSPACE) {
838 showWorkspace(false);
839 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700840 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700841 }
842 mOnResumeState = State.NONE;
843
Craig Mautner360310b2012-10-26 15:13:08 -0700844 // Background was set to gradient in onPause(), restore to black if in all apps.
845 setWorkspaceBackground(mState == State.WORKSPACE);
846
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800847 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700848 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700849 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400850 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700851 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400852 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700853 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700855 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200856 // We might have postponed some bind calls until onResume (see waitUntilResume) --
857 // execute them here
858 long startTimeCallbacks = 0;
859 if (DEBUG_RESUME_TIME) {
860 startTimeCallbacks = System.currentTimeMillis();
861 }
862
863 if (mAppsCustomizeContent != null) {
864 mAppsCustomizeContent.setBulkBind(true);
865 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700866 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
867 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200868 }
869 if (mAppsCustomizeContent != null) {
870 mAppsCustomizeContent.setBulkBind(false);
871 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700872 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200873 if (DEBUG_RESUME_TIME) {
874 Log.d(TAG, "Time spent processing callbacks in onResume: " +
875 (System.currentTimeMillis() - startTimeCallbacks));
876 }
Michael Jurka447bf842013-05-15 14:52:15 +0200877 }
Michael Jurka54554252013-08-01 12:52:23 +0200878 if (mOnResumeCallbacks.size() > 0) {
879 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
880 mOnResumeCallbacks.get(i).run();
881 }
882 mOnResumeCallbacks.clear();
883 }
Winson Chunge4e50662012-01-23 14:45:13 -0800884
885 // Reset the pressed state of icons that were locked in the press state while activities
886 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800887 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800888 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800889 mWaitingForResume.setStayPressed(false);
890 }
Winson Chunge4e50662012-01-23 14:45:13 -0800891 if (mAppsCustomizeContent != null) {
892 // Resets the previous all apps icon press state
893 mAppsCustomizeContent.resetDrawableState();
894 }
Winson Chung780fe592013-09-26 14:48:44 -0700895 // Reset AllApps to its initial state
896 if (mAppsCustomizeTabHost != null) {
897 mAppsCustomizeTabHost.reset();
898 }
Adam Cohen06dff352012-06-01 17:17:08 -0700899 // It is possible that widgets can receive updates while launcher is not in the foreground.
900 // Consequently, the widgets will be inflated in the orientation of the foreground activity
901 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
902 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700903 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700904
Winson Chung780fe592013-09-26 14:48:44 -0700905 // Process any items that were added while Launcher was away.
906 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
907
Winson Chung5841efa2013-09-30 18:06:44 -0700908 // Update the voice search button proxy
909 updateVoiceButtonProxyVisible(false);
910
Adam Cohenf9426d52012-06-04 17:26:21 -0700911 // Again, as with the above scenario, it's possible that one or more of the global icons
912 // were updated in the wrong orientation.
913 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200914 if (DEBUG_RESUME_TIME) {
915 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
916 }
Adam Cohen6fecd412013-10-02 17:41:50 -0700917
918 if (mWorkspace.getCustomContentCallbacks() != null) {
919 // If we are resuming and the custom content is the current page, we call onShow().
920 // It is also poassible that onShow will instead be called slightly after first layout
921 // if PagedView#setRestorePage was set to the custom content page in onCreate().
922 if (mWorkspace.isOnOrMovingToCustomContent()) {
923 mWorkspace.getCustomContentCallbacks().onShow();
924 }
925 }
Adam Cohenedaaa302013-10-01 17:33:27 -0700926 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -0700927 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -0700928 }
929
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800930 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700931 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700932 // Ensure that items added to Launcher are queued until Launcher returns
933 InstallShortcutReceiver.enableInstallQueue();
934
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700935 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700936 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800937 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700938 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -0700939
940 // We call onHide() aggressively. The custom content callbacks should be able to
941 // debounce excess onHide calls.
942 if (mWorkspace.getCustomContentCallbacks() != null) {
943 mWorkspace.getCustomContentCallbacks().onHide();
944 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700945 }
Romain Guycbb89e42009-06-08 15:52:54 -0700946
Adam Cohen66a01fd2013-06-11 12:48:00 -0700947 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -0700948 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600949 addCustomContentToLeft();
950 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700951 }
952
Adam Cohenbffe7452013-07-22 18:21:45 -0700953 QSBScroller mQsbScroller = new QSBScroller() {
954 int scrollY = 0;
955
956 @Override
957 public void setScrollY(int scroll) {
958 scrollY = scroll;
959
960 if (mWorkspace.isOnOrMovingToCustomContent()) {
961 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100962 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700963 }
964 }
965 };
966
967 public void resetQSBScroll() {
968 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100969 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700970 }
971
972 public interface CustomContentCallbacks {
973 // Custom content is completely shown
974 public void onShow();
975
976 // Custom content is completely hidden
977 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700978
979 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
980 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700981 }
982
Adam Cohen30bacb22013-08-29 14:25:25 -0700983 protected void startSettings() {
984 }
985
Adam Cohenbffe7452013-07-22 18:21:45 -0700986 public interface QSBScroller {
987 public void setScrollY(int scrollY);
988 }
989
Winson Chung98ca0f72013-07-29 12:58:51 -0700990 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -0700991 CustomContentCallbacks callbacks, String description) {
992 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -0700993 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700994 }
995
Adam Cohenedb40762013-07-18 16:45:45 -0700996 // The custom content needs to offset its content to account for the QSB
997 public int getTopOffsetForCustomContent() {
998 return mWorkspace.getPaddingTop();
999 }
1000
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001001 @Override
1002 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001003 // Flag the loader to stop early before switching
1004 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001005 if (mAppsCustomizeContent != null) {
1006 mAppsCustomizeContent.surrender();
1007 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001008 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001009 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001010
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001011 // We can't hide the IME if it was forced open. So don't bother
1012 /*
1013 @Override
1014 public void onWindowFocusChanged(boolean hasFocus) {
1015 super.onWindowFocusChanged(hasFocus);
1016
1017 if (hasFocus) {
1018 final InputMethodManager inputManager = (InputMethodManager)
1019 getSystemService(Context.INPUT_METHOD_SERVICE);
1020 WindowManager.LayoutParams lp = getWindow().getAttributes();
1021 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
1022 android.os.Handler()) {
1023 protected void onReceiveResult(int resultCode, Bundle resultData) {
1024 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1025 }
1026 });
1027 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1028 }
1029 }
1030 */
1031
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032 private boolean acceptFilter() {
1033 final InputMethodManager inputManager = (InputMethodManager)
1034 getSystemService(Context.INPUT_METHOD_SERVICE);
1035 return !inputManager.isFullscreenMode();
1036 }
1037
1038 @Override
1039 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001040 final int uniChar = event.getUnicodeChar();
1041 final boolean handled = super.onKeyDown(keyCode, event);
1042 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1043 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001044 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1045 keyCode, event);
1046 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001047 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001048 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001049 // showSearchDialog()
1050 // If there are multiple keystrokes before the search dialog takes focus,
1051 // onSearchRequested() will be called for every keystroke,
1052 // but it is idempotent, so it's fine.
1053 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001054 }
1055 }
1056
Joe Onorato8a9625e2010-01-28 15:55:35 -08001057 // Eat the long press event so the keyboard doesn't come up.
1058 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1059 return true;
1060 }
1061
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001062 return handled;
1063 }
1064
Karl Rosaen138a0412009-04-23 19:00:21 -07001065 private String getTypedText() {
1066 return mDefaultKeySsb.toString();
1067 }
1068
1069 private void clearTypedText() {
1070 mDefaultKeySsb.clear();
1071 mDefaultKeySsb.clearSpans();
1072 Selection.setSelection(mDefaultKeySsb, 0);
1073 }
1074
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001075 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001076 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1077 * State
1078 */
1079 private static State intToState(int stateOrdinal) {
1080 State state = State.WORKSPACE;
1081 final State[] stateValues = State.values();
1082 for (int i = 0; i < stateValues.length; i++) {
1083 if (stateValues[i].ordinal() == stateOrdinal) {
1084 state = stateValues[i];
1085 break;
1086 }
1087 }
1088 return state;
1089 }
1090
1091 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001092 * Restores the previous state, if it exists.
1093 *
1094 * @param savedState The previous state.
1095 */
1096 private void restoreState(Bundle savedState) {
1097 if (savedState == null) {
1098 return;
1099 }
1100
Michael Jurka883f55b2010-10-21 15:47:14 -07001101 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001102 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001103 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001104 }
1105
Winson Chungf0c6ae02012-03-21 16:10:31 -07001106 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001108 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001109 }
1110
Winson Chung3d503fb2011-07-13 17:25:49 -07001111 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001112 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001113
Winson Chung3d503fb2011-07-13 17:25:49 -07001114 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1115 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001116 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001117 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1118 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001119 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1120 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1121 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001122 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001123 mRestoring = true;
1124 }
1125
1126 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1127 if (renameFolder) {
1128 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001129 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130 mRestoring = true;
1131 }
Winson Chunga12a2502010-12-20 14:41:35 -08001132
Winson Chung785d2eb2011-04-14 16:08:02 -07001133 // Restore the AppsCustomize tab
1134 if (mAppsCustomizeTabHost != null) {
1135 String curTab = savedState.getString("apps_customize_currentTab");
1136 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001137 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001138 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001139 mAppsCustomizeContent.loadAssociatedPages(
1140 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001141 }
1142
Winson Chung5afbf7b2011-07-25 11:53:08 -07001143 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1144 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001145 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001146 }
1147
1148 /**
1149 * Finds all the views we need and configure them properly.
1150 */
1151 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001152 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001153
Craig Mautner360310b2012-10-26 15:13:08 -07001154 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001155 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1156 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001157
John Spurlock77e1f472013-09-11 10:09:51 -04001158 mLauncherView.setSystemUiVisibility(
1159 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001160 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161
Winson Chung4c98d922011-05-31 16:50:48 -07001162 // Setup the drag layer
1163 mDragLayer.setup(this, dragController);
1164
Winson Chung3d503fb2011-07-13 17:25:49 -07001165 // Setup the hotseat
1166 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1167 if (mHotseat != null) {
1168 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001169 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001170 }
1171
Adam Cohenf358a4b2013-07-23 16:47:31 -07001172 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001173 View widgetButton = findViewById(R.id.widget_button);
1174 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001175 @Override
1176 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001177 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001178 }
1179 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001180 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1181
1182 View wallpaperButton = findViewById(R.id.wallpaper_button);
1183 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001184 @Override
1185 public void onClick(View arg0) {
1186 startWallpaper();
1187 }
1188 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001189 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1190
1191 View settingsButton = findViewById(R.id.settings_button);
1192 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001193 @Override
1194 public void onClick(View arg0) {
1195 startSettings();
1196 }
1197 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001198 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001199 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001200
Winson Chung4c98d922011-05-31 16:50:48 -07001201 // Setup the workspace
1202 mWorkspace.setHapticFeedbackEnabled(false);
1203 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001204 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001205 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001206
Winson Chungf0ea4d32011-06-06 14:27:16 -07001207 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001208 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001209
Winson Chungf0ea4d32011-06-06 14:27:16 -07001210 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001211 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001212 mAppsCustomizeContent = (AppsCustomizePagedView)
1213 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1214 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001215
Winson Chung3d503fb2011-07-13 17:25:49 -07001216 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001217 dragController.setDragScoller(mWorkspace);
1218 dragController.setScrollView(mDragLayer);
1219 dragController.setMoveTarget(mWorkspace);
1220 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001221 if (mSearchDropTargetBar != null) {
1222 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001223 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001224
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001225 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001226 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001227 mWeightWatcher = new WeightWatcher(this);
1228 mWeightWatcher.setAlpha(0.5f);
1229 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001230 new FrameLayout.LayoutParams(
1231 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001232 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001233 Gravity.BOTTOM)
1234 );
Adam Cohen39a06042013-07-19 14:30:12 -07001235
1236 boolean show = shouldShowWeightWatcher();
1237 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001238 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 }
1240
1241 /**
1242 * Creates a view representing a shortcut.
1243 *
1244 * @param info The data structure describing the shortcut.
1245 *
1246 * @return A View inflated from R.layout.application.
1247 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001248 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001249 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001250 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 }
1252
1253 /**
1254 * Creates a view representing a shortcut inflated from the specified resource.
1255 *
1256 * @param layoutResId The id of the XML layout used to create the shortcut.
1257 * @param parent The group the shortcut belongs to.
1258 * @param info The data structure describing the shortcut.
1259 *
1260 * @return A View inflated from layoutResId.
1261 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001262 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001263 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1264 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001266 return favorite;
1267 }
1268
1269 /**
1270 * Add an application shortcut to the workspace.
1271 *
1272 * @param data The intent describing the application.
1273 * @param cellInfo The position on screen where to create the shortcut.
1274 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001275 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001276 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001277 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001278
Adam Cohenfbba09b2011-07-18 21:43:05 -07001279 // First we check if we already know the exact location where we want to add this item.
1280 if (cellX >= 0 && cellY >= 0) {
1281 cellXY[0] = cellX;
1282 cellXY[1] = cellY;
1283 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001284 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001285 return;
1286 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001287
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001288 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001289
Romain Guy73b979d2009-06-09 12:57:21 -07001290 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001291 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001292 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001293 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001294 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001295 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001296 } else {
1297 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001298 }
1299 }
Romain Guycbb89e42009-06-08 15:52:54 -07001300
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301 /**
1302 * Add a shortcut to the workspace.
1303 *
1304 * @param data The intent describing the shortcut.
1305 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001306 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001307 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001308 int cellY) {
1309 int[] cellXY = mTmpAddItemCellCoordinates;
1310 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001311 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001312
Michael Jurkad3ef3062010-11-23 16:23:58 -08001313 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001314
Adam Cohen558baaf2011-08-15 15:22:57 -07001315 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001316 if (info == null) {
1317 return;
1318 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001319 final View view = createShortcut(info);
1320
Adam Cohenfbba09b2011-07-18 21:43:05 -07001321 // First we check if we already know the exact location where we want to add this item.
1322 if (cellX >= 0 && cellY >= 0) {
1323 cellXY[0] = cellX;
1324 cellXY[1] = cellY;
1325 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001326
1327 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001328 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001329 true, null,null)) {
1330 return;
1331 }
1332 DragObject dragObject = new DragObject();
1333 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001334 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1335 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001336 return;
1337 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001338 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001339 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001340 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001341 foundCellSpan = (result != null);
1342 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001343 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001344 }
1345
1346 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001347 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001348 return;
1349 }
1350
Adam Cohendcd297f2013-06-18 13:13:40 -07001351 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001352
1353 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001354 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001355 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001356 }
1357 }
1358
Adam Cohen2f093b62012-04-30 18:59:53 -07001359 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1360 int minHeight) {
1361 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001362 // We want to account for the extra amount of padding that we are adding to the widget
1363 // to ensure that it gets the full amount of space that it has requested
1364 int requiredWidth = minWidth + padding.left + padding.right;
1365 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001366 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001367 }
1368
Adam Cohen2f093b62012-04-30 18:59:53 -07001369 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1370 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001371 }
1372
Adam Cohen2f093b62012-04-30 18:59:53 -07001373 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1374 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001375 }
1376
Adam Cohen2f093b62012-04-30 18:59:53 -07001377 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1378 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001379 }
1380
Adam Cohen2f093b62012-04-30 18:59:53 -07001381 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1382 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001383 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001384 }
1385
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001386 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001387 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001389 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001390 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001391 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001392 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001393 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1394 if (appWidgetInfo == null) {
1395 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1396 }
Romain Guycbb89e42009-06-08 15:52:54 -07001397
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001398 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001399 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001400
Adam Cohen2f093b62012-04-30 18:59:53 -07001401 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1402 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001403
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001405 // We have saved the position to which the widget was dragged-- this really only matters
1406 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001407 int[] cellXY = mTmpAddItemCellCoordinates;
1408 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001409 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001410 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001411 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1412 cellXY[0] = mPendingAddInfo.cellX;
1413 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001414 spanXY[0] = mPendingAddInfo.spanX;
1415 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001416 foundCellSpan = true;
1417 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001418 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001419 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001420 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1421 spanXY[1], cellXY, finalSpan);
1422 spanXY[0] = finalSpan[0];
1423 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001424 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001425 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001426 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001427 }
1428
Michael Jurka0280c3b2010-09-17 15:00:07 -07001429 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001430 if (appWidgetId != -1) {
1431 // Deleting an app widget ID is a void call but writes to disk before returning
1432 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001433 new Thread("deleteAppWidgetId") {
1434 public void run() {
1435 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1436 }
1437 }.start();
1438 }
Winson Chung93eef082012-03-23 15:59:27 -07001439 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001440 return;
1441 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001442
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001443 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001444 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1445 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001446 launcherInfo.spanX = spanXY[0];
1447 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001448 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1449 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001450
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001452 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453
1454 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001455 if (hostView == null) {
1456 // Perform actual inflation because we're live
1457 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1458 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1459 } else {
1460 // The AppWidgetHostView has already been inflated and instantiated
1461 launcherInfo.hostView = hostView;
1462 }
Romain Guycbb89e42009-06-08 15:52:54 -07001463
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001464 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001465 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001466 launcherInfo.notifyWidgetSizeChanged(this);
1467
Adam Cohendcd297f2013-06-18 13:13:40 -07001468 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001469 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001470
1471 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001472 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001473 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 }
Romain Guycbb89e42009-06-08 15:52:54 -07001475
Adam Cohended9f8d2010-11-03 13:25:16 -07001476 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1477 @Override
1478 public void onReceive(Context context, Intent intent) {
1479 final String action = intent.getAction();
1480 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1481 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001482 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001483 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001484
Winson Chungc100e8e2011-08-09 16:02:43 -07001485 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001486 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001487 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001488 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001489 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001490 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1491 mUserPresent = true;
1492 updateRunning();
1493 }
1494 }
1495 };
1496
1497 @Override
1498 public void onAttachedToWindow() {
1499 super.onAttachedToWindow();
1500
1501 // Listen for broadcasts related to user-presence
1502 final IntentFilter filter = new IntentFilter();
1503 filter.addAction(Intent.ACTION_SCREEN_OFF);
1504 filter.addAction(Intent.ACTION_USER_PRESENT);
1505 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001506 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001507 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001508 mVisible = true;
1509 }
1510
1511 @Override
1512 public void onDetachedFromWindow() {
1513 super.onDetachedFromWindow();
1514 mVisible = false;
1515
Adam Cohend113e0c2010-11-11 10:48:05 -08001516 if (mAttached) {
1517 unregisterReceiver(mReceiver);
1518 mAttached = false;
1519 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001520 updateRunning();
1521 }
1522
1523 public void onWindowVisibilityChanged(int visibility) {
1524 mVisible = visibility == View.VISIBLE;
1525 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001526 // The following code used to be in onResume, but it turns out onResume is called when
1527 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1528 // is a more appropriate event to handle
1529 if (mVisible) {
1530 mAppsCustomizeTabHost.onWindowVisible();
1531 if (!mWorkspaceLoading) {
1532 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001533 // We want to let Launcher draw itself at least once before we force it to build
1534 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001535 // apps is nice and speedy.
1536 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001537 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001538 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001539 if (mStarted) return;
1540 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001541 // We delay the layer building a bit in order to give
1542 // other message processing a time to run. In particular
1543 // this avoids a delay in hiding the IME if it was
1544 // currently shown, because doing that may involve
1545 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001546 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001547 final ViewTreeObserver.OnDrawListener listener = this;
1548 mWorkspace.post(new Runnable() {
1549 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001550 if (mWorkspace != null &&
1551 mWorkspace.getViewTreeObserver() != null) {
1552 mWorkspace.getViewTreeObserver().
1553 removeOnDrawListener(listener);
1554 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001555 }
1556 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001557 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001558 }
1559 });
1560 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001561 // When Launcher comes back to foreground, a different Activity might be responsible for
1562 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001563 if (!DISABLE_MARKET_BUTTON) {
1564 updateAppMarketIcon();
1565 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001566 clearTypedText();
1567 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001568 }
1569
1570 private void sendAdvanceMessage(long delay) {
1571 mHandler.removeMessages(ADVANCE_MSG);
1572 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1573 mHandler.sendMessageDelayed(msg, delay);
1574 mAutoAdvanceSentTime = System.currentTimeMillis();
1575 }
1576
1577 private void updateRunning() {
1578 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1579 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1580 mAutoAdvanceRunning = autoAdvanceRunning;
1581 if (autoAdvanceRunning) {
1582 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1583 sendAdvanceMessage(delay);
1584 } else {
1585 if (!mWidgetsToAdvance.isEmpty()) {
1586 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1587 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1588 }
1589 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001590 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001591 }
1592 }
1593 }
1594
1595 private final Handler mHandler = new Handler() {
1596 @Override
1597 public void handleMessage(Message msg) {
1598 if (msg.what == ADVANCE_MSG) {
1599 int i = 0;
1600 for (View key: mWidgetsToAdvance.keySet()) {
1601 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1602 final int delay = mAdvanceStagger * i;
1603 if (v instanceof Advanceable) {
1604 postDelayed(new Runnable() {
1605 public void run() {
1606 ((Advanceable) v).advance();
1607 }
1608 }, delay);
1609 }
1610 i++;
1611 }
1612 sendAdvanceMessage(mAdvanceInterval);
1613 }
1614 }
1615 };
1616
1617 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001618 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001619 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1620 if (v instanceof Advanceable) {
1621 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001622 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001623 updateRunning();
1624 }
1625 }
1626
1627 void removeWidgetToAutoAdvance(View hostView) {
1628 if (mWidgetsToAdvance.containsKey(hostView)) {
1629 mWidgetsToAdvance.remove(hostView);
1630 updateRunning();
1631 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001632 }
1633
Joe Onorato9c1289c2009-08-17 11:03:03 -04001634 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001635 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001636 launcherInfo.hostView = null;
1637 }
1638
Winson Chung93eef082012-03-23 15:59:27 -07001639 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1640 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1641 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001642 }
1643
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001644 public LauncherAppWidgetHost getAppWidgetHost() {
1645 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001646 }
Romain Guycbb89e42009-06-08 15:52:54 -07001647
Winson Chunga9abd0e2010-10-27 17:18:37 -07001648 public LauncherModel getModel() {
1649 return mModel;
1650 }
1651
Bjorn Bringertc459e522013-06-07 19:36:01 +01001652 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001653 getWindow().closeAllPanels();
1654
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001655 // Whatever we were doing is hereby canceled.
1656 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001657 }
1658
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001659 @Override
1660 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001661 long startTime = 0;
1662 if (DEBUG_RESUME_TIME) {
1663 startTime = System.currentTimeMillis();
1664 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001665 super.onNewIntent(intent);
1666
1667 // Close the menu
1668 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001669 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001670 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001671
Jamie Genniscb222e82012-10-23 15:44:26 -07001672 final boolean alreadyOnHome =
1673 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001674 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001675
Adam Cohen6fecd412013-10-02 17:41:50 -07001676 if (mWorkspace == null) {
1677 // Can be cases where mWorkspace is null, this prevents a NPE
1678 return;
1679 }
1680 Folder openFolder = mWorkspace.getOpenFolder();
1681 // In all these cases, only animate if we're already on home
1682 mWorkspace.exitWidgetResizeMode();
1683 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1684 openFolder == null) {
1685 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001686 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001687
Adam Cohen6fecd412013-10-02 17:41:50 -07001688 closeFolder();
1689 exitSpringLoadedDragMode();
1690
1691 // If we are already on home, then just animate back to the workspace,
1692 // otherwise, just wait until onResume to set the state back to Workspace
1693 if (alreadyOnHome) {
1694 showWorkspaceAndExitOverviewMode(true);
1695 } else {
1696 mOnResumeState = State.WORKSPACE;
1697 }
1698
1699 final View v = getWindow().peekDecorView();
1700 if (v != null && v.getWindowToken() != null) {
1701 InputMethodManager imm = (InputMethodManager)getSystemService(
1702 INPUT_METHOD_SERVICE);
1703 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1704 }
1705
1706 // Reset the apps customize page
1707 if (mAppsCustomizeTabHost != null) {
1708 mAppsCustomizeTabHost.reset();
1709 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 }
Michael Jurka447bf842013-05-15 14:52:15 +02001711 if (DEBUG_RESUME_TIME) {
1712 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1713 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714 }
1715
Adam Cohen040a5d22013-09-16 17:09:33 -07001716 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1717 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001718 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001719 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001720 }
1721 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001722 protected void showWorkspaceAndExitOverviewMode() {
Allan Wojciechowskifdc43022013-10-02 11:13:17 -04001723 showWorkspaceAndExitOverviewMode(false);
Adam Cohen040a5d22013-09-16 17:09:33 -07001724 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001725
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001727 public void onRestoreInstanceState(Bundle state) {
1728 super.onRestoreInstanceState(state);
1729 for (int page: mSynchronouslyBoundPages) {
1730 mWorkspace.restoreInstanceStateForChild(page);
1731 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732 }
1733
1734 @Override
1735 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001736 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001737 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001738
Michael Jurka883f55b2010-10-21 15:47:14 -07001739 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001740 // We close any open folder since it will not be re-opened, and we need to make sure
1741 // this state is reflected.
1742 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001743
Adam Cohendcd297f2013-06-18 13:13:40 -07001744 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001745 mWaitingForResult) {
1746 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001747 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001748 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1749 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001750 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1751 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1752 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001753 }
1754
1755 if (mFolderInfo != null && mWaitingForResult) {
1756 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1757 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1758 }
Michael Jurka946ad472010-07-09 18:05:18 -07001759
Winson Chung785d2eb2011-04-14 16:08:02 -07001760 // Save the current AppsCustomize tab
1761 if (mAppsCustomizeTabHost != null) {
1762 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1763 if (currentTabTag != null) {
1764 outState.putString("apps_customize_currentTab", currentTabTag);
1765 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001766 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1767 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001768 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001769 }
1770
1771 @Override
1772 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001773 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001774
Winson Chunge7a03942011-08-05 15:05:12 -07001775 // Remove all pending runnables
1776 mHandler.removeMessages(ADVANCE_MSG);
1777 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001778 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001779
Winson Chungcd2b0142011-06-08 16:02:26 -07001780 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001781 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001782 mModel.stopLoader();
1783 app.setLauncher(null);
1784
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001785 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001786 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001788 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001790 mAppWidgetHost = null;
1791
1792 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793
1794 TextKeyListener.getInstance().release();
1795
Winson Chung81b52252012-08-27 15:34:29 -07001796 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1797 // to prevent leaking Launcher activities on orientation change.
1798 if (mModel != null) {
1799 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1800 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001801
1802 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001803 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001804
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001805 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001806 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1807 mWorkspace.removeAllViews();
1808 mWorkspace = null;
1809 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001810
Michael Jurka2ecf9952012-06-18 12:52:28 -07001811 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 }
1813
Adam Cohena9cf38f2011-05-02 15:36:58 -07001814 public DragController getDragController() {
1815 return mDragController;
1816 }
1817
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 @Override
1819 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001820 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001821 super.startActivityForResult(intent, requestCode);
1822 }
1823
Winson Chung70d72102011-08-12 11:24:35 -07001824 /**
1825 * Indicates that we want global search for this activity by setting the globalSearch
1826 * argument for {@link #startSearch} to true.
1827 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001828 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001829 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001831
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001832 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001833
Karl Rosaen138a0412009-04-23 19:00:21 -07001834 if (initialQuery == null) {
1835 // Use any text typed in the launcher as the initial query
1836 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001837 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001838 if (appSearchData == null) {
1839 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001840 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001841 }
Winson Chungadf0c182012-08-23 14:59:07 -07001842 Rect sourceBounds = new Rect();
1843 if (mSearchDropTargetBar != null) {
1844 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1845 }
Romain Guycbb89e42009-06-08 15:52:54 -07001846
Bjorn Bringertc459e522013-06-07 19:36:01 +01001847 startSearch(initialQuery, selectInitialQuery,
1848 appSearchData, sourceBounds);
1849 }
1850
1851 public void startSearch(String initialQuery,
1852 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001853 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001854 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001855 }
1856
1857 /**
1858 * Starts the global search activity. This code is a copied from SearchManager
1859 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001860 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001861 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001862 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001863 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1864 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1865 if (globalSearchActivity == null) {
1866 Log.w(TAG, "No global search activity found.");
1867 return;
1868 }
1869 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1870 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1871 intent.setComponent(globalSearchActivity);
1872 // Make sure that we have a Bundle to put source in
1873 if (appSearchData == null) {
1874 appSearchData = new Bundle();
1875 } else {
1876 appSearchData = new Bundle(appSearchData);
1877 }
1878 // Set source to package name of app that starts global search, if not set already.
1879 if (!appSearchData.containsKey("source")) {
1880 appSearchData.putString("source", getPackageName());
1881 }
1882 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1883 if (!TextUtils.isEmpty(initialQuery)) {
1884 intent.putExtra(SearchManager.QUERY, initialQuery);
1885 }
1886 if (selectInitialQuery) {
1887 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1888 }
1889 intent.setSourceBounds(sourceBounds);
1890 try {
1891 startActivity(intent);
1892 } catch (ActivityNotFoundException ex) {
1893 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1894 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001895 }
1896
Winson Chung70d72102011-08-12 11:24:35 -07001897 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001898 public boolean onPrepareOptionsMenu(Menu menu) {
1899 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001900 if (!mWorkspace.isInOverviewMode()) {
1901 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001902 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001903 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001904 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001905
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001906 @Override
1907 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001908 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001909 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001910 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001911 }
1912
Joe Onorato9c1289c2009-08-17 11:03:03 -04001913 public boolean isWorkspaceLocked() {
1914 return mWorkspaceLoading || mWaitingForResult;
1915 }
1916
Michael Jurka0280c3b2010-09-17 15:00:07 -07001917 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001918 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001919 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001920 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1921 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001922 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001923 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001924 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001925
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001926 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1927 AppWidgetProviderInfo appWidgetInfo) {
1928 if (appWidgetInfo.configure != null) {
1929 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001930
Bjorn Bringert7984c942009-12-09 15:38:25 +00001931 // Launch over to configure widget, if needed
1932 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001933 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001934 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001935 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001937 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001938 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001939 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001940 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001941 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 }
1943 }
Romain Guycbb89e42009-06-08 15:52:54 -07001944
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001945 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07001946 // Close any folders that may be open.
1947 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001948 mWorkspace.moveToCustomContentScreen(animate);
1949 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001950 /**
1951 * Process a shortcut drop.
1952 *
1953 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001954 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001955 * @param cell The cell it should be added to, optional
1956 * @param position The location on the screen where it was dropped, optional
1957 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001958 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001959 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001960 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001961 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001962 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001963 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001964
1965 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001966 mPendingAddInfo.cellX = cell[0];
1967 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001968 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001969
1970 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1971 createShortcutIntent.setComponent(componentName);
1972 processShortcut(createShortcutIntent);
1973 }
1974
Adam Cohenfbba09b2011-07-18 21:43:05 -07001975 /**
1976 * Process a widget drop.
1977 *
1978 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001979 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001980 * @param cell The cell it should be added to, optional
1981 * @param position The location on the screen where it was dropped, optional
1982 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001983 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001984 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001985 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001986 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001987 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001988 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001989 mPendingAddInfo.minSpanX = info.minSpanX;
1990 mPendingAddInfo.minSpanY = info.minSpanY;
1991
Adam Cohenfbba09b2011-07-18 21:43:05 -07001992 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001993 mPendingAddInfo.cellX = cell[0];
1994 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001995 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001996 if (span != null) {
1997 mPendingAddInfo.spanX = span[0];
1998 mPendingAddInfo.spanY = span[1];
1999 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002000
Adam Cohened66b2b2012-01-23 17:28:51 -08002001 AppWidgetHostView hostView = info.boundWidget;
2002 int appWidgetId;
2003 if (hostView != null) {
2004 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002005 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002006 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002007 // In this case, we either need to start an activity to get permission to bind
2008 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002009 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002010 Bundle options = info.bindOptions;
2011
2012 boolean success = false;
2013 if (options != null) {
2014 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2015 info.componentName, options);
2016 } else {
2017 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2018 info.componentName);
2019 }
2020 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002021 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002022 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002023 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002024 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2025 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2026 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002027 // TODO: we need to make sure that this accounts for the options bundle.
2028 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002029 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2030 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002031 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002032 }
2033
Joe Onoratodeb98af2010-02-19 14:59:39 -08002034 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002035 // Handle case where user selected "Applications"
2036 String applicationName = getResources().getString(R.string.group_applications);
2037 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002038
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002039 if (applicationName != null && applicationName.equals(shortcutName)) {
2040 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2041 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002042
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002043 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2044 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002045 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002046 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002047 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002048 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002049 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050 }
2051
Winson Chung24ab2f12010-09-16 14:10:47 -07002052 void processWallpaper(Intent intent) {
2053 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2054 }
2055
Adam Cohendcd297f2013-06-18 13:13:40 -07002056 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002057 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002058 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 folderInfo.title = getText(R.string.folder_name);
2060
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002062 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002063 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002064 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065
2066 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002067 FolderIcon newFolder =
2068 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002069 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002070 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002071 // Force measure the new folder icon
2072 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2073 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002074 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 }
Romain Guycbb89e42009-06-08 15:52:54 -07002076
Joe Onorato9c1289c2009-08-17 11:03:03 -04002077 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002078 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002079 }
2080
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002081 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002082 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002084 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002085 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002086 }
2087
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002088 protected ComponentName getWallpaperPickerComponent() {
2089 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2090 }
2091
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002092 /**
2093 * Registers various content observers. The current implementation registers
2094 * only a favorites observer to keep track of the favorites applications.
2095 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002096 private void registerContentObservers() {
2097 ContentResolver resolver = getContentResolver();
2098 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2099 true, mWidgetObserver);
2100 }
2101
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002102 @Override
2103 public boolean dispatchKeyEvent(KeyEvent event) {
2104 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2105 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002106 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002107 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002108 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002109 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002110 dumpState();
2111 return true;
2112 }
2113 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002114 }
2115 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2116 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002117 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002118 return true;
2119 }
2120 }
2121
2122 return super.dispatchKeyEvent(event);
2123 }
2124
Joe Onorato88ec0992009-11-19 13:16:06 -08002125 @Override
2126 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002127 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002128 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002129 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002130 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002131 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002132 Folder openFolder = mWorkspace.getOpenFolder();
2133 if (openFolder.isEditingName()) {
2134 openFolder.dismissEditingName();
2135 } else {
2136 closeFolder();
2137 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002138 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002139 mWorkspace.exitWidgetResizeMode();
2140
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002141 // Back button is a no-op here, but give at least some feedback for the button press
2142 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002143 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002144 }
2145
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002147 * Re-listen when widgets are reset.
2148 */
2149 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002150 if (mAppWidgetHost != null) {
2151 mAppWidgetHost.startListening();
2152 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002153 }
2154
2155 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002156 * Launches the intent referred by the clicked shortcut.
2157 *
2158 * @param v The view representing the clicked shortcut.
2159 */
2160 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002161 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2162 // view has detached (it's possible for this to happen if the view is removed mid touch).
2163 if (v.getWindowToken() == null) {
2164 return;
2165 }
2166
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002167 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002168 return;
2169 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002170
Adam Cohen1697b792013-09-17 19:08:21 -07002171 if (v instanceof Workspace) {
2172 if (mWorkspace.isInOverviewMode()) {
2173 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002174 }
2175 return;
2176 }
2177
2178 if (v instanceof CellLayout) {
2179 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002180 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002181 }
2182 }
2183
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002184 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002185 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002186 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002187 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2188 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002189
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002190 // Check for special shortcuts
2191 if (intent.getComponent() != null) {
2192 final String shortcutClass = intent.getComponent().getClassName();
2193
2194 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002195 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002196 return;
2197 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2198 MemoryDumpActivity.startDump(this);
2199 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002200 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2201 toggleShowWeightWatcher();
2202 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002203 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002204 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002205
2206 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002207 int[] pos = new int[2];
2208 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002209 intent.setSourceBounds(new Rect(pos[0], pos[1],
2210 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002211
2212 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002213
Daniel Sandlerff02d492013-08-05 02:12:05 -04002214 mStats.recordLaunch(intent, shortcut);
2215
Michael Jurkaddd62e92011-02-16 17:49:14 -08002216 if (success && v instanceof BubbleTextView) {
2217 mWaitingForResume = (BubbleTextView) v;
2218 mWaitingForResume.setStayPressed(true);
2219 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002220 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002221 if (v instanceof FolderIcon) {
2222 FolderIcon fi = (FolderIcon) v;
2223 handleFolderClick(fi);
2224 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002225 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002226 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002227 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002228 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002229 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002230 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231 }
2232 }
2233
Michael Jurka0e260592010-06-30 17:07:39 -07002234 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002235 return false;
2236 }
2237
Michael Jurkaaf442092010-06-10 17:01:57 -07002238 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002239 * Event handler for the search button
2240 *
2241 * @param v The view that was clicked.
2242 */
2243 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002244 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2245
Amith Yamasania135ba82011-08-09 17:42:01 -07002246 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002247 }
2248
2249 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002250 * Event handler for the voice button
2251 *
2252 * @param v The view that was clicked.
2253 */
2254 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002255 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002256
Bjorn Bringertc459e522013-06-07 19:36:01 +01002257 startVoice();
2258 }
2259
2260 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002261 try {
2262 final SearchManager searchManager =
2263 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2264 ComponentName activityName = searchManager.getGlobalSearchActivity();
2265 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002266 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002267 if (activityName != null) {
2268 intent.setPackage(activityName.getPackageName());
2269 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002270 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002271 } catch (ActivityNotFoundException e) {
2272 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002273 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002274 startActivitySafely(null, intent, "onClickVoiceButton");
2275 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002276 }
2277
2278 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002279 * Event handler for the "grid" button that appears on the home screen, which
2280 * enters all apps mode.
2281 *
2282 * @param v The view that was clicked.
2283 */
2284 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002285 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002286 }
2287
2288 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002289 // Provide the same haptic feedback that the system offers for virtual keys.
2290 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002291 }
2292
Adam Cohen61f560d2013-09-30 15:58:20 -07002293 public void performHapticFeedbackOnTouchDown(View v) {
2294 // Provide the same haptic feedback that the system offers for virtual keys.
2295 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2296 }
2297
2298 public View.OnTouchListener getHapticFeedbackTouchListener() {
2299 if (mHapticFeedbackTouchListener == null) {
2300 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2301 @Override
2302 public boolean onTouch(View v, MotionEvent event) {
2303 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2304 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2305 }
2306 return false;
2307 }
2308 };
2309 }
2310 return mHapticFeedbackTouchListener;
2311 }
2312
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002313 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002314 if (!DISABLE_MARKET_BUTTON) {
2315 if (mAppMarketIntent != null) {
2316 startActivitySafely(v, mAppMarketIntent, "app market");
2317 } else {
2318 Log.e(TAG, "Invalid app market intent.");
2319 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002320 }
2321 }
2322
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002323 /**
2324 * Called when the user stops interacting with the launcher.
2325 * This implies that the user is now on the homescreen and is not doing housekeeping.
2326 */
2327 protected void onInteractionEnd() {}
2328
2329 /**
2330 * Called when the user starts interacting with the launcher.
2331 * The possible interactions are:
2332 * - open all apps
2333 * - reorder an app shortcut, or a widget
2334 * - open the overview mode.
2335 * This is a good time to stop doing things that only make sense
2336 * when the user is on the homescreen and not doing housekeeping.
2337 */
2338 protected void onInteractionBegin() {}
2339
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002340 void startApplicationDetailsActivity(ComponentName componentName) {
2341 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002342 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2343 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002344 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002345 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002346 }
2347
Michael Jurka1e2f4652013-07-08 18:03:46 -07002348 // returns true if the activity was started
2349 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002350 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002351 // System applications cannot be installed. For now, show a toast explaining that.
2352 // We may give them the option of disabling apps this way.
2353 int messageId = R.string.uninstall_system_app_text;
2354 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002355 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002356 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002357 String packageName = componentName.getPackageName();
2358 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002359 Intent intent = new Intent(
2360 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002361 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2362 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002363 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002364 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002365 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002366 }
2367
Michael Jurka86a720e2012-05-09 11:23:23 -07002368 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002369 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002370
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002371 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002372 // Only launch using the new animation if the shortcut has not opted out (this is a
2373 // private contract between launcher and may be ignored in the future).
2374 boolean useLaunchAnimation = (v != null) &&
2375 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2376 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002377 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2378 v.getMeasuredWidth(), v.getMeasuredHeight());
2379
2380 startActivity(intent, opts.toBundle());
2381 } else {
2382 startActivity(intent);
2383 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002384 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 } catch (SecurityException e) {
2386 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002387 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002388 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002389 "or use the exported attribute for this activity. "
2390 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002391 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002392 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002393 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002394
Michael Jurka86a720e2012-05-09 11:23:23 -07002395 boolean startActivitySafely(View v, Intent intent, Object tag) {
2396 boolean success = false;
2397 try {
2398 success = startActivity(v, intent, tag);
2399 } catch (ActivityNotFoundException e) {
2400 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2401 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2402 }
2403 return success;
2404 }
2405
Adam Cohena9cf38f2011-05-02 15:36:58 -07002406 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002407 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002408 Folder openFolder = mWorkspace.getFolderForTag(info);
2409
2410 // If the folder info reports that the associated folder is open, then verify that
2411 // it is actually opened. There have been a few instances where this gets out of sync.
2412 if (info.opened && openFolder == null) {
2413 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002414 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002415 info.opened = false;
2416 }
2417
Adam Cohenfb91f302012-06-11 15:45:18 -07002418 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002419 // Close any open folder
2420 closeFolder();
2421 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002422 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002423 } else {
2424 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002425 int folderScreen;
2426 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002427 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002428 // .. and close it
2429 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002430 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002431 // Close any folder open on the current screen
2432 closeFolder();
2433 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002434 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002435 }
2436 }
2437 }
2438 }
2439
Adam Cohen268c4752012-06-06 17:47:33 -07002440 /**
2441 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2442 * in the DragLayer in the exact absolute location of the original FolderIcon.
2443 */
2444 private void copyFolderIconToImage(FolderIcon fi) {
2445 final int width = fi.getMeasuredWidth();
2446 final int height = fi.getMeasuredHeight();
2447
2448 // Lazy load ImageView, Bitmap and Canvas
2449 if (mFolderIconImageView == null) {
2450 mFolderIconImageView = new ImageView(this);
2451 }
2452 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2453 mFolderIconBitmap.getHeight() != height) {
2454 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2455 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2456 }
2457
2458 DragLayer.LayoutParams lp;
2459 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2460 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2461 } else {
2462 lp = new DragLayer.LayoutParams(width, height);
2463 }
2464
Adam Cohen307fe232012-08-16 17:55:58 -07002465 // The layout from which the folder is being opened may be scaled, adjust the starting
2466 // view size by this scale factor.
2467 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002468 lp.customPosition = true;
2469 lp.x = mRectForFolderAnimation.left;
2470 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002471 lp.width = (int) (scale * width);
2472 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002473
2474 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2475 fi.draw(mFolderIconCanvas);
2476 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002477 if (fi.getFolder() != null) {
2478 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2479 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002480 }
Adam Cohen268c4752012-06-06 17:47:33 -07002481 // Just in case this image view is still in the drag layer from a previous animation,
2482 // we remove it and re-add it.
2483 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2484 mDragLayer.removeView(mFolderIconImageView);
2485 }
2486 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002487 if (fi.getFolder() != null) {
2488 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002489 }
Adam Cohen268c4752012-06-06 17:47:33 -07002490 }
2491
Adam Cohen2801caf2011-05-13 20:57:39 -07002492 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002493 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002494 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2495 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2496 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2497
Adam Cohenc51934b2011-07-26 21:07:43 -07002498 FolderInfo info = (FolderInfo) fi.getTag();
2499 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2500 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002501 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2502 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002503 }
2504
Adam Cohen268c4752012-06-06 17:47:33 -07002505 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2506 copyFolderIconToImage(fi);
2507 fi.setVisibility(View.INVISIBLE);
2508
Michael Jurka2ecf9952012-06-18 12:52:28 -07002509 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002510 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002511 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2512 oa.start();
2513 }
2514
Adam Cohen268c4752012-06-06 17:47:33 -07002515 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002516 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002517 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2518 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2519 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2520
Adam Cohen268c4752012-06-06 17:47:33 -07002521 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002522
Adam Cohen268c4752012-06-06 17:47:33 -07002523 // We remove and re-draw the FolderIcon in-case it has changed
2524 mDragLayer.removeView(mFolderIconImageView);
2525 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002526 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002527 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002528 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002529 oa.addListener(new AnimatorListenerAdapter() {
2530 @Override
2531 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002532 if (cl != null) {
2533 cl.clearFolderLeaveBehind();
2534 // Remove the ImageView copy of the FolderIcon and make the original visible.
2535 mDragLayer.removeView(mFolderIconImageView);
2536 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002537 }
2538 }
2539 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002540 oa.start();
2541 }
2542
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002543 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002544 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002545 * is animated relative to the specified View. If the View is null, no animation
2546 * is played.
2547 *
2548 * @param folderInfo The FolderInfo describing the folder to open.
2549 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002550 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002551 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002552 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002553
Adam Cohena9cf38f2011-05-02 15:36:58 -07002554 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002555
Adam Cohen4554ee12011-08-03 16:13:21 -07002556 // Just verify that the folder hasn't already been added to the DragLayer.
2557 // There was a one-off crash where the folder had a parent already.
2558 if (folder.getParent() == null) {
2559 mDragLayer.addView(folder);
2560 mDragController.addDropTarget((DropTarget) folder);
2561 } else {
2562 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2563 folder.getParent() + ").");
2564 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002565 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002566 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002567
2568 // Notify the accessibility manager that this folder "window" has appeared and occluded
2569 // the workspace items
2570 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2571 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002572 }
2573
2574 public void closeFolder() {
2575 Folder folder = mWorkspace.getOpenFolder();
2576 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002577 if (folder.isEditingName()) {
2578 folder.dismissEditingName();
2579 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002580 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002581
2582 // Dismiss the folder cling
2583 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002584 }
2585 }
2586
2587 void closeFolder(Folder folder) {
2588 folder.getInfo().opened = false;
2589
2590 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2591 if (parent != null) {
2592 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2593 shrinkAndFadeInFolderIcon(fi);
2594 }
2595 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002596
2597 // Notify the accessibility manager that this folder "window" has disappeard and no
2598 // longer occludeds the workspace items
2599 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002600 }
2601
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002602 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002603 if (!isDraggingEnabled()) return false;
2604 if (isWorkspaceLocked()) return false;
2605 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002606
Adam Cohen1697b792013-09-17 19:08:21 -07002607 if (v instanceof Workspace) {
2608 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002609 if (mWorkspace.enterOverviewMode()) {
2610 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2611 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2612 return true;
2613 } else {
2614 return false;
2615 }
Adam Cohen1697b792013-09-17 19:08:21 -07002616 }
Adam Cohen1697b792013-09-17 19:08:21 -07002617 }
2618
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002619 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002620 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002621 }
2622
Michael Jurka0280c3b2010-09-17 15:00:07 -07002623 resetAddInfo();
2624 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002625 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002626 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002627 return true;
2628 }
2629
Winson Chung3d503fb2011-07-13 17:25:49 -07002630 // The hotseat touch handling does not go through Workspace, and we always allow long press
2631 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002632 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002633 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2634 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002635 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002636 // User long pressed on empty space
2637 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2638 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2639 // Disabling reordering until we sort out some issues.
2640 if (mWorkspace.isInOverviewMode()) {
2641 mWorkspace.startReordering(v);
2642 } else {
2643 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002644 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002645 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002646 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002647 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002648 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002649 }
2650 }
2651 }
2652 return true;
2653 }
2654
Winson Chung3d503fb2011-07-13 17:25:49 -07002655 boolean isHotseatLayout(View layout) {
2656 return mHotseat != null && layout != null &&
2657 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2658 }
2659 Hotseat getHotseat() {
2660 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002661 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002662 View getOverviewPanel() {
2663 return mOverviewPanel;
2664 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002665 SearchDropTargetBar getSearchBar() {
2666 return mSearchDropTargetBar;
2667 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002668
Winson Chung3d503fb2011-07-13 17:25:49 -07002669 /**
2670 * Returns the CellLayout of the specified container at the specified screen.
2671 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002672 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002673 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2674 if (mHotseat != null) {
2675 return mHotseat.getLayout();
2676 } else {
2677 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002678 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002679 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002680 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002681 }
2682 }
2683
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002684 Workspace getWorkspace() {
2685 return mWorkspace;
2686 }
2687
Daniel Sandler843e8602010-06-07 14:59:01 -04002688 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002689 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002690 }
2691
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002692 /**
2693 * Helper method for the cameraZoomIn/cameraZoomOut animations
2694 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002695 * @param scaleFactor The scale factor used for the zoom
2696 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002697 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002698 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002699 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002700 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002701
Craig Mautner360310b2012-10-26 15:13:08 -07002702 private void setWorkspaceBackground(boolean workspace) {
2703 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002704 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002705 }
2706
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002707 void updateWallpaperVisibility(boolean visible) {
2708 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2709 int curflags = getWindow().getAttributes().flags
2710 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2711 if (wpflags != curflags) {
2712 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2713 }
Craig Mautner360310b2012-10-26 15:13:08 -07002714 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002715 }
2716
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002717 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2718 if (v instanceof LauncherTransitionable) {
2719 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2720 }
2721 }
2722
Michael Jurkabed61d22012-02-14 22:51:29 -08002723 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2724 if (v instanceof LauncherTransitionable) {
2725 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2726 }
Winson Chung70442722012-02-10 15:43:22 -08002727
2728 // Update the workspace transition step as well
2729 dispatchOnLauncherTransitionStep(v, 0f);
2730 }
2731
2732 private void dispatchOnLauncherTransitionStep(View v, float t) {
2733 if (v instanceof LauncherTransitionable) {
2734 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2735 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002736 }
2737
2738 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2739 if (v instanceof LauncherTransitionable) {
2740 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2741 }
Winson Chung70442722012-02-10 15:43:22 -08002742
2743 // Update the workspace transition step as well
2744 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002745 }
2746
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002747 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002748 * Things to test when changing the following seven functions.
2749 * - Home from workspace
2750 * - from center screen
2751 * - from other screens
2752 * - Home from all apps
2753 * - from center screen
2754 * - from other screens
2755 * - Back from all apps
2756 * - from center screen
2757 * - from other screens
2758 * - Launch app from workspace and quit
2759 * - with back
2760 * - with home
2761 * - Launch app from all apps and quit
2762 * - with back
2763 * - with home
2764 * - Go to a screen that's not the default, then all
2765 * apps, and launch and app, and go back
2766 * - with back
2767 * -with home
2768 * - On workspace, long press power and go back
2769 * - with back
2770 * - with home
2771 * - On all apps, long press power and go back
2772 * - with back
2773 * - with home
2774 * - On workspace, power off
2775 * - On all apps, power off
2776 * - Launch an app and turn off the screen while in that app
2777 * - Go back with home key
2778 * - Go back with back key TODO: make this not go to workspace
2779 * - From all apps
2780 * - From workspace
2781 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2782 * - From all apps
2783 * - From the center workspace
2784 * - From another workspace
2785 */
2786
2787 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002788 * Zoom the camera out from the workspace to reveal 'toView'.
2789 * Assumes that the view to show is anchored at either the very top or very bottom
2790 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002791 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002792 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002793 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2794 showAppsCustomizeHelper(animated, springLoaded, contentType);
2795 }
2796 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2797 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002798 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002799 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002800 mStateAnimation.cancel();
2801 mStateAnimation = null;
2802 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002803 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002804
Winson Chungf0ea4d32011-06-06 14:27:16 -07002805 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2806 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2807 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002808 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002809 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002810 final int startDelay =
2811 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002812
Michael Jurkab3e22d92011-10-31 15:58:33 -07002813 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002814
Michael Jurkad74c9842011-07-10 12:44:21 -07002815 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002816 Animator workspaceAnim =
2817 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002818 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2819 // Set the content type for the all apps space
2820 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2821 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002822
2823 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002824 toView.setScaleX(scale);
2825 toView.setScaleY(scale);
2826 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2827 scaleAnim.
2828 scaleX(1f).scaleY(1f).
2829 setDuration(duration).
2830 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002831
Winson Chungf0ea4d32011-06-06 14:27:16 -07002832 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002833 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002834 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002835 .ofFloat(toView, "alpha", 0f, 1f)
2836 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002837 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002838 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2839 @Override
2840 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002841 if (animation == null) {
2842 throw new RuntimeException("animation is null");
2843 }
Winson Chung70442722012-02-10 15:43:22 -08002844 float t = (Float) animation.getAnimatedValue();
2845 dispatchOnLauncherTransitionStep(fromView, t);
2846 dispatchOnLauncherTransitionStep(toView, t);
2847 }
2848 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002849
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002850 // toView should appear right at the end of the workspace shrink
2851 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002852 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002853 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002854 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002855
2856 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002857 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002858 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002859 // Prepare the position
2860 toView.setTranslationX(0.0f);
2861 toView.setTranslationY(0.0f);
2862 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002863 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002864 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002865 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002866 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002867 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2868 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002869
Winson Chungc7d2b602012-05-16 17:02:20 -07002870 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002871 if (mSearchDropTargetBar != null) {
2872 mSearchDropTargetBar.hideSearchBar(false);
2873 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002874 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002875 });
2876
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002877 if (workspaceAnim != null) {
2878 mStateAnimation.play(workspaceAnim);
2879 }
Michael Jurka1899a362011-11-03 13:50:45 -07002880
2881 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002882
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002883 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2884 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002885
2886 // If any of the objects being animated haven't been measured/laid out
2887 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002888 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002889 (mWorkspace.getMeasuredWidth() == 0) ||
2890 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002891 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002892 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002893
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002894 final AnimatorSet stateAnimation = mStateAnimation;
2895 final Runnable startAnimRunnable = new Runnable() {
2896 public void run() {
2897 // Check that mStateAnimation hasn't changed while
2898 // we waited for a layout/draw pass
2899 if (mStateAnimation != stateAnimation)
2900 return;
2901 setPivotsForZoom(toView, scale);
2902 dispatchOnLauncherTransitionStart(fromView, animated, false);
2903 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002904 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002905 }
2906 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002907 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002908 final ViewTreeObserver observer = toView.getViewTreeObserver();
2909 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2910 public void onGlobalLayout() {
2911 startAnimRunnable.run();
2912 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2913 }
2914 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002915 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002916 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002917 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002918 } else {
2919 toView.setTranslationX(0.0f);
2920 toView.setTranslationY(0.0f);
2921 toView.setScaleX(1.0f);
2922 toView.setScaleY(1.0f);
2923 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002924 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002925
Daniel Sandlere4f98912013-06-25 15:13:26 -04002926 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002927 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002928 if (mSearchDropTargetBar != null) {
2929 mSearchDropTargetBar.hideSearchBar(false);
2930 }
Michael Jurkaabded662011-03-04 12:06:57 -08002931 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002932 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002933 dispatchOnLauncherTransitionStart(fromView, animated, false);
2934 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002935 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002936 dispatchOnLauncherTransitionStart(toView, animated, false);
2937 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002938 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002939 }
2940
2941 /**
2942 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002943 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002944 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002945 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002946 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2947 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002948
Michael Jurkab3e22d92011-10-31 15:58:33 -07002949 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002950 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002951 mStateAnimation.cancel();
2952 mStateAnimation = null;
2953 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002954 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002955
Winson Chungf0ea4d32011-06-06 14:27:16 -07002956 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002957 final int fadeOutDuration =
2958 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002959 final float scaleFactor = (float)
2960 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2961 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002962 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002963 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002964 if (toState == State.WORKSPACE) {
2965 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2966 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002967 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002968 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2969 workspaceAnim = mWorkspace.getChangeStateAnimation(
2970 Workspace.State.SPRING_LOADED, animated);
2971 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002972
Michael Jurkab3e22d92011-10-31 15:58:33 -07002973 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002974 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002975 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002976 final LauncherViewPropertyAnimator scaleAnim =
2977 new LauncherViewPropertyAnimator(fromView);
2978 scaleAnim.
2979 scaleX(scaleFactor).scaleY(scaleFactor).
2980 setDuration(duration).
2981 setInterpolator(new Workspace.ZoomInInterpolator());
2982
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002983 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002984 .ofFloat(fromView, "alpha", 1f, 0f)
2985 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002986 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002987 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2988 @Override
2989 public void onAnimationUpdate(ValueAnimator animation) {
2990 float t = 1f - (Float) animation.getAnimatedValue();
2991 dispatchOnLauncherTransitionStep(fromView, t);
2992 dispatchOnLauncherTransitionStep(toView, t);
2993 }
2994 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002995
Michael Jurka2ecf9952012-06-18 12:52:28 -07002996 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002997
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002998 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2999 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003000 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003001
3002 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003003 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003004 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003005 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003006 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3007 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003008 if (onCompleteRunnable != null) {
3009 onCompleteRunnable.run();
3010 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003011 mAppsCustomizeContent.updateCurrentPageScroll();
3012 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003013 }
3014 });
3015
Winson Chungf0ea4d32011-06-06 14:27:16 -07003016 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003017 if (workspaceAnim != null) {
3018 mStateAnimation.play(workspaceAnim);
3019 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003020 dispatchOnLauncherTransitionStart(fromView, animated, true);
3021 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003022 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003023 } else {
3024 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003025 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003026 dispatchOnLauncherTransitionStart(fromView, animated, true);
3027 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003028 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003029 dispatchOnLauncherTransitionStart(toView, animated, true);
3030 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003031 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003032 }
3033
Michael Jurkae326f182011-11-21 14:05:46 -08003034 @Override
3035 public void onTrimMemory(int level) {
3036 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003037 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003038 mAppsCustomizeTabHost.onTrimMemory();
3039 }
3040 }
3041
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003042 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003043 showWorkspace(animated, null);
3044 }
3045
3046 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003047 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003048 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003049 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003050 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003051
Winson Chungc7d2b602012-05-16 17:02:20 -07003052 // Show the search bar (only animate if we were showing the drop target bar in spring
3053 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003054 if (mSearchDropTargetBar != null) {
3055 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3056 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003057
Michael Jurkab3e22d92011-10-31 15:58:33 -07003058 // Set focus to the AppsCustomize button
3059 if (mAllAppsButton != null) {
3060 mAllAppsButton.requestFocus();
3061 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003062 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003063
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003064 // Change the state *after* we've called all the transition code
3065 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003066
Winson Chung5fb63472011-02-02 17:03:37 -08003067 // Resume the auto-advance of widgets
3068 mUserPresent = true;
3069 updateRunning();
3070
alanv1d4fde62012-10-17 13:15:47 -07003071 // Send an accessibility event to announce the context change
3072 getWindow().getDecorView()
3073 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003074
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003075 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003076 }
3077
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003078 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003079 }
3080
Winson Chungc58497e2013-09-03 17:48:37 -07003081 void showAllApps(boolean animated,
3082 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003083 if (mState != State.WORKSPACE) return;
3084
Winson Chungc58497e2013-09-03 17:48:37 -07003085 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003086 mAppsCustomizeTabHost.requestFocus();
3087
Michael Jurkab3e22d92011-10-31 15:58:33 -07003088 // Change the state *after* we've called all the transition code
3089 mState = State.APPS_CUSTOMIZE;
3090
3091 // Pause the auto-advance of widgets until we are out of AllApps
3092 mUserPresent = false;
3093 updateRunning();
3094 closeFolder();
3095
3096 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003097 getWindow().getDecorView()
3098 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003099 }
3100
Adam Cohen7777d962011-08-18 18:58:38 -07003101 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003102 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003103 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003104 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003105 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003106 }
Adam Cohen7777d962011-08-18 18:58:38 -07003107
Adam Cohened66b2b2012-01-23 17:28:51 -08003108 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3109 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003110 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3111
Winson Chunge7a03942011-08-05 15:05:12 -07003112 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003113 @Override
3114 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003115 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003116 // Before we show workspace, hide all apps again because
3117 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3118 // clean up our state transition functions
3119 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003120 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003121 } else {
3122 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003123 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003124 }
3125 }, (extendedDelay ?
3126 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3127 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3128 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003129
Michael Jurkad3ef3062010-11-23 16:23:58 -08003130 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003131 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003132 final boolean animated = true;
3133 final boolean springLoaded = true;
3134 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003135 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003136 }
3137 // Otherwise, we are not in spring loaded mode, so don't do anything.
3138 }
3139
Michael Jurkab3e22d92011-10-31 15:58:33 -07003140 void lockAllApps() {
3141 // TODO
3142 }
3143
3144 void unlockAllApps() {
3145 // TODO
3146 }
3147
Winson Chungf0ea4d32011-06-06 14:27:16 -07003148 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003149 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003150 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003151 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003152 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003153 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003154 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003155 int duration = 0;
3156 if (mSearchDropTargetBar != null) {
3157 duration = mSearchDropTargetBar.getTransitionInDuration();
3158 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003159 mHotseat.animate().alpha(1f).setDuration(duration);
3160 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003161 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003162 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003163 }
3164 }
3165 }
3166
3167 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003168 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003169 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003170 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003171 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003172 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003173 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003174 int duration = 0;
3175 if (mSearchDropTargetBar != null) {
3176 duration = mSearchDropTargetBar.getTransitionOutDuration();
3177 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003178 mHotseat.animate().alpha(0f).setDuration(duration);
3179 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003180 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003181 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003182 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003183 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003184 }
3185
Patrick Dubroy5f445422011-02-18 14:35:21 -08003186 /**
3187 * Add an item from all apps or customize onto the given workspace screen.
3188 * If layout is null, add to the current screen.
3189 */
3190 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003191 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003192 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003193 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003194 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003195
Winson Chungdff8ebb2011-09-08 17:25:31 -07003196 /** Maps the current orientation to an index for referencing orientation correct global icons */
3197 private int getCurrentOrientationIndexForGlobalIcons() {
3198 // default - 0, landscape - 1
3199 switch (getResources().getConfiguration().orientation) {
3200 case Configuration.ORIENTATION_LANDSCAPE:
3201 return 1;
3202 default:
3203 return 0;
3204 }
3205 }
3206
Michael Jurkaae65ee32012-04-30 11:45:54 -07003207 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003208 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003209 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003210 // Look for the toolbar icon specified in the activity meta-data
3211 Bundle metaData = packageManager.getActivityInfo(
3212 activityName, PackageManager.GET_META_DATA).metaData;
3213 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003214 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003215 if (iconResId != 0) {
3216 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003217 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003218 }
3219 }
3220 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003221 // This can happen if the activity defines an invalid drawable
3222 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3223 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003224 } catch (Resources.NotFoundException nfe) {
3225 // This can happen if the activity defines an invalid drawable
3226 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3227 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003228 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003229 return null;
3230 }
3231
3232 // if successful in getting icon, return it; otherwise, set button to use default drawable
3233 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003234 int buttonId, ComponentName activityName, int fallbackDrawableId,
3235 String toolbarResourceName) {
3236 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003237 Resources r = getResources();
3238 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3239 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003240
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003241 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003242 // If we were unable to find the icon via the meta-data, use a generic one
3243 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003244 toolbarIcon = r.getDrawable(fallbackDrawableId);
3245 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003246 if (button != null) {
3247 button.setCompoundDrawables(toolbarIcon, null, null, null);
3248 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003249 return null;
3250 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003251 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003252 if (button != null) {
3253 button.setCompoundDrawables(toolbarIcon, null, null, null);
3254 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003255 return toolbarIcon.getConstantState();
3256 }
3257 }
3258
3259 // if successful in getting icon, return it; otherwise, set button to use default drawable
3260 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003261 int buttonId, ComponentName activityName, int fallbackDrawableId,
3262 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003263 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003264 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003265
Michael Jurka19e0fc52011-07-22 18:00:21 -07003266 if (button != null) {
3267 // If we were unable to find the icon via the meta-data, use a
3268 // generic one
3269 if (toolbarIcon == null) {
3270 button.setImageResource(fallbackDrawableId);
3271 } else {
3272 button.setImageDrawable(toolbarIcon);
3273 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003274 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003275
3276 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3277
Michael Jurka0423dcf2010-10-05 14:56:18 -07003278 }
3279
Winson Chung1b884092012-06-08 17:13:02 -07003280 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003281 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003282 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003283 }
3284
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003285 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003286 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003287 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003288 }
3289
Winson Chungbb185bd2011-11-21 12:31:42 -08003290 private void invalidatePressedFocusedStates(View container, View button) {
3291 if (container instanceof HolographicLinearLayout) {
3292 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3293 layout.invalidatePressedFocusedStates();
3294 } else if (button instanceof HolographicImageView) {
3295 HolographicImageView view = (HolographicImageView) button;
3296 view.invalidatePressedFocusedStates();
3297 }
3298 }
3299
Cristina Stancu476493b2013-08-07 17:20:14 +01003300 public View getQsbBar() {
3301 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003302 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3303 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003304 }
3305 return mQsbBar;
3306 }
3307
3308 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003309 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003310 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003311 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003312 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003313
Winson Chung1cad91e2011-05-25 17:41:01 -07003314 final SearchManager searchManager =
3315 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3316 ComponentName activityName = searchManager.getGlobalSearchActivity();
3317 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003318 int coi = getCurrentOrientationIndexForGlobalIcons();
3319 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003320 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3321 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3322 if (sGlobalSearchIcon[coi] == null) {
3323 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3324 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3325 TOOLBAR_ICON_METADATA_NAME);
3326 }
3327
Winson Chungc51db6a2011-10-05 11:44:49 -07003328 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3329 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003330 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003331 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003332 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003333 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003334 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3335 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003336 if (searchButton != null) searchButton.setVisibility(View.GONE);
3337 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003338 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003339 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003340 }
3341 }
3342
Cristina Stancu476493b2013-08-07 17:20:14 +01003343 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003344 final View searchButtonContainer = findViewById(R.id.search_button_container);
3345 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003346 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003347 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003348 }
3349
Cristina Stancu476493b2013-08-07 17:20:14 +01003350 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003351 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003352 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003353
Winson Chungc51db6a2011-10-05 11:44:49 -07003354 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003355 final SearchManager searchManager =
3356 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3357 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3358
3359 ComponentName activityName = null;
3360 if (globalSearchActivity != null) {
3361 // Check if the global search activity handles voice search
3362 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3363 intent.setPackage(globalSearchActivity.getPackageName());
3364 activityName = intent.resolveActivity(getPackageManager());
3365 }
3366
3367 if (activityName == null) {
3368 // Fallback: check if an activity other than the global search activity
3369 // resolves this
3370 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3371 activityName = intent.resolveActivity(getPackageManager());
3372 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003373 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003374 int coi = getCurrentOrientationIndexForGlobalIcons();
3375 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003376 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3377 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3378 if (sVoiceSearchIcon[coi] == null) {
3379 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3380 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3381 TOOLBAR_ICON_METADATA_NAME);
3382 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003383 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003384 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003385 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003386 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003387 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003388 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003389 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003390 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003391 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003392 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003393 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003394 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003395
Cristina Stancu476493b2013-08-07 17:20:14 +01003396 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003397 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3398 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003399 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003400 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003401 }
3402
Winson Chung5841efa2013-09-30 18:06:44 -07003403 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003404 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3405 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003406 boolean visible = !forceDisableVoiceButtonProxy &&
3407 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003408 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003409 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003410 }
3411 }
Winson Chung5841efa2013-09-30 18:06:44 -07003412
3413 /**
3414 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3415 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3416 */
3417 public void disableVoiceButtonProxy(boolean disabled) {
3418 updateVoiceButtonProxyVisible(disabled);
3419 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003420 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003421 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003422 */
3423 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003424 if (!DISABLE_MARKET_BUTTON) {
3425 final View marketButton = findViewById(R.id.market_button);
3426 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3427 // Find the app market activity by resolving an intent.
3428 // (If multiple app markets are installed, it will return the ResolverActivity.)
3429 ComponentName activityName = intent.resolveActivity(getPackageManager());
3430 if (activityName != null) {
3431 int coi = getCurrentOrientationIndexForGlobalIcons();
3432 mAppMarketIntent = intent;
3433 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3434 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3435 TOOLBAR_ICON_METADATA_NAME);
3436 marketButton.setVisibility(View.VISIBLE);
3437 } else {
3438 // We should hide and disable the view so that we don't try and restore the visibility
3439 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3440 marketButton.setVisibility(View.GONE);
3441 marketButton.setEnabled(false);
3442 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003443 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003444 }
3445
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003446 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003447 if (!DISABLE_MARKET_BUTTON) {
3448 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3449 Resources r = getResources();
3450 Drawable marketIconDrawable = d.newDrawable(r);
3451 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3452 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3453 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003454
Winson Chungd64a6662013-09-30 11:06:59 -07003455 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3456 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003457 }
3458
Michael Jurkad7c28052012-04-27 15:43:36 -07003459 @Override
3460 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003461 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003462 final List<CharSequence> text = event.getText();
3463 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003464 // Populate event with a fake title based on the current state.
3465 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003466 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003467 } else {
3468 text.add(getString(R.string.all_apps_home_button_label));
3469 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003470 return result;
3471 }
3472
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003473 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003474 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003475 */
3476 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3477 @Override
3478 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003479 closeSystemDialogs();
3480 }
3481 }
3482
3483 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003484 * Receives notifications whenever the appwidgets are reset.
3485 */
3486 private class AppWidgetResetObserver extends ContentObserver {
3487 public AppWidgetResetObserver() {
3488 super(new Handler());
3489 }
3490
3491 @Override
3492 public void onChange(boolean selfChange) {
3493 onAppWidgetReset();
3494 }
3495 }
3496
3497 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003498 * If the activity is currently paused, signal that we need to run the passed Runnable
3499 * in onResume.
3500 *
3501 * This needs to be called from incoming places where resources might have been loaded
3502 * while we are paused. That is becaues the Configuration might be wrong
3503 * when we're not running, and if it comes back to what it was when we
3504 * were paused, we are not restarted.
3505 *
3506 * Implementation of the method from LauncherModel.Callbacks.
3507 *
3508 * @return true if we are currently paused. The caller might be able to
3509 * skip some work in that case since we will come back again.
3510 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003511 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003512 if (mPaused) {
3513 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003514 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003515 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003516 }
3517 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003518 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003519 return true;
3520 } else {
3521 return false;
3522 }
3523 }
3524
Michael Jurkac402cd92013-05-20 15:49:32 +02003525 private boolean waitUntilResume(Runnable run) {
3526 return waitUntilResume(run, false);
3527 }
3528
Michael Jurka1e2f4652013-07-08 18:03:46 -07003529 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003530 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003531 }
3532
Michael Jurka7607c2f2013-04-03 14:33:19 -07003533 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003534 * If the activity is currently paused, signal that we need to re-run the loader
3535 * in onResume.
3536 *
3537 * This needs to be called from incoming places where resources might have been loaded
3538 * while we are paused. That is becaues the Configuration might be wrong
3539 * when we're not running, and if it comes back to what it was when we
3540 * were paused, we are not restarted.
3541 *
3542 * Implementation of the method from LauncherModel.Callbacks.
3543 *
3544 * @return true if we are currently paused. The caller might be able to
3545 * skip some work in that case since we will come back again.
3546 */
3547 public boolean setLoadOnResume() {
3548 if (mPaused) {
3549 Log.i(TAG, "setLoadOnResume");
3550 mOnResumeNeedsLoad = true;
3551 return true;
3552 } else {
3553 return false;
3554 }
3555 }
3556
3557 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003558 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003559 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003560 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003561 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003562 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003563 } else {
3564 return SCREEN_COUNT / 2;
3565 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003566 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003567
Joe Onorato9c1289c2009-08-17 11:03:03 -04003568 /**
3569 * Refreshes the shortcuts shown on the workspace.
3570 *
3571 * Implementation of the method from LauncherModel.Callbacks.
3572 */
3573 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003574 // If we're starting binding all over again, clear any bind calls we'd postponed in
3575 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3576 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003577 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003578
Winson Chungd64d1762013-08-20 14:37:16 -07003579 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003580 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003581 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003582
Michael Jurka05bf644e2011-11-30 20:28:53 -08003583 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003584 if (mHotseat != null) {
3585 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003586 }
3587 }
3588
Adam Cohendcd297f2013-06-18 13:13:40 -07003589 @Override
3590 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003591 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003592
Adam Cohen5084cba2013-09-03 12:01:16 -07003593 // If there are no screens, we need to have an empty screen
3594 if (orderedScreenIds.size() == 0) {
3595 mWorkspace.addExtraEmptyScreen();
3596 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003597
3598 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003599 // setCurrentPage() so ensure that all pages are added before calling this).
3600 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003601 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3602 mWorkspace.createCustomContentPage();
3603 }
Winson Chung64359a52013-07-08 17:17:08 -07003604 }
3605
3606 @Override
3607 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003608 int count = orderedScreenIds.size();
3609 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003610 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003611 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003612 }
3613
Adam Cohen39a06042013-07-19 14:30:12 -07003614 private boolean shouldShowWeightWatcher() {
3615 String spKey = LauncherAppState.getSharedPreferencesKey();
3616 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003617 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003618
3619 return show;
3620 }
3621
3622 private void toggleShowWeightWatcher() {
3623 String spKey = LauncherAppState.getSharedPreferencesKey();
3624 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3625 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3626
3627 show = !show;
3628
3629 SharedPreferences.Editor editor = sp.edit();
3630 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3631 editor.commit();
3632
3633 if (mWeightWatcher != null) {
3634 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3635 }
3636 }
3637
Winson Chungd64d1762013-08-20 14:37:16 -07003638 public void bindAppsAdded(final ArrayList<Long> newScreens,
3639 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003640 final ArrayList<ItemInfo> addAnimated,
3641 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003642 Runnable r = new Runnable() {
3643 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003644 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003645 }
3646 };
3647 if (waitUntilResume(r)) {
3648 return;
3649 }
3650
Winson Chungd64d1762013-08-20 14:37:16 -07003651 // Add the new screens
3652 bindAddScreens(newScreens);
3653
3654 // We add the items without animation on non-visible pages, and with
3655 // animations on the new page (which we will try and snap to).
3656 if (!addNotAnimated.isEmpty()) {
3657 bindItems(addNotAnimated, 0,
3658 addNotAnimated.size(), false);
3659 }
3660 if (!addAnimated.isEmpty()) {
3661 bindItems(addAnimated, 0,
3662 addAnimated.size(), true);
3663 }
Winson Chungc58497e2013-09-03 17:48:37 -07003664
Winson Chung87412982013-10-03 18:34:14 -07003665 // Remove the extra empty screen
3666 mWorkspace.removeExtraEmptyScreen();
3667
Winson Chungc58497e2013-09-03 17:48:37 -07003668 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3669 addedApps != null && mAppsCustomizeContent != null) {
3670 mAppsCustomizeContent.addApps(addedApps);
3671 }
Winson Chungd64d1762013-08-20 14:37:16 -07003672 }
3673
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003674 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003675 * Bind the items start-end from the list.
3676 *
3677 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003678 */
Winson Chung64359a52013-07-08 17:17:08 -07003679 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3680 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003681 Runnable r = new Runnable() {
3682 public void run() {
3683 bindItems(shortcuts, start, end, forceAnimateIcons);
3684 }
3685 };
3686 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003687 return;
3688 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003689
Winson Chungf0c6ae02012-03-21 16:10:31 -07003690 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003691 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3692 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003693 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003694 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003695 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003696 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003697 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003698
3699 // Short circuit if we are loading dock items for a configuration which has no dock
3700 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3701 mHotseat == null) {
3702 continue;
3703 }
3704
Joe Onorato9c1289c2009-08-17 11:03:03 -04003705 switch (item.itemType) {
3706 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3707 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003708 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003709 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003710
Winson Chung64359a52013-07-08 17:17:08 -07003711 /*
3712 * TODO: FIX collision case
3713 */
Winson Chungce376632013-07-11 16:12:41 -07003714 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3715 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3716 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3717 throw new RuntimeException("OCCUPIED");
3718 }
Winson Chung64359a52013-07-08 17:17:08 -07003719 }
3720
Adam Cohendcd297f2013-06-18 13:13:40 -07003721 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3722 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003723 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003724 // Animate all the applications up now
3725 shortcut.setAlpha(0f);
3726 shortcut.setScaleX(0f);
3727 shortcut.setScaleY(0f);
3728 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003729 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003730 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003731 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003732 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003733 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003734 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003735 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003736 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3737 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003738 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003739 default:
3740 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003741 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003742 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003743
Winson Chung997a9232013-07-24 15:33:46 -07003744 if (animateIcons) {
3745 // Animate to the correct page
3746 if (newShortcutsScreenId > -1) {
3747 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003748 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003749 final Runnable startBounceAnimRunnable = new Runnable() {
3750 public void run() {
3751 anim.playTogether(bounceAnims);
3752 anim.start();
3753 }
3754 };
Winson Chung997a9232013-07-24 15:33:46 -07003755 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003756 // We post the animation slightly delayed to prevent slowdowns
3757 // when we are loading right after we return to launcher.
3758 mWorkspace.postDelayed(new Runnable() {
3759 public void run() {
3760 mWorkspace.snapToPage(newScreenIndex);
Winson Chungb2323832013-10-03 15:22:09 -07003761 mWorkspace.postDelayed(startBounceAnimRunnable,
3762 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07003763 }
3764 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003765 } else {
3766 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003767 }
3768 }
Winson Chung64359a52013-07-08 17:17:08 -07003769 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003770 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003771 }
3772
Joe Onorato9c1289c2009-08-17 11:03:03 -04003773 /**
3774 * Implementation of the method from LauncherModel.Callbacks.
3775 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003776 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003777 Runnable r = new Runnable() {
3778 public void run() {
3779 bindFolders(folders);
3780 }
3781 };
3782 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003783 return;
3784 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003785 sFolders.clear();
3786 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003787 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003788
3789 /**
3790 * Add the views for a widget to the workspace.
3791 *
3792 * Implementation of the method from LauncherModel.Callbacks.
3793 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003794 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003795 Runnable r = new Runnable() {
3796 public void run() {
3797 bindAppWidget(item);
3798 }
3799 };
3800 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003801 return;
3802 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003803
Daniel Sandler843e8602010-06-07 14:59:01 -04003804 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3805 if (DEBUG_WIDGETS) {
3806 Log.d(TAG, "bindAppWidget: " + item);
3807 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003808 final Workspace workspace = mWorkspace;
3809
3810 final int appWidgetId = item.appWidgetId;
3811 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003812 if (DEBUG_WIDGETS) {
3813 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3814 }
3815
Joe Onorato9c1289c2009-08-17 11:03:03 -04003816 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3817
Joe Onorato9c1289c2009-08-17 11:03:03 -04003818 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003819 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003820
Adam Cohendcd297f2013-06-18 13:13:40 -07003821 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003822 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003823 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3824
Joe Onorato9c1289c2009-08-17 11:03:03 -04003825 workspace.requestLayout();
3826
Daniel Sandler843e8602010-06-07 14:59:01 -04003827 if (DEBUG_WIDGETS) {
3828 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3829 + (SystemClock.uptimeMillis()-start) + "ms");
3830 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003831 }
3832
Adam Cohen1462de32012-07-24 22:34:36 -07003833 public void onPageBoundSynchronously(int page) {
3834 mSynchronouslyBoundPages.add(page);
3835 }
3836
Joe Onorato9c1289c2009-08-17 11:03:03 -04003837 /**
3838 * Callback saying that there aren't any more items to bind.
3839 *
3840 * Implementation of the method from LauncherModel.Callbacks.
3841 */
Adam Cohene25af792013-06-06 23:08:25 -07003842 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003843 Runnable r = new Runnable() {
3844 public void run() {
3845 finishBindingItems(upgradePath);
3846 }
3847 };
3848 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003849 return;
3850 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003851 if (mSavedState != null) {
3852 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003853 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003854 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003855 mSavedState = null;
3856 }
3857
Adam Cohen1462de32012-07-24 22:34:36 -07003858 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003859
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003860 // If we received the result of any pending adds while the loader was running (e.g. the
3861 // widget configuration forced an orientation change), process them now.
3862 for (int i = 0; i < sPendingAddList.size(); i++) {
3863 completeAdd(sPendingAddList.get(i));
3864 }
3865 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003866
Winson Chungc51db6a2011-10-05 11:44:49 -07003867 // Update the market app icon as necessary (the other icons will be managed in response to
3868 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003869 if (!DISABLE_MARKET_BUTTON) {
3870 updateAppMarketIcon();
3871 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003872
Winson Chungf0c6ae02012-03-21 16:10:31 -07003873 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003874 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003875 mWorkspace.getUniqueComponents(true, null);
3876 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003877 }
Adam Cohen99894d92013-06-14 11:22:59 -07003878
Adam Cohen66a01fd2013-06-11 12:48:00 -07003879 mWorkspace.post(new Runnable() {
3880 @Override
3881 public void run() {
3882 onFinishBindingItems();
3883 }
3884 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003885 }
3886
Winson Chunga0b7e862013-09-05 16:03:15 -07003887 public boolean isAllAppsButtonRank(int rank) {
3888 if (mHotseat != null) {
3889 return mHotseat.isAllAppsButtonRank(rank);
3890 }
3891 return false;
3892 }
3893
Winson Chunga2413752012-04-03 14:22:34 -07003894 private boolean canRunNewAppsAnimation() {
3895 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3896 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3897 }
3898
Winson Chungc9168342013-06-26 14:54:55 -07003899 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3900 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3901 PropertyValuesHolder.ofFloat("alpha", 1f),
3902 PropertyValuesHolder.ofFloat("scaleX", 1f),
3903 PropertyValuesHolder.ofFloat("scaleY", 1f));
3904 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3905 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3906 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3907 return bounceAnim;
3908 }
3909
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003910 @Override
3911 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003912 boolean searchVisible = updateGlobalSearchIcon();
3913 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003914 if (mSearchDropTargetBar != null) {
3915 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3916 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003917 }
3918
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003919 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003920 * Add the icons for all apps.
3921 *
3922 * Implementation of the method from LauncherModel.Callbacks.
3923 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003924 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003925 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3926 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3927 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3928 getHotseat().addAllAppsFolder(mIconCache, apps,
3929 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3930 }
3931 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003932 }
Winson Chungc58497e2013-09-03 17:48:37 -07003933 } else {
3934 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3935 mAppsCustomizeContent != null) {
3936 mAppsCustomizeContent.setApps(apps);
3937 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003938 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003939 }
3940
3941 /**
3942 * A package was updated.
3943 *
3944 * Implementation of the method from LauncherModel.Callbacks.
3945 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003946 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003947 Runnable r = new Runnable() {
3948 public void run() {
3949 bindAppsUpdated(apps);
3950 }
3951 };
3952 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003953 return;
3954 }
3955
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003956 if (mWorkspace != null) {
3957 mWorkspace.updateShortcuts(apps);
3958 }
Winson Chungc58497e2013-09-03 17:48:37 -07003959
3960 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3961 mAppsCustomizeContent != null) {
3962 mAppsCustomizeContent.updateApps(apps);
3963 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003964 }
3965
3966 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003967 * A package was uninstalled. We take both the super set of packageNames
3968 * in addition to specific applications to remove, the reason being that
3969 * this can be called when a package is updated as well. In that scenario,
3970 * we only remove specific components from the workspace, where as
3971 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003972 *
3973 * Implementation of the method from LauncherModel.Callbacks.
3974 */
Winson Chung83892cc2013-05-01 16:53:33 -07003975 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003976 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003977 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003978 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003979 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003980 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003981 }
Winson Chungd64d1762013-08-20 14:37:16 -07003982 };
3983 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003984 return;
3985 }
3986
Winson Chung64359a52013-07-08 17:17:08 -07003987 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003988 mWorkspace.removeItemsByPackageName(packageNames);
3989 } else {
3990 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003991 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003992
Winson Chunga1820962011-10-03 16:31:06 -07003993 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003994 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003995
3996 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3997 mAppsCustomizeContent != null) {
3998 mAppsCustomizeContent.removeApps(appInfos);
3999 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004000 }
Joe Onoratobe386092009-11-17 17:32:16 -08004001
4002 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004003 * A number of packages were updated.
4004 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004005 private ArrayList<Object> mWidgetsAndShortcuts;
4006 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004007 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004008 bindPackagesUpdated(mWidgetsAndShortcuts);
4009 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004010 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004011 };
4012
4013 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4014 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4015 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004016 return;
4017 }
4018
Winson Chung64359a52013-07-08 17:17:08 -07004019 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07004020 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4021 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004022 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004023 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004024 }
4025
Winson Chung400438b2011-01-16 17:53:48 -08004026 private int mapConfigurationOriActivityInfoOri(int configOri) {
4027 final Display d = getWindowManager().getDefaultDisplay();
4028 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4029 switch (d.getRotation()) {
4030 case Surface.ROTATION_0:
4031 case Surface.ROTATION_180:
4032 // We are currently in the same basic orientation as the natural orientation
4033 naturalOri = configOri;
4034 break;
4035 case Surface.ROTATION_90:
4036 case Surface.ROTATION_270:
4037 // We are currently in the other basic orientation to the natural orientation
4038 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4039 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4040 break;
4041 }
4042
4043 int[] oriMap = {
4044 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4045 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4046 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4047 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4048 };
4049 // Since the map starts at portrait, we need to offset if this device's natural orientation
4050 // is landscape.
4051 int indexOffset = 0;
4052 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4053 indexOffset = 1;
4054 }
4055 return oriMap[(d.getRotation() + indexOffset) % 4];
4056 }
Adam Cohen446e9402011-09-15 18:21:21 -07004057
Winson Chung4b919f82012-05-01 10:44:08 -07004058 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004059 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004060 getResources().getBoolean(R.bool.allow_rotation);
4061 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004062 }
Winson Chung4b919f82012-05-01 10:44:08 -07004063 public void lockScreenOrientation() {
4064 if (isRotationEnabled()) {
4065 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4066 .getConfiguration().orientation));
4067 }
4068 }
4069 public void unlockScreenOrientation(boolean immediate) {
4070 if (isRotationEnabled()) {
4071 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004072 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004073 } else {
4074 mHandler.postDelayed(new Runnable() {
4075 public void run() {
4076 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4077 }
4078 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004079 }
Winson Chung4b919f82012-05-01 10:44:08 -07004080 }
Winson Chung400438b2011-01-16 17:53:48 -08004081 }
4082
Winson Chung82f55532011-08-09 14:14:23 -07004083 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004084 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004085 if (DISABLE_CLINGS) {
4086 return false;
4087 }
4088
Brett Chabot2a9e2282011-08-23 15:03:13 -07004089 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004090 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004091
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -07004092 // Disable clings for accessibility when explore by touch is enabled
4093 final AccessibilityManager a11yManager = (AccessibilityManager) getSystemService(
4094 ACCESSIBILITY_SERVICE);
4095 if (a11yManager.isTouchExplorationEnabled()) {
4096 return false;
4097 }
4098
Michael Jurkae233a8b2013-03-19 13:49:20 +01004099 // Restricted secondary users (child mode) will potentially have very few apps
4100 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004101// boolean supportsLimitedUsers =
4102// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4103// Account[] accounts = AccountManager.get(this).getAccounts();
4104// if (supportsLimitedUsers && accounts.length == 0) {
4105// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4106// Bundle restrictions = um.getUserRestrictions();
4107// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4108// return false;
4109// }
4110// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004111 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004112 }
Michael Jurka22143132012-10-04 17:42:38 +02004113
Winson Chungfa545132013-09-26 17:45:32 -07004114 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004115 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004116 Cling cling = (Cling) findViewById(clingId);
4117 View scrim = null;
4118 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004119 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004120 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004121 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004122 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004123 cling.show(animate, SHOW_CLING_DURATION);
4124
4125 if (dimNavBarVisibilty) {
4126 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4127 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004128 }
4129 }
4130 return cling;
4131 }
Michael Jurka22143132012-10-04 17:42:38 +02004132
Winson Chungaf40f202013-09-18 18:26:31 -07004133 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4134 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004135 // To catch cases where siblings of top-level views are made invisible, just check whether
4136 // the cling is directly set to GONE before dismissing it.
4137 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004138 final Runnable cleanUpClingCb = new Runnable() {
4139 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004140 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004141 // We should update the shared preferences on a background thread
4142 new Thread("dismissClingThread") {
4143 public void run() {
4144 SharedPreferences.Editor editor = mSharedPrefs.edit();
4145 editor.putBoolean(flag, true);
4146 editor.commit();
4147 }
4148 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004149 if (postAnimationCb != null) {
4150 postAnimationCb.run();
4151 }
4152 }
4153 };
4154 if (duration <= 0) {
4155 cleanUpClingCb.run();
4156 } else {
4157 cling.hide(duration, cleanUpClingCb);
4158 }
Michael Jurka22143132012-10-04 17:42:38 +02004159 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004160
4161 if (restoreNavBarVisibilty) {
4162 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4163 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4164 }
Winson Chung82f55532011-08-09 14:14:23 -07004165 }
4166 }
Michael Jurka22143132012-10-04 17:42:38 +02004167
Winson Chung9d9d74f2011-09-19 11:49:12 -07004168 private void removeCling(int id) {
4169 final View cling = findViewById(id);
4170 if (cling != null) {
4171 final ViewGroup parent = (ViewGroup) cling.getParent();
4172 parent.post(new Runnable() {
4173 @Override
4174 public void run() {
4175 parent.removeView(cling);
4176 }
4177 });
Michael Jurka22143132012-10-04 17:42:38 +02004178 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004179 }
4180 }
Michael Jurka974c3862012-05-22 22:00:31 -07004181
4182 private boolean skipCustomClingIfNoAccounts() {
4183 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4184 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4185 if (customCling) {
4186 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004187 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004188 Account[] accounts = am.getAccountsByType("com.google");
4189 return accounts.length == 0;
4190 }
4191 return false;
4192 }
4193
Winson Chungaf40f202013-09-18 18:26:31 -07004194 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004195 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004196 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004197 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004198 // If we're not using the default workspace layout, replace workspace cling
4199 // with a custom workspace cling (usually specified in an overlay)
4200 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004201 if (!DISABLE_CUSTOM_CLINGS) {
4202 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4203 getResources().getBoolean(R.bool.config_useCustomClings)) {
4204 // Use a custom cling
4205 View cling = findViewById(R.id.workspace_cling);
4206 ViewGroup clingParent = (ViewGroup) cling.getParent();
4207 int clingIndex = clingParent.indexOfChild(cling);
4208 clingParent.removeViewAt(clingIndex);
4209 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4210 clingParent.addView(customCling, clingIndex);
4211 customCling.setId(R.id.workspace_cling);
4212 }
4213 }
4214 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4215 if (cling != null) {
4216 String sbHintStr = getFirstRunClingSearchBarHint();
4217 String ccHintStr = getFirstRunCustomContentHint();
4218 if (!sbHintStr.isEmpty()) {
4219 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4220 sbHint.setText(sbHintStr);
4221 sbHint.setVisibility(View.VISIBLE);
4222 }
4223 if (!ccHintStr.isEmpty()) {
4224 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4225 ccHint.setText(ccHintStr);
4226 ccHint.setVisibility(View.VISIBLE);
4227 }
Michael Jurka45355c42012-10-08 13:21:35 +02004228 }
Winson Chungfa545132013-09-26 17:45:32 -07004229 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004230 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004231 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004232 }
4233 }
Winson Chungaf40f202013-09-18 18:26:31 -07004234
Winson Chunge6eabff2013-09-24 11:01:23 -07004235 protected String getFirstRunClingSearchBarHint() {
4236 return "";
4237 }
4238 protected String getFirstRunCustomContentHint() {
4239 return "";
4240 }
4241
Winson Chungaf40f202013-09-18 18:26:31 -07004242 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004243 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004244 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004245 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004246 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004247 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004248 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004249 }
4250 }
4251 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004252 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004253 if (isClingsEnabled() &&
4254 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004255 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4256 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004257 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004258 } else {
4259 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004260 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004261 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004262 }
Michael Jurka104c4562013-07-08 18:03:46 -07004263 protected SharedPreferences getSharedPrefs() {
4264 return mSharedPrefs;
4265 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004266 public boolean isFolderClingVisible() {
4267 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004268 if (cling != null) {
4269 return cling.getVisibility() == View.VISIBLE;
4270 }
4271 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004272 }
Winson Chungaf40f202013-09-18 18:26:31 -07004273 public void dismissFirstRunCling(View v) {
4274 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4275 Runnable cb = new Runnable() {
4276 public void run() {
4277 // Show the workspace cling next
4278 showFirstRunWorkspaceCling();
4279 }
4280 };
4281 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4282 DISMISS_CLING_DURATION, false);
4283 }
Winson Chung82f55532011-08-09 14:14:23 -07004284 public void dismissWorkspaceCling(View v) {
4285 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004286 Runnable cb = null;
4287 if (v == null) {
4288 cb = new Runnable() {
4289 public void run() {
4290 mWorkspace.enterOverviewMode();
4291 }
4292 };
4293 }
4294 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4295 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004296 }
4297 public void dismissFolderCling(View v) {
4298 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004299 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4300 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004301 }
4302
Winson Chung80baf5a2010-08-09 16:03:15 -07004303 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004304 * Prints out out state for debugging.
4305 */
4306 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004307 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004308 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004309 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4310 Log.d(TAG, "mRestoring=" + mRestoring);
4311 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4312 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004313 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004314 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004315
Winson Chung785d2eb2011-04-14 16:08:02 -07004316 if (mAppsCustomizeContent != null) {
4317 mAppsCustomizeContent.dumpState();
4318 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004319 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004320 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004321
4322 @Override
4323 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4324 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004325 synchronized (sDumpLogs) {
4326 writer.println(" ");
4327 writer.println("Debug logs: ");
4328 for (int i = 0; i < sDumpLogs.size(); i++) {
4329 writer.println(" " + sDumpLogs.get(i));
4330 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004331 }
4332 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004333
4334 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004335 if (DEBUG_DUMP_LOG) {
4336 synchronized (sDumpLogs) {
4337 Log.d(TAG, "");
4338 Log.d(TAG, "*********************");
4339 Log.d(TAG, "Launcher debug logs: ");
4340 for (int i = 0; i < sDumpLogs.size(); i++) {
4341 Log.d(TAG, " " + sDumpLogs.get(i));
4342 }
4343 Log.d(TAG, "*********************");
4344 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004345 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004346 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004347 }
4348
4349 public static void addDumpLog(String tag, String log, boolean debugLog) {
4350 if (debugLog) {
4351 Log.d(tag, log);
4352 }
Winson Chungede41292013-09-19 16:27:36 -07004353 if (DEBUG_DUMP_LOG) {
4354 sDateStamp.setTime(System.currentTimeMillis());
4355 synchronized (sDumpLogs) {
4356 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004357 }
Winson Chungede41292013-09-19 16:27:36 -07004358 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004359 }
4360
Winson Chungede41292013-09-19 16:27:36 -07004361 public void dumpLogsToLocalData() {
4362 if (DEBUG_DUMP_LOG) {
4363 new Thread("DumpLogsToLocalData") {
4364 @Override
4365 public void run() {
4366 boolean success = false;
4367 sDateStamp.setTime(sRunStart);
4368 String FILENAME = sDateStamp.getMonth() + "-"
4369 + sDateStamp.getDay() + "_"
4370 + sDateStamp.getHours() + "-"
4371 + sDateStamp.getMinutes() + "_"
4372 + sDateStamp.getSeconds() + ".txt";
4373
4374 FileOutputStream fos = null;
4375 File outFile = null;
4376 try {
4377 outFile = new File(getFilesDir(), FILENAME);
4378 outFile.createNewFile();
4379 fos = new FileOutputStream(outFile);
4380 } catch (Exception e) {
4381 e.printStackTrace();
4382 }
4383 if (fos != null) {
4384 PrintWriter writer = new PrintWriter(fos);
4385
4386 writer.println(" ");
4387 writer.println("Debug logs: ");
4388 synchronized (sDumpLogs) {
4389 for (int i = 0; i < sDumpLogs.size(); i++) {
4390 writer.println(" " + sDumpLogs.get(i));
4391 }
4392 }
4393 writer.close();
4394 }
4395 try {
4396 if (fos != null) {
4397 fos.close();
4398 success = true;
4399 }
4400 } catch (IOException e) {
4401 e.printStackTrace();
4402 }
4403 }
4404 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004405 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004406 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004407}
Michael Jurka2763be32011-02-24 11:19:57 -08004408
Michael Jurkaabded662011-03-04 12:06:57 -08004409interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004410 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004411 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004412 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004413 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004414 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004415}