blob: 5aec399b5bbc7eb591239b5ab71d9ff33e8d8b5f [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 Sandler6053b802013-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;
Adam Cohened307df2013-10-02 09:37:31 -0700273 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800274 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700275 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700276 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400277
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700278 private static LocaleConfiguration sLocaleConfiguration = null;
279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700281
Adam Cohen61f560d2013-09-30 15:58:20 -0700282 private View.OnTouchListener mHapticFeedbackTouchListener;
283
Adam Cohended9f8d2010-11-03 13:25:16 -0700284 // Related to the auto-advancing of widgets
285 private final int ADVANCE_MSG = 1;
286 private final int mAdvanceInterval = 20000;
287 private final int mAdvanceStagger = 250;
288 private long mAutoAdvanceSentTime;
289 private long mAutoAdvanceTimeLeft = -1;
290 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
291 new HashMap<View, AppWidgetProviderInfo>();
292
Winson Chung400438b2011-01-16 17:53:48 -0800293 // Determines how long to wait after a rotation before restoring the screen orientation to
294 // match the sensor state.
295 private final int mRestoreScreenOrientationDelay = 500;
296
Michael Jurka4ef207b2010-11-29 17:05:45 -0800297 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700298 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
299 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
300 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800301
Winson Chungd64a6662013-09-30 11:06:59 -0700302 private Intent mAppMarketIntent = null;
303 private static final boolean DISABLE_MARKET_BUTTON = true;
304
Craig Mautner360310b2012-10-26 15:13:08 -0700305 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700306
Adam Cohen1462de32012-07-24 22:34:36 -0700307 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
308
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700309 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700310 static Date sDateStamp = new Date();
311 static DateFormat sDateFormat =
312 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
313 static long sRunStart = System.currentTimeMillis();
314 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700315
Winson Chung46353de2012-02-16 14:05:10 -0800316 // We only want to get the SharedPreferences once since it does an FS stat each time we get
317 // it from the context.
318 private SharedPreferences mSharedPrefs;
319
Adam Cohene25af792013-06-06 23:08:25 -0700320 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
321
Winson Chungf0c6ae02012-03-21 16:10:31 -0700322 // Holds the page that we need to animate to, and the icon views that we need to animate up
323 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700324 private ImageView mFolderIconImageView;
325 private Bitmap mFolderIconBitmap;
326 private Canvas mFolderIconCanvas;
327 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700328
Michael Jurkaddd62e92011-02-16 17:49:14 -0800329 private BubbleTextView mWaitingForResume;
330
John Spurlockd4507ee2013-10-04 14:38:05 -0400331 protected TranslucentDecor mTransparentDecor;
Michael Jurka7267fa52013-09-26 15:29:57 -0700332
Michael Jurka22143132012-10-04 17:42:38 +0200333 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
334 = new HideFromAccessibilityHelper();
335
Michael Jurkac1f5d262011-09-30 19:32:27 -0700336 private Runnable mBuildLayersRunnable = new Runnable() {
337 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700338 if (mWorkspace != null) {
339 mWorkspace.buildPageHardwareLayers();
340 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700341 }
342 };
343
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800344 private static ArrayList<PendingAddArguments> sPendingAddList
345 = new ArrayList<PendingAddArguments>();
346
Michael Jurka7267fa52013-09-26 15:29:57 -0700347 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800348
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800349 private static class PendingAddArguments {
350 int requestCode;
351 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700352 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700353 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800354 int cellX;
355 int cellY;
356 }
357
Daniel Sandlerff02d492013-08-05 02:12:05 -0400358 private Stats mStats;
359
Michael Jurka0a457bf2012-11-19 14:05:05 -0800360 private static boolean isPropertyEnabled(String propertyName) {
361 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700362 }
363
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 @Override
365 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700366 if (DEBUG_STRICT_MODE) {
367 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
368 .detectDiskReads()
369 .detectDiskWrites()
370 .detectNetwork() // or .detectAll() for all detectable problems
371 .penaltyLog()
372 .build());
373 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
374 .detectLeakedSqlLiteObjects()
375 .detectLeakedClosableObjects()
376 .penaltyLog()
377 .penaltyDeath()
378 .build());
379 }
380
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400382
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400383 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400384 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700385
386 // Determine the dynamic grid properties
387 Point smallestSize = new Point();
388 Point largestSize = new Point();
389 Point realSize = new Point();
390 Display display = getWindowManager().getDefaultDisplay();
391 display.getCurrentSizeRange(smallestSize, largestSize);
392 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700393 DisplayMetrics dm = new DisplayMetrics();
394 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700395 // Lazy-initialize the dynamic grid
396 DeviceProfile grid = app.initDynamicGrid(this,
397 Math.min(smallestSize.x, smallestSize.y),
398 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700399 realSize.x, realSize.y,
400 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700401
402 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400403 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700404 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800405 mModel = app.setLauncher(this);
406 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400407 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700409
Daniel Sandlerff02d492013-08-05 02:12:05 -0400410 mStats = new Stats(this);
411
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700412 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700413
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700414 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
415 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700416
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700417 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
418 // this also ensures that any synchronous binding below doesn't re-trigger another
419 // LauncherModel load.
420 mPaused = false;
421
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200423 android.os.Debug.startMethodTracing(
424 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 }
426
Adam Cohen53805212013-10-01 10:39:23 -0700427
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800429 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700430
John Spurlockd4507ee2013-10-04 14:38:05 -0400431 mTransparentDecor = new TranslucentDecor(findViewById(R.id.launcher));
432 mTransparentDecor.requestTranslucentDecor(true);
Michael Jurka7267fa52013-09-26 15:29:57 -0700433
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800434 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100435 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800437 registerContentObservers();
438
Joe Onorato7c312c12009-08-13 21:36:53 -0700439 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700440
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 mSavedState = savedInstanceState;
442 restoreState(mSavedState);
443
Winson Chunga12a2502010-12-20 14:41:35 -0800444 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700445 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200446 mAppsCustomizeContent.onPackagesUpdated(
447 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700448 }
Winson Chunga12a2502010-12-20 14:41:35 -0800449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 if (PROFILE_STARTUP) {
451 android.os.Debug.stopMethodTracing();
452 }
453
454 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700455 if (sPausedFromUserAction) {
456 // If the user leaves launcher, then we should just load items asynchronously when
457 // they return.
458 mModel.startLoader(true, -1);
459 } else {
460 // We only load the page synchronously if the user rotates (or triggers a
461 // configuration change) while launcher is in the foreground
462 mModel.startLoader(true, mWorkspace.getCurrentPage());
463 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464 }
465
466 // For handling default keys
467 mDefaultKeySsb = new SpannableStringBuilder();
468 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800469
470 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
471 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800472
Adam Cohenf9426d52012-06-04 17:26:21 -0700473 updateGlobalIcons();
474
475 // On large interfaces, we want the screen to auto-rotate based on the current orientation
476 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700477
478 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700479 }
480
Winson Chung4a2afa32012-07-19 14:53:05 -0700481 protected void onUserLeaveHint() {
482 super.onUserLeaveHint();
483 sPausedFromUserAction = true;
484 }
485
Winson Chung98ca0f72013-07-29 12:58:51 -0700486 /** To be overriden by subclasses to hint to Launcher that we have custom content */
487 protected boolean hasCustomContentToLeft() {
488 return false;
489 }
490
Dave Hawkeya8881582013-09-17 15:55:33 -0600491 /**
492 * To be overridden by subclasses to create the custom content and call
493 * {@link #addToCustomContentPage}. This will only be invoked if
494 * {@link #hasCustomContentToLeft()} is {@code true}.
495 */
496 protected void addCustomContentToLeft() {
497 }
498
499 /**
500 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
501 * ensure the custom content page is added or removed if necessary.
502 */
503 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600504 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600505 // Not bound yet, wait for bindScreens to be called.
506 return;
507 }
508
509 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
510 // Create the custom content page and call the subclass to populate it.
511 mWorkspace.createCustomContentPage();
512 addCustomContentToLeft();
513 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
514 mWorkspace.removeCustomContentPage();
515 }
516 }
517
Adam Cohenf9426d52012-06-04 17:26:21 -0700518 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700519 boolean searchVisible = false;
520 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800521 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700522 int coi = getCurrentOrientationIndexForGlobalIcons();
523 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
524 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700525 if (!DISABLE_MARKET_BUTTON) {
526 updateAppMarketIcon();
527 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700528 searchVisible = updateGlobalSearchIcon();
529 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700530 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700531 if (sGlobalSearchIcon[coi] != null) {
532 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700533 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700534 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700535 if (sVoiceSearchIcon[coi] != null) {
536 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700537 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700538 }
Winson Chungd64a6662013-09-30 11:06:59 -0700539 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700540 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800541 }
Winson Chungadf0c182012-08-23 14:59:07 -0700542 if (mSearchDropTargetBar != null) {
543 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
544 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800545 }
Romain Guycbb89e42009-06-08 15:52:54 -0700546
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800547 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700548 if (sLocaleConfiguration == null) {
549 new AsyncTask<Void, Void, LocaleConfiguration>() {
550 @Override
551 protected LocaleConfiguration doInBackground(Void... unused) {
552 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
553 readConfiguration(Launcher.this, localeConfiguration);
554 return localeConfiguration;
555 }
556
557 @Override
558 protected void onPostExecute(LocaleConfiguration result) {
559 sLocaleConfiguration = result;
560 checkForLocaleChange(); // recursive, but now with a locale configuration
561 }
562 }.execute();
563 return;
564 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700565
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566 final Configuration configuration = getResources().getConfiguration();
567
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700568 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800569 final String locale = configuration.locale.toString();
570
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700571 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800572 final int mcc = configuration.mcc;
573
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 final int mnc = configuration.mnc;
576
Romain Guy84f296c2009-11-04 15:00:44 -0800577 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800578
Romain Guy84f296c2009-11-04 15:00:44 -0800579 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700580 sLocaleConfiguration.locale = locale;
581 sLocaleConfiguration.mcc = mcc;
582 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700583
Joe Onorato0589f0f2010-02-08 13:44:00 -0800584 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700585
586 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
587 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700588 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700589 public void run() {
590 writeConfiguration(Launcher.this, localeConfiguration);
591 }
592 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700593 }
594 }
595
596 private static class LocaleConfiguration {
597 public String locale;
598 public int mcc = -1;
599 public int mnc = -1;
600 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700601
Romain Guy98d01652009-06-30 16:21:04 -0700602 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
603 DataInputStream in = null;
604 try {
605 in = new DataInputStream(context.openFileInput(PREFERENCES));
606 configuration.locale = in.readUTF();
607 configuration.mcc = in.readInt();
608 configuration.mnc = in.readInt();
609 } catch (FileNotFoundException e) {
610 // Ignore
611 } catch (IOException e) {
612 // Ignore
613 } finally {
614 if (in != null) {
615 try {
616 in.close();
617 } catch (IOException e) {
618 // Ignore
619 }
620 }
621 }
622 }
623
624 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
625 DataOutputStream out = null;
626 try {
627 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
628 out.writeUTF(configuration.locale);
629 out.writeInt(configuration.mcc);
630 out.writeInt(configuration.mnc);
631 out.flush();
632 } catch (FileNotFoundException e) {
633 // Ignore
634 } catch (IOException e) {
635 //noinspection ResultOfMethodCallIgnored
636 context.getFileStreamPath(PREFERENCES).delete();
637 } finally {
638 if (out != null) {
639 try {
640 out.close();
641 } catch (IOException e) {
642 // Ignore
643 }
644 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800645 }
646 }
647
Anton Hanssona2f665f2013-09-26 12:18:32 +0100648 public Stats getStats() {
649 return mStats;
650 }
651
Bjorn Bringertc459e522013-06-07 19:36:01 +0100652 public LayoutInflater getInflater() {
653 return mInflater;
654 }
655
Adam Cohen716b51e2011-06-30 12:09:54 -0700656 public DragLayer getDragLayer() {
657 return mDragLayer;
658 }
659
Winson Chung36a62fe2012-05-06 18:04:42 -0700660 boolean isDraggingEnabled() {
661 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
662 // that is subsequently removed from the workspace in startBinding().
663 return !mModel.isLoadingWorkspace();
664 }
665
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 static int getScreen() {
667 synchronized (sLock) {
668 return sScreen;
669 }
670 }
671
672 static void setScreen(int screen) {
673 synchronized (sLock) {
674 sScreen = screen;
675 }
676 }
677
Winson Chung557d6ed2011-07-08 15:34:52 -0700678 /**
679 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
680 * a configuration step, this allows the proper animations to run after other transitions.
681 */
682 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700683 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800684 switch (args.requestCode) {
685 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700686 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700687 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800688 break;
689 case REQUEST_PICK_SHORTCUT:
690 processShortcut(args.intent);
691 break;
692 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700693 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700694 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700695 result = true;
696 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800697 case REQUEST_CREATE_APPWIDGET:
698 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700699 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700700 result = true;
701 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800702 }
Michael Jurka27614d22012-04-02 06:40:22 -0700703 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
704 // if you turned the screen off and then back while in All Apps, Launcher would not
705 // return to the workspace. Clearing mAddInfo.container here fixes this issue
706 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700707 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800708 }
709
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800710 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700711 protected void onActivityResult(
712 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700713 // Reset the startActivity waiting flag
714 mWaitingForResult = false;
715
Michael Jurka8b805b12012-04-18 14:23:14 -0700716 if (requestCode == REQUEST_BIND_APPWIDGET) {
717 int appWidgetId = data != null ?
718 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
719 if (resultCode == RESULT_CANCELED) {
720 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
721 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700722 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700723 }
724 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200725 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
726 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
727 mWorkspace.exitOverviewMode(false);
728 }
729 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700730 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200731
Winson Chung557d6ed2011-07-08 15:34:52 -0700732 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800733 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
734 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700735
Adam Cohened66b2b2012-01-23 17:28:51 -0800736 // We have special handling for widgets
737 if (isWidgetDrop) {
738 int appWidgetId = data != null ?
739 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700740 if (appWidgetId < 0) {
741 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
742 "widget configuration activity.");
743 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
744 } else {
745 completeTwoStageWidgetDrop(resultCode, appWidgetId);
746 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800747 return;
748 }
749
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 // The pattern used here is that a user PICKs a specific application,
751 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700752
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800753 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
754 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700755 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800756 final PendingAddArguments args = new PendingAddArguments();
757 args.requestCode = requestCode;
758 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700759 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700760 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700761 args.cellX = mPendingAddInfo.cellX;
762 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800763 if (isWorkspaceLocked()) {
764 sPendingAddList.add(args);
765 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700766 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800767 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800768 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800769 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700770 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800771 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
772 null);
773 }
774
775 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700776 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700777 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800778 Runnable onCompleteRunnable = null;
779 int animationType = 0;
780
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700781 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800782 if (resultCode == RESULT_OK) {
783 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
784 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700785 mPendingAddWidgetInfo);
786 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800787 onCompleteRunnable = new Runnable() {
788 @Override
789 public void run() {
790 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700791 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800792 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
793 null);
794 }
795 };
796 } else if (resultCode == RESULT_CANCELED) {
797 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
798 onCompleteRunnable = new Runnable() {
799 @Override
800 public void run() {
801 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
802 null);
803 }
804 };
805 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700806 if (mDragLayer.getAnimatedView() != null) {
807 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
808 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
809 animationType, boundWidget, true);
810 } else {
811 // The animated view may be null in the case of a rotation during widget configuration
812 onCompleteRunnable.run();
813 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800814 }
815
816 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700817 protected void onStop() {
818 super.onStop();
819 FirstFrameAnimatorHelper.setIsVisible(false);
820 }
821
822 @Override
823 protected void onStart() {
824 super.onStart();
825 FirstFrameAnimatorHelper.setIsVisible(true);
826 }
827
828 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800829 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200830 long startTime = 0;
831 if (DEBUG_RESUME_TIME) {
832 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400833 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200834 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800835 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700836
Winson Chung4a2afa32012-07-19 14:53:05 -0700837 // Restore the previous launcher state
838 if (mOnResumeState == State.WORKSPACE) {
839 showWorkspace(false);
840 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700841 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700842 }
843 mOnResumeState = State.NONE;
844
Craig Mautner360310b2012-10-26 15:13:08 -0700845 // Background was set to gradient in onPause(), restore to black if in all apps.
846 setWorkspaceBackground(mState == State.WORKSPACE);
847
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800848 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700849 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700850 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400851 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700852 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400853 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700854 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700856 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200857 // We might have postponed some bind calls until onResume (see waitUntilResume) --
858 // execute them here
859 long startTimeCallbacks = 0;
860 if (DEBUG_RESUME_TIME) {
861 startTimeCallbacks = System.currentTimeMillis();
862 }
863
864 if (mAppsCustomizeContent != null) {
865 mAppsCustomizeContent.setBulkBind(true);
866 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700867 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
868 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200869 }
870 if (mAppsCustomizeContent != null) {
871 mAppsCustomizeContent.setBulkBind(false);
872 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700873 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200874 if (DEBUG_RESUME_TIME) {
875 Log.d(TAG, "Time spent processing callbacks in onResume: " +
876 (System.currentTimeMillis() - startTimeCallbacks));
877 }
Michael Jurka447bf842013-05-15 14:52:15 +0200878 }
Michael Jurka54554252013-08-01 12:52:23 +0200879 if (mOnResumeCallbacks.size() > 0) {
880 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
881 mOnResumeCallbacks.get(i).run();
882 }
883 mOnResumeCallbacks.clear();
884 }
Winson Chunge4e50662012-01-23 14:45:13 -0800885
886 // Reset the pressed state of icons that were locked in the press state while activities
887 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800888 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800889 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800890 mWaitingForResume.setStayPressed(false);
891 }
Winson Chunge4e50662012-01-23 14:45:13 -0800892 if (mAppsCustomizeContent != null) {
893 // Resets the previous all apps icon press state
894 mAppsCustomizeContent.resetDrawableState();
895 }
Winson Chung780fe592013-09-26 14:48:44 -0700896 // Reset AllApps to its initial state
897 if (mAppsCustomizeTabHost != null) {
898 mAppsCustomizeTabHost.reset();
899 }
Adam Cohen06dff352012-06-01 17:17:08 -0700900 // It is possible that widgets can receive updates while launcher is not in the foreground.
901 // Consequently, the widgets will be inflated in the orientation of the foreground activity
902 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
903 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700904 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700905
Winson Chung780fe592013-09-26 14:48:44 -0700906 // Process any items that were added while Launcher was away.
907 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
908
Winson Chung5841efa2013-09-30 18:06:44 -0700909 // Update the voice search button proxy
910 updateVoiceButtonProxyVisible(false);
911
Adam Cohenf9426d52012-06-04 17:26:21 -0700912 // Again, as with the above scenario, it's possible that one or more of the global icons
913 // were updated in the wrong orientation.
914 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200915 if (DEBUG_RESUME_TIME) {
916 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
917 }
Adam Cohen6fecd412013-10-02 17:41:50 -0700918
919 if (mWorkspace.getCustomContentCallbacks() != null) {
920 // If we are resuming and the custom content is the current page, we call onShow().
921 // It is also poassible that onShow will instead be called slightly after first layout
922 // if PagedView#setRestorePage was set to the custom content page in onCreate().
923 if (mWorkspace.isOnOrMovingToCustomContent()) {
924 mWorkspace.getCustomContentCallbacks().onShow();
925 }
926 }
Adam Cohenedaaa302013-10-01 17:33:27 -0700927 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -0700928 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -0700929 }
930
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800931 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700932 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700933 // Ensure that items added to Launcher are queued until Launcher returns
934 InstallShortcutReceiver.enableInstallQueue();
935
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700936 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700937 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800938 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700939 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -0700940
941 // We call onHide() aggressively. The custom content callbacks should be able to
942 // debounce excess onHide calls.
943 if (mWorkspace.getCustomContentCallbacks() != null) {
944 mWorkspace.getCustomContentCallbacks().onHide();
945 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700946 }
Romain Guycbb89e42009-06-08 15:52:54 -0700947
Adam Cohen66a01fd2013-06-11 12:48:00 -0700948 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -0700949 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600950 addCustomContentToLeft();
951 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700952 }
953
Adam Cohenbffe7452013-07-22 18:21:45 -0700954 QSBScroller mQsbScroller = new QSBScroller() {
955 int scrollY = 0;
956
957 @Override
958 public void setScrollY(int scroll) {
959 scrollY = scroll;
960
961 if (mWorkspace.isOnOrMovingToCustomContent()) {
962 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100963 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700964 }
965 }
966 };
967
968 public void resetQSBScroll() {
969 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100970 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700971 }
972
973 public interface CustomContentCallbacks {
974 // Custom content is completely shown
975 public void onShow();
976
977 // Custom content is completely hidden
978 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700979
980 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
981 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700982 }
983
Adam Cohen30bacb22013-08-29 14:25:25 -0700984 protected void startSettings() {
985 }
986
Adam Cohenbffe7452013-07-22 18:21:45 -0700987 public interface QSBScroller {
988 public void setScrollY(int scrollY);
989 }
990
Winson Chung98ca0f72013-07-29 12:58:51 -0700991 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -0700992 CustomContentCallbacks callbacks, String description) {
993 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -0700994 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700995 }
996
Adam Cohenedb40762013-07-18 16:45:45 -0700997 // The custom content needs to offset its content to account for the QSB
998 public int getTopOffsetForCustomContent() {
999 return mWorkspace.getPaddingTop();
1000 }
1001
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001002 @Override
1003 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001004 // Flag the loader to stop early before switching
1005 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001006 if (mAppsCustomizeContent != null) {
1007 mAppsCustomizeContent.surrender();
1008 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001009 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001010 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001011
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001012 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001013 @Override
1014 public void onWindowFocusChanged(boolean hasFocus) {
1015 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001016 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001017 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001018
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001019 private boolean acceptFilter() {
1020 final InputMethodManager inputManager = (InputMethodManager)
1021 getSystemService(Context.INPUT_METHOD_SERVICE);
1022 return !inputManager.isFullscreenMode();
1023 }
1024
1025 @Override
1026 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001027 final int uniChar = event.getUnicodeChar();
1028 final boolean handled = super.onKeyDown(keyCode, event);
1029 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1030 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001031 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1032 keyCode, event);
1033 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001034 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001035 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001036 // showSearchDialog()
1037 // If there are multiple keystrokes before the search dialog takes focus,
1038 // onSearchRequested() will be called for every keystroke,
1039 // but it is idempotent, so it's fine.
1040 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001041 }
1042 }
1043
Joe Onorato8a9625e2010-01-28 15:55:35 -08001044 // Eat the long press event so the keyboard doesn't come up.
1045 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1046 return true;
1047 }
1048
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001049 return handled;
1050 }
1051
Karl Rosaen138a0412009-04-23 19:00:21 -07001052 private String getTypedText() {
1053 return mDefaultKeySsb.toString();
1054 }
1055
1056 private void clearTypedText() {
1057 mDefaultKeySsb.clear();
1058 mDefaultKeySsb.clearSpans();
1059 Selection.setSelection(mDefaultKeySsb, 0);
1060 }
1061
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001062 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001063 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1064 * State
1065 */
1066 private static State intToState(int stateOrdinal) {
1067 State state = State.WORKSPACE;
1068 final State[] stateValues = State.values();
1069 for (int i = 0; i < stateValues.length; i++) {
1070 if (stateValues[i].ordinal() == stateOrdinal) {
1071 state = stateValues[i];
1072 break;
1073 }
1074 }
1075 return state;
1076 }
1077
1078 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001079 * Restores the previous state, if it exists.
1080 *
1081 * @param savedState The previous state.
1082 */
1083 private void restoreState(Bundle savedState) {
1084 if (savedState == null) {
1085 return;
1086 }
1087
Michael Jurka883f55b2010-10-21 15:47:14 -07001088 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001089 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001090 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001091 }
1092
Winson Chungf0c6ae02012-03-21 16:10:31 -07001093 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001094 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001095 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001096 }
1097
Winson Chung3d503fb2011-07-13 17:25:49 -07001098 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001099 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001100
Winson Chung3d503fb2011-07-13 17:25:49 -07001101 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1102 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001103 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001104 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1105 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001106 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1107 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1108 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001109 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001110 mRestoring = true;
1111 }
1112
1113 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1114 if (renameFolder) {
1115 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001116 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001117 mRestoring = true;
1118 }
Winson Chunga12a2502010-12-20 14:41:35 -08001119
Winson Chung785d2eb2011-04-14 16:08:02 -07001120 // Restore the AppsCustomize tab
1121 if (mAppsCustomizeTabHost != null) {
1122 String curTab = savedState.getString("apps_customize_currentTab");
1123 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001124 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001125 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001126 mAppsCustomizeContent.loadAssociatedPages(
1127 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001128 }
1129
Winson Chung5afbf7b2011-07-25 11:53:08 -07001130 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1131 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001132 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133 }
1134
1135 /**
1136 * Finds all the views we need and configure them properly.
1137 */
1138 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001139 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001140
Craig Mautner360310b2012-10-26 15:13:08 -07001141 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001142 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1143 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001144
John Spurlock77e1f472013-09-11 10:09:51 -04001145 mLauncherView.setSystemUiVisibility(
1146 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001147 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001148
Winson Chung4c98d922011-05-31 16:50:48 -07001149 // Setup the drag layer
1150 mDragLayer.setup(this, dragController);
1151
Winson Chung3d503fb2011-07-13 17:25:49 -07001152 // Setup the hotseat
1153 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1154 if (mHotseat != null) {
1155 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001156 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001157 }
1158
Adam Cohenf358a4b2013-07-23 16:47:31 -07001159 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001160 View widgetButton = findViewById(R.id.widget_button);
1161 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001162 @Override
1163 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001164 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001165 }
1166 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001167 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1168
1169 View wallpaperButton = findViewById(R.id.wallpaper_button);
1170 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001171 @Override
1172 public void onClick(View arg0) {
1173 startWallpaper();
1174 }
1175 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001176 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1177
1178 View settingsButton = findViewById(R.id.settings_button);
1179 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001180 @Override
1181 public void onClick(View arg0) {
1182 startSettings();
1183 }
1184 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001185 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001186 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001187
Winson Chung4c98d922011-05-31 16:50:48 -07001188 // Setup the workspace
1189 mWorkspace.setHapticFeedbackEnabled(false);
1190 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001191 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001192 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001193
Winson Chungf0ea4d32011-06-06 14:27:16 -07001194 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001195 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001196
Winson Chungf0ea4d32011-06-06 14:27:16 -07001197 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001198 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001199 mAppsCustomizeContent = (AppsCustomizePagedView)
1200 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1201 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001202
Winson Chung3d503fb2011-07-13 17:25:49 -07001203 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001204 dragController.setDragScoller(mWorkspace);
1205 dragController.setScrollView(mDragLayer);
1206 dragController.setMoveTarget(mWorkspace);
1207 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001208 if (mSearchDropTargetBar != null) {
1209 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001210 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001211
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001212 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001213 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001214 mWeightWatcher = new WeightWatcher(this);
1215 mWeightWatcher.setAlpha(0.5f);
1216 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001217 new FrameLayout.LayoutParams(
1218 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001219 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001220 Gravity.BOTTOM)
1221 );
Adam Cohen39a06042013-07-19 14:30:12 -07001222
1223 boolean show = shouldShowWeightWatcher();
1224 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001225 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226 }
1227
1228 /**
1229 * Creates a view representing a shortcut.
1230 *
1231 * @param info The data structure describing the shortcut.
1232 *
1233 * @return A View inflated from R.layout.application.
1234 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001235 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001236 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001237 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001238 }
1239
1240 /**
1241 * Creates a view representing a shortcut inflated from the specified resource.
1242 *
1243 * @param layoutResId The id of the XML layout used to create the shortcut.
1244 * @param parent The group the shortcut belongs to.
1245 * @param info The data structure describing the shortcut.
1246 *
1247 * @return A View inflated from layoutResId.
1248 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001249 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001250 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1251 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001252 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253 return favorite;
1254 }
1255
1256 /**
1257 * Add an application shortcut to the workspace.
1258 *
1259 * @param data The intent describing the application.
1260 * @param cellInfo The position on screen where to create the shortcut.
1261 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001262 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001263 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001264 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001265
Adam Cohenfbba09b2011-07-18 21:43:05 -07001266 // First we check if we already know the exact location where we want to add this item.
1267 if (cellX >= 0 && cellY >= 0) {
1268 cellXY[0] = cellX;
1269 cellXY[1] = cellY;
1270 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001271 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001272 return;
1273 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001274
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001275 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001276
Romain Guy73b979d2009-06-09 12:57:21 -07001277 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001278 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001279 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001280 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001281 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001282 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001283 } else {
1284 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001285 }
1286 }
Romain Guycbb89e42009-06-08 15:52:54 -07001287
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001288 /**
1289 * Add a shortcut to the workspace.
1290 *
1291 * @param data The intent describing the shortcut.
1292 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001293 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001294 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001295 int cellY) {
1296 int[] cellXY = mTmpAddItemCellCoordinates;
1297 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001298 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001299
Michael Jurkad3ef3062010-11-23 16:23:58 -08001300 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001301
Adam Cohen558baaf2011-08-15 15:22:57 -07001302 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001303 if (info == null) {
1304 return;
1305 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001306 final View view = createShortcut(info);
1307
Adam Cohenfbba09b2011-07-18 21:43:05 -07001308 // First we check if we already know the exact location where we want to add this item.
1309 if (cellX >= 0 && cellY >= 0) {
1310 cellXY[0] = cellX;
1311 cellXY[1] = cellY;
1312 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001313
1314 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001315 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001316 true, null,null)) {
1317 return;
1318 }
1319 DragObject dragObject = new DragObject();
1320 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001321 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1322 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001323 return;
1324 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001325 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001326 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001327 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001328 foundCellSpan = (result != null);
1329 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001330 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001331 }
1332
1333 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001334 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001335 return;
1336 }
1337
Adam Cohendcd297f2013-06-18 13:13:40 -07001338 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001339
1340 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001341 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001342 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343 }
1344 }
1345
Adam Cohen2f093b62012-04-30 18:59:53 -07001346 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1347 int minHeight) {
1348 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001349 // We want to account for the extra amount of padding that we are adding to the widget
1350 // to ensure that it gets the full amount of space that it has requested
1351 int requiredWidth = minWidth + padding.left + padding.right;
1352 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001353 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001354 }
1355
Adam Cohen2f093b62012-04-30 18:59:53 -07001356 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1357 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001358 }
1359
Adam Cohen2f093b62012-04-30 18:59:53 -07001360 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1361 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001362 }
1363
Adam Cohen2f093b62012-04-30 18:59:53 -07001364 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1365 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001366 }
1367
Adam Cohen2f093b62012-04-30 18:59:53 -07001368 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1369 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001370 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001371 }
1372
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001373 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001374 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001375 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001376 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001377 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001379 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001380 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1381 if (appWidgetInfo == null) {
1382 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1383 }
Romain Guycbb89e42009-06-08 15:52:54 -07001384
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001385 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001386 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001387
Adam Cohen2f093b62012-04-30 18:59:53 -07001388 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1389 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001390
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001391 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001392 // We have saved the position to which the widget was dragged-- this really only matters
1393 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001394 int[] cellXY = mTmpAddItemCellCoordinates;
1395 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001396 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001397 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001398 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1399 cellXY[0] = mPendingAddInfo.cellX;
1400 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001401 spanXY[0] = mPendingAddInfo.spanX;
1402 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001403 foundCellSpan = true;
1404 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001405 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001406 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001407 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1408 spanXY[1], cellXY, finalSpan);
1409 spanXY[0] = finalSpan[0];
1410 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001411 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001412 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001413 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001414 }
1415
Michael Jurka0280c3b2010-09-17 15:00:07 -07001416 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001417 if (appWidgetId != -1) {
1418 // Deleting an app widget ID is a void call but writes to disk before returning
1419 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001420 new Thread("deleteAppWidgetId") {
1421 public void run() {
1422 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1423 }
1424 }.start();
1425 }
Winson Chung93eef082012-03-23 15:59:27 -07001426 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001427 return;
1428 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001429
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001430 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001431 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1432 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001433 launcherInfo.spanX = spanXY[0];
1434 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001435 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1436 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001437
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001439 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440
1441 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001442 if (hostView == null) {
1443 // Perform actual inflation because we're live
1444 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1445 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1446 } else {
1447 // The AppWidgetHostView has already been inflated and instantiated
1448 launcherInfo.hostView = hostView;
1449 }
Romain Guycbb89e42009-06-08 15:52:54 -07001450
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001452 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001453 launcherInfo.notifyWidgetSizeChanged(this);
1454
Adam Cohendcd297f2013-06-18 13:13:40 -07001455 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001456 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001457
1458 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001459 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001460 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 }
Romain Guycbb89e42009-06-08 15:52:54 -07001462
Adam Cohended9f8d2010-11-03 13:25:16 -07001463 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1464 @Override
1465 public void onReceive(Context context, Intent intent) {
1466 final String action = intent.getAction();
1467 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1468 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001469 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001470 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001471
Winson Chungc100e8e2011-08-09 16:02:43 -07001472 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001473 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001474 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001475 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001476 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001477 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1478 mUserPresent = true;
1479 updateRunning();
1480 }
1481 }
1482 };
1483
1484 @Override
1485 public void onAttachedToWindow() {
1486 super.onAttachedToWindow();
1487
1488 // Listen for broadcasts related to user-presence
1489 final IntentFilter filter = new IntentFilter();
1490 filter.addAction(Intent.ACTION_SCREEN_OFF);
1491 filter.addAction(Intent.ACTION_USER_PRESENT);
1492 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001493 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001494 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001495 mVisible = true;
1496 }
1497
1498 @Override
1499 public void onDetachedFromWindow() {
1500 super.onDetachedFromWindow();
1501 mVisible = false;
1502
Adam Cohend113e0c2010-11-11 10:48:05 -08001503 if (mAttached) {
1504 unregisterReceiver(mReceiver);
1505 mAttached = false;
1506 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001507 updateRunning();
1508 }
1509
1510 public void onWindowVisibilityChanged(int visibility) {
1511 mVisible = visibility == View.VISIBLE;
1512 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001513 // The following code used to be in onResume, but it turns out onResume is called when
1514 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1515 // is a more appropriate event to handle
1516 if (mVisible) {
1517 mAppsCustomizeTabHost.onWindowVisible();
1518 if (!mWorkspaceLoading) {
1519 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001520 // We want to let Launcher draw itself at least once before we force it to build
1521 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001522 // apps is nice and speedy.
1523 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001524 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001525 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001526 if (mStarted) return;
1527 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001528 // We delay the layer building a bit in order to give
1529 // other message processing a time to run. In particular
1530 // this avoids a delay in hiding the IME if it was
1531 // currently shown, because doing that may involve
1532 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001533 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001534 final ViewTreeObserver.OnDrawListener listener = this;
1535 mWorkspace.post(new Runnable() {
1536 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001537 if (mWorkspace != null &&
1538 mWorkspace.getViewTreeObserver() != null) {
1539 mWorkspace.getViewTreeObserver().
1540 removeOnDrawListener(listener);
1541 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001542 }
1543 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001544 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001545 }
1546 });
1547 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001548 // When Launcher comes back to foreground, a different Activity might be responsible for
1549 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001550 if (!DISABLE_MARKET_BUTTON) {
1551 updateAppMarketIcon();
1552 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001553 clearTypedText();
1554 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001555 }
1556
1557 private void sendAdvanceMessage(long delay) {
1558 mHandler.removeMessages(ADVANCE_MSG);
1559 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1560 mHandler.sendMessageDelayed(msg, delay);
1561 mAutoAdvanceSentTime = System.currentTimeMillis();
1562 }
1563
1564 private void updateRunning() {
1565 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1566 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1567 mAutoAdvanceRunning = autoAdvanceRunning;
1568 if (autoAdvanceRunning) {
1569 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1570 sendAdvanceMessage(delay);
1571 } else {
1572 if (!mWidgetsToAdvance.isEmpty()) {
1573 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1574 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1575 }
1576 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001577 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001578 }
1579 }
1580 }
1581
1582 private final Handler mHandler = new Handler() {
1583 @Override
1584 public void handleMessage(Message msg) {
1585 if (msg.what == ADVANCE_MSG) {
1586 int i = 0;
1587 for (View key: mWidgetsToAdvance.keySet()) {
1588 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1589 final int delay = mAdvanceStagger * i;
1590 if (v instanceof Advanceable) {
1591 postDelayed(new Runnable() {
1592 public void run() {
1593 ((Advanceable) v).advance();
1594 }
1595 }, delay);
1596 }
1597 i++;
1598 }
1599 sendAdvanceMessage(mAdvanceInterval);
1600 }
1601 }
1602 };
1603
1604 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001605 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001606 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1607 if (v instanceof Advanceable) {
1608 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001609 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001610 updateRunning();
1611 }
1612 }
1613
1614 void removeWidgetToAutoAdvance(View hostView) {
1615 if (mWidgetsToAdvance.containsKey(hostView)) {
1616 mWidgetsToAdvance.remove(hostView);
1617 updateRunning();
1618 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001619 }
1620
Joe Onorato9c1289c2009-08-17 11:03:03 -04001621 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001622 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001623 launcherInfo.hostView = null;
1624 }
1625
Winson Chung93eef082012-03-23 15:59:27 -07001626 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1627 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1628 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001629 }
1630
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001631 public LauncherAppWidgetHost getAppWidgetHost() {
1632 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001633 }
Romain Guycbb89e42009-06-08 15:52:54 -07001634
Winson Chunga9abd0e2010-10-27 17:18:37 -07001635 public LauncherModel getModel() {
1636 return mModel;
1637 }
1638
Bjorn Bringertc459e522013-06-07 19:36:01 +01001639 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001640 getWindow().closeAllPanels();
1641
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001642 // Whatever we were doing is hereby canceled.
1643 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001644 }
1645
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001646 @Override
1647 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001648 long startTime = 0;
1649 if (DEBUG_RESUME_TIME) {
1650 startTime = System.currentTimeMillis();
1651 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001652 super.onNewIntent(intent);
1653
1654 // Close the menu
1655 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001656 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001657 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001658
Adam Cohened307df2013-10-02 09:37:31 -07001659 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1660 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1661 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001662
Adam Cohen6fecd412013-10-02 17:41:50 -07001663 if (mWorkspace == null) {
1664 // Can be cases where mWorkspace is null, this prevents a NPE
1665 return;
1666 }
1667 Folder openFolder = mWorkspace.getOpenFolder();
1668 // In all these cases, only animate if we're already on home
1669 mWorkspace.exitWidgetResizeMode();
1670 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1671 openFolder == null) {
1672 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001673 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001674
Adam Cohen6fecd412013-10-02 17:41:50 -07001675 closeFolder();
1676 exitSpringLoadedDragMode();
1677
1678 // If we are already on home, then just animate back to the workspace,
1679 // otherwise, just wait until onResume to set the state back to Workspace
1680 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001681 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001682 } else {
1683 mOnResumeState = State.WORKSPACE;
1684 }
1685
1686 final View v = getWindow().peekDecorView();
1687 if (v != null && v.getWindowToken() != null) {
1688 InputMethodManager imm = (InputMethodManager)getSystemService(
1689 INPUT_METHOD_SERVICE);
1690 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1691 }
1692
1693 // Reset the apps customize page
1694 if (mAppsCustomizeTabHost != null) {
1695 mAppsCustomizeTabHost.reset();
1696 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001697 }
Adam Cohened307df2013-10-02 09:37:31 -07001698
Michael Jurka447bf842013-05-15 14:52:15 +02001699 if (DEBUG_RESUME_TIME) {
1700 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1701 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001702 }
1703
1704 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001705 public void onRestoreInstanceState(Bundle state) {
1706 super.onRestoreInstanceState(state);
1707 for (int page: mSynchronouslyBoundPages) {
1708 mWorkspace.restoreInstanceStateForChild(page);
1709 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 }
1711
1712 @Override
1713 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001714 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001715 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716
Michael Jurka883f55b2010-10-21 15:47:14 -07001717 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001718 // We close any open folder since it will not be re-opened, and we need to make sure
1719 // this state is reflected.
1720 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001721
Adam Cohendcd297f2013-06-18 13:13:40 -07001722 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001723 mWaitingForResult) {
1724 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001725 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001726 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1727 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001728 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1729 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1730 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001731 }
1732
1733 if (mFolderInfo != null && mWaitingForResult) {
1734 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1735 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1736 }
Michael Jurka946ad472010-07-09 18:05:18 -07001737
Winson Chung785d2eb2011-04-14 16:08:02 -07001738 // Save the current AppsCustomize tab
1739 if (mAppsCustomizeTabHost != null) {
1740 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1741 if (currentTabTag != null) {
1742 outState.putString("apps_customize_currentTab", currentTabTag);
1743 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001744 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1745 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001746 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747 }
1748
1749 @Override
1750 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001752
Winson Chunge7a03942011-08-05 15:05:12 -07001753 // Remove all pending runnables
1754 mHandler.removeMessages(ADVANCE_MSG);
1755 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001756 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001757
Winson Chungcd2b0142011-06-08 16:02:26 -07001758 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001759 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001760 mModel.stopLoader();
1761 app.setLauncher(null);
1762
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001763 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001764 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001765 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001766 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001767 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001768 mAppWidgetHost = null;
1769
1770 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001771
1772 TextKeyListener.getInstance().release();
1773
Winson Chung81b52252012-08-27 15:34:29 -07001774 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1775 // to prevent leaking Launcher activities on orientation change.
1776 if (mModel != null) {
1777 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1778 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001779
1780 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001781 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001782
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001783 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001784 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1785 mWorkspace.removeAllViews();
1786 mWorkspace = null;
1787 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001788
Michael Jurka2ecf9952012-06-18 12:52:28 -07001789 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001790 }
1791
Adam Cohena9cf38f2011-05-02 15:36:58 -07001792 public DragController getDragController() {
1793 return mDragController;
1794 }
1795
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796 @Override
1797 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001798 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001799 super.startActivityForResult(intent, requestCode);
1800 }
1801
Winson Chung70d72102011-08-12 11:24:35 -07001802 /**
1803 * Indicates that we want global search for this activity by setting the globalSearch
1804 * argument for {@link #startSearch} to true.
1805 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001806 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001807 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001808 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001809
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001810 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001811
Karl Rosaen138a0412009-04-23 19:00:21 -07001812 if (initialQuery == null) {
1813 // Use any text typed in the launcher as the initial query
1814 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001815 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 if (appSearchData == null) {
1817 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001818 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001819 }
Winson Chungadf0c182012-08-23 14:59:07 -07001820 Rect sourceBounds = new Rect();
1821 if (mSearchDropTargetBar != null) {
1822 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1823 }
Romain Guycbb89e42009-06-08 15:52:54 -07001824
Bjorn Bringertc459e522013-06-07 19:36:01 +01001825 startSearch(initialQuery, selectInitialQuery,
1826 appSearchData, sourceBounds);
1827 }
1828
1829 public void startSearch(String initialQuery,
1830 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001831 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001832 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001833 }
1834
1835 /**
1836 * Starts the global search activity. This code is a copied from SearchManager
1837 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001838 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001839 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001840 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001841 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1842 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1843 if (globalSearchActivity == null) {
1844 Log.w(TAG, "No global search activity found.");
1845 return;
1846 }
1847 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1848 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1849 intent.setComponent(globalSearchActivity);
1850 // Make sure that we have a Bundle to put source in
1851 if (appSearchData == null) {
1852 appSearchData = new Bundle();
1853 } else {
1854 appSearchData = new Bundle(appSearchData);
1855 }
1856 // Set source to package name of app that starts global search, if not set already.
1857 if (!appSearchData.containsKey("source")) {
1858 appSearchData.putString("source", getPackageName());
1859 }
1860 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1861 if (!TextUtils.isEmpty(initialQuery)) {
1862 intent.putExtra(SearchManager.QUERY, initialQuery);
1863 }
1864 if (selectInitialQuery) {
1865 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1866 }
1867 intent.setSourceBounds(sourceBounds);
1868 try {
1869 startActivity(intent);
1870 } catch (ActivityNotFoundException ex) {
1871 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1872 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001873 }
1874
Winson Chung70d72102011-08-12 11:24:35 -07001875 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001876 public boolean onPrepareOptionsMenu(Menu menu) {
1877 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001878 if (!mWorkspace.isInOverviewMode()) {
1879 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001880 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001881 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001882 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001884 @Override
1885 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001886 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001887 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001888 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001889 }
1890
Joe Onorato9c1289c2009-08-17 11:03:03 -04001891 public boolean isWorkspaceLocked() {
1892 return mWorkspaceLoading || mWaitingForResult;
1893 }
1894
Michael Jurka0280c3b2010-09-17 15:00:07 -07001895 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001896 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001897 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001898 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1899 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001900 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001901 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001902 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001903
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001904 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1905 AppWidgetProviderInfo appWidgetInfo) {
1906 if (appWidgetInfo.configure != null) {
1907 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001908
Bjorn Bringert7984c942009-12-09 15:38:25 +00001909 // Launch over to configure widget, if needed
1910 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001911 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001912 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001913 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001915 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001916 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001917 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001918 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001919 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 }
1921 }
Romain Guycbb89e42009-06-08 15:52:54 -07001922
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001923 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07001924 // Close any folders that may be open.
1925 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001926 mWorkspace.moveToCustomContentScreen(animate);
1927 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001928 /**
1929 * Process a shortcut drop.
1930 *
1931 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001932 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001933 * @param cell The cell it should be added to, optional
1934 * @param position The location on the screen where it was dropped, optional
1935 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001936 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001937 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001938 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001939 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001940 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001941 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001942
1943 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001944 mPendingAddInfo.cellX = cell[0];
1945 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001946 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001947
1948 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1949 createShortcutIntent.setComponent(componentName);
1950 processShortcut(createShortcutIntent);
1951 }
1952
Adam Cohenfbba09b2011-07-18 21:43:05 -07001953 /**
1954 * Process a widget drop.
1955 *
1956 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001957 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001958 * @param cell The cell it should be added to, optional
1959 * @param position The location on the screen where it was dropped, optional
1960 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001961 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001962 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001963 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001964 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001965 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001966 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001967 mPendingAddInfo.minSpanX = info.minSpanX;
1968 mPendingAddInfo.minSpanY = info.minSpanY;
1969
Adam Cohenfbba09b2011-07-18 21:43:05 -07001970 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001971 mPendingAddInfo.cellX = cell[0];
1972 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001973 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001974 if (span != null) {
1975 mPendingAddInfo.spanX = span[0];
1976 mPendingAddInfo.spanY = span[1];
1977 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001978
Adam Cohened66b2b2012-01-23 17:28:51 -08001979 AppWidgetHostView hostView = info.boundWidget;
1980 int appWidgetId;
1981 if (hostView != null) {
1982 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001983 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001984 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001985 // In this case, we either need to start an activity to get permission to bind
1986 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001987 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001988 Bundle options = info.bindOptions;
1989
1990 boolean success = false;
1991 if (options != null) {
1992 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1993 info.componentName, options);
1994 } else {
1995 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1996 info.componentName);
1997 }
1998 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001999 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002000 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002001 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002002 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2003 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2004 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002005 // TODO: we need to make sure that this accounts for the options bundle.
2006 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002007 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2008 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002009 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002010 }
2011
Joe Onoratodeb98af2010-02-19 14:59:39 -08002012 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002013 // Handle case where user selected "Applications"
2014 String applicationName = getResources().getString(R.string.group_applications);
2015 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002016
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002017 if (applicationName != null && applicationName.equals(shortcutName)) {
2018 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2019 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002020
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002021 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2022 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002023 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002024 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002025 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002026 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002027 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002028 }
2029
Winson Chung24ab2f12010-09-16 14:10:47 -07002030 void processWallpaper(Intent intent) {
2031 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2032 }
2033
Adam Cohendcd297f2013-06-18 13:13:40 -07002034 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002035 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002036 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002037 folderInfo.title = getText(R.string.folder_name);
2038
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002039 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002040 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002041 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002042 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002043
2044 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002045 FolderIcon newFolder =
2046 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002047 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002048 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002049 // Force measure the new folder icon
2050 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2051 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002052 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 }
Romain Guycbb89e42009-06-08 15:52:54 -07002054
Joe Onorato9c1289c2009-08-17 11:03:03 -04002055 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002056 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002057 }
2058
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002059 protected void startWallpaper() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002061 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002062 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 }
2064
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002065 protected ComponentName getWallpaperPickerComponent() {
2066 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2067 }
2068
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002069 /**
2070 * Registers various content observers. The current implementation registers
2071 * only a favorites observer to keep track of the favorites applications.
2072 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002073 private void registerContentObservers() {
2074 ContentResolver resolver = getContentResolver();
2075 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2076 true, mWidgetObserver);
2077 }
2078
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 @Override
2080 public boolean dispatchKeyEvent(KeyEvent event) {
2081 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2082 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002084 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002085 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002086 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002087 dumpState();
2088 return true;
2089 }
2090 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002091 }
2092 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2093 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002094 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002095 return true;
2096 }
2097 }
2098
2099 return super.dispatchKeyEvent(event);
2100 }
2101
Joe Onorato88ec0992009-11-19 13:16:06 -08002102 @Override
2103 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002104 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002105 if (mAppsCustomizeContent.getContentType() ==
2106 AppsCustomizePagedView.ContentType.Applications) {
2107 showWorkspace(true);
2108 } else {
2109 showOverviewMode(true);
2110 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002111 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002112 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002113 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002114 Folder openFolder = mWorkspace.getOpenFolder();
2115 if (openFolder.isEditingName()) {
2116 openFolder.dismissEditingName();
2117 } else {
2118 closeFolder();
2119 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002120 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002121 mWorkspace.exitWidgetResizeMode();
2122
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002123 // Back button is a no-op here, but give at least some feedback for the button press
2124 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002125 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002126 }
2127
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002129 * Re-listen when widgets are reset.
2130 */
2131 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002132 if (mAppWidgetHost != null) {
2133 mAppWidgetHost.startListening();
2134 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002135 }
2136
2137 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002138 * Launches the intent referred by the clicked shortcut.
2139 *
2140 * @param v The view representing the clicked shortcut.
2141 */
2142 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002143 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2144 // view has detached (it's possible for this to happen if the view is removed mid touch).
2145 if (v.getWindowToken() == null) {
2146 return;
2147 }
2148
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002149 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002150 return;
2151 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002152
Adam Cohen1697b792013-09-17 19:08:21 -07002153 if (v instanceof Workspace) {
2154 if (mWorkspace.isInOverviewMode()) {
2155 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002156 }
2157 return;
2158 }
2159
2160 if (v instanceof CellLayout) {
2161 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002162 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002163 }
2164 }
2165
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002166 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002167 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002168 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002169 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2170 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002171
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002172 // Check for special shortcuts
2173 if (intent.getComponent() != null) {
2174 final String shortcutClass = intent.getComponent().getClassName();
2175
2176 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002177 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002178 return;
2179 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2180 MemoryDumpActivity.startDump(this);
2181 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002182 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2183 toggleShowWeightWatcher();
2184 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002185 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002186 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002187
2188 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002189 int[] pos = new int[2];
2190 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002191 intent.setSourceBounds(new Rect(pos[0], pos[1],
2192 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002193
2194 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002195
Daniel Sandlerff02d492013-08-05 02:12:05 -04002196 mStats.recordLaunch(intent, shortcut);
2197
Michael Jurkaddd62e92011-02-16 17:49:14 -08002198 if (success && v instanceof BubbleTextView) {
2199 mWaitingForResume = (BubbleTextView) v;
2200 mWaitingForResume.setStayPressed(true);
2201 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002202 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002203 if (v instanceof FolderIcon) {
2204 FolderIcon fi = (FolderIcon) v;
2205 handleFolderClick(fi);
2206 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002207 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002208 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002209 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002210 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002211 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002212 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002213 }
2214 }
2215
Michael Jurka0e260592010-06-30 17:07:39 -07002216 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002217 return false;
2218 }
2219
Michael Jurkaaf442092010-06-10 17:01:57 -07002220 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002221 * Event handler for the search button
2222 *
2223 * @param v The view that was clicked.
2224 */
2225 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002226 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2227
Amith Yamasania135ba82011-08-09 17:42:01 -07002228 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002229 }
2230
2231 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002232 * Event handler for the voice button
2233 *
2234 * @param v The view that was clicked.
2235 */
2236 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002237 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002238
Bjorn Bringertc459e522013-06-07 19:36:01 +01002239 startVoice();
2240 }
2241
2242 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002243 try {
2244 final SearchManager searchManager =
2245 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2246 ComponentName activityName = searchManager.getGlobalSearchActivity();
2247 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002248 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002249 if (activityName != null) {
2250 intent.setPackage(activityName.getPackageName());
2251 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002252 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002253 } catch (ActivityNotFoundException e) {
2254 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002255 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002256 startActivitySafely(null, intent, "onClickVoiceButton");
2257 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002258 }
2259
2260 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002261 * Event handler for the "grid" button that appears on the home screen, which
2262 * enters all apps mode.
2263 *
2264 * @param v The view that was clicked.
2265 */
2266 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002267 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002268 }
2269
2270 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002271 // Provide the same haptic feedback that the system offers for virtual keys.
2272 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002273 }
2274
Adam Cohen61f560d2013-09-30 15:58:20 -07002275 public void performHapticFeedbackOnTouchDown(View v) {
2276 // Provide the same haptic feedback that the system offers for virtual keys.
2277 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2278 }
2279
2280 public View.OnTouchListener getHapticFeedbackTouchListener() {
2281 if (mHapticFeedbackTouchListener == null) {
2282 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2283 @Override
2284 public boolean onTouch(View v, MotionEvent event) {
2285 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2286 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2287 }
2288 return false;
2289 }
2290 };
2291 }
2292 return mHapticFeedbackTouchListener;
2293 }
2294
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002295 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002296 if (!DISABLE_MARKET_BUTTON) {
2297 if (mAppMarketIntent != null) {
2298 startActivitySafely(v, mAppMarketIntent, "app market");
2299 } else {
2300 Log.e(TAG, "Invalid app market intent.");
2301 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002302 }
2303 }
2304
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002305 /**
2306 * Called when the user stops interacting with the launcher.
2307 * This implies that the user is now on the homescreen and is not doing housekeeping.
2308 */
2309 protected void onInteractionEnd() {}
2310
2311 /**
2312 * Called when the user starts interacting with the launcher.
2313 * The possible interactions are:
2314 * - open all apps
2315 * - reorder an app shortcut, or a widget
2316 * - open the overview mode.
2317 * This is a good time to stop doing things that only make sense
2318 * when the user is on the homescreen and not doing housekeeping.
2319 */
2320 protected void onInteractionBegin() {}
2321
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002322 void startApplicationDetailsActivity(ComponentName componentName) {
2323 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002324 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2325 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002326 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002327 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002328 }
2329
Michael Jurka1e2f4652013-07-08 18:03:46 -07002330 // returns true if the activity was started
2331 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002332 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002333 // System applications cannot be installed. For now, show a toast explaining that.
2334 // We may give them the option of disabling apps this way.
2335 int messageId = R.string.uninstall_system_app_text;
2336 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002337 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002338 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002339 String packageName = componentName.getPackageName();
2340 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002341 Intent intent = new Intent(
2342 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002343 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2344 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002345 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002346 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002347 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002348 }
2349
Michael Jurka86a720e2012-05-09 11:23:23 -07002350 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002351 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002352
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002353 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002354 // Only launch using the new animation if the shortcut has not opted out (this is a
2355 // private contract between launcher and may be ignored in the future).
2356 boolean useLaunchAnimation = (v != null) &&
2357 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2358 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002359 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2360 v.getMeasuredWidth(), v.getMeasuredHeight());
2361
2362 startActivity(intent, opts.toBundle());
2363 } else {
2364 startActivity(intent);
2365 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002366 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002367 } catch (SecurityException e) {
2368 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002369 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002371 "or use the exported attribute for this activity. "
2372 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002373 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002374 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002375 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002376
Michael Jurka86a720e2012-05-09 11:23:23 -07002377 boolean startActivitySafely(View v, Intent intent, Object tag) {
2378 boolean success = false;
2379 try {
2380 success = startActivity(v, intent, tag);
2381 } catch (ActivityNotFoundException e) {
2382 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2383 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2384 }
2385 return success;
2386 }
2387
Adam Cohena9cf38f2011-05-02 15:36:58 -07002388 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002389 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002390 Folder openFolder = mWorkspace.getFolderForTag(info);
2391
2392 // If the folder info reports that the associated folder is open, then verify that
2393 // it is actually opened. There have been a few instances where this gets out of sync.
2394 if (info.opened && openFolder == null) {
2395 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002396 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002397 info.opened = false;
2398 }
2399
Adam Cohenfb91f302012-06-11 15:45:18 -07002400 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002401 // Close any open folder
2402 closeFolder();
2403 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002404 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002405 } else {
2406 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002407 int folderScreen;
2408 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002409 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002410 // .. and close it
2411 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002412 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002413 // Close any folder open on the current screen
2414 closeFolder();
2415 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002416 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002417 }
2418 }
2419 }
2420 }
2421
Adam Cohen268c4752012-06-06 17:47:33 -07002422 /**
2423 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2424 * in the DragLayer in the exact absolute location of the original FolderIcon.
2425 */
2426 private void copyFolderIconToImage(FolderIcon fi) {
2427 final int width = fi.getMeasuredWidth();
2428 final int height = fi.getMeasuredHeight();
2429
2430 // Lazy load ImageView, Bitmap and Canvas
2431 if (mFolderIconImageView == null) {
2432 mFolderIconImageView = new ImageView(this);
2433 }
2434 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2435 mFolderIconBitmap.getHeight() != height) {
2436 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2437 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2438 }
2439
2440 DragLayer.LayoutParams lp;
2441 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2442 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2443 } else {
2444 lp = new DragLayer.LayoutParams(width, height);
2445 }
2446
Adam Cohen307fe232012-08-16 17:55:58 -07002447 // The layout from which the folder is being opened may be scaled, adjust the starting
2448 // view size by this scale factor.
2449 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002450 lp.customPosition = true;
2451 lp.x = mRectForFolderAnimation.left;
2452 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002453 lp.width = (int) (scale * width);
2454 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002455
2456 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2457 fi.draw(mFolderIconCanvas);
2458 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002459 if (fi.getFolder() != null) {
2460 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2461 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002462 }
Adam Cohen268c4752012-06-06 17:47:33 -07002463 // Just in case this image view is still in the drag layer from a previous animation,
2464 // we remove it and re-add it.
2465 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2466 mDragLayer.removeView(mFolderIconImageView);
2467 }
2468 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002469 if (fi.getFolder() != null) {
2470 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002471 }
Adam Cohen268c4752012-06-06 17:47:33 -07002472 }
2473
Adam Cohen2801caf2011-05-13 20:57:39 -07002474 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002475 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002476 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2477 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2478 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2479
Adam Cohenc51934b2011-07-26 21:07:43 -07002480 FolderInfo info = (FolderInfo) fi.getTag();
2481 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2482 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002483 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2484 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002485 }
2486
Adam Cohen268c4752012-06-06 17:47:33 -07002487 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2488 copyFolderIconToImage(fi);
2489 fi.setVisibility(View.INVISIBLE);
2490
Michael Jurka2ecf9952012-06-18 12:52:28 -07002491 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002492 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002493 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2494 oa.start();
2495 }
2496
Adam Cohen268c4752012-06-06 17:47:33 -07002497 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002498 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002499 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2500 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2501 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2502
Adam Cohen268c4752012-06-06 17:47:33 -07002503 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002504
Adam Cohen268c4752012-06-06 17:47:33 -07002505 // We remove and re-draw the FolderIcon in-case it has changed
2506 mDragLayer.removeView(mFolderIconImageView);
2507 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002508 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002509 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002510 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002511 oa.addListener(new AnimatorListenerAdapter() {
2512 @Override
2513 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002514 if (cl != null) {
2515 cl.clearFolderLeaveBehind();
2516 // Remove the ImageView copy of the FolderIcon and make the original visible.
2517 mDragLayer.removeView(mFolderIconImageView);
2518 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002519 }
2520 }
2521 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002522 oa.start();
2523 }
2524
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002525 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002526 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002527 * is animated relative to the specified View. If the View is null, no animation
2528 * is played.
2529 *
2530 * @param folderInfo The FolderInfo describing the folder to open.
2531 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002532 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002533 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002534 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002535
Adam Cohena9cf38f2011-05-02 15:36:58 -07002536 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002537
Adam Cohen4554ee12011-08-03 16:13:21 -07002538 // Just verify that the folder hasn't already been added to the DragLayer.
2539 // There was a one-off crash where the folder had a parent already.
2540 if (folder.getParent() == null) {
2541 mDragLayer.addView(folder);
2542 mDragController.addDropTarget((DropTarget) folder);
2543 } else {
2544 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2545 folder.getParent() + ").");
2546 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002547 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002548 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002549
2550 // Notify the accessibility manager that this folder "window" has appeared and occluded
2551 // the workspace items
2552 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2553 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002554 }
2555
2556 public void closeFolder() {
2557 Folder folder = mWorkspace.getOpenFolder();
2558 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002559 if (folder.isEditingName()) {
2560 folder.dismissEditingName();
2561 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002562 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002563
2564 // Dismiss the folder cling
2565 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002566 }
2567 }
2568
2569 void closeFolder(Folder folder) {
2570 folder.getInfo().opened = false;
2571
2572 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2573 if (parent != null) {
2574 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2575 shrinkAndFadeInFolderIcon(fi);
2576 }
2577 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002578
2579 // Notify the accessibility manager that this folder "window" has disappeard and no
2580 // longer occludeds the workspace items
2581 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002582 }
2583
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002584 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002585 if (!isDraggingEnabled()) return false;
2586 if (isWorkspaceLocked()) return false;
2587 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002588
Adam Cohen1697b792013-09-17 19:08:21 -07002589 if (v instanceof Workspace) {
2590 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002591 if (mWorkspace.enterOverviewMode()) {
2592 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2593 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2594 return true;
2595 } else {
2596 return false;
2597 }
Adam Cohen1697b792013-09-17 19:08:21 -07002598 }
Adam Cohen1697b792013-09-17 19:08:21 -07002599 }
2600
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002601 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002602 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002603 }
2604
Michael Jurka0280c3b2010-09-17 15:00:07 -07002605 resetAddInfo();
2606 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002607 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002608 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002609 return true;
2610 }
2611
Winson Chung3d503fb2011-07-13 17:25:49 -07002612 // The hotseat touch handling does not go through Workspace, and we always allow long press
2613 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002614 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002615 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2616 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002617 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002618 // User long pressed on empty space
2619 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2620 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2621 // Disabling reordering until we sort out some issues.
2622 if (mWorkspace.isInOverviewMode()) {
2623 mWorkspace.startReordering(v);
2624 } else {
2625 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002626 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002627 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002628 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002629 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002630 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002631 }
2632 }
2633 }
2634 return true;
2635 }
2636
Winson Chung3d503fb2011-07-13 17:25:49 -07002637 boolean isHotseatLayout(View layout) {
2638 return mHotseat != null && layout != null &&
2639 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2640 }
2641 Hotseat getHotseat() {
2642 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002643 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002644 View getOverviewPanel() {
2645 return mOverviewPanel;
2646 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002647 SearchDropTargetBar getSearchBar() {
2648 return mSearchDropTargetBar;
2649 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002650
Winson Chung3d503fb2011-07-13 17:25:49 -07002651 /**
2652 * Returns the CellLayout of the specified container at the specified screen.
2653 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002654 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002655 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2656 if (mHotseat != null) {
2657 return mHotseat.getLayout();
2658 } else {
2659 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002660 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002661 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002662 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002663 }
2664 }
2665
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002666 Workspace getWorkspace() {
2667 return mWorkspace;
2668 }
2669
Daniel Sandler843e8602010-06-07 14:59:01 -04002670 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002671 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002672 }
2673
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002674 /**
2675 * Helper method for the cameraZoomIn/cameraZoomOut animations
2676 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002677 * @param scaleFactor The scale factor used for the zoom
2678 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002679 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002680 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002681 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002682 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002683
Craig Mautner360310b2012-10-26 15:13:08 -07002684 private void setWorkspaceBackground(boolean workspace) {
2685 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002686 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002687 }
2688
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002689 void updateWallpaperVisibility(boolean visible) {
2690 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2691 int curflags = getWindow().getAttributes().flags
2692 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2693 if (wpflags != curflags) {
2694 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2695 }
Craig Mautner360310b2012-10-26 15:13:08 -07002696 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002697 }
2698
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002699 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2700 if (v instanceof LauncherTransitionable) {
2701 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2702 }
2703 }
2704
Michael Jurkabed61d22012-02-14 22:51:29 -08002705 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2706 if (v instanceof LauncherTransitionable) {
2707 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2708 }
Winson Chung70442722012-02-10 15:43:22 -08002709
2710 // Update the workspace transition step as well
2711 dispatchOnLauncherTransitionStep(v, 0f);
2712 }
2713
2714 private void dispatchOnLauncherTransitionStep(View v, float t) {
2715 if (v instanceof LauncherTransitionable) {
2716 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2717 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002718 }
2719
2720 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2721 if (v instanceof LauncherTransitionable) {
2722 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2723 }
Winson Chung70442722012-02-10 15:43:22 -08002724
2725 // Update the workspace transition step as well
2726 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002727 }
2728
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002729 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002730 * Things to test when changing the following seven functions.
2731 * - Home from workspace
2732 * - from center screen
2733 * - from other screens
2734 * - Home from all apps
2735 * - from center screen
2736 * - from other screens
2737 * - Back from all apps
2738 * - from center screen
2739 * - from other screens
2740 * - Launch app from workspace and quit
2741 * - with back
2742 * - with home
2743 * - Launch app from all apps and quit
2744 * - with back
2745 * - with home
2746 * - Go to a screen that's not the default, then all
2747 * apps, and launch and app, and go back
2748 * - with back
2749 * -with home
2750 * - On workspace, long press power and go back
2751 * - with back
2752 * - with home
2753 * - On all apps, long press power and go back
2754 * - with back
2755 * - with home
2756 * - On workspace, power off
2757 * - On all apps, power off
2758 * - Launch an app and turn off the screen while in that app
2759 * - Go back with home key
2760 * - Go back with back key TODO: make this not go to workspace
2761 * - From all apps
2762 * - From workspace
2763 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2764 * - From all apps
2765 * - From the center workspace
2766 * - From another workspace
2767 */
2768
2769 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002770 * Zoom the camera out from the workspace to reveal 'toView'.
2771 * Assumes that the view to show is anchored at either the very top or very bottom
2772 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002773 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002774 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002775 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2776 showAppsCustomizeHelper(animated, springLoaded, contentType);
2777 }
2778 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2779 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002780 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002781 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002782 mStateAnimation.cancel();
2783 mStateAnimation = null;
2784 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002785 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002786
Winson Chungf0ea4d32011-06-06 14:27:16 -07002787 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2788 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2789 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002790 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002791 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002792 final int startDelay =
2793 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002794
Michael Jurkab3e22d92011-10-31 15:58:33 -07002795 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002796
Michael Jurkad74c9842011-07-10 12:44:21 -07002797 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002798 Animator workspaceAnim =
2799 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002800 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2801 // Set the content type for the all apps space
2802 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2803 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002804
2805 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002806 toView.setScaleX(scale);
2807 toView.setScaleY(scale);
2808 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2809 scaleAnim.
2810 scaleX(1f).scaleY(1f).
2811 setDuration(duration).
2812 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002813
Winson Chungf0ea4d32011-06-06 14:27:16 -07002814 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002815 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002816 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002817 .ofFloat(toView, "alpha", 0f, 1f)
2818 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002819 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002820 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2821 @Override
2822 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002823 if (animation == null) {
2824 throw new RuntimeException("animation is null");
2825 }
Winson Chung70442722012-02-10 15:43:22 -08002826 float t = (Float) animation.getAnimatedValue();
2827 dispatchOnLauncherTransitionStep(fromView, t);
2828 dispatchOnLauncherTransitionStep(toView, t);
2829 }
2830 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002831
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002832 // toView should appear right at the end of the workspace shrink
2833 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002834 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002835 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002836 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002837
2838 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002839 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002840 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002841 // Prepare the position
2842 toView.setTranslationX(0.0f);
2843 toView.setTranslationY(0.0f);
2844 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002845 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002846 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002847 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002848 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002849 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2850 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002851
Winson Chungc7d2b602012-05-16 17:02:20 -07002852 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002853 if (mSearchDropTargetBar != null) {
2854 mSearchDropTargetBar.hideSearchBar(false);
2855 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002856 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002857 });
2858
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002859 if (workspaceAnim != null) {
2860 mStateAnimation.play(workspaceAnim);
2861 }
Michael Jurka1899a362011-11-03 13:50:45 -07002862
2863 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002864
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002865 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2866 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002867
2868 // If any of the objects being animated haven't been measured/laid out
2869 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002870 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002871 (mWorkspace.getMeasuredWidth() == 0) ||
2872 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002873 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002874 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002875
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002876 final AnimatorSet stateAnimation = mStateAnimation;
2877 final Runnable startAnimRunnable = new Runnable() {
2878 public void run() {
2879 // Check that mStateAnimation hasn't changed while
2880 // we waited for a layout/draw pass
2881 if (mStateAnimation != stateAnimation)
2882 return;
2883 setPivotsForZoom(toView, scale);
2884 dispatchOnLauncherTransitionStart(fromView, animated, false);
2885 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002886 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002887 }
2888 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002889 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002890 final ViewTreeObserver observer = toView.getViewTreeObserver();
2891 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2892 public void onGlobalLayout() {
2893 startAnimRunnable.run();
2894 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2895 }
2896 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002897 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002898 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002899 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002900 } else {
2901 toView.setTranslationX(0.0f);
2902 toView.setTranslationY(0.0f);
2903 toView.setScaleX(1.0f);
2904 toView.setScaleY(1.0f);
2905 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002906 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002907
Daniel Sandlere4f98912013-06-25 15:13:26 -04002908 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002909 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002910 if (mSearchDropTargetBar != null) {
2911 mSearchDropTargetBar.hideSearchBar(false);
2912 }
Michael Jurkaabded662011-03-04 12:06:57 -08002913 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002914 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002915 dispatchOnLauncherTransitionStart(fromView, animated, false);
2916 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002917 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002918 dispatchOnLauncherTransitionStart(toView, animated, false);
2919 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002920 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002921 }
2922
2923 /**
2924 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002925 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002926 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002927 */
Adam Cohened307df2013-10-02 09:37:31 -07002928 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08002929 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002930
Michael Jurkab3e22d92011-10-31 15:58:33 -07002931 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002932 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002933 mStateAnimation.cancel();
2934 mStateAnimation = null;
2935 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002936 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002937
Winson Chungf0ea4d32011-06-06 14:27:16 -07002938 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002939 final int fadeOutDuration =
2940 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002941 final float scaleFactor = (float)
2942 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2943 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002944 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002945 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07002946 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002947 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2948 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07002949 toState, animated, stagger, -1);
2950 } else if (toState == Workspace.State.SPRING_LOADED ||
2951 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002952 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07002953 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002954 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002955
Michael Jurkab3e22d92011-10-31 15:58:33 -07002956 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002957 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002958 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002959 final LauncherViewPropertyAnimator scaleAnim =
2960 new LauncherViewPropertyAnimator(fromView);
2961 scaleAnim.
2962 scaleX(scaleFactor).scaleY(scaleFactor).
2963 setDuration(duration).
2964 setInterpolator(new Workspace.ZoomInInterpolator());
2965
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002966 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002967 .ofFloat(fromView, "alpha", 1f, 0f)
2968 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002969 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002970 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2971 @Override
2972 public void onAnimationUpdate(ValueAnimator animation) {
2973 float t = 1f - (Float) animation.getAnimatedValue();
2974 dispatchOnLauncherTransitionStep(fromView, t);
2975 dispatchOnLauncherTransitionStep(toView, t);
2976 }
2977 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002978
Michael Jurka2ecf9952012-06-18 12:52:28 -07002979 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002980
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002981 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2982 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002983 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002984
2985 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002986 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002987 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002988 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002989 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2990 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002991 if (onCompleteRunnable != null) {
2992 onCompleteRunnable.run();
2993 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002994 mAppsCustomizeContent.updateCurrentPageScroll();
2995 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002996 }
2997 });
2998
Winson Chungf0ea4d32011-06-06 14:27:16 -07002999 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003000 if (workspaceAnim != null) {
3001 mStateAnimation.play(workspaceAnim);
3002 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003003 dispatchOnLauncherTransitionStart(fromView, animated, true);
3004 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003005 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003006 } else {
3007 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003008 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003009 dispatchOnLauncherTransitionStart(fromView, animated, true);
3010 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003011 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003012 dispatchOnLauncherTransitionStart(toView, animated, true);
3013 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003014 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003015 }
3016
Michael Jurkae326f182011-11-21 14:05:46 -08003017 @Override
3018 public void onTrimMemory(int level) {
3019 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003020 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003021 mAppsCustomizeTabHost.onTrimMemory();
3022 }
3023 }
3024
Adam Cohened307df2013-10-02 09:37:31 -07003025 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003026 showWorkspace(animated, null);
3027 }
3028
Adam Cohened307df2013-10-02 09:37:31 -07003029 protected void showWorkspace() {
3030 showWorkspace(true);
3031 }
3032
Adam Cohened66b2b2012-01-23 17:28:51 -08003033 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003034 if (mWorkspace.isInOverviewMode()) {
3035 mWorkspace.exitOverviewMode(animated);
3036 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003037 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003038 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003039 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003040 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003041
Winson Chungc7d2b602012-05-16 17:02:20 -07003042 // Show the search bar (only animate if we were showing the drop target bar in spring
3043 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003044 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003045 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003046 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003047
Michael Jurkab3e22d92011-10-31 15:58:33 -07003048 // Set focus to the AppsCustomize button
3049 if (mAllAppsButton != null) {
3050 mAllAppsButton.requestFocus();
3051 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003052 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003053
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003054 // Change the state *after* we've called all the transition code
3055 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003056
Winson Chung5fb63472011-02-02 17:03:37 -08003057 // Resume the auto-advance of widgets
3058 mUserPresent = true;
3059 updateRunning();
3060
alanv1d4fde62012-10-17 13:15:47 -07003061 // Send an accessibility event to announce the context change
3062 getWindow().getDecorView()
3063 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003064
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003065 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003066 }
3067
Adam Cohened307df2013-10-02 09:37:31 -07003068 void showOverviewMode(boolean animated) {
3069 mWorkspace.setVisibility(View.VISIBLE);
3070 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3071 mState = State.WORKSPACE;
3072 onWorkspaceShown(animated);
3073 }
3074
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003075 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003076 }
3077
Winson Chungc58497e2013-09-03 17:48:37 -07003078 void showAllApps(boolean animated,
3079 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003080 if (mState != State.WORKSPACE) return;
3081
Winson Chungc58497e2013-09-03 17:48:37 -07003082 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003083 mAppsCustomizeTabHost.requestFocus();
3084
Michael Jurkab3e22d92011-10-31 15:58:33 -07003085 // Change the state *after* we've called all the transition code
3086 mState = State.APPS_CUSTOMIZE;
3087
3088 // Pause the auto-advance of widgets until we are out of AllApps
3089 mUserPresent = false;
3090 updateRunning();
3091 closeFolder();
3092
3093 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003094 getWindow().getDecorView()
3095 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003096 }
3097
Adam Cohen7777d962011-08-18 18:58:38 -07003098 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003099 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003100 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003101 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003102 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003103 }
Adam Cohen7777d962011-08-18 18:58:38 -07003104
Adam Cohened66b2b2012-01-23 17:28:51 -08003105 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3106 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003107 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3108
Winson Chunge7a03942011-08-05 15:05:12 -07003109 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003110 @Override
3111 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003112 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003113 // Before we show workspace, hide all apps again because
3114 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3115 // clean up our state transition functions
3116 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003117 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003118 } else {
3119 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003120 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003121 }
3122 }, (extendedDelay ?
3123 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3124 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3125 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003126
Michael Jurkad3ef3062010-11-23 16:23:58 -08003127 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003128 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003129 final boolean animated = true;
3130 final boolean springLoaded = true;
3131 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003132 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003133 }
3134 // Otherwise, we are not in spring loaded mode, so don't do anything.
3135 }
3136
Michael Jurkab3e22d92011-10-31 15:58:33 -07003137 void lockAllApps() {
3138 // TODO
3139 }
3140
3141 void unlockAllApps() {
3142 // TODO
3143 }
3144
Winson Chungf0ea4d32011-06-06 14:27:16 -07003145 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003146 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003147 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003148 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003149 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003150 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003151 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003152 int duration = 0;
3153 if (mSearchDropTargetBar != null) {
3154 duration = mSearchDropTargetBar.getTransitionInDuration();
3155 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003156 mHotseat.animate().alpha(1f).setDuration(duration);
3157 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003158 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003159 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003160 }
3161 }
3162 }
3163
3164 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003165 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003166 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003167 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003168 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003169 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003170 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003171 int duration = 0;
3172 if (mSearchDropTargetBar != null) {
3173 duration = mSearchDropTargetBar.getTransitionOutDuration();
3174 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003175 mHotseat.animate().alpha(0f).setDuration(duration);
3176 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003177 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003178 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003179 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003180 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003181 }
3182
Patrick Dubroy5f445422011-02-18 14:35:21 -08003183 /**
3184 * Add an item from all apps or customize onto the given workspace screen.
3185 * If layout is null, add to the current screen.
3186 */
3187 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003188 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003189 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003190 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003191 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003192
Winson Chungdff8ebb2011-09-08 17:25:31 -07003193 /** Maps the current orientation to an index for referencing orientation correct global icons */
3194 private int getCurrentOrientationIndexForGlobalIcons() {
3195 // default - 0, landscape - 1
3196 switch (getResources().getConfiguration().orientation) {
3197 case Configuration.ORIENTATION_LANDSCAPE:
3198 return 1;
3199 default:
3200 return 0;
3201 }
3202 }
3203
Michael Jurkaae65ee32012-04-30 11:45:54 -07003204 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003205 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003206 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003207 // Look for the toolbar icon specified in the activity meta-data
3208 Bundle metaData = packageManager.getActivityInfo(
3209 activityName, PackageManager.GET_META_DATA).metaData;
3210 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003211 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003212 if (iconResId != 0) {
3213 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003214 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003215 }
3216 }
3217 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003218 // This can happen if the activity defines an invalid drawable
3219 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3220 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003221 } catch (Resources.NotFoundException nfe) {
3222 // This can happen if the activity defines an invalid drawable
3223 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3224 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003225 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003226 return null;
3227 }
3228
3229 // if successful in getting icon, return it; otherwise, set button to use default drawable
3230 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003231 int buttonId, ComponentName activityName, int fallbackDrawableId,
3232 String toolbarResourceName) {
3233 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003234 Resources r = getResources();
3235 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3236 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003237
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003238 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003239 // If we were unable to find the icon via the meta-data, use a generic one
3240 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003241 toolbarIcon = r.getDrawable(fallbackDrawableId);
3242 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003243 if (button != null) {
3244 button.setCompoundDrawables(toolbarIcon, null, null, null);
3245 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003246 return null;
3247 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003248 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003249 if (button != null) {
3250 button.setCompoundDrawables(toolbarIcon, null, null, null);
3251 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003252 return toolbarIcon.getConstantState();
3253 }
3254 }
3255
3256 // if successful in getting icon, return it; otherwise, set button to use default drawable
3257 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003258 int buttonId, ComponentName activityName, int fallbackDrawableId,
3259 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003260 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003261 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003262
Michael Jurka19e0fc52011-07-22 18:00:21 -07003263 if (button != null) {
3264 // If we were unable to find the icon via the meta-data, use a
3265 // generic one
3266 if (toolbarIcon == null) {
3267 button.setImageResource(fallbackDrawableId);
3268 } else {
3269 button.setImageDrawable(toolbarIcon);
3270 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003271 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003272
3273 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3274
Michael Jurka0423dcf2010-10-05 14:56:18 -07003275 }
3276
Winson Chung1b884092012-06-08 17:13:02 -07003277 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003278 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003279 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003280 }
3281
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003282 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003283 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003284 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003285 }
3286
Winson Chungbb185bd2011-11-21 12:31:42 -08003287 private void invalidatePressedFocusedStates(View container, View button) {
3288 if (container instanceof HolographicLinearLayout) {
3289 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3290 layout.invalidatePressedFocusedStates();
3291 } else if (button instanceof HolographicImageView) {
3292 HolographicImageView view = (HolographicImageView) button;
3293 view.invalidatePressedFocusedStates();
3294 }
3295 }
3296
Cristina Stancu476493b2013-08-07 17:20:14 +01003297 public View getQsbBar() {
3298 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003299 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3300 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003301 }
3302 return mQsbBar;
3303 }
3304
3305 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003306 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003307 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003308 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003309 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003310
Winson Chung1cad91e2011-05-25 17:41:01 -07003311 final SearchManager searchManager =
3312 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3313 ComponentName activityName = searchManager.getGlobalSearchActivity();
3314 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003315 int coi = getCurrentOrientationIndexForGlobalIcons();
3316 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003317 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3318 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3319 if (sGlobalSearchIcon[coi] == null) {
3320 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3321 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3322 TOOLBAR_ICON_METADATA_NAME);
3323 }
3324
Winson Chungc51db6a2011-10-05 11:44:49 -07003325 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3326 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003327 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003328 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003329 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003330 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003331 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3332 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003333 if (searchButton != null) searchButton.setVisibility(View.GONE);
3334 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003335 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003336 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003337 }
3338 }
3339
Cristina Stancu476493b2013-08-07 17:20:14 +01003340 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003341 final View searchButtonContainer = findViewById(R.id.search_button_container);
3342 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003343 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003344 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003345 }
3346
Cristina Stancu476493b2013-08-07 17:20:14 +01003347 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003348 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003349 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003350
Winson Chungc51db6a2011-10-05 11:44:49 -07003351 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003352 final SearchManager searchManager =
3353 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3354 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3355
3356 ComponentName activityName = null;
3357 if (globalSearchActivity != null) {
3358 // Check if the global search activity handles voice search
3359 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3360 intent.setPackage(globalSearchActivity.getPackageName());
3361 activityName = intent.resolveActivity(getPackageManager());
3362 }
3363
3364 if (activityName == null) {
3365 // Fallback: check if an activity other than the global search activity
3366 // resolves this
3367 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3368 activityName = intent.resolveActivity(getPackageManager());
3369 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003370 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003371 int coi = getCurrentOrientationIndexForGlobalIcons();
3372 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003373 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3374 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3375 if (sVoiceSearchIcon[coi] == null) {
3376 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3377 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3378 TOOLBAR_ICON_METADATA_NAME);
3379 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003380 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003381 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003382 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003383 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003384 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003385 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003386 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003387 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003388 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003389 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003390 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003391 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003392
Cristina Stancu476493b2013-08-07 17:20:14 +01003393 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003394 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3395 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003396 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003397 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003398 }
3399
Winson Chung5841efa2013-09-30 18:06:44 -07003400 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003401 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3402 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003403 boolean visible = !forceDisableVoiceButtonProxy &&
3404 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003405 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003406 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003407 }
3408 }
Winson Chung5841efa2013-09-30 18:06:44 -07003409
3410 /**
3411 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3412 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3413 */
3414 public void disableVoiceButtonProxy(boolean disabled) {
3415 updateVoiceButtonProxyVisible(disabled);
3416 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003417 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003418 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003419 */
3420 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003421 if (!DISABLE_MARKET_BUTTON) {
3422 final View marketButton = findViewById(R.id.market_button);
3423 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3424 // Find the app market activity by resolving an intent.
3425 // (If multiple app markets are installed, it will return the ResolverActivity.)
3426 ComponentName activityName = intent.resolveActivity(getPackageManager());
3427 if (activityName != null) {
3428 int coi = getCurrentOrientationIndexForGlobalIcons();
3429 mAppMarketIntent = intent;
3430 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3431 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3432 TOOLBAR_ICON_METADATA_NAME);
3433 marketButton.setVisibility(View.VISIBLE);
3434 } else {
3435 // We should hide and disable the view so that we don't try and restore the visibility
3436 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3437 marketButton.setVisibility(View.GONE);
3438 marketButton.setEnabled(false);
3439 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003440 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003441 }
3442
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003443 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003444 if (!DISABLE_MARKET_BUTTON) {
3445 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3446 Resources r = getResources();
3447 Drawable marketIconDrawable = d.newDrawable(r);
3448 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3449 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3450 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003451
Winson Chungd64a6662013-09-30 11:06:59 -07003452 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3453 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003454 }
3455
Michael Jurkad7c28052012-04-27 15:43:36 -07003456 @Override
3457 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003458 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003459 final List<CharSequence> text = event.getText();
3460 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003461 // Populate event with a fake title based on the current state.
3462 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003463 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003464 } else {
3465 text.add(getString(R.string.all_apps_home_button_label));
3466 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003467 return result;
3468 }
3469
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003470 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003471 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003472 */
3473 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3474 @Override
3475 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003476 closeSystemDialogs();
3477 }
3478 }
3479
3480 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003481 * Receives notifications whenever the appwidgets are reset.
3482 */
3483 private class AppWidgetResetObserver extends ContentObserver {
3484 public AppWidgetResetObserver() {
3485 super(new Handler());
3486 }
3487
3488 @Override
3489 public void onChange(boolean selfChange) {
3490 onAppWidgetReset();
3491 }
3492 }
3493
3494 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003495 * If the activity is currently paused, signal that we need to run the passed Runnable
3496 * in onResume.
3497 *
3498 * This needs to be called from incoming places where resources might have been loaded
3499 * while we are paused. That is becaues the Configuration might be wrong
3500 * when we're not running, and if it comes back to what it was when we
3501 * were paused, we are not restarted.
3502 *
3503 * Implementation of the method from LauncherModel.Callbacks.
3504 *
3505 * @return true if we are currently paused. The caller might be able to
3506 * skip some work in that case since we will come back again.
3507 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003508 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003509 if (mPaused) {
3510 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003511 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003512 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003513 }
3514 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003515 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003516 return true;
3517 } else {
3518 return false;
3519 }
3520 }
3521
Michael Jurkac402cd92013-05-20 15:49:32 +02003522 private boolean waitUntilResume(Runnable run) {
3523 return waitUntilResume(run, false);
3524 }
3525
Michael Jurka1e2f4652013-07-08 18:03:46 -07003526 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003527 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003528 }
3529
Michael Jurka7607c2f2013-04-03 14:33:19 -07003530 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003531 * If the activity is currently paused, signal that we need to re-run the loader
3532 * in onResume.
3533 *
3534 * This needs to be called from incoming places where resources might have been loaded
3535 * while we are paused. That is becaues the Configuration might be wrong
3536 * when we're not running, and if it comes back to what it was when we
3537 * were paused, we are not restarted.
3538 *
3539 * Implementation of the method from LauncherModel.Callbacks.
3540 *
3541 * @return true if we are currently paused. The caller might be able to
3542 * skip some work in that case since we will come back again.
3543 */
3544 public boolean setLoadOnResume() {
3545 if (mPaused) {
3546 Log.i(TAG, "setLoadOnResume");
3547 mOnResumeNeedsLoad = true;
3548 return true;
3549 } else {
3550 return false;
3551 }
3552 }
3553
3554 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003555 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003556 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003557 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003558 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003559 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003560 } else {
3561 return SCREEN_COUNT / 2;
3562 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003563 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003564
Joe Onorato9c1289c2009-08-17 11:03:03 -04003565 /**
3566 * Refreshes the shortcuts shown on the workspace.
3567 *
3568 * Implementation of the method from LauncherModel.Callbacks.
3569 */
3570 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003571 // If we're starting binding all over again, clear any bind calls we'd postponed in
3572 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3573 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003574 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003575
Winson Chungd64d1762013-08-20 14:37:16 -07003576 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003577 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003578 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003579
Michael Jurka05bf6442011-11-30 20:28:53 -08003580 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003581 if (mHotseat != null) {
3582 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003583 }
3584 }
3585
Adam Cohendcd297f2013-06-18 13:13:40 -07003586 @Override
3587 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003588 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003589
Adam Cohen5084cba2013-09-03 12:01:16 -07003590 // If there are no screens, we need to have an empty screen
3591 if (orderedScreenIds.size() == 0) {
3592 mWorkspace.addExtraEmptyScreen();
3593 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003594
3595 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003596 // setCurrentPage() so ensure that all pages are added before calling this).
3597 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003598 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3599 mWorkspace.createCustomContentPage();
3600 }
Winson Chung64359a52013-07-08 17:17:08 -07003601 }
3602
3603 @Override
3604 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003605 int count = orderedScreenIds.size();
3606 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003607 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003608 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003609 }
3610
Adam Cohen39a06042013-07-19 14:30:12 -07003611 private boolean shouldShowWeightWatcher() {
3612 String spKey = LauncherAppState.getSharedPreferencesKey();
3613 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003614 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003615
3616 return show;
3617 }
3618
3619 private void toggleShowWeightWatcher() {
3620 String spKey = LauncherAppState.getSharedPreferencesKey();
3621 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3622 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3623
3624 show = !show;
3625
3626 SharedPreferences.Editor editor = sp.edit();
3627 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3628 editor.commit();
3629
3630 if (mWeightWatcher != null) {
3631 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3632 }
3633 }
3634
Winson Chungd64d1762013-08-20 14:37:16 -07003635 public void bindAppsAdded(final ArrayList<Long> newScreens,
3636 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003637 final ArrayList<ItemInfo> addAnimated,
3638 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003639 Runnable r = new Runnable() {
3640 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003641 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003642 }
3643 };
3644 if (waitUntilResume(r)) {
3645 return;
3646 }
3647
Winson Chungd64d1762013-08-20 14:37:16 -07003648 // Add the new screens
3649 bindAddScreens(newScreens);
3650
3651 // We add the items without animation on non-visible pages, and with
3652 // animations on the new page (which we will try and snap to).
3653 if (!addNotAnimated.isEmpty()) {
3654 bindItems(addNotAnimated, 0,
3655 addNotAnimated.size(), false);
3656 }
3657 if (!addAnimated.isEmpty()) {
3658 bindItems(addAnimated, 0,
3659 addAnimated.size(), true);
3660 }
Winson Chungc58497e2013-09-03 17:48:37 -07003661
Winson Chung87412982013-10-03 18:34:14 -07003662 // Remove the extra empty screen
3663 mWorkspace.removeExtraEmptyScreen();
3664
Winson Chungc58497e2013-09-03 17:48:37 -07003665 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3666 addedApps != null && mAppsCustomizeContent != null) {
3667 mAppsCustomizeContent.addApps(addedApps);
3668 }
Winson Chungd64d1762013-08-20 14:37:16 -07003669 }
3670
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003671 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003672 * Bind the items start-end from the list.
3673 *
3674 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003675 */
Winson Chung64359a52013-07-08 17:17:08 -07003676 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3677 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003678 Runnable r = new Runnable() {
3679 public void run() {
3680 bindItems(shortcuts, start, end, forceAnimateIcons);
3681 }
3682 };
3683 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003684 return;
3685 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003686
Winson Chungf0c6ae02012-03-21 16:10:31 -07003687 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003688 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3689 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003690 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003691 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003692 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003693 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003694 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003695
3696 // Short circuit if we are loading dock items for a configuration which has no dock
3697 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3698 mHotseat == null) {
3699 continue;
3700 }
3701
Joe Onorato9c1289c2009-08-17 11:03:03 -04003702 switch (item.itemType) {
3703 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3704 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003705 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003706 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003707
Winson Chung64359a52013-07-08 17:17:08 -07003708 /*
3709 * TODO: FIX collision case
3710 */
Winson Chungce376632013-07-11 16:12:41 -07003711 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3712 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3713 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3714 throw new RuntimeException("OCCUPIED");
3715 }
Winson Chung64359a52013-07-08 17:17:08 -07003716 }
3717
Adam Cohendcd297f2013-06-18 13:13:40 -07003718 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3719 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003720 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003721 // Animate all the applications up now
3722 shortcut.setAlpha(0f);
3723 shortcut.setScaleX(0f);
3724 shortcut.setScaleY(0f);
3725 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003726 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003727 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003728 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003729 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003730 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003731 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003732 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003733 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3734 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003735 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003736 default:
3737 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003738 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003739 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003740
Winson Chung997a9232013-07-24 15:33:46 -07003741 if (animateIcons) {
3742 // Animate to the correct page
3743 if (newShortcutsScreenId > -1) {
3744 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003745 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003746 final Runnable startBounceAnimRunnable = new Runnable() {
3747 public void run() {
3748 anim.playTogether(bounceAnims);
3749 anim.start();
3750 }
3751 };
Winson Chung997a9232013-07-24 15:33:46 -07003752 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003753 // We post the animation slightly delayed to prevent slowdowns
3754 // when we are loading right after we return to launcher.
3755 mWorkspace.postDelayed(new Runnable() {
3756 public void run() {
3757 mWorkspace.snapToPage(newScreenIndex);
Winson Chungb2323832013-10-03 15:22:09 -07003758 mWorkspace.postDelayed(startBounceAnimRunnable,
3759 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07003760 }
3761 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003762 } else {
3763 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003764 }
3765 }
Winson Chung64359a52013-07-08 17:17:08 -07003766 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003767 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003768 }
3769
Joe Onorato9c1289c2009-08-17 11:03:03 -04003770 /**
3771 * Implementation of the method from LauncherModel.Callbacks.
3772 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003773 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003774 Runnable r = new Runnable() {
3775 public void run() {
3776 bindFolders(folders);
3777 }
3778 };
3779 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003780 return;
3781 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003782 sFolders.clear();
3783 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003784 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003785
3786 /**
3787 * Add the views for a widget to the workspace.
3788 *
3789 * Implementation of the method from LauncherModel.Callbacks.
3790 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003791 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003792 Runnable r = new Runnable() {
3793 public void run() {
3794 bindAppWidget(item);
3795 }
3796 };
3797 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003798 return;
3799 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003800
Daniel Sandler843e8602010-06-07 14:59:01 -04003801 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3802 if (DEBUG_WIDGETS) {
3803 Log.d(TAG, "bindAppWidget: " + item);
3804 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003805 final Workspace workspace = mWorkspace;
3806
3807 final int appWidgetId = item.appWidgetId;
3808 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003809 if (DEBUG_WIDGETS) {
3810 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3811 }
3812
Joe Onorato9c1289c2009-08-17 11:03:03 -04003813 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3814
Joe Onorato9c1289c2009-08-17 11:03:03 -04003815 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003816 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003817
Adam Cohendcd297f2013-06-18 13:13:40 -07003818 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003819 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003820 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3821
Joe Onorato9c1289c2009-08-17 11:03:03 -04003822 workspace.requestLayout();
3823
Daniel Sandler843e8602010-06-07 14:59:01 -04003824 if (DEBUG_WIDGETS) {
3825 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3826 + (SystemClock.uptimeMillis()-start) + "ms");
3827 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003828 }
3829
Adam Cohen1462de32012-07-24 22:34:36 -07003830 public void onPageBoundSynchronously(int page) {
3831 mSynchronouslyBoundPages.add(page);
3832 }
3833
Joe Onorato9c1289c2009-08-17 11:03:03 -04003834 /**
3835 * Callback saying that there aren't any more items to bind.
3836 *
3837 * Implementation of the method from LauncherModel.Callbacks.
3838 */
Adam Cohene25af792013-06-06 23:08:25 -07003839 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003840 Runnable r = new Runnable() {
3841 public void run() {
3842 finishBindingItems(upgradePath);
3843 }
3844 };
3845 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003846 return;
3847 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003848 if (mSavedState != null) {
3849 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003850 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003851 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003852 mSavedState = null;
3853 }
3854
Adam Cohen1462de32012-07-24 22:34:36 -07003855 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003856
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003857 // If we received the result of any pending adds while the loader was running (e.g. the
3858 // widget configuration forced an orientation change), process them now.
3859 for (int i = 0; i < sPendingAddList.size(); i++) {
3860 completeAdd(sPendingAddList.get(i));
3861 }
3862 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003863
Winson Chungc51db6a2011-10-05 11:44:49 -07003864 // Update the market app icon as necessary (the other icons will be managed in response to
3865 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003866 if (!DISABLE_MARKET_BUTTON) {
3867 updateAppMarketIcon();
3868 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003869
Winson Chungf0c6ae02012-03-21 16:10:31 -07003870 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003871 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003872 mWorkspace.getUniqueComponents(true, null);
3873 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003874 }
Adam Cohen99894d92013-06-14 11:22:59 -07003875
Adam Cohen66a01fd2013-06-11 12:48:00 -07003876 mWorkspace.post(new Runnable() {
3877 @Override
3878 public void run() {
3879 onFinishBindingItems();
3880 }
3881 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003882 }
3883
Winson Chunga0b7e862013-09-05 16:03:15 -07003884 public boolean isAllAppsButtonRank(int rank) {
3885 if (mHotseat != null) {
3886 return mHotseat.isAllAppsButtonRank(rank);
3887 }
3888 return false;
3889 }
3890
Winson Chunga2413752012-04-03 14:22:34 -07003891 private boolean canRunNewAppsAnimation() {
3892 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3893 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3894 }
3895
Winson Chungc9168342013-06-26 14:54:55 -07003896 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3897 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3898 PropertyValuesHolder.ofFloat("alpha", 1f),
3899 PropertyValuesHolder.ofFloat("scaleX", 1f),
3900 PropertyValuesHolder.ofFloat("scaleY", 1f));
3901 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3902 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3903 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3904 return bounceAnim;
3905 }
3906
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003907 @Override
3908 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003909 boolean searchVisible = updateGlobalSearchIcon();
3910 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003911 if (mSearchDropTargetBar != null) {
3912 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3913 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003914 }
3915
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003916 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003917 * Add the icons for all apps.
3918 *
3919 * Implementation of the method from LauncherModel.Callbacks.
3920 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003921 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003922 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3923 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3924 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3925 getHotseat().addAllAppsFolder(mIconCache, apps,
3926 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3927 }
3928 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003929 }
Winson Chungc58497e2013-09-03 17:48:37 -07003930 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07003931 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07003932 mAppsCustomizeContent.setApps(apps);
3933 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003934 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003935 }
3936
3937 /**
3938 * A package was updated.
3939 *
3940 * Implementation of the method from LauncherModel.Callbacks.
3941 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003942 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003943 Runnable r = new Runnable() {
3944 public void run() {
3945 bindAppsUpdated(apps);
3946 }
3947 };
3948 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003949 return;
3950 }
3951
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003952 if (mWorkspace != null) {
3953 mWorkspace.updateShortcuts(apps);
3954 }
Winson Chungc58497e2013-09-03 17:48:37 -07003955
3956 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3957 mAppsCustomizeContent != null) {
3958 mAppsCustomizeContent.updateApps(apps);
3959 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003960 }
3961
3962 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003963 * A package was uninstalled. We take both the super set of packageNames
3964 * in addition to specific applications to remove, the reason being that
3965 * this can be called when a package is updated as well. In that scenario,
3966 * we only remove specific components from the workspace, where as
3967 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003968 *
3969 * Implementation of the method from LauncherModel.Callbacks.
3970 */
Winson Chung83892cc2013-05-01 16:53:33 -07003971 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003972 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003973 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003974 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003975 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003976 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003977 }
Winson Chungd64d1762013-08-20 14:37:16 -07003978 };
3979 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003980 return;
3981 }
3982
Winson Chung64359a52013-07-08 17:17:08 -07003983 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003984 mWorkspace.removeItemsByPackageName(packageNames);
3985 } else {
3986 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003987 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003988
Winson Chunga1820962011-10-03 16:31:06 -07003989 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003990 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003991
3992 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3993 mAppsCustomizeContent != null) {
3994 mAppsCustomizeContent.removeApps(appInfos);
3995 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003996 }
Joe Onoratobe386092009-11-17 17:32:16 -08003997
3998 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003999 * A number of packages were updated.
4000 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004001 private ArrayList<Object> mWidgetsAndShortcuts;
4002 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004003 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004004 bindPackagesUpdated(mWidgetsAndShortcuts);
4005 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004006 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004007 };
4008
4009 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4010 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4011 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004012 return;
4013 }
4014
Winson Chung64359a52013-07-08 17:17:08 -07004015 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07004016 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4017 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004018 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004019 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004020 }
4021
Winson Chung400438b2011-01-16 17:53:48 -08004022 private int mapConfigurationOriActivityInfoOri(int configOri) {
4023 final Display d = getWindowManager().getDefaultDisplay();
4024 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4025 switch (d.getRotation()) {
4026 case Surface.ROTATION_0:
4027 case Surface.ROTATION_180:
4028 // We are currently in the same basic orientation as the natural orientation
4029 naturalOri = configOri;
4030 break;
4031 case Surface.ROTATION_90:
4032 case Surface.ROTATION_270:
4033 // We are currently in the other basic orientation to the natural orientation
4034 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4035 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4036 break;
4037 }
4038
4039 int[] oriMap = {
4040 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4041 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4042 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4043 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4044 };
4045 // Since the map starts at portrait, we need to offset if this device's natural orientation
4046 // is landscape.
4047 int indexOffset = 0;
4048 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4049 indexOffset = 1;
4050 }
4051 return oriMap[(d.getRotation() + indexOffset) % 4];
4052 }
Adam Cohen446e9402011-09-15 18:21:21 -07004053
Winson Chung4b919f82012-05-01 10:44:08 -07004054 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004055 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004056 getResources().getBoolean(R.bool.allow_rotation);
4057 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004058 }
Winson Chung4b919f82012-05-01 10:44:08 -07004059 public void lockScreenOrientation() {
4060 if (isRotationEnabled()) {
4061 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4062 .getConfiguration().orientation));
4063 }
4064 }
4065 public void unlockScreenOrientation(boolean immediate) {
4066 if (isRotationEnabled()) {
4067 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004068 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004069 } else {
4070 mHandler.postDelayed(new Runnable() {
4071 public void run() {
4072 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4073 }
4074 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004075 }
Winson Chung4b919f82012-05-01 10:44:08 -07004076 }
Winson Chung400438b2011-01-16 17:53:48 -08004077 }
4078
Winson Chung82f55532011-08-09 14:14:23 -07004079 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004080 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004081 if (DISABLE_CLINGS) {
4082 return false;
4083 }
4084
Brett Chabot2a9e2282011-08-23 15:03:13 -07004085 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004086 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004087
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -07004088 // Disable clings for accessibility when explore by touch is enabled
4089 final AccessibilityManager a11yManager = (AccessibilityManager) getSystemService(
4090 ACCESSIBILITY_SERVICE);
4091 if (a11yManager.isTouchExplorationEnabled()) {
4092 return false;
4093 }
4094
Michael Jurkae233a8b2013-03-19 13:49:20 +01004095 // Restricted secondary users (child mode) will potentially have very few apps
4096 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004097// boolean supportsLimitedUsers =
4098// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4099// Account[] accounts = AccountManager.get(this).getAccounts();
4100// if (supportsLimitedUsers && accounts.length == 0) {
4101// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4102// Bundle restrictions = um.getUserRestrictions();
4103// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4104// return false;
4105// }
4106// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004107 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004108 }
Michael Jurka22143132012-10-04 17:42:38 +02004109
Winson Chungfa545132013-09-26 17:45:32 -07004110 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004111 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004112 Cling cling = (Cling) findViewById(clingId);
4113 View scrim = null;
4114 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004115 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004116 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004117 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004118 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004119 cling.show(animate, SHOW_CLING_DURATION);
4120
4121 if (dimNavBarVisibilty) {
4122 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4123 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004124 }
4125 }
4126 return cling;
4127 }
Michael Jurka22143132012-10-04 17:42:38 +02004128
Winson Chungaf40f202013-09-18 18:26:31 -07004129 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4130 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004131 // To catch cases where siblings of top-level views are made invisible, just check whether
4132 // the cling is directly set to GONE before dismissing it.
4133 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004134 final Runnable cleanUpClingCb = new Runnable() {
4135 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004136 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004137 // We should update the shared preferences on a background thread
4138 new Thread("dismissClingThread") {
4139 public void run() {
4140 SharedPreferences.Editor editor = mSharedPrefs.edit();
4141 editor.putBoolean(flag, true);
4142 editor.commit();
4143 }
4144 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004145 if (postAnimationCb != null) {
4146 postAnimationCb.run();
4147 }
4148 }
4149 };
4150 if (duration <= 0) {
4151 cleanUpClingCb.run();
4152 } else {
4153 cling.hide(duration, cleanUpClingCb);
4154 }
Michael Jurka22143132012-10-04 17:42:38 +02004155 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004156
4157 if (restoreNavBarVisibilty) {
4158 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4159 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4160 }
Winson Chung82f55532011-08-09 14:14:23 -07004161 }
4162 }
Michael Jurka22143132012-10-04 17:42:38 +02004163
Winson Chung9d9d74f2011-09-19 11:49:12 -07004164 private void removeCling(int id) {
4165 final View cling = findViewById(id);
4166 if (cling != null) {
4167 final ViewGroup parent = (ViewGroup) cling.getParent();
4168 parent.post(new Runnable() {
4169 @Override
4170 public void run() {
4171 parent.removeView(cling);
4172 }
4173 });
Michael Jurka22143132012-10-04 17:42:38 +02004174 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004175 }
4176 }
Michael Jurka974c3862012-05-22 22:00:31 -07004177
4178 private boolean skipCustomClingIfNoAccounts() {
4179 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4180 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4181 if (customCling) {
4182 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004183 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004184 Account[] accounts = am.getAccountsByType("com.google");
4185 return accounts.length == 0;
4186 }
4187 return false;
4188 }
4189
Winson Chungaf40f202013-09-18 18:26:31 -07004190 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004191 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004192 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004193 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004194 // If we're not using the default workspace layout, replace workspace cling
4195 // with a custom workspace cling (usually specified in an overlay)
4196 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004197 if (!DISABLE_CUSTOM_CLINGS) {
4198 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4199 getResources().getBoolean(R.bool.config_useCustomClings)) {
4200 // Use a custom cling
4201 View cling = findViewById(R.id.workspace_cling);
4202 ViewGroup clingParent = (ViewGroup) cling.getParent();
4203 int clingIndex = clingParent.indexOfChild(cling);
4204 clingParent.removeViewAt(clingIndex);
4205 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4206 clingParent.addView(customCling, clingIndex);
4207 customCling.setId(R.id.workspace_cling);
4208 }
4209 }
4210 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4211 if (cling != null) {
4212 String sbHintStr = getFirstRunClingSearchBarHint();
4213 String ccHintStr = getFirstRunCustomContentHint();
4214 if (!sbHintStr.isEmpty()) {
4215 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4216 sbHint.setText(sbHintStr);
4217 sbHint.setVisibility(View.VISIBLE);
4218 }
4219 if (!ccHintStr.isEmpty()) {
4220 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4221 ccHint.setText(ccHintStr);
4222 ccHint.setVisibility(View.VISIBLE);
4223 }
Michael Jurka45355c42012-10-08 13:21:35 +02004224 }
Winson Chungfa545132013-09-26 17:45:32 -07004225 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004226 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004227 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004228 }
4229 }
Winson Chungaf40f202013-09-18 18:26:31 -07004230
Winson Chunge6eabff2013-09-24 11:01:23 -07004231 protected String getFirstRunClingSearchBarHint() {
4232 return "";
4233 }
4234 protected String getFirstRunCustomContentHint() {
4235 return "";
4236 }
4237
Winson Chungaf40f202013-09-18 18:26:31 -07004238 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004239 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004240 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004241 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004242 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004243 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004244 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004245 }
4246 }
4247 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004248 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004249 if (isClingsEnabled() &&
4250 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004251 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4252 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004253 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004254 } else {
4255 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004256 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004257 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004258 }
Michael Jurka104c4562013-07-08 18:03:46 -07004259 protected SharedPreferences getSharedPrefs() {
4260 return mSharedPrefs;
4261 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004262 public boolean isFolderClingVisible() {
4263 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004264 if (cling != null) {
4265 return cling.getVisibility() == View.VISIBLE;
4266 }
4267 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004268 }
Winson Chungaf40f202013-09-18 18:26:31 -07004269 public void dismissFirstRunCling(View v) {
4270 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4271 Runnable cb = new Runnable() {
4272 public void run() {
4273 // Show the workspace cling next
4274 showFirstRunWorkspaceCling();
4275 }
4276 };
4277 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4278 DISMISS_CLING_DURATION, false);
4279 }
Winson Chung82f55532011-08-09 14:14:23 -07004280 public void dismissWorkspaceCling(View v) {
4281 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004282 Runnable cb = null;
4283 if (v == null) {
4284 cb = new Runnable() {
4285 public void run() {
4286 mWorkspace.enterOverviewMode();
4287 }
4288 };
4289 }
4290 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4291 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004292 }
4293 public void dismissFolderCling(View v) {
4294 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004295 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4296 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004297 }
4298
Winson Chung80baf5a2010-08-09 16:03:15 -07004299 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004300 * Prints out out state for debugging.
4301 */
4302 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004303 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004304 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004305 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4306 Log.d(TAG, "mRestoring=" + mRestoring);
4307 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4308 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004309 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004310 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004311
Winson Chung785d2eb2011-04-14 16:08:02 -07004312 if (mAppsCustomizeContent != null) {
4313 mAppsCustomizeContent.dumpState();
4314 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004315 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004316 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004317
4318 @Override
4319 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4320 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004321 synchronized (sDumpLogs) {
4322 writer.println(" ");
4323 writer.println("Debug logs: ");
4324 for (int i = 0; i < sDumpLogs.size(); i++) {
4325 writer.println(" " + sDumpLogs.get(i));
4326 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004327 }
4328 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004329
4330 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004331 if (DEBUG_DUMP_LOG) {
4332 synchronized (sDumpLogs) {
4333 Log.d(TAG, "");
4334 Log.d(TAG, "*********************");
4335 Log.d(TAG, "Launcher debug logs: ");
4336 for (int i = 0; i < sDumpLogs.size(); i++) {
4337 Log.d(TAG, " " + sDumpLogs.get(i));
4338 }
4339 Log.d(TAG, "*********************");
4340 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004341 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004342 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004343 }
4344
4345 public static void addDumpLog(String tag, String log, boolean debugLog) {
4346 if (debugLog) {
4347 Log.d(tag, log);
4348 }
Winson Chungede41292013-09-19 16:27:36 -07004349 if (DEBUG_DUMP_LOG) {
4350 sDateStamp.setTime(System.currentTimeMillis());
4351 synchronized (sDumpLogs) {
4352 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004353 }
Winson Chungede41292013-09-19 16:27:36 -07004354 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004355 }
4356
Winson Chungede41292013-09-19 16:27:36 -07004357 public void dumpLogsToLocalData() {
4358 if (DEBUG_DUMP_LOG) {
4359 new Thread("DumpLogsToLocalData") {
4360 @Override
4361 public void run() {
4362 boolean success = false;
4363 sDateStamp.setTime(sRunStart);
4364 String FILENAME = sDateStamp.getMonth() + "-"
4365 + sDateStamp.getDay() + "_"
4366 + sDateStamp.getHours() + "-"
4367 + sDateStamp.getMinutes() + "_"
4368 + sDateStamp.getSeconds() + ".txt";
4369
4370 FileOutputStream fos = null;
4371 File outFile = null;
4372 try {
4373 outFile = new File(getFilesDir(), FILENAME);
4374 outFile.createNewFile();
4375 fos = new FileOutputStream(outFile);
4376 } catch (Exception e) {
4377 e.printStackTrace();
4378 }
4379 if (fos != null) {
4380 PrintWriter writer = new PrintWriter(fos);
4381
4382 writer.println(" ");
4383 writer.println("Debug logs: ");
4384 synchronized (sDumpLogs) {
4385 for (int i = 0; i < sDumpLogs.size(); i++) {
4386 writer.println(" " + sDumpLogs.get(i));
4387 }
4388 }
4389 writer.close();
4390 }
4391 try {
4392 if (fos != null) {
4393 fos.close();
4394 success = true;
4395 }
4396 } catch (IOException e) {
4397 e.printStackTrace();
4398 }
4399 }
4400 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004401 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004402 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004403}
Michael Jurka2763be32011-02-24 11:19:57 -08004404
Michael Jurkaabded662011-03-04 12:06:57 -08004405interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004406 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004407 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004408 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004409 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004410 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004411}