blob: c9dd56041841c09e0bfa2f456ae551210b9f1cf7 [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 Sandler6053b8002013-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;
218 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700219 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800222 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800223
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000224 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
225 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
226
Winson Chunga2413752012-04-03 14:22:34 -0700227 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700228 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
229 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700230 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700231
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800232 private final BroadcastReceiver mCloseSystemDialogsReceiver
233 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800234 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 private LayoutInflater mInflater;
237
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700239 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800240 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800241 private DragLayer mDragLayer;
242 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700243 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800244 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700245
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700246 private AppWidgetManager mAppWidgetManager;
247 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700248
Michael Jurkac9d95c52011-08-29 14:03:34 -0700249 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700250 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800251 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700252
Michael Jurka0280c3b2010-09-17 15:00:07 -0700253 private int[] mTmpAddItemCellCoordinates = new int[2];
254
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 private FolderInfo mFolderInfo;
256
Winson Chung3d503fb2011-07-13 17:25:49 -0700257 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800258 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700259
Michael Jurka838a4ca2011-02-07 13:33:06 -0800260 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700261
Winson Chungc51db6a2011-10-05 11:44:49 -0700262 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700263 private AppsCustomizeTabHost mAppsCustomizeTabHost;
264 private AppsCustomizePagedView mAppsCustomizeContent;
265 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800266 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700269 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
270 // scroll issues (because the workspace may not have been measured yet) and extra work.
271 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
272 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273
274 private SpannableStringBuilder mDefaultKeySsb = null;
275
Joe Onorato9c1289c2009-08-17 11:03:03 -0400276 private boolean mWorkspaceLoading = true;
277
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800278 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800279 private boolean mRestoring;
280 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700281 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282
Michael Jurka1e2f4652013-07-08 18:03:46 -0700283 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700284 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
285
Winson Chung4a2afa32012-07-19 14:53:05 -0700286 // Keep track of whether the user has left launcher
287 private static boolean sPausedFromUserAction = false;
288
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289 private Bundle mSavedInstanceState;
290
Joe Onorato9c1289c2009-08-17 11:03:03 -0400291 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800292 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800293 private boolean mUserPresent = true;
294 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700295 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800296 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400297
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700298 private static LocaleConfiguration sLocaleConfiguration = null;
299
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700300 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700301
Adam Cohen61f560d2013-09-30 15:58:20 -0700302 private View.OnTouchListener mHapticFeedbackTouchListener;
303
Adam Cohended9f8d2010-11-03 13:25:16 -0700304 // Related to the auto-advancing of widgets
305 private final int ADVANCE_MSG = 1;
306 private final int mAdvanceInterval = 20000;
307 private final int mAdvanceStagger = 250;
308 private long mAutoAdvanceSentTime;
309 private long mAutoAdvanceTimeLeft = -1;
310 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
311 new HashMap<View, AppWidgetProviderInfo>();
312
Winson Chung400438b2011-01-16 17:53:48 -0800313 // Determines how long to wait after a rotation before restoring the screen orientation to
314 // match the sensor state.
315 private final int mRestoreScreenOrientationDelay = 500;
316
Michael Jurka4ef207b2010-11-29 17:05:45 -0800317 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700318 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
319 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
320 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800321
Winson Chungd64a6662013-09-30 11:06:59 -0700322 private Intent mAppMarketIntent = null;
323 private static final boolean DISABLE_MARKET_BUTTON = true;
324
Craig Mautner360310b2012-10-26 15:13:08 -0700325 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700326
Adam Cohen1462de32012-07-24 22:34:36 -0700327 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700328 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700329
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700330 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700331 static Date sDateStamp = new Date();
332 static DateFormat sDateFormat =
333 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
334 static long sRunStart = System.currentTimeMillis();
335 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700336
Winson Chung46353de2012-02-16 14:05:10 -0800337 // We only want to get the SharedPreferences once since it does an FS stat each time we get
338 // it from the context.
339 private SharedPreferences mSharedPrefs;
340
Adam Cohene25af792013-06-06 23:08:25 -0700341 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
342
Winson Chungf0c6ae02012-03-21 16:10:31 -0700343 // Holds the page that we need to animate to, and the icon views that we need to animate up
344 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700345 private ImageView mFolderIconImageView;
346 private Bitmap mFolderIconBitmap;
347 private Canvas mFolderIconCanvas;
348 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700349
Michael Jurkaddd62e92011-02-16 17:49:14 -0800350 private BubbleTextView mWaitingForResume;
351
Michael Jurkac1f5d262011-09-30 19:32:27 -0700352 private Runnable mBuildLayersRunnable = new Runnable() {
353 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700354 if (mWorkspace != null) {
355 mWorkspace.buildPageHardwareLayers();
356 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700357 }
358 };
359
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800360 private static ArrayList<PendingAddArguments> sPendingAddList
361 = new ArrayList<PendingAddArguments>();
362
Michael Jurka7267fa52013-09-26 15:29:57 -0700363 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800364
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800365 private static class PendingAddArguments {
366 int requestCode;
367 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700368 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700369 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800370 int cellX;
371 int cellY;
372 }
373
Daniel Sandlerff02d492013-08-05 02:12:05 -0400374 private Stats mStats;
375
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800376 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800377 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700378 }
379
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380 @Override
381 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700382 if (DEBUG_STRICT_MODE) {
383 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
384 .detectDiskReads()
385 .detectDiskWrites()
386 .detectNetwork() // or .detectAll() for all detectable problems
387 .penaltyLog()
388 .build());
389 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
390 .detectLeakedSqlLiteObjects()
391 .detectLeakedClosableObjects()
392 .penaltyLog()
393 .penaltyDeath()
394 .build());
395 }
396
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800397 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400398
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400399 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400400 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700401 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700402 // Determine the dynamic grid properties
403 Point smallestSize = new Point();
404 Point largestSize = new Point();
405 Point realSize = new Point();
406 Display display = getWindowManager().getDefaultDisplay();
407 display.getCurrentSizeRange(smallestSize, largestSize);
408 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700409 DisplayMetrics dm = new DisplayMetrics();
410 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700411
Winson Chung5f8afe62013-08-12 16:19:28 -0700412 // Lazy-initialize the dynamic grid
413 DeviceProfile grid = app.initDynamicGrid(this,
414 Math.min(smallestSize.x, smallestSize.y),
415 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700416 realSize.x, realSize.y,
417 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700418
419 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400420 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700421 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800422 mModel = app.setLauncher(this);
423 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700424 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400425 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800426 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700428
Daniel Sandlerff02d492013-08-05 02:12:05 -0400429 mStats = new Stats(this);
430
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700431 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700432
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700433 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
434 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700435
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700436 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
437 // this also ensures that any synchronous binding below doesn't re-trigger another
438 // LauncherModel load.
439 mPaused = false;
440
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200442 android.os.Debug.startMethodTracing(
443 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444 }
445
Adam Cohen53805212013-10-01 10:39:23 -0700446
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800447 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100451 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800453 registerContentObservers();
454
Joe Onorato7c312c12009-08-13 21:36:53 -0700455 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700456
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 mSavedState = savedInstanceState;
458 restoreState(mSavedState);
459
460 if (PROFILE_STARTUP) {
461 android.os.Debug.stopMethodTracing();
462 }
463
464 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700465 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700466 // If the user leaves launcher, then we should just load items asynchronously when
467 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500468 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 } else {
470 // We only load the page synchronously if the user rotates (or triggers a
471 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800472 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700473 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800474 }
475
476 // For handling default keys
477 mDefaultKeySsb = new SpannableStringBuilder();
478 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800479
480 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
481 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800482
Adam Cohenf9426d52012-06-04 17:26:21 -0700483 updateGlobalIcons();
484
485 // On large interfaces, we want the screen to auto-rotate based on the current orientation
486 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700487
Adam Cohen432609a2014-03-13 17:03:22 -0700488 if (shouldShowIntroScreen()) {
489 showIntroScreen();
490 } else {
491 showFirstRunActivity();
492 }
493
Winson Chunge43a1e72014-01-15 10:33:02 -0800494 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
495 // on the device, then we always show the first run cling experience (or if there is no
496 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800497 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
498 if (mModel.canMigrateFromOldLauncherDb(this)) {
499 mLauncherClings.showMigrationCling();
500 } else {
501 mLauncherClings.showFirstRunCling();
502 }
Winson Chunga6945242014-01-08 14:04:34 -0800503 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800504 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800505 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700506 }
507
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700508 @Override
509 public void onLauncherProviderChange() { }
510
Winson Chung4a2afa32012-07-19 14:53:05 -0700511 protected void onUserLeaveHint() {
512 super.onUserLeaveHint();
513 sPausedFromUserAction = true;
514 }
515
Winson Chung98ca0f72013-07-29 12:58:51 -0700516 /** To be overriden by subclasses to hint to Launcher that we have custom content */
517 protected boolean hasCustomContentToLeft() {
518 return false;
519 }
520
Dave Hawkeya8881582013-09-17 15:55:33 -0600521 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500522 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600523 * {@link #addToCustomContentPage}. This will only be invoked if
524 * {@link #hasCustomContentToLeft()} is {@code true}.
525 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500526 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600527 }
528
529 /**
530 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
531 * ensure the custom content page is added or removed if necessary.
532 */
533 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600534 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600535 // Not bound yet, wait for bindScreens to be called.
536 return;
537 }
538
539 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
540 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500541 mWorkspace.createCustomContentContainer();
542 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600543 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
544 mWorkspace.removeCustomContentPage();
545 }
546 }
547
Adam Cohenf9426d52012-06-04 17:26:21 -0700548 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700549 boolean searchVisible = false;
550 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800551 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700552 int coi = getCurrentOrientationIndexForGlobalIcons();
553 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
554 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700555 if (!DISABLE_MARKET_BUTTON) {
556 updateAppMarketIcon();
557 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700558 searchVisible = updateGlobalSearchIcon();
559 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700560 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700561 if (sGlobalSearchIcon[coi] != null) {
562 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700563 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700564 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700565 if (sVoiceSearchIcon[coi] != null) {
566 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700567 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700568 }
Winson Chungd64a6662013-09-30 11:06:59 -0700569 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700570 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800571 }
Winson Chungadf0c182012-08-23 14:59:07 -0700572 if (mSearchDropTargetBar != null) {
573 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
574 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 }
Romain Guycbb89e42009-06-08 15:52:54 -0700576
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700578 if (sLocaleConfiguration == null) {
579 new AsyncTask<Void, Void, LocaleConfiguration>() {
580 @Override
581 protected LocaleConfiguration doInBackground(Void... unused) {
582 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
583 readConfiguration(Launcher.this, localeConfiguration);
584 return localeConfiguration;
585 }
586
587 @Override
588 protected void onPostExecute(LocaleConfiguration result) {
589 sLocaleConfiguration = result;
590 checkForLocaleChange(); // recursive, but now with a locale configuration
591 }
592 }.execute();
593 return;
594 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700595
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800596 final Configuration configuration = getResources().getConfiguration();
597
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700598 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800599 final String locale = configuration.locale.toString();
600
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700601 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800602 final int mcc = configuration.mcc;
603
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700604 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800605 final int mnc = configuration.mnc;
606
Romain Guy84f296c2009-11-04 15:00:44 -0800607 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800608
Romain Guy84f296c2009-11-04 15:00:44 -0800609 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700610 sLocaleConfiguration.locale = locale;
611 sLocaleConfiguration.mcc = mcc;
612 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700613
Joe Onorato0589f0f2010-02-08 13:44:00 -0800614 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700615
616 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100617 new AsyncTask<Void, Void, Void>() {
618 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700619 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100620 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700621 }
Michael Jurka43467462013-11-14 12:03:58 +0100622 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700623 }
624 }
625
626 private static class LocaleConfiguration {
627 public String locale;
628 public int mcc = -1;
629 public int mnc = -1;
630 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700631
Romain Guy98d01652009-06-30 16:21:04 -0700632 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
633 DataInputStream in = null;
634 try {
635 in = new DataInputStream(context.openFileInput(PREFERENCES));
636 configuration.locale = in.readUTF();
637 configuration.mcc = in.readInt();
638 configuration.mnc = in.readInt();
639 } catch (FileNotFoundException e) {
640 // Ignore
641 } catch (IOException e) {
642 // Ignore
643 } finally {
644 if (in != null) {
645 try {
646 in.close();
647 } catch (IOException e) {
648 // Ignore
649 }
650 }
651 }
652 }
653
654 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
655 DataOutputStream out = null;
656 try {
657 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
658 out.writeUTF(configuration.locale);
659 out.writeInt(configuration.mcc);
660 out.writeInt(configuration.mnc);
661 out.flush();
662 } catch (FileNotFoundException e) {
663 // Ignore
664 } catch (IOException e) {
665 //noinspection ResultOfMethodCallIgnored
666 context.getFileStreamPath(PREFERENCES).delete();
667 } finally {
668 if (out != null) {
669 try {
670 out.close();
671 } catch (IOException e) {
672 // Ignore
673 }
674 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 }
676 }
677
Anton Hanssona2f665f2013-09-26 12:18:32 +0100678 public Stats getStats() {
679 return mStats;
680 }
681
Bjorn Bringertc459e522013-06-07 19:36:01 +0100682 public LayoutInflater getInflater() {
683 return mInflater;
684 }
685
Winson Chung36a62fe2012-05-06 18:04:42 -0700686 boolean isDraggingEnabled() {
687 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
688 // that is subsequently removed from the workspace in startBinding().
689 return !mModel.isLoadingWorkspace();
690 }
691
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 static int getScreen() {
693 synchronized (sLock) {
694 return sScreen;
695 }
696 }
697
698 static void setScreen(int screen) {
699 synchronized (sLock) {
700 sScreen = screen;
701 }
702 }
703
Winson Chung557d6ed2011-07-08 15:34:52 -0700704 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000705 * Copied from View -- the View version of the method isn't called
706 * anywhere else in our process and only exists for API level 17+,
707 * so it's ok to keep our own version with no API requirement.
708 */
709 public static int generateViewId() {
710 for (;;) {
711 final int result = sNextGeneratedId.get();
712 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
713 int newValue = result + 1;
714 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
715 if (sNextGeneratedId.compareAndSet(result, newValue)) {
716 return result;
717 }
718 }
719 }
720
721 public int getViewIdForItem(ItemInfo info) {
722 // This cast is safe given the > 2B range for int.
723 int itemId = (int) info.id;
724 if (mItemIdToViewId.containsKey(itemId)) {
725 return mItemIdToViewId.get(itemId);
726 }
727 int viewId = generateViewId();
728 mItemIdToViewId.put(itemId, viewId);
729 return viewId;
730 }
731
732 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700733 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
734 * a configuration step, this allows the proper animations to run after other transitions.
735 */
736 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700737 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800739 case REQUEST_PICK_SHORTCUT:
740 processShortcut(args.intent);
741 break;
742 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700743 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700744 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700745 result = true;
746 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800747 case REQUEST_CREATE_APPWIDGET:
748 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700749 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700750 result = true;
751 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800752 }
Michael Jurka27614d22012-04-02 06:40:22 -0700753 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
754 // if you turned the screen off and then back while in All Apps, Launcher would not
755 // return to the workspace. Clearing mAddInfo.container here fixes this issue
756 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700757 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800758 }
759
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800760 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700761 protected void onActivityResult(
762 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700763 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700764 setWaitingForResult(false);
Adam Cohen4637b5a2013-11-04 18:21:24 -0800765 int pendingAddWidgetId = mPendingAddWidgetId;
766 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700767
Adam Cohenad4e15c2013-10-17 16:21:35 -0700768 Runnable exitSpringLoaded = new Runnable() {
769 @Override
770 public void run() {
771 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
772 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
773 }
774 };
775
Michael Jurka8b805b12012-04-18 14:23:14 -0700776 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700777 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700778 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
779 if (resultCode == RESULT_CANCELED) {
780 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700781 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700782 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700783 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700784 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
785 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700786 }
787 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200788 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
789 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
790 mWorkspace.exitOverviewMode(false);
791 }
792 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700793 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200794
Adam Cohened66b2b2012-01-23 17:28:51 -0800795 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
796 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700797
Adam Cohened66b2b2012-01-23 17:28:51 -0800798 // We have special handling for widgets
799 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800800 final int appWidgetId;
801 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
802 : -1;
803 if (widgetId < 0) {
804 appWidgetId = pendingAddWidgetId;
805 } else {
806 appWidgetId = widgetId;
807 }
808
Adam Cohenad4e15c2013-10-17 16:21:35 -0700809 final int result;
810 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800811 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700812 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
813 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700814 result = RESULT_CANCELED;
815 completeTwoStageWidgetDrop(result, appWidgetId);
816 onComplete = new Runnable() {
817 @Override
818 public void run() {
819 exitSpringLoadedDragModeDelayed(false, 0, null);
820 }
821 };
Winson Chung5aaab772012-04-27 15:24:02 -0700822 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700823 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700824 final CellLayout dropLayout =
825 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
826 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700827 onComplete = new Runnable() {
828 @Override
829 public void run() {
830 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700831 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700832 }
833 };
Winson Chung5aaab772012-04-27 15:24:02 -0700834 }
Adam Cohen689ff162014-05-08 17:27:56 -0700835 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700836 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800837 return;
838 }
839
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800840 // The pattern used here is that a user PICKs a specific application,
841 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700842
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
844 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700845 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800846 final PendingAddArguments args = new PendingAddArguments();
847 args.requestCode = requestCode;
848 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700849 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700850 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700851 args.cellX = mPendingAddInfo.cellX;
852 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800853 if (isWorkspaceLocked()) {
854 sPendingAddList.add(args);
855 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700856 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 }
Adam Cohen689ff162014-05-08 17:27:56 -0700858 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700859 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Adam Cohen00074722013-10-11 17:46:09 -0700860 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700861 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700862 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800863 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800864 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800865 }
866
867 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700868 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700869 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800870 Runnable onCompleteRunnable = null;
871 int animationType = 0;
872
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700873 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800874 if (resultCode == RESULT_OK) {
875 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
876 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700877 mPendingAddWidgetInfo);
878 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800879 onCompleteRunnable = new Runnable() {
880 @Override
881 public void run() {
882 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700883 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700884 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
885 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800886 }
887 };
888 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800889 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800890 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800891 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700892 if (mDragLayer.getAnimatedView() != null) {
893 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
894 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
895 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700896 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700897 // The animated view may be null in the case of a rotation during widget configuration
898 onCompleteRunnable.run();
899 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800900 }
901
902 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700903 protected void onStop() {
904 super.onStop();
905 FirstFrameAnimatorHelper.setIsVisible(false);
906 }
907
908 @Override
909 protected void onStart() {
910 super.onStart();
911 FirstFrameAnimatorHelper.setIsVisible(true);
912 }
913
914 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800915 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200916 long startTime = 0;
917 if (DEBUG_RESUME_TIME) {
918 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400919 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200920 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800921 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700922
Winson Chung4a2afa32012-07-19 14:53:05 -0700923 // Restore the previous launcher state
924 if (mOnResumeState == State.WORKSPACE) {
925 showWorkspace(false);
926 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800927 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700928 }
929 mOnResumeState = State.NONE;
930
Craig Mautner360310b2012-10-26 15:13:08 -0700931 // Background was set to gradient in onPause(), restore to black if in all apps.
932 setWorkspaceBackground(mState == State.WORKSPACE);
933
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800934 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700935 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700936 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700937 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500938 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400939 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700940 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800941 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700942 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200943 // We might have postponed some bind calls until onResume (see waitUntilResume) --
944 // execute them here
945 long startTimeCallbacks = 0;
946 if (DEBUG_RESUME_TIME) {
947 startTimeCallbacks = System.currentTimeMillis();
948 }
949
950 if (mAppsCustomizeContent != null) {
951 mAppsCustomizeContent.setBulkBind(true);
952 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700953 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
954 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200955 }
956 if (mAppsCustomizeContent != null) {
957 mAppsCustomizeContent.setBulkBind(false);
958 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700959 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200960 if (DEBUG_RESUME_TIME) {
961 Log.d(TAG, "Time spent processing callbacks in onResume: " +
962 (System.currentTimeMillis() - startTimeCallbacks));
963 }
Michael Jurka447bf842013-05-15 14:52:15 +0200964 }
Michael Jurka54554252013-08-01 12:52:23 +0200965 if (mOnResumeCallbacks.size() > 0) {
966 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
967 mOnResumeCallbacks.get(i).run();
968 }
969 mOnResumeCallbacks.clear();
970 }
Winson Chunge4e50662012-01-23 14:45:13 -0800971
972 // Reset the pressed state of icons that were locked in the press state while activities
973 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800974 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800975 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800976 mWaitingForResume.setStayPressed(false);
977 }
Winson Chunge4e50662012-01-23 14:45:13 -0800978 if (mAppsCustomizeContent != null) {
979 // Resets the previous all apps icon press state
980 mAppsCustomizeContent.resetDrawableState();
981 }
Winson Chung82963d52013-10-09 11:20:57 -0700982
Adam Cohen06dff352012-06-01 17:17:08 -0700983 // It is possible that widgets can receive updates while launcher is not in the foreground.
984 // Consequently, the widgets will be inflated in the orientation of the foreground activity
985 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
986 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700987 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700988
Winson Chung780fe592013-09-26 14:48:44 -0700989 // Process any items that were added while Launcher was away.
990 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
991
Winson Chung5841efa2013-09-30 18:06:44 -0700992 // Update the voice search button proxy
993 updateVoiceButtonProxyVisible(false);
994
Adam Cohenf9426d52012-06-04 17:26:21 -0700995 // Again, as with the above scenario, it's possible that one or more of the global icons
996 // were updated in the wrong orientation.
997 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200998 if (DEBUG_RESUME_TIME) {
999 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1000 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001001
1002 if (mWorkspace.getCustomContentCallbacks() != null) {
1003 // If we are resuming and the custom content is the current page, we call onShow().
1004 // It is also poassible that onShow will instead be called slightly after first layout
1005 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1006 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001007 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001008 }
1009 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001010 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001011 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001012 }
1013
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001014 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001015 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001016 // Ensure that items added to Launcher are queued until Launcher returns
1017 InstallShortcutReceiver.enableInstallQueue();
1018
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001019 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001020 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001021 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001022 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001023
1024 // We call onHide() aggressively. The custom content callbacks should be able to
1025 // debounce excess onHide calls.
1026 if (mWorkspace.getCustomContentCallbacks() != null) {
1027 mWorkspace.getCustomContentCallbacks().onHide();
1028 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001029 }
Romain Guycbb89e42009-06-08 15:52:54 -07001030
Adam Cohenbffe7452013-07-22 18:21:45 -07001031 QSBScroller mQsbScroller = new QSBScroller() {
1032 int scrollY = 0;
1033
1034 @Override
1035 public void setScrollY(int scroll) {
1036 scrollY = scroll;
1037
1038 if (mWorkspace.isOnOrMovingToCustomContent()) {
1039 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001040 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001041 }
1042 }
1043 };
1044
1045 public void resetQSBScroll() {
1046 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001047 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001048 }
1049
1050 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001051 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1052 // by a onResume or by scrolling otherwise.
1053 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001054
1055 // Custom content is completely hidden
1056 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001057
1058 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1059 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001060 }
1061
Jorim Jaggid017f882014-01-14 17:08:48 -08001062 protected boolean hasSettings() {
1063 return false;
1064 }
1065
Adam Cohenbffe7452013-07-22 18:21:45 -07001066 public interface QSBScroller {
1067 public void setScrollY(int scrollY);
1068 }
1069
Winson Chung98ca0f72013-07-29 12:58:51 -07001070 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001071 CustomContentCallbacks callbacks, String description) {
1072 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001073 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001074 }
1075
Adam Cohenedb40762013-07-18 16:45:45 -07001076 // The custom content needs to offset its content to account for the QSB
1077 public int getTopOffsetForCustomContent() {
1078 return mWorkspace.getPaddingTop();
1079 }
1080
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001081 @Override
1082 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001083 // Flag the loader to stop early before switching
1084 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001085 if (mAppsCustomizeContent != null) {
1086 mAppsCustomizeContent.surrender();
1087 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001088 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001089 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001090
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001091 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001092 @Override
1093 public void onWindowFocusChanged(boolean hasFocus) {
1094 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001095 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001096 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001097
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001098 private boolean acceptFilter() {
1099 final InputMethodManager inputManager = (InputMethodManager)
1100 getSystemService(Context.INPUT_METHOD_SERVICE);
1101 return !inputManager.isFullscreenMode();
1102 }
1103
1104 @Override
1105 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001106 final int uniChar = event.getUnicodeChar();
1107 final boolean handled = super.onKeyDown(keyCode, event);
1108 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1109 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001110 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1111 keyCode, event);
1112 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001113 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001114 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001115 // showSearchDialog()
1116 // If there are multiple keystrokes before the search dialog takes focus,
1117 // onSearchRequested() will be called for every keystroke,
1118 // but it is idempotent, so it's fine.
1119 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001120 }
1121 }
1122
Joe Onorato8a9625e2010-01-28 15:55:35 -08001123 // Eat the long press event so the keyboard doesn't come up.
1124 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1125 return true;
1126 }
1127
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001128 return handled;
1129 }
1130
Karl Rosaen138a0412009-04-23 19:00:21 -07001131 private String getTypedText() {
1132 return mDefaultKeySsb.toString();
1133 }
1134
1135 private void clearTypedText() {
1136 mDefaultKeySsb.clear();
1137 mDefaultKeySsb.clearSpans();
1138 Selection.setSelection(mDefaultKeySsb, 0);
1139 }
1140
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001141 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001142 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1143 * State
1144 */
1145 private static State intToState(int stateOrdinal) {
1146 State state = State.WORKSPACE;
1147 final State[] stateValues = State.values();
1148 for (int i = 0; i < stateValues.length; i++) {
1149 if (stateValues[i].ordinal() == stateOrdinal) {
1150 state = stateValues[i];
1151 break;
1152 }
1153 }
1154 return state;
1155 }
1156
1157 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001158 * Restores the previous state, if it exists.
1159 *
1160 * @param savedState The previous state.
1161 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001162 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001163 private void restoreState(Bundle savedState) {
1164 if (savedState == null) {
1165 return;
1166 }
1167
Michael Jurka883f55b2010-10-21 15:47:14 -07001168 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001169 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001170 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001171 }
1172
Adam Cohen21cd0022013-10-09 18:57:02 -07001173 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1174 PagedView.INVALID_RESTORE_PAGE);
1175 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001176 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 }
1178
Winson Chung3d503fb2011-07-13 17:25:49 -07001179 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001180 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001181
Winson Chung3d503fb2011-07-13 17:25:49 -07001182 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1183 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001184 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001185 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1186 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001187 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1188 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1189 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001190 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001191 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001192 mRestoring = true;
1193 }
1194
1195 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1196 if (renameFolder) {
1197 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001198 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001199 mRestoring = true;
1200 }
Winson Chunga12a2502010-12-20 14:41:35 -08001201
Winson Chung785d2eb2011-04-14 16:08:02 -07001202 // Restore the AppsCustomize tab
1203 if (mAppsCustomizeTabHost != null) {
1204 String curTab = savedState.getString("apps_customize_currentTab");
1205 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001206 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001207 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001208 mAppsCustomizeContent.loadAssociatedPages(
1209 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001210 }
1211
Winson Chung5afbf7b2011-07-25 11:53:08 -07001212 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1213 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001214 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001215 mItemIdToViewId = (HashMap<Integer, Integer>)
1216 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217 }
1218
1219 /**
1220 * Finds all the views we need and configure them properly.
1221 */
1222 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001223 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001224
Craig Mautner360310b2012-10-26 15:13:08 -07001225 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001226 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1227 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001228 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001229 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001230
John Spurlock77e1f472013-09-11 10:09:51 -04001231 mLauncherView.setSystemUiVisibility(
1232 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001233 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234
Winson Chung4c98d922011-05-31 16:50:48 -07001235 // Setup the drag layer
1236 mDragLayer.setup(this, dragController);
1237
Winson Chung3d503fb2011-07-13 17:25:49 -07001238 // Setup the hotseat
1239 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1240 if (mHotseat != null) {
1241 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001242 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001243 }
1244
Jorim Jaggid017f882014-01-14 17:08:48 -08001245 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001246 View widgetButton = findViewById(R.id.widget_button);
1247 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001248 @Override
1249 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001250 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001251 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001252 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001253 }
1254 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001255 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1256
1257 View wallpaperButton = findViewById(R.id.wallpaper_button);
1258 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001259 @Override
1260 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001261 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001262 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001263 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001264 }
1265 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001266 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1267
1268 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001269 if (hasSettings()) {
1270 settingsButton.setOnClickListener(new OnClickListener() {
1271 @Override
1272 public void onClick(View arg0) {
1273 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001274 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001275 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001276 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001277 });
1278 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1279 } else {
1280 settingsButton.setVisibility(View.GONE);
1281 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1282 lp.gravity = Gravity.END | Gravity.TOP;
1283 widgetButton.requestLayout();
1284 }
1285
Adam Cohendbdff6b2013-09-18 19:09:15 -07001286 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001287
Winson Chung4c98d922011-05-31 16:50:48 -07001288 // Setup the workspace
1289 mWorkspace.setHapticFeedbackEnabled(false);
1290 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001291 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001292 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001293
Winson Chungf0ea4d32011-06-06 14:27:16 -07001294 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001295 mSearchDropTargetBar = (SearchDropTargetBar)
1296 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001297
Winson Chungf0ea4d32011-06-06 14:27:16 -07001298 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001299 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001300 mAppsCustomizeContent = (AppsCustomizePagedView)
1301 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1302 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001303
Winson Chung3d503fb2011-07-13 17:25:49 -07001304 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001305 dragController.setDragScoller(mWorkspace);
1306 dragController.setScrollView(mDragLayer);
1307 dragController.setMoveTarget(mWorkspace);
1308 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001309 if (mSearchDropTargetBar != null) {
1310 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001311 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001312
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001313 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001314 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001315 mWeightWatcher = new WeightWatcher(this);
1316 mWeightWatcher.setAlpha(0.5f);
1317 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001318 new FrameLayout.LayoutParams(
1319 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001320 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001321 Gravity.BOTTOM)
1322 );
Adam Cohen39a06042013-07-19 14:30:12 -07001323
1324 boolean show = shouldShowWeightWatcher();
1325 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001326 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001327 }
1328
1329 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001330 * Sets the all apps button. This method is called from {@link Hotseat}.
1331 */
1332 public void setAllAppsButton(View allAppsButton) {
1333 mAllAppsButton = allAppsButton;
1334 }
1335
1336 public View getAllAppsButton() {
1337 return mAllAppsButton;
1338 }
1339
1340 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001341 * Creates a view representing a shortcut.
1342 *
1343 * @param info The data structure describing the shortcut.
1344 *
1345 * @return A View inflated from R.layout.application.
1346 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001347 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001348 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001349 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 }
1351
1352 /**
1353 * Creates a view representing a shortcut inflated from the specified resource.
1354 *
1355 * @param layoutResId The id of the XML layout used to create the shortcut.
1356 * @param parent The group the shortcut belongs to.
1357 * @param info The data structure describing the shortcut.
1358 *
1359 * @return A View inflated from layoutResId.
1360 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001361 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001362 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1363 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001364 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001365 return favorite;
1366 }
1367
1368 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369 * Add a shortcut to the workspace.
1370 *
1371 * @param data The intent describing the shortcut.
1372 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001373 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001374 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001375 int cellY) {
1376 int[] cellXY = mTmpAddItemCellCoordinates;
1377 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001378 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001379
Michael Jurkad3ef3062010-11-23 16:23:58 -08001380 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001381
Adam Cohen558baaf2011-08-15 15:22:57 -07001382 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001383 if (info == null) {
1384 return;
1385 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001386 final View view = createShortcut(info);
1387
Adam Cohenfbba09b2011-07-18 21:43:05 -07001388 // First we check if we already know the exact location where we want to add this item.
1389 if (cellX >= 0 && cellY >= 0) {
1390 cellXY[0] = cellX;
1391 cellXY[1] = cellY;
1392 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001393
1394 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001395 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001396 true, null,null)) {
1397 return;
1398 }
1399 DragObject dragObject = new DragObject();
1400 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001401 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1402 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001403 return;
1404 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001405 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001406 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001407 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001408 foundCellSpan = (result != null);
1409 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001410 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001411 }
1412
1413 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001414 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001415 return;
1416 }
1417
Adam Cohendcd297f2013-06-18 13:13:40 -07001418 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001419
1420 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001421 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001422 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423 }
1424 }
1425
Adam Cohen2f093b62012-04-30 18:59:53 -07001426 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1427 int minHeight) {
1428 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001429 // We want to account for the extra amount of padding that we are adding to the widget
1430 // to ensure that it gets the full amount of space that it has requested
1431 int requiredWidth = minWidth + padding.left + padding.right;
1432 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001433 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001434 }
1435
Adam Cohen2f093b62012-04-30 18:59:53 -07001436 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1437 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001438 }
1439
Adam Cohen2f093b62012-04-30 18:59:53 -07001440 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1441 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001442 }
1443
Adam Cohen2f093b62012-04-30 18:59:53 -07001444 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1445 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001446 }
1447
Adam Cohen2f093b62012-04-30 18:59:53 -07001448 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1449 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001450 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001451 }
1452
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001454 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001455 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001456 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001457 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001459 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001460 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1461 if (appWidgetInfo == null) {
1462 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1463 }
Romain Guycbb89e42009-06-08 15:52:54 -07001464
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001465 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001466 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001467
Adam Cohen2f093b62012-04-30 18:59:53 -07001468 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1469 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001470
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001472 // We have saved the position to which the widget was dragged-- this really only matters
1473 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001474 int[] cellXY = mTmpAddItemCellCoordinates;
1475 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001476 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001477 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001478 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1479 cellXY[0] = mPendingAddInfo.cellX;
1480 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001481 spanXY[0] = mPendingAddInfo.spanX;
1482 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001483 foundCellSpan = true;
1484 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001485 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001486 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001487 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1488 spanXY[1], cellXY, finalSpan);
1489 spanXY[0] = finalSpan[0];
1490 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001491 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001492 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001493 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001494 }
1495
Michael Jurka0280c3b2010-09-17 15:00:07 -07001496 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001497 if (appWidgetId != -1) {
1498 // Deleting an app widget ID is a void call but writes to disk before returning
1499 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001500 new AsyncTask<Void, Void, Void>() {
1501 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001502 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001503 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001504 }
Michael Jurka43467462013-11-14 12:03:58 +01001505 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001506 }
Winson Chung93eef082012-03-23 15:59:27 -07001507 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001508 return;
1509 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001510
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001511 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001512 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1513 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001514 launcherInfo.spanX = spanXY[0];
1515 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001516 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1517 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001518
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001520 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521
1522 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001523 if (hostView == null) {
1524 // Perform actual inflation because we're live
1525 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1526 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1527 } else {
1528 // The AppWidgetHostView has already been inflated and instantiated
1529 launcherInfo.hostView = hostView;
1530 }
Romain Guycbb89e42009-06-08 15:52:54 -07001531
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001532 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001533 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001534 launcherInfo.notifyWidgetSizeChanged(this);
1535
Adam Cohendcd297f2013-06-18 13:13:40 -07001536 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001537 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001538
1539 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001540 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001541 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 }
Romain Guycbb89e42009-06-08 15:52:54 -07001543
Adam Cohended9f8d2010-11-03 13:25:16 -07001544 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1545 @Override
1546 public void onReceive(Context context, Intent intent) {
1547 final String action = intent.getAction();
1548 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1549 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001550 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001551 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001552
Winson Chungc100e8e2011-08-09 16:02:43 -07001553 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001554 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001555 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001556 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001557 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001558 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1559 mUserPresent = true;
1560 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001561 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1562 mModel.resetLoadedState(false, true);
1563 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1564 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1565 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1566 mModel.resetLoadedState(false, true);
1567 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1568 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1569 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001570 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1571 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1572 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001573 }
1574 }
1575 };
1576
1577 @Override
1578 public void onAttachedToWindow() {
1579 super.onAttachedToWindow();
1580
1581 // Listen for broadcasts related to user-presence
1582 final IntentFilter filter = new IntentFilter();
1583 filter.addAction(Intent.ACTION_SCREEN_OFF);
1584 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001585 // For handling managed profiles
1586 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1587 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001588 if (ENABLE_DEBUG_INTENTS) {
1589 filter.addAction(DebugIntents.DELETE_DATABASE);
1590 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1591 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001592 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001593 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001594 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001595 mVisible = true;
1596 }
1597
1598 @Override
1599 public void onDetachedFromWindow() {
1600 super.onDetachedFromWindow();
1601 mVisible = false;
1602
Adam Cohend113e0c2010-11-11 10:48:05 -08001603 if (mAttached) {
1604 unregisterReceiver(mReceiver);
1605 mAttached = false;
1606 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001607 updateRunning();
1608 }
1609
1610 public void onWindowVisibilityChanged(int visibility) {
1611 mVisible = visibility == View.VISIBLE;
1612 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001613 // The following code used to be in onResume, but it turns out onResume is called when
1614 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1615 // is a more appropriate event to handle
1616 if (mVisible) {
1617 mAppsCustomizeTabHost.onWindowVisible();
1618 if (!mWorkspaceLoading) {
1619 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001620 // We want to let Launcher draw itself at least once before we force it to build
1621 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001622 // apps is nice and speedy.
1623 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001624 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001625 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001626 if (mStarted) return;
1627 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001628 // We delay the layer building a bit in order to give
1629 // other message processing a time to run. In particular
1630 // this avoids a delay in hiding the IME if it was
1631 // currently shown, because doing that may involve
1632 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001633 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001634 final ViewTreeObserver.OnDrawListener listener = this;
1635 mWorkspace.post(new Runnable() {
1636 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001637 if (mWorkspace != null &&
1638 mWorkspace.getViewTreeObserver() != null) {
1639 mWorkspace.getViewTreeObserver().
1640 removeOnDrawListener(listener);
1641 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001642 }
1643 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001644 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001645 }
1646 });
1647 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001648 // When Launcher comes back to foreground, a different Activity might be responsible for
1649 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001650 if (!DISABLE_MARKET_BUTTON) {
1651 updateAppMarketIcon();
1652 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001653 clearTypedText();
1654 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001655 }
1656
1657 private void sendAdvanceMessage(long delay) {
1658 mHandler.removeMessages(ADVANCE_MSG);
1659 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1660 mHandler.sendMessageDelayed(msg, delay);
1661 mAutoAdvanceSentTime = System.currentTimeMillis();
1662 }
1663
1664 private void updateRunning() {
1665 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1666 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1667 mAutoAdvanceRunning = autoAdvanceRunning;
1668 if (autoAdvanceRunning) {
1669 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1670 sendAdvanceMessage(delay);
1671 } else {
1672 if (!mWidgetsToAdvance.isEmpty()) {
1673 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1674 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1675 }
1676 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001677 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001678 }
1679 }
1680 }
1681
1682 private final Handler mHandler = new Handler() {
1683 @Override
1684 public void handleMessage(Message msg) {
1685 if (msg.what == ADVANCE_MSG) {
1686 int i = 0;
1687 for (View key: mWidgetsToAdvance.keySet()) {
1688 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1689 final int delay = mAdvanceStagger * i;
1690 if (v instanceof Advanceable) {
1691 postDelayed(new Runnable() {
1692 public void run() {
1693 ((Advanceable) v).advance();
1694 }
1695 }, delay);
1696 }
1697 i++;
1698 }
1699 sendAdvanceMessage(mAdvanceInterval);
1700 }
1701 }
1702 };
1703
1704 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001705 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001706 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1707 if (v instanceof Advanceable) {
1708 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001709 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001710 updateRunning();
1711 }
1712 }
1713
1714 void removeWidgetToAutoAdvance(View hostView) {
1715 if (mWidgetsToAdvance.containsKey(hostView)) {
1716 mWidgetsToAdvance.remove(hostView);
1717 updateRunning();
1718 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001719 }
1720
Joe Onorato9c1289c2009-08-17 11:03:03 -04001721 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001722 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001723 launcherInfo.hostView = null;
1724 }
1725
Winson Chung93eef082012-03-23 15:59:27 -07001726 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1727 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1728 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001729 }
1730
Winson Chunga6945242014-01-08 14:04:34 -08001731 public DragLayer getDragLayer() {
1732 return mDragLayer;
1733 }
1734
1735 public Workspace getWorkspace() {
1736 return mWorkspace;
1737 }
1738
1739 public Hotseat getHotseat() {
1740 return mHotseat;
1741 }
1742
Jorim Jaggid017f882014-01-14 17:08:48 -08001743 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001744 return mOverviewPanel;
1745 }
1746
1747 public SearchDropTargetBar getSearchBar() {
1748 return mSearchDropTargetBar;
1749 }
1750
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001751 public LauncherAppWidgetHost getAppWidgetHost() {
1752 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001753 }
Romain Guycbb89e42009-06-08 15:52:54 -07001754
Winson Chunga9abd0e2010-10-27 17:18:37 -07001755 public LauncherModel getModel() {
1756 return mModel;
1757 }
1758
Winson Chunga6945242014-01-08 14:04:34 -08001759 public LauncherClings getLauncherClings() {
1760 return mLauncherClings;
1761 }
1762
1763 protected SharedPreferences getSharedPrefs() {
1764 return mSharedPrefs;
1765 }
1766
Bjorn Bringertc459e522013-06-07 19:36:01 +01001767 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001768 getWindow().closeAllPanels();
1769
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001770 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001771 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001772 }
1773
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 @Override
1775 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001776 long startTime = 0;
1777 if (DEBUG_RESUME_TIME) {
1778 startTime = System.currentTimeMillis();
1779 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001780 super.onNewIntent(intent);
1781
1782 // Close the menu
1783 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001784 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001785 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001786
Adam Cohened307df2013-10-02 09:37:31 -07001787 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1788 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1789 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001790
Adam Cohen6fecd412013-10-02 17:41:50 -07001791 if (mWorkspace == null) {
1792 // Can be cases where mWorkspace is null, this prevents a NPE
1793 return;
1794 }
1795 Folder openFolder = mWorkspace.getOpenFolder();
1796 // In all these cases, only animate if we're already on home
1797 mWorkspace.exitWidgetResizeMode();
1798 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001799 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001800 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001801 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001802
Adam Cohen6fecd412013-10-02 17:41:50 -07001803 closeFolder();
1804 exitSpringLoadedDragMode();
1805
1806 // If we are already on home, then just animate back to the workspace,
1807 // otherwise, just wait until onResume to set the state back to Workspace
1808 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001809 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001810 } else {
1811 mOnResumeState = State.WORKSPACE;
1812 }
1813
1814 final View v = getWindow().peekDecorView();
1815 if (v != null && v.getWindowToken() != null) {
1816 InputMethodManager imm = (InputMethodManager)getSystemService(
1817 INPUT_METHOD_SERVICE);
1818 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1819 }
1820
1821 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001822 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001823 mAppsCustomizeTabHost.reset();
1824 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001825
1826 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001827 }
Adam Cohened307df2013-10-02 09:37:31 -07001828
Michael Jurka447bf842013-05-15 14:52:15 +02001829 if (DEBUG_RESUME_TIME) {
1830 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1831 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 }
1833
Adam Coppa120b8e2013-11-12 16:26:04 +00001834 /**
1835 * Override point for subclasses to prevent movement to the default screen when the home
1836 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1837 */
1838 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1839 return true;
1840 }
1841
1842 /**
1843 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1844 */
1845 protected void onHomeIntent() {
1846 // Do nothing
1847 }
1848
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001850 public void onRestoreInstanceState(Bundle state) {
1851 super.onRestoreInstanceState(state);
1852 for (int page: mSynchronouslyBoundPages) {
1853 mWorkspace.restoreInstanceStateForChild(page);
1854 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001855 }
1856
1857 @Override
1858 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001859 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001860 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1861 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001862 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001863 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001864
Michael Jurka883f55b2010-10-21 15:47:14 -07001865 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001866 // We close any open folder since it will not be re-opened, and we need to make sure
1867 // this state is reflected.
1868 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001869
Adam Cohendcd297f2013-06-18 13:13:40 -07001870 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001871 mWaitingForResult) {
1872 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001873 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001874 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1875 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001876 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1877 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1878 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001879 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880 }
1881
1882 if (mFolderInfo != null && mWaitingForResult) {
1883 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1884 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1885 }
Michael Jurka946ad472010-07-09 18:05:18 -07001886
Winson Chung785d2eb2011-04-14 16:08:02 -07001887 // Save the current AppsCustomize tab
1888 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001889 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1890 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001891 if (currentTabTag != null) {
1892 outState.putString("apps_customize_currentTab", currentTabTag);
1893 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001894 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1895 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001896 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001897 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001898 }
1899
1900 @Override
1901 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001902 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001903
Winson Chunge7a03942011-08-05 15:05:12 -07001904 // Remove all pending runnables
1905 mHandler.removeMessages(ADVANCE_MSG);
1906 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001907 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001908
Winson Chungcd2b0142011-06-08 16:02:26 -07001909 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001910 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001911 mModel.stopLoader();
1912 app.setLauncher(null);
1913
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001915 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001916 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001917 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001918 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001919 mAppWidgetHost = null;
1920
1921 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001922
1923 TextKeyListener.getInstance().release();
1924
Winson Chung81b52252012-08-27 15:34:29 -07001925 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1926 // to prevent leaking Launcher activities on orientation change.
1927 if (mModel != null) {
1928 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1929 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001930
1931 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001932 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001933
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001934 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001935 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001936 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001937 mWorkspace = null;
1938 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001939
Michael Jurka2ecf9952012-06-18 12:52:28 -07001940 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 }
1942
Adam Cohena9cf38f2011-05-02 15:36:58 -07001943 public DragController getDragController() {
1944 return mDragController;
1945 }
1946
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 @Override
1948 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001949 if (requestCode >= 0) {
1950 setWaitingForResult(true);
1951 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952 super.startActivityForResult(intent, requestCode);
1953 }
1954
Winson Chung70d72102011-08-12 11:24:35 -07001955 /**
1956 * Indicates that we want global search for this activity by setting the globalSearch
1957 * argument for {@link #startSearch} to true.
1958 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001959 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001960 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001962
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001963 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001964
Karl Rosaen138a0412009-04-23 19:00:21 -07001965 if (initialQuery == null) {
1966 // Use any text typed in the launcher as the initial query
1967 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001968 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 if (appSearchData == null) {
1970 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001971 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972 }
Winson Chungadf0c182012-08-23 14:59:07 -07001973 Rect sourceBounds = new Rect();
1974 if (mSearchDropTargetBar != null) {
1975 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1976 }
Romain Guycbb89e42009-06-08 15:52:54 -07001977
Bjorn Bringertc459e522013-06-07 19:36:01 +01001978 startSearch(initialQuery, selectInitialQuery,
1979 appSearchData, sourceBounds);
1980 }
1981
1982 public void startSearch(String initialQuery,
1983 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001984 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001985 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001986 }
1987
1988 /**
1989 * Starts the global search activity. This code is a copied from SearchManager
1990 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001991 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001992 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001993 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001994 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1995 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1996 if (globalSearchActivity == null) {
1997 Log.w(TAG, "No global search activity found.");
1998 return;
1999 }
2000 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2001 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2002 intent.setComponent(globalSearchActivity);
2003 // Make sure that we have a Bundle to put source in
2004 if (appSearchData == null) {
2005 appSearchData = new Bundle();
2006 } else {
2007 appSearchData = new Bundle(appSearchData);
2008 }
2009 // Set source to package name of app that starts global search, if not set already.
2010 if (!appSearchData.containsKey("source")) {
2011 appSearchData.putString("source", getPackageName());
2012 }
2013 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2014 if (!TextUtils.isEmpty(initialQuery)) {
2015 intent.putExtra(SearchManager.QUERY, initialQuery);
2016 }
2017 if (selectInitialQuery) {
2018 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2019 }
2020 intent.setSourceBounds(sourceBounds);
2021 try {
2022 startActivity(intent);
2023 } catch (ActivityNotFoundException ex) {
2024 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2025 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002026 }
2027
Yura4f93ec62014-02-04 14:15:21 +00002028 public boolean isOnCustomContent() {
2029 return mWorkspace.isOnOrMovingToCustomContent();
2030 }
2031
Winson Chung70d72102011-08-12 11:24:35 -07002032 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002033 public boolean onPrepareOptionsMenu(Menu menu) {
2034 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002035 if (!isOnCustomContent()) {
2036 // Close any open folders
2037 closeFolder();
2038 // Stop resizing any widgets
2039 mWorkspace.exitWidgetResizeMode();
2040 if (!mWorkspace.isInOverviewMode()) {
2041 // Show the overview mode
2042 showOverviewMode(true);
2043 } else {
2044 showWorkspace(true);
2045 }
Winson Chunge0298742014-01-17 12:03:00 -08002046 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002047 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002048 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002050 @Override
2051 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002052 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002053 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002054 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002055 }
2056
Joe Onorato9c1289c2009-08-17 11:03:03 -04002057 public boolean isWorkspaceLocked() {
2058 return mWorkspaceLoading || mWaitingForResult;
2059 }
2060
Adam Cohen517a7f52014-03-01 12:12:59 -08002061 public boolean isWorkspaceLoading() {
2062 return mWorkspaceLoading;
2063 }
2064
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002065 private void setWorkspaceLoading(boolean value) {
2066 boolean isLocked = isWorkspaceLocked();
2067 mWorkspaceLoading = value;
2068 if (isLocked != isWorkspaceLocked()) {
2069 onWorkspaceLockedChanged();
2070 }
2071 }
2072
2073 private void setWaitingForResult(boolean value) {
2074 boolean isLocked = isWorkspaceLocked();
2075 mWaitingForResult = value;
2076 if (isLocked != isWorkspaceLocked()) {
2077 onWorkspaceLockedChanged();
2078 }
2079 }
2080
2081 protected void onWorkspaceLockedChanged() { }
2082
Michael Jurka0280c3b2010-09-17 15:00:07 -07002083 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002084 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002085 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002086 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2087 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002088 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002089 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002090 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002091
Adam Cohenad4e15c2013-10-17 16:21:35 -07002092 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2093 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2094 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2095 }
2096
2097 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2098 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2099 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002100 if (appWidgetInfo.configure != null) {
2101 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002102 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002103
Bjorn Bringert7984c942009-12-09 15:38:25 +00002104 // Launch over to configure widget, if needed
2105 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002106 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002107 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002108 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002109 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002110 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002111 Runnable onComplete = new Runnable() {
2112 @Override
2113 public void run() {
2114 // Exit spring loaded mode if necessary after adding the widget
2115 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2116 null);
2117 }
2118 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002119 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002120 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002121 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002122 }
2123 }
Romain Guycbb89e42009-06-08 15:52:54 -07002124
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002125 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002126 // Close any folders that may be open.
2127 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002128 mWorkspace.moveToCustomContentScreen(animate);
2129 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002130 /**
2131 * Process a shortcut drop.
2132 *
2133 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002134 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002135 * @param cell The cell it should be added to, optional
2136 * @param position The location on the screen where it was dropped, optional
2137 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002138 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002139 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002140 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002141 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002142 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002143 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002144
2145 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002146 mPendingAddInfo.cellX = cell[0];
2147 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002148 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002149
2150 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2151 createShortcutIntent.setComponent(componentName);
2152 processShortcut(createShortcutIntent);
2153 }
2154
Adam Cohenfbba09b2011-07-18 21:43:05 -07002155 /**
2156 * Process a widget drop.
2157 *
2158 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002159 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002160 * @param cell The cell it should be added to, optional
2161 * @param position The location on the screen where it was dropped, optional
2162 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002163 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002164 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002165 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002166 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002167 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002168 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002169 mPendingAddInfo.minSpanX = info.minSpanX;
2170 mPendingAddInfo.minSpanY = info.minSpanY;
2171
Adam Cohenfbba09b2011-07-18 21:43:05 -07002172 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002173 mPendingAddInfo.cellX = cell[0];
2174 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002175 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002176 if (span != null) {
2177 mPendingAddInfo.spanX = span[0];
2178 mPendingAddInfo.spanY = span[1];
2179 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002180
Adam Cohened66b2b2012-01-23 17:28:51 -08002181 AppWidgetHostView hostView = info.boundWidget;
2182 int appWidgetId;
2183 if (hostView != null) {
2184 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002185 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002186 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002187 // In this case, we either need to start an activity to get permission to bind
2188 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002189 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002190 Bundle options = info.bindOptions;
2191
2192 boolean success = false;
2193 if (options != null) {
2194 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2195 info.componentName, options);
2196 } else {
2197 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2198 info.componentName);
2199 }
2200 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002201 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002202 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002203 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002204 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2205 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2206 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002207 // TODO: we need to make sure that this accounts for the options bundle.
2208 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002209 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2210 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002211 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002212 }
2213
Joe Onoratodeb98af2010-02-19 14:59:39 -08002214 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002215 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002216 }
2217
Winson Chung24ab2f12010-09-16 14:10:47 -07002218 void processWallpaper(Intent intent) {
2219 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2220 }
2221
Adam Cohendcd297f2013-06-18 13:13:40 -07002222 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002223 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002224 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002225 folderInfo.title = getText(R.string.folder_name);
2226
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002227 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002228 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002229 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002230 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231
2232 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002233 FolderIcon newFolder =
2234 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002235 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002236 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002237 // Force measure the new folder icon
2238 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2239 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002240 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002241 }
Romain Guycbb89e42009-06-08 15:52:54 -07002242
Joe Onorato9c1289c2009-08-17 11:03:03 -04002243 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002244 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002245 }
2246
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002247 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002248 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002249 }
2250
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002251 /**
2252 * Registers various content observers. The current implementation registers
2253 * only a favorites observer to keep track of the favorites applications.
2254 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002255 private void registerContentObservers() {
2256 ContentResolver resolver = getContentResolver();
2257 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2258 true, mWidgetObserver);
2259 }
2260
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002261 @Override
2262 public boolean dispatchKeyEvent(KeyEvent event) {
2263 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2264 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002265 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002266 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002267 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002268 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002269 dumpState();
2270 return true;
2271 }
2272 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002273 }
2274 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2275 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002276 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002277 return true;
2278 }
2279 }
2280
2281 return super.dispatchKeyEvent(event);
2282 }
2283
Joe Onorato88ec0992009-11-19 13:16:06 -08002284 @Override
2285 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002286 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002287 if (mAppsCustomizeContent.getContentType() ==
2288 AppsCustomizePagedView.ContentType.Applications) {
2289 showWorkspace(true);
2290 } else {
2291 showOverviewMode(true);
2292 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002293 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002294 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002295 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002296 Folder openFolder = mWorkspace.getOpenFolder();
2297 if (openFolder.isEditingName()) {
2298 openFolder.dismissEditingName();
2299 } else {
2300 closeFolder();
2301 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002302 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002303 mWorkspace.exitWidgetResizeMode();
2304
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002305 // Back button is a no-op here, but give at least some feedback for the button press
2306 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002307 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002308 }
2309
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002310 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002311 * Re-listen when widgets are reset.
2312 */
2313 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002314 if (mAppWidgetHost != null) {
2315 mAppWidgetHost.startListening();
2316 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002317 }
2318
2319 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002320 * Launches the intent referred by the clicked shortcut.
2321 *
2322 * @param v The view representing the clicked shortcut.
2323 */
2324 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002325 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2326 // view has detached (it's possible for this to happen if the view is removed mid touch).
2327 if (v.getWindowToken() == null) {
2328 return;
2329 }
2330
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002331 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002332 return;
2333 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002334
Adam Cohen1697b792013-09-17 19:08:21 -07002335 if (v instanceof Workspace) {
2336 if (mWorkspace.isInOverviewMode()) {
2337 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002338 }
2339 return;
2340 }
2341
2342 if (v instanceof CellLayout) {
2343 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002344 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002345 }
2346 }
2347
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002348 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002349 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002350 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002351 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002352 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002353 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002354 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002355 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002356 onClickAllAppsButton(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002357 }
2358 }
2359
Michael Jurka0e260592010-06-30 17:07:39 -07002360 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002361 return false;
2362 }
2363
Michael Jurkaaf442092010-06-10 17:01:57 -07002364 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002365 * Event handler for the search button
2366 *
2367 * @param v The view that was clicked.
2368 */
2369 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002370 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2371
Amith Yamasania135ba82011-08-09 17:42:01 -07002372 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002373 }
2374
2375 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002376 * Event handler for the voice button
2377 *
2378 * @param v The view that was clicked.
2379 */
2380 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002381 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002382
Bjorn Bringertc459e522013-06-07 19:36:01 +01002383 startVoice();
2384 }
2385
2386 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002387 try {
2388 final SearchManager searchManager =
2389 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2390 ComponentName activityName = searchManager.getGlobalSearchActivity();
2391 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002392 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002393 if (activityName != null) {
2394 intent.setPackage(activityName.getPackageName());
2395 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002396 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002397 } catch (ActivityNotFoundException e) {
2398 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002399 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002400 startActivitySafely(null, intent, "onClickVoiceButton");
2401 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002402 }
2403
2404 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002405 * Event handler for the "grid" button that appears on the home screen, which
2406 * enters all apps mode.
2407 *
2408 * @param v The view that was clicked.
2409 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002410 protected void onClickAllAppsButton(View v) {
2411 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2412 if (isAllAppsVisible()) {
2413 showWorkspace(true);
2414 } else {
2415 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2416 }
2417 }
2418
2419 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002420 * Event handler for a paged view icon click.
2421 * @param v The view that was clicked.
2422 * @param appInfo The {link AppInfo} of the view.
2423 */
2424 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2425 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2426 startActivitySafely(v, appInfo.intent, appInfo);
2427 getStats().recordLaunch(appInfo.intent);
2428 }
2429
2430 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002431 * Event handler for an app shortcut click.
2432 *
2433 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2434 */
2435 protected void onClickAppShortcut(View v) {
2436 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2437 Object tag = v.getTag();
2438 if (!(tag instanceof ShortcutInfo)) {
2439 throw new IllegalArgumentException("Input must be a Shortcut");
2440 }
2441
2442 // Open shortcut
2443 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2444 final Intent intent = shortcut.intent;
2445
2446 // Check for special shortcuts
2447 if (intent.getComponent() != null) {
2448 final String shortcutClass = intent.getComponent().getClassName();
2449
2450 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2451 MemoryDumpActivity.startDump(this);
2452 return;
2453 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2454 toggleShowWeightWatcher();
2455 return;
2456 }
2457 }
2458
2459 // Start activities
2460 int[] pos = new int[2];
2461 v.getLocationOnScreen(pos);
2462 intent.setSourceBounds(new Rect(pos[0], pos[1],
2463 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2464
2465 boolean success = startActivitySafely(v, intent, tag);
2466
2467 mStats.recordLaunch(intent, shortcut);
2468
2469 if (success && v instanceof BubbleTextView) {
2470 mWaitingForResume = (BubbleTextView) v;
2471 mWaitingForResume.setStayPressed(true);
2472 }
2473 }
2474
2475 /**
2476 * Event handler for a folder icon click.
2477 *
2478 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2479 */
2480 protected void onClickFolderIcon(View v) {
2481 if (LOGD) Log.d(TAG, "onClickFolder");
2482 if (!(v instanceof FolderIcon)){
2483 throw new IllegalArgumentException("Input must be a FolderIcon");
2484 }
2485
2486 FolderIcon folderIcon = (FolderIcon) v;
2487 final FolderInfo info = folderIcon.getFolderInfo();
2488 Folder openFolder = mWorkspace.getFolderForTag(info);
2489
2490 // If the folder info reports that the associated folder is open, then verify that
2491 // it is actually opened. There have been a few instances where this gets out of sync.
2492 if (info.opened && openFolder == null) {
2493 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2494 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2495 info.opened = false;
2496 }
2497
2498 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2499 // Close any open folder
2500 closeFolder();
2501 // Open the requested folder
2502 openFolder(folderIcon);
2503 } else {
2504 // Find the open folder...
2505 int folderScreen;
2506 if (openFolder != null) {
2507 folderScreen = mWorkspace.getPageForView(openFolder);
2508 // .. and close it
2509 closeFolder(openFolder);
2510 if (folderScreen != mWorkspace.getCurrentPage()) {
2511 // Close any folder open on the current screen
2512 closeFolder();
2513 // Pull the folder onto this screen
2514 openFolder(folderIcon);
2515 }
2516 }
2517 }
Michael Jurka5130e402011-10-13 04:55:35 -07002518 }
2519
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002520 /**
2521 * Event handler for the (Add) Widgets button that appears after a long press
2522 * on the home screen.
2523 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002524 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002525 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002526 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2527 }
2528
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002529 /**
2530 * Event handler for the wallpaper picker button that appears after a long press
2531 * on the home screen.
2532 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002533 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002534 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2535 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2536 pickWallpaper.setComponent(getWallpaperPickerComponent());
2537 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2538 }
2539
2540 /**
2541 * Event handler for a click on the settings button that appears after a long press
2542 * on the home screen.
2543 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002544 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002545 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2546 }
2547
Michael Jurka5130e402011-10-13 04:55:35 -07002548 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002549 // Provide the same haptic feedback that the system offers for virtual keys.
2550 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002551 }
2552
Adam Cohen61f560d2013-09-30 15:58:20 -07002553 public void performHapticFeedbackOnTouchDown(View v) {
2554 // Provide the same haptic feedback that the system offers for virtual keys.
2555 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2556 }
2557
2558 public View.OnTouchListener getHapticFeedbackTouchListener() {
2559 if (mHapticFeedbackTouchListener == null) {
2560 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2561 @Override
2562 public boolean onTouch(View v, MotionEvent event) {
2563 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2564 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2565 }
2566 return false;
2567 }
2568 };
2569 }
2570 return mHapticFeedbackTouchListener;
2571 }
2572
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002573 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002574 if (!DISABLE_MARKET_BUTTON) {
2575 if (mAppMarketIntent != null) {
2576 startActivitySafely(v, mAppMarketIntent, "app market");
2577 } else {
2578 Log.e(TAG, "Invalid app market intent.");
2579 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002580 }
2581 }
2582
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002583 public void onDragStarted(View view) {}
2584
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002585 /**
2586 * Called when the user stops interacting with the launcher.
2587 * This implies that the user is now on the homescreen and is not doing housekeeping.
2588 */
2589 protected void onInteractionEnd() {}
2590
2591 /**
2592 * Called when the user starts interacting with the launcher.
2593 * The possible interactions are:
2594 * - open all apps
2595 * - reorder an app shortcut, or a widget
2596 * - open the overview mode.
2597 * This is a good time to stop doing things that only make sense
2598 * when the user is on the homescreen and not doing housekeeping.
2599 */
2600 protected void onInteractionBegin() {}
2601
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002602 void startApplicationDetailsActivity(ComponentName componentName) {
2603 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002604 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2605 Uri.fromParts("package", packageName, null));
Adrian Roos850f9132014-01-13 17:44:52 -08002606 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |
2607 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002608 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002609 }
2610
Michael Jurka1e2f4652013-07-08 18:03:46 -07002611 // returns true if the activity was started
2612 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002613 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002614 // System applications cannot be installed. For now, show a toast explaining that.
2615 // We may give them the option of disabling apps this way.
2616 int messageId = R.string.uninstall_system_app_text;
2617 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002618 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002619 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002620 String packageName = componentName.getPackageName();
2621 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002622 Intent intent = new Intent(
2623 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002624 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2625 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002626 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002627 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002628 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002629 }
2630
Michael Jurka86a720e2012-05-09 11:23:23 -07002631 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyed131872014-04-30 03:02:21 +01002632 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002633 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002634 // Only launch using the new animation if the shortcut has not opted out (this is a
2635 // private contract between launcher and may be ignored in the future).
2636 boolean useLaunchAnimation = (v != null) &&
2637 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002638 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2639 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002640
Kenny Guy1317e2d2014-05-08 18:52:50 +01002641 UserHandleCompat user = null;
2642 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2643 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2644 user = userManager.getUserForSerialNumber(serialNumber);
2645 }
2646
2647 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002648 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002649 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2650 v.getMeasuredWidth(), v.getMeasuredHeight());
Kenny Guy1317e2d2014-05-08 18:52:50 +01002651 optsBundle = opts.toBundle();
2652 }
2653
2654 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2655 // Could be launching some bookkeeping activity
2656 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002657 } else {
Kenny Guy1317e2d2014-05-08 18:52:50 +01002658 launcherApps.startActivityForProfile(intent.getComponent(),
2659 intent.getSourceBounds(), optsBundle, user);
Winson Chungc7450e32012-04-17 17:34:08 -07002660 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002661 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002662 } catch (SecurityException e) {
2663 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002664 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002665 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002666 "or use the exported attribute for this activity. "
2667 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002668 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002669 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002670 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002671
Michael Jurka86a720e2012-05-09 11:23:23 -07002672 boolean startActivitySafely(View v, Intent intent, Object tag) {
2673 boolean success = false;
2674 try {
2675 success = startActivity(v, intent, tag);
2676 } catch (ActivityNotFoundException e) {
2677 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2678 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2679 }
2680 return success;
2681 }
2682
Adam Cohen268c4752012-06-06 17:47:33 -07002683 /**
2684 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2685 * in the DragLayer in the exact absolute location of the original FolderIcon.
2686 */
2687 private void copyFolderIconToImage(FolderIcon fi) {
2688 final int width = fi.getMeasuredWidth();
2689 final int height = fi.getMeasuredHeight();
2690
2691 // Lazy load ImageView, Bitmap and Canvas
2692 if (mFolderIconImageView == null) {
2693 mFolderIconImageView = new ImageView(this);
2694 }
2695 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2696 mFolderIconBitmap.getHeight() != height) {
2697 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2698 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2699 }
2700
2701 DragLayer.LayoutParams lp;
2702 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2703 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2704 } else {
2705 lp = new DragLayer.LayoutParams(width, height);
2706 }
2707
Adam Cohen307fe232012-08-16 17:55:58 -07002708 // The layout from which the folder is being opened may be scaled, adjust the starting
2709 // view size by this scale factor.
2710 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002711 lp.customPosition = true;
2712 lp.x = mRectForFolderAnimation.left;
2713 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002714 lp.width = (int) (scale * width);
2715 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002716
2717 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2718 fi.draw(mFolderIconCanvas);
2719 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002720 if (fi.getFolder() != null) {
2721 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2722 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002723 }
Adam Cohen268c4752012-06-06 17:47:33 -07002724 // Just in case this image view is still in the drag layer from a previous animation,
2725 // we remove it and re-add it.
2726 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2727 mDragLayer.removeView(mFolderIconImageView);
2728 }
2729 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002730 if (fi.getFolder() != null) {
2731 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002732 }
Adam Cohen268c4752012-06-06 17:47:33 -07002733 }
2734
Adam Cohen2801caf2011-05-13 20:57:39 -07002735 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002736 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002737 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2738 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2739 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2740
Adam Cohenc51934b2011-07-26 21:07:43 -07002741 FolderInfo info = (FolderInfo) fi.getTag();
2742 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2743 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002744 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2745 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002746 }
2747
Adam Cohen268c4752012-06-06 17:47:33 -07002748 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2749 copyFolderIconToImage(fi);
2750 fi.setVisibility(View.INVISIBLE);
2751
Michael Jurka2ecf9952012-06-18 12:52:28 -07002752 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002753 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002754 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2755 oa.start();
2756 }
2757
Adam Cohen268c4752012-06-06 17:47:33 -07002758 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002759 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002760 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2761 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2762 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2763
Adam Cohen268c4752012-06-06 17:47:33 -07002764 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002765
Adam Cohen268c4752012-06-06 17:47:33 -07002766 // We remove and re-draw the FolderIcon in-case it has changed
2767 mDragLayer.removeView(mFolderIconImageView);
2768 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002769 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002770 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002771 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002772 oa.addListener(new AnimatorListenerAdapter() {
2773 @Override
2774 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002775 if (cl != null) {
2776 cl.clearFolderLeaveBehind();
2777 // Remove the ImageView copy of the FolderIcon and make the original visible.
2778 mDragLayer.removeView(mFolderIconImageView);
2779 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002780 }
2781 }
2782 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002783 oa.start();
2784 }
2785
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002786 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002787 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002788 * is animated relative to the specified View. If the View is null, no animation
2789 * is played.
2790 *
2791 * @param folderInfo The FolderInfo describing the folder to open.
2792 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002793 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002794 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002795 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002796
Adam Cohena9cf38f2011-05-02 15:36:58 -07002797 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002798
Adam Cohen4554ee12011-08-03 16:13:21 -07002799 // Just verify that the folder hasn't already been added to the DragLayer.
2800 // There was a one-off crash where the folder had a parent already.
2801 if (folder.getParent() == null) {
2802 mDragLayer.addView(folder);
2803 mDragController.addDropTarget((DropTarget) folder);
2804 } else {
2805 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2806 folder.getParent() + ").");
2807 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002808 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002809 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002810
2811 // Notify the accessibility manager that this folder "window" has appeared and occluded
2812 // the workspace items
2813 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2814 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002815 }
2816
2817 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002818 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002819 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002820 if (folder.isEditingName()) {
2821 folder.dismissEditingName();
2822 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002823 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002824
2825 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002826 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002827 }
2828 }
2829
2830 void closeFolder(Folder folder) {
2831 folder.getInfo().opened = false;
2832
2833 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2834 if (parent != null) {
2835 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2836 shrinkAndFadeInFolderIcon(fi);
2837 }
2838 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002839
2840 // Notify the accessibility manager that this folder "window" has disappeard and no
2841 // longer occludeds the workspace items
2842 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002843 }
2844
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002845 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002846 if (!isDraggingEnabled()) return false;
2847 if (isWorkspaceLocked()) return false;
2848 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002849
Adam Cohen1697b792013-09-17 19:08:21 -07002850 if (v instanceof Workspace) {
2851 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002852 if (mWorkspace.enterOverviewMode()) {
2853 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2854 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2855 return true;
2856 } else {
2857 return false;
2858 }
Adam Cohen1697b792013-09-17 19:08:21 -07002859 }
Adam Cohen1697b792013-09-17 19:08:21 -07002860 }
2861
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002862 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002863 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002864 }
2865
Michael Jurka0280c3b2010-09-17 15:00:07 -07002866 resetAddInfo();
2867 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002868 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002869 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002870 return true;
2871 }
2872
Winson Chung3d503fb2011-07-13 17:25:49 -07002873 // The hotseat touch handling does not go through Workspace, and we always allow long press
2874 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002875 final View itemUnderLongClick = longClickCellInfo.cell;
Dan Sandlere26d0942014-01-13 14:30:14 -05002876 final boolean inHotseat = isHotseatLayout(v);
2877 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07002878 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002879 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002880 // User long pressed on empty space
2881 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2882 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2883 // Disabling reordering until we sort out some issues.
2884 if (mWorkspace.isInOverviewMode()) {
2885 mWorkspace.startReordering(v);
2886 } else {
2887 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002888 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002889 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05002890 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
2891 mHotseat.getOrderInHotseat(
2892 longClickCellInfo.cellX,
2893 longClickCellInfo.cellY));
2894 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002895 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002896 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002897 }
2898 }
2899 }
2900 return true;
2901 }
2902
Winson Chung3d503fb2011-07-13 17:25:49 -07002903 boolean isHotseatLayout(View layout) {
2904 return mHotseat != null && layout != null &&
2905 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2906 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002907
Winson Chung3d503fb2011-07-13 17:25:49 -07002908 /**
2909 * Returns the CellLayout of the specified container at the specified screen.
2910 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002911 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002912 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2913 if (mHotseat != null) {
2914 return mHotseat.getLayout();
2915 } else {
2916 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002917 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002918 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002919 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002920 }
2921 }
2922
Daniel Sandler843e8602010-06-07 14:59:01 -04002923 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002924 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002925 }
2926
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002927 /**
2928 * Helper method for the cameraZoomIn/cameraZoomOut animations
2929 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002930 * @param scaleFactor The scale factor used for the zoom
2931 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002932 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002933 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002934 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002935 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002936
Craig Mautner360310b2012-10-26 15:13:08 -07002937 private void setWorkspaceBackground(boolean workspace) {
2938 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002939 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002940 }
2941
Selim Cinek3a8a8f72014-01-16 10:38:38 -08002942 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002943 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2944 int curflags = getWindow().getAttributes().flags
2945 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2946 if (wpflags != curflags) {
2947 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2948 }
Craig Mautner360310b2012-10-26 15:13:08 -07002949 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002950 }
2951
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002952 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2953 if (v instanceof LauncherTransitionable) {
2954 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2955 }
2956 }
2957
Michael Jurkabed61d22012-02-14 22:51:29 -08002958 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2959 if (v instanceof LauncherTransitionable) {
2960 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2961 }
Winson Chung70442722012-02-10 15:43:22 -08002962
2963 // Update the workspace transition step as well
2964 dispatchOnLauncherTransitionStep(v, 0f);
2965 }
2966
2967 private void dispatchOnLauncherTransitionStep(View v, float t) {
2968 if (v instanceof LauncherTransitionable) {
2969 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2970 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002971 }
2972
2973 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2974 if (v instanceof LauncherTransitionable) {
2975 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2976 }
Winson Chung70442722012-02-10 15:43:22 -08002977
2978 // Update the workspace transition step as well
2979 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002980 }
2981
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002982 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002983 * Things to test when changing the following seven functions.
2984 * - Home from workspace
2985 * - from center screen
2986 * - from other screens
2987 * - Home from all apps
2988 * - from center screen
2989 * - from other screens
2990 * - Back from all apps
2991 * - from center screen
2992 * - from other screens
2993 * - Launch app from workspace and quit
2994 * - with back
2995 * - with home
2996 * - Launch app from all apps and quit
2997 * - with back
2998 * - with home
2999 * - Go to a screen that's not the default, then all
3000 * apps, and launch and app, and go back
3001 * - with back
3002 * -with home
3003 * - On workspace, long press power and go back
3004 * - with back
3005 * - with home
3006 * - On all apps, long press power and go back
3007 * - with back
3008 * - with home
3009 * - On workspace, power off
3010 * - On all apps, power off
3011 * - Launch an app and turn off the screen while in that app
3012 * - Go back with home key
3013 * - Go back with back key TODO: make this not go to workspace
3014 * - From all apps
3015 * - From workspace
3016 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3017 * - From all apps
3018 * - From the center workspace
3019 * - From another workspace
3020 */
3021
3022 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003023 * Zoom the camera out from the workspace to reveal 'toView'.
3024 * Assumes that the view to show is anchored at either the very top or very bottom
3025 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003026 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003027 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003028 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3029 showAppsCustomizeHelper(animated, springLoaded, contentType);
3030 }
3031 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3032 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003033 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003034 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003035 mStateAnimation.cancel();
3036 mStateAnimation = null;
3037 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003038 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003039
Winson Chungf0ea4d32011-06-06 14:27:16 -07003040 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3041 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3042 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003043 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003044 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003045 final int startDelay =
3046 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003047
Michael Jurkab3e22d92011-10-31 15:58:33 -07003048 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003049
Michael Jurkad74c9842011-07-10 12:44:21 -07003050 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003051 Animator workspaceAnim =
3052 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003053 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003054 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3055 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003056 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3057 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003058
3059 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003060 toView.setScaleX(scale);
3061 toView.setScaleY(scale);
3062 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
3063 scaleAnim.
3064 scaleX(1f).scaleY(1f).
3065 setDuration(duration).
3066 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08003067
Winson Chungf0ea4d32011-06-06 14:27:16 -07003068 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08003069 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003070 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003071 .ofFloat(toView, "alpha", 0f, 1f)
3072 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003073 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08003074 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3075 @Override
3076 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07003077 if (animation == null) {
3078 throw new RuntimeException("animation is null");
3079 }
Winson Chung70442722012-02-10 15:43:22 -08003080 float t = (Float) animation.getAnimatedValue();
3081 dispatchOnLauncherTransitionStep(fromView, t);
3082 dispatchOnLauncherTransitionStep(toView, t);
3083 }
3084 });
Adam Cohenf16e5712011-01-13 13:31:45 -08003085
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003086 // toView should appear right at the end of the workspace shrink
3087 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07003088 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003089 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08003090 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003091
3092 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003093 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07003094 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003095 // Prepare the position
3096 toView.setTranslationX(0.0f);
3097 toView.setTranslationY(0.0f);
3098 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003099 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003100 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07003101 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003102 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003103 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3104 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07003105
Winson Chungc7d2b602012-05-16 17:02:20 -07003106 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003107 if (mSearchDropTargetBar != null) {
3108 mSearchDropTargetBar.hideSearchBar(false);
3109 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07003110 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003111 });
3112
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003113 if (workspaceAnim != null) {
3114 mStateAnimation.play(workspaceAnim);
3115 }
Michael Jurka1899a362011-11-03 13:50:45 -07003116
3117 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003118
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003119 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3120 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003121
3122 // If any of the objects being animated haven't been measured/laid out
3123 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003124 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003125 (mWorkspace.getMeasuredWidth() == 0) ||
3126 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003127 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003128 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003129
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003130 final AnimatorSet stateAnimation = mStateAnimation;
3131 final Runnable startAnimRunnable = new Runnable() {
3132 public void run() {
3133 // Check that mStateAnimation hasn't changed while
3134 // we waited for a layout/draw pass
3135 if (mStateAnimation != stateAnimation)
3136 return;
3137 setPivotsForZoom(toView, scale);
3138 dispatchOnLauncherTransitionStart(fromView, animated, false);
3139 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003140 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003141 }
3142 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003143 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003144 final ViewTreeObserver observer = toView.getViewTreeObserver();
3145 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3146 public void onGlobalLayout() {
3147 startAnimRunnable.run();
3148 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3149 }
3150 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003151 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003152 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003153 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003154 } else {
3155 toView.setTranslationX(0.0f);
3156 toView.setTranslationY(0.0f);
3157 toView.setScaleX(1.0f);
3158 toView.setScaleY(1.0f);
3159 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003160 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003161
Daniel Sandlere4f98912013-06-25 15:13:26 -04003162 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003163 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003164 if (mSearchDropTargetBar != null) {
3165 mSearchDropTargetBar.hideSearchBar(false);
3166 }
Michael Jurkaabded662011-03-04 12:06:57 -08003167 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003168 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003169 dispatchOnLauncherTransitionStart(fromView, animated, false);
3170 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003171 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003172 dispatchOnLauncherTransitionStart(toView, animated, false);
3173 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003174 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003175 }
3176
3177 /**
3178 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003179 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003180 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003181 */
Adam Cohened307df2013-10-02 09:37:31 -07003182 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003183 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003184
Michael Jurkab3e22d92011-10-31 15:58:33 -07003185 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003186 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003187 mStateAnimation.cancel();
3188 mStateAnimation = null;
3189 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003190 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003191
Winson Chungf0ea4d32011-06-06 14:27:16 -07003192 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003193 final int fadeOutDuration =
3194 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003195 final float scaleFactor = (float)
3196 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3197 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003198 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003199 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003200 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003201 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3202 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003203 toState, animated, stagger, -1);
3204 } else if (toState == Workspace.State.SPRING_LOADED ||
3205 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003206 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003207 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003208 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003209
Michael Jurkab3e22d92011-10-31 15:58:33 -07003210 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003211 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003212 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003213 final LauncherViewPropertyAnimator scaleAnim =
3214 new LauncherViewPropertyAnimator(fromView);
3215 scaleAnim.
3216 scaleX(scaleFactor).scaleY(scaleFactor).
3217 setDuration(duration).
3218 setInterpolator(new Workspace.ZoomInInterpolator());
3219
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003220 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003221 .ofFloat(fromView, "alpha", 1f, 0f)
3222 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003223 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003224 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3225 @Override
3226 public void onAnimationUpdate(ValueAnimator animation) {
3227 float t = 1f - (Float) animation.getAnimatedValue();
3228 dispatchOnLauncherTransitionStep(fromView, t);
3229 dispatchOnLauncherTransitionStep(toView, t);
3230 }
3231 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003232
Michael Jurka2ecf9952012-06-18 12:52:28 -07003233 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003234
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003235 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3236 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003237 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003238
3239 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003240 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003241 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003242 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003243 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3244 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003245 if (onCompleteRunnable != null) {
3246 onCompleteRunnable.run();
3247 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003248 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003249 }
3250 });
3251
Winson Chungf0ea4d32011-06-06 14:27:16 -07003252 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003253 if (workspaceAnim != null) {
3254 mStateAnimation.play(workspaceAnim);
3255 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003256 dispatchOnLauncherTransitionStart(fromView, animated, true);
3257 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003258 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003259 } else {
3260 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003261 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003262 dispatchOnLauncherTransitionStart(fromView, animated, true);
3263 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003264 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003265 dispatchOnLauncherTransitionStart(toView, animated, true);
3266 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003267 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003268 }
3269
Michael Jurkae326f182011-11-21 14:05:46 -08003270 @Override
3271 public void onTrimMemory(int level) {
3272 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003273 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003274 mAppsCustomizeTabHost.onTrimMemory();
3275 }
3276 }
3277
Adam Cohened307df2013-10-02 09:37:31 -07003278 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003279 showWorkspace(animated, null);
3280 }
3281
Adam Cohened307df2013-10-02 09:37:31 -07003282 protected void showWorkspace() {
3283 showWorkspace(true);
3284 }
3285
Adam Cohened66b2b2012-01-23 17:28:51 -08003286 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003287 if (mWorkspace.isInOverviewMode()) {
3288 mWorkspace.exitOverviewMode(animated);
3289 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003290 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003291 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003292 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003293 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003294
Winson Chungc7d2b602012-05-16 17:02:20 -07003295 // Show the search bar (only animate if we were showing the drop target bar in spring
3296 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003297 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003298 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003299 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003300
Michael Jurkab3e22d92011-10-31 15:58:33 -07003301 // Set focus to the AppsCustomize button
3302 if (mAllAppsButton != null) {
3303 mAllAppsButton.requestFocus();
3304 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003305 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003306
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003307 // Change the state *after* we've called all the transition code
3308 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003309
Winson Chung5fb63472011-02-02 17:03:37 -08003310 // Resume the auto-advance of widgets
3311 mUserPresent = true;
3312 updateRunning();
3313
alanv1d4fde62012-10-17 13:15:47 -07003314 // Send an accessibility event to announce the context change
3315 getWindow().getDecorView()
3316 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003317
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003318 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003319 }
3320
Adam Cohened307df2013-10-02 09:37:31 -07003321 void showOverviewMode(boolean animated) {
3322 mWorkspace.setVisibility(View.VISIBLE);
3323 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3324 mState = State.WORKSPACE;
3325 onWorkspaceShown(animated);
3326 }
3327
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003328 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003329 }
3330
Winson Chung82963d52013-10-09 11:20:57 -07003331 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3332 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003333 if (mState != State.WORKSPACE) return;
3334
Winson Chung82963d52013-10-09 11:20:57 -07003335 if (resetPageToZero) {
3336 mAppsCustomizeTabHost.reset();
3337 }
Winson Chungc58497e2013-09-03 17:48:37 -07003338 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003339 mAppsCustomizeTabHost.requestFocus();
3340
Michael Jurkab3e22d92011-10-31 15:58:33 -07003341 // Change the state *after* we've called all the transition code
3342 mState = State.APPS_CUSTOMIZE;
3343
3344 // Pause the auto-advance of widgets until we are out of AllApps
3345 mUserPresent = false;
3346 updateRunning();
3347 closeFolder();
3348
3349 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003350 getWindow().getDecorView()
3351 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003352 }
3353
Adam Cohen7777d962011-08-18 18:58:38 -07003354 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003355 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003356 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003357 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003358 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003359 }
Adam Cohen7777d962011-08-18 18:58:38 -07003360
Adam Cohenad4e15c2013-10-17 16:21:35 -07003361 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003362 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003363 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3364
Winson Chunge7a03942011-08-05 15:05:12 -07003365 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003366 @Override
3367 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003368 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003369 // Before we show workspace, hide all apps again because
3370 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3371 // clean up our state transition functions
3372 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003373 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003374 } else {
3375 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003376 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003377 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003378 }, delay);
3379
Winson Chung557d6ed2011-07-08 15:34:52 -07003380 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003381
Michael Jurkad3ef3062010-11-23 16:23:58 -08003382 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003383 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003384 final boolean animated = true;
3385 final boolean springLoaded = true;
3386 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003387 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003388 }
3389 // Otherwise, we are not in spring loaded mode, so don't do anything.
3390 }
3391
Michael Jurkab3e22d92011-10-31 15:58:33 -07003392 void lockAllApps() {
3393 // TODO
3394 }
3395
3396 void unlockAllApps() {
3397 // TODO
3398 }
3399
Winson Chungf0ea4d32011-06-06 14:27:16 -07003400 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003401 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003402 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003403 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003404 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003405 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003406 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003407 int duration = 0;
3408 if (mSearchDropTargetBar != null) {
3409 duration = mSearchDropTargetBar.getTransitionInDuration();
3410 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003411 mHotseat.animate().alpha(1f).setDuration(duration);
3412 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003413 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003414 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003415 }
3416 }
3417 }
3418
3419 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003420 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003421 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003422 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003423 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003424 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003425 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003426 int duration = 0;
3427 if (mSearchDropTargetBar != null) {
3428 duration = mSearchDropTargetBar.getTransitionOutDuration();
3429 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003430 mHotseat.animate().alpha(0f).setDuration(duration);
3431 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003432 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003433 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003434 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003435 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003436 }
3437
Patrick Dubroy5f445422011-02-18 14:35:21 -08003438 /**
3439 * Add an item from all apps or customize onto the given workspace screen.
3440 * If layout is null, add to the current screen.
3441 */
3442 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003443 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003444 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003445 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003446 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003447
Winson Chungdff8ebb2011-09-08 17:25:31 -07003448 /** Maps the current orientation to an index for referencing orientation correct global icons */
3449 private int getCurrentOrientationIndexForGlobalIcons() {
3450 // default - 0, landscape - 1
3451 switch (getResources().getConfiguration().orientation) {
3452 case Configuration.ORIENTATION_LANDSCAPE:
3453 return 1;
3454 default:
3455 return 0;
3456 }
3457 }
3458
Michael Jurkaae65ee32012-04-30 11:45:54 -07003459 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003460 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003461 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003462 // Look for the toolbar icon specified in the activity meta-data
3463 Bundle metaData = packageManager.getActivityInfo(
3464 activityName, PackageManager.GET_META_DATA).metaData;
3465 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003466 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003467 if (iconResId != 0) {
3468 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003469 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003470 }
3471 }
3472 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003473 // This can happen if the activity defines an invalid drawable
3474 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3475 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003476 } catch (Resources.NotFoundException nfe) {
3477 // This can happen if the activity defines an invalid drawable
3478 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3479 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003480 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003481 return null;
3482 }
3483
3484 // if successful in getting icon, return it; otherwise, set button to use default drawable
3485 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003486 int buttonId, ComponentName activityName, int fallbackDrawableId,
3487 String toolbarResourceName) {
3488 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003489 Resources r = getResources();
3490 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3491 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003492
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003493 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003494 // If we were unable to find the icon via the meta-data, use a generic one
3495 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003496 toolbarIcon = r.getDrawable(fallbackDrawableId);
3497 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003498 if (button != null) {
3499 button.setCompoundDrawables(toolbarIcon, null, null, null);
3500 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003501 return null;
3502 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003503 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003504 if (button != null) {
3505 button.setCompoundDrawables(toolbarIcon, null, null, null);
3506 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003507 return toolbarIcon.getConstantState();
3508 }
3509 }
3510
3511 // if successful in getting icon, return it; otherwise, set button to use default drawable
3512 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003513 int buttonId, ComponentName activityName, int fallbackDrawableId,
3514 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003515 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003516 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003517
Michael Jurka19e0fc52011-07-22 18:00:21 -07003518 if (button != null) {
3519 // If we were unable to find the icon via the meta-data, use a
3520 // generic one
3521 if (toolbarIcon == null) {
3522 button.setImageResource(fallbackDrawableId);
3523 } else {
3524 button.setImageDrawable(toolbarIcon);
3525 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003526 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003527
3528 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3529
Michael Jurka0423dcf2010-10-05 14:56:18 -07003530 }
3531
Winson Chung1b884092012-06-08 17:13:02 -07003532 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003533 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003534 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003535 }
3536
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003537 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003538 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003539 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003540 }
3541
Winson Chungbb185bd2011-11-21 12:31:42 -08003542 private void invalidatePressedFocusedStates(View container, View button) {
3543 if (container instanceof HolographicLinearLayout) {
3544 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3545 layout.invalidatePressedFocusedStates();
3546 } else if (button instanceof HolographicImageView) {
3547 HolographicImageView view = (HolographicImageView) button;
3548 view.invalidatePressedFocusedStates();
3549 }
3550 }
3551
Cristina Stancu476493b2013-08-07 17:20:14 +01003552 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003553 if (mQsb == null) {
3554 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3555 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003556 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003557 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003558 }
3559
3560 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003561 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003562 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003563 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003564 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003565
Winson Chung1cad91e2011-05-25 17:41:01 -07003566 final SearchManager searchManager =
3567 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3568 ComponentName activityName = searchManager.getGlobalSearchActivity();
3569 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003570 int coi = getCurrentOrientationIndexForGlobalIcons();
3571 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003572 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3573 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3574 if (sGlobalSearchIcon[coi] == null) {
3575 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3576 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3577 TOOLBAR_ICON_METADATA_NAME);
3578 }
3579
Winson Chungc51db6a2011-10-05 11:44:49 -07003580 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3581 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003582 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003583 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003584 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003585 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003586 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3587 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003588 if (searchButton != null) searchButton.setVisibility(View.GONE);
3589 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003590 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003591 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003592 }
3593 }
3594
Cristina Stancu476493b2013-08-07 17:20:14 +01003595 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003596 final View searchButtonContainer = findViewById(R.id.search_button_container);
3597 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003598 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003599 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003600 }
3601
Cristina Stancu476493b2013-08-07 17:20:14 +01003602 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003603 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003604 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003605
Winson Chungc51db6a2011-10-05 11:44:49 -07003606 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003607 final SearchManager searchManager =
3608 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3609 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3610
3611 ComponentName activityName = null;
3612 if (globalSearchActivity != null) {
3613 // Check if the global search activity handles voice search
3614 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3615 intent.setPackage(globalSearchActivity.getPackageName());
3616 activityName = intent.resolveActivity(getPackageManager());
3617 }
3618
3619 if (activityName == null) {
3620 // Fallback: check if an activity other than the global search activity
3621 // resolves this
3622 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3623 activityName = intent.resolveActivity(getPackageManager());
3624 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003625 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003626 int coi = getCurrentOrientationIndexForGlobalIcons();
3627 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003628 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3629 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3630 if (sVoiceSearchIcon[coi] == null) {
3631 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3632 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3633 TOOLBAR_ICON_METADATA_NAME);
3634 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003635 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003636 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003637 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003638 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003639 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003640 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003641 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003642 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003643 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003644 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003645 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003646 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003647
Cristina Stancu476493b2013-08-07 17:20:14 +01003648 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003649 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3650 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003651 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003652 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003653 }
3654
Winson Chung5841efa2013-09-30 18:06:44 -07003655 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003656 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3657 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003658 boolean visible = !forceDisableVoiceButtonProxy &&
3659 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003660 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003661 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003662 }
3663 }
Winson Chung5841efa2013-09-30 18:06:44 -07003664
3665 /**
3666 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3667 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3668 */
3669 public void disableVoiceButtonProxy(boolean disabled) {
3670 updateVoiceButtonProxyVisible(disabled);
3671 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003672 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003673 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003674 */
3675 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003676 if (!DISABLE_MARKET_BUTTON) {
3677 final View marketButton = findViewById(R.id.market_button);
3678 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3679 // Find the app market activity by resolving an intent.
3680 // (If multiple app markets are installed, it will return the ResolverActivity.)
3681 ComponentName activityName = intent.resolveActivity(getPackageManager());
3682 if (activityName != null) {
3683 int coi = getCurrentOrientationIndexForGlobalIcons();
3684 mAppMarketIntent = intent;
3685 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3686 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3687 TOOLBAR_ICON_METADATA_NAME);
3688 marketButton.setVisibility(View.VISIBLE);
3689 } else {
3690 // We should hide and disable the view so that we don't try and restore the visibility
3691 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3692 marketButton.setVisibility(View.GONE);
3693 marketButton.setEnabled(false);
3694 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003695 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003696 }
3697
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003698 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003699 if (!DISABLE_MARKET_BUTTON) {
3700 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3701 Resources r = getResources();
3702 Drawable marketIconDrawable = d.newDrawable(r);
3703 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3704 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3705 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003706
Winson Chungd64a6662013-09-30 11:06:59 -07003707 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3708 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003709 }
3710
Michael Jurkad7c28052012-04-27 15:43:36 -07003711 @Override
3712 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003713 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003714 final List<CharSequence> text = event.getText();
3715 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003716 // Populate event with a fake title based on the current state.
3717 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003718 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003719 } else {
3720 text.add(getString(R.string.all_apps_home_button_label));
3721 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003722 return result;
3723 }
3724
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003725 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003726 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003727 */
3728 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3729 @Override
3730 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003731 closeSystemDialogs();
3732 }
3733 }
3734
3735 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003736 * Receives notifications whenever the appwidgets are reset.
3737 */
3738 private class AppWidgetResetObserver extends ContentObserver {
3739 public AppWidgetResetObserver() {
3740 super(new Handler());
3741 }
3742
3743 @Override
3744 public void onChange(boolean selfChange) {
3745 onAppWidgetReset();
3746 }
3747 }
3748
3749 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003750 * If the activity is currently paused, signal that we need to run the passed Runnable
3751 * in onResume.
3752 *
3753 * This needs to be called from incoming places where resources might have been loaded
3754 * while we are paused. That is becaues the Configuration might be wrong
3755 * when we're not running, and if it comes back to what it was when we
3756 * were paused, we are not restarted.
3757 *
3758 * Implementation of the method from LauncherModel.Callbacks.
3759 *
3760 * @return true if we are currently paused. The caller might be able to
3761 * skip some work in that case since we will come back again.
3762 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003763 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003764 if (mPaused) {
3765 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003766 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003767 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003768 }
3769 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003770 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003771 return true;
3772 } else {
3773 return false;
3774 }
3775 }
3776
Michael Jurkac402cd92013-05-20 15:49:32 +02003777 private boolean waitUntilResume(Runnable run) {
3778 return waitUntilResume(run, false);
3779 }
3780
Michael Jurka1e2f4652013-07-08 18:03:46 -07003781 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003782 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003783 }
3784
Michael Jurka7607c2f2013-04-03 14:33:19 -07003785 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003786 * If the activity is currently paused, signal that we need to re-run the loader
3787 * in onResume.
3788 *
3789 * This needs to be called from incoming places where resources might have been loaded
3790 * while we are paused. That is becaues the Configuration might be wrong
3791 * when we're not running, and if it comes back to what it was when we
3792 * were paused, we are not restarted.
3793 *
3794 * Implementation of the method from LauncherModel.Callbacks.
3795 *
3796 * @return true if we are currently paused. The caller might be able to
3797 * skip some work in that case since we will come back again.
3798 */
3799 public boolean setLoadOnResume() {
3800 if (mPaused) {
3801 Log.i(TAG, "setLoadOnResume");
3802 mOnResumeNeedsLoad = true;
3803 return true;
3804 } else {
3805 return false;
3806 }
3807 }
3808
3809 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003810 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003811 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003812 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003813 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003814 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003815 } else {
3816 return SCREEN_COUNT / 2;
3817 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003818 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003819
Joe Onorato9c1289c2009-08-17 11:03:03 -04003820 /**
3821 * Refreshes the shortcuts shown on the workspace.
3822 *
3823 * Implementation of the method from LauncherModel.Callbacks.
3824 */
3825 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003826 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003827
Michael Jurka7607c2f2013-04-03 14:33:19 -07003828 // If we're starting binding all over again, clear any bind calls we'd postponed in
3829 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3830 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003831 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003832
Winson Chungd64d1762013-08-20 14:37:16 -07003833 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003834 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003835 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003836
Michael Jurka05bf644e2011-11-30 20:28:53 -08003837 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003838 if (mHotseat != null) {
3839 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003840 }
3841 }
3842
Adam Cohendcd297f2013-06-18 13:13:40 -07003843 @Override
3844 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003845 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003846
Adam Cohen5084cba2013-09-03 12:01:16 -07003847 // If there are no screens, we need to have an empty screen
3848 if (orderedScreenIds.size() == 0) {
3849 mWorkspace.addExtraEmptyScreen();
3850 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003851
3852 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003853 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003854 if (hasCustomContentToLeft()) {
3855 mWorkspace.createCustomContentContainer();
3856 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003857 }
Winson Chung64359a52013-07-08 17:17:08 -07003858 }
3859
3860 @Override
3861 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003862 // Log to disk
3863 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3864 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3865 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003866 int count = orderedScreenIds.size();
3867 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003868 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003869 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003870 }
3871
Adam Cohen39a06042013-07-19 14:30:12 -07003872 private boolean shouldShowWeightWatcher() {
3873 String spKey = LauncherAppState.getSharedPreferencesKey();
3874 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003875 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003876
3877 return show;
3878 }
3879
3880 private void toggleShowWeightWatcher() {
3881 String spKey = LauncherAppState.getSharedPreferencesKey();
3882 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3883 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3884
3885 show = !show;
3886
3887 SharedPreferences.Editor editor = sp.edit();
3888 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3889 editor.commit();
3890
3891 if (mWeightWatcher != null) {
3892 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3893 }
3894 }
3895
Winson Chungd64d1762013-08-20 14:37:16 -07003896 public void bindAppsAdded(final ArrayList<Long> newScreens,
3897 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003898 final ArrayList<ItemInfo> addAnimated,
3899 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003900 Runnable r = new Runnable() {
3901 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003902 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003903 }
3904 };
3905 if (waitUntilResume(r)) {
3906 return;
3907 }
3908
Winson Chungd64d1762013-08-20 14:37:16 -07003909 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003910 if (newScreens != null) {
3911 bindAddScreens(newScreens);
3912 }
Winson Chungd64d1762013-08-20 14:37:16 -07003913
3914 // We add the items without animation on non-visible pages, and with
3915 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003916 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003917 bindItems(addNotAnimated, 0,
3918 addNotAnimated.size(), false);
3919 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003920 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003921 bindItems(addAnimated, 0,
3922 addAnimated.size(), true);
3923 }
Winson Chungc58497e2013-09-03 17:48:37 -07003924
Winson Chung87412982013-10-03 18:34:14 -07003925 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003926 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003927
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003928 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07003929 addedApps != null && mAppsCustomizeContent != null) {
3930 mAppsCustomizeContent.addApps(addedApps);
3931 }
Winson Chungd64d1762013-08-20 14:37:16 -07003932 }
3933
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003934 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003935 * Bind the items start-end from the list.
3936 *
3937 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003938 */
Winson Chung64359a52013-07-08 17:17:08 -07003939 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3940 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003941 Runnable r = new Runnable() {
3942 public void run() {
3943 bindItems(shortcuts, start, end, forceAnimateIcons);
3944 }
3945 };
3946 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003947 return;
3948 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003949
Winson Chungf0c6ae02012-03-21 16:10:31 -07003950 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003951 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3952 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003953 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003954 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003955 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003956 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003957 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003958
3959 // Short circuit if we are loading dock items for a configuration which has no dock
3960 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3961 mHotseat == null) {
3962 continue;
3963 }
3964
Joe Onorato9c1289c2009-08-17 11:03:03 -04003965 switch (item.itemType) {
3966 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3967 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003968 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003969 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003970
Winson Chung64359a52013-07-08 17:17:08 -07003971 /*
3972 * TODO: FIX collision case
3973 */
Winson Chungce376632013-07-11 16:12:41 -07003974 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3975 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3976 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003977 View v = cl.getChildAt(item.cellX, item.cellY);
3978 Object tag = v.getTag();
3979 String desc = "Collision while binding workspace item: " + item
3980 + ". Collides with " + tag;
3981 if (LauncherAppState.isDogfoodBuild()) {
3982 throw (new RuntimeException(desc));
3983 } else {
3984 Log.d(TAG, desc);
3985 }
Winson Chungce376632013-07-11 16:12:41 -07003986 }
Winson Chung64359a52013-07-08 17:17:08 -07003987 }
3988
Adam Cohendcd297f2013-06-18 13:13:40 -07003989 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3990 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003991 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003992 // Animate all the applications up now
3993 shortcut.setAlpha(0f);
3994 shortcut.setScaleX(0f);
3995 shortcut.setScaleY(0f);
3996 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003997 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003998 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003999 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004000 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004001 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004002 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004003 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004004 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4005 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004006 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004007 default:
4008 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004009 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004010 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004011
Winson Chung997a9232013-07-24 15:33:46 -07004012 if (animateIcons) {
4013 // Animate to the correct page
4014 if (newShortcutsScreenId > -1) {
4015 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004016 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004017 final Runnable startBounceAnimRunnable = new Runnable() {
4018 public void run() {
4019 anim.playTogether(bounceAnims);
4020 anim.start();
4021 }
4022 };
Winson Chung997a9232013-07-24 15:33:46 -07004023 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004024 // We post the animation slightly delayed to prevent slowdowns
4025 // when we are loading right after we return to launcher.
4026 mWorkspace.postDelayed(new Runnable() {
4027 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004028 if (mWorkspace != null) {
4029 mWorkspace.snapToPage(newScreenIndex);
4030 mWorkspace.postDelayed(startBounceAnimRunnable,
4031 NEW_APPS_ANIMATION_DELAY);
4032 }
Winson Chung94d67682013-09-25 16:29:40 -07004033 }
4034 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004035 } else {
4036 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004037 }
4038 }
Winson Chung64359a52013-07-08 17:17:08 -07004039 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004040 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004041 }
4042
Joe Onorato9c1289c2009-08-17 11:03:03 -04004043 /**
4044 * Implementation of the method from LauncherModel.Callbacks.
4045 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004046 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004047 Runnable r = new Runnable() {
4048 public void run() {
4049 bindFolders(folders);
4050 }
4051 };
4052 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004053 return;
4054 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004055 sFolders.clear();
4056 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004057 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004058
4059 /**
4060 * Add the views for a widget to the workspace.
4061 *
4062 * Implementation of the method from LauncherModel.Callbacks.
4063 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004064 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004065 Runnable r = new Runnable() {
4066 public void run() {
4067 bindAppWidget(item);
4068 }
4069 };
4070 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004071 return;
4072 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004073
Daniel Sandler843e8602010-06-07 14:59:01 -04004074 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4075 if (DEBUG_WIDGETS) {
4076 Log.d(TAG, "bindAppWidget: " + item);
4077 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004078 final Workspace workspace = mWorkspace;
4079
4080 final int appWidgetId = item.appWidgetId;
4081 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04004082 if (DEBUG_WIDGETS) {
4083 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4084 }
4085
Joe Onorato9c1289c2009-08-17 11:03:03 -04004086 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4087
Joe Onorato9c1289c2009-08-17 11:03:03 -04004088 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004089 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004090
Adam Cohendcd297f2013-06-18 13:13:40 -07004091 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004092 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004093 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4094
Joe Onorato9c1289c2009-08-17 11:03:03 -04004095 workspace.requestLayout();
4096
Daniel Sandler843e8602010-06-07 14:59:01 -04004097 if (DEBUG_WIDGETS) {
4098 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4099 + (SystemClock.uptimeMillis()-start) + "ms");
4100 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004101 }
4102
Adam Cohen1462de32012-07-24 22:34:36 -07004103 public void onPageBoundSynchronously(int page) {
4104 mSynchronouslyBoundPages.add(page);
4105 }
4106
Joe Onorato9c1289c2009-08-17 11:03:03 -04004107 /**
4108 * Callback saying that there aren't any more items to bind.
4109 *
4110 * Implementation of the method from LauncherModel.Callbacks.
4111 */
Adam Cohene25af792013-06-06 23:08:25 -07004112 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004113 Runnable r = new Runnable() {
4114 public void run() {
4115 finishBindingItems(upgradePath);
4116 }
4117 };
4118 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004119 return;
4120 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004121 if (mSavedState != null) {
4122 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004123 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004124 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004125 mSavedState = null;
4126 }
4127
Adam Cohen1462de32012-07-24 22:34:36 -07004128 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004129
Patrick Dubroy002cbf42011-03-03 16:36:21 -08004130 // If we received the result of any pending adds while the loader was running (e.g. the
4131 // widget configuration forced an orientation change), process them now.
4132 for (int i = 0; i < sPendingAddList.size(); i++) {
4133 completeAdd(sPendingAddList.get(i));
4134 }
4135 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004136
Winson Chungc51db6a2011-10-05 11:44:49 -07004137 // Update the market app icon as necessary (the other icons will be managed in response to
4138 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004139 if (!DISABLE_MARKET_BUTTON) {
4140 updateAppMarketIcon();
4141 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004142
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004143 setWorkspaceLoading(false);
Adam Cohene25af792013-06-06 23:08:25 -07004144 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004145 mWorkspace.getUniqueComponents(true, null);
4146 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004147 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004148 }
4149
Winson Chunga0b7e862013-09-05 16:03:15 -07004150 public boolean isAllAppsButtonRank(int rank) {
4151 if (mHotseat != null) {
4152 return mHotseat.isAllAppsButtonRank(rank);
4153 }
4154 return false;
4155 }
4156
Winson Chunga2413752012-04-03 14:22:34 -07004157 private boolean canRunNewAppsAnimation() {
4158 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4159 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4160 }
4161
Winson Chungc9168342013-06-26 14:54:55 -07004162 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4163 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4164 PropertyValuesHolder.ofFloat("alpha", 1f),
4165 PropertyValuesHolder.ofFloat("scaleX", 1f),
4166 PropertyValuesHolder.ofFloat("scaleY", 1f));
4167 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4168 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4169 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4170 return bounceAnim;
4171 }
4172
Adam Cohen27772732013-11-11 14:00:56 +00004173 public boolean useVerticalBarLayout() {
4174 return LauncherAppState.getInstance().getDynamicGrid().
4175 getDeviceProfile().isVerticalBarLayout();
4176 }
4177
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004178 protected Rect getSearchBarBounds() {
4179 return LauncherAppState.getInstance().getDynamicGrid().
4180 getDeviceProfile().getSearchBarBounds();
4181 }
4182
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004183 @Override
4184 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004185 boolean searchVisible = updateGlobalSearchIcon();
4186 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004187 if (mSearchDropTargetBar != null) {
4188 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4189 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004190 }
4191
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004192 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004193 * Add the icons for all apps.
4194 *
4195 * Implementation of the method from LauncherModel.Callbacks.
4196 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004197 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004198 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004199 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4200 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4201 getHotseat().addAllAppsFolder(mIconCache, apps,
4202 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4203 }
4204 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004205 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004206 if (mAppsCustomizeContent != null) {
4207 mAppsCustomizeContent.onPackagesUpdated(
4208 LauncherModel.getSortedWidgetsAndShortcuts(this));
4209 }
Winson Chungc58497e2013-09-03 17:48:37 -07004210 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004211 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004212 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004213 mAppsCustomizeContent.onPackagesUpdated(
4214 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004215 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004216 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004217 }
4218
4219 /**
4220 * A package was updated.
4221 *
4222 * Implementation of the method from LauncherModel.Callbacks.
4223 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004224 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004225 Runnable r = new Runnable() {
4226 public void run() {
4227 bindAppsUpdated(apps);
4228 }
4229 };
4230 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004231 return;
4232 }
4233
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004234 if (mWorkspace != null) {
4235 mWorkspace.updateShortcuts(apps);
4236 }
Winson Chungc58497e2013-09-03 17:48:37 -07004237
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004238 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004239 mAppsCustomizeContent != null) {
4240 mAppsCustomizeContent.updateApps(apps);
4241 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004242 }
4243
4244 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004245 * Update the state of a package, typically related to install state.
4246 *
4247 * Implementation of the method from LauncherModel.Callbacks.
4248 */
4249 public void updatePackageState(String pkgName, int state) {
4250 if (mWorkspace != null) {
4251 mWorkspace.updatePackageState(pkgName, state);
4252 }
4253 }
4254
4255 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004256 * A package was uninstalled. We take both the super set of packageNames
4257 * in addition to specific applications to remove, the reason being that
4258 * this can be called when a package is updated as well. In that scenario,
4259 * we only remove specific components from the workspace, where as
4260 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004261 *
4262 * Implementation of the method from LauncherModel.Callbacks.
4263 */
Winson Chung83892cc2013-05-01 16:53:33 -07004264 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004265 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004266 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004267 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004268 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004269 }
Winson Chungd64d1762013-08-20 14:37:16 -07004270 };
4271 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004272 return;
4273 }
4274
Winson Chungdf95eb12013-10-16 14:57:07 -07004275 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004276 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004277 }
4278 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004279 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004280 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004281
Winson Chunga1820962011-10-03 16:31:06 -07004282 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004283 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004284
Winson Chungdf95eb12013-10-16 14:57:07 -07004285 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004286 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004287 mAppsCustomizeContent != null) {
4288 mAppsCustomizeContent.removeApps(appInfos);
4289 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004290 }
Joe Onoratobe386092009-11-17 17:32:16 -08004291
4292 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004293 * A number of packages were updated.
4294 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004295 private ArrayList<Object> mWidgetsAndShortcuts;
4296 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004297 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004298 bindPackagesUpdated(mWidgetsAndShortcuts);
4299 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004300 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004301 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004302 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4303 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4304 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004305 return;
4306 }
4307
Winson Chung64359a52013-07-08 17:17:08 -07004308 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004309 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004310 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004311 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004312 }
4313
Winson Chung400438b2011-01-16 17:53:48 -08004314 private int mapConfigurationOriActivityInfoOri(int configOri) {
4315 final Display d = getWindowManager().getDefaultDisplay();
4316 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4317 switch (d.getRotation()) {
4318 case Surface.ROTATION_0:
4319 case Surface.ROTATION_180:
4320 // We are currently in the same basic orientation as the natural orientation
4321 naturalOri = configOri;
4322 break;
4323 case Surface.ROTATION_90:
4324 case Surface.ROTATION_270:
4325 // We are currently in the other basic orientation to the natural orientation
4326 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4327 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4328 break;
4329 }
4330
4331 int[] oriMap = {
4332 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4333 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4334 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4335 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4336 };
4337 // Since the map starts at portrait, we need to offset if this device's natural orientation
4338 // is landscape.
4339 int indexOffset = 0;
4340 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4341 indexOffset = 1;
4342 }
4343 return oriMap[(d.getRotation() + indexOffset) % 4];
4344 }
Adam Cohen446e9402011-09-15 18:21:21 -07004345
Winson Chung4b919f82012-05-01 10:44:08 -07004346 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004347 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004348 getResources().getBoolean(R.bool.allow_rotation);
4349 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004350 }
Winson Chung4b919f82012-05-01 10:44:08 -07004351 public void lockScreenOrientation() {
4352 if (isRotationEnabled()) {
4353 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4354 .getConfiguration().orientation));
4355 }
4356 }
4357 public void unlockScreenOrientation(boolean immediate) {
4358 if (isRotationEnabled()) {
4359 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004360 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004361 } else {
4362 mHandler.postDelayed(new Runnable() {
4363 public void run() {
4364 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4365 }
4366 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004367 }
Winson Chung4b919f82012-05-01 10:44:08 -07004368 }
Winson Chung400438b2011-01-16 17:53:48 -08004369 }
4370
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004371 /**
4372 * Called when the SearchBar hint should be changed.
4373 *
4374 * @param hint the hint to be displayed in the search bar.
4375 */
4376 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004377 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004378 }
4379
Winson Chunge43a1e72014-01-15 10:33:02 -08004380 protected boolean isLauncherPreinstalled() {
4381 PackageManager pm = getPackageManager();
4382 try {
4383 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4384 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4385 return true;
4386 } else {
4387 return false;
4388 }
4389 } catch (NameNotFoundException e) {
4390 e.printStackTrace();
4391 return false;
4392 }
4393 }
4394
Winson Chunge6eabff2013-09-24 11:01:23 -07004395 protected String getFirstRunClingSearchBarHint() {
4396 return "";
4397 }
4398 protected String getFirstRunCustomContentHint() {
4399 return "";
4400 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004401 protected int getFirstRunFocusedHotseatAppDrawableId() {
4402 return -1;
4403 }
4404 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4405 return null;
4406 }
4407 protected int getFirstRunFocusedHotseatAppRank() {
4408 return -1;
4409 }
4410 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4411 return "";
4412 }
4413 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4414 return "";
4415 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004416
Winson Chungaf40f202013-09-18 18:26:31 -07004417 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004418 mLauncherClings.dismissFirstRunCling(v);
4419 }
4420 public void dismissMigrationClingCopyApps(View v) {
4421 mLauncherClings.dismissMigrationClingCopyApps(v);
4422 }
4423 public void dismissMigrationClingUseDefault(View v) {
4424 mLauncherClings.dismissMigrationClingUseDefault(v);
4425 }
4426 public void dismissMigrationWorkspaceCling(View v) {
4427 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004428 }
Winson Chung82f55532011-08-09 14:14:23 -07004429 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004430 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004431 }
4432 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004433 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004434 }
4435
Adam Cohen432609a2014-03-13 17:03:22 -07004436
4437 /**
4438 * To be overridden by subclasses to indicate that there is an activity to launch
4439 * before showing the standard launcher experience.
4440 */
4441 protected boolean hasFirstRunActivity() {
4442 return false;
4443 }
4444
4445 /**
4446 * To be overridden by subclasses to launch any first run activity
4447 */
4448 protected Intent getFirstRunActivity() {
4449 return null;
4450 }
4451
Winson Chunga6945242014-01-08 14:04:34 -08004452 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004453 return !ActivityManager.isRunningInTestHarness() &&
4454 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004455 }
4456
Adam Cohen4a9423d2014-03-28 14:22:31 -07004457 protected boolean hasRunFirstRunActivity() {
4458 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4459 }
4460
Adam Cohen432609a2014-03-13 17:03:22 -07004461 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004462 if (shouldRunFirstRunActivity() &&
4463 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004464 Intent firstRunIntent = getFirstRunActivity();
4465 if (firstRunIntent != null) {
4466 startActivity(firstRunIntent);
4467 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004468 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004469 }
4470 }
Adam Cohen432609a2014-03-13 17:03:22 -07004471 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004472 }
4473
4474 private void markFirstRunActivityShown() {
4475 SharedPreferences.Editor editor = mSharedPrefs.edit();
4476 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4477 editor.apply();
4478 }
4479
Adam Cohen432609a2014-03-13 17:03:22 -07004480 /**
4481 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4482 * screen that must be displayed and dismissed.
4483 */
4484 protected boolean hasDismissableIntroScreen() {
4485 return false;
4486 }
4487
4488 /**
4489 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4490 */
4491 protected View getIntroScreen() {
4492 return null;
4493 }
4494
4495 /**
4496 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4497 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4498 */
4499 private boolean shouldShowIntroScreen() {
4500 return hasDismissableIntroScreen() &&
4501 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4502 }
4503
4504 protected void showIntroScreen() {
4505 View introScreen = getIntroScreen();
4506 changeWallpaperVisiblity(false);
4507 if (introScreen != null) {
4508 mDragLayer.showOverlayView(introScreen);
4509 }
4510 }
4511
4512 public void dismissIntroScreen() {
4513 markIntroScreenDismissed();
4514 if (showFirstRunActivity()) {
4515 // We delay hiding the intro view until the first run activity is showing. This
4516 // avoids a blip.
4517 mWorkspace.postDelayed(new Runnable() {
4518 @Override
4519 public void run() {
4520 mDragLayer.dismissOverlayView();
4521 }
4522 }, ACTIVITY_START_DELAY);
4523 } else {
4524 mDragLayer.dismissOverlayView();
4525 }
4526 changeWallpaperVisiblity(true);
4527 }
4528
4529 private void markIntroScreenDismissed() {
4530 SharedPreferences.Editor editor = mSharedPrefs.edit();
4531 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4532 editor.apply();
4533 }
4534
Winson Chunga6945242014-01-08 14:04:34 -08004535 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004536 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4537 if (mHotseat != null) mHotseat.setAlpha(1f);
4538 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4539 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004540 }
4541
4542 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004543 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4544 if (mHotseat != null) mHotseat.setAlpha(0f);
4545 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4546 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004547 }
4548
Mathew Inwood72fbec12013-11-19 15:45:07 +00004549 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004550 // Called from search suggestion, not supported in other profiles.
4551 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4552 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4553 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4554 myUser);
4555 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004556 return null;
4557 }
Kenny Guyed131872014-04-30 03:02:21 +01004558 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004559 }
4560
4561 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4562 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004563 // Called from search suggestion, not supported in other profiles.
4564 return createShortcutDragInfo(shortcutIntent, caption, icon,
4565 UserHandleCompat.myUserHandle());
4566 }
4567
4568 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4569 Bitmap icon, UserHandleCompat user) {
4570 return new ShortcutInfo(shortcutIntent, caption, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004571 }
4572
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004573 protected void moveWorkspaceToDefaultScreen() {
4574 mWorkspace.moveToDefaultScreen(false);
4575 }
4576
Mathew Inwood72fbec12013-11-19 15:45:07 +00004577 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4578 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004579 mWorkspace.onExternalDragStartedWithItem(dragView);
4580 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004581 }
4582
Anjali Koppalf5d29132014-02-28 13:33:27 -08004583 @Override
4584 public void onPageSwitch(View newPage, int newPageIndex) {
4585 }
4586
Winson Chung80baf5a2010-08-09 16:03:15 -07004587 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004588 * Prints out out state for debugging.
4589 */
4590 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004591 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004592 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004593 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4594 Log.d(TAG, "mRestoring=" + mRestoring);
4595 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4596 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004597 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004598 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004599
Winson Chung785d2eb2011-04-14 16:08:02 -07004600 if (mAppsCustomizeContent != null) {
4601 mAppsCustomizeContent.dumpState();
4602 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004603 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004604 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004605
4606 @Override
4607 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4608 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004609 synchronized (sDumpLogs) {
4610 writer.println(" ");
4611 writer.println("Debug logs: ");
4612 for (int i = 0; i < sDumpLogs.size(); i++) {
4613 writer.println(" " + sDumpLogs.get(i));
4614 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004615 }
4616 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004617
4618 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004619 if (DEBUG_DUMP_LOG) {
4620 synchronized (sDumpLogs) {
4621 Log.d(TAG, "");
4622 Log.d(TAG, "*********************");
4623 Log.d(TAG, "Launcher debug logs: ");
4624 for (int i = 0; i < sDumpLogs.size(); i++) {
4625 Log.d(TAG, " " + sDumpLogs.get(i));
4626 }
4627 Log.d(TAG, "*********************");
4628 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004629 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004630 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004631 }
4632
4633 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004634 addDumpLog(tag, log, null, debugLog);
4635 }
4636
4637 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004638 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004639 if (e != null) {
4640 Log.d(tag, log, e);
4641 } else {
4642 Log.d(tag, log);
4643 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004644 }
Winson Chungede41292013-09-19 16:27:36 -07004645 if (DEBUG_DUMP_LOG) {
4646 sDateStamp.setTime(System.currentTimeMillis());
4647 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004648 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4649 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004650 }
Winson Chungede41292013-09-19 16:27:36 -07004651 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004652 }
4653
Winson Chungede41292013-09-19 16:27:36 -07004654 public void dumpLogsToLocalData() {
4655 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004656 new AsyncTask<Void, Void, Void>() {
4657 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004658 boolean success = false;
4659 sDateStamp.setTime(sRunStart);
4660 String FILENAME = sDateStamp.getMonth() + "-"
4661 + sDateStamp.getDay() + "_"
4662 + sDateStamp.getHours() + "-"
4663 + sDateStamp.getMinutes() + "_"
4664 + sDateStamp.getSeconds() + ".txt";
4665
4666 FileOutputStream fos = null;
4667 File outFile = null;
4668 try {
4669 outFile = new File(getFilesDir(), FILENAME);
4670 outFile.createNewFile();
4671 fos = new FileOutputStream(outFile);
4672 } catch (Exception e) {
4673 e.printStackTrace();
4674 }
4675 if (fos != null) {
4676 PrintWriter writer = new PrintWriter(fos);
4677
4678 writer.println(" ");
4679 writer.println("Debug logs: ");
4680 synchronized (sDumpLogs) {
4681 for (int i = 0; i < sDumpLogs.size(); i++) {
4682 writer.println(" " + sDumpLogs.get(i));
4683 }
4684 }
4685 writer.close();
4686 }
4687 try {
4688 if (fos != null) {
4689 fos.close();
4690 success = true;
4691 }
4692 } catch (IOException e) {
4693 e.printStackTrace();
4694 }
Michael Jurka43467462013-11-14 12:03:58 +01004695 return null;
Winson Chungede41292013-09-19 16:27:36 -07004696 }
Michael Jurka43467462013-11-14 12:03:58 +01004697 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004698 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004699 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004700}
Michael Jurka2763be32011-02-24 11:19:57 -08004701
Michael Jurkaabded662011-03-04 12:06:57 -08004702interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004703 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004704 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004705 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004706 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004707 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004708}
Dan Sandlerd5024042014-01-09 15:01:33 -05004709
4710interface DebugIntents {
4711 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4712 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004713}