blob: 7fa259da0b53d0fbe5fa2e9c70087fd7489fb03e [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080019import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
20import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Vadim Tryshev6d2321c2018-04-11 17:19:08 -070021
Sunny Goyal4c7f2152017-10-17 17:17:16 -070022import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
Sunny Goyal3e3f44c2017-10-23 17:14:52 -070023import static com.android.launcher3.LauncherState.ALL_APPS;
24import static com.android.launcher3.LauncherState.NORMAL;
Sunny Goyalaeb16432017-10-16 11:46:41 -070025import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
Sunny Goyal326403e2017-10-02 12:45:10 -070026
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.Animator;
Jon Miranda2d89ea82017-05-04 11:47:53 -070028import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070029import android.animation.AnimatorSet;
Jon Miranda2d89ea82017-05-04 11:47:53 -070030import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070031import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000032import android.annotation.TargetApi;
Tony Wickham005df0b2018-02-13 11:28:12 -080033import android.app.ActivityOptions;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080034import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070035import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.Context;
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070040import android.content.ContextWrapper;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070042import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070043import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.content.pm.PackageManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -080046import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070047import android.database.sqlite.SQLiteDatabase;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070048import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020049import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.os.Bundle;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070051import android.os.Parcelable;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080052import android.os.Process;
Winson Chunga2413752012-04-03 14:22:34 -070053import android.os.StrictMode;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070054import android.os.UserHandle;
Tony Wickham86222d22017-03-29 15:30:43 -070055import android.support.annotation.Nullable;
Michael Jurkaa33411c2012-06-14 16:18:21 -070056import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070058import android.util.Log;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070059import android.util.SparseArray;
Adam Cohen96d30a12013-07-16 18:13:21 -070060import android.view.KeyEvent;
Sunny Goyal66b24572016-09-21 15:57:55 -070061import android.view.KeyboardShortcutGroup;
62import android.view.KeyboardShortcutInfo;
Sunny Goyal9b29ca52017-02-17 10:39:44 -080063import android.view.LayoutInflater;
Adam Cohen96d30a12013-07-16 18:13:21 -070064import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070065import android.view.View;
Adam Cohen96d30a12013-07-16 18:13:21 -070066import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080067import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070068import android.view.animation.OvershootInterpolator;
Adam Cohen96d30a12013-07-16 18:13:21 -070069import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070070
Sunny Goyal651077b2014-06-30 14:15:31 -070071import com.android.launcher3.DropTarget.DragObject;
Jon Mirandac476d6e2017-05-04 16:30:01 -070072import com.android.launcher3.Workspace.ItemOperator;
Sunny Goyalae502842016-06-17 08:43:56 -070073import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070074import com.android.launcher3.allapps.AllAppsContainerView;
Hyunyoung Song645764e2016-06-06 14:19:02 -070075import com.android.launcher3.allapps.AllAppsTransitionController;
Sunny Goyal7ede6112017-12-05 15:11:21 -080076import com.android.launcher3.allapps.DiscoveryBounce;
Sunny Goyal0b0847b2018-03-14 12:30:11 -070077import com.android.launcher3.badge.BadgeInfo;
Sunny Goyalffe83f12014-08-14 17:39:34 -070078import com.android.launcher3.compat.AppWidgetManagerCompat;
Sunny Goyal22ca9ec2017-05-18 15:03:13 -070079import com.android.launcher3.compat.LauncherAppsCompatVO;
Tony Wickhame0c33232016-02-08 11:37:04 -080080import com.android.launcher3.config.FeatureFlags;
Vadim Tryshevfedca432015-08-19 17:55:02 -070081import com.android.launcher3.dragndrop.DragController;
82import com.android.launcher3.dragndrop.DragLayer;
83import com.android.launcher3.dragndrop.DragView;
Sunny Goyal26119432016-02-18 22:09:23 +000084import com.android.launcher3.folder.FolderIcon;
Sunny Goyal0b0847b2018-03-14 12:30:11 -070085import com.android.launcher3.folder.FolderIconPreviewVerifier;
Sunny Goyal66b24572016-09-21 15:57:55 -070086import com.android.launcher3.keyboard.CustomActionsPopup;
Sunny Goyal3333b0c2016-05-09 20:43:21 -070087import com.android.launcher3.keyboard.ViewGroupFocusHelper;
Sunny Goyala7ce1662016-05-31 15:01:35 -070088import com.android.launcher3.logging.FileLog;
Hyunyoung Songaa953652016-04-19 18:30:24 -070089import com.android.launcher3.logging.UserEventDispatcher;
Sunny Goyala535ae42017-02-27 10:07:13 -080090import com.android.launcher3.model.ModelWriter;
Sunny Goyala535ae42017-02-27 10:07:13 -080091import com.android.launcher3.notification.NotificationListener;
Tony Wickham540913e2017-01-23 11:47:51 -080092import com.android.launcher3.popup.PopupContainerWithArrow;
Sunny Goyala535ae42017-02-27 10:07:13 -080093import com.android.launcher3.popup.PopupDataProvider;
Tony Wickham1bce7fd2016-04-28 17:39:03 -070094import com.android.launcher3.shortcuts.DeepShortcutManager;
Sunny Goyalf8088ee2017-11-10 14:52:00 -080095import com.android.launcher3.states.InternalStateHandler;
Sunny Goyal623eddd2018-03-02 12:24:41 -080096import com.android.launcher3.states.RotationHelper;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -080097import com.android.launcher3.touch.ItemClickHandler;
Sunny Goyala5ace712017-11-15 17:12:51 -080098import com.android.launcher3.uioverrides.UiFactory;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +053099import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
100import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
Sunny Goyalaeb16432017-10-16 11:46:41 -0700101import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyal2100c782016-08-22 16:00:03 -0700102import com.android.launcher3.util.ActivityResultInfo;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700103import com.android.launcher3.util.ComponentKey;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700104import com.android.launcher3.util.ItemInfoMatcher;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700105import com.android.launcher3.util.MultiHashMap;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700106import com.android.launcher3.util.PackageManagerHelper;
Tony Wickham010d2552017-01-20 08:15:28 -0800107import com.android.launcher3.util.PackageUserKey;
Sunny Goyal2100c782016-08-22 16:00:03 -0700108import com.android.launcher3.util.PendingRequestArgs;
Sunny Goyal8392c822017-06-20 10:03:56 -0700109import com.android.launcher3.util.SystemUiController;
Mario Bertschlera6936942017-05-31 14:48:19 -0700110import com.android.launcher3.util.Themes;
Adam Cohen091440a2015-03-18 14:16:05 -0700111import com.android.launcher3.util.Thunk;
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700112import com.android.launcher3.util.TraceHelper;
Sunny Goyal326403e2017-10-02 12:45:10 -0700113import com.android.launcher3.util.UiThreadHelper;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700114import com.android.launcher3.util.ViewOnDrawExecutor;
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800115import com.android.launcher3.views.OptionsPopupView;
Sunny Goyal29947f02017-12-18 13:49:44 -0800116import com.android.launcher3.widget.LauncherAppWidgetHostView;
Sunny Goyal782f0c92017-01-19 10:27:54 -0800117import com.android.launcher3.widget.PendingAddShortcutInfo;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700118import com.android.launcher3.widget.PendingAddWidgetInfo;
Sunny Goyal29947f02017-12-18 13:49:44 -0800119import com.android.launcher3.widget.PendingAppWidgetHostView;
Sunny Goyal04a324a2017-01-20 21:08:59 -0800120import com.android.launcher3.widget.WidgetAddFlowHandler;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700121import com.android.launcher3.widget.WidgetHostViewLoader;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700122import com.android.launcher3.widget.WidgetListRowEntry;
123import com.android.launcher3.widget.WidgetsFullSheet;
Sunny Goyal952e63d2017-08-16 04:59:08 -0700124import com.android.launcher3.widget.custom.CustomWidgetParser;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700125
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700126import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700127import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700128import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700129import java.util.Collection;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700130import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700131import java.util.List;
Tony Wickham010d2552017-01-20 08:15:28 -0800132import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700133
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134/**
135 * Default launcher application.
136 */
Sunny Goyalab837732018-03-27 17:35:54 -0700137public class Launcher extends BaseDraggingActivity
138 implements LauncherExterns, LauncherModel.Callbacks, LauncherProviderChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700139 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700140 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Winson Chunga2413752012-04-03 14:22:34 -0700142 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700143
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700145 private static final int REQUEST_CREATE_APPWIDGET = 5;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700146
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700147 private static final int REQUEST_PICK_APPWIDGET = 9;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Michael Jurka8b805b12012-04-18 14:23:14 -0700149 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800150 public static final int REQUEST_BIND_PENDING_APPWIDGET = 12;
151 public static final int REQUEST_RECONFIGURE_APPWIDGET = 13;
Michael Jurka8b805b12012-04-18 14:23:14 -0700152
Jon Mirandac476d6e2017-05-04 16:30:01 -0700153 private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
Sunny Goyal28c6b962015-10-12 11:42:05 -0700154
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700155 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
156
Mathew Inwood876a8462013-06-14 14:12:41 +0100157 /**
158 * IntentStarter uses request codes starting with this. This must be greater than all activity
159 * request codes used internally.
160 */
161 protected static final int REQUEST_LAST = 100;
162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 // Type: int
164 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700165 // Type: int
166 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal2100c782016-08-22 16:00:03 -0700167 // Type: PendingRequestArgs
168 private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
169 // Type: ActivityResultInfo
170 private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700171 // Type: SparseArray<Parcelable>
172 private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700174 private LauncherStateManager mStateManager;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700175
Adam Cohenad4e15c2013-10-17 16:21:35 -0700176 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
Winson Chunga2413752012-04-03 14:22:34 -0700178 // How long to wait before the new-shortcut animation automatically pans the workspace
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700179 private static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
180 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
181 @Thunk static final int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700182
Jon Miranda54441f52018-01-24 15:38:25 -0800183 private LauncherAppTransitionManager mAppTransitionManager;
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800184 private Configuration mOldConfig;
Jon Miranda54441f52018-01-24 15:38:25 -0800185
Adam Cohen091440a2015-03-18 14:16:05 -0700186 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700187 private View mLauncherView;
Adam Cohen091440a2015-03-18 14:16:05 -0700188 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800189 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700190
Sunny Goyalffe83f12014-08-14 17:39:34 -0700191 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700192 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700193
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700194 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700195
Sunny Goyal316490e2015-06-02 09:38:28 -0700196 @Thunk Hotseat mHotseat;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700197 private View mDragHandleIndicator;
198 @Nullable private View mHotseatSearchBox;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700199
Sunny Goyal47328fd2016-05-25 18:56:41 -0700200 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700201
202 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700203 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700204 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700205
Winson Chung8ae41982017-11-10 11:42:13 -0800206 // UI and state for the overview panel
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800207 private View mOverviewPanel;
Winson Chung8ae41982017-11-10 11:42:13 -0800208
Vadim Tryshev6d2321c2018-04-11 17:19:08 -0700209 private View mOverviewPanelContainer;
210
Adam Cohen091440a2015-03-18 14:16:05 -0700211 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400212
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700213 private OnResumeCallback mOnResumeCallback;
214
Sunny Goyal527c7d32015-08-28 15:19:36 -0700215 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700216
Joe Onorato9c1289c2009-08-17 11:03:03 -0400217 private LauncherModel mModel;
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800218 private ModelWriter mModelWriter;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800219 private IconCache mIconCache;
Sunny Goyalae502842016-06-17 08:43:56 -0700220 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400221
Jon Miranda2d89ea82017-05-04 11:47:53 -0700222 private ObjectAnimator mScrimAnimator;
Jon Miranda7fda2852017-07-19 16:07:01 -0700223 private boolean mShouldFadeInScrim;
Jon Miranda2d89ea82017-05-04 11:47:53 -0700224
Tony Wickham010d2552017-01-20 08:15:28 -0800225 private PopupDataProvider mPopupDataProvider;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700226
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800227 private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -0700228
Winson Chung46353de2012-02-16 14:05:10 -0800229 // We only want to get the SharedPreferences once since it does an FS stat each time we get
230 // it from the context.
231 private SharedPreferences mSharedPrefs;
232
Sunny Goyal2100c782016-08-22 16:00:03 -0700233 // Activity result which needs to be processed after workspace has loaded.
234 private ActivityResultInfo mPendingActivityResult;
235 /**
236 * Holds extra information required to handle a result from an external call, like
237 * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
238 */
239 private PendingRequestArgs mPendingRequestArgs;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800240
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700241 public ViewGroupFocusHelper mFocusHandler;
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700242 private boolean mAppLaunchSuccess;
243
Sunny Goyal623eddd2018-03-02 12:24:41 -0800244 private RotationHelper mRotationHelper;
Sunny Goyal7779d622015-06-11 16:18:39 -0700245
Winson Chungedb0d6b2018-03-21 17:32:55 -0700246 // Used to keep track of the swipe up state
247 private SharedPreferences.OnSharedPreferenceChangeListener mSharedPrefsListener =
248 (sharedPreferences, s) -> {
249 mDragLayer.setup(mDragController);
250 };
251
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252 @Override
253 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700254 if (DEBUG_STRICT_MODE) {
255 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
256 .detectDiskReads()
257 .detectDiskWrites()
258 .detectNetwork() // or .detectAll() for all detectable problems
259 .penaltyLog()
260 .build());
261 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
262 .detectLeakedSqlLiteObjects()
263 .detectLeakedClosableObjects()
264 .penaltyLog()
265 .penaltyDeath()
266 .build());
267 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700268 TraceHelper.beginSection("Launcher-onCreate");
Winson Chunga2413752012-04-03 14:22:34 -0700269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 super.onCreate(savedInstanceState);
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700271 TraceHelper.partitionSection("Launcher-onCreate", "super call");
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400272
Sunny Goyal87f784c2017-01-11 10:48:34 -0800273 LauncherAppState app = LauncherAppState.getInstance(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800274 mOldConfig = new Configuration(getResources().getConfiguration());
Sunny Goyal0e7724c2018-02-22 13:22:21 -0800275 mModel = app.setLauncher(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800276 initDeviceProfile(app.getInvariantDeviceProfile());
Winson Chung6e1c0d32013-10-25 15:24:24 -0700277
Sunny Goyalf7258242015-10-19 16:59:07 -0700278 mSharedPrefs = Utilities.getPrefs(this);
Winson Chungedb0d6b2018-03-21 17:32:55 -0700279 mSharedPrefs.registerOnSharedPreferenceChangeListener(mSharedPrefsListener);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800280 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700281 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700282
Joe Onorato41a12d22009-10-31 18:30:00 -0400283 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700284 mAllAppsController = new AllAppsTransitionController(this);
Sunny Goyalc4fa8c32017-11-07 12:23:58 -0800285 mStateManager = new LauncherStateManager(this);
Tracy Zhou8b23c6f2018-04-30 17:13:27 -0700286 UiFactory.onCreate(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700287
Sunny Goyalffe83f12014-08-14 17:39:34 -0700288 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700289
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700290 mAppWidgetHost = new LauncherAppWidgetHost(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700291 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700292
Sunny Goyal60820d72017-05-09 12:40:11 -0700293 mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
Michael Jurka7267fa52013-09-26 15:29:57 -0700294
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295 setupViews();
Tony Wickham010d2552017-01-20 08:15:28 -0800296 mPopupDataProvider = new PopupDataProvider(this);
297
Sunny Goyal623eddd2018-03-02 12:24:41 -0800298 mRotationHelper = new RotationHelper(this);
Sunny Goyal90548432018-04-04 17:17:00 -0700299 mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300
Sunny Goyald3864fa2017-11-14 15:06:36 -0800301 boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
302 if (internalStateHandled) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800303 if (savedInstanceState != null) {
304 // InternalStateHandler has already set the appropriate state.
305 // We dont need to do anything.
306 savedInstanceState.remove(RUNTIME_STATE);
307 }
308 }
309 restoreState(savedInstanceState);
Winson Chungb63b44c2017-11-10 17:54:44 -0800310
Sunny Goyal2100c782016-08-22 16:00:03 -0700311 // We only load the page synchronously if the user rotates (or triggers a
312 // configuration change) while launcher is in the foreground
Sunny Goyalfe770c92016-09-27 14:38:58 -0700313 int currentScreen = PagedView.INVALID_RESTORE_PAGE;
314 if (savedInstanceState != null) {
315 currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
316 }
Sunny Goyald3864fa2017-11-14 15:06:36 -0800317
Sunny Goyalfe770c92016-09-27 14:38:58 -0700318 if (!mModel.startLoader(currentScreen)) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800319 if (!internalStateHandled) {
320 // If we are not binding synchronously, show a fade in animation when
321 // the first page bind completes.
322 mDragLayer.setAlpha(0);
323 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700324 } else {
Sunny Goyalfe770c92016-09-27 14:38:58 -0700325 // Pages bound synchronously.
326 mWorkspace.setCurrentPage(currentScreen);
327
Sunny Goyal2100c782016-08-22 16:00:03 -0700328 setWorkspaceLoading(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800329 }
330
331 // For handling default keys
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800332 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800333
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800334 setContentView(mLauncherView);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800335 getRootView().dispatchInsets();
Mario Bertschlera6936942017-05-31 14:48:19 -0700336
Jon Miranda7fda2852017-07-19 16:07:01 -0700337 // Listen for broadcasts
338 IntentFilter filter = new IntentFilter();
339 filter.addAction(Intent.ACTION_SCREEN_OFF);
340 filter.addAction(Intent.ACTION_USER_PRESENT); // When the device wakes up + keyguard is gone
341 registerReceiver(mReceiver, filter);
342 mShouldFadeInScrim = true;
Sunny Goyala616d2b2017-06-12 13:54:01 -0700343
Sunny Goyal8392c822017-06-20 10:03:56 -0700344 getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
345 Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
Sunny Goyal14b32402017-07-31 10:03:28 -0700346
347 if (mLauncherCallbacks != null) {
348 mLauncherCallbacks.onCreate(savedInstanceState);
349 }
Sunny Goyal623eddd2018-03-02 12:24:41 -0800350 mRotationHelper.initialize();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700351
352 TraceHelper.endSection("Launcher-onCreate");
Adam Cohen9211d422014-10-07 18:14:53 -0700353 }
354
Sunny Goyal7779d622015-06-11 16:18:39 -0700355 @Override
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800356 public void onConfigurationChanged(Configuration newConfig) {
357 int diff = newConfig.diff(mOldConfig);
358 if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
359 mUserEventDispatcher = null;
360 initDeviceProfile(mDeviceProfile.inv);
Sunny Goyalfde55052018-02-01 14:46:13 -0800361 dispatchDeviceProfileChanged();
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800362
363 getRootView().dispatchInsets();
Sunny Goyaled2d2bc2018-04-19 12:34:43 -0700364 getStateManager().reapplyState(true /* cancelCurrentAnimation */);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800365
Sunny Goyal7185dd62018-03-14 17:51:49 -0700366 // Recreate touch controllers
367 mDragLayer.setup(mDragController);
368
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800369 // TODO: We can probably avoid rebind when only screen size changed.
Sunny Goyal605bcf32018-03-02 15:16:12 -0800370 rebindModel();
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800371 }
372
373 mOldConfig.setTo(newConfig);
Tracy Zhoua706f002018-03-28 13:55:19 -0700374 UiFactory.onLauncherStateOrResumeChanged(this);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800375 super.onConfigurationChanged(newConfig);
376 }
377
Sunny Goyal605bcf32018-03-02 15:16:12 -0800378 @Override
379 public void rebindModel() {
380 int currentPage = mWorkspace.getNextPage();
381 if (mModel.startLoader(currentPage)) {
382 mWorkspace.setCurrentPage(currentPage);
383 setWorkspaceLoading(true);
384 }
385 }
386
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800387 private void initDeviceProfile(InvariantDeviceProfile idp) {
388 // Load configuration-specific DeviceProfile
Sunny Goyalf633ef52018-03-13 09:57:05 -0700389 setDeviceProfile(idp.getDeviceProfile(this));
Sunny Goyal605bcf32018-03-02 15:16:12 -0800390 mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout(), true);
Sunny Goyalf8d56fc2018-01-31 15:18:11 -0800391 }
392
Sunny Goyal623eddd2018-03-02 12:24:41 -0800393 public RotationHelper getRotationHelper() {
394 return mRotationHelper;
395 }
396
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700397 public LauncherStateManager getStateManager() {
398 return mStateManager;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700399 }
400
Mario Bertschler27288382017-05-24 15:35:09 -0700401 @Override
Sunny Goyalc7b8df82017-06-27 11:11:03 -0700402 public <T extends View> T findViewById(int id) {
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800403 return mLauncherView.findViewById(id);
404 }
405
406 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700407 public void onAppWidgetHostReset() {
408 if (mAppWidgetHost != null) {
409 mAppWidgetHost.startListening();
410 }
411 }
412
Adam Cohen9211d422014-10-07 18:14:53 -0700413 private LauncherCallbacks mLauncherCallbacks;
414
Sunny Goyal32554d12015-12-03 15:31:25 -0800415 /**
416 * Call this after onCreate to set or clear overlay.
417 */
418 public void setLauncherOverlay(LauncherOverlay overlay) {
419 if (overlay != null) {
420 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
421 }
422 mWorkspace.setLauncherOverlay(overlay);
423 }
424
Adam Cohen9211d422014-10-07 18:14:53 -0700425 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
426 mLauncherCallbacks = callbacks;
427 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700428 }
429
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700430 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700431 public void onLauncherProviderChanged() {
Adam Cohen9211d422014-10-07 18:14:53 -0700432 if (mLauncherCallbacks != null) {
433 mLauncherCallbacks.onLauncherProviderChange();
434 }
435 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700436
Hyunyoung Song3f471442015-04-08 19:01:34 -0700437 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700438 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
439 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700440 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700441 }
442
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000443 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700444 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
445 // This cast is safe as long as the id < 0x00FFFFFF
446 // Since we jail all the dynamically generated views, there should be no clashes
447 // with any other views.
448 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000449 }
450
Tony Wickham010d2552017-01-20 08:15:28 -0800451 public PopupDataProvider getPopupDataProvider() {
452 return mPopupDataProvider;
453 }
454
Sunny Goyal0b0847b2018-03-14 12:30:11 -0700455 @Override
456 public BadgeInfo getBadgeInfoForItem(ItemInfo info) {
457 return mPopupDataProvider.getBadgeInfoForItem(info);
458 }
459
460 @Override
461 public void invalidateParent(ItemInfo info) {
462 FolderIconPreviewVerifier verifier = new FolderIconPreviewVerifier(getDeviceProfile().inv);
463 if (verifier.isItemInPreview(info.rank) && (info.container >= 0)) {
464 View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container);
465 if (folderIcon != null) {
466 folderIcon.invalidate();
467 }
468 }
469 }
470
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000471 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700472 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
473 * a configuration step, this allows the proper animations to run after other transitions.
474 */
Sunny Goyal2100c782016-08-22 16:00:03 -0700475 private long completeAdd(
476 int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
477 long screenId = info.screenId;
478 if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Adam Cohen83079e42014-09-19 17:43:08 -0700479 // When the screen id represents an actual screen (as opposed to a rank) we make sure
480 // that the drop page actually exists.
Sunny Goyal2100c782016-08-22 16:00:03 -0700481 screenId = ensurePendingDropLayoutExists(info.screenId);
Adam Cohen83079e42014-09-19 17:43:08 -0700482 }
Adam Cohendb364c32014-05-20 14:23:40 -0700483
Sunny Goyal2100c782016-08-22 16:00:03 -0700484 switch (requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800485 case REQUEST_CREATE_SHORTCUT:
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700486 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
Winson Chungb8472bb2011-08-05 13:49:21 -0700487 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800488 case REQUEST_CREATE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700489 completeAddAppWidget(appWidgetId, info, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700490 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700491 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700492 completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700493 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700494 case REQUEST_BIND_PENDING_APPWIDGET: {
Sunny Goyal2100c782016-08-22 16:00:03 -0700495 int widgetId = appWidgetId;
496 LauncherAppWidgetInfo widgetInfo =
Sunny Goyald478c832016-04-01 12:04:16 -0700497 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
Sunny Goyal2100c782016-08-22 16:00:03 -0700498 if (widgetInfo != null) {
Sunny Goyald478c832016-04-01 12:04:16 -0700499 // Since the view was just bound, also launch the configure activity if needed
500 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
501 .getLauncherAppWidgetInfo(widgetId);
Sunny Goyal04a324a2017-01-20 21:08:59 -0800502 if (provider != null) {
503 new WidgetAddFlowHandler(provider)
504 .startConfigActivity(this, widgetInfo, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -0700505 }
506 }
507 break;
508 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800509 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700510
Adam Cohendb364c32014-05-20 14:23:40 -0700511 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800512 }
513
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800514 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700515 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700516 if (isWorkspaceLoading()) {
517 // process the result once the workspace has loaded.
518 mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
519 return;
520 }
521 mPendingActivityResult = null;
522
Winson Chunge341d302013-08-16 14:31:00 -0700523 // Reset the startActivity waiting flag
Sunny Goyal2100c782016-08-22 16:00:03 -0700524 final PendingRequestArgs requestArgs = mPendingRequestArgs;
525 setWaitingForResult(null);
526 if (requestArgs == null) {
527 return;
528 }
529
530 final int pendingAddWidgetId = requestArgs.getWidgetId();
Winson Chunge341d302013-08-16 14:31:00 -0700531
Adam Cohenad4e15c2013-10-17 16:21:35 -0700532 Runnable exitSpringLoaded = new Runnable() {
533 @Override
534 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700535 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700536 }
537 };
538
Michael Jurka8b805b12012-04-18 14:23:14 -0700539 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700540 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700541 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700542 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
543 if (resultCode == RESULT_CANCELED) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700544 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
Adam Cohen689ff162014-05-08 17:27:56 -0700545 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700546 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700547 } else if (resultCode == RESULT_OK) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700548 addAppWidgetImpl(
549 appWidgetId, requestArgs, null,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800550 requestArgs.getWidgetHandler(),
Sunny Goyal2100c782016-08-22 16:00:03 -0700551 ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700552 }
553 return;
554 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200555
Adam Cohened66b2b2012-01-23 17:28:51 -0800556 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700557 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700558
Adam Cohened66b2b2012-01-23 17:28:51 -0800559 // We have special handling for widgets
560 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800561 final int appWidgetId;
562 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
563 : -1;
564 if (widgetId < 0) {
565 appWidgetId = pendingAddWidgetId;
566 } else {
567 appWidgetId = widgetId;
568 }
569
Adam Cohenad4e15c2013-10-17 16:21:35 -0700570 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800571 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700572 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
573 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700574 result = RESULT_CANCELED;
Sunny Goyal2100c782016-08-22 16:00:03 -0700575 completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
Adam Cohendb364c32014-05-20 14:23:40 -0700576 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700577 @Override
578 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700579 getStateManager().goToState(NORMAL);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700580 }
581 };
Adam Cohendb364c32014-05-20 14:23:40 -0700582
Sunny Goyal2100c782016-08-22 16:00:03 -0700583 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
584 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
585 } else {
586 if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
587 // When the screen id represents an actual screen (as opposed to a rank)
588 // we make sure that the drop page actually exists.
589 requestArgs.screenId =
590 ensurePendingDropLayoutExists(requestArgs.screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700591 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700592 final CellLayout dropLayout =
593 mWorkspace.getScreenWithId(requestArgs.screenId);
594
595 dropLayout.setDropPending(true);
596 final Runnable onComplete = new Runnable() {
597 @Override
598 public void run() {
599 completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
600 dropLayout.setDropPending(false);
601 }
602 };
603 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
604 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Winson Chung5aaab772012-04-27 15:24:02 -0700605 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800606 return;
607 }
608
Sunny Goyald478c832016-04-01 12:04:16 -0700609 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
610 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700611 if (resultCode == RESULT_OK) {
612 // Update the widget view.
Sunny Goyal2100c782016-08-22 16:00:03 -0700613 completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
Sunny Goyalff572272014-07-23 13:58:07 -0700614 }
615 // Leave the widget in the pending state if the user canceled the configure.
616 return;
617 }
618
Sunny Goyalaad90582015-07-09 14:22:50 -0700619 if (requestCode == REQUEST_CREATE_SHORTCUT) {
620 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
Sunny Goyal2100c782016-08-22 16:00:03 -0700621 if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
622 completeAdd(requestCode, data, -1, requestArgs);
623 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
624 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
625
Sunny Goyalaad90582015-07-09 14:22:50 -0700626 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700627 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
628 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800629 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800631 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800632 }
633
634 @Override
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700635 public void onActivityResult(
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800636 final int requestCode, final int resultCode, final Intent data) {
637 handleActivityResult(requestCode, resultCode, data);
638 if (mLauncherCallbacks != null) {
639 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
640 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800641 }
642
Sunny Goyal7ce471b2017-08-02 03:37:39 -0700643 @Override
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700644 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600645 int[] grantResults) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700646 PendingRequestArgs pendingArgs = mPendingRequestArgs;
647 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null
648 && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
649 setWaitingForResult(null);
650
Sunny Goyal28c6b962015-10-12 11:42:05 -0700651 View v = null;
Sunny Goyal2100c782016-08-22 16:00:03 -0700652 CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700653 if (layout != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700654 v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700655 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700656 Intent intent = pendingArgs.getPendingIntent();
657
Sunny Goyal28c6b962015-10-12 11:42:05 -0700658 if (grantResults.length > 0
659 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal85fc55a2016-05-31 10:44:03 -0700660 startActivitySafely(v, intent, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700661 } else {
662 // TODO: Show a snack bar with link to settings
663 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
Sunny Goyal112ce422016-08-22 16:45:29 -0700664 getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
Sunny Goyal28c6b962015-10-12 11:42:05 -0700665 }
666 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600667 if (mLauncherCallbacks != null) {
668 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
669 grantResults);
670 }
671 }
672
Adam Cohendb364c32014-05-20 14:23:40 -0700673 /**
674 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
675 *
676 * @param screenId the screen id to check
677 * @return the new screen, or screenId if it exists
678 */
679 private long ensurePendingDropLayoutExists(long screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800680 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700681 if (dropLayout == null) {
682 // it's possible that the add screen was removed because it was
683 // empty and a re-bind occurred
684 mWorkspace.addExtraEmptyScreen();
685 return mWorkspace.commitExtraEmptyScreen();
686 } else {
687 return screenId;
688 }
689 }
690
Sunny Goyal2100c782016-08-22 16:00:03 -0700691 @Thunk void completeTwoStageWidgetDrop(
692 final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
693 CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800694 Runnable onCompleteRunnable = null;
695 int animationType = 0;
696
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700697 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800698 if (resultCode == RESULT_OK) {
699 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
700 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800701 requestArgs.getWidgetHandler().getProviderInfo(this));
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700702 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800703 onCompleteRunnable = new Runnable() {
704 @Override
705 public void run() {
Sunny Goyal2100c782016-08-22 16:00:03 -0700706 completeAddAppWidget(appWidgetId, requestArgs, layout, null);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700707 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohened66b2b2012-01-23 17:28:51 -0800708 }
709 };
710 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800711 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800712 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800713 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700714 if (mDragLayer.getAnimatedView() != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700715 mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700716 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
717 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700718 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700719 // The animated view may be null in the case of a rotation during widget configuration
720 onCompleteRunnable.run();
721 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800722 }
723
724 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700725 protected void onStop() {
726 super.onStop();
727 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700728
729 if (mLauncherCallbacks != null) {
730 mLauncherCallbacks.onStop();
731 }
Sunny Goyal67419a12017-11-14 16:55:22 -0800732 mAppWidgetHost.setListenIfResumed(false);
Tony Wickham010d2552017-01-20 08:15:28 -0800733
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700734 if (!mAppLaunchSuccess) {
735 getUserEventDispatcher().logActionCommand(Action.Command.STOP,
Hyunyoung Songb3fbc0b2018-02-14 13:40:25 -0800736 mStateManager.getState().containerType, -1);
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700737 }
Tony Wickham010d2552017-01-20 08:15:28 -0800738 NotificationListener.removeNotificationsChangedListener();
Sunny Goyalaf161fd2018-02-05 16:34:57 -0800739 getStateManager().moveToRestState();
Winson Chungedb0d6b2018-03-21 17:32:55 -0700740
Winson Chungdea51352018-04-24 13:02:10 -0700741 // Workaround for b/78520668, explicitly trim memory once UI is hidden
742 UiFactory.onTrimMemory(this, TRIM_MEMORY_UI_HIDDEN);
Michael Jurkacd496d72013-04-11 11:32:45 -0700743 }
744
745 @Override
746 protected void onStart() {
747 super.onStart();
748 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700749
750 if (mLauncherCallbacks != null) {
751 mLauncherCallbacks.onStart();
752 }
Sunny Goyal67419a12017-11-14 16:55:22 -0800753 mAppWidgetHost.setListenIfResumed(true);
Sunny Goyalcac002d2018-01-04 09:51:45 -0800754 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
Jon Miranda2d89ea82017-05-04 11:47:53 -0700755
Jon Mirandade43a712018-01-18 11:35:10 -0800756 if (mShouldFadeInScrim && mLauncherView.getBackground() != null) {
Jon Miranda2d89ea82017-05-04 11:47:53 -0700757 if (mScrimAnimator != null) {
758 mScrimAnimator.cancel();
759 }
Jon Mirandade43a712018-01-18 11:35:10 -0800760 mLauncherView.getBackground().setAlpha(0);
761 mScrimAnimator = ObjectAnimator.ofInt(mLauncherView.getBackground(),
Jon Miranda2d89ea82017-05-04 11:47:53 -0700762 LauncherAnimUtils.DRAWABLE_ALPHA, 0, 255);
763 mScrimAnimator.addListener(new AnimatorListenerAdapter() {
764 @Override
765 public void onAnimationEnd(Animator animation) {
766 mScrimAnimator = null;
767 }
768 });
769 mScrimAnimator.setDuration(600);
770 mScrimAnimator.setStartDelay(getWindow().getTransitionBackgroundFadeDuration());
771 mScrimAnimator.start();
772 }
Jon Miranda7fda2852017-07-19 16:07:01 -0700773 mShouldFadeInScrim = false;
Winson Chung62a70be2018-02-23 15:10:05 -0800774 UiFactory.onStart(this);
Michael Jurkacd496d72013-04-11 11:32:45 -0700775 }
776
777 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800778 protected void onResume() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700779 TraceHelper.beginSection("ON_RESUME");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800780 super.onResume();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700781 TraceHelper.partitionSection("ON_RESUME", "superCall");
782
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700783 mAppLaunchSuccess = false;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700784 getUserEventDispatcher().resetElapsedSessionMillis();
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700785 setOnResumeCallback(null);
Sunny Goyala474a9b2017-05-04 16:47:11 -0700786 // Process any items that were added while Launcher was away.
787 InstallShortcutReceiver.disableAndFlushInstallQueue(
788 InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);
Sunny Goyal95f3d6b2016-08-10 16:09:29 -0700789
Sunny Goyala474a9b2017-05-04 16:47:11 -0700790 // Refresh shortcuts if the permission changed.
791 mModel.refreshShortcutsIfRequired();
Adam Cohen9211d422014-10-07 18:14:53 -0700792
Tracy Zhoue5575f92018-04-19 11:12:53 -0700793 DiscoveryBounce.showForHomeIfNeeded(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700794 if (mLauncherCallbacks != null) {
795 mLauncherCallbacks.onResume();
796 }
Tracy Zhoua706f002018-03-28 13:55:19 -0700797 UiFactory.onLauncherStateOrResumeChanged(this);
Mario Bertschler0fc6f682017-02-17 12:16:13 -0800798
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700799 TraceHelper.endSection("ON_RESUME");
Adam Cohen06dff352012-06-01 17:17:08 -0700800 }
801
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800802 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700803 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700804 // Ensure that items added to Launcher are queued until Launcher returns
Sunny Goyala474a9b2017-05-04 16:47:11 -0700805 InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED);
Winson Chung997a9232013-07-24 15:33:46 -0700806
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700807 super.onPause();
Joe Onorato24b6fd82009-11-12 13:47:09 -0800808 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700809 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -0700810
Adam Cohen9211d422014-10-07 18:14:53 -0700811 if (mLauncherCallbacks != null) {
812 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -0700813 }
Adam Cohenbffe7452013-07-22 18:21:45 -0700814 }
815
Winson Chungd7823942018-02-16 03:23:47 +0000816 @Override
Tracy Zhoua706f002018-03-28 13:55:19 -0700817 protected void onUserLeaveHint() {
818 super.onUserLeaveHint();
819 UiFactory.onLauncherStateOrResumeChanged(this);
820 }
821
822 @Override
Winson Chungd7823942018-02-16 03:23:47 +0000823 public void onWindowFocusChanged(boolean hasFocus) {
824 super.onWindowFocusChanged(hasFocus);
825 mStateManager.onWindowFocusChanged();
826 }
827
Adam Cohenc2d6e892014-10-16 09:49:24 -0700828 public interface LauncherOverlay {
829
830 /**
831 * Touch interaction leading to overscroll has begun
832 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700833 void onScrollInteractionBegin();
Adam Cohenc2d6e892014-10-16 09:49:24 -0700834
835 /**
836 * Touch interaction related to overscroll has ended
837 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700838 void onScrollInteractionEnd();
Adam Cohenc2d6e892014-10-16 09:49:24 -0700839
840 /**
841 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
842 * screen (or in the case of RTL, the rightmost screen).
843 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700844 void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700845
846 /**
Sunny Goyal32554d12015-12-03 15:31:25 -0800847 * Called when the launcher is ready to use the overlay
848 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -0700849 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700850 void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700851 }
852
853 public interface LauncherOverlayCallbacks {
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700854 void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700855 }
856
857 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
858
Sunny Goyalc86df472016-02-25 09:19:38 -0800859 public void onScrollChanged(float progress) {
860 if (mWorkspace != null) {
861 mWorkspace.onOverlayScrollChanged(progress);
862 }
863 }
Adam Cohenc2d6e892014-10-16 09:49:24 -0700864 }
865
Sunny Goyal16764582017-11-06 16:00:34 -0800866 public boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -0700867 if (mLauncherCallbacks != null) {
868 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700869 } else {
Sunny Goyal4179e9b2017-03-08 14:25:09 -0800870 // On O and above we there is always some setting present settings (add icon to
871 // home screen or icon badging). On earlier APIs we will have the allow rotation
872 // setting, on devices with a locked orientation,
Hyunyoung Songe24cb632017-09-11 11:18:03 -0700873 return Utilities.ATLEAST_OREO || !getResources().getBoolean(R.bool.allow_rotation);
Adam Cohen9211d422014-10-07 18:14:53 -0700874 }
Jorim Jaggid017f882014-01-14 17:08:48 -0800875 }
876
Sunny Goyalf9403d92017-10-18 10:55:56 -0700877 public boolean isInState(LauncherState state) {
Sunny Goyalea609262017-10-25 15:47:38 -0700878 return mStateManager.getState() == state;
Sunny Goyalf9403d92017-10-18 10:55:56 -0700879 }
880
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800881 /**
882 * Restores the previous state, if it exists.
883 *
884 * @param savedState The previous state.
885 */
886 private void restoreState(Bundle savedState) {
887 if (savedState == null) {
888 return;
889 }
890
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700891 int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
Sunny Goyalf9403d92017-10-18 10:55:56 -0700892 LauncherState[] stateValues = LauncherState.values();
893 LauncherState state = stateValues[stateOrdinal];
Sunny Goyalbc683e92017-12-06 10:25:07 -0800894 if (!state.disableRestore) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700895 mStateManager.goToState(state, false /* animated */);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800896 }
897
Sunny Goyal2100c782016-08-22 16:00:03 -0700898 PendingRequestArgs requestArgs = savedState.getParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS);
899 if (requestArgs != null) {
900 setWaitingForResult(requestArgs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700902
903 mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700904
905 SparseArray<Parcelable> widgetsState =
906 savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL);
907 if (widgetsState != null) {
908 WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState);
909 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800910 }
911
912 /**
913 * Finds all the views we need and configure them properly.
914 */
915 private void setupViews() {
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800916 mDragLayer = findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700917 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Sunny Goyal966d9012017-06-06 16:43:59 -0700918 mWorkspace = mDragLayer.findViewById(R.id.workspace);
Sunny Goyald0a6ae72016-06-16 12:29:03 -0700919 mWorkspace.initParentViews(mDragLayer);
Sunny Goyal16764582017-11-06 16:00:34 -0800920 mOverviewPanel = findViewById(R.id.overview_panel);
Vadim Tryshev6d2321c2018-04-11 17:19:08 -0700921 mOverviewPanelContainer = findViewById(R.id.overview_panel_container);
Sunny Goyal7c7be8c2018-03-07 19:58:07 -0800922 mHotseat = findViewById(R.id.hotseat);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700923 mDragHandleIndicator = findViewById(R.id.drag_indicator);
924 mHotseatSearchBox = findViewById(R.id.search_container_hotseat);
Craig Mautner360310b2012-10-26 15:13:08 -0700925
Sunny Goyal784f9c32016-03-23 16:56:54 -0700926 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
927 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
928 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800929
Winson Chung4c98d922011-05-31 16:50:48 -0700930 // Setup the drag layer
Tony Wickhama0068302018-04-11 16:16:11 -0700931 Runnable setupDragLayer = () -> mDragLayer.setup(mDragController);
932 UiFactory.setOnTouchControllersChangedListener(this, setupDragLayer);
933 setupDragLayer.run();
Winson Chung4c98d922011-05-31 16:50:48 -0700934
Hyunyoung Song645764e2016-06-06 14:19:02 -0700935 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -0700936 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
937 // default state, otherwise we will update to the wrong offsets in RTL
938 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -0700939 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700940 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700941
Tony Wickham34d2c912015-09-11 09:27:58 -0700942 // Get the search/delete/uninstall bar
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700943 mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700944
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700945 // Setup Apps
946 mAppsView = findViewById(R.id.apps_view);
Craig Mautner360310b2012-10-26 15:13:08 -0700947
Winson Chung3d503fb2011-07-13 17:25:49 -0700948 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -0700949 mDragController.setMoveTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700950 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -0400951
Sunny Goyal7185dd62018-03-14 17:51:49 -0700952 mAllAppsController.setupViews(mAppsView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800953 }
954
955 /**
956 * Creates a view representing a shortcut.
957 *
958 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800959 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800960 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700961 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800962 }
963
964 /**
965 * Creates a view representing a shortcut inflated from the specified resource.
966 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800967 * @param parent The group the shortcut belongs to.
968 * @param info The data structure describing the shortcut.
969 *
970 * @return A View inflated from layoutResId.
971 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700972 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal9b29ca52017-02-17 10:39:44 -0800973 BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
974 .inflate(R.layout.app_icon, parent, false);
Sunny Goyal1cd01b02016-11-09 10:43:58 -0800975 favorite.applyFromShortcutInfo(info);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800976 favorite.setOnClickListener(ItemClickHandler.INSTANCE);
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700977 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800978 return favorite;
979 }
980
981 /**
Jon Mirandac476d6e2017-05-04 16:30:01 -0700982 * Add a shortcut to the workspace or to a Folder.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800983 *
984 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800985 */
Adam Cohendcd297f2013-06-18 13:13:40 -0700986 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700987 int cellY, PendingRequestArgs args) {
Jon Mirandac476d6e2017-05-04 16:30:01 -0700988 if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
989 || args.getPendingIntent().getComponent() == null) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700990 return;
991 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700992
Jon Mirandac476d6e2017-05-04 16:30:01 -0700993 int[] cellXY = mTmpAddItemCellCoordinates;
994 CellLayout layout = getCellLayout(container, screenId);
995
Sunny Goyal782f0c92017-01-19 10:27:54 -0800996 ShortcutInfo info = null;
Hyunyoung Songe24cb632017-09-11 11:18:03 -0700997 if (Utilities.ATLEAST_OREO) {
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700998 info = LauncherAppsCompatVO.createShortcutInfoFromPinItemRequest(
999 this, LauncherAppsCompatVO.getPinItemRequest(data), 0);
Sunny Goyal782f0c92017-01-19 10:27:54 -08001000 }
1001
1002 if (info == null) {
Sunny Goyalb57645f2017-03-20 13:57:28 -07001003 // Legacy shortcuts are only supported for primary profile.
1004 info = Process.myUserHandle().equals(args.user)
1005 ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
Sunny Goyal782f0c92017-01-19 10:27:54 -08001006
Sunny Goyalb57645f2017-03-20 13:57:28 -07001007 if (info == null) {
1008 Log.e(TAG, "Unable to parse a valid custom shortcut result");
1009 return;
1010 } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
Sunny Goyal342e4662017-02-02 15:21:08 -08001011 info.intent, args.getPendingIntent().getComponent().getPackageName())) {
Sunny Goyal782f0c92017-01-19 10:27:54 -08001012 // The app is trying to add a shortcut without sufficient permissions
1013 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
1014 return;
1015 }
1016 }
1017
Jon Mirandac476d6e2017-05-04 16:30:01 -07001018 if (container < 0) {
1019 // Adding a shortcut to the Workspace.
1020 final View view = createShortcut(info);
1021 boolean foundCellSpan = false;
1022 // First we check if we already know the exact location where we want to add this item.
1023 if (cellX >= 0 && cellY >= 0) {
1024 cellXY[0] = cellX;
1025 cellXY[1] = cellY;
1026 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001027
Jon Mirandac476d6e2017-05-04 16:30:01 -07001028 // If appropriate, either create a folder or add to an existing folder
1029 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Sunny Goyal1797af42017-10-06 13:29:57 -07001030 true, null)) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001031 return;
1032 }
1033 DragObject dragObject = new DragObject();
1034 dragObject.dragInfo = info;
1035 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1036 true)) {
1037 return;
1038 }
1039 } else {
1040 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1041 }
1042
1043 if (!foundCellSpan) {
1044 mWorkspace.onNoCellFound(layout);
Adam Cohen558baaf2011-08-15 15:22:57 -07001045 return;
1046 }
Jon Mirandac476d6e2017-05-04 16:30:01 -07001047
1048 getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
1049 mWorkspace.addInScreen(view, info);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001050 } else {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001051 // Adding a shortcut to a Folder.
Sunny Goyale29897f2017-07-20 10:09:42 -07001052 FolderIcon folderIcon = findFolderIcon(container);
Jon Mirandac476d6e2017-05-04 16:30:01 -07001053 if (folderIcon != null) {
1054 FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
1055 folderInfo.add(info, args.rank, false);
1056 } else {
Sunny Goyale29897f2017-07-20 10:09:42 -07001057 Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
Jon Mirandac476d6e2017-05-04 16:30:01 -07001058 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001059 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 }
1061
Sunny Goyale29897f2017-07-20 10:09:42 -07001062 public FolderIcon findFolderIcon(final long folderIconId) {
1063 return (FolderIcon) mWorkspace.getFirstMatch(new ItemOperator() {
1064 @Override
1065 public boolean evaluate(ItemInfo info, View view) {
1066 return info != null && info.id == folderIconId;
1067 }
1068 });
1069 }
1070
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001072 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001073 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001074 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001075 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001076 @Thunk void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001077 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1078
Adam Cohened66b2b2012-01-23 17:28:51 -08001079 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001080 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001081 }
Romain Guycbb89e42009-06-08 15:52:54 -07001082
Adam Cohen59400422014-03-05 18:07:04 -08001083 LauncherAppWidgetInfo launcherInfo;
1084 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
Sunny Goyal2100c782016-08-22 16:00:03 -07001085 launcherInfo.spanX = itemInfo.spanX;
1086 launcherInfo.spanY = itemInfo.spanY;
1087 launcherInfo.minSpanX = itemInfo.minSpanX;
1088 launcherInfo.minSpanY = itemInfo.minSpanY;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001089 launcherInfo.user = appWidgetInfo.getProfile();
Romain Guycbb89e42009-06-08 15:52:54 -07001090
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001091 getModelWriter().addItemToDatabase(launcherInfo,
Sunny Goyal2100c782016-08-22 16:00:03 -07001092 itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001093
Sunny Goyal2100c782016-08-22 16:00:03 -07001094 if (hostView == null) {
1095 // Perform actual inflation because we're live
1096 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001097 }
Sunny Goyal2100c782016-08-22 16:00:03 -07001098 hostView.setVisibility(View.VISIBLE);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301099 prepareAppWidget(hostView, launcherInfo);
1100 mWorkspace.addInScreen(hostView, launcherInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 }
Romain Guycbb89e42009-06-08 15:52:54 -07001102
Sunny Goyald5462aa2016-11-22 16:52:39 +05301103 private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001104 hostView.setTag(item);
1105 item.onBindAppWidget(this, hostView);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001106 hostView.setFocusable(true);
1107 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001108 }
1109
Adam Cohended9f8d2010-11-03 13:25:16 -07001110 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1111 @Override
1112 public void onReceive(Context context, Intent intent) {
1113 final String action = intent.getAction();
1114 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001115 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001116 // processing a multi-step drop
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001117 if (mAppsView != null && mPendingRequestArgs == null) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001118 mStateManager.goToState(NORMAL);
Winson Chung785d2eb2011-04-14 16:08:02 -07001119 }
Jon Miranda7fda2852017-07-19 16:07:01 -07001120 mShouldFadeInScrim = true;
1121 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1122 // ACTION_USER_PRESENT is sent after onStart/onResume. This covers the case where
1123 // the user unlocked and the Launcher is not in the foreground.
1124 mShouldFadeInScrim = false;
Adam Cohended9f8d2010-11-03 13:25:16 -07001125 }
1126 }
1127 };
1128
Tony Wickham010d2552017-01-20 08:15:28 -08001129 public void updateIconBadges(final Set<PackageUserKey> updatedBadges) {
Sunny Goyal29947f02017-12-18 13:49:44 -08001130 mWorkspace.updateIconBadges(updatedBadges);
Sunny Goyal60180b02018-02-07 12:56:30 -08001131 mAppsView.getAppsStore().updateIconBadges(updatedBadges);
Tony Wickham2fe09f22017-04-25 12:46:04 -07001132
Sunny Goyal29947f02017-12-18 13:49:44 -08001133 PopupContainerWithArrow popup = PopupContainerWithArrow.getOpen(Launcher.this);
1134 if (popup != null) {
1135 popup.updateNotificationHeader(updatedBadges);
Tony Wickham010d2552017-01-20 08:15:28 -08001136 }
1137 }
1138
Adam Cohended9f8d2010-11-03 13:25:16 -07001139 @Override
1140 public void onAttachedToWindow() {
1141 super.onAttachedToWindow();
1142
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001143 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Sunny Goyalc86df472016-02-25 09:19:38 -08001144 if (mLauncherCallbacks != null) {
1145 mLauncherCallbacks.onAttachedToWindow();
1146 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001147 }
1148
1149 @Override
1150 public void onDetachedFromWindow() {
1151 super.onDetachedFromWindow();
Sunny Goyalc86df472016-02-25 09:19:38 -08001152
1153 if (mLauncherCallbacks != null) {
1154 mLauncherCallbacks.onDetachedFromWindow();
1155 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001156 }
1157
Sunny Goyal3bac2c22018-02-07 14:44:05 -08001158 public void onQuickstepGestureStarted(boolean isVisible) {
1159 if (mLauncherCallbacks != null) {
1160 mLauncherCallbacks.onQuickstepGestureStarted(isVisible);
1161 }
1162 }
1163
Sunny Goyalc4fa8c32017-11-07 12:23:58 -08001164 public AllAppsTransitionController getAllAppsController() {
1165 return mAllAppsController;
1166 }
1167
Sunny Goyal9d69c8d2018-03-19 13:41:31 -07001168 @Override
Winson Chung1a341002018-01-17 10:00:23 -08001169 public LauncherRootView getRootView() {
1170 return (LauncherRootView) mLauncherView;
1171 }
1172
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001173 @Override
Winson Chunga6945242014-01-08 14:04:34 -08001174 public DragLayer getDragLayer() {
1175 return mDragLayer;
1176 }
1177
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001178 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001179 return mAppsView;
1180 }
1181
Winson Chunga6945242014-01-08 14:04:34 -08001182 public Workspace getWorkspace() {
1183 return mWorkspace;
1184 }
1185
1186 public Hotseat getHotseat() {
1187 return mHotseat;
1188 }
1189
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001190 public View getDragHandleIndicator() {
1191 return mDragHandleIndicator;
1192 }
1193
1194 public View getHotseatSearchBox() {
1195 return mHotseatSearchBox;
1196 }
1197
Sunny Goyal7c7be8c2018-03-07 19:58:07 -08001198 public <T extends View> T getOverviewPanel() {
Winson Chung8ae41982017-11-10 11:42:13 -08001199 return (T) mOverviewPanel;
Winson Chunga6945242014-01-08 14:04:34 -08001200 }
1201
Vadim Tryshev6d2321c2018-04-11 17:19:08 -07001202 public <T extends View> T getOverviewPanelContainer() {
1203 return (T) mOverviewPanelContainer;
1204 }
1205
Sunny Goyal47328fd2016-05-25 18:56:41 -07001206 public DropTargetBar getDropTargetBar() {
1207 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001208 }
1209
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001210 public LauncherAppWidgetHost getAppWidgetHost() {
1211 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 }
Romain Guycbb89e42009-06-08 15:52:54 -07001213
Winson Chunga9abd0e2010-10-27 17:18:37 -07001214 public LauncherModel getModel() {
1215 return mModel;
1216 }
1217
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001218 public ModelWriter getModelWriter() {
1219 return mModelWriter;
1220 }
1221
Adam Cohen79d90c52016-04-22 13:29:20 -07001222 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001223 return mSharedPrefs;
1224 }
1225
Sunny Goyalf8d56fc2018-01-31 15:18:11 -08001226 public int getOrientation() { return mOldConfig.orientation; }
Jon Miranda6bed3502017-09-19 14:43:17 -07001227
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 @Override
1229 protected void onNewIntent(Intent intent) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001230 TraceHelper.beginSection("NEW_INTENT");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001231 super.onNewIntent(intent);
1232
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001233 boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
Winson15f8b172015-08-19 11:02:39 -07001234 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1235 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Sunny Goyal85313732016-09-28 12:00:07 -07001236
1237 // Check this condition before handling isActionMain, as this will get reset.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001238 boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
Sunny Goyalf9403d92017-10-18 10:55:56 -07001239 && AbstractFloatingView.getTopOpenView(this) == null;
Winson15f8b172015-08-19 11:02:39 -07001240 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001241 boolean internalStateHandled = InternalStateHandler
Sunny Goyal8b264562018-02-03 23:00:13 -08001242 .handleNewIntent(this, intent, isStarted());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001243
Winson15f8b172015-08-19 11:02:39 -07001244 if (isActionMain) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001245 if (!internalStateHandled) {
1246 // Note: There should be at most one log per method call. This is enforced
1247 // implicitly by using if-else statements.
1248 UserEventDispatcher ued = getUserEventDispatcher();
1249 AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(this);
1250 if (topOpenView != null) {
1251 topOpenView.logActionCommand(Action.Command.HOME_INTENT);
1252 } else if (alreadyOnHome) {
1253 Target target = newContainerTarget(mStateManager.getState().containerType);
1254 target.pageIndex = mWorkspace.getCurrentPage();
Hyunyoung Songb3fbc0b2018-02-14 13:40:25 -08001255 ued.logActionCommand(Action.Command.HOME_INTENT, target,
1256 newContainerTarget(ContainerType.WORKSPACE));
Sunny Goyald3864fa2017-11-14 15:06:36 -08001257 }
Jon Mirandafeba90f2016-10-06 10:53:29 -07001258
Sunny Goyald3864fa2017-11-14 15:06:36 -08001259 // In all these cases, only animate if we're already on home
Sunny Goyalcc96aa12018-01-11 09:56:07 -08001260 AbstractFloatingView.closeAllOpenViews(this, isStarted());
Jon Mirandafeba90f2016-10-06 10:53:29 -07001261
Sunny Goyala2467272018-03-16 14:53:05 -07001262 if (!isInState(NORMAL)) {
1263 // Only change state, if not already the same. This prevents cancelling any
1264 // animations running as part of resume
1265 mStateManager.goToState(NORMAL);
1266 }
Sunny Goyald3864fa2017-11-14 15:06:36 -08001267
1268 // Reset the apps view
1269 if (!alreadyOnHome && mAppsView != null) {
Sunny Goyal7185dd62018-03-14 17:51:49 -07001270 mAppsView.reset(isStarted() /* animate */);
Sunny Goyald3864fa2017-11-14 15:06:36 -08001271 }
1272
1273 if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive()) {
1274 mWorkspace.post(mWorkspace::moveToDefaultScreen);
1275 }
1276 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001277
1278 final View v = getWindow().peekDecorView();
1279 if (v != null && v.getWindowToken() != null) {
Sunny Goyal326403e2017-10-02 12:45:10 -07001280 UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
Adam Cohen6fecd412013-10-02 17:41:50 -07001281 }
1282
Adam Cohen9211d422014-10-07 18:14:53 -07001283 if (mLauncherCallbacks != null) {
Sunny Goyal85462132018-04-24 11:39:37 -07001284 mLauncherCallbacks.onHomeIntent(internalStateHandled);
Adam Cohen9211d422014-10-07 18:14:53 -07001285 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286 }
Winson15f8b172015-08-19 11:02:39 -07001287
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001288 TraceHelper.endSection("NEW_INTENT");
Adam Coppa120b8e2013-11-12 16:26:04 +00001289 }
1290
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001291 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001292 public void onRestoreInstanceState(Bundle state) {
1293 super.onRestoreInstanceState(state);
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001294 mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001295 }
1296
1297 @Override
1298 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001299 if (mWorkspace.getChildCount() > 0) {
Sunny Goyal7ce471b2017-08-02 03:37:39 -07001300 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001301
Adam Cohen21cd0022013-10-09 18:57:02 -07001302 }
Sunny Goyalea609262017-10-25 15:47:38 -07001303 outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001304
1305
1306 AbstractFloatingView widgets = AbstractFloatingView
1307 .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET);
1308 if (widgets != null) {
1309 SparseArray<Parcelable> widgetsState = new SparseArray<>();
1310 widgets.saveHierarchyState(widgetsState);
1311 outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState);
1312 } else {
1313 outState.remove(RUNTIME_STATE_WIDGET_PANEL);
1314 }
1315
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001316 // We close any open folders and shortcut containers since they will not be re-opened,
1317 // and we need to make sure this state is reflected.
1318 AbstractFloatingView.closeAllOpenViews(this, false);
Tony Wickham49c8d292016-07-01 11:44:34 -07001319
Sunny Goyal2100c782016-08-22 16:00:03 -07001320 if (mPendingRequestArgs != null) {
1321 outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
1322 }
1323 if (mPendingActivityResult != null) {
1324 outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325 }
1326
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001327 super.onSaveInstanceState(outState);
1328
Adam Cohen9211d422014-10-07 18:14:53 -07001329 if (mLauncherCallbacks != null) {
1330 mLauncherCallbacks.onSaveInstanceState(outState);
1331 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332 }
1333
1334 @Override
1335 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001336 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001337
Sunny Goyal5cc7bbd2017-06-12 09:50:39 -07001338 unregisterReceiver(mReceiver);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001339 mWorkspace.removeFolderListeners();
Winson Chunge7a03942011-08-05 15:05:12 -07001340
Tony Wickhama0068302018-04-11 16:16:11 -07001341 UiFactory.setOnTouchControllersChangedListener(this, null);
1342
Winson Chungcd2b0142011-06-08 16:02:26 -07001343 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001344 // It's possible to receive onDestroy after a new Launcher activity has
1345 // been created. In this case, don't interfere with the new Launcher.
1346 if (mModel.isCurrentCallbacks(this)) {
1347 mModel.stopLoader();
Sunny Goyal87f784c2017-01-11 10:48:34 -08001348 LauncherAppState.getInstance(this).setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001349 }
Sunny Goyal623eddd2018-03-02 12:24:41 -08001350 mRotationHelper.destroy();
Winson Chungedb0d6b2018-03-21 17:32:55 -07001351 mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mSharedPrefsListener);
Sunny Goyal745bad92016-05-02 10:54:12 -07001352
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001354 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001356 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001357 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001358
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001359 TextKeyListener.getInstance().release();
Mario Bertschler27288382017-05-24 15:35:09 -07001360
Michael Jurka2ecf9952012-06-18 12:52:28 -07001361 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07001362
Tony2917a8b2017-07-31 23:29:42 -07001363 clearPendingBinds();
1364
Adam Cohen9211d422014-10-07 18:14:53 -07001365 if (mLauncherCallbacks != null) {
1366 mLauncherCallbacks.onDestroy();
1367 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001368 }
1369
Sunny Goyalae502842016-06-17 08:43:56 -07001370 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
1371 return mAccessibilityDelegate;
1372 }
1373
Adam Cohena9cf38f2011-05-02 15:36:58 -07001374 public DragController getDragController() {
1375 return mDragController;
1376 }
1377
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001379 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001380 super.startActivityForResult(intent, requestCode, options);
Adam Cohen173f7112015-03-27 15:14:00 -07001381 }
1382
1383 @Override
1384 public void startIntentSenderForResult (IntentSender intent, int requestCode,
1385 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
Adam Cohen173f7112015-03-27 15:14:00 -07001386 try {
1387 super.startIntentSenderForResult(intent, requestCode,
1388 fillInIntent, flagsMask, flagsValues, extraFlags, options);
1389 } catch (IntentSender.SendIntentException e) {
1390 throw new ActivityNotFoundException();
1391 }
1392 }
1393
Winson Chung70d72102011-08-12 11:24:35 -07001394 /**
1395 * Indicates that we want global search for this activity by setting the globalSearch
1396 * argument for {@link #startSearch} to true.
1397 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001398 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001399 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001400 Bundle appSearchData, boolean globalSearch) {
1401 if (appSearchData == null) {
1402 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001403 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001405
Sunny Goyal6f28e712016-09-13 14:19:29 -07001406 if (mLauncherCallbacks == null ||
1407 !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) {
1408 // Starting search from the callbacks failed. Start the default global search.
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001409 super.startSearch(initialQuery, selectInitialQuery, appSearchData, true);
Ian Parkinson047036e2014-09-01 15:40:53 +01001410 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001411
1412 // We need to show the workspace after starting the search
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001413 mStateManager.goToState(NORMAL);
Bjorn Bringertc459e522013-06-07 19:36:01 +01001414 }
1415
Joe Onorato9c1289c2009-08-17 11:03:03 -04001416 public boolean isWorkspaceLocked() {
Sunny Goyal2100c782016-08-22 16:00:03 -07001417 return mWorkspaceLoading || mPendingRequestArgs != null;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001418 }
1419
Adam Cohen517a7f52014-03-01 12:12:59 -08001420 public boolean isWorkspaceLoading() {
1421 return mWorkspaceLoading;
1422 }
1423
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001424 private void setWorkspaceLoading(boolean value) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001425 mWorkspaceLoading = value;
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001426 }
1427
Sunny Goyal04a324a2017-01-20 21:08:59 -08001428 public void setWaitingForResult(PendingRequestArgs args) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001429 mPendingRequestArgs = args;
Adam Cohen9211d422014-10-07 18:14:53 -07001430 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001431
Sunny Goyal2100c782016-08-22 16:00:03 -07001432 void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001433 WidgetAddFlowHandler addFlowHandler) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001434 if (LOGD) {
1435 Log.d(TAG, "Adding widget from drop");
1436 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001437 addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001438 }
1439
Sunny Goyal2100c782016-08-22 16:00:03 -07001440 void addAppWidgetImpl(int appWidgetId, ItemInfo info,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001441 AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
1442 if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, REQUEST_CREATE_APPWIDGET)) {
1443 // If the configuration flow was not started, add the widget
Michael Jurkaaf442092010-06-10 17:01:57 -07001444
Adam Cohenad4e15c2013-10-17 16:21:35 -07001445 Runnable onComplete = new Runnable() {
1446 @Override
1447 public void run() {
1448 // Exit spring loaded mode if necessary after adding the widget
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001449 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001450 }
1451 };
Sunny Goyal04a324a2017-01-20 21:08:59 -08001452 completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this));
Adam Cohen689ff162014-05-08 17:27:56 -07001453 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001454 }
1455 }
Romain Guycbb89e42009-06-08 15:52:54 -07001456
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001457 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
1458 int[] cell, int spanX, int spanY) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001459 info.container = container;
1460 info.screenId = screenId;
1461 if (cell != null) {
1462 info.cellX = cell[0];
1463 info.cellY = cell[1];
1464 }
1465 info.spanX = spanX;
1466 info.spanY = spanY;
1467
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001468 switch (info.itemType) {
1469 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
1470 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -07001471 addAppWidgetFromDrop((PendingAddWidgetInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001472 break;
1473 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal782f0c92017-01-19 10:27:54 -08001474 processShortcutFromDrop((PendingAddShortcutInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001475 break;
1476 default:
1477 throw new IllegalStateException("Unknown item type: " + info.itemType);
1478 }
1479 }
1480
Adam Cohenfbba09b2011-07-18 21:43:05 -07001481 /**
1482 * Process a shortcut drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001483 */
Sunny Goyal782f0c92017-01-19 10:27:54 -08001484 private void processShortcutFromDrop(PendingAddShortcutInfo info) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001485 Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
1486 setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
Sunny Goyal782f0c92017-01-19 10:27:54 -08001487 if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
1488 handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
1489 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001490 }
1491
Adam Cohenfbba09b2011-07-18 21:43:05 -07001492 /**
1493 * Process a widget drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001494 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001495 private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001496 AppWidgetHostView hostView = info.boundWidget;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001497 final int appWidgetId;
Sunny Goyal8a0dc382017-01-25 11:30:06 -08001498 WidgetAddFlowHandler addFlowHandler = info.getHandler();
Adam Cohened66b2b2012-01-23 17:28:51 -08001499 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001500 // In the case where we've prebound the widget, we remove it from the DragLayer
1501 if (LOGD) {
1502 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
1503 }
1504 getDragLayer().removeView(hostView);
1505
Adam Cohened66b2b2012-01-23 17:28:51 -08001506 appWidgetId = hostView.getAppWidgetId();
Sunny Goyal04a324a2017-01-20 21:08:59 -08001507 addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07001508
1509 // Clear the boundWidget so that it doesn't get destroyed.
1510 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08001511 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001512 // In this case, we either need to start an activity to get permission to bind
1513 // the widget, or we need to start an activity to configure the widget, or both.
Sunny Goyal952e63d2017-08-16 04:59:08 -07001514 if (FeatureFlags.ENABLE_CUSTOM_WIDGETS &&
1515 info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
1516 appWidgetId = CustomWidgetParser.getWidgetIdForCustomProvider(
1517 this, info.componentName);
1518 } else {
1519 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1520 }
Adam Cohendd70d662012-10-04 16:53:44 -07001521 Bundle options = info.bindOptions;
1522
Sunny Goyalffe83f12014-08-14 17:39:34 -07001523 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1524 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07001525 if (success) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001526 addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
Michael Jurka8b805b12012-04-18 14:23:14 -07001527 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001528 addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
Michael Jurka8b805b12012-04-18 14:23:14 -07001529 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001530 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001531 }
1532
Adam Cohendcd297f2013-06-18 13:13:40 -07001533 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001534 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001535 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001536 folderInfo.title = getText(R.string.folder_name);
1537
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001538 // Update the model
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001539 getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001540
1541 // Create the view
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001542 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301543 mWorkspace.addInScreen(newFolder, folderInfo);
Winson Chung5f8afe62013-08-12 16:19:28 -07001544 // Force measure the new folder icon
1545 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
1546 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07001547 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001548 }
Romain Guycbb89e42009-06-08 15:52:54 -07001549
Winsonc0b52fe2015-09-09 16:38:15 -07001550 /**
Winsonfa56b3f2015-09-14 12:01:13 -07001551 * Unbinds the view for the specified item, and removes the item and all its children.
1552 *
1553 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07001554 * @param itemInfo the {@link ItemInfo} for this view.
1555 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07001556 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001557 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07001558 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07001559 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07001560 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
1561 if (folderIcon instanceof FolderIcon) {
Sunny Goyalc52ba712016-04-05 15:59:05 -07001562 ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07001563 } else {
1564 mWorkspace.removeWorkspaceItem(v);
1565 }
Winsonc0b52fe2015-09-09 16:38:15 -07001566 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001567 getModelWriter().deleteItemFromDatabase(itemInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001568 }
1569 } else if (itemInfo instanceof FolderInfo) {
1570 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001571 if (v instanceof FolderIcon) {
1572 ((FolderIcon) v).removeListeners();
1573 }
Winsonc0b52fe2015-09-09 16:38:15 -07001574 mWorkspace.removeWorkspaceItem(v);
1575 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001576 getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001577 }
1578 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
1579 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07001580 mWorkspace.removeWorkspaceItem(v);
Winsonc0b52fe2015-09-09 16:38:15 -07001581 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07001582 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001583 }
1584 } else {
1585 return false;
1586 }
1587 return true;
1588 }
1589
1590 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07001591 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07001592 */
Sunny Goyal56c73602015-09-25 12:55:01 -07001593 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07001594 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyald478c832016-04-01 12:04:16 -07001595 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdAllocated()) {
Winsonc0b52fe2015-09-09 16:38:15 -07001596 // Deleting an app widget ID is a void call but writes to disk before returning
1597 // to the caller...
1598 new AsyncTask<Void, Void, Void>() {
1599 public Void doInBackground(Void ... args) {
1600 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
1601 return null;
1602 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07001603 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07001604 }
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001605 getModelWriter().deleteItemFromDatabase(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001606 }
1607
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 @Override
1609 public boolean dispatchKeyEvent(KeyEvent event) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08001610 return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001611 }
1612
Joe Onorato88ec0992009-11-19 13:16:06 -08001613 @Override
1614 public void onBackPressed() {
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08001615 if (finishAutoCancelActionMode()) {
1616 return;
1617 }
Adam Cohen9211d422014-10-07 18:14:53 -07001618 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
1619 return;
1620 }
1621
Sunny Goyal45478022015-06-08 16:52:41 -07001622 if (mDragController.isDragging()) {
1623 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08001624 return;
1625 }
1626
Jon Mirandafeba90f2016-10-06 10:53:29 -07001627 // Note: There should be at most one log per method call. This is enforced implicitly
1628 // by using if-else statements.
1629 UserEventDispatcher ued = getUserEventDispatcher();
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001630 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
1631 if (topView != null) {
Sunny Goyal37920962017-09-28 13:43:24 -07001632 topView.onBackPressed();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001633 } else if (!isInState(NORMAL)) {
Sunny Goyal49bcf342018-01-11 13:59:53 -08001634 LauncherState lastState = mStateManager.getLastState();
Hyunyoung Songb3fbc0b2018-02-14 13:40:25 -08001635 ued.logActionCommand(Action.Command.BACK, mStateManager.getState().containerType,
1636 lastState.containerType);
Sunny Goyal49bcf342018-01-11 13:59:53 -08001637 mStateManager.goToState(lastState);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001638 } else {
1639 // Back button is a no-op here, but give at least some feedback for the button press
1640 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001641 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001642 }
1643
Sunny Goyalfe770c92016-09-27 14:38:58 -07001644 @TargetApi(Build.VERSION_CODES.M)
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001645 @Override
Tony Wickham005df0b2018-02-13 11:28:12 -08001646 public ActivityOptions getActivityLaunchOptions(View v, boolean useDefaultLaunchOptions) {
Jon Miranda17940f02018-01-18 14:46:34 -08001647 return useDefaultLaunchOptions
Jon Miranda54441f52018-01-24 15:38:25 -08001648 ? mAppTransitionManager.getDefaultActivityLaunchOptions(this, v)
1649 : mAppTransitionManager.getActivityLaunchOptions(this, v);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001650 }
1651
Tony Wickham3a6746a2018-03-29 09:39:56 -07001652 public LauncherAppTransitionManager getAppTransitionManager() {
1653 return mAppTransitionManager;
1654 }
1655
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001656 @TargetApi(Build.VERSION_CODES.M)
1657 @Override
1658 protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) {
1659 // Due to legacy reasons, direct call shortcuts require Launchers to have the
1660 // corresponding permission. Show the appropriate permission prompt if that
1661 // is the case.
1662 if (intent.getComponent() == null
1663 && Intent.ACTION_CALL.equals(intent.getAction())
1664 && checkSelfPermission(android.Manifest.permission.CALL_PHONE) !=
1665 PackageManager.PERMISSION_GRANTED) {
1666
1667 setWaitingForResult(PendingRequestArgs
1668 .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
1669 requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE},
1670 REQUEST_PERMISSION_CALL_PHONE);
1671 return true;
1672 } else {
1673 return false;
1674 }
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001675 }
1676
Sunny Goyala7ce1662016-05-31 15:01:35 -07001677 public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
Sunny Goyal0b0847b2018-03-14 12:30:11 -07001678 mAppLaunchSuccess = super.startActivitySafely(v, intent, item);
1679 if (mAppLaunchSuccess && v instanceof BubbleTextView) {
1680 // This is set to the view that launched the activity that navigated the user away
1681 // from launcher. Since there is no callback for when the activity has finished
1682 // launching, enable the press state and keep this reference to reset the press
1683 // state when we return to launcher.
1684 BubbleTextView btv = (BubbleTextView) v;
1685 btv.setStayPressed(true);
1686 setOnResumeCallback(btv);
Sunny Goyala7ce1662016-05-31 15:01:35 -07001687 }
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -07001688 return mAppLaunchSuccess;
Michael Jurka86a720e2012-05-09 11:23:23 -07001689 }
1690
Winson Chung3d503fb2011-07-13 17:25:49 -07001691 boolean isHotseatLayout(View layout) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001692 // TODO: Remove this method
Winson Chung3d503fb2011-07-13 17:25:49 -07001693 return mHotseat != null && layout != null &&
1694 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1695 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001696
Winson Chung3d503fb2011-07-13 17:25:49 -07001697 /**
1698 * Returns the CellLayout of the specified container at the specified screen.
1699 */
Sunny Goyal92820592015-03-02 11:31:35 -08001700 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001701 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1702 if (mHotseat != null) {
1703 return mHotseat.getLayout();
1704 } else {
1705 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001706 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001707 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08001708 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08001709 }
1710 }
1711
Michael Jurkae326f182011-11-21 14:05:46 -08001712 @Override
1713 public void onTrimMemory(int level) {
1714 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07001715 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
1716 // The widget preview db can result in holding onto over
1717 // 3MB of memory for caching which isn't necessary.
1718 SQLiteDatabase.releaseMemory();
1719
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08001720 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07001721 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08001722 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01001723 if (mLauncherCallbacks != null) {
1724 mLauncherCallbacks.onTrimMemory(level);
1725 }
Winson Chung62a70be2018-02-23 15:10:05 -08001726 UiFactory.onTrimMemory(this, level);
Michael Jurkae326f182011-11-21 14:05:46 -08001727 }
1728
Michael Jurkad7c28052012-04-27 15:43:36 -07001729 @Override
1730 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07001731 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07001732 final List<CharSequence> text = event.getText();
1733 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07001734 // Populate event with a fake title based on the current state.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001735 // TODO: When can workspace be null?
1736 text.add(mWorkspace == null
1737 ? getString(R.string.all_apps_home_button_label)
Sunny Goyalea609262017-10-25 15:47:38 -07001738 : mStateManager.getState().getDescription(this));
Michael Jurkad7c28052012-04-27 15:43:36 -07001739 return result;
1740 }
1741
Sunny Goyal3dce5f32017-10-05 11:40:05 -07001742 public void setOnResumeCallback(OnResumeCallback callback) {
1743 if (mOnResumeCallback != null) {
1744 mOnResumeCallback.onLauncherResume();
1745 }
1746 mOnResumeCallback = callback;
Michael Jurka1e2f4652013-07-08 18:03:46 -07001747 }
1748
Michael Jurka7607c2f2013-04-03 14:33:19 -07001749 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001750 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07001752 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04001753 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07001754 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001755 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07001756 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07001757 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07001758 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001759 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001760
Joe Onorato9c1289c2009-08-17 11:03:03 -04001761 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07001762 * Clear any pending bind callbacks. This is called when is loader is planning to
1763 * perform a full rebind from scratch.
1764 */
1765 @Override
1766 public void clearPendingBinds() {
Sunny Goyal527c7d32015-08-28 15:19:36 -07001767 if (mPendingExecutor != null) {
1768 mPendingExecutor.markCompleted();
1769 mPendingExecutor = null;
1770 }
1771 }
1772
1773 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001774 * Refreshes the shortcuts shown on the workspace.
1775 *
1776 * Implementation of the method from LauncherModel.Callbacks.
1777 */
1778 public void startBinding() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001779 TraceHelper.beginSection("startBinding");
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001780 // Floating panels (except the full widget sheet) are associated with individual icons. If
1781 // we are starting a fresh bind, close all such panels as all the icons are about
1782 // to go away.
1783 AbstractFloatingView.closeOpenViews(this, true,
Sunny Goyal7ede6112017-12-05 15:11:21 -08001784 AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
Jon Miranda6dc7f1e2017-02-21 12:37:51 -08001785
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001786 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08001787
Winson Chungd64d1762013-08-20 14:37:16 -07001788 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07001789 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07001790 mWorkspace.removeAllWorkspaceScreens();
Sunny Goyalc11fac32018-02-27 19:20:15 -08001791 mAppWidgetHost.clearViews();
Winson Chungd64d1762013-08-20 14:37:16 -07001792
Winson Chung3d503fb2011-07-13 17:25:49 -07001793 if (mHotseat != null) {
Sunny Goyal11e96492018-03-23 17:06:00 -07001794 mHotseat.resetLayout(mDeviceProfile.isVerticalBarLayout());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001796 TraceHelper.endSection("startBinding");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001797 }
1798
Adam Cohendcd297f2013-06-18 13:13:40 -07001799 @Override
1800 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001801 // Make sure the first screen is always at the start.
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001802 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
1803 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001804 orderedScreenIds.remove(Workspace.FIRST_SCREEN_ID);
1805 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001806 LauncherModel.updateWorkspaceScreenOrder(this, orderedScreenIds);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001807 } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
1808 // If there are no screens, we need to have an empty screen
1809 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07001810 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001811 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07001812
Winsonc7d2e832016-07-28 12:24:55 -07001813 // After we have added all the screens, if the wallpaper was locked to the default state,
1814 // then notify to indicate that it can be released and a proper wallpaper offset can be
1815 // computed before the next layout
1816 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07001817 }
1818
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001819 private void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001820 int count = orderedScreenIds.size();
1821 for (int i = 0; i < count; i++) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001822 long screenId = orderedScreenIds.get(i);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07001823 if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001824 // No need to bind the first screen, as its always bound.
1825 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
1826 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001827 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001828 }
1829
Sunny Goyalb23980c2017-08-17 07:45:25 -07001830 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08001831 public void bindAppsAdded(ArrayList<Long> newScreens, ArrayList<ItemInfo> addNotAnimated,
1832 ArrayList<ItemInfo> addAnimated) {
Winson Chungd64d1762013-08-20 14:37:16 -07001833 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08001834 if (newScreens != null) {
1835 bindAddScreens(newScreens);
1836 }
Winson Chungd64d1762013-08-20 14:37:16 -07001837
1838 // We add the items without animation on non-visible pages, and with
1839 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08001840 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07001841 bindItems(addNotAnimated, false);
Winson Chungd64d1762013-08-20 14:37:16 -07001842 }
Adam Cohen76a47a12014-02-05 11:47:43 -08001843 if (addAnimated != null && !addAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07001844 bindItems(addAnimated, true);
Winson Chungd64d1762013-08-20 14:37:16 -07001845 }
Winson Chungc58497e2013-09-03 17:48:37 -07001846
Winson Chung87412982013-10-03 18:34:14 -07001847 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07001848 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chungd64d1762013-08-20 14:37:16 -07001849 }
1850
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001851 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001852 * Bind the items start-end from the list.
1853 *
1854 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001855 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07001856 @Override
Sunny Goyalb23980c2017-08-17 07:45:25 -07001857 public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08001858 // Get the list of added items and intersect them with the set of items here
Winson Chung64359a52013-07-08 17:17:08 -07001859 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
Rajeev Kumar43c0f582017-06-23 15:34:55 -07001860 final Collection<Animator> bounceAnims = new ArrayList<>();
Winson Chung997a9232013-07-24 15:33:46 -07001861 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001862 Workspace workspace = mWorkspace;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001863 long newItemsScreenId = -1;
Sunny Goyalb23980c2017-08-17 07:45:25 -07001864 int end = items.size();
1865 for (int i = 0; i < end; i++) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08001866 final ItemInfo item = items.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07001867
1868 // Short circuit if we are loading dock items for a configuration which has no dock
1869 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
1870 mHotseat == null) {
1871 continue;
1872 }
1873
Sunny Goyal639e9062015-08-19 19:17:06 -07001874 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001875 switch (item.itemType) {
1876 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1877 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal3be633b2016-12-08 09:59:25 -08001878 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
Winson Chungf0c6ae02012-03-21 16:10:31 -07001879 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07001880 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001881 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001882 }
1883 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
Sunny Goyal639e9062015-08-19 19:17:06 -07001884 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001885 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001886 (FolderInfo) item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001887 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001888 }
Sunny Goyal952e63d2017-08-16 04:59:08 -07001889 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
1890 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: {
Sunny Goyala9a1a212017-08-18 01:03:21 -07001891 view = inflateAppWidget((LauncherAppWidgetInfo) item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07001892 if (view == null) {
1893 continue;
Sunny Goyal3be633b2016-12-08 09:59:25 -08001894 }
Sunny Goyal3be633b2016-12-08 09:59:25 -08001895 break;
1896 }
Winson Chungc763c4e2013-07-19 13:49:06 -07001897 default:
1898 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001899 }
Sunny Goyal639e9062015-08-19 19:17:06 -07001900
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001901 /*
1902 * Remove colliding items.
1903 */
1904 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
1905 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
1906 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
1907 View v = cl.getChildAt(item.cellX, item.cellY);
1908 Object tag = v.getTag();
1909 String desc = "Collision while binding workspace item: " + item
1910 + ". Collides with " + tag;
Sunny Goyal3d706ad2017-03-06 16:56:39 -08001911 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001912 throw (new RuntimeException(desc));
1913 } else {
1914 Log.d(TAG, desc);
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001915 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001916 continue;
1917 }
1918 }
1919 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05301920 workspace.addInScreenFromBind(view, item);
Sunny Goyal639e9062015-08-19 19:17:06 -07001921 if (animateIcons) {
1922 // Animate all the applications up now
1923 view.setAlpha(0f);
1924 view.setScaleX(0f);
1925 view.setScaleY(0f);
1926 bounceAnims.add(createNewAppBounceAnimation(view, i));
Sunny Goyal3be633b2016-12-08 09:59:25 -08001927 newItemsScreenId = item.screenId;
Sunny Goyal639e9062015-08-19 19:17:06 -07001928 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001929 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07001930
Winson Chung997a9232013-07-24 15:33:46 -07001931 if (animateIcons) {
1932 // Animate to the correct page
Sunny Goyal3be633b2016-12-08 09:59:25 -08001933 if (newItemsScreenId > -1) {
Winson Chung997a9232013-07-24 15:33:46 -07001934 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Sunny Goyal3be633b2016-12-08 09:59:25 -08001935 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07001936 final Runnable startBounceAnimRunnable = new Runnable() {
1937 public void run() {
1938 anim.playTogether(bounceAnims);
1939 anim.start();
1940 }
1941 };
Sunny Goyal3be633b2016-12-08 09:59:25 -08001942 if (newItemsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07001943 // We post the animation slightly delayed to prevent slowdowns
1944 // when we are loading right after we return to launcher.
1945 mWorkspace.postDelayed(new Runnable() {
1946 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00001947 if (mWorkspace != null) {
Jon Miranda64eb8ea2018-03-29 11:43:58 -07001948 AbstractFloatingView.closeAllOpenViews(Launcher.this, false);
1949
Ian Parkinson94449152014-01-21 13:09:59 +00001950 mWorkspace.snapToPage(newScreenIndex);
1951 mWorkspace.postDelayed(startBounceAnimRunnable,
1952 NEW_APPS_ANIMATION_DELAY);
1953 }
Winson Chung94d67682013-09-25 16:29:40 -07001954 }
1955 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07001956 } else {
1957 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07001958 }
1959 }
Winson Chung64359a52013-07-08 17:17:08 -07001960 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001961 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 }
1963
Joe Onorato9c1289c2009-08-17 11:03:03 -04001964 /**
1965 * Add the views for a widget to the workspace.
Joe Onorato9c1289c2009-08-17 11:03:03 -04001966 */
Sunny Goyala9a1a212017-08-18 01:03:21 -07001967 public void bindAppWidget(LauncherAppWidgetInfo item) {
1968 View view = inflateAppWidget(item);
1969 if (view != null) {
1970 mWorkspace.addInScreen(view, item);
1971 mWorkspace.requestLayout();
1972 }
1973 }
1974
1975 private View inflateAppWidget(LauncherAppWidgetInfo item) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001976 if (mIsSafeModeEnabled) {
Sunny Goyald5462aa2016-11-22 16:52:39 +05301977 PendingAppWidgetHostView view =
1978 new PendingAppWidgetHostView(this, item, mIconCache, true);
1979 prepareAppWidget(view, item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07001980 return view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001981 }
1982
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001983 TraceHelper.beginSection("BIND_WIDGET");
Joe Onorato9c1289c2009-08-17 11:03:03 -04001984
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001985 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08001986
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001987 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
1988 // If the provider is not ready, bind as a pending widget.
1989 appWidgetInfo = null;
1990 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
1991 // The widget id is not valid. Try to find the widget based on the provider info.
1992 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
1993 } else {
1994 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
1995 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07001996
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001997 // If the provider is ready, but the width is not yet restored, try to restore it.
1998 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
1999 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07002000 if (appWidgetInfo == null) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002001 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
2002 + " belongs to component " + item.providerName
2003 + ", as the provider is null");
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002004 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002005 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002006 }
Sunny Goyalff572272014-07-23 13:58:07 -07002007
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002008 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002009 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyald478c832016-04-01 12:04:16 -07002010 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
2011 // Id has not been allocated yet. Allocate a new id.
2012 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
2013 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyalff572272014-07-23 13:58:07 -07002014
Sunny Goyald478c832016-04-01 12:04:16 -07002015 // Also try to bind the widget. If the bind fails, the user will be shown
2016 // a click to setup UI, which will ask for the bind permission.
Sunny Goyala52ecb02016-12-16 15:04:51 -08002017 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
Sunny Goyald478c832016-04-01 12:04:16 -07002018 pendingInfo.spanX = item.spanX;
2019 pendingInfo.spanY = item.spanY;
2020 pendingInfo.minSpanX = item.minSpanX;
2021 pendingInfo.minSpanY = item.minSpanY;
2022 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyal86df1382016-08-10 15:03:22 -07002023
2024 boolean isDirectConfig =
2025 item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
2026 if (isDirectConfig && item.bindOptions != null) {
2027 Bundle newOptions = item.bindOptions.getExtras();
2028 if (options != null) {
2029 newOptions.putAll(options);
2030 }
2031 options = newOptions;
2032 }
Sunny Goyald478c832016-04-01 12:04:16 -07002033 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2034 item.appWidgetId, appWidgetInfo, options);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002035
Sunny Goyal86df1382016-08-10 15:03:22 -07002036 // We tried to bind once. If we were not able to bind, we would need to
2037 // go through the permission dialog, which means we cannot skip the config
2038 // activity.
2039 item.bindOptions = null;
2040 item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
2041
Sunny Goyald478c832016-04-01 12:04:16 -07002042 // Bind succeeded
2043 if (success) {
2044 // If the widget has a configure activity, it is still needs to set it up,
2045 // otherwise the widget is ready to go.
Sunny Goyal86df1382016-08-10 15:03:22 -07002046 item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
Sunny Goyald478c832016-04-01 12:04:16 -07002047 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
2048 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002049 }
Sunny Goyald478c832016-04-01 12:04:16 -07002050
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002051 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002052 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002053 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002054 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002055 // The widget was marked as UI not ready, but there is no configure activity to
2056 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002057 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002058 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002059 }
Sunny Goyalff572272014-07-23 13:58:07 -07002060 }
2061
Sunny Goyald5462aa2016-11-22 16:52:39 +05302062 final AppWidgetHostView view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002063 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002064 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002065 if (appWidgetInfo == null) {
Sunny Goyal713edfc2016-05-06 09:58:34 -07002066 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Sunny Goyal56c73602015-09-25 12:55:01 -07002067 deleteWidgetInfo(item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002068 return null;
Sunny Goyal56c73602015-09-25 12:55:01 -07002069 }
2070
Sunny Goyal233ee962015-08-03 13:05:01 -07002071 item.minSpanX = appWidgetInfo.minSpanX;
2072 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyald5462aa2016-11-22 16:52:39 +05302073 view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
Sunny Goyal651077b2014-06-30 14:15:31 -07002074 } else {
Sunny Goyald5462aa2016-11-22 16:52:39 +05302075 view = new PendingAppWidgetHostView(this, item, mIconCache, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07002076 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302077 prepareAppWidget(view, item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002078
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002079 TraceHelper.endSection("BIND_WIDGET", "id=" + item.appWidgetId);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002080 return view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002081 }
2082
Sunny Goyalff572272014-07-23 13:58:07 -07002083 /**
2084 * Restores a pending widget.
2085 *
2086 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07002087 */
Sunny Goyald478c832016-04-01 12:04:16 -07002088 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07002089 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
2090 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
2091 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07002092 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002093 }
2094
Sunny Goyal0fc1be12014-08-11 17:05:23 -07002095 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07002096 info.restoreStatus = finalRestoreFlag;
Jon Miranda2b823f42017-05-02 18:36:18 -07002097 if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2098 info.pendingItemInfo = null;
2099 }
Sunny Goyalff572272014-07-23 13:58:07 -07002100
Sunny Goyalba47faa2017-10-04 16:50:57 -07002101 if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
Sunny Goyal29947f02017-12-18 13:49:44 -08002102 view.reInflate();
Sunny Goyalba47faa2017-10-04 16:50:57 -07002103 }
2104
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002105 getModelWriter().updateItemInDatabase(info);
Sunny Goyald478c832016-04-01 12:04:16 -07002106 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07002107 }
2108
Adam Cohen1462de32012-07-24 22:34:36 -07002109 public void onPageBoundSynchronously(int page) {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002110 mSynchronouslyBoundPage = page;
Adam Cohen1462de32012-07-24 22:34:36 -07002111 }
2112
Sunny Goyal527c7d32015-08-28 15:19:36 -07002113 @Override
2114 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
2115 if (mPendingExecutor != null) {
2116 mPendingExecutor.markCompleted();
2117 }
2118 mPendingExecutor = executor;
Sunny Goyal60180b02018-02-07 12:56:30 -08002119 if (!isInState(ALL_APPS)) {
2120 mAppsView.getAppsStore().setDeferUpdates(true);
2121 mPendingExecutor.execute(() -> mAppsView.getAppsStore().setDeferUpdates(false));
2122 }
2123
Sunny Goyal527c7d32015-08-28 15:19:36 -07002124 executor.attachTo(this);
2125 }
2126
2127 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
2128 if (mPendingExecutor == executor) {
2129 mPendingExecutor = null;
2130 }
2131 }
2132
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002133 @Override
2134 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002135 if (mDragLayer.getAlpha() < 1) {
Sunny Goyal29947f02017-12-18 13:49:44 -08002136 mDragLayer.animate().alpha(1).withEndAction(
2137 executor == null ? null : executor::onLoadAnimationCompleted).start();
2138 } else if (executor != null) {
2139 executor.onLoadAnimationCompleted();
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002140 }
2141 }
2142
Joe Onorato9c1289c2009-08-17 11:03:03 -04002143 /**
2144 * Callback saying that there aren't any more items to bind.
2145 *
2146 * Implementation of the method from LauncherModel.Callbacks.
2147 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08002148 public void finishBindingItems() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002149 TraceHelper.beginSection("finishBindingItems");
Adam Cohen1462de32012-07-24 22:34:36 -07002150 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002151
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002152 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07002153
Sunny Goyal2100c782016-08-22 16:00:03 -07002154 if (mPendingActivityResult != null) {
2155 handleActivityResult(mPendingActivityResult.requestCode,
2156 mPendingActivityResult.resultCode, mPendingActivityResult.data);
2157 mPendingActivityResult = null;
Adam Cohendb364c32014-05-20 14:23:40 -07002158 }
2159
Sunny Goyala474a9b2017-05-04 16:47:11 -07002160 InstallShortcutReceiver.disableAndFlushInstallQueue(
2161 InstallShortcutReceiver.FLAG_LOADER_RUNNING, this);
Adam Cohen9211d422014-10-07 18:14:53 -07002162
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002163 TraceHelper.endSection("finishBindingItems");
Winson Chungf0c6ae02012-03-21 16:10:31 -07002164 }
2165
Winson Chunga2413752012-04-03 14:22:34 -07002166 private boolean canRunNewAppsAnimation() {
2167 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07002168 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07002169 }
2170
Winson Chungc9168342013-06-26 14:54:55 -07002171 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07002172 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07002173 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
2174 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07002175 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07002176 return bounceAnim;
2177 }
2178
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002179 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002180 * Add the icons for all apps.
2181 *
2182 * Implementation of the method from LauncherModel.Callbacks.
2183 */
Sunny Goyal29947f02017-12-18 13:49:44 -08002184 public void bindAllApplications(ArrayList<AppInfo> apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002185 mAppsView.getAppsStore().setApps(apps);
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002186
Adam Cohen9211d422014-10-07 18:14:53 -07002187 if (mLauncherCallbacks != null) {
2188 mLauncherCallbacks.bindAllApplications(apps);
2189 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002190 }
2191
2192 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002193 * Copies LauncherModel's map of activities to shortcut ids to Launcher's. This is necessary
2194 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
2195 */
2196 @Override
2197 public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMapCopy) {
Tony Wickham010d2552017-01-20 08:15:28 -08002198 mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
Tony Wickham1bce7fd2016-04-28 17:39:03 -07002199 }
2200
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002201 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002202 * A package was updated.
2203 *
2204 * Implementation of the method from LauncherModel.Callbacks.
2205 */
Sunny Goyal29947f02017-12-18 13:49:44 -08002206 @Override
2207 public void bindAppsAddedOrUpdated(ArrayList<AppInfo> apps) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002208 mAppsView.getAppsStore().addOrUpdateApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002209 }
2210
Sunny Goyal4390ace2014-10-13 11:33:11 -07002211 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002212 public void bindPromiseAppProgressUpdated(PromiseAppInfo app) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002213 mAppsView.getAppsStore().updatePromiseAppProgress(app);
Mario Bertschler08ffaae2017-03-20 11:30:27 -07002214 }
2215
2216 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002217 public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002218 mWorkspace.widgetsRestored(widgets);
2219 }
2220
Joe Onorato9c1289c2009-08-17 11:03:03 -04002221 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002222 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002223 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002224 *
2225 * @param updated list of shortcuts which have changed.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002226 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07002227 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002228 public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated, final UserHandle user) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07002229 if (!updated.isEmpty()) {
2230 mWorkspace.updateShortcuts(updated);
2231 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002232 }
2233
2234 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002235 * Update the state of a package, typically related to install state.
2236 *
2237 * Implementation of the method from LauncherModel.Callbacks.
2238 */
Sunny Goyale755d462014-07-22 13:48:29 -07002239 @Override
Sunny Goyal29947f02017-12-18 13:49:44 -08002240 public void bindRestoreItemsChange(HashSet<ItemInfo> updates) {
Sunny Goyal756adbc2015-04-16 15:20:51 -07002241 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07002242 }
2243
2244 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002245 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07002246 * in addition to specific applications to remove, the reason being that
2247 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002248 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07002249 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002250 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07002251 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002252 public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002253 mWorkspace.removeItemsByMatcher(matcher);
2254 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002255 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07002256
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002257 @Override
2258 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
Sunny Goyal60180b02018-02-07 12:56:30 -08002259 mAppsView.getAppsStore().removeApps(appInfos);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002260 }
Joe Onoratobe386092009-11-17 17:32:16 -08002261
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002262 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002263 public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
2264 mPopupDataProvider.setAllWidgets(allWidgets);
Tony Wickham26b17462017-03-20 17:12:24 -07002265 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
2266 if (topView != null) {
2267 topView.onWidgetsBound();
2268 }
2269 }
2270
Tony Wickham86222d22017-03-29 15:30:43 -07002271 /**
2272 * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only
2273 * refreshes the widgets and shortcuts associated with the given package/user
2274 */
2275 public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) {
Sunny Goyalc6e97692017-06-02 13:46:55 -07002276 mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002277 }
2278
Winson Chung80baf5a2010-08-09 16:03:15 -07002279 /**
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002280 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
Joe Onoratobe386092009-11-17 17:32:16 -08002281 */
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002282 @Override
2283 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2284 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002285
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002286 if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
2287 writer.println(prefix + "Workspace Items");
Sunny Goyal7ce471b2017-08-02 03:37:39 -07002288 for (int i = 0; i < mWorkspace.getPageCount(); i++) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002289 writer.println(prefix + " Homescreen " + i);
2290
2291 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
2292 for (int j = 0; j < layout.getChildCount(); j++) {
2293 Object tag = layout.getChildAt(j).getTag();
2294 if (tag != null) {
2295 writer.println(prefix + " " + tag.toString());
2296 }
2297 }
2298 }
2299
2300 writer.println(prefix + " Hotseat");
2301 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
Sunny Goyala1365452015-10-01 15:46:24 -07002302 for (int j = 0; j < layout.getChildCount(); j++) {
2303 Object tag = layout.getChildAt(j).getTag();
2304 if (tag != null) {
2305 writer.println(prefix + " " + tag.toString());
2306 }
Adam Cohen4caf2982013-08-20 18:54:31 -07002307 }
Sunny Goyala1365452015-10-01 15:46:24 -07002308 }
2309
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002310 writer.println(prefix + "Misc:");
2311 writer.print(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
2312 writer.print(" mPendingRequestArgs=" + mPendingRequestArgs);
2313 writer.println(" mPendingActivityResult=" + mPendingActivityResult);
Sunny Goyal2bba1902018-02-27 12:20:50 -08002314 writer.println(" deviceProfile isTransposed=" + getDeviceProfile().isVerticalBarLayout());
2315 writer.println(" orientation=" + getResources().getConfiguration().orientation);
2316
2317 try {
2318 FileLog.flushAll(writer);
2319 } catch (Exception e) {
2320 // Ignore
2321 }
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002322
2323 mModel.dumpState(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002324
Adam Cohen9211d422014-10-07 18:14:53 -07002325 if (mLauncherCallbacks != null) {
2326 mLauncherCallbacks.dump(prefix, fd, writer, args);
2327 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002328 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07002329
Sunny Goyal66b24572016-09-21 15:57:55 -07002330 @Override
2331 @TargetApi(Build.VERSION_CODES.N)
2332 public void onProvideKeyboardShortcuts(
2333 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
2334
2335 ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002336 if (isInState(NORMAL)) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002337 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
2338 KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
2339 }
2340 View currentFocus = getCurrentFocus();
2341 if (new CustomActionsPopup(this, currentFocus).canShow()) {
2342 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions),
2343 KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
2344 }
Tony18c4aa42017-05-10 21:23:57 -05002345 if (currentFocus.getTag() instanceof ItemInfo
2346 && DeepShortcutManager.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002347 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.action_deep_shortcut),
2348 KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
2349 }
2350 if (!shortcutInfos.isEmpty()) {
2351 data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
2352 }
2353
2354 super.onProvideKeyboardShortcuts(data, menu, deviceId);
2355 }
2356
2357 @Override
2358 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2359 if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
2360 switch (keyCode) {
2361 case KeyEvent.KEYCODE_A:
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002362 if (isInState(NORMAL)) {
2363 getStateManager().goToState(ALL_APPS);
Sunny Goyal66b24572016-09-21 15:57:55 -07002364 return true;
2365 }
2366 break;
2367 case KeyEvent.KEYCODE_S: {
2368 View focusedView = getCurrentFocus();
2369 if (focusedView instanceof BubbleTextView
2370 && focusedView.getTag() instanceof ItemInfo
2371 && mAccessibilityDelegate.performAction(focusedView,
2372 (ItemInfo) focusedView.getTag(),
2373 LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) {
Sunny Goyal00ac9202017-11-09 15:24:06 -08002374 PopupContainerWithArrow.getOpen(this).requestFocus();
Sunny Goyal66b24572016-09-21 15:57:55 -07002375 return true;
2376 }
2377 break;
2378 }
2379 case KeyEvent.KEYCODE_O:
2380 if (new CustomActionsPopup(this, getCurrentFocus()).show()) {
2381 return true;
2382 }
2383 break;
2384 }
2385 }
2386 return super.onKeyShortcut(keyCode, event);
2387 }
2388
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002389 @Override
2390 public boolean onKeyUp(int keyCode, KeyEvent event) {
2391 if (keyCode == KeyEvent.KEYCODE_MENU) {
2392 // KEYCODE_MENU is sent by some tests, for example
2393 // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling.
2394 if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() &&
2395 isInState(NORMAL)) {
2396 // Close any open floating views.
2397 AbstractFloatingView.closeAllOpenViews(this);
2398
2399 // Setting the touch point to (-1, -1) will show the options popup in the center of
2400 // the screen.
Sunny Goyal2fd7a8b2018-03-30 17:10:13 -07002401 OptionsPopupView.showDefaultOptions(this, -1, -1);
Vadim Tryshev646a0dd2018-02-05 16:27:50 -08002402 }
2403 return true;
2404 }
2405 return super.onKeyUp(keyCode, event);
2406 }
2407
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07002408 public static Launcher getLauncher(Context context) {
2409 if (context instanceof Launcher) {
2410 return (Launcher) context;
2411 }
2412 return ((Launcher) ((ContextWrapper) context).getBaseContext());
2413 }
2414
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002415 /**
2416 * Callback for listening for onResume
2417 */
2418 public interface OnResumeCallback {
2419
2420 void onLauncherResume();
2421 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002422}