blob: 01b1cde99002a77bbb3fe97523103bc0aae308ea [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
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080026import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080031import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070032import android.appwidget.AppWidgetManager;
33import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080035import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080036import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040037import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080038import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070041import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070042import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070043import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080044import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070046import android.content.pm.PackageManager.NameNotFoundException;
Mathew Inwood72fbec12013-11-19 15:45:07 +000047import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070051import android.graphics.Bitmap;
52import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070053import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070054import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040057import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070058import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020060import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080061import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070062import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070063import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040064import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070065import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080066import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.text.Selection;
68import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070069import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070071import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070072import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070073import android.view.Display;
74import android.view.Gravity;
75import android.view.HapticFeedbackConstants;
76import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.view.MotionEvent;
80import android.view.Surface;
81import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070082import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080083import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070084import android.view.ViewGroup;
85import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080086import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080088import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070089import android.view.animation.AccelerateDecelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080090import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.Advanceable;
93import android.widget.FrameLayout;
94import android.widget.ImageView;
95import android.widget.TextView;
96import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070097
Kenny Guyed131872014-04-30 03:02:21 +010098import com.android.launcher3.compat.LauncherActivityInfoCompat;
99import com.android.launcher3.compat.LauncherAppsCompat;
100import com.android.launcher3.compat.UserHandleCompat;
101import com.android.launcher3.compat.UserManagerCompat;
Daniel Sandler325dc232013-06-05 22:57:57 -0400102import com.android.launcher3.DropTarget.DragObject;
Anjali Koppalf5d29132014-02-28 13:33:27 -0800103import com.android.launcher3.PagedView.PageSwitchListener;
Romain Guyedcce092010-03-04 13:03:17 -0800104
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.io.DataInputStream;
106import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700107import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700108import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000119import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700120
Winson Chunga6945242014-01-08 14:04:34 -0800121
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122/**
123 * Default launcher application.
124 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100125public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700126 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700127 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800128 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700129 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130
Daniel Sandlerf061f822013-06-27 13:59:36 -0400131 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400132 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700133 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400134 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700135 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700136
Dan Sandlerd5024042014-01-09 15:01:33 -0500137 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
138
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700140 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700142 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700143 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144
Michael Jurka8b805b12012-04-18 14:23:14 -0700145 private static final int REQUEST_BIND_APPWIDGET = 11;
146
Mathew Inwood876a8462013-06-14 14:12:41 +0100147 /**
148 * IntentStarter uses request codes starting with this. This must be greater than all activity
149 * request codes used internally.
150 */
151 protected static final int REQUEST_LAST = 100;
152
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
154
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800155 static final int SCREEN_COUNT = 5;
156 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157
Romain Guy98d01652009-06-30 16:21:04 -0700158 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800159 // To turn on these properties, type
160 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
161 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
162 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800163 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164
Winson Chung2672ff92012-05-04 16:22:30 -0700165 // The Intent extra that defines whether to ignore the launch animation
166 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400167 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700168
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
170 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700171 // Type: int
172 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
175 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
177 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700178 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700180 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 // Type: boolean
182 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
183 // Type: long
184 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700185 // Type: int
186 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
187 // Type: int
188 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
189 // Type: parcelable
190 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000191 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800192 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000193 // Type: int[]
194 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195
Adam Cohenb54a5982014-01-08 15:21:04 -0800196
Adam Cohen432609a2014-03-13 17:03:22 -0700197 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800198 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
199
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100200 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700201 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100202 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700203 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100204 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700205
Adam Cohen39a06042013-07-19 14:30:12 -0700206 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700207 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700208
Winson Chunga6945242014-01-08 14:04:34 -0800209 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
210
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700211 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700212 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700213 private State mState = State.WORKSPACE;
214 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700215
Joe Onorato9c1289c2009-08-17 11:03:03 -0400216 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700217 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800218 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT_FOLDER_CLOSE = 400;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700219 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700220 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800223 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000225 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
226 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
227
Winson Chunga2413752012-04-03 14:22:34 -0700228 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700229 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
230 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700231 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700232
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800233 private final BroadcastReceiver mCloseSystemDialogsReceiver
234 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800235 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
236
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237 private LayoutInflater mInflater;
238
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800239 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700240 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800241 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800242 private DragLayer mDragLayer;
243 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700244 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800245 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700246
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700247 private AppWidgetManager mAppWidgetManager;
248 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700249
Michael Jurkac9d95c52011-08-29 14:03:34 -0700250 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700251 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800252 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700253
Michael Jurka0280c3b2010-09-17 15:00:07 -0700254 private int[] mTmpAddItemCellCoordinates = new int[2];
255
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256 private FolderInfo mFolderInfo;
257
Winson Chung3d503fb2011-07-13 17:25:49 -0700258 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800259 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700260
Michael Jurka838a4ca2011-02-07 13:33:06 -0800261 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700262
Winson Chungc51db6a2011-10-05 11:44:49 -0700263 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700264 private AppsCustomizeTabHost mAppsCustomizeTabHost;
265 private AppsCustomizePagedView mAppsCustomizeContent;
266 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800267 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700270 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
271 // scroll issues (because the workspace may not have been measured yet) and extra work.
272 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
273 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800274
275 private SpannableStringBuilder mDefaultKeySsb = null;
276
Joe Onorato9c1289c2009-08-17 11:03:03 -0400277 private boolean mWorkspaceLoading = true;
278
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800279 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280 private boolean mRestoring;
281 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700282 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283
Michael Jurka1e2f4652013-07-08 18:03:46 -0700284 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700285 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
286
Winson Chung4a2afa32012-07-19 14:53:05 -0700287 // Keep track of whether the user has left launcher
288 private static boolean sPausedFromUserAction = false;
289
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800290 private Bundle mSavedInstanceState;
291
Joe Onorato9c1289c2009-08-17 11:03:03 -0400292 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800293 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800294 private boolean mUserPresent = true;
295 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700296 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800297 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400298
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700299 private static LocaleConfiguration sLocaleConfiguration = null;
300
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700301 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700302
Adam Cohen61f560d2013-09-30 15:58:20 -0700303 private View.OnTouchListener mHapticFeedbackTouchListener;
304
Adam Cohended9f8d2010-11-03 13:25:16 -0700305 // Related to the auto-advancing of widgets
306 private final int ADVANCE_MSG = 1;
307 private final int mAdvanceInterval = 20000;
308 private final int mAdvanceStagger = 250;
309 private long mAutoAdvanceSentTime;
310 private long mAutoAdvanceTimeLeft = -1;
311 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
312 new HashMap<View, AppWidgetProviderInfo>();
313
Winson Chung400438b2011-01-16 17:53:48 -0800314 // Determines how long to wait after a rotation before restoring the screen orientation to
315 // match the sensor state.
316 private final int mRestoreScreenOrientationDelay = 500;
317
Michael Jurka4ef207b2010-11-29 17:05:45 -0800318 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700319 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
320 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
321 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800322
Winson Chungd64a6662013-09-30 11:06:59 -0700323 private Intent mAppMarketIntent = null;
324 private static final boolean DISABLE_MARKET_BUTTON = true;
325
Craig Mautner360310b2012-10-26 15:13:08 -0700326 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700327
Adam Cohen1462de32012-07-24 22:34:36 -0700328 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700329 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700330
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700331 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700332 static Date sDateStamp = new Date();
333 static DateFormat sDateFormat =
334 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
335 static long sRunStart = System.currentTimeMillis();
336 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700337
Winson Chung46353de2012-02-16 14:05:10 -0800338 // We only want to get the SharedPreferences once since it does an FS stat each time we get
339 // it from the context.
340 private SharedPreferences mSharedPrefs;
341
Adam Cohene25af792013-06-06 23:08:25 -0700342 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
343
Winson Chungf0c6ae02012-03-21 16:10:31 -0700344 // Holds the page that we need to animate to, and the icon views that we need to animate up
345 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700346 private ImageView mFolderIconImageView;
347 private Bitmap mFolderIconBitmap;
348 private Canvas mFolderIconCanvas;
349 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700350
Michael Jurkaddd62e92011-02-16 17:49:14 -0800351 private BubbleTextView mWaitingForResume;
352
Michael Jurkac1f5d262011-09-30 19:32:27 -0700353 private Runnable mBuildLayersRunnable = new Runnable() {
354 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700355 if (mWorkspace != null) {
356 mWorkspace.buildPageHardwareLayers();
357 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700358 }
359 };
360
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800361 private static ArrayList<PendingAddArguments> sPendingAddList
362 = new ArrayList<PendingAddArguments>();
363
Michael Jurka7267fa52013-09-26 15:29:57 -0700364 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800365
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800366 private static class PendingAddArguments {
367 int requestCode;
368 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700369 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700370 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800371 int cellX;
372 int cellY;
373 }
374
Daniel Sandlerff02d492013-08-05 02:12:05 -0400375 private Stats mStats;
376
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800377 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800378 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700379 }
380
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381 @Override
382 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700383 if (DEBUG_STRICT_MODE) {
384 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
385 .detectDiskReads()
386 .detectDiskWrites()
387 .detectNetwork() // or .detectAll() for all detectable problems
388 .penaltyLog()
389 .build());
390 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
391 .detectLeakedSqlLiteObjects()
392 .detectLeakedClosableObjects()
393 .penaltyLog()
394 .penaltyDeath()
395 .build());
396 }
397
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800398 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400399
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400400 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400401 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700402 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700403 // Determine the dynamic grid properties
404 Point smallestSize = new Point();
405 Point largestSize = new Point();
406 Point realSize = new Point();
407 Display display = getWindowManager().getDefaultDisplay();
408 display.getCurrentSizeRange(smallestSize, largestSize);
409 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700410 DisplayMetrics dm = new DisplayMetrics();
411 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700412
Winson Chung5f8afe62013-08-12 16:19:28 -0700413 // Lazy-initialize the dynamic grid
414 DeviceProfile grid = app.initDynamicGrid(this,
415 Math.min(smallestSize.x, smallestSize.y),
416 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700417 realSize.x, realSize.y,
418 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700419
420 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400421 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700422 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800423 mModel = app.setLauncher(this);
424 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700425 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400426 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800427 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700429
Daniel Sandlerff02d492013-08-05 02:12:05 -0400430 mStats = new Stats(this);
431
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700432 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700433
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700434 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
435 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700436
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700437 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
438 // this also ensures that any synchronous binding below doesn't re-trigger another
439 // LauncherModel load.
440 mPaused = false;
441
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200443 android.os.Debug.startMethodTracing(
444 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 }
446
Adam Cohen53805212013-10-01 10:39:23 -0700447
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700450
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800451 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100452 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800453
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800454 registerContentObservers();
455
Joe Onorato7c312c12009-08-13 21:36:53 -0700456 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700457
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 mSavedState = savedInstanceState;
459 restoreState(mSavedState);
460
461 if (PROFILE_STARTUP) {
462 android.os.Debug.stopMethodTracing();
463 }
464
465 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700466 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700467 // If the user leaves launcher, then we should just load items asynchronously when
468 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500469 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700470 } else {
471 // We only load the page synchronously if the user rotates (or triggers a
472 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800473 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700474 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800475 }
476
477 // For handling default keys
478 mDefaultKeySsb = new SpannableStringBuilder();
479 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800480
481 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
482 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800483
Adam Cohenf9426d52012-06-04 17:26:21 -0700484 updateGlobalIcons();
485
486 // On large interfaces, we want the screen to auto-rotate based on the current orientation
487 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700488
Adam Cohen432609a2014-03-13 17:03:22 -0700489 if (shouldShowIntroScreen()) {
490 showIntroScreen();
491 } else {
492 showFirstRunActivity();
493 }
494
Winson Chunge43a1e72014-01-15 10:33:02 -0800495 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
496 // on the device, then we always show the first run cling experience (or if there is no
497 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800498 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
499 if (mModel.canMigrateFromOldLauncherDb(this)) {
500 mLauncherClings.showMigrationCling();
501 } else {
502 mLauncherClings.showFirstRunCling();
503 }
Winson Chunga6945242014-01-08 14:04:34 -0800504 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800505 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800506 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700507 }
508
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700509 @Override
510 public void onLauncherProviderChange() { }
511
Winson Chung4a2afa32012-07-19 14:53:05 -0700512 protected void onUserLeaveHint() {
513 super.onUserLeaveHint();
514 sPausedFromUserAction = true;
515 }
516
Winson Chung98ca0f72013-07-29 12:58:51 -0700517 /** To be overriden by subclasses to hint to Launcher that we have custom content */
518 protected boolean hasCustomContentToLeft() {
519 return false;
520 }
521
Dave Hawkeya8881582013-09-17 15:55:33 -0600522 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500523 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600524 * {@link #addToCustomContentPage}. This will only be invoked if
525 * {@link #hasCustomContentToLeft()} is {@code true}.
526 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500527 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600528 }
529
530 /**
531 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
532 * ensure the custom content page is added or removed if necessary.
533 */
534 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600535 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600536 // Not bound yet, wait for bindScreens to be called.
537 return;
538 }
539
540 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
541 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500542 mWorkspace.createCustomContentContainer();
543 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600544 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
545 mWorkspace.removeCustomContentPage();
546 }
547 }
548
Adam Cohenf9426d52012-06-04 17:26:21 -0700549 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700550 boolean searchVisible = false;
551 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800552 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700553 int coi = getCurrentOrientationIndexForGlobalIcons();
554 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
555 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700556 if (!DISABLE_MARKET_BUTTON) {
557 updateAppMarketIcon();
558 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700559 searchVisible = updateGlobalSearchIcon();
560 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700561 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700562 if (sGlobalSearchIcon[coi] != null) {
563 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700564 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700565 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700566 if (sVoiceSearchIcon[coi] != null) {
567 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700568 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700569 }
Winson Chungd64a6662013-09-30 11:06:59 -0700570 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700571 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800572 }
Winson Chungadf0c182012-08-23 14:59:07 -0700573 if (mSearchDropTargetBar != null) {
574 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
575 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800576 }
Romain Guycbb89e42009-06-08 15:52:54 -0700577
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800578 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700579 if (sLocaleConfiguration == null) {
580 new AsyncTask<Void, Void, LocaleConfiguration>() {
581 @Override
582 protected LocaleConfiguration doInBackground(Void... unused) {
583 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
584 readConfiguration(Launcher.this, localeConfiguration);
585 return localeConfiguration;
586 }
587
588 @Override
589 protected void onPostExecute(LocaleConfiguration result) {
590 sLocaleConfiguration = result;
591 checkForLocaleChange(); // recursive, but now with a locale configuration
592 }
593 }.execute();
594 return;
595 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700596
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800597 final Configuration configuration = getResources().getConfiguration();
598
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700599 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800600 final String locale = configuration.locale.toString();
601
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700602 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800603 final int mcc = configuration.mcc;
604
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700605 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800606 final int mnc = configuration.mnc;
607
Romain Guy84f296c2009-11-04 15:00:44 -0800608 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800609
Romain Guy84f296c2009-11-04 15:00:44 -0800610 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700611 sLocaleConfiguration.locale = locale;
612 sLocaleConfiguration.mcc = mcc;
613 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700614
Joe Onorato0589f0f2010-02-08 13:44:00 -0800615 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700616
617 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100618 new AsyncTask<Void, Void, Void>() {
619 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700620 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100621 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700622 }
Michael Jurka43467462013-11-14 12:03:58 +0100623 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700624 }
625 }
626
627 private static class LocaleConfiguration {
628 public String locale;
629 public int mcc = -1;
630 public int mnc = -1;
631 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700632
Romain Guy98d01652009-06-30 16:21:04 -0700633 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
634 DataInputStream in = null;
635 try {
636 in = new DataInputStream(context.openFileInput(PREFERENCES));
637 configuration.locale = in.readUTF();
638 configuration.mcc = in.readInt();
639 configuration.mnc = in.readInt();
640 } catch (FileNotFoundException e) {
641 // Ignore
642 } catch (IOException e) {
643 // Ignore
644 } finally {
645 if (in != null) {
646 try {
647 in.close();
648 } catch (IOException e) {
649 // Ignore
650 }
651 }
652 }
653 }
654
655 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
656 DataOutputStream out = null;
657 try {
658 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
659 out.writeUTF(configuration.locale);
660 out.writeInt(configuration.mcc);
661 out.writeInt(configuration.mnc);
662 out.flush();
663 } catch (FileNotFoundException e) {
664 // Ignore
665 } catch (IOException e) {
666 //noinspection ResultOfMethodCallIgnored
667 context.getFileStreamPath(PREFERENCES).delete();
668 } finally {
669 if (out != null) {
670 try {
671 out.close();
672 } catch (IOException e) {
673 // Ignore
674 }
675 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800676 }
677 }
678
Anton Hanssona2f665f2013-09-26 12:18:32 +0100679 public Stats getStats() {
680 return mStats;
681 }
682
Bjorn Bringertc459e522013-06-07 19:36:01 +0100683 public LayoutInflater getInflater() {
684 return mInflater;
685 }
686
Winson Chung36a62fe2012-05-06 18:04:42 -0700687 boolean isDraggingEnabled() {
688 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
689 // that is subsequently removed from the workspace in startBinding().
690 return !mModel.isLoadingWorkspace();
691 }
692
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 static int getScreen() {
694 synchronized (sLock) {
695 return sScreen;
696 }
697 }
698
699 static void setScreen(int screen) {
700 synchronized (sLock) {
701 sScreen = screen;
702 }
703 }
704
Winson Chung557d6ed2011-07-08 15:34:52 -0700705 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000706 * Copied from View -- the View version of the method isn't called
707 * anywhere else in our process and only exists for API level 17+,
708 * so it's ok to keep our own version with no API requirement.
709 */
710 public static int generateViewId() {
711 for (;;) {
712 final int result = sNextGeneratedId.get();
713 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
714 int newValue = result + 1;
715 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
716 if (sNextGeneratedId.compareAndSet(result, newValue)) {
717 return result;
718 }
719 }
720 }
721
722 public int getViewIdForItem(ItemInfo info) {
723 // This cast is safe given the > 2B range for int.
724 int itemId = (int) info.id;
725 if (mItemIdToViewId.containsKey(itemId)) {
726 return mItemIdToViewId.get(itemId);
727 }
728 int viewId = generateViewId();
729 mItemIdToViewId.put(itemId, viewId);
730 return viewId;
731 }
732
733 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700734 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
735 * a configuration step, this allows the proper animations to run after other transitions.
736 */
737 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700738 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800739 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800740 case REQUEST_PICK_SHORTCUT:
741 processShortcut(args.intent);
742 break;
743 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700744 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700745 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700746 result = true;
747 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 case REQUEST_CREATE_APPWIDGET:
749 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700750 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700751 result = true;
752 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800753 }
Michael Jurka27614d22012-04-02 06:40:22 -0700754 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
755 // if you turned the screen off and then back while in All Apps, Launcher would not
756 // return to the workspace. Clearing mAddInfo.container here fixes this issue
757 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700758 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800759 }
760
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800761 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700762 protected void onActivityResult(
763 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700764 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700765 setWaitingForResult(false);
Adam Cohen4637b5a2013-11-04 18:21:24 -0800766 int pendingAddWidgetId = mPendingAddWidgetId;
767 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700768
Adam Cohenad4e15c2013-10-17 16:21:35 -0700769 Runnable exitSpringLoaded = new Runnable() {
770 @Override
771 public void run() {
772 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
773 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
774 }
775 };
776
Michael Jurka8b805b12012-04-18 14:23:14 -0700777 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700778 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700779 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
780 if (resultCode == RESULT_CANCELED) {
781 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700782 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
783 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700784 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700785 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
786 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700787 }
788 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200789 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
790 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
791 mWorkspace.exitOverviewMode(false);
792 }
793 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700794 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200795
Adam Cohened66b2b2012-01-23 17:28:51 -0800796 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
797 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700798
Adam Cohened66b2b2012-01-23 17:28:51 -0800799 // We have special handling for widgets
800 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800801 final int appWidgetId;
802 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
803 : -1;
804 if (widgetId < 0) {
805 appWidgetId = pendingAddWidgetId;
806 } else {
807 appWidgetId = widgetId;
808 }
809
Adam Cohenad4e15c2013-10-17 16:21:35 -0700810 final int result;
811 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800812 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700813 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
814 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700815 result = RESULT_CANCELED;
816 completeTwoStageWidgetDrop(result, appWidgetId);
817 onComplete = new Runnable() {
818 @Override
819 public void run() {
820 exitSpringLoadedDragModeDelayed(false, 0, null);
821 }
822 };
Winson Chung5aaab772012-04-27 15:24:02 -0700823 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700824 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700825 final CellLayout dropLayout =
826 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
827 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700828 onComplete = new Runnable() {
829 @Override
830 public void run() {
831 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700832 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700833 }
834 };
Winson Chung5aaab772012-04-27 15:24:02 -0700835 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700836 mWorkspace.removeExtraEmptyScreen(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
837 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800838 return;
839 }
840
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841 // The pattern used here is that a user PICKs a specific application,
842 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700843
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
845 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700846 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800847 final PendingAddArguments args = new PendingAddArguments();
848 args.requestCode = requestCode;
849 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700850 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700851 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700852 args.cellX = mPendingAddInfo.cellX;
853 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800854 if (isWorkspaceLocked()) {
855 sPendingAddList.add(args);
856 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700857 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800858 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700859 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
860 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Adam Cohen00074722013-10-11 17:46:09 -0700861 } else if (resultCode == RESULT_CANCELED) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700862 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
863 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800864 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800865 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800866 }
867
868 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700869 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700870 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800871 Runnable onCompleteRunnable = null;
872 int animationType = 0;
873
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700874 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800875 if (resultCode == RESULT_OK) {
876 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
877 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700878 mPendingAddWidgetInfo);
879 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800880 onCompleteRunnable = new Runnable() {
881 @Override
882 public void run() {
883 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700884 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700885 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
886 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800887 }
888 };
889 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800890 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800891 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800892 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700893 if (mDragLayer.getAnimatedView() != null) {
894 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
895 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
896 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700897 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700898 // The animated view may be null in the case of a rotation during widget configuration
899 onCompleteRunnable.run();
900 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901 }
902
903 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700904 protected void onStop() {
905 super.onStop();
906 FirstFrameAnimatorHelper.setIsVisible(false);
907 }
908
909 @Override
910 protected void onStart() {
911 super.onStart();
912 FirstFrameAnimatorHelper.setIsVisible(true);
913 }
914
915 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200917 long startTime = 0;
918 if (DEBUG_RESUME_TIME) {
919 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400920 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200921 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700923
Winson Chung4a2afa32012-07-19 14:53:05 -0700924 // Restore the previous launcher state
925 if (mOnResumeState == State.WORKSPACE) {
926 showWorkspace(false);
927 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800928 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700929 }
930 mOnResumeState = State.NONE;
931
Craig Mautner360310b2012-10-26 15:13:08 -0700932 // Background was set to gradient in onPause(), restore to black if in all apps.
933 setWorkspaceBackground(mState == State.WORKSPACE);
934
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800935 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700936 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700937 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700938 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500939 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400940 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700941 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800942 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700943 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200944 // We might have postponed some bind calls until onResume (see waitUntilResume) --
945 // execute them here
946 long startTimeCallbacks = 0;
947 if (DEBUG_RESUME_TIME) {
948 startTimeCallbacks = System.currentTimeMillis();
949 }
950
951 if (mAppsCustomizeContent != null) {
952 mAppsCustomizeContent.setBulkBind(true);
953 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700954 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
955 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200956 }
957 if (mAppsCustomizeContent != null) {
958 mAppsCustomizeContent.setBulkBind(false);
959 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700960 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200961 if (DEBUG_RESUME_TIME) {
962 Log.d(TAG, "Time spent processing callbacks in onResume: " +
963 (System.currentTimeMillis() - startTimeCallbacks));
964 }
Michael Jurka447bf842013-05-15 14:52:15 +0200965 }
Michael Jurka54554252013-08-01 12:52:23 +0200966 if (mOnResumeCallbacks.size() > 0) {
967 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
968 mOnResumeCallbacks.get(i).run();
969 }
970 mOnResumeCallbacks.clear();
971 }
Winson Chunge4e50662012-01-23 14:45:13 -0800972
973 // Reset the pressed state of icons that were locked in the press state while activities
974 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800975 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800976 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800977 mWaitingForResume.setStayPressed(false);
978 }
Winson Chunge4e50662012-01-23 14:45:13 -0800979 if (mAppsCustomizeContent != null) {
980 // Resets the previous all apps icon press state
981 mAppsCustomizeContent.resetDrawableState();
982 }
Winson Chung82963d52013-10-09 11:20:57 -0700983
Adam Cohen06dff352012-06-01 17:17:08 -0700984 // It is possible that widgets can receive updates while launcher is not in the foreground.
985 // Consequently, the widgets will be inflated in the orientation of the foreground activity
986 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
987 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700988 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700989
Winson Chung780fe592013-09-26 14:48:44 -0700990 // Process any items that were added while Launcher was away.
991 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
992
Winson Chung5841efa2013-09-30 18:06:44 -0700993 // Update the voice search button proxy
994 updateVoiceButtonProxyVisible(false);
995
Adam Cohenf9426d52012-06-04 17:26:21 -0700996 // Again, as with the above scenario, it's possible that one or more of the global icons
997 // were updated in the wrong orientation.
998 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200999 if (DEBUG_RESUME_TIME) {
1000 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1001 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001002
1003 if (mWorkspace.getCustomContentCallbacks() != null) {
1004 // If we are resuming and the custom content is the current page, we call onShow().
1005 // It is also poassible that onShow will instead be called slightly after first layout
1006 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1007 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001008 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001009 }
1010 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001011 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001012 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001013 }
1014
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001015 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001016 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001017 // Ensure that items added to Launcher are queued until Launcher returns
1018 InstallShortcutReceiver.enableInstallQueue();
1019
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001020 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001021 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001022 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001023 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001024
1025 // We call onHide() aggressively. The custom content callbacks should be able to
1026 // debounce excess onHide calls.
1027 if (mWorkspace.getCustomContentCallbacks() != null) {
1028 mWorkspace.getCustomContentCallbacks().onHide();
1029 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001030 }
Romain Guycbb89e42009-06-08 15:52:54 -07001031
Adam Cohenbffe7452013-07-22 18:21:45 -07001032 QSBScroller mQsbScroller = new QSBScroller() {
1033 int scrollY = 0;
1034
1035 @Override
1036 public void setScrollY(int scroll) {
1037 scrollY = scroll;
1038
1039 if (mWorkspace.isOnOrMovingToCustomContent()) {
1040 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001041 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001042 }
1043 }
1044 };
1045
1046 public void resetQSBScroll() {
1047 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001048 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001049 }
1050
1051 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001052 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1053 // by a onResume or by scrolling otherwise.
1054 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001055
1056 // Custom content is completely hidden
1057 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001058
1059 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1060 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001061 }
1062
Jorim Jaggid017f882014-01-14 17:08:48 -08001063 protected boolean hasSettings() {
1064 return false;
1065 }
1066
Adam Cohenbffe7452013-07-22 18:21:45 -07001067 public interface QSBScroller {
1068 public void setScrollY(int scrollY);
1069 }
1070
Winson Chung98ca0f72013-07-29 12:58:51 -07001071 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001072 CustomContentCallbacks callbacks, String description) {
1073 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001074 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001075 }
1076
Adam Cohenedb40762013-07-18 16:45:45 -07001077 // The custom content needs to offset its content to account for the QSB
1078 public int getTopOffsetForCustomContent() {
1079 return mWorkspace.getPaddingTop();
1080 }
1081
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001082 @Override
1083 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001084 // Flag the loader to stop early before switching
1085 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001086 if (mAppsCustomizeContent != null) {
1087 mAppsCustomizeContent.surrender();
1088 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001089 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001090 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001091
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001092 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001093 @Override
1094 public void onWindowFocusChanged(boolean hasFocus) {
1095 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001096 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001097 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001098
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 private boolean acceptFilter() {
1100 final InputMethodManager inputManager = (InputMethodManager)
1101 getSystemService(Context.INPUT_METHOD_SERVICE);
1102 return !inputManager.isFullscreenMode();
1103 }
1104
1105 @Override
1106 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001107 final int uniChar = event.getUnicodeChar();
1108 final boolean handled = super.onKeyDown(keyCode, event);
1109 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1110 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001111 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1112 keyCode, event);
1113 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001114 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001115 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001116 // showSearchDialog()
1117 // If there are multiple keystrokes before the search dialog takes focus,
1118 // onSearchRequested() will be called for every keystroke,
1119 // but it is idempotent, so it's fine.
1120 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001121 }
1122 }
1123
Joe Onorato8a9625e2010-01-28 15:55:35 -08001124 // Eat the long press event so the keyboard doesn't come up.
1125 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1126 return true;
1127 }
1128
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001129 return handled;
1130 }
1131
Karl Rosaen138a0412009-04-23 19:00:21 -07001132 private String getTypedText() {
1133 return mDefaultKeySsb.toString();
1134 }
1135
1136 private void clearTypedText() {
1137 mDefaultKeySsb.clear();
1138 mDefaultKeySsb.clearSpans();
1139 Selection.setSelection(mDefaultKeySsb, 0);
1140 }
1141
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001142 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001143 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1144 * State
1145 */
1146 private static State intToState(int stateOrdinal) {
1147 State state = State.WORKSPACE;
1148 final State[] stateValues = State.values();
1149 for (int i = 0; i < stateValues.length; i++) {
1150 if (stateValues[i].ordinal() == stateOrdinal) {
1151 state = stateValues[i];
1152 break;
1153 }
1154 }
1155 return state;
1156 }
1157
1158 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001159 * Restores the previous state, if it exists.
1160 *
1161 * @param savedState The previous state.
1162 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001163 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001164 private void restoreState(Bundle savedState) {
1165 if (savedState == null) {
1166 return;
1167 }
1168
Michael Jurka883f55b2010-10-21 15:47:14 -07001169 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001170 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001171 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001172 }
1173
Adam Cohen21cd0022013-10-09 18:57:02 -07001174 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1175 PagedView.INVALID_RESTORE_PAGE);
1176 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001177 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001178 }
1179
Winson Chung3d503fb2011-07-13 17:25:49 -07001180 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001181 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001182
Winson Chung3d503fb2011-07-13 17:25:49 -07001183 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1184 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001185 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001186 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1187 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001188 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1189 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1190 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001191 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001192 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001193 mRestoring = true;
1194 }
1195
1196 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1197 if (renameFolder) {
1198 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001199 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 mRestoring = true;
1201 }
Winson Chunga12a2502010-12-20 14:41:35 -08001202
Winson Chung785d2eb2011-04-14 16:08:02 -07001203 // Restore the AppsCustomize tab
1204 if (mAppsCustomizeTabHost != null) {
1205 String curTab = savedState.getString("apps_customize_currentTab");
1206 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001207 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001208 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001209 mAppsCustomizeContent.loadAssociatedPages(
1210 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001211 }
1212
Winson Chung5afbf7b2011-07-25 11:53:08 -07001213 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1214 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001215 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001216 mItemIdToViewId = (HashMap<Integer, Integer>)
1217 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001218 }
1219
1220 /**
1221 * Finds all the views we need and configure them properly.
1222 */
1223 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001224 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001225
Craig Mautner360310b2012-10-26 15:13:08 -07001226 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001227 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1228 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001229 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001230 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001231
John Spurlock77e1f472013-09-11 10:09:51 -04001232 mLauncherView.setSystemUiVisibility(
1233 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001234 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235
Winson Chung4c98d922011-05-31 16:50:48 -07001236 // Setup the drag layer
1237 mDragLayer.setup(this, dragController);
1238
Winson Chung3d503fb2011-07-13 17:25:49 -07001239 // Setup the hotseat
1240 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1241 if (mHotseat != null) {
1242 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001243 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001244 }
1245
Jorim Jaggid017f882014-01-14 17:08:48 -08001246 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001247 View widgetButton = findViewById(R.id.widget_button);
1248 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001249 @Override
1250 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001251 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001252 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001253 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001254 }
1255 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001256 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1257
1258 View wallpaperButton = findViewById(R.id.wallpaper_button);
1259 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001260 @Override
1261 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001262 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001263 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001264 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001265 }
1266 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001267 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1268
1269 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001270 if (hasSettings()) {
1271 settingsButton.setOnClickListener(new OnClickListener() {
1272 @Override
1273 public void onClick(View arg0) {
1274 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001275 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001276 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001277 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001278 });
1279 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1280 } else {
1281 settingsButton.setVisibility(View.GONE);
1282 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1283 lp.gravity = Gravity.END | Gravity.TOP;
1284 widgetButton.requestLayout();
1285 }
1286
Adam Cohendbdff6b2013-09-18 19:09:15 -07001287 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001288
Winson Chung4c98d922011-05-31 16:50:48 -07001289 // Setup the workspace
1290 mWorkspace.setHapticFeedbackEnabled(false);
1291 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001292 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001293 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001294
Winson Chungf0ea4d32011-06-06 14:27:16 -07001295 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001296 mSearchDropTargetBar = (SearchDropTargetBar)
1297 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001298
Winson Chungf0ea4d32011-06-06 14:27:16 -07001299 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001300 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001301 mAppsCustomizeContent = (AppsCustomizePagedView)
1302 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1303 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001304
Winson Chung3d503fb2011-07-13 17:25:49 -07001305 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001306 dragController.setDragScoller(mWorkspace);
1307 dragController.setScrollView(mDragLayer);
1308 dragController.setMoveTarget(mWorkspace);
1309 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001310 if (mSearchDropTargetBar != null) {
1311 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001312 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001313
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001314 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001315 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001316 mWeightWatcher = new WeightWatcher(this);
1317 mWeightWatcher.setAlpha(0.5f);
1318 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001319 new FrameLayout.LayoutParams(
1320 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001321 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001322 Gravity.BOTTOM)
1323 );
Adam Cohen39a06042013-07-19 14:30:12 -07001324
1325 boolean show = shouldShowWeightWatcher();
1326 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001327 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 }
1329
1330 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001331 * Sets the all apps button. This method is called from {@link Hotseat}.
1332 */
1333 public void setAllAppsButton(View allAppsButton) {
1334 mAllAppsButton = allAppsButton;
1335 }
1336
1337 public View getAllAppsButton() {
1338 return mAllAppsButton;
1339 }
1340
1341 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001342 * Creates a view representing a shortcut.
1343 *
1344 * @param info The data structure describing the shortcut.
1345 *
1346 * @return A View inflated from R.layout.application.
1347 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001348 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001349 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001350 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 }
1352
1353 /**
1354 * Creates a view representing a shortcut inflated from the specified resource.
1355 *
1356 * @param layoutResId The id of the XML layout used to create the shortcut.
1357 * @param parent The group the shortcut belongs to.
1358 * @param info The data structure describing the shortcut.
1359 *
1360 * @return A View inflated from layoutResId.
1361 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001362 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001363 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1364 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001365 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 return favorite;
1367 }
1368
1369 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 * Add a shortcut to the workspace.
1371 *
1372 * @param data The intent describing the shortcut.
1373 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001375 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001376 int cellY) {
1377 int[] cellXY = mTmpAddItemCellCoordinates;
1378 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001379 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001380
Michael Jurkad3ef3062010-11-23 16:23:58 -08001381 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001382
Adam Cohen558baaf2011-08-15 15:22:57 -07001383 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001384 if (info == null) {
1385 return;
1386 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001387 final View view = createShortcut(info);
1388
Adam Cohenfbba09b2011-07-18 21:43:05 -07001389 // First we check if we already know the exact location where we want to add this item.
1390 if (cellX >= 0 && cellY >= 0) {
1391 cellXY[0] = cellX;
1392 cellXY[1] = cellY;
1393 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001394
1395 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001396 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001397 true, null,null)) {
1398 return;
1399 }
1400 DragObject dragObject = new DragObject();
1401 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001402 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1403 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001404 return;
1405 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001406 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001407 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001408 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001409 foundCellSpan = (result != null);
1410 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001411 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001412 }
1413
1414 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001415 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001416 return;
1417 }
1418
Adam Cohendcd297f2013-06-18 13:13:40 -07001419 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420
1421 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001422 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001423 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 }
1425 }
1426
Adam Cohen2f093b62012-04-30 18:59:53 -07001427 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1428 int minHeight) {
1429 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001430 // We want to account for the extra amount of padding that we are adding to the widget
1431 // to ensure that it gets the full amount of space that it has requested
1432 int requiredWidth = minWidth + padding.left + padding.right;
1433 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001434 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001435 }
1436
Adam Cohen2f093b62012-04-30 18:59:53 -07001437 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1438 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001439 }
1440
Adam Cohen2f093b62012-04-30 18:59:53 -07001441 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1442 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001443 }
1444
Adam Cohen2f093b62012-04-30 18:59:53 -07001445 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1446 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001447 }
1448
Adam Cohen2f093b62012-04-30 18:59:53 -07001449 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1450 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001451 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001452 }
1453
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001454 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001455 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001456 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001457 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001458 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001459 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001460 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001461 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1462 if (appWidgetInfo == null) {
1463 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1464 }
Romain Guycbb89e42009-06-08 15:52:54 -07001465
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001466 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001467 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001468
Adam Cohen2f093b62012-04-30 18:59:53 -07001469 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1470 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001471
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001472 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001473 // We have saved the position to which the widget was dragged-- this really only matters
1474 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001475 int[] cellXY = mTmpAddItemCellCoordinates;
1476 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001477 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001478 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001479 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1480 cellXY[0] = mPendingAddInfo.cellX;
1481 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001482 spanXY[0] = mPendingAddInfo.spanX;
1483 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001484 foundCellSpan = true;
1485 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001486 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001487 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001488 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1489 spanXY[1], cellXY, finalSpan);
1490 spanXY[0] = finalSpan[0];
1491 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001492 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001493 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001494 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001495 }
1496
Michael Jurka0280c3b2010-09-17 15:00:07 -07001497 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001498 if (appWidgetId != -1) {
1499 // Deleting an app widget ID is a void call but writes to disk before returning
1500 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001501 new AsyncTask<Void, Void, Void>() {
1502 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001503 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001504 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001505 }
Michael Jurka43467462013-11-14 12:03:58 +01001506 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001507 }
Winson Chung93eef082012-03-23 15:59:27 -07001508 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001509 return;
1510 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001511
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001512 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001513 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1514 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001515 launcherInfo.spanX = spanXY[0];
1516 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001517 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1518 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001519
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001520 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001521 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522
1523 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001524 if (hostView == null) {
1525 // Perform actual inflation because we're live
1526 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1527 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1528 } else {
1529 // The AppWidgetHostView has already been inflated and instantiated
1530 launcherInfo.hostView = hostView;
1531 }
Romain Guycbb89e42009-06-08 15:52:54 -07001532
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001533 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001534 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001535 launcherInfo.notifyWidgetSizeChanged(this);
1536
Adam Cohendcd297f2013-06-18 13:13:40 -07001537 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001538 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001539
1540 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001541 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001542 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543 }
Romain Guycbb89e42009-06-08 15:52:54 -07001544
Adam Cohended9f8d2010-11-03 13:25:16 -07001545 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1546 @Override
1547 public void onReceive(Context context, Intent intent) {
1548 final String action = intent.getAction();
1549 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1550 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001551 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001552 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001553
Winson Chungc100e8e2011-08-09 16:02:43 -07001554 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001555 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001556 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001557 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001558 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001559 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1560 mUserPresent = true;
1561 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001562 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1563 mModel.resetLoadedState(false, true);
1564 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1565 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1566 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1567 mModel.resetLoadedState(false, true);
1568 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1569 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1570 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001571 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1572 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1573 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001574 }
1575 }
1576 };
1577
1578 @Override
1579 public void onAttachedToWindow() {
1580 super.onAttachedToWindow();
1581
1582 // Listen for broadcasts related to user-presence
1583 final IntentFilter filter = new IntentFilter();
1584 filter.addAction(Intent.ACTION_SCREEN_OFF);
1585 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001586 // For handling managed profiles
1587 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1588 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001589 if (ENABLE_DEBUG_INTENTS) {
1590 filter.addAction(DebugIntents.DELETE_DATABASE);
1591 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1592 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001593 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001594 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001595 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001596 mVisible = true;
1597 }
1598
1599 @Override
1600 public void onDetachedFromWindow() {
1601 super.onDetachedFromWindow();
1602 mVisible = false;
1603
Adam Cohend113e0c2010-11-11 10:48:05 -08001604 if (mAttached) {
1605 unregisterReceiver(mReceiver);
1606 mAttached = false;
1607 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001608 updateRunning();
1609 }
1610
1611 public void onWindowVisibilityChanged(int visibility) {
1612 mVisible = visibility == View.VISIBLE;
1613 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001614 // The following code used to be in onResume, but it turns out onResume is called when
1615 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1616 // is a more appropriate event to handle
1617 if (mVisible) {
1618 mAppsCustomizeTabHost.onWindowVisible();
1619 if (!mWorkspaceLoading) {
1620 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001621 // We want to let Launcher draw itself at least once before we force it to build
1622 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001623 // apps is nice and speedy.
1624 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001625 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001626 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001627 if (mStarted) return;
1628 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001629 // We delay the layer building a bit in order to give
1630 // other message processing a time to run. In particular
1631 // this avoids a delay in hiding the IME if it was
1632 // currently shown, because doing that may involve
1633 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001634 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001635 final ViewTreeObserver.OnDrawListener listener = this;
1636 mWorkspace.post(new Runnable() {
1637 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001638 if (mWorkspace != null &&
1639 mWorkspace.getViewTreeObserver() != null) {
1640 mWorkspace.getViewTreeObserver().
1641 removeOnDrawListener(listener);
1642 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001643 }
1644 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001645 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001646 }
1647 });
1648 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001649 // When Launcher comes back to foreground, a different Activity might be responsible for
1650 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001651 if (!DISABLE_MARKET_BUTTON) {
1652 updateAppMarketIcon();
1653 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001654 clearTypedText();
1655 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001656 }
1657
1658 private void sendAdvanceMessage(long delay) {
1659 mHandler.removeMessages(ADVANCE_MSG);
1660 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1661 mHandler.sendMessageDelayed(msg, delay);
1662 mAutoAdvanceSentTime = System.currentTimeMillis();
1663 }
1664
1665 private void updateRunning() {
1666 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1667 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1668 mAutoAdvanceRunning = autoAdvanceRunning;
1669 if (autoAdvanceRunning) {
1670 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1671 sendAdvanceMessage(delay);
1672 } else {
1673 if (!mWidgetsToAdvance.isEmpty()) {
1674 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1675 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1676 }
1677 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001678 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001679 }
1680 }
1681 }
1682
1683 private final Handler mHandler = new Handler() {
1684 @Override
1685 public void handleMessage(Message msg) {
1686 if (msg.what == ADVANCE_MSG) {
1687 int i = 0;
1688 for (View key: mWidgetsToAdvance.keySet()) {
1689 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1690 final int delay = mAdvanceStagger * i;
1691 if (v instanceof Advanceable) {
1692 postDelayed(new Runnable() {
1693 public void run() {
1694 ((Advanceable) v).advance();
1695 }
1696 }, delay);
1697 }
1698 i++;
1699 }
1700 sendAdvanceMessage(mAdvanceInterval);
1701 }
1702 }
1703 };
1704
1705 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001706 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001707 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1708 if (v instanceof Advanceable) {
1709 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001710 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001711 updateRunning();
1712 }
1713 }
1714
1715 void removeWidgetToAutoAdvance(View hostView) {
1716 if (mWidgetsToAdvance.containsKey(hostView)) {
1717 mWidgetsToAdvance.remove(hostView);
1718 updateRunning();
1719 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001720 }
1721
Joe Onorato9c1289c2009-08-17 11:03:03 -04001722 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001723 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001724 launcherInfo.hostView = null;
1725 }
1726
Winson Chung93eef082012-03-23 15:59:27 -07001727 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1728 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1729 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001730 }
1731
Winson Chunga6945242014-01-08 14:04:34 -08001732 public DragLayer getDragLayer() {
1733 return mDragLayer;
1734 }
1735
1736 public Workspace getWorkspace() {
1737 return mWorkspace;
1738 }
1739
1740 public Hotseat getHotseat() {
1741 return mHotseat;
1742 }
1743
Jorim Jaggid017f882014-01-14 17:08:48 -08001744 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001745 return mOverviewPanel;
1746 }
1747
1748 public SearchDropTargetBar getSearchBar() {
1749 return mSearchDropTargetBar;
1750 }
1751
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001752 public LauncherAppWidgetHost getAppWidgetHost() {
1753 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001754 }
Romain Guycbb89e42009-06-08 15:52:54 -07001755
Winson Chunga9abd0e2010-10-27 17:18:37 -07001756 public LauncherModel getModel() {
1757 return mModel;
1758 }
1759
Winson Chunga6945242014-01-08 14:04:34 -08001760 public LauncherClings getLauncherClings() {
1761 return mLauncherClings;
1762 }
1763
1764 protected SharedPreferences getSharedPrefs() {
1765 return mSharedPrefs;
1766 }
1767
Bjorn Bringertc459e522013-06-07 19:36:01 +01001768 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001769 getWindow().closeAllPanels();
1770
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001771 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001772 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001773 }
1774
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001775 @Override
1776 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001777 long startTime = 0;
1778 if (DEBUG_RESUME_TIME) {
1779 startTime = System.currentTimeMillis();
1780 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001781 super.onNewIntent(intent);
1782
1783 // Close the menu
1784 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001785 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001786 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001787
Adam Cohened307df2013-10-02 09:37:31 -07001788 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1789 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1790 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001791
Adam Cohen6fecd412013-10-02 17:41:50 -07001792 if (mWorkspace == null) {
1793 // Can be cases where mWorkspace is null, this prevents a NPE
1794 return;
1795 }
1796 Folder openFolder = mWorkspace.getOpenFolder();
1797 // In all these cases, only animate if we're already on home
1798 mWorkspace.exitWidgetResizeMode();
1799 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001800 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001801 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001802 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001803
Adam Cohen6fecd412013-10-02 17:41:50 -07001804 closeFolder();
1805 exitSpringLoadedDragMode();
1806
1807 // If we are already on home, then just animate back to the workspace,
1808 // otherwise, just wait until onResume to set the state back to Workspace
1809 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001810 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001811 } else {
1812 mOnResumeState = State.WORKSPACE;
1813 }
1814
1815 final View v = getWindow().peekDecorView();
1816 if (v != null && v.getWindowToken() != null) {
1817 InputMethodManager imm = (InputMethodManager)getSystemService(
1818 INPUT_METHOD_SERVICE);
1819 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1820 }
1821
1822 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001823 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001824 mAppsCustomizeTabHost.reset();
1825 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001826
1827 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001828 }
Adam Cohened307df2013-10-02 09:37:31 -07001829
Michael Jurka447bf842013-05-15 14:52:15 +02001830 if (DEBUG_RESUME_TIME) {
1831 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1832 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001833 }
1834
Adam Coppa120b8e2013-11-12 16:26:04 +00001835 /**
1836 * Override point for subclasses to prevent movement to the default screen when the home
1837 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1838 */
1839 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1840 return true;
1841 }
1842
1843 /**
1844 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1845 */
1846 protected void onHomeIntent() {
1847 // Do nothing
1848 }
1849
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001850 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001851 public void onRestoreInstanceState(Bundle state) {
1852 super.onRestoreInstanceState(state);
1853 for (int page: mSynchronouslyBoundPages) {
1854 mWorkspace.restoreInstanceStateForChild(page);
1855 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001856 }
1857
1858 @Override
1859 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001860 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001861 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1862 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001863 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001864 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001865
Michael Jurka883f55b2010-10-21 15:47:14 -07001866 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001867 // We close any open folder since it will not be re-opened, and we need to make sure
1868 // this state is reflected.
1869 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001870
Adam Cohendcd297f2013-06-18 13:13:40 -07001871 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001872 mWaitingForResult) {
1873 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001874 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001875 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1876 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001877 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1878 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1879 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001880 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001881 }
1882
1883 if (mFolderInfo != null && mWaitingForResult) {
1884 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1885 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1886 }
Michael Jurka946ad472010-07-09 18:05:18 -07001887
Winson Chung785d2eb2011-04-14 16:08:02 -07001888 // Save the current AppsCustomize tab
1889 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001890 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1891 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001892 if (currentTabTag != null) {
1893 outState.putString("apps_customize_currentTab", currentTabTag);
1894 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001895 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1896 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001897 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001898 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899 }
1900
1901 @Override
1902 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001904
Winson Chunge7a03942011-08-05 15:05:12 -07001905 // Remove all pending runnables
1906 mHandler.removeMessages(ADVANCE_MSG);
1907 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001908 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001909
Winson Chungcd2b0142011-06-08 16:02:26 -07001910 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001911 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001912 mModel.stopLoader();
1913 app.setLauncher(null);
1914
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001916 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001917 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001918 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001919 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001920 mAppWidgetHost = null;
1921
1922 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923
1924 TextKeyListener.getInstance().release();
1925
Winson Chung81b52252012-08-27 15:34:29 -07001926 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1927 // to prevent leaking Launcher activities on orientation change.
1928 if (mModel != null) {
1929 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1930 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001931
1932 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001933 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001934
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001935 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001936 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001937 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001938 mWorkspace = null;
1939 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001940
Michael Jurka2ecf9952012-06-18 12:52:28 -07001941 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 }
1943
Adam Cohena9cf38f2011-05-02 15:36:58 -07001944 public DragController getDragController() {
1945 return mDragController;
1946 }
1947
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948 @Override
1949 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001950 if (requestCode >= 0) {
1951 setWaitingForResult(true);
1952 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953 super.startActivityForResult(intent, requestCode);
1954 }
1955
Winson Chung70d72102011-08-12 11:24:35 -07001956 /**
1957 * Indicates that we want global search for this activity by setting the globalSearch
1958 * argument for {@link #startSearch} to true.
1959 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001961 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001963
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001964 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001965
Karl Rosaen138a0412009-04-23 19:00:21 -07001966 if (initialQuery == null) {
1967 // Use any text typed in the launcher as the initial query
1968 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001969 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001970 if (appSearchData == null) {
1971 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001972 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001973 }
Winson Chungadf0c182012-08-23 14:59:07 -07001974 Rect sourceBounds = new Rect();
1975 if (mSearchDropTargetBar != null) {
1976 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1977 }
Romain Guycbb89e42009-06-08 15:52:54 -07001978
Bjorn Bringertc459e522013-06-07 19:36:01 +01001979 startSearch(initialQuery, selectInitialQuery,
1980 appSearchData, sourceBounds);
1981 }
1982
1983 public void startSearch(String initialQuery,
1984 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001985 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001986 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001987 }
1988
1989 /**
1990 * Starts the global search activity. This code is a copied from SearchManager
1991 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001992 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001993 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001994 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001995 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1996 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1997 if (globalSearchActivity == null) {
1998 Log.w(TAG, "No global search activity found.");
1999 return;
2000 }
2001 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2002 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2003 intent.setComponent(globalSearchActivity);
2004 // Make sure that we have a Bundle to put source in
2005 if (appSearchData == null) {
2006 appSearchData = new Bundle();
2007 } else {
2008 appSearchData = new Bundle(appSearchData);
2009 }
2010 // Set source to package name of app that starts global search, if not set already.
2011 if (!appSearchData.containsKey("source")) {
2012 appSearchData.putString("source", getPackageName());
2013 }
2014 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2015 if (!TextUtils.isEmpty(initialQuery)) {
2016 intent.putExtra(SearchManager.QUERY, initialQuery);
2017 }
2018 if (selectInitialQuery) {
2019 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2020 }
2021 intent.setSourceBounds(sourceBounds);
2022 try {
2023 startActivity(intent);
2024 } catch (ActivityNotFoundException ex) {
2025 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2026 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 }
2028
Yura4f93ec62014-02-04 14:15:21 +00002029 public boolean isOnCustomContent() {
2030 return mWorkspace.isOnOrMovingToCustomContent();
2031 }
2032
Winson Chung70d72102011-08-12 11:24:35 -07002033 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002034 public boolean onPrepareOptionsMenu(Menu menu) {
2035 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002036 if (!isOnCustomContent()) {
2037 // Close any open folders
2038 closeFolder();
2039 // Stop resizing any widgets
2040 mWorkspace.exitWidgetResizeMode();
2041 if (!mWorkspace.isInOverviewMode()) {
2042 // Show the overview mode
2043 showOverviewMode(true);
2044 } else {
2045 showWorkspace(true);
2046 }
Winson Chunge0298742014-01-17 12:03:00 -08002047 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002048 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002049 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002051 @Override
2052 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002053 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002054 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002055 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002056 }
2057
Joe Onorato9c1289c2009-08-17 11:03:03 -04002058 public boolean isWorkspaceLocked() {
2059 return mWorkspaceLoading || mWaitingForResult;
2060 }
2061
Adam Cohen517a7f52014-03-01 12:12:59 -08002062 public boolean isWorkspaceLoading() {
2063 return mWorkspaceLoading;
2064 }
2065
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002066 private void setWorkspaceLoading(boolean value) {
2067 boolean isLocked = isWorkspaceLocked();
2068 mWorkspaceLoading = value;
2069 if (isLocked != isWorkspaceLocked()) {
2070 onWorkspaceLockedChanged();
2071 }
2072 }
2073
2074 private void setWaitingForResult(boolean value) {
2075 boolean isLocked = isWorkspaceLocked();
2076 mWaitingForResult = value;
2077 if (isLocked != isWorkspaceLocked()) {
2078 onWorkspaceLockedChanged();
2079 }
2080 }
2081
2082 protected void onWorkspaceLockedChanged() { }
2083
Michael Jurka0280c3b2010-09-17 15:00:07 -07002084 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002085 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002086 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002087 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2088 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002089 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002090 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002091 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002092
Adam Cohenad4e15c2013-10-17 16:21:35 -07002093 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2094 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2095 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2096 }
2097
2098 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2099 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2100 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002101 if (appWidgetInfo.configure != null) {
2102 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002103 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002104
Bjorn Bringert7984c942009-12-09 15:38:25 +00002105 // Launch over to configure widget, if needed
2106 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002107 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002108 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002109 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002110 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002111 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002112 Runnable onComplete = new Runnable() {
2113 @Override
2114 public void run() {
2115 // Exit spring loaded mode if necessary after adding the widget
2116 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2117 null);
2118 }
2119 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002120 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002121 appWidgetInfo);
Adam Cohenad4e15c2013-10-17 16:21:35 -07002122 mWorkspace.removeExtraEmptyScreen(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123 }
2124 }
Romain Guycbb89e42009-06-08 15:52:54 -07002125
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002126 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002127 // Close any folders that may be open.
2128 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002129 mWorkspace.moveToCustomContentScreen(animate);
2130 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002131 /**
2132 * Process a shortcut drop.
2133 *
2134 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002135 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002136 * @param cell The cell it should be added to, optional
2137 * @param position The location on the screen where it was dropped, optional
2138 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002139 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002140 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002141 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002142 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002143 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002144 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002145
2146 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002147 mPendingAddInfo.cellX = cell[0];
2148 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002149 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002150
2151 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2152 createShortcutIntent.setComponent(componentName);
2153 processShortcut(createShortcutIntent);
2154 }
2155
Adam Cohenfbba09b2011-07-18 21:43:05 -07002156 /**
2157 * Process a widget drop.
2158 *
2159 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002160 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002161 * @param cell The cell it should be added to, optional
2162 * @param position The location on the screen where it was dropped, optional
2163 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002164 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002165 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002166 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002167 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002168 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002169 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002170 mPendingAddInfo.minSpanX = info.minSpanX;
2171 mPendingAddInfo.minSpanY = info.minSpanY;
2172
Adam Cohenfbba09b2011-07-18 21:43:05 -07002173 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002174 mPendingAddInfo.cellX = cell[0];
2175 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002176 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002177 if (span != null) {
2178 mPendingAddInfo.spanX = span[0];
2179 mPendingAddInfo.spanY = span[1];
2180 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002181
Adam Cohened66b2b2012-01-23 17:28:51 -08002182 AppWidgetHostView hostView = info.boundWidget;
2183 int appWidgetId;
2184 if (hostView != null) {
2185 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002186 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002187 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002188 // In this case, we either need to start an activity to get permission to bind
2189 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002190 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002191 Bundle options = info.bindOptions;
2192
2193 boolean success = false;
2194 if (options != null) {
2195 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2196 info.componentName, options);
2197 } else {
2198 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2199 info.componentName);
2200 }
2201 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002202 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002203 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002204 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002205 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2206 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2207 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002208 // TODO: we need to make sure that this accounts for the options bundle.
2209 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002210 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2211 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002212 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002213 }
2214
Joe Onoratodeb98af2010-02-19 14:59:39 -08002215 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002216 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002217 }
2218
Winson Chung24ab2f12010-09-16 14:10:47 -07002219 void processWallpaper(Intent intent) {
2220 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2221 }
2222
Adam Cohendcd297f2013-06-18 13:13:40 -07002223 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002224 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002225 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002226 folderInfo.title = getText(R.string.folder_name);
2227
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002228 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002229 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002230 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002231 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002232
2233 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002234 FolderIcon newFolder =
2235 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002236 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002237 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002238 // Force measure the new folder icon
2239 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2240 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002241 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002242 }
Romain Guycbb89e42009-06-08 15:52:54 -07002243
Joe Onorato9c1289c2009-08-17 11:03:03 -04002244 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002245 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002246 }
2247
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002248 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002249 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002250 }
2251
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002252 /**
2253 * Registers various content observers. The current implementation registers
2254 * only a favorites observer to keep track of the favorites applications.
2255 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002256 private void registerContentObservers() {
2257 ContentResolver resolver = getContentResolver();
2258 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2259 true, mWidgetObserver);
2260 }
2261
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002262 @Override
2263 public boolean dispatchKeyEvent(KeyEvent event) {
2264 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2265 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002266 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002267 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002268 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002269 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002270 dumpState();
2271 return true;
2272 }
2273 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002274 }
2275 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2276 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002277 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002278 return true;
2279 }
2280 }
2281
2282 return super.dispatchKeyEvent(event);
2283 }
2284
Joe Onorato88ec0992009-11-19 13:16:06 -08002285 @Override
2286 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002287 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002288 if (mAppsCustomizeContent.getContentType() ==
2289 AppsCustomizePagedView.ContentType.Applications) {
2290 showWorkspace(true);
2291 } else {
2292 showOverviewMode(true);
2293 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002294 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002295 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002296 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002297 Folder openFolder = mWorkspace.getOpenFolder();
2298 if (openFolder.isEditingName()) {
2299 openFolder.dismissEditingName();
2300 } else {
2301 closeFolder();
2302 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002303 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002304 mWorkspace.exitWidgetResizeMode();
2305
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002306 // Back button is a no-op here, but give at least some feedback for the button press
2307 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002308 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002309 }
2310
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002311 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002312 * Re-listen when widgets are reset.
2313 */
2314 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002315 if (mAppWidgetHost != null) {
2316 mAppWidgetHost.startListening();
2317 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002318 }
2319
2320 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002321 * Launches the intent referred by the clicked shortcut.
2322 *
2323 * @param v The view representing the clicked shortcut.
2324 */
2325 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002326 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2327 // view has detached (it's possible for this to happen if the view is removed mid touch).
2328 if (v.getWindowToken() == null) {
2329 return;
2330 }
2331
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002332 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002333 return;
2334 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002335
Adam Cohen1697b792013-09-17 19:08:21 -07002336 if (v instanceof Workspace) {
2337 if (mWorkspace.isInOverviewMode()) {
2338 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002339 }
2340 return;
2341 }
2342
2343 if (v instanceof CellLayout) {
2344 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002345 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002346 }
2347 }
2348
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002349 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002350 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002351 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002352 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002353 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002354 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002355 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002356 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002357 onClickAllAppsButton(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002358 }
2359 }
2360
Michael Jurka0e260592010-06-30 17:07:39 -07002361 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002362 return false;
2363 }
2364
Michael Jurkaaf442092010-06-10 17:01:57 -07002365 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002366 * Event handler for the search button
2367 *
2368 * @param v The view that was clicked.
2369 */
2370 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002371 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2372
Amith Yamasania135ba82011-08-09 17:42:01 -07002373 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002374 }
2375
2376 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002377 * Event handler for the voice button
2378 *
2379 * @param v The view that was clicked.
2380 */
2381 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002382 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002383
Bjorn Bringertc459e522013-06-07 19:36:01 +01002384 startVoice();
2385 }
2386
2387 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002388 try {
2389 final SearchManager searchManager =
2390 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2391 ComponentName activityName = searchManager.getGlobalSearchActivity();
2392 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002393 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002394 if (activityName != null) {
2395 intent.setPackage(activityName.getPackageName());
2396 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002397 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002398 } catch (ActivityNotFoundException e) {
2399 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002400 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002401 startActivitySafely(null, intent, "onClickVoiceButton");
2402 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002403 }
2404
2405 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002406 * Event handler for the "grid" button that appears on the home screen, which
2407 * enters all apps mode.
2408 *
2409 * @param v The view that was clicked.
2410 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002411 protected void onClickAllAppsButton(View v) {
2412 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2413 if (isAllAppsVisible()) {
2414 showWorkspace(true);
2415 } else {
2416 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2417 }
2418 }
2419
2420 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002421 * Event handler for a paged view icon click.
2422 * @param v The view that was clicked.
2423 * @param appInfo The {link AppInfo} of the view.
2424 */
2425 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2426 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2427 startActivitySafely(v, appInfo.intent, appInfo);
2428 getStats().recordLaunch(appInfo.intent);
2429 }
2430
2431 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002432 * Event handler for an app shortcut click.
2433 *
2434 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2435 */
2436 protected void onClickAppShortcut(View v) {
2437 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2438 Object tag = v.getTag();
2439 if (!(tag instanceof ShortcutInfo)) {
2440 throw new IllegalArgumentException("Input must be a Shortcut");
2441 }
2442
2443 // Open shortcut
2444 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2445 final Intent intent = shortcut.intent;
2446
2447 // Check for special shortcuts
2448 if (intent.getComponent() != null) {
2449 final String shortcutClass = intent.getComponent().getClassName();
2450
2451 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2452 MemoryDumpActivity.startDump(this);
2453 return;
2454 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2455 toggleShowWeightWatcher();
2456 return;
2457 }
2458 }
2459
2460 // Start activities
2461 int[] pos = new int[2];
2462 v.getLocationOnScreen(pos);
2463 intent.setSourceBounds(new Rect(pos[0], pos[1],
2464 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2465
2466 boolean success = startActivitySafely(v, intent, tag);
2467
2468 mStats.recordLaunch(intent, shortcut);
2469
2470 if (success && v instanceof BubbleTextView) {
2471 mWaitingForResume = (BubbleTextView) v;
2472 mWaitingForResume.setStayPressed(true);
2473 }
2474 }
2475
2476 /**
2477 * Event handler for a folder icon click.
2478 *
2479 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2480 */
2481 protected void onClickFolderIcon(View v) {
2482 if (LOGD) Log.d(TAG, "onClickFolder");
2483 if (!(v instanceof FolderIcon)){
2484 throw new IllegalArgumentException("Input must be a FolderIcon");
2485 }
2486
2487 FolderIcon folderIcon = (FolderIcon) v;
2488 final FolderInfo info = folderIcon.getFolderInfo();
2489 Folder openFolder = mWorkspace.getFolderForTag(info);
2490
2491 // If the folder info reports that the associated folder is open, then verify that
2492 // it is actually opened. There have been a few instances where this gets out of sync.
2493 if (info.opened && openFolder == null) {
2494 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2495 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2496 info.opened = false;
2497 }
2498
2499 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2500 // Close any open folder
2501 closeFolder();
2502 // Open the requested folder
2503 openFolder(folderIcon);
2504 } else {
2505 // Find the open folder...
2506 int folderScreen;
2507 if (openFolder != null) {
2508 folderScreen = mWorkspace.getPageForView(openFolder);
2509 // .. and close it
2510 closeFolder(openFolder);
2511 if (folderScreen != mWorkspace.getCurrentPage()) {
2512 // Close any folder open on the current screen
2513 closeFolder();
2514 // Pull the folder onto this screen
2515 openFolder(folderIcon);
2516 }
2517 }
2518 }
Michael Jurka5130e402011-10-13 04:55:35 -07002519 }
2520
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002521 /**
2522 * Event handler for the (Add) Widgets button that appears after a long press
2523 * on the home screen.
2524 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002525 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002526 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002527 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2528 }
2529
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002530 /**
2531 * Event handler for the wallpaper picker button that appears after a long press
2532 * on the home screen.
2533 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002534 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002535 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2536 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2537 pickWallpaper.setComponent(getWallpaperPickerComponent());
2538 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2539 }
2540
2541 /**
2542 * Event handler for a click on the settings button that appears after a long press
2543 * on the home screen.
2544 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002545 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002546 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2547 }
2548
Michael Jurka5130e402011-10-13 04:55:35 -07002549 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002550 // Provide the same haptic feedback that the system offers for virtual keys.
2551 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002552 }
2553
Adam Cohen61f560d2013-09-30 15:58:20 -07002554 public void performHapticFeedbackOnTouchDown(View v) {
2555 // Provide the same haptic feedback that the system offers for virtual keys.
2556 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2557 }
2558
2559 public View.OnTouchListener getHapticFeedbackTouchListener() {
2560 if (mHapticFeedbackTouchListener == null) {
2561 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2562 @Override
2563 public boolean onTouch(View v, MotionEvent event) {
2564 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2565 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2566 }
2567 return false;
2568 }
2569 };
2570 }
2571 return mHapticFeedbackTouchListener;
2572 }
2573
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002574 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002575 if (!DISABLE_MARKET_BUTTON) {
2576 if (mAppMarketIntent != null) {
2577 startActivitySafely(v, mAppMarketIntent, "app market");
2578 } else {
2579 Log.e(TAG, "Invalid app market intent.");
2580 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002581 }
2582 }
2583
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002584 public void onDragStarted(View view) {}
2585
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002586 /**
2587 * Called when the user stops interacting with the launcher.
2588 * This implies that the user is now on the homescreen and is not doing housekeeping.
2589 */
2590 protected void onInteractionEnd() {}
2591
2592 /**
2593 * Called when the user starts interacting with the launcher.
2594 * The possible interactions are:
2595 * - open all apps
2596 * - reorder an app shortcut, or a widget
2597 * - open the overview mode.
2598 * This is a good time to stop doing things that only make sense
2599 * when the user is on the homescreen and not doing housekeeping.
2600 */
2601 protected void onInteractionBegin() {}
2602
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002603 void startApplicationDetailsActivity(ComponentName componentName) {
2604 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002605 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2606 Uri.fromParts("package", packageName, null));
Adrian Roos850f9132014-01-13 17:44:52 -08002607 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |
2608 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002609 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002610 }
2611
Michael Jurka1e2f4652013-07-08 18:03:46 -07002612 // returns true if the activity was started
2613 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002614 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002615 // System applications cannot be installed. For now, show a toast explaining that.
2616 // We may give them the option of disabling apps this way.
2617 int messageId = R.string.uninstall_system_app_text;
2618 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002619 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002620 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002621 String packageName = componentName.getPackageName();
2622 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002623 Intent intent = new Intent(
2624 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002625 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2626 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002627 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002628 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002629 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002630 }
2631
Michael Jurka86a720e2012-05-09 11:23:23 -07002632 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyed131872014-04-30 03:02:21 +01002633 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002634 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002635 // Only launch using the new animation if the shortcut has not opted out (this is a
2636 // private contract between launcher and may be ignored in the future).
2637 boolean useLaunchAnimation = (v != null) &&
2638 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002639 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2640 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002641
Kenny Guy1317e2d2014-05-08 18:52:50 +01002642 UserHandleCompat user = null;
2643 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2644 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2645 user = userManager.getUserForSerialNumber(serialNumber);
2646 }
2647
2648 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002649 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002650 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2651 v.getMeasuredWidth(), v.getMeasuredHeight());
Kenny Guy1317e2d2014-05-08 18:52:50 +01002652 optsBundle = opts.toBundle();
2653 }
2654
2655 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2656 // Could be launching some bookkeeping activity
2657 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002658 } else {
Kenny Guy1317e2d2014-05-08 18:52:50 +01002659 launcherApps.startActivityForProfile(intent.getComponent(),
2660 intent.getSourceBounds(), optsBundle, user);
Winson Chungc7450e32012-04-17 17:34:08 -07002661 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002662 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002663 } catch (SecurityException e) {
2664 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002665 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002666 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002667 "or use the exported attribute for this activity. "
2668 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002669 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002670 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002671 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002672
Michael Jurka86a720e2012-05-09 11:23:23 -07002673 boolean startActivitySafely(View v, Intent intent, Object tag) {
2674 boolean success = false;
2675 try {
2676 success = startActivity(v, intent, tag);
2677 } catch (ActivityNotFoundException e) {
2678 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2679 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2680 }
2681 return success;
2682 }
2683
Adam Cohen268c4752012-06-06 17:47:33 -07002684 /**
2685 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2686 * in the DragLayer in the exact absolute location of the original FolderIcon.
2687 */
2688 private void copyFolderIconToImage(FolderIcon fi) {
2689 final int width = fi.getMeasuredWidth();
2690 final int height = fi.getMeasuredHeight();
2691
2692 // Lazy load ImageView, Bitmap and Canvas
2693 if (mFolderIconImageView == null) {
2694 mFolderIconImageView = new ImageView(this);
2695 }
2696 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2697 mFolderIconBitmap.getHeight() != height) {
2698 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2699 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2700 }
2701
2702 DragLayer.LayoutParams lp;
2703 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2704 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2705 } else {
2706 lp = new DragLayer.LayoutParams(width, height);
2707 }
2708
Adam Cohen307fe232012-08-16 17:55:58 -07002709 // The layout from which the folder is being opened may be scaled, adjust the starting
2710 // view size by this scale factor.
2711 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002712 lp.customPosition = true;
2713 lp.x = mRectForFolderAnimation.left;
2714 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002715 lp.width = (int) (scale * width);
2716 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002717
2718 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2719 fi.draw(mFolderIconCanvas);
2720 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002721 if (fi.getFolder() != null) {
2722 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2723 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002724 }
Adam Cohen268c4752012-06-06 17:47:33 -07002725 // Just in case this image view is still in the drag layer from a previous animation,
2726 // we remove it and re-add it.
2727 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2728 mDragLayer.removeView(mFolderIconImageView);
2729 }
2730 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002731 if (fi.getFolder() != null) {
2732 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002733 }
Adam Cohen268c4752012-06-06 17:47:33 -07002734 }
2735
Adam Cohen2801caf2011-05-13 20:57:39 -07002736 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002737 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002738 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2739 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2740 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2741
Adam Cohenc51934b2011-07-26 21:07:43 -07002742 FolderInfo info = (FolderInfo) fi.getTag();
2743 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2744 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002745 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2746 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002747 }
2748
Adam Cohen268c4752012-06-06 17:47:33 -07002749 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2750 copyFolderIconToImage(fi);
2751 fi.setVisibility(View.INVISIBLE);
2752
Michael Jurka2ecf9952012-06-18 12:52:28 -07002753 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002754 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002755 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2756 oa.start();
2757 }
2758
Adam Cohen268c4752012-06-06 17:47:33 -07002759 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002760 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002761 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2762 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2763 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2764
Adam Cohen268c4752012-06-06 17:47:33 -07002765 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002766
Adam Cohen268c4752012-06-06 17:47:33 -07002767 // We remove and re-draw the FolderIcon in-case it has changed
2768 mDragLayer.removeView(mFolderIconImageView);
2769 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002770 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002771 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002772 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002773 oa.addListener(new AnimatorListenerAdapter() {
2774 @Override
2775 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002776 if (cl != null) {
2777 cl.clearFolderLeaveBehind();
2778 // Remove the ImageView copy of the FolderIcon and make the original visible.
2779 mDragLayer.removeView(mFolderIconImageView);
2780 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002781 }
2782 }
2783 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002784 oa.start();
2785 }
2786
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002787 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002788 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002789 * is animated relative to the specified View. If the View is null, no animation
2790 * is played.
2791 *
2792 * @param folderInfo The FolderInfo describing the folder to open.
2793 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002794 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002795 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002796 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002797
Adam Cohena9cf38f2011-05-02 15:36:58 -07002798 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002799
Adam Cohen4554ee12011-08-03 16:13:21 -07002800 // Just verify that the folder hasn't already been added to the DragLayer.
2801 // There was a one-off crash where the folder had a parent already.
2802 if (folder.getParent() == null) {
2803 mDragLayer.addView(folder);
2804 mDragController.addDropTarget((DropTarget) folder);
2805 } else {
2806 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2807 folder.getParent() + ").");
2808 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002809 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002810 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002811
2812 // Notify the accessibility manager that this folder "window" has appeared and occluded
2813 // the workspace items
2814 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2815 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002816 }
2817
2818 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002819 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002820 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002821 if (folder.isEditingName()) {
2822 folder.dismissEditingName();
2823 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002824 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002825
2826 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002827 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002828 }
2829 }
2830
2831 void closeFolder(Folder folder) {
2832 folder.getInfo().opened = false;
2833
2834 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2835 if (parent != null) {
2836 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2837 shrinkAndFadeInFolderIcon(fi);
2838 }
2839 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002840
2841 // Notify the accessibility manager that this folder "window" has disappeard and no
2842 // longer occludeds the workspace items
2843 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002844 }
2845
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002846 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002847 if (!isDraggingEnabled()) return false;
2848 if (isWorkspaceLocked()) return false;
2849 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002850
Adam Cohen1697b792013-09-17 19:08:21 -07002851 if (v instanceof Workspace) {
2852 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002853 if (mWorkspace.enterOverviewMode()) {
2854 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2855 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2856 return true;
2857 } else {
2858 return false;
2859 }
Adam Cohen1697b792013-09-17 19:08:21 -07002860 }
Adam Cohen1697b792013-09-17 19:08:21 -07002861 }
2862
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002863 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002864 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002865 }
2866
Michael Jurka0280c3b2010-09-17 15:00:07 -07002867 resetAddInfo();
2868 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002869 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002870 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002871 return true;
2872 }
2873
Winson Chung3d503fb2011-07-13 17:25:49 -07002874 // The hotseat touch handling does not go through Workspace, and we always allow long press
2875 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002876 final View itemUnderLongClick = longClickCellInfo.cell;
Dan Sandlere26d0942014-01-13 14:30:14 -05002877 final boolean inHotseat = isHotseatLayout(v);
2878 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07002879 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002880 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002881 // User long pressed on empty space
2882 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2883 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2884 // Disabling reordering until we sort out some issues.
2885 if (mWorkspace.isInOverviewMode()) {
2886 mWorkspace.startReordering(v);
2887 } else {
2888 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002889 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002890 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05002891 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
2892 mHotseat.getOrderInHotseat(
2893 longClickCellInfo.cellX,
2894 longClickCellInfo.cellY));
2895 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002896 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002897 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002898 }
2899 }
2900 }
2901 return true;
2902 }
2903
Winson Chung3d503fb2011-07-13 17:25:49 -07002904 boolean isHotseatLayout(View layout) {
2905 return mHotseat != null && layout != null &&
2906 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2907 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002908
Winson Chung3d503fb2011-07-13 17:25:49 -07002909 /**
2910 * Returns the CellLayout of the specified container at the specified screen.
2911 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002912 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002913 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2914 if (mHotseat != null) {
2915 return mHotseat.getLayout();
2916 } else {
2917 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002918 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002919 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002920 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002921 }
2922 }
2923
Daniel Sandler843e8602010-06-07 14:59:01 -04002924 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002925 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002926 }
2927
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002928 /**
2929 * Helper method for the cameraZoomIn/cameraZoomOut animations
2930 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002931 * @param scaleFactor The scale factor used for the zoom
2932 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002933 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002934 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002935 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002936 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002937
Craig Mautner360310b2012-10-26 15:13:08 -07002938 private void setWorkspaceBackground(boolean workspace) {
2939 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002940 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002941 }
2942
Selim Cinek3a8a8f72014-01-16 10:38:38 -08002943 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002944 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2945 int curflags = getWindow().getAttributes().flags
2946 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2947 if (wpflags != curflags) {
2948 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2949 }
Craig Mautner360310b2012-10-26 15:13:08 -07002950 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002951 }
2952
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002953 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2954 if (v instanceof LauncherTransitionable) {
2955 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2956 }
2957 }
2958
Michael Jurkabed61d22012-02-14 22:51:29 -08002959 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2960 if (v instanceof LauncherTransitionable) {
2961 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2962 }
Winson Chung70442722012-02-10 15:43:22 -08002963
2964 // Update the workspace transition step as well
2965 dispatchOnLauncherTransitionStep(v, 0f);
2966 }
2967
2968 private void dispatchOnLauncherTransitionStep(View v, float t) {
2969 if (v instanceof LauncherTransitionable) {
2970 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2971 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002972 }
2973
2974 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2975 if (v instanceof LauncherTransitionable) {
2976 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2977 }
Winson Chung70442722012-02-10 15:43:22 -08002978
2979 // Update the workspace transition step as well
2980 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002981 }
2982
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002983 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002984 * Things to test when changing the following seven functions.
2985 * - Home from workspace
2986 * - from center screen
2987 * - from other screens
2988 * - Home from all apps
2989 * - from center screen
2990 * - from other screens
2991 * - Back from all apps
2992 * - from center screen
2993 * - from other screens
2994 * - Launch app from workspace and quit
2995 * - with back
2996 * - with home
2997 * - Launch app from all apps and quit
2998 * - with back
2999 * - with home
3000 * - Go to a screen that's not the default, then all
3001 * apps, and launch and app, and go back
3002 * - with back
3003 * -with home
3004 * - On workspace, long press power and go back
3005 * - with back
3006 * - with home
3007 * - On all apps, long press power and go back
3008 * - with back
3009 * - with home
3010 * - On workspace, power off
3011 * - On all apps, power off
3012 * - Launch an app and turn off the screen while in that app
3013 * - Go back with home key
3014 * - Go back with back key TODO: make this not go to workspace
3015 * - From all apps
3016 * - From workspace
3017 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3018 * - From all apps
3019 * - From the center workspace
3020 * - From another workspace
3021 */
3022
3023 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003024 * Zoom the camera out from the workspace to reveal 'toView'.
3025 * Assumes that the view to show is anchored at either the very top or very bottom
3026 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003027 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003028 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003029 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3030 showAppsCustomizeHelper(animated, springLoaded, contentType);
3031 }
3032 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3033 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003034 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003035 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003036 mStateAnimation.cancel();
3037 mStateAnimation = null;
3038 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003039 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003040
Winson Chungf0ea4d32011-06-06 14:27:16 -07003041 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3042 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3043 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003044 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003045 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003046 final int startDelay =
3047 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003048
Michael Jurkab3e22d92011-10-31 15:58:33 -07003049 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003050
Michael Jurkad74c9842011-07-10 12:44:21 -07003051 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003052 Animator workspaceAnim =
3053 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003054 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003055 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3056 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003057 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3058 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003059
3060 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003061 toView.setScaleX(scale);
3062 toView.setScaleY(scale);
3063 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
3064 scaleAnim.
3065 scaleX(1f).scaleY(1f).
3066 setDuration(duration).
3067 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08003068
Winson Chungf0ea4d32011-06-06 14:27:16 -07003069 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08003070 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003071 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003072 .ofFloat(toView, "alpha", 0f, 1f)
3073 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003074 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08003075 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3076 @Override
3077 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07003078 if (animation == null) {
3079 throw new RuntimeException("animation is null");
3080 }
Winson Chung70442722012-02-10 15:43:22 -08003081 float t = (Float) animation.getAnimatedValue();
3082 dispatchOnLauncherTransitionStep(fromView, t);
3083 dispatchOnLauncherTransitionStep(toView, t);
3084 }
3085 });
Adam Cohenf16e5712011-01-13 13:31:45 -08003086
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003087 // toView should appear right at the end of the workspace shrink
3088 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07003089 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003090 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08003091 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003092
3093 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003094 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07003095 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003096 // Prepare the position
3097 toView.setTranslationX(0.0f);
3098 toView.setTranslationY(0.0f);
3099 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003100 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003101 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07003102 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003103 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003104 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3105 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07003106
Winson Chungc7d2b602012-05-16 17:02:20 -07003107 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003108 if (mSearchDropTargetBar != null) {
3109 mSearchDropTargetBar.hideSearchBar(false);
3110 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07003111 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003112 });
3113
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003114 if (workspaceAnim != null) {
3115 mStateAnimation.play(workspaceAnim);
3116 }
Michael Jurka1899a362011-11-03 13:50:45 -07003117
3118 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003119
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003120 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3121 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003122
3123 // If any of the objects being animated haven't been measured/laid out
3124 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003125 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003126 (mWorkspace.getMeasuredWidth() == 0) ||
3127 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003128 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003129 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003130
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003131 final AnimatorSet stateAnimation = mStateAnimation;
3132 final Runnable startAnimRunnable = new Runnable() {
3133 public void run() {
3134 // Check that mStateAnimation hasn't changed while
3135 // we waited for a layout/draw pass
3136 if (mStateAnimation != stateAnimation)
3137 return;
3138 setPivotsForZoom(toView, scale);
3139 dispatchOnLauncherTransitionStart(fromView, animated, false);
3140 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003141 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003142 }
3143 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003144 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003145 final ViewTreeObserver observer = toView.getViewTreeObserver();
3146 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3147 public void onGlobalLayout() {
3148 startAnimRunnable.run();
3149 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3150 }
3151 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003152 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003153 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003154 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003155 } else {
3156 toView.setTranslationX(0.0f);
3157 toView.setTranslationY(0.0f);
3158 toView.setScaleX(1.0f);
3159 toView.setScaleY(1.0f);
3160 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003161 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003162
Daniel Sandlere4f98912013-06-25 15:13:26 -04003163 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003164 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003165 if (mSearchDropTargetBar != null) {
3166 mSearchDropTargetBar.hideSearchBar(false);
3167 }
Michael Jurkaabded662011-03-04 12:06:57 -08003168 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003169 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003170 dispatchOnLauncherTransitionStart(fromView, animated, false);
3171 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003172 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003173 dispatchOnLauncherTransitionStart(toView, animated, false);
3174 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003175 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003176 }
3177
3178 /**
3179 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003180 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003181 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003182 */
Adam Cohened307df2013-10-02 09:37:31 -07003183 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003184 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003185
Michael Jurkab3e22d92011-10-31 15:58:33 -07003186 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003187 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003188 mStateAnimation.cancel();
3189 mStateAnimation = null;
3190 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003191 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003192
Winson Chungf0ea4d32011-06-06 14:27:16 -07003193 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003194 final int fadeOutDuration =
3195 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003196 final float scaleFactor = (float)
3197 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3198 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003199 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003200 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003201 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003202 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3203 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003204 toState, animated, stagger, -1);
3205 } else if (toState == Workspace.State.SPRING_LOADED ||
3206 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003207 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003208 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003209 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003210
Michael Jurkab3e22d92011-10-31 15:58:33 -07003211 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003212 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003213 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003214 final LauncherViewPropertyAnimator scaleAnim =
3215 new LauncherViewPropertyAnimator(fromView);
3216 scaleAnim.
3217 scaleX(scaleFactor).scaleY(scaleFactor).
3218 setDuration(duration).
3219 setInterpolator(new Workspace.ZoomInInterpolator());
3220
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003221 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003222 .ofFloat(fromView, "alpha", 1f, 0f)
3223 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003224 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003225 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3226 @Override
3227 public void onAnimationUpdate(ValueAnimator animation) {
3228 float t = 1f - (Float) animation.getAnimatedValue();
3229 dispatchOnLauncherTransitionStep(fromView, t);
3230 dispatchOnLauncherTransitionStep(toView, t);
3231 }
3232 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003233
Michael Jurka2ecf9952012-06-18 12:52:28 -07003234 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003235
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003236 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3237 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003238 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003239
3240 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003241 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003242 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003243 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003244 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3245 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003246 if (onCompleteRunnable != null) {
3247 onCompleteRunnable.run();
3248 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003249 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003250 }
3251 });
3252
Winson Chungf0ea4d32011-06-06 14:27:16 -07003253 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003254 if (workspaceAnim != null) {
3255 mStateAnimation.play(workspaceAnim);
3256 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003257 dispatchOnLauncherTransitionStart(fromView, animated, true);
3258 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003259 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003260 } else {
3261 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003262 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003263 dispatchOnLauncherTransitionStart(fromView, animated, true);
3264 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003265 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003266 dispatchOnLauncherTransitionStart(toView, animated, true);
3267 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003268 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003269 }
3270
Michael Jurkae326f182011-11-21 14:05:46 -08003271 @Override
3272 public void onTrimMemory(int level) {
3273 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003274 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003275 mAppsCustomizeTabHost.onTrimMemory();
3276 }
3277 }
3278
Adam Cohened307df2013-10-02 09:37:31 -07003279 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003280 showWorkspace(animated, null);
3281 }
3282
Adam Cohened307df2013-10-02 09:37:31 -07003283 protected void showWorkspace() {
3284 showWorkspace(true);
3285 }
3286
Adam Cohened66b2b2012-01-23 17:28:51 -08003287 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003288 if (mWorkspace.isInOverviewMode()) {
3289 mWorkspace.exitOverviewMode(animated);
3290 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003291 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003292 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003293 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003294 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003295
Winson Chungc7d2b602012-05-16 17:02:20 -07003296 // Show the search bar (only animate if we were showing the drop target bar in spring
3297 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003298 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003299 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003300 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003301
Michael Jurkab3e22d92011-10-31 15:58:33 -07003302 // Set focus to the AppsCustomize button
3303 if (mAllAppsButton != null) {
3304 mAllAppsButton.requestFocus();
3305 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003306 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003307
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003308 // Change the state *after* we've called all the transition code
3309 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003310
Winson Chung5fb63472011-02-02 17:03:37 -08003311 // Resume the auto-advance of widgets
3312 mUserPresent = true;
3313 updateRunning();
3314
alanv1d4fde62012-10-17 13:15:47 -07003315 // Send an accessibility event to announce the context change
3316 getWindow().getDecorView()
3317 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003318
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003319 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003320 }
3321
Adam Cohened307df2013-10-02 09:37:31 -07003322 void showOverviewMode(boolean animated) {
3323 mWorkspace.setVisibility(View.VISIBLE);
3324 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3325 mState = State.WORKSPACE;
3326 onWorkspaceShown(animated);
3327 }
3328
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003329 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003330 }
3331
Winson Chung82963d52013-10-09 11:20:57 -07003332 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3333 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003334 if (mState != State.WORKSPACE) return;
3335
Winson Chung82963d52013-10-09 11:20:57 -07003336 if (resetPageToZero) {
3337 mAppsCustomizeTabHost.reset();
3338 }
Winson Chungc58497e2013-09-03 17:48:37 -07003339 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003340 mAppsCustomizeTabHost.requestFocus();
3341
Michael Jurkab3e22d92011-10-31 15:58:33 -07003342 // Change the state *after* we've called all the transition code
3343 mState = State.APPS_CUSTOMIZE;
3344
3345 // Pause the auto-advance of widgets until we are out of AllApps
3346 mUserPresent = false;
3347 updateRunning();
3348 closeFolder();
3349
3350 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003351 getWindow().getDecorView()
3352 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003353 }
3354
Adam Cohen7777d962011-08-18 18:58:38 -07003355 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003356 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003357 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003358 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003359 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003360 }
Adam Cohen7777d962011-08-18 18:58:38 -07003361
Adam Cohenad4e15c2013-10-17 16:21:35 -07003362 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003363 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003364 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3365
Winson Chunge7a03942011-08-05 15:05:12 -07003366 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003367 @Override
3368 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003369 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003370 // Before we show workspace, hide all apps again because
3371 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3372 // clean up our state transition functions
3373 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003374 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003375 } else {
3376 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003377 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003378 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003379 }, delay);
3380
Winson Chung557d6ed2011-07-08 15:34:52 -07003381 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003382
Michael Jurkad3ef3062010-11-23 16:23:58 -08003383 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003384 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003385 final boolean animated = true;
3386 final boolean springLoaded = true;
3387 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003388 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003389 }
3390 // Otherwise, we are not in spring loaded mode, so don't do anything.
3391 }
3392
Michael Jurkab3e22d92011-10-31 15:58:33 -07003393 void lockAllApps() {
3394 // TODO
3395 }
3396
3397 void unlockAllApps() {
3398 // TODO
3399 }
3400
Winson Chungf0ea4d32011-06-06 14:27:16 -07003401 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003402 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003403 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003404 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003405 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003406 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003407 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003408 int duration = 0;
3409 if (mSearchDropTargetBar != null) {
3410 duration = mSearchDropTargetBar.getTransitionInDuration();
3411 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003412 mHotseat.animate().alpha(1f).setDuration(duration);
3413 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003414 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003415 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003416 }
3417 }
3418 }
3419
3420 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003421 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003422 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003423 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003424 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003425 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003426 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003427 int duration = 0;
3428 if (mSearchDropTargetBar != null) {
3429 duration = mSearchDropTargetBar.getTransitionOutDuration();
3430 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003431 mHotseat.animate().alpha(0f).setDuration(duration);
3432 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003433 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003434 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003435 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003436 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003437 }
3438
Patrick Dubroy5f445422011-02-18 14:35:21 -08003439 /**
3440 * Add an item from all apps or customize onto the given workspace screen.
3441 * If layout is null, add to the current screen.
3442 */
3443 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003444 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003445 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003446 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003447 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003448
Winson Chungdff8ebb2011-09-08 17:25:31 -07003449 /** Maps the current orientation to an index for referencing orientation correct global icons */
3450 private int getCurrentOrientationIndexForGlobalIcons() {
3451 // default - 0, landscape - 1
3452 switch (getResources().getConfiguration().orientation) {
3453 case Configuration.ORIENTATION_LANDSCAPE:
3454 return 1;
3455 default:
3456 return 0;
3457 }
3458 }
3459
Michael Jurkaae65ee32012-04-30 11:45:54 -07003460 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003461 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003462 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003463 // Look for the toolbar icon specified in the activity meta-data
3464 Bundle metaData = packageManager.getActivityInfo(
3465 activityName, PackageManager.GET_META_DATA).metaData;
3466 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003467 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003468 if (iconResId != 0) {
3469 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003470 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003471 }
3472 }
3473 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003474 // This can happen if the activity defines an invalid drawable
3475 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3476 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003477 } catch (Resources.NotFoundException nfe) {
3478 // This can happen if the activity defines an invalid drawable
3479 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3480 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003481 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003482 return null;
3483 }
3484
3485 // if successful in getting icon, return it; otherwise, set button to use default drawable
3486 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003487 int buttonId, ComponentName activityName, int fallbackDrawableId,
3488 String toolbarResourceName) {
3489 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003490 Resources r = getResources();
3491 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3492 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003493
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003494 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003495 // If we were unable to find the icon via the meta-data, use a generic one
3496 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003497 toolbarIcon = r.getDrawable(fallbackDrawableId);
3498 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003499 if (button != null) {
3500 button.setCompoundDrawables(toolbarIcon, null, null, null);
3501 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003502 return null;
3503 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003504 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003505 if (button != null) {
3506 button.setCompoundDrawables(toolbarIcon, null, null, null);
3507 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003508 return toolbarIcon.getConstantState();
3509 }
3510 }
3511
3512 // if successful in getting icon, return it; otherwise, set button to use default drawable
3513 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003514 int buttonId, ComponentName activityName, int fallbackDrawableId,
3515 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003516 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003517 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003518
Michael Jurka19e0fc52011-07-22 18:00:21 -07003519 if (button != null) {
3520 // If we were unable to find the icon via the meta-data, use a
3521 // generic one
3522 if (toolbarIcon == null) {
3523 button.setImageResource(fallbackDrawableId);
3524 } else {
3525 button.setImageDrawable(toolbarIcon);
3526 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003527 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003528
3529 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3530
Michael Jurka0423dcf2010-10-05 14:56:18 -07003531 }
3532
Winson Chung1b884092012-06-08 17:13:02 -07003533 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003534 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003535 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003536 }
3537
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003538 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003539 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003540 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003541 }
3542
Winson Chungbb185bd2011-11-21 12:31:42 -08003543 private void invalidatePressedFocusedStates(View container, View button) {
3544 if (container instanceof HolographicLinearLayout) {
3545 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3546 layout.invalidatePressedFocusedStates();
3547 } else if (button instanceof HolographicImageView) {
3548 HolographicImageView view = (HolographicImageView) button;
3549 view.invalidatePressedFocusedStates();
3550 }
3551 }
3552
Cristina Stancu476493b2013-08-07 17:20:14 +01003553 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003554 if (mQsb == null) {
3555 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3556 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003557 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003558 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003559 }
3560
3561 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003562 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003563 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003564 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003565 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003566
Winson Chung1cad91e2011-05-25 17:41:01 -07003567 final SearchManager searchManager =
3568 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3569 ComponentName activityName = searchManager.getGlobalSearchActivity();
3570 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003571 int coi = getCurrentOrientationIndexForGlobalIcons();
3572 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003573 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3574 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3575 if (sGlobalSearchIcon[coi] == null) {
3576 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3577 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3578 TOOLBAR_ICON_METADATA_NAME);
3579 }
3580
Winson Chungc51db6a2011-10-05 11:44:49 -07003581 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3582 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003583 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003584 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003585 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003586 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003587 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3588 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003589 if (searchButton != null) searchButton.setVisibility(View.GONE);
3590 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003591 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003592 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003593 }
3594 }
3595
Cristina Stancu476493b2013-08-07 17:20:14 +01003596 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003597 final View searchButtonContainer = findViewById(R.id.search_button_container);
3598 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003599 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003600 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003601 }
3602
Cristina Stancu476493b2013-08-07 17:20:14 +01003603 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003604 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003605 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003606
Winson Chungc51db6a2011-10-05 11:44:49 -07003607 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003608 final SearchManager searchManager =
3609 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3610 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3611
3612 ComponentName activityName = null;
3613 if (globalSearchActivity != null) {
3614 // Check if the global search activity handles voice search
3615 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3616 intent.setPackage(globalSearchActivity.getPackageName());
3617 activityName = intent.resolveActivity(getPackageManager());
3618 }
3619
3620 if (activityName == null) {
3621 // Fallback: check if an activity other than the global search activity
3622 // resolves this
3623 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3624 activityName = intent.resolveActivity(getPackageManager());
3625 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003626 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003627 int coi = getCurrentOrientationIndexForGlobalIcons();
3628 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003629 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3630 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3631 if (sVoiceSearchIcon[coi] == null) {
3632 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3633 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3634 TOOLBAR_ICON_METADATA_NAME);
3635 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003636 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003637 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003638 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003639 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003640 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003641 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003642 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003643 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003644 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003645 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003646 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003647 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003648
Cristina Stancu476493b2013-08-07 17:20:14 +01003649 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003650 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3651 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003652 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003653 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003654 }
3655
Winson Chung5841efa2013-09-30 18:06:44 -07003656 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003657 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3658 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003659 boolean visible = !forceDisableVoiceButtonProxy &&
3660 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003661 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003662 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003663 }
3664 }
Winson Chung5841efa2013-09-30 18:06:44 -07003665
3666 /**
3667 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3668 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3669 */
3670 public void disableVoiceButtonProxy(boolean disabled) {
3671 updateVoiceButtonProxyVisible(disabled);
3672 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003673 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003674 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003675 */
3676 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003677 if (!DISABLE_MARKET_BUTTON) {
3678 final View marketButton = findViewById(R.id.market_button);
3679 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3680 // Find the app market activity by resolving an intent.
3681 // (If multiple app markets are installed, it will return the ResolverActivity.)
3682 ComponentName activityName = intent.resolveActivity(getPackageManager());
3683 if (activityName != null) {
3684 int coi = getCurrentOrientationIndexForGlobalIcons();
3685 mAppMarketIntent = intent;
3686 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3687 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3688 TOOLBAR_ICON_METADATA_NAME);
3689 marketButton.setVisibility(View.VISIBLE);
3690 } else {
3691 // We should hide and disable the view so that we don't try and restore the visibility
3692 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3693 marketButton.setVisibility(View.GONE);
3694 marketButton.setEnabled(false);
3695 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003696 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003697 }
3698
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003699 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003700 if (!DISABLE_MARKET_BUTTON) {
3701 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3702 Resources r = getResources();
3703 Drawable marketIconDrawable = d.newDrawable(r);
3704 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3705 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3706 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003707
Winson Chungd64a6662013-09-30 11:06:59 -07003708 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3709 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003710 }
3711
Michael Jurkad7c28052012-04-27 15:43:36 -07003712 @Override
3713 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003714 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003715 final List<CharSequence> text = event.getText();
3716 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003717 // Populate event with a fake title based on the current state.
3718 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003719 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003720 } else {
3721 text.add(getString(R.string.all_apps_home_button_label));
3722 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003723 return result;
3724 }
3725
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003726 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003727 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003728 */
3729 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3730 @Override
3731 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003732 closeSystemDialogs();
3733 }
3734 }
3735
3736 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003737 * Receives notifications whenever the appwidgets are reset.
3738 */
3739 private class AppWidgetResetObserver extends ContentObserver {
3740 public AppWidgetResetObserver() {
3741 super(new Handler());
3742 }
3743
3744 @Override
3745 public void onChange(boolean selfChange) {
3746 onAppWidgetReset();
3747 }
3748 }
3749
3750 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003751 * If the activity is currently paused, signal that we need to run the passed Runnable
3752 * in onResume.
3753 *
3754 * This needs to be called from incoming places where resources might have been loaded
3755 * while we are paused. That is becaues the Configuration might be wrong
3756 * when we're not running, and if it comes back to what it was when we
3757 * were paused, we are not restarted.
3758 *
3759 * Implementation of the method from LauncherModel.Callbacks.
3760 *
3761 * @return true if we are currently paused. The caller might be able to
3762 * skip some work in that case since we will come back again.
3763 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003764 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003765 if (mPaused) {
3766 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003767 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003768 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003769 }
3770 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003771 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003772 return true;
3773 } else {
3774 return false;
3775 }
3776 }
3777
Michael Jurkac402cd92013-05-20 15:49:32 +02003778 private boolean waitUntilResume(Runnable run) {
3779 return waitUntilResume(run, false);
3780 }
3781
Michael Jurka1e2f4652013-07-08 18:03:46 -07003782 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003783 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003784 }
3785
Michael Jurka7607c2f2013-04-03 14:33:19 -07003786 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003787 * If the activity is currently paused, signal that we need to re-run the loader
3788 * in onResume.
3789 *
3790 * This needs to be called from incoming places where resources might have been loaded
3791 * while we are paused. That is becaues the Configuration might be wrong
3792 * when we're not running, and if it comes back to what it was when we
3793 * were paused, we are not restarted.
3794 *
3795 * Implementation of the method from LauncherModel.Callbacks.
3796 *
3797 * @return true if we are currently paused. The caller might be able to
3798 * skip some work in that case since we will come back again.
3799 */
3800 public boolean setLoadOnResume() {
3801 if (mPaused) {
3802 Log.i(TAG, "setLoadOnResume");
3803 mOnResumeNeedsLoad = true;
3804 return true;
3805 } else {
3806 return false;
3807 }
3808 }
3809
3810 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003811 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003812 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003813 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003814 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003815 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003816 } else {
3817 return SCREEN_COUNT / 2;
3818 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003819 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003820
Joe Onorato9c1289c2009-08-17 11:03:03 -04003821 /**
3822 * Refreshes the shortcuts shown on the workspace.
3823 *
3824 * Implementation of the method from LauncherModel.Callbacks.
3825 */
3826 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003827 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003828
Michael Jurka7607c2f2013-04-03 14:33:19 -07003829 // If we're starting binding all over again, clear any bind calls we'd postponed in
3830 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3831 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003832 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003833
Winson Chungd64d1762013-08-20 14:37:16 -07003834 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003835 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003836 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003837
Michael Jurka05bf6442011-11-30 20:28:53 -08003838 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003839 if (mHotseat != null) {
3840 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003841 }
3842 }
3843
Adam Cohendcd297f2013-06-18 13:13:40 -07003844 @Override
3845 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003846 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003847
Adam Cohen5084cba2013-09-03 12:01:16 -07003848 // If there are no screens, we need to have an empty screen
3849 if (orderedScreenIds.size() == 0) {
3850 mWorkspace.addExtraEmptyScreen();
3851 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003852
3853 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003854 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003855 if (hasCustomContentToLeft()) {
3856 mWorkspace.createCustomContentContainer();
3857 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003858 }
Winson Chung64359a52013-07-08 17:17:08 -07003859 }
3860
3861 @Override
3862 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003863 // Log to disk
3864 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3865 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3866 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003867 int count = orderedScreenIds.size();
3868 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003869 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003870 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003871 }
3872
Adam Cohen39a06042013-07-19 14:30:12 -07003873 private boolean shouldShowWeightWatcher() {
3874 String spKey = LauncherAppState.getSharedPreferencesKey();
3875 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003876 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003877
3878 return show;
3879 }
3880
3881 private void toggleShowWeightWatcher() {
3882 String spKey = LauncherAppState.getSharedPreferencesKey();
3883 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3884 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3885
3886 show = !show;
3887
3888 SharedPreferences.Editor editor = sp.edit();
3889 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3890 editor.commit();
3891
3892 if (mWeightWatcher != null) {
3893 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3894 }
3895 }
3896
Winson Chungd64d1762013-08-20 14:37:16 -07003897 public void bindAppsAdded(final ArrayList<Long> newScreens,
3898 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003899 final ArrayList<ItemInfo> addAnimated,
3900 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003901 Runnable r = new Runnable() {
3902 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003903 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003904 }
3905 };
3906 if (waitUntilResume(r)) {
3907 return;
3908 }
3909
Winson Chungd64d1762013-08-20 14:37:16 -07003910 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003911 if (newScreens != null) {
3912 bindAddScreens(newScreens);
3913 }
Winson Chungd64d1762013-08-20 14:37:16 -07003914
3915 // We add the items without animation on non-visible pages, and with
3916 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003917 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003918 bindItems(addNotAnimated, 0,
3919 addNotAnimated.size(), false);
3920 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003921 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003922 bindItems(addAnimated, 0,
3923 addAnimated.size(), true);
3924 }
Winson Chungc58497e2013-09-03 17:48:37 -07003925
Winson Chung87412982013-10-03 18:34:14 -07003926 // Remove the extra empty screen
Adam Cohenad4e15c2013-10-17 16:21:35 -07003927 mWorkspace.removeExtraEmptyScreen(false, null);
Winson Chung87412982013-10-03 18:34:14 -07003928
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003929 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07003930 addedApps != null && mAppsCustomizeContent != null) {
3931 mAppsCustomizeContent.addApps(addedApps);
3932 }
Winson Chungd64d1762013-08-20 14:37:16 -07003933 }
3934
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003935 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003936 * Bind the items start-end from the list.
3937 *
3938 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003939 */
Winson Chung64359a52013-07-08 17:17:08 -07003940 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3941 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003942 Runnable r = new Runnable() {
3943 public void run() {
3944 bindItems(shortcuts, start, end, forceAnimateIcons);
3945 }
3946 };
3947 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003948 return;
3949 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003950
Winson Chungf0c6ae02012-03-21 16:10:31 -07003951 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003952 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3953 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003954 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003955 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003956 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003957 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003958 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003959
3960 // Short circuit if we are loading dock items for a configuration which has no dock
3961 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3962 mHotseat == null) {
3963 continue;
3964 }
3965
Joe Onorato9c1289c2009-08-17 11:03:03 -04003966 switch (item.itemType) {
3967 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3968 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003969 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003970 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003971
Winson Chung64359a52013-07-08 17:17:08 -07003972 /*
3973 * TODO: FIX collision case
3974 */
Winson Chungce376632013-07-11 16:12:41 -07003975 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3976 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3977 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003978 View v = cl.getChildAt(item.cellX, item.cellY);
3979 Object tag = v.getTag();
3980 String desc = "Collision while binding workspace item: " + item
3981 + ". Collides with " + tag;
3982 if (LauncherAppState.isDogfoodBuild()) {
3983 throw (new RuntimeException(desc));
3984 } else {
3985 Log.d(TAG, desc);
3986 }
Winson Chungce376632013-07-11 16:12:41 -07003987 }
Winson Chung64359a52013-07-08 17:17:08 -07003988 }
3989
Adam Cohendcd297f2013-06-18 13:13:40 -07003990 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3991 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003992 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003993 // Animate all the applications up now
3994 shortcut.setAlpha(0f);
3995 shortcut.setScaleX(0f);
3996 shortcut.setScaleY(0f);
3997 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003998 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003999 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004000 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004001 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004002 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004003 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004004 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004005 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4006 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004007 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004008 default:
4009 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004010 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004011 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004012
Winson Chung997a9232013-07-24 15:33:46 -07004013 if (animateIcons) {
4014 // Animate to the correct page
4015 if (newShortcutsScreenId > -1) {
4016 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004017 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004018 final Runnable startBounceAnimRunnable = new Runnable() {
4019 public void run() {
4020 anim.playTogether(bounceAnims);
4021 anim.start();
4022 }
4023 };
Winson Chung997a9232013-07-24 15:33:46 -07004024 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004025 // We post the animation slightly delayed to prevent slowdowns
4026 // when we are loading right after we return to launcher.
4027 mWorkspace.postDelayed(new Runnable() {
4028 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004029 if (mWorkspace != null) {
4030 mWorkspace.snapToPage(newScreenIndex);
4031 mWorkspace.postDelayed(startBounceAnimRunnable,
4032 NEW_APPS_ANIMATION_DELAY);
4033 }
Winson Chung94d67682013-09-25 16:29:40 -07004034 }
4035 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004036 } else {
4037 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004038 }
4039 }
Winson Chung64359a52013-07-08 17:17:08 -07004040 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004041 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004042 }
4043
Joe Onorato9c1289c2009-08-17 11:03:03 -04004044 /**
4045 * Implementation of the method from LauncherModel.Callbacks.
4046 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004047 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004048 Runnable r = new Runnable() {
4049 public void run() {
4050 bindFolders(folders);
4051 }
4052 };
4053 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004054 return;
4055 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004056 sFolders.clear();
4057 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004058 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004059
4060 /**
4061 * Add the views for a widget to the workspace.
4062 *
4063 * Implementation of the method from LauncherModel.Callbacks.
4064 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004065 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004066 Runnable r = new Runnable() {
4067 public void run() {
4068 bindAppWidget(item);
4069 }
4070 };
4071 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004072 return;
4073 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004074
Daniel Sandler843e8602010-06-07 14:59:01 -04004075 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4076 if (DEBUG_WIDGETS) {
4077 Log.d(TAG, "bindAppWidget: " + item);
4078 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004079 final Workspace workspace = mWorkspace;
4080
4081 final int appWidgetId = item.appWidgetId;
4082 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04004083 if (DEBUG_WIDGETS) {
4084 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4085 }
4086
Joe Onorato9c1289c2009-08-17 11:03:03 -04004087 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4088
Joe Onorato9c1289c2009-08-17 11:03:03 -04004089 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004090 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004091
Adam Cohendcd297f2013-06-18 13:13:40 -07004092 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004093 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004094 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4095
Joe Onorato9c1289c2009-08-17 11:03:03 -04004096 workspace.requestLayout();
4097
Daniel Sandler843e8602010-06-07 14:59:01 -04004098 if (DEBUG_WIDGETS) {
4099 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4100 + (SystemClock.uptimeMillis()-start) + "ms");
4101 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004102 }
4103
Adam Cohen1462de32012-07-24 22:34:36 -07004104 public void onPageBoundSynchronously(int page) {
4105 mSynchronouslyBoundPages.add(page);
4106 }
4107
Joe Onorato9c1289c2009-08-17 11:03:03 -04004108 /**
4109 * Callback saying that there aren't any more items to bind.
4110 *
4111 * Implementation of the method from LauncherModel.Callbacks.
4112 */
Adam Cohene25af792013-06-06 23:08:25 -07004113 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004114 Runnable r = new Runnable() {
4115 public void run() {
4116 finishBindingItems(upgradePath);
4117 }
4118 };
4119 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004120 return;
4121 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004122 if (mSavedState != null) {
4123 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004124 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004125 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004126 mSavedState = null;
4127 }
4128
Adam Cohen1462de32012-07-24 22:34:36 -07004129 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004130
Patrick Dubroy002cbf42011-03-03 16:36:21 -08004131 // If we received the result of any pending adds while the loader was running (e.g. the
4132 // widget configuration forced an orientation change), process them now.
4133 for (int i = 0; i < sPendingAddList.size(); i++) {
4134 completeAdd(sPendingAddList.get(i));
4135 }
4136 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004137
Winson Chungc51db6a2011-10-05 11:44:49 -07004138 // Update the market app icon as necessary (the other icons will be managed in response to
4139 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004140 if (!DISABLE_MARKET_BUTTON) {
4141 updateAppMarketIcon();
4142 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004143
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004144 setWorkspaceLoading(false);
Adam Cohene25af792013-06-06 23:08:25 -07004145 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004146 mWorkspace.getUniqueComponents(true, null);
4147 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004148 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004149 }
4150
Winson Chunga0b7e862013-09-05 16:03:15 -07004151 public boolean isAllAppsButtonRank(int rank) {
4152 if (mHotseat != null) {
4153 return mHotseat.isAllAppsButtonRank(rank);
4154 }
4155 return false;
4156 }
4157
Winson Chunga2413752012-04-03 14:22:34 -07004158 private boolean canRunNewAppsAnimation() {
4159 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4160 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4161 }
4162
Winson Chungc9168342013-06-26 14:54:55 -07004163 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4164 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4165 PropertyValuesHolder.ofFloat("alpha", 1f),
4166 PropertyValuesHolder.ofFloat("scaleX", 1f),
4167 PropertyValuesHolder.ofFloat("scaleY", 1f));
4168 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4169 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4170 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4171 return bounceAnim;
4172 }
4173
Adam Cohen27772732013-11-11 14:00:56 +00004174 public boolean useVerticalBarLayout() {
4175 return LauncherAppState.getInstance().getDynamicGrid().
4176 getDeviceProfile().isVerticalBarLayout();
4177 }
4178
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004179 protected Rect getSearchBarBounds() {
4180 return LauncherAppState.getInstance().getDynamicGrid().
4181 getDeviceProfile().getSearchBarBounds();
4182 }
4183
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004184 @Override
4185 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004186 boolean searchVisible = updateGlobalSearchIcon();
4187 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004188 if (mSearchDropTargetBar != null) {
4189 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4190 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004191 }
4192
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004193 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004194 * Add the icons for all apps.
4195 *
4196 * Implementation of the method from LauncherModel.Callbacks.
4197 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004198 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004199 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004200 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4201 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4202 getHotseat().addAllAppsFolder(mIconCache, apps,
4203 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4204 }
4205 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004206 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004207 if (mAppsCustomizeContent != null) {
4208 mAppsCustomizeContent.onPackagesUpdated(
4209 LauncherModel.getSortedWidgetsAndShortcuts(this));
4210 }
Winson Chungc58497e2013-09-03 17:48:37 -07004211 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004212 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004213 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004214 mAppsCustomizeContent.onPackagesUpdated(
4215 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004216 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004217 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004218 }
4219
4220 /**
4221 * A package was updated.
4222 *
4223 * Implementation of the method from LauncherModel.Callbacks.
4224 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004225 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004226 Runnable r = new Runnable() {
4227 public void run() {
4228 bindAppsUpdated(apps);
4229 }
4230 };
4231 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004232 return;
4233 }
4234
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004235 if (mWorkspace != null) {
4236 mWorkspace.updateShortcuts(apps);
4237 }
Winson Chungc58497e2013-09-03 17:48:37 -07004238
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004239 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004240 mAppsCustomizeContent != null) {
4241 mAppsCustomizeContent.updateApps(apps);
4242 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004243 }
4244
4245 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004246 * Update the state of a package, typically related to install state.
4247 *
4248 * Implementation of the method from LauncherModel.Callbacks.
4249 */
4250 public void updatePackageState(String pkgName, int state) {
4251 if (mWorkspace != null) {
4252 mWorkspace.updatePackageState(pkgName, state);
4253 }
4254 }
4255
4256 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004257 * A package was uninstalled. We take both the super set of packageNames
4258 * in addition to specific applications to remove, the reason being that
4259 * this can be called when a package is updated as well. In that scenario,
4260 * we only remove specific components from the workspace, where as
4261 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004262 *
4263 * Implementation of the method from LauncherModel.Callbacks.
4264 */
Winson Chung83892cc2013-05-01 16:53:33 -07004265 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004266 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004267 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004268 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004269 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004270 }
Winson Chungd64d1762013-08-20 14:37:16 -07004271 };
4272 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004273 return;
4274 }
4275
Winson Chungdf95eb12013-10-16 14:57:07 -07004276 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004277 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004278 }
4279 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004280 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004281 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004282
Winson Chunga1820962011-10-03 16:31:06 -07004283 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004284 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004285
Winson Chungdf95eb12013-10-16 14:57:07 -07004286 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004287 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004288 mAppsCustomizeContent != null) {
4289 mAppsCustomizeContent.removeApps(appInfos);
4290 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004291 }
Joe Onoratobe386092009-11-17 17:32:16 -08004292
4293 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004294 * A number of packages were updated.
4295 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004296 private ArrayList<Object> mWidgetsAndShortcuts;
4297 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004298 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004299 bindPackagesUpdated(mWidgetsAndShortcuts);
4300 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004301 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004302 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004303 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4304 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4305 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004306 return;
4307 }
4308
Winson Chung64359a52013-07-08 17:17:08 -07004309 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004310 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004311 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004312 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004313 }
4314
Winson Chung400438b2011-01-16 17:53:48 -08004315 private int mapConfigurationOriActivityInfoOri(int configOri) {
4316 final Display d = getWindowManager().getDefaultDisplay();
4317 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4318 switch (d.getRotation()) {
4319 case Surface.ROTATION_0:
4320 case Surface.ROTATION_180:
4321 // We are currently in the same basic orientation as the natural orientation
4322 naturalOri = configOri;
4323 break;
4324 case Surface.ROTATION_90:
4325 case Surface.ROTATION_270:
4326 // We are currently in the other basic orientation to the natural orientation
4327 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4328 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4329 break;
4330 }
4331
4332 int[] oriMap = {
4333 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4334 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4335 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4336 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4337 };
4338 // Since the map starts at portrait, we need to offset if this device's natural orientation
4339 // is landscape.
4340 int indexOffset = 0;
4341 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4342 indexOffset = 1;
4343 }
4344 return oriMap[(d.getRotation() + indexOffset) % 4];
4345 }
Adam Cohen446e9402011-09-15 18:21:21 -07004346
Winson Chung4b919f82012-05-01 10:44:08 -07004347 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004348 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004349 getResources().getBoolean(R.bool.allow_rotation);
4350 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004351 }
Winson Chung4b919f82012-05-01 10:44:08 -07004352 public void lockScreenOrientation() {
4353 if (isRotationEnabled()) {
4354 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4355 .getConfiguration().orientation));
4356 }
4357 }
4358 public void unlockScreenOrientation(boolean immediate) {
4359 if (isRotationEnabled()) {
4360 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004361 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004362 } else {
4363 mHandler.postDelayed(new Runnable() {
4364 public void run() {
4365 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4366 }
4367 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004368 }
Winson Chung4b919f82012-05-01 10:44:08 -07004369 }
Winson Chung400438b2011-01-16 17:53:48 -08004370 }
4371
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004372 /**
4373 * Called when the SearchBar hint should be changed.
4374 *
4375 * @param hint the hint to be displayed in the search bar.
4376 */
4377 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004378 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004379 }
4380
Winson Chunge43a1e72014-01-15 10:33:02 -08004381 protected boolean isLauncherPreinstalled() {
4382 PackageManager pm = getPackageManager();
4383 try {
4384 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4385 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4386 return true;
4387 } else {
4388 return false;
4389 }
4390 } catch (NameNotFoundException e) {
4391 e.printStackTrace();
4392 return false;
4393 }
4394 }
4395
Winson Chunge6eabff2013-09-24 11:01:23 -07004396 protected String getFirstRunClingSearchBarHint() {
4397 return "";
4398 }
4399 protected String getFirstRunCustomContentHint() {
4400 return "";
4401 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004402 protected int getFirstRunFocusedHotseatAppDrawableId() {
4403 return -1;
4404 }
4405 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4406 return null;
4407 }
4408 protected int getFirstRunFocusedHotseatAppRank() {
4409 return -1;
4410 }
4411 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4412 return "";
4413 }
4414 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4415 return "";
4416 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004417
Winson Chungaf40f202013-09-18 18:26:31 -07004418 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004419 mLauncherClings.dismissFirstRunCling(v);
4420 }
4421 public void dismissMigrationClingCopyApps(View v) {
4422 mLauncherClings.dismissMigrationClingCopyApps(v);
4423 }
4424 public void dismissMigrationClingUseDefault(View v) {
4425 mLauncherClings.dismissMigrationClingUseDefault(v);
4426 }
4427 public void dismissMigrationWorkspaceCling(View v) {
4428 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004429 }
Winson Chung82f55532011-08-09 14:14:23 -07004430 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004431 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004432 }
4433 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004434 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004435 }
4436
Adam Cohen432609a2014-03-13 17:03:22 -07004437
4438 /**
4439 * To be overridden by subclasses to indicate that there is an activity to launch
4440 * before showing the standard launcher experience.
4441 */
4442 protected boolean hasFirstRunActivity() {
4443 return false;
4444 }
4445
4446 /**
4447 * To be overridden by subclasses to launch any first run activity
4448 */
4449 protected Intent getFirstRunActivity() {
4450 return null;
4451 }
4452
Winson Chunga6945242014-01-08 14:04:34 -08004453 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004454 return !ActivityManager.isRunningInTestHarness() &&
4455 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004456 }
4457
Adam Cohen4a9423d2014-03-28 14:22:31 -07004458 protected boolean hasRunFirstRunActivity() {
4459 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4460 }
4461
Adam Cohen432609a2014-03-13 17:03:22 -07004462 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004463 if (shouldRunFirstRunActivity() &&
4464 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004465 Intent firstRunIntent = getFirstRunActivity();
4466 if (firstRunIntent != null) {
4467 startActivity(firstRunIntent);
4468 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004469 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004470 }
4471 }
Adam Cohen432609a2014-03-13 17:03:22 -07004472 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004473 }
4474
4475 private void markFirstRunActivityShown() {
4476 SharedPreferences.Editor editor = mSharedPrefs.edit();
4477 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4478 editor.apply();
4479 }
4480
Adam Cohen432609a2014-03-13 17:03:22 -07004481 /**
4482 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4483 * screen that must be displayed and dismissed.
4484 */
4485 protected boolean hasDismissableIntroScreen() {
4486 return false;
4487 }
4488
4489 /**
4490 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4491 */
4492 protected View getIntroScreen() {
4493 return null;
4494 }
4495
4496 /**
4497 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4498 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4499 */
4500 private boolean shouldShowIntroScreen() {
4501 return hasDismissableIntroScreen() &&
4502 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4503 }
4504
4505 protected void showIntroScreen() {
4506 View introScreen = getIntroScreen();
4507 changeWallpaperVisiblity(false);
4508 if (introScreen != null) {
4509 mDragLayer.showOverlayView(introScreen);
4510 }
4511 }
4512
4513 public void dismissIntroScreen() {
4514 markIntroScreenDismissed();
4515 if (showFirstRunActivity()) {
4516 // We delay hiding the intro view until the first run activity is showing. This
4517 // avoids a blip.
4518 mWorkspace.postDelayed(new Runnable() {
4519 @Override
4520 public void run() {
4521 mDragLayer.dismissOverlayView();
4522 }
4523 }, ACTIVITY_START_DELAY);
4524 } else {
4525 mDragLayer.dismissOverlayView();
4526 }
4527 changeWallpaperVisiblity(true);
4528 }
4529
4530 private void markIntroScreenDismissed() {
4531 SharedPreferences.Editor editor = mSharedPrefs.edit();
4532 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4533 editor.apply();
4534 }
4535
Winson Chunga6945242014-01-08 14:04:34 -08004536 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004537 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4538 if (mHotseat != null) mHotseat.setAlpha(1f);
4539 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4540 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004541 }
4542
4543 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004544 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4545 if (mHotseat != null) mHotseat.setAlpha(0f);
4546 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4547 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004548 }
4549
Mathew Inwood72fbec12013-11-19 15:45:07 +00004550 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004551 // Called from search suggestion, not supported in other profiles.
4552 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4553 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4554 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4555 myUser);
4556 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004557 return null;
4558 }
Kenny Guyed131872014-04-30 03:02:21 +01004559 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004560 }
4561
4562 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4563 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004564 // Called from search suggestion, not supported in other profiles.
4565 return createShortcutDragInfo(shortcutIntent, caption, icon,
4566 UserHandleCompat.myUserHandle());
4567 }
4568
4569 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4570 Bitmap icon, UserHandleCompat user) {
4571 return new ShortcutInfo(shortcutIntent, caption, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004572 }
4573
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004574 protected void moveWorkspaceToDefaultScreen() {
4575 mWorkspace.moveToDefaultScreen(false);
4576 }
4577
Mathew Inwood72fbec12013-11-19 15:45:07 +00004578 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4579 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004580 mWorkspace.onExternalDragStartedWithItem(dragView);
4581 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004582 }
4583
Anjali Koppalf5d29132014-02-28 13:33:27 -08004584 @Override
4585 public void onPageSwitch(View newPage, int newPageIndex) {
4586 }
4587
Winson Chung80baf5a2010-08-09 16:03:15 -07004588 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004589 * Prints out out state for debugging.
4590 */
4591 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004592 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004593 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004594 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4595 Log.d(TAG, "mRestoring=" + mRestoring);
4596 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4597 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004598 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004599 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004600
Winson Chung785d2eb2011-04-14 16:08:02 -07004601 if (mAppsCustomizeContent != null) {
4602 mAppsCustomizeContent.dumpState();
4603 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004604 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004605 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004606
4607 @Override
4608 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4609 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004610 synchronized (sDumpLogs) {
4611 writer.println(" ");
4612 writer.println("Debug logs: ");
4613 for (int i = 0; i < sDumpLogs.size(); i++) {
4614 writer.println(" " + sDumpLogs.get(i));
4615 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004616 }
4617 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004618
4619 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004620 if (DEBUG_DUMP_LOG) {
4621 synchronized (sDumpLogs) {
4622 Log.d(TAG, "");
4623 Log.d(TAG, "*********************");
4624 Log.d(TAG, "Launcher debug logs: ");
4625 for (int i = 0; i < sDumpLogs.size(); i++) {
4626 Log.d(TAG, " " + sDumpLogs.get(i));
4627 }
4628 Log.d(TAG, "*********************");
4629 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004630 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004631 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004632 }
4633
4634 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004635 addDumpLog(tag, log, null, debugLog);
4636 }
4637
4638 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004639 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004640 if (e != null) {
4641 Log.d(tag, log, e);
4642 } else {
4643 Log.d(tag, log);
4644 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004645 }
Winson Chungede41292013-09-19 16:27:36 -07004646 if (DEBUG_DUMP_LOG) {
4647 sDateStamp.setTime(System.currentTimeMillis());
4648 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004649 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4650 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004651 }
Winson Chungede41292013-09-19 16:27:36 -07004652 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004653 }
4654
Winson Chungede41292013-09-19 16:27:36 -07004655 public void dumpLogsToLocalData() {
4656 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004657 new AsyncTask<Void, Void, Void>() {
4658 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004659 boolean success = false;
4660 sDateStamp.setTime(sRunStart);
4661 String FILENAME = sDateStamp.getMonth() + "-"
4662 + sDateStamp.getDay() + "_"
4663 + sDateStamp.getHours() + "-"
4664 + sDateStamp.getMinutes() + "_"
4665 + sDateStamp.getSeconds() + ".txt";
4666
4667 FileOutputStream fos = null;
4668 File outFile = null;
4669 try {
4670 outFile = new File(getFilesDir(), FILENAME);
4671 outFile.createNewFile();
4672 fos = new FileOutputStream(outFile);
4673 } catch (Exception e) {
4674 e.printStackTrace();
4675 }
4676 if (fos != null) {
4677 PrintWriter writer = new PrintWriter(fos);
4678
4679 writer.println(" ");
4680 writer.println("Debug logs: ");
4681 synchronized (sDumpLogs) {
4682 for (int i = 0; i < sDumpLogs.size(); i++) {
4683 writer.println(" " + sDumpLogs.get(i));
4684 }
4685 }
4686 writer.close();
4687 }
4688 try {
4689 if (fos != null) {
4690 fos.close();
4691 success = true;
4692 }
4693 } catch (IOException e) {
4694 e.printStackTrace();
4695 }
Michael Jurka43467462013-11-14 12:03:58 +01004696 return null;
Winson Chungede41292013-09-19 16:27:36 -07004697 }
Michael Jurka43467462013-11-14 12:03:58 +01004698 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004699 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004700 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004701}
Michael Jurka2763be32011-02-24 11:19:57 -08004702
Michael Jurkaabded662011-03-04 12:06:57 -08004703interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004704 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004705 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004706 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004707 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004708 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004709}
Dan Sandlerd5024042014-01-09 15:01:33 -05004710
4711interface DebugIntents {
4712 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4713 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004714}