blob: a403f710676c78820d852757fe8c7621697b4be3 [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 Goyalc99cb172017-10-19 16:15:09 -070019import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
20import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
21
Sunny Goyal076839c2017-10-30 13:52:20 -070022import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_BY_PUBLISHER;
23import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER;
24import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_QUIET_USER;
25import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_SAFEMODE;
26import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED;
Sunny Goyal4c7f2152017-10-17 17:17:16 -070027import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
Sunny Goyal3e3f44c2017-10-23 17:14:52 -070028import static com.android.launcher3.LauncherState.ALL_APPS;
29import static com.android.launcher3.LauncherState.NORMAL;
30import static com.android.launcher3.LauncherState.OVERVIEW;
Sunny Goyalaeb16432017-10-16 11:46:41 -070031import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
Sunny Goyal326403e2017-10-02 12:45:10 -070032import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS;
33import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS;
34
Sunny Goyal28c6b962015-10-12 11:42:05 -070035import android.Manifest;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070036import android.animation.Animator;
Jon Miranda2d89ea82017-05-04 11:47:53 -070037import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070038import android.animation.AnimatorSet;
Jon Miranda2d89ea82017-05-04 11:47:53 -070039import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070040import android.animation.ValueAnimator;
Sunny Goyal70660032015-05-14 00:07:08 -070041import android.annotation.SuppressLint;
Adam Cohen0b395352014-06-09 22:54:36 +000042import android.annotation.TargetApi;
Winson Chungc7450e32012-04-17 17:34:08 -070043import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040044import android.app.AlertDialog;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080045import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070046import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080048import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080049import android.content.ComponentCallbacks2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.Context;
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070051import android.content.ContextWrapper;
Chris Wren40c5ed32014-06-24 18:24:23 -040052import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070054import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070055import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070056import android.content.SharedPreferences;
Sunny Goyal745bad92016-05-02 10:54:12 -070057import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058import android.content.pm.PackageManager;
Adam Cohen3f9c9712014-10-31 11:48:25 -070059import android.database.sqlite.SQLiteDatabase;
Jon Mirandacc42c5b2016-10-27 17:15:27 -070060import android.graphics.Point;
Michael Jurkaaf442092010-06-10 17:01:57 -070061import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070062import android.graphics.drawable.Drawable;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070063import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020064import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.os.Bundle;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070066import android.os.Parcelable;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080067import android.os.Process;
Winson Chunga2413752012-04-03 14:22:34 -070068import android.os.StrictMode;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070069import android.os.UserHandle;
Tony Wickham86222d22017-03-29 15:30:43 -070070import android.support.annotation.Nullable;
Michael Jurkaa33411c2012-06-14 16:18:21 -070071import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -070074import android.util.SparseArray;
Sunny Goyal7c8a65e2017-12-22 11:11:33 -080075import android.view.ActionMode;
Adam Cohen96d30a12013-07-16 18:13:21 -070076import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070077import android.view.HapticFeedbackConstants;
78import android.view.KeyEvent;
Sunny Goyal66b24572016-09-21 15:57:55 -070079import android.view.KeyboardShortcutGroup;
80import android.view.KeyboardShortcutInfo;
Sunny Goyal9b29ca52017-02-17 10:39:44 -080081import android.view.LayoutInflater;
Adam Cohen96d30a12013-07-16 18:13:21 -070082import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070083import android.view.MotionEvent;
Adam Cohen96d30a12013-07-16 18:13:21 -070084import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080085import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080087import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070088import android.view.animation.OvershootInterpolator;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070090
Sunny Goyal651077b2014-06-30 14:15:31 -070091import com.android.launcher3.DropTarget.DragObject;
Sunny Goyala7ce1662016-05-31 15:01:35 -070092import com.android.launcher3.LauncherSettings.Favorites;
Jon Mirandac476d6e2017-05-04 16:30:01 -070093import com.android.launcher3.Workspace.ItemOperator;
Sunny Goyalae502842016-06-17 08:43:56 -070094import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070095import com.android.launcher3.allapps.AllAppsContainerView;
Hyunyoung Song645764e2016-06-06 14:19:02 -070096import com.android.launcher3.allapps.AllAppsTransitionController;
Sunny Goyal7ede6112017-12-05 15:11:21 -080097import com.android.launcher3.allapps.DiscoveryBounce;
Sunny Goyalffe83f12014-08-14 17:39:34 -070098import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +010099import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700100import com.android.launcher3.compat.LauncherAppsCompatVO;
Tony Wickhame0c33232016-02-08 11:37:04 -0800101import com.android.launcher3.config.FeatureFlags;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700102import com.android.launcher3.dragndrop.DragController;
103import com.android.launcher3.dragndrop.DragLayer;
Sunny Goyal94b510c2016-08-16 15:36:48 -0700104import com.android.launcher3.dragndrop.DragOptions;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700105import com.android.launcher3.dragndrop.DragView;
Mario Bertschler27288382017-05-24 15:35:09 -0700106import com.android.launcher3.dynamicui.WallpaperColorInfo;
Sunny Goyal26119432016-02-18 22:09:23 +0000107import com.android.launcher3.folder.Folder;
108import com.android.launcher3.folder.FolderIcon;
Sunny Goyal66b24572016-09-21 15:57:55 -0700109import com.android.launcher3.keyboard.CustomActionsPopup;
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700110import com.android.launcher3.keyboard.ViewGroupFocusHelper;
Sunny Goyala7ce1662016-05-31 15:01:35 -0700111import com.android.launcher3.logging.FileLog;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700112import com.android.launcher3.logging.UserEventDispatcher;
Sunny Goyala535ae42017-02-27 10:07:13 -0800113import com.android.launcher3.model.ModelWriter;
Sunny Goyala535ae42017-02-27 10:07:13 -0800114import com.android.launcher3.notification.NotificationListener;
Tony Wickham540913e2017-01-23 11:47:51 -0800115import com.android.launcher3.popup.PopupContainerWithArrow;
Sunny Goyala535ae42017-02-27 10:07:13 -0800116import com.android.launcher3.popup.PopupDataProvider;
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700117import com.android.launcher3.shortcuts.DeepShortcutManager;
Sunny Goyalf8088ee2017-11-10 14:52:00 -0800118import com.android.launcher3.states.InternalStateHandler;
Sunny Goyala5ace712017-11-15 17:12:51 -0800119import com.android.launcher3.uioverrides.UiFactory;
Jon Mirandac6cf4932017-02-07 17:12:36 -0800120import com.android.launcher3.userevent.nano.LauncherLogProto;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +0530121import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
122import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
Sunny Goyalaeb16432017-10-16 11:46:41 -0700123import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyal2100c782016-08-22 16:00:03 -0700124import com.android.launcher3.util.ActivityResultInfo;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700125import com.android.launcher3.util.ComponentKey;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700126import com.android.launcher3.util.ItemInfoMatcher;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700127import com.android.launcher3.util.MultiHashMap;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700128import com.android.launcher3.util.PackageManagerHelper;
Tony Wickham010d2552017-01-20 08:15:28 -0800129import com.android.launcher3.util.PackageUserKey;
Sunny Goyal2100c782016-08-22 16:00:03 -0700130import com.android.launcher3.util.PendingRequestArgs;
Sunny Goyal326403e2017-10-02 12:45:10 -0700131import com.android.launcher3.util.RunnableWithId;
Sunny Goyal8392c822017-06-20 10:03:56 -0700132import com.android.launcher3.util.SystemUiController;
Mario Bertschlera6936942017-05-31 14:48:19 -0700133import com.android.launcher3.util.Themes;
Adam Cohen091440a2015-03-18 14:16:05 -0700134import com.android.launcher3.util.Thunk;
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700135import com.android.launcher3.util.TraceHelper;
Sunny Goyal326403e2017-10-02 12:45:10 -0700136import com.android.launcher3.util.UiThreadHelper;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700137import com.android.launcher3.util.ViewOnDrawExecutor;
Sunny Goyal782f0c92017-01-19 10:27:54 -0800138import com.android.launcher3.widget.PendingAddShortcutInfo;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700139import com.android.launcher3.widget.PendingAddWidgetInfo;
Sunny Goyal04a324a2017-01-20 21:08:59 -0800140import com.android.launcher3.widget.WidgetAddFlowHandler;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700141import com.android.launcher3.widget.WidgetHostViewLoader;
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700142import com.android.launcher3.widget.WidgetListRowEntry;
143import com.android.launcher3.widget.WidgetsFullSheet;
Sunny Goyal952e63d2017-08-16 04:59:08 -0700144import com.android.launcher3.widget.custom.CustomWidgetParser;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700145
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700146import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700147import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700148import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700149import java.util.Collection;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700150import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700151import java.util.List;
Tony Wickham010d2552017-01-20 08:15:28 -0800152import java.util.Set;
Tony2917a8b2017-07-31 23:29:42 -0700153import java.util.concurrent.Executor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700154
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155/**
156 * Default launcher application.
157 */
Sunny Goyal27835952017-01-13 12:15:53 -0800158public class Launcher extends BaseActivity
Adam Cohen79d90c52016-04-22 13:29:20 -0700159 implements LauncherExterns, View.OnClickListener, OnLongClickListener,
160 LauncherModel.Callbacks, View.OnTouchListener, LauncherProviderChangeListener,
Mario Bertschler27288382017-05-24 15:35:09 -0700161 WallpaperColorInfo.OnThemeChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700162 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700163 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164
Winson Chunga2413752012-04-03 14:22:34 -0700165 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700166
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700168 private static final int REQUEST_CREATE_APPWIDGET = 5;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700169
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700170 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700171 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172
Michael Jurka8b805b12012-04-18 14:23:14 -0700173 private static final int REQUEST_BIND_APPWIDGET = 11;
Jon Mirandac476d6e2017-05-04 16:30:01 -0700174 private static final int REQUEST_BIND_PENDING_APPWIDGET = 12;
175 private static final int REQUEST_RECONFIGURE_APPWIDGET = 13;
Michael Jurka8b805b12012-04-18 14:23:14 -0700176
Jon Mirandac476d6e2017-05-04 16:30:01 -0700177 private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
Sunny Goyal28c6b962015-10-12 11:42:05 -0700178
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700179 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
180
Mathew Inwood876a8462013-06-14 14:12:41 +0100181 /**
182 * IntentStarter uses request codes starting with this. This must be greater than all activity
183 * request codes used internally.
184 */
185 protected static final int REQUEST_LAST = 100;
186
Winson Chung2672ff92012-05-04 16:22:30 -0700187 // The Intent extra that defines whether to ignore the launch animation
188 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400189 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700190
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 // Type: int
192 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700193 // Type: int
194 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal2100c782016-08-22 16:00:03 -0700195 // Type: PendingRequestArgs
196 private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args";
197 // Type: ActivityResultInfo
198 private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700199 // Type: SparseArray<Parcelable>
200 private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800201
Sunny Goyal7c8a65e2017-12-22 11:11:33 -0800202 // When starting an action mode, setting this tag will cause the action mode to be cancelled
203 // automatically when user interacts with the launcher.
204 public static final Object AUTO_CANCEL_ACTION_MODE = new Object();
205
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700206 private LauncherStateManager mStateManager;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700207
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700208 private boolean mIsSafeModeEnabled;
209
Adam Cohenad4e15c2013-10-17 16:21:35 -0700210 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211
Winson Chunga2413752012-04-03 14:22:34 -0700212 // How long to wait before the new-shortcut animation automatically pans the workspace
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700213 private static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
214 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
215 @Thunk static final int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700216
Adam Cohen091440a2015-03-18 14:16:05 -0700217 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700218 private View mLauncherView;
Adam Cohen091440a2015-03-18 14:16:05 -0700219 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800220 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700221
Sunny Goyalffe83f12014-08-14 17:39:34 -0700222 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700223 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700224
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700225 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700226
Sunny Goyal316490e2015-06-02 09:38:28 -0700227 @Thunk Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700228
Sunny Goyal47328fd2016-05-25 18:56:41 -0700229 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700230
231 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700232 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700233 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700234
Winson Chung8ae41982017-11-10 11:42:13 -0800235 // UI and state for the overview panel
236 private ViewGroup mOverviewPanel;
237
Jon Miranda6bed3502017-09-19 14:43:17 -0700238 // We need to store the orientation Launcher was created with, due to a bug (b/64916689)
239 // that results in widgets being inflated in the wrong orientation.
240 private int mOrientation;
241
Adam Cohen091440a2015-03-18 14:16:05 -0700242 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400243
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800244 private boolean mPaused = true;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700245 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700247 private final ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<>();
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700248 private OnResumeCallback mOnResumeCallback;
249
Sunny Goyal527c7d32015-08-28 15:19:36 -0700250 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700251
Joe Onorato9c1289c2009-08-17 11:03:03 -0400252 private LauncherModel mModel;
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800253 private ModelWriter mModelWriter;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800254 private IconCache mIconCache;
Sunny Goyalae502842016-06-17 08:43:56 -0700255 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400256
Jon Miranda2d89ea82017-05-04 11:47:53 -0700257 private ObjectAnimator mScrimAnimator;
Jon Miranda7fda2852017-07-19 16:07:01 -0700258 private boolean mShouldFadeInScrim;
Jon Miranda2d89ea82017-05-04 11:47:53 -0700259
Tony Wickham010d2552017-01-20 08:15:28 -0800260 private PopupDataProvider mPopupDataProvider;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700261
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800262 private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE;
Adam Cohen1462de32012-07-24 22:34:36 -0700263
Winson Chung46353de2012-02-16 14:05:10 -0800264 // We only want to get the SharedPreferences once since it does an FS stat each time we get
265 // it from the context.
266 private SharedPreferences mSharedPrefs;
267
Sunny Goyal2100c782016-08-22 16:00:03 -0700268 // Activity result which needs to be processed after workspace has loaded.
269 private ActivityResultInfo mPendingActivityResult;
270 /**
271 * Holds extra information required to handle a result from an external call, like
272 * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)}
273 */
274 private PendingRequestArgs mPendingRequestArgs;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800275
Jon Miranda379198e2016-09-23 08:54:40 -0700276 private float mLastDispatchTouchEventX = 0.0f;
Jon Miranda379198e2016-09-23 08:54:40 -0700277
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700278 public ViewGroupFocusHelper mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700279 private boolean mRotationEnabled = false;
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700280 private boolean mAppLaunchSuccess;
281
Sunny Goyal745bad92016-05-02 10:54:12 -0700282 private RotationPrefChangeHandler mRotationPrefChangeHandler;
Sunny Goyal7c8a65e2017-12-22 11:11:33 -0800283 private ActionMode mCurrentActionMode;
Sunny Goyal7779d622015-06-11 16:18:39 -0700284
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285 @Override
286 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700287 if (DEBUG_STRICT_MODE) {
288 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
289 .detectDiskReads()
290 .detectDiskWrites()
291 .detectNetwork() // or .detectAll() for all detectable problems
292 .penaltyLog()
293 .build());
294 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
295 .detectLeakedSqlLiteObjects()
296 .detectLeakedClosableObjects()
297 .penaltyLog()
298 .penaltyDeath()
299 .build());
300 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700301 TraceHelper.beginSection("Launcher-onCreate");
Winson Chunga2413752012-04-03 14:22:34 -0700302
Adam Cohen9211d422014-10-07 18:14:53 -0700303 if (mLauncherCallbacks != null) {
304 mLauncherCallbacks.preOnCreate();
305 }
306
Mario Bertschler27288382017-05-24 15:35:09 -0700307 WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
308 wallpaperColorInfo.setOnThemeChangeListener(this);
Mario Bertschlera6936942017-05-31 14:48:19 -0700309 overrideTheme(wallpaperColorInfo.isDark(), wallpaperColorInfo.supportsDarkText());
Mario Bertschler27288382017-05-24 15:35:09 -0700310
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800311 super.onCreate(savedInstanceState);
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700312 TraceHelper.partitionSection("Launcher-onCreate", "super call");
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400313
Sunny Goyal87f784c2017-01-11 10:48:34 -0800314 LauncherAppState app = LauncherAppState.getInstance(this);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700315
Adam Cohen2e6da152015-05-06 11:42:25 -0700316 // Load configuration-specific DeviceProfile
Sunny Goyal27835952017-01-13 12:15:53 -0800317 mDeviceProfile = app.getInvariantDeviceProfile().getDeviceProfile(this);
Jon Mirandafe964322017-03-22 10:25:17 -0700318 if (isInMultiWindowModeCompat()) {
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700319 Display display = getWindowManager().getDefaultDisplay();
320 Point mwSize = new Point();
321 display.getSize(mwSize);
322 mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
323 }
Sunny Goyalc6205602015-05-21 20:46:33 -0700324
Jon Miranda6bed3502017-09-19 14:43:17 -0700325 mOrientation = getResources().getConfiguration().orientation;
Sunny Goyalf7258242015-10-19 16:59:07 -0700326 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700327 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800328 mModel = app.setLauncher(this);
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800329 mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout());
Joe Onorato0589f0f2010-02-08 13:44:00 -0800330 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700331 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700332
Joe Onorato41a12d22009-10-31 18:30:00 -0400333 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700334 mAllAppsController = new AllAppsTransitionController(this);
Sunny Goyalc4fa8c32017-11-07 12:23:58 -0800335 mStateManager = new LauncherStateManager(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700336
Sunny Goyalffe83f12014-08-14 17:39:34 -0700337 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700338
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700339 mAppWidgetHost = new LauncherAppWidgetHost(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700340 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700341
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700342 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
343 // this also ensures that any synchronous binding below doesn't re-trigger another
344 // LauncherModel load.
345 mPaused = false;
346
Sunny Goyal60820d72017-05-09 12:40:11 -0700347 mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
Michael Jurka7267fa52013-09-26 15:29:57 -0700348
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800349 setupViews();
Winson1f064272016-07-18 17:18:02 -0700350 mDeviceProfile.layout(this, false /* notifyListeners */);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800351
Tony Wickham010d2552017-01-20 08:15:28 -0800352 mPopupDataProvider = new PopupDataProvider(this);
353
Sunny Goyald3864fa2017-11-14 15:06:36 -0800354 mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
355 // In case we are on a device with locked rotation, we should look at preferences to check
356 // if the user has specifically allowed rotation.
357 if (!mRotationEnabled) {
358 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
359 mRotationPrefChangeHandler = new RotationPrefChangeHandler();
360 mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
361 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362
Sunny Goyald3864fa2017-11-14 15:06:36 -0800363 boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
364 if (internalStateHandled) {
365 // Temporarily enable the rotation
366 mRotationEnabled = true;
367
368 if (savedInstanceState != null) {
369 // InternalStateHandler has already set the appropriate state.
370 // We dont need to do anything.
371 savedInstanceState.remove(RUNTIME_STATE);
372 }
373 }
374 restoreState(savedInstanceState);
Winson Chungb63b44c2017-11-10 17:54:44 -0800375
Sunny Goyal2100c782016-08-22 16:00:03 -0700376 // We only load the page synchronously if the user rotates (or triggers a
377 // configuration change) while launcher is in the foreground
Sunny Goyalfe770c92016-09-27 14:38:58 -0700378 int currentScreen = PagedView.INVALID_RESTORE_PAGE;
379 if (savedInstanceState != null) {
380 currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
381 }
Sunny Goyald3864fa2017-11-14 15:06:36 -0800382
Sunny Goyalfe770c92016-09-27 14:38:58 -0700383 if (!mModel.startLoader(currentScreen)) {
Sunny Goyald3864fa2017-11-14 15:06:36 -0800384 if (!internalStateHandled) {
385 // If we are not binding synchronously, show a fade in animation when
386 // the first page bind completes.
387 mDragLayer.setAlpha(0);
388 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700389 } else {
Sunny Goyalfe770c92016-09-27 14:38:58 -0700390 // Pages bound synchronously.
391 mWorkspace.setCurrentPage(currentScreen);
392
Sunny Goyal2100c782016-08-22 16:00:03 -0700393 setWorkspaceLoading(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800394 }
395
396 // For handling default keys
Sunny Goyalf4aceab2017-12-06 16:16:31 -0800397 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800398
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700399 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
400 // we want the screen to auto-rotate based on the current orientation
Sunny Goyalc99cb172017-10-19 16:15:09 -0700401 setRequestedOrientation(mRotationEnabled
402 ? SCREEN_ORIENTATION_UNSPECIFIED : SCREEN_ORIENTATION_NOSENSOR);
Winson Chungaf40f202013-09-18 18:26:31 -0700403
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800404 setContentView(mLauncherView);
Mario Bertschlera6936942017-05-31 14:48:19 -0700405
Jon Miranda7fda2852017-07-19 16:07:01 -0700406 // Listen for broadcasts
407 IntentFilter filter = new IntentFilter();
408 filter.addAction(Intent.ACTION_SCREEN_OFF);
409 filter.addAction(Intent.ACTION_USER_PRESENT); // When the device wakes up + keyguard is gone
410 registerReceiver(mReceiver, filter);
411 mShouldFadeInScrim = true;
Sunny Goyala616d2b2017-06-12 13:54:01 -0700412
Sunny Goyal8392c822017-06-20 10:03:56 -0700413 getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
414 Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
Sunny Goyal14b32402017-07-31 10:03:28 -0700415
416 if (mLauncherCallbacks != null) {
417 mLauncherCallbacks.onCreate(savedInstanceState);
418 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700419
420 TraceHelper.endSection("Launcher-onCreate");
Adam Cohen9211d422014-10-07 18:14:53 -0700421 }
422
Sunny Goyal7779d622015-06-11 16:18:39 -0700423 @Override
Mario Bertschler27288382017-05-24 15:35:09 -0700424 public void onThemeChanged() {
425 recreate();
426 }
427
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700428 public LauncherStateManager getStateManager() {
429 return mStateManager;
Sunny Goyalbe93f262017-10-20 17:05:27 -0700430 }
431
Mario Bertschlera6936942017-05-31 14:48:19 -0700432 protected void overrideTheme(boolean isDark, boolean supportsDarkText) {
Mario Bertschler27288382017-05-24 15:35:09 -0700433 if (isDark) {
434 setTheme(R.style.LauncherThemeDark);
Mario Bertschlera6936942017-05-31 14:48:19 -0700435 } else if (supportsDarkText) {
436 setTheme(R.style.LauncherThemeDarkText);
Mario Bertschler27288382017-05-24 15:35:09 -0700437 }
438 }
439
440 @Override
Sunny Goyalc7b8df82017-06-27 11:11:03 -0700441 public <T extends View> T findViewById(int id) {
Sunny Goyal0bbd5542016-11-11 10:41:26 -0800442 return mLauncherView.findViewById(id);
443 }
444
445 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700446 public void onAppWidgetHostReset() {
447 if (mAppWidgetHost != null) {
448 mAppWidgetHost.startListening();
449 }
450 }
451
Adam Cohen9211d422014-10-07 18:14:53 -0700452 private LauncherCallbacks mLauncherCallbacks;
453
Winson1f064272016-07-18 17:18:02 -0700454 public void onInsetsChanged(Rect insets) {
455 mDeviceProfile.updateInsets(insets);
456 mDeviceProfile.layout(this, true /* notifyListeners */);
457 }
458
Sunny Goyal32554d12015-12-03 15:31:25 -0800459 /**
460 * Call this after onCreate to set or clear overlay.
461 */
462 public void setLauncherOverlay(LauncherOverlay overlay) {
463 if (overlay != null) {
464 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
465 }
466 mWorkspace.setLauncherOverlay(overlay);
467 }
468
Adam Cohen9211d422014-10-07 18:14:53 -0700469 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
470 mLauncherCallbacks = callbacks;
471 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700472 }
473
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700474 @Override
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700475 public void onLauncherProviderChanged() {
Adam Cohen9211d422014-10-07 18:14:53 -0700476 if (mLauncherCallbacks != null) {
477 mLauncherCallbacks.onLauncherProviderChange();
478 }
479 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700480
Hyunyoung Song3f471442015-04-08 19:01:34 -0700481 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700482 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
483 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700484 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700485 }
486
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000487 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700488 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
489 // This cast is safe as long as the id < 0x00FFFFFF
490 // Since we jail all the dynamically generated views, there should be no clashes
491 // with any other views.
492 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000493 }
494
Tony Wickham010d2552017-01-20 08:15:28 -0800495 public PopupDataProvider getPopupDataProvider() {
496 return mPopupDataProvider;
497 }
498
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000499 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700500 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
501 * a configuration step, this allows the proper animations to run after other transitions.
502 */
Sunny Goyal2100c782016-08-22 16:00:03 -0700503 private long completeAdd(
504 int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
505 long screenId = info.screenId;
506 if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
Adam Cohen83079e42014-09-19 17:43:08 -0700507 // When the screen id represents an actual screen (as opposed to a rank) we make sure
508 // that the drop page actually exists.
Sunny Goyal2100c782016-08-22 16:00:03 -0700509 screenId = ensurePendingDropLayoutExists(info.screenId);
Adam Cohen83079e42014-09-19 17:43:08 -0700510 }
Adam Cohendb364c32014-05-20 14:23:40 -0700511
Sunny Goyal2100c782016-08-22 16:00:03 -0700512 switch (requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800513 case REQUEST_CREATE_SHORTCUT:
Sunny Goyalfb5096d2016-09-08 14:32:06 -0700514 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
Winson Chungb8472bb2011-08-05 13:49:21 -0700515 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800516 case REQUEST_CREATE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700517 completeAddAppWidget(appWidgetId, info, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700518 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700519 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -0700520 completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700521 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700522 case REQUEST_BIND_PENDING_APPWIDGET: {
Sunny Goyal2100c782016-08-22 16:00:03 -0700523 int widgetId = appWidgetId;
524 LauncherAppWidgetInfo widgetInfo =
Sunny Goyald478c832016-04-01 12:04:16 -0700525 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
Sunny Goyal2100c782016-08-22 16:00:03 -0700526 if (widgetInfo != null) {
Sunny Goyald478c832016-04-01 12:04:16 -0700527 // Since the view was just bound, also launch the configure activity if needed
528 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
529 .getLauncherAppWidgetInfo(widgetId);
Sunny Goyal04a324a2017-01-20 21:08:59 -0800530 if (provider != null) {
531 new WidgetAddFlowHandler(provider)
532 .startConfigActivity(this, widgetInfo, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -0700533 }
534 }
535 break;
536 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800537 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700538
Adam Cohendb364c32014-05-20 14:23:40 -0700539 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800540 }
541
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800542 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700543 final int requestCode, final int resultCode, final Intent data) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700544 if (isWorkspaceLoading()) {
545 // process the result once the workspace has loaded.
546 mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
547 return;
548 }
549 mPendingActivityResult = null;
550
Winson Chunge341d302013-08-16 14:31:00 -0700551 // Reset the startActivity waiting flag
Sunny Goyal2100c782016-08-22 16:00:03 -0700552 final PendingRequestArgs requestArgs = mPendingRequestArgs;
553 setWaitingForResult(null);
554 if (requestArgs == null) {
555 return;
556 }
557
558 final int pendingAddWidgetId = requestArgs.getWidgetId();
Winson Chunge341d302013-08-16 14:31:00 -0700559
Adam Cohenad4e15c2013-10-17 16:21:35 -0700560 Runnable exitSpringLoaded = new Runnable() {
561 @Override
562 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700563 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700564 }
565 };
566
Michael Jurka8b805b12012-04-18 14:23:14 -0700567 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700568 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700569 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700570 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
571 if (resultCode == RESULT_CANCELED) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700572 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
Adam Cohen689ff162014-05-08 17:27:56 -0700573 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700574 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700575 } else if (resultCode == RESULT_OK) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700576 addAppWidgetImpl(
577 appWidgetId, requestArgs, null,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800578 requestArgs.getWidgetHandler(),
Sunny Goyal2100c782016-08-22 16:00:03 -0700579 ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700580 }
581 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200582 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700583 if (resultCode == RESULT_OK && isInState(OVERVIEW)) {
Tony Wickhame3054412015-09-09 09:05:25 -0700584 // User could have free-scrolled between pages before picking a wallpaper; make sure
585 // we move to the closest one now.
586 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700587 mStateManager.goToState(NORMAL, false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200588 }
589 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700590 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200591
Adam Cohened66b2b2012-01-23 17:28:51 -0800592 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700593 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700594
Adam Cohened66b2b2012-01-23 17:28:51 -0800595 // We have special handling for widgets
596 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800597 final int appWidgetId;
598 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
599 : -1;
600 if (widgetId < 0) {
601 appWidgetId = pendingAddWidgetId;
602 } else {
603 appWidgetId = widgetId;
604 }
605
Adam Cohenad4e15c2013-10-17 16:21:35 -0700606 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800607 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700608 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
609 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700610 result = RESULT_CANCELED;
Sunny Goyal2100c782016-08-22 16:00:03 -0700611 completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
Adam Cohendb364c32014-05-20 14:23:40 -0700612 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700613 @Override
614 public void run() {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700615 getStateManager().goToState(NORMAL);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700616 }
617 };
Adam Cohendb364c32014-05-20 14:23:40 -0700618
Sunny Goyal2100c782016-08-22 16:00:03 -0700619 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
620 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
621 } else {
622 if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
623 // When the screen id represents an actual screen (as opposed to a rank)
624 // we make sure that the drop page actually exists.
625 requestArgs.screenId =
626 ensurePendingDropLayoutExists(requestArgs.screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700627 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700628 final CellLayout dropLayout =
629 mWorkspace.getScreenWithId(requestArgs.screenId);
630
631 dropLayout.setDropPending(true);
632 final Runnable onComplete = new Runnable() {
633 @Override
634 public void run() {
635 completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
636 dropLayout.setDropPending(false);
637 }
638 };
639 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
640 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Winson Chung5aaab772012-04-27 15:24:02 -0700641 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800642 return;
643 }
644
Sunny Goyald478c832016-04-01 12:04:16 -0700645 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
646 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700647 if (resultCode == RESULT_OK) {
648 // Update the widget view.
Sunny Goyal2100c782016-08-22 16:00:03 -0700649 completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
Sunny Goyalff572272014-07-23 13:58:07 -0700650 }
651 // Leave the widget in the pending state if the user canceled the configure.
652 return;
653 }
654
Sunny Goyalaad90582015-07-09 14:22:50 -0700655 if (requestCode == REQUEST_CREATE_SHORTCUT) {
656 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
Sunny Goyal2100c782016-08-22 16:00:03 -0700657 if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
658 completeAdd(requestCode, data, -1, requestArgs);
659 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
660 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
661
Sunny Goyalaad90582015-07-09 14:22:50 -0700662 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700663 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
664 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800665 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800667 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800668 }
669
670 @Override
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700671 public void onActivityResult(
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800672 final int requestCode, final int resultCode, final Intent data) {
673 handleActivityResult(requestCode, resultCode, data);
674 if (mLauncherCallbacks != null) {
675 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
676 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800677 }
678
Sunny Goyal7ce471b2017-08-02 03:37:39 -0700679 @Override
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700680 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600681 int[] grantResults) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700682 PendingRequestArgs pendingArgs = mPendingRequestArgs;
683 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null
684 && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) {
685 setWaitingForResult(null);
686
Sunny Goyal28c6b962015-10-12 11:42:05 -0700687 View v = null;
Sunny Goyal2100c782016-08-22 16:00:03 -0700688 CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700689 if (layout != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700690 v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700691 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700692 Intent intent = pendingArgs.getPendingIntent();
693
Sunny Goyal28c6b962015-10-12 11:42:05 -0700694 if (grantResults.length > 0
695 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal85fc55a2016-05-31 10:44:03 -0700696 startActivitySafely(v, intent, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700697 } else {
698 // TODO: Show a snack bar with link to settings
699 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
Sunny Goyal112ce422016-08-22 16:45:29 -0700700 getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show();
Sunny Goyal28c6b962015-10-12 11:42:05 -0700701 }
702 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600703 if (mLauncherCallbacks != null) {
704 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
705 grantResults);
706 }
707 }
708
Adam Cohendb364c32014-05-20 14:23:40 -0700709 /**
710 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
711 *
712 * @param screenId the screen id to check
713 * @return the new screen, or screenId if it exists
714 */
715 private long ensurePendingDropLayoutExists(long screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800716 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700717 if (dropLayout == null) {
718 // it's possible that the add screen was removed because it was
719 // empty and a re-bind occurred
720 mWorkspace.addExtraEmptyScreen();
721 return mWorkspace.commitExtraEmptyScreen();
722 } else {
723 return screenId;
724 }
725 }
726
Sunny Goyal2100c782016-08-22 16:00:03 -0700727 @Thunk void completeTwoStageWidgetDrop(
728 final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
729 CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800730 Runnable onCompleteRunnable = null;
731 int animationType = 0;
732
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700733 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800734 if (resultCode == RESULT_OK) {
735 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
736 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Sunny Goyal04a324a2017-01-20 21:08:59 -0800737 requestArgs.getWidgetHandler().getProviderInfo(this));
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700738 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800739 onCompleteRunnable = new Runnable() {
740 @Override
741 public void run() {
Sunny Goyal2100c782016-08-22 16:00:03 -0700742 completeAddAppWidget(appWidgetId, requestArgs, layout, null);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700743 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohened66b2b2012-01-23 17:28:51 -0800744 }
745 };
746 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800747 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800748 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800749 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700750 if (mDragLayer.getAnimatedView() != null) {
Sunny Goyal2100c782016-08-22 16:00:03 -0700751 mWorkspace.animateWidgetDrop(requestArgs, cellLayout,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700752 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
753 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700754 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700755 // The animated view may be null in the case of a rotation during widget configuration
756 onCompleteRunnable.run();
757 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758 }
759
760 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700761 protected void onStop() {
762 super.onStop();
763 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700764
765 if (mLauncherCallbacks != null) {
766 mLauncherCallbacks.onStop();
767 }
Sunny Goyal67419a12017-11-14 16:55:22 -0800768 mAppWidgetHost.setListenIfResumed(false);
Tony Wickham010d2552017-01-20 08:15:28 -0800769
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700770 if (!mAppLaunchSuccess) {
771 getUserEventDispatcher().logActionCommand(Action.Command.STOP,
Sunny Goyalea609262017-10-25 15:47:38 -0700772 mStateManager.getState().containerType);
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700773 }
Tony Wickham010d2552017-01-20 08:15:28 -0800774 NotificationListener.removeNotificationsChangedListener();
Michael Jurkacd496d72013-04-11 11:32:45 -0700775 }
776
777 @Override
778 protected void onStart() {
779 super.onStart();
780 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700781
782 if (mLauncherCallbacks != null) {
783 mLauncherCallbacks.onStart();
784 }
Sunny Goyal67419a12017-11-14 16:55:22 -0800785 mAppWidgetHost.setListenIfResumed(true);
Tony Wickham010d2552017-01-20 08:15:28 -0800786
787 if (!isWorkspaceLoading()) {
788 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
789 }
Jon Miranda2d89ea82017-05-04 11:47:53 -0700790
Jon Miranda7fda2852017-07-19 16:07:01 -0700791 if (mShouldFadeInScrim && mDragLayer.getBackground() != null) {
Jon Miranda2d89ea82017-05-04 11:47:53 -0700792 if (mScrimAnimator != null) {
793 mScrimAnimator.cancel();
794 }
795 mDragLayer.getBackground().setAlpha(0);
796 mScrimAnimator = ObjectAnimator.ofInt(mDragLayer.getBackground(),
797 LauncherAnimUtils.DRAWABLE_ALPHA, 0, 255);
798 mScrimAnimator.addListener(new AnimatorListenerAdapter() {
799 @Override
800 public void onAnimationEnd(Animator animation) {
801 mScrimAnimator = null;
802 }
803 });
804 mScrimAnimator.setDuration(600);
805 mScrimAnimator.setStartDelay(getWindow().getTransitionBackgroundFadeDuration());
806 mScrimAnimator.start();
807 }
Jon Miranda7fda2852017-07-19 16:07:01 -0700808 mShouldFadeInScrim = false;
Michael Jurkacd496d72013-04-11 11:32:45 -0700809 }
810
811 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800812 protected void onResume() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700813 TraceHelper.beginSection("ON_RESUME");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800814 super.onResume();
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700815 TraceHelper.partitionSection("ON_RESUME", "superCall");
816
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -0700817 mAppLaunchSuccess = false;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700818 getUserEventDispatcher().resetElapsedSessionMillis();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800819 mPaused = false;
Sunny Goyal2100c782016-08-22 16:00:03 -0700820 if (mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700821 setWorkspaceLoading(true);
Sunny Goyal93f878c2016-03-30 17:31:24 -0700822 mModel.startLoader(getCurrentWorkspaceScreen());
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700823 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800824 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700825 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200826 // We might have postponed some bind calls until onResume (see waitUntilResume) --
827 // execute them here
Michael Jurka1e2f4652013-07-08 18:03:46 -0700828 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
829 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200830 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700831 mBindOnResumeCallbacks.clear();
Michael Jurka447bf842013-05-15 14:52:15 +0200832 }
Winson Chunge4e50662012-01-23 14:45:13 -0800833
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700834 setOnResumeCallback(null);
Sunny Goyala474a9b2017-05-04 16:47:11 -0700835 // Process any items that were added while Launcher was away.
836 InstallShortcutReceiver.disableAndFlushInstallQueue(
837 InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this);
Sunny Goyal95f3d6b2016-08-10 16:09:29 -0700838
Sunny Goyala474a9b2017-05-04 16:47:11 -0700839 // Refresh shortcuts if the permission changed.
840 mModel.refreshShortcutsIfRequired();
Adam Cohen9211d422014-10-07 18:14:53 -0700841
Sunny Goyal7ede6112017-12-05 15:11:21 -0800842 DiscoveryBounce.showIfNeeded(this);
Adam Cohen9211d422014-10-07 18:14:53 -0700843 if (mLauncherCallbacks != null) {
844 mLauncherCallbacks.onResume();
845 }
Mario Bertschler0fc6f682017-02-17 12:16:13 -0800846
Sunny Goyalfca6bc92017-09-28 16:28:34 -0700847 TraceHelper.endSection("ON_RESUME");
Adam Cohen06dff352012-06-01 17:17:08 -0700848 }
849
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700851 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700852 // Ensure that items added to Launcher are queued until Launcher returns
Sunny Goyala474a9b2017-05-04 16:47:11 -0700853 InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED);
Winson Chung997a9232013-07-24 15:33:46 -0700854
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700855 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700856 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800857 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700858 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -0700859
Adam Cohen9211d422014-10-07 18:14:53 -0700860 if (mLauncherCallbacks != null) {
861 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -0700862 }
Adam Cohenbffe7452013-07-22 18:21:45 -0700863 }
864
Adam Cohenc2d6e892014-10-16 09:49:24 -0700865 public interface LauncherOverlay {
866
867 /**
868 * Touch interaction leading to overscroll has begun
869 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700870 void onScrollInteractionBegin();
Adam Cohenc2d6e892014-10-16 09:49:24 -0700871
872 /**
873 * Touch interaction related to overscroll has ended
874 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700875 void onScrollInteractionEnd();
Adam Cohenc2d6e892014-10-16 09:49:24 -0700876
877 /**
878 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
879 * screen (or in the case of RTL, the rightmost screen).
880 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700881 void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700882
883 /**
Sunny Goyal32554d12015-12-03 15:31:25 -0800884 * Called when the launcher is ready to use the overlay
885 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -0700886 */
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700887 void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700888 }
889
890 public interface LauncherOverlayCallbacks {
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700891 void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700892 }
893
894 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
895
Sunny Goyalc86df472016-02-25 09:19:38 -0800896 public void onScrollChanged(float progress) {
897 if (mWorkspace != null) {
898 mWorkspace.onOverlayScrollChanged(progress);
899 }
900 }
Adam Cohenc2d6e892014-10-16 09:49:24 -0700901 }
902
Sunny Goyal16764582017-11-06 16:00:34 -0800903 public boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -0700904 if (mLauncherCallbacks != null) {
905 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700906 } else {
Sunny Goyal4179e9b2017-03-08 14:25:09 -0800907 // On O and above we there is always some setting present settings (add icon to
908 // home screen or icon badging). On earlier APIs we will have the allow rotation
909 // setting, on devices with a locked orientation,
Hyunyoung Songe24cb632017-09-11 11:18:03 -0700910 return Utilities.ATLEAST_OREO || !getResources().getBoolean(R.bool.allow_rotation);
Adam Cohen9211d422014-10-07 18:14:53 -0700911 }
Jorim Jaggid017f882014-01-14 17:08:48 -0800912 }
913
Sunny Goyalf9403d92017-10-18 10:55:56 -0700914 public boolean isInState(LauncherState state) {
Sunny Goyalea609262017-10-25 15:47:38 -0700915 return mStateManager.getState() == state;
Sunny Goyalf9403d92017-10-18 10:55:56 -0700916 }
917
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800918 /**
919 * Restores the previous state, if it exists.
920 *
921 * @param savedState The previous state.
922 */
923 private void restoreState(Bundle savedState) {
924 if (savedState == null) {
925 return;
926 }
927
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700928 int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal);
Sunny Goyalf9403d92017-10-18 10:55:56 -0700929 LauncherState[] stateValues = LauncherState.values();
930 LauncherState state = stateValues[stateOrdinal];
Sunny Goyalbc683e92017-12-06 10:25:07 -0800931 if (!state.disableRestore) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -0700932 mStateManager.goToState(state, false /* animated */);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800933 }
934
Sunny Goyal2100c782016-08-22 16:00:03 -0700935 PendingRequestArgs requestArgs = savedState.getParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS);
936 if (requestArgs != null) {
937 setWaitingForResult(requestArgs);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800938 }
Sunny Goyal2100c782016-08-22 16:00:03 -0700939
940 mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700941
942 SparseArray<Parcelable> widgetsState =
943 savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL);
944 if (widgetsState != null) {
945 WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState);
946 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800947 }
948
949 /**
950 * Finds all the views we need and configure them properly.
951 */
952 private void setupViews() {
Winson Chung4c98d922011-05-31 16:50:48 -0700953 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700954 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Sunny Goyal966d9012017-06-06 16:43:59 -0700955 mWorkspace = mDragLayer.findViewById(R.id.workspace);
Sunny Goyald0a6ae72016-06-16 12:29:03 -0700956 mWorkspace.initParentViews(mDragLayer);
Sunny Goyal16764582017-11-06 16:00:34 -0800957 mOverviewPanel = findViewById(R.id.overview_panel);
Craig Mautner360310b2012-10-26 15:13:08 -0700958
Sunny Goyal784f9c32016-03-23 16:56:54 -0700959 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
960 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
961 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800962
Winson Chung4c98d922011-05-31 16:50:48 -0700963 // Setup the drag layer
Sunny Goyal7ede6112017-12-05 15:11:21 -0800964 mDragLayer.setup(this, mDragController);
Winson Chung4c98d922011-05-31 16:50:48 -0700965
Winson Chung3d503fb2011-07-13 17:25:49 -0700966 // Setup the hotseat
967 mHotseat = (Hotseat) findViewById(R.id.hotseat);
968 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -0700969 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -0700970 }
971
Winson Chung4c98d922011-05-31 16:50:48 -0700972 // Setup the workspace
973 mWorkspace.setHapticFeedbackEnabled(false);
974 mWorkspace.setOnLongClickListener(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700975 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -0700976 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
977 // default state, otherwise we will update to the wrong offsets in RTL
978 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -0700979 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700980 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700981
Tony Wickham34d2c912015-09-11 09:27:58 -0700982 // Get the search/delete/uninstall bar
Rajeev Kumar43c0f582017-06-23 15:34:55 -0700983 mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700984
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -0700985 // Setup Apps
986 mAppsView = findViewById(R.id.apps_view);
Craig Mautner360310b2012-10-26 15:13:08 -0700987
Winson Chung3d503fb2011-07-13 17:25:49 -0700988 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -0700989 mDragController.setMoveTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700990 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -0400991
Hyunyoung Songd725f642017-08-17 22:26:35 -0700992 mAllAppsController.setupViews(mAppsView, mHotseat, mWorkspace);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800993 }
994
995 /**
996 * Creates a view representing a shortcut.
997 *
998 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800999 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001000 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001001 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001002 }
1003
1004 /**
1005 * Creates a view representing a shortcut inflated from the specified resource.
1006 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001007 * @param parent The group the shortcut belongs to.
1008 * @param info The data structure describing the shortcut.
1009 *
1010 * @return A View inflated from layoutResId.
1011 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001012 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal9b29ca52017-02-17 10:39:44 -08001013 BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
1014 .inflate(R.layout.app_icon, parent, false);
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001015 favorite.applyFromShortcutInfo(info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001016 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001017 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001018 return favorite;
1019 }
1020
1021 /**
Jon Mirandac476d6e2017-05-04 16:30:01 -07001022 * Add a shortcut to the workspace or to a Folder.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001023 *
1024 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001025 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001026 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001027 int cellY, PendingRequestArgs args) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001028 if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
1029 || args.getPendingIntent().getComponent() == null) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001030 return;
1031 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001032
Jon Mirandac476d6e2017-05-04 16:30:01 -07001033 int[] cellXY = mTmpAddItemCellCoordinates;
1034 CellLayout layout = getCellLayout(container, screenId);
1035
Sunny Goyal782f0c92017-01-19 10:27:54 -08001036 ShortcutInfo info = null;
Hyunyoung Songe24cb632017-09-11 11:18:03 -07001037 if (Utilities.ATLEAST_OREO) {
Sunny Goyal22ca9ec2017-05-18 15:03:13 -07001038 info = LauncherAppsCompatVO.createShortcutInfoFromPinItemRequest(
1039 this, LauncherAppsCompatVO.getPinItemRequest(data), 0);
Sunny Goyal782f0c92017-01-19 10:27:54 -08001040 }
1041
1042 if (info == null) {
Sunny Goyalb57645f2017-03-20 13:57:28 -07001043 // Legacy shortcuts are only supported for primary profile.
1044 info = Process.myUserHandle().equals(args.user)
1045 ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
Sunny Goyal782f0c92017-01-19 10:27:54 -08001046
Sunny Goyalb57645f2017-03-20 13:57:28 -07001047 if (info == null) {
1048 Log.e(TAG, "Unable to parse a valid custom shortcut result");
1049 return;
1050 } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
Sunny Goyal342e4662017-02-02 15:21:08 -08001051 info.intent, args.getPendingIntent().getComponent().getPackageName())) {
Sunny Goyal782f0c92017-01-19 10:27:54 -08001052 // The app is trying to add a shortcut without sufficient permissions
1053 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
1054 return;
1055 }
1056 }
1057
Jon Mirandac476d6e2017-05-04 16:30:01 -07001058 if (container < 0) {
1059 // Adding a shortcut to the Workspace.
1060 final View view = createShortcut(info);
1061 boolean foundCellSpan = false;
1062 // First we check if we already know the exact location where we want to add this item.
1063 if (cellX >= 0 && cellY >= 0) {
1064 cellXY[0] = cellX;
1065 cellXY[1] = cellY;
1066 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001067
Jon Mirandac476d6e2017-05-04 16:30:01 -07001068 // If appropriate, either create a folder or add to an existing folder
1069 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Sunny Goyal1797af42017-10-06 13:29:57 -07001070 true, null)) {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001071 return;
1072 }
1073 DragObject dragObject = new DragObject();
1074 dragObject.dragInfo = info;
1075 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1076 true)) {
1077 return;
1078 }
1079 } else {
1080 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1081 }
1082
1083 if (!foundCellSpan) {
1084 mWorkspace.onNoCellFound(layout);
Adam Cohen558baaf2011-08-15 15:22:57 -07001085 return;
1086 }
Jon Mirandac476d6e2017-05-04 16:30:01 -07001087
1088 getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
1089 mWorkspace.addInScreen(view, info);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001090 } else {
Jon Mirandac476d6e2017-05-04 16:30:01 -07001091 // Adding a shortcut to a Folder.
Sunny Goyale29897f2017-07-20 10:09:42 -07001092 FolderIcon folderIcon = findFolderIcon(container);
Jon Mirandac476d6e2017-05-04 16:30:01 -07001093 if (folderIcon != null) {
1094 FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
1095 folderInfo.add(info, args.rank, false);
1096 } else {
Sunny Goyale29897f2017-07-20 10:09:42 -07001097 Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
Jon Mirandac476d6e2017-05-04 16:30:01 -07001098 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001099 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001100 }
1101
Sunny Goyale29897f2017-07-20 10:09:42 -07001102 public FolderIcon findFolderIcon(final long folderIconId) {
1103 return (FolderIcon) mWorkspace.getFirstMatch(new ItemOperator() {
1104 @Override
1105 public boolean evaluate(ItemInfo info, View view) {
1106 return info != null && info.id == folderIconId;
1107 }
1108 });
1109 }
1110
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001111 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001112 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001114 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001116 @Thunk void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001117 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1118
Adam Cohened66b2b2012-01-23 17:28:51 -08001119 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001120 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001121 }
Romain Guycbb89e42009-06-08 15:52:54 -07001122
Adam Cohen59400422014-03-05 18:07:04 -08001123 LauncherAppWidgetInfo launcherInfo;
1124 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
Sunny Goyal2100c782016-08-22 16:00:03 -07001125 launcherInfo.spanX = itemInfo.spanX;
1126 launcherInfo.spanY = itemInfo.spanY;
1127 launcherInfo.minSpanX = itemInfo.minSpanX;
1128 launcherInfo.minSpanY = itemInfo.minSpanY;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001129 launcherInfo.user = appWidgetInfo.getProfile();
Romain Guycbb89e42009-06-08 15:52:54 -07001130
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001131 getModelWriter().addItemToDatabase(launcherInfo,
Sunny Goyal2100c782016-08-22 16:00:03 -07001132 itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133
Sunny Goyal2100c782016-08-22 16:00:03 -07001134 if (hostView == null) {
1135 // Perform actual inflation because we're live
1136 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001137 }
Sunny Goyal2100c782016-08-22 16:00:03 -07001138 hostView.setVisibility(View.VISIBLE);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301139 prepareAppWidget(hostView, launcherInfo);
1140 mWorkspace.addInScreen(hostView, launcherInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001141 }
Romain Guycbb89e42009-06-08 15:52:54 -07001142
Sunny Goyald5462aa2016-11-22 16:52:39 +05301143 private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001144 hostView.setTag(item);
1145 item.onBindAppWidget(this, hostView);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001146 hostView.setFocusable(true);
1147 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001148 }
1149
Adam Cohended9f8d2010-11-03 13:25:16 -07001150 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1151 @Override
1152 public void onReceive(Context context, Intent intent) {
1153 final String action = intent.getAction();
1154 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001155 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001156 // processing a multi-step drop
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001157 if (mAppsView != null && mPendingRequestArgs == null) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001158 mStateManager.goToState(NORMAL);
Winson Chung785d2eb2011-04-14 16:08:02 -07001159 }
Jon Miranda7fda2852017-07-19 16:07:01 -07001160 mShouldFadeInScrim = true;
1161 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1162 // ACTION_USER_PRESENT is sent after onStart/onResume. This covers the case where
1163 // the user unlocked and the Launcher is not in the foreground.
1164 mShouldFadeInScrim = false;
Adam Cohended9f8d2010-11-03 13:25:16 -07001165 }
1166 }
1167 };
1168
Tony Wickham010d2552017-01-20 08:15:28 -08001169 public void updateIconBadges(final Set<PackageUserKey> updatedBadges) {
1170 Runnable r = new Runnable() {
1171 @Override
1172 public void run() {
1173 mWorkspace.updateIconBadges(updatedBadges);
1174 mAppsView.updateIconBadges(updatedBadges);
Tony Wickham2fe09f22017-04-25 12:46:04 -07001175
Sunny Goyal00ac9202017-11-09 15:24:06 -08001176 PopupContainerWithArrow popup = PopupContainerWithArrow.getOpen(Launcher.this);
1177 if (popup != null) {
1178 popup.updateNotificationHeader(updatedBadges);
Tony Wickham2fe09f22017-04-25 12:46:04 -07001179 }
Tony Wickham010d2552017-01-20 08:15:28 -08001180 }
1181 };
1182 if (!waitUntilResume(r)) {
1183 r.run();
1184 }
1185 }
1186
Adam Cohended9f8d2010-11-03 13:25:16 -07001187 @Override
1188 public void onAttachedToWindow() {
1189 super.onAttachedToWindow();
1190
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001191 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Sunny Goyalc86df472016-02-25 09:19:38 -08001192 if (mLauncherCallbacks != null) {
1193 mLauncherCallbacks.onAttachedToWindow();
1194 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001195 }
1196
1197 @Override
1198 public void onDetachedFromWindow() {
1199 super.onDetachedFromWindow();
Sunny Goyalc86df472016-02-25 09:19:38 -08001200
1201 if (mLauncherCallbacks != null) {
1202 mLauncherCallbacks.onDetachedFromWindow();
1203 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001204 }
1205
Sunny Goyalc4fa8c32017-11-07 12:23:58 -08001206 public AllAppsTransitionController getAllAppsController() {
1207 return mAllAppsController;
1208 }
1209
Winson Chunga6945242014-01-08 14:04:34 -08001210 public DragLayer getDragLayer() {
1211 return mDragLayer;
1212 }
1213
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001214 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001215 return mAppsView;
1216 }
1217
Winson Chunga6945242014-01-08 14:04:34 -08001218 public Workspace getWorkspace() {
1219 return mWorkspace;
1220 }
1221
1222 public Hotseat getHotseat() {
1223 return mHotseat;
1224 }
1225
Winson Chung8ae41982017-11-10 11:42:13 -08001226 public <T extends ViewGroup> T getOverviewPanel() {
1227 return (T) mOverviewPanel;
Winson Chunga6945242014-01-08 14:04:34 -08001228 }
1229
Sunny Goyal47328fd2016-05-25 18:56:41 -07001230 public DropTargetBar getDropTargetBar() {
1231 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001232 }
1233
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001234 public LauncherAppWidgetHost getAppWidgetHost() {
1235 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001236 }
Romain Guycbb89e42009-06-08 15:52:54 -07001237
Winson Chunga9abd0e2010-10-27 17:18:37 -07001238 public LauncherModel getModel() {
1239 return mModel;
1240 }
1241
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001242 public ModelWriter getModelWriter() {
1243 return mModelWriter;
1244 }
1245
Adam Cohen79d90c52016-04-22 13:29:20 -07001246 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001247 return mSharedPrefs;
1248 }
1249
Jon Miranda6bed3502017-09-19 14:43:17 -07001250 public int getOrientation() { return mOrientation; }
1251
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001252 @Override
1253 protected void onNewIntent(Intent intent) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001254 TraceHelper.beginSection("NEW_INTENT");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 super.onNewIntent(intent);
1256
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001257 boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
Winson15f8b172015-08-19 11:02:39 -07001258 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1259 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Sunny Goyal85313732016-09-28 12:00:07 -07001260
1261 // Check this condition before handling isActionMain, as this will get reset.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001262 boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
Sunny Goyalf9403d92017-10-18 10:55:56 -07001263 && AbstractFloatingView.getTopOpenView(this) == null;
Winson15f8b172015-08-19 11:02:39 -07001264 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
Sunny Goyald3864fa2017-11-14 15:06:36 -08001265 boolean internalStateHandled = InternalStateHandler
1266 .handleNewIntent(this, intent, alreadyOnHome);
1267
Winson15f8b172015-08-19 11:02:39 -07001268 if (isActionMain) {
Sunny Goyald3864fa2017-11-14 15:06:36 -08001269 if (!internalStateHandled) {
1270 // Note: There should be at most one log per method call. This is enforced
1271 // implicitly by using if-else statements.
1272 UserEventDispatcher ued = getUserEventDispatcher();
1273 AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(this);
1274 if (topOpenView != null) {
1275 topOpenView.logActionCommand(Action.Command.HOME_INTENT);
1276 } else if (alreadyOnHome) {
1277 Target target = newContainerTarget(mStateManager.getState().containerType);
1278 target.pageIndex = mWorkspace.getCurrentPage();
1279 ued.logActionCommand(Action.Command.HOME_INTENT, target);
1280 }
Jon Mirandafeba90f2016-10-06 10:53:29 -07001281
Sunny Goyald3864fa2017-11-14 15:06:36 -08001282 // In all these cases, only animate if we're already on home
1283 AbstractFloatingView.closeAllOpenViews(this, alreadyOnHome);
Jon Mirandafeba90f2016-10-06 10:53:29 -07001284
Sunny Goyald3864fa2017-11-14 15:06:36 -08001285 mStateManager.goToState(NORMAL, alreadyOnHome /* animated */);
1286
1287 // Reset the apps view
1288 if (!alreadyOnHome && mAppsView != null) {
1289 mAppsView.reset();
1290 }
1291
1292 if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive()) {
1293 mWorkspace.post(mWorkspace::moveToDefaultScreen);
1294 }
1295 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001296
1297 final View v = getWindow().peekDecorView();
1298 if (v != null && v.getWindowToken() != null) {
Sunny Goyal326403e2017-10-02 12:45:10 -07001299 UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
Adam Cohen6fecd412013-10-02 17:41:50 -07001300 }
1301
Adam Cohen9211d422014-10-07 18:14:53 -07001302 if (mLauncherCallbacks != null) {
1303 mLauncherCallbacks.onHomeIntent();
1304 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305 }
Winson15f8b172015-08-19 11:02:39 -07001306
Sunny Goyalfca6bc92017-09-28 16:28:34 -07001307 TraceHelper.endSection("NEW_INTENT");
Adam Coppa120b8e2013-11-12 16:26:04 +00001308 }
1309
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001311 public void onRestoreInstanceState(Bundle state) {
1312 super.onRestoreInstanceState(state);
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001313 mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314 }
1315
1316 @Override
1317 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001318 if (mWorkspace.getChildCount() > 0) {
Sunny Goyal7ce471b2017-08-02 03:37:39 -07001319 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001320
Adam Cohen21cd0022013-10-09 18:57:02 -07001321 }
Sunny Goyalea609262017-10-25 15:47:38 -07001322 outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001323
1324
1325 AbstractFloatingView widgets = AbstractFloatingView
1326 .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET);
1327 if (widgets != null) {
1328 SparseArray<Parcelable> widgetsState = new SparseArray<>();
1329 widgets.saveHierarchyState(widgetsState);
1330 outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState);
1331 } else {
1332 outState.remove(RUNTIME_STATE_WIDGET_PANEL);
1333 }
1334
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001335 // We close any open folders and shortcut containers since they will not be re-opened,
1336 // and we need to make sure this state is reflected.
1337 AbstractFloatingView.closeAllOpenViews(this, false);
Tony Wickham49c8d292016-07-01 11:44:34 -07001338
Sunny Goyal2100c782016-08-22 16:00:03 -07001339 if (mPendingRequestArgs != null) {
1340 outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs);
1341 }
1342 if (mPendingActivityResult != null) {
1343 outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001344 }
1345
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07001346 super.onSaveInstanceState(outState);
1347
Adam Cohen9211d422014-10-07 18:14:53 -07001348 if (mLauncherCallbacks != null) {
1349 mLauncherCallbacks.onSaveInstanceState(outState);
1350 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 }
1352
1353 @Override
1354 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001356
Sunny Goyal5cc7bbd2017-06-12 09:50:39 -07001357 unregisterReceiver(mReceiver);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001358 mWorkspace.removeFolderListeners();
Winson Chunge7a03942011-08-05 15:05:12 -07001359
Winson Chungcd2b0142011-06-08 16:02:26 -07001360 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001361 // It's possible to receive onDestroy after a new Launcher activity has
1362 // been created. In this case, don't interfere with the new Launcher.
1363 if (mModel.isCurrentCallbacks(this)) {
1364 mModel.stopLoader();
Sunny Goyal87f784c2017-01-11 10:48:34 -08001365 LauncherAppState.getInstance(this).setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001366 }
Winson Chungcd2b0142011-06-08 16:02:26 -07001367
Sunny Goyal745bad92016-05-02 10:54:12 -07001368 if (mRotationPrefChangeHandler != null) {
1369 mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
1370 }
1371
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001372 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001373 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001375 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001376 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001377
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378 TextKeyListener.getInstance().release();
Mario Bertschler27288382017-05-24 15:35:09 -07001379 WallpaperColorInfo.getInstance(this).setOnThemeChangeListener(null);
1380
Michael Jurka2ecf9952012-06-18 12:52:28 -07001381 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07001382
Tony2917a8b2017-07-31 23:29:42 -07001383 clearPendingBinds();
1384
Adam Cohen9211d422014-10-07 18:14:53 -07001385 if (mLauncherCallbacks != null) {
1386 mLauncherCallbacks.onDestroy();
1387 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388 }
1389
Sunny Goyalae502842016-06-17 08:43:56 -07001390 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
1391 return mAccessibilityDelegate;
1392 }
1393
Adam Cohena9cf38f2011-05-02 15:36:58 -07001394 public DragController getDragController() {
1395 return mDragController;
1396 }
1397
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001398 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001399 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001400 super.startActivityForResult(intent, requestCode, options);
Adam Cohen173f7112015-03-27 15:14:00 -07001401 }
1402
1403 @Override
1404 public void startIntentSenderForResult (IntentSender intent, int requestCode,
1405 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
Adam Cohen173f7112015-03-27 15:14:00 -07001406 try {
1407 super.startIntentSenderForResult(intent, requestCode,
1408 fillInIntent, flagsMask, flagsValues, extraFlags, options);
1409 } catch (IntentSender.SendIntentException e) {
1410 throw new ActivityNotFoundException();
1411 }
1412 }
1413
Winson Chung70d72102011-08-12 11:24:35 -07001414 /**
1415 * Indicates that we want global search for this activity by setting the globalSearch
1416 * argument for {@link #startSearch} to true.
1417 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001419 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 Bundle appSearchData, boolean globalSearch) {
1421 if (appSearchData == null) {
1422 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001423 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001425
Sunny Goyal6f28e712016-09-13 14:19:29 -07001426 if (mLauncherCallbacks == null ||
1427 !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) {
1428 // Starting search from the callbacks failed. Start the default global search.
Sunny Goyalf4aceab2017-12-06 16:16:31 -08001429 super.startSearch(initialQuery, selectInitialQuery, appSearchData, true);
Ian Parkinson047036e2014-09-01 15:40:53 +01001430 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001431
1432 // We need to show the workspace after starting the search
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001433 mStateManager.goToState(NORMAL);
Bjorn Bringertc459e522013-06-07 19:36:01 +01001434 }
1435
Joe Onorato9c1289c2009-08-17 11:03:03 -04001436 public boolean isWorkspaceLocked() {
Sunny Goyal2100c782016-08-22 16:00:03 -07001437 return mWorkspaceLoading || mPendingRequestArgs != null;
Joe Onorato9c1289c2009-08-17 11:03:03 -04001438 }
1439
Adam Cohen517a7f52014-03-01 12:12:59 -08001440 public boolean isWorkspaceLoading() {
1441 return mWorkspaceLoading;
1442 }
1443
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001444 private void setWorkspaceLoading(boolean value) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001445 mWorkspaceLoading = value;
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001446 }
1447
Sunny Goyal04a324a2017-01-20 21:08:59 -08001448 public void setWaitingForResult(PendingRequestArgs args) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001449 mPendingRequestArgs = args;
Adam Cohen9211d422014-10-07 18:14:53 -07001450 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001451
Sunny Goyal2100c782016-08-22 16:00:03 -07001452 void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001453 WidgetAddFlowHandler addFlowHandler) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001454 if (LOGD) {
1455 Log.d(TAG, "Adding widget from drop");
1456 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001457 addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001458 }
1459
Sunny Goyal2100c782016-08-22 16:00:03 -07001460 void addAppWidgetImpl(int appWidgetId, ItemInfo info,
Sunny Goyal04a324a2017-01-20 21:08:59 -08001461 AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) {
1462 if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, REQUEST_CREATE_APPWIDGET)) {
1463 // If the configuration flow was not started, add the widget
Michael Jurkaaf442092010-06-10 17:01:57 -07001464
Adam Cohenad4e15c2013-10-17 16:21:35 -07001465 Runnable onComplete = new Runnable() {
1466 @Override
1467 public void run() {
1468 // Exit spring loaded mode if necessary after adding the widget
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001469 mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
Adam Cohenad4e15c2013-10-17 16:21:35 -07001470 }
1471 };
Sunny Goyal04a324a2017-01-20 21:08:59 -08001472 completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this));
Adam Cohen689ff162014-05-08 17:27:56 -07001473 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 }
1475 }
Romain Guycbb89e42009-06-08 15:52:54 -07001476
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001477 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
1478 int[] cell, int spanX, int spanY) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001479 info.container = container;
1480 info.screenId = screenId;
1481 if (cell != null) {
1482 info.cellX = cell[0];
1483 info.cellY = cell[1];
1484 }
1485 info.spanX = spanX;
1486 info.spanY = spanY;
1487
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001488 switch (info.itemType) {
1489 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
1490 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
Sunny Goyal2100c782016-08-22 16:00:03 -07001491 addAppWidgetFromDrop((PendingAddWidgetInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001492 break;
1493 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal782f0c92017-01-19 10:27:54 -08001494 processShortcutFromDrop((PendingAddShortcutInfo) info);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08001495 break;
1496 default:
1497 throw new IllegalStateException("Unknown item type: " + info.itemType);
1498 }
1499 }
1500
Adam Cohenfbba09b2011-07-18 21:43:05 -07001501 /**
1502 * Process a shortcut drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001503 */
Sunny Goyal782f0c92017-01-19 10:27:54 -08001504 private void processShortcutFromDrop(PendingAddShortcutInfo info) {
Sunny Goyalfb5096d2016-09-08 14:32:06 -07001505 Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
1506 setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
Sunny Goyal782f0c92017-01-19 10:27:54 -08001507 if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
1508 handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
1509 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001510 }
1511
Adam Cohenfbba09b2011-07-18 21:43:05 -07001512 /**
1513 * Process a widget drop.
Adam Cohenfbba09b2011-07-18 21:43:05 -07001514 */
Sunny Goyal2100c782016-08-22 16:00:03 -07001515 private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001516 AppWidgetHostView hostView = info.boundWidget;
Sunny Goyal952e63d2017-08-16 04:59:08 -07001517 final int appWidgetId;
Sunny Goyal8a0dc382017-01-25 11:30:06 -08001518 WidgetAddFlowHandler addFlowHandler = info.getHandler();
Adam Cohened66b2b2012-01-23 17:28:51 -08001519 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001520 // In the case where we've prebound the widget, we remove it from the DragLayer
1521 if (LOGD) {
1522 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
1523 }
1524 getDragLayer().removeView(hostView);
1525
Adam Cohened66b2b2012-01-23 17:28:51 -08001526 appWidgetId = hostView.getAppWidgetId();
Sunny Goyal04a324a2017-01-20 21:08:59 -08001527 addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07001528
1529 // Clear the boundWidget so that it doesn't get destroyed.
1530 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08001531 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001532 // In this case, we either need to start an activity to get permission to bind
1533 // the widget, or we need to start an activity to configure the widget, or both.
Sunny Goyal952e63d2017-08-16 04:59:08 -07001534 if (FeatureFlags.ENABLE_CUSTOM_WIDGETS &&
1535 info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
1536 appWidgetId = CustomWidgetParser.getWidgetIdForCustomProvider(
1537 this, info.componentName);
1538 } else {
1539 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1540 }
Adam Cohendd70d662012-10-04 16:53:44 -07001541 Bundle options = info.bindOptions;
1542
Sunny Goyalffe83f12014-08-14 17:39:34 -07001543 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
1544 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07001545 if (success) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001546 addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
Michael Jurka8b805b12012-04-18 14:23:14 -07001547 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001548 addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
Michael Jurka8b805b12012-04-18 14:23:14 -07001549 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001550 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001551 }
1552
Adam Cohendcd297f2013-06-18 13:13:40 -07001553 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001554 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001555 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556 folderInfo.title = getText(R.string.folder_name);
1557
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 // Update the model
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001559 getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560
1561 // Create the view
Sunny Goyal1cd01b02016-11-09 10:43:58 -08001562 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo);
Sunny Goyald5462aa2016-11-22 16:52:39 +05301563 mWorkspace.addInScreen(newFolder, folderInfo);
Winson Chung5f8afe62013-08-12 16:19:28 -07001564 // Force measure the new folder icon
1565 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
1566 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07001567 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001568 }
Romain Guycbb89e42009-06-08 15:52:54 -07001569
Winsonc0b52fe2015-09-09 16:38:15 -07001570 /**
Winsonfa56b3f2015-09-14 12:01:13 -07001571 * Unbinds the view for the specified item, and removes the item and all its children.
1572 *
1573 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07001574 * @param itemInfo the {@link ItemInfo} for this view.
1575 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07001576 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001577 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07001578 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07001579 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07001580 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
1581 if (folderIcon instanceof FolderIcon) {
Sunny Goyalc52ba712016-04-05 15:59:05 -07001582 ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07001583 } else {
1584 mWorkspace.removeWorkspaceItem(v);
1585 }
Winsonc0b52fe2015-09-09 16:38:15 -07001586 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001587 getModelWriter().deleteItemFromDatabase(itemInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001588 }
1589 } else if (itemInfo instanceof FolderInfo) {
1590 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001591 if (v instanceof FolderIcon) {
1592 ((FolderIcon) v).removeListeners();
1593 }
Winsonc0b52fe2015-09-09 16:38:15 -07001594 mWorkspace.removeWorkspaceItem(v);
1595 if (deleteFromDb) {
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001596 getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001597 }
1598 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
1599 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07001600 mWorkspace.removeWorkspaceItem(v);
Winsonc0b52fe2015-09-09 16:38:15 -07001601 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07001602 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001603 }
1604 } else {
1605 return false;
1606 }
1607 return true;
1608 }
1609
1610 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07001611 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07001612 */
Sunny Goyal56c73602015-09-25 12:55:01 -07001613 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07001614 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyald478c832016-04-01 12:04:16 -07001615 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdAllocated()) {
Winsonc0b52fe2015-09-09 16:38:15 -07001616 // Deleting an app widget ID is a void call but writes to disk before returning
1617 // to the caller...
1618 new AsyncTask<Void, Void, Void>() {
1619 public Void doInBackground(Void ... args) {
1620 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
1621 return null;
1622 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07001623 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07001624 }
Sunny Goyal43bf11d2017-02-02 13:52:53 -08001625 getModelWriter().deleteItemFromDatabase(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07001626 }
1627
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001628 @Override
1629 public boolean dispatchKeyEvent(KeyEvent event) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08001630 return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001631 }
1632
Joe Onorato88ec0992009-11-19 13:16:06 -08001633 @Override
1634 public void onBackPressed() {
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08001635 if (finishAutoCancelActionMode()) {
1636 return;
1637 }
Adam Cohen9211d422014-10-07 18:14:53 -07001638 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
1639 return;
1640 }
1641
Sunny Goyal45478022015-06-08 16:52:41 -07001642 if (mDragController.isDragging()) {
1643 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08001644 return;
1645 }
1646
Jon Mirandafeba90f2016-10-06 10:53:29 -07001647 // Note: There should be at most one log per method call. This is enforced implicitly
1648 // by using if-else statements.
1649 UserEventDispatcher ued = getUserEventDispatcher();
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001650 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
1651 if (topView != null) {
Sunny Goyal37920962017-09-28 13:43:24 -07001652 topView.onBackPressed();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001653 } else if (!isInState(NORMAL)) {
Sunny Goyalea609262017-10-25 15:47:38 -07001654 ued.logActionCommand(Action.Command.BACK, mStateManager.getState().containerType);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001655 mStateManager.goToState(NORMAL);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001656 } else {
1657 // Back button is a no-op here, but give at least some feedback for the button press
1658 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001659 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001660 }
1661
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001662 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001663 * Launches the intent referred by the clicked shortcut.
1664 *
1665 * @param v The view representing the clicked shortcut.
1666 */
1667 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001668 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1669 // view has detached (it's possible for this to happen if the view is removed mid touch).
1670 if (v.getWindowToken() == null) {
1671 return;
1672 }
1673
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001674 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001675 return;
1676 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001677
Adam Cohen1697b792013-09-17 19:08:21 -07001678 if (v instanceof Workspace) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001679 if (isInState(OVERVIEW)) {
Jon Miranda2e61fba2017-02-24 09:12:59 -08001680 getUserEventDispatcher().logActionOnContainer(LauncherLogProto.Action.Type.TOUCH,
1681 LauncherLogProto.Action.Direction.NONE,
1682 LauncherLogProto.ContainerType.OVERVIEW, mWorkspace.getCurrentPage());
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001683 mStateManager.goToState(NORMAL);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001684 }
1685 return;
1686 }
1687
1688 if (v instanceof CellLayout) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001689 if (isInState(OVERVIEW)) {
Jon Mirandac6cf4932017-02-07 17:12:36 -08001690 int page = mWorkspace.indexOfChild(v);
1691 getUserEventDispatcher().logActionOnContainer(LauncherLogProto.Action.Type.TOUCH,
1692 LauncherLogProto.Action.Direction.NONE,
1693 LauncherLogProto.ContainerType.OVERVIEW, page);
1694 mWorkspace.snapToPageFromOverView(page);
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07001695 mStateManager.goToState(NORMAL);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001696 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07001697 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07001698 }
1699
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001701 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001702 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001703 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001704 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001705 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001706 }
Sunny Goyal508da152014-08-14 10:53:27 -07001707 } else if (tag instanceof AppInfo) {
1708 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07001709 } else if (tag instanceof LauncherAppWidgetInfo) {
1710 if (v instanceof PendingAppWidgetHostView) {
1711 onClickPendingWidget((PendingAppWidgetHostView) v);
1712 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713 }
1714 }
1715
Sunny Goyal70660032015-05-14 00:07:08 -07001716 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07001717 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07001718 return false;
1719 }
1720
Michael Jurkaaf442092010-06-10 17:01:57 -07001721 /**
Sunny Goyalff572272014-07-23 13:58:07 -07001722 * Event handler for the app widget view which has not fully restored.
1723 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07001724 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07001725 if (mIsSafeModeEnabled) {
1726 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
1727 return;
1728 }
1729
Sunny Goyale7b8cd92014-08-27 14:04:33 -07001730 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07001731 if (v.isReadyForClickSetup()) {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001732 LauncherAppWidgetProviderInfo appWidgetInfo =
1733 mAppWidgetManager.findProvider(info.providerName, info.user);
1734 if (appWidgetInfo == null) {
1735 return;
1736 }
1737 WidgetAddFlowHandler addFlowHandler = new WidgetAddFlowHandler(appWidgetInfo);
1738
Sunny Goyald478c832016-04-01 12:04:16 -07001739 if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
1740 if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
1741 // This should not happen, as we make sure that an Id is allocated during bind.
1742 return;
1743 }
Sunny Goyal04a324a2017-01-20 21:08:59 -08001744 addFlowHandler.startBindFlow(this, info.appWidgetId, info,
1745 REQUEST_BIND_PENDING_APPWIDGET);
Sunny Goyald478c832016-04-01 12:04:16 -07001746 } else {
Sunny Goyal04a324a2017-01-20 21:08:59 -08001747 addFlowHandler.startConfigActivity(this, info, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07001748 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07001749 } else {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07001750 final String packageName = info.providerName.getPackageName();
Sunny Goyale6e72002017-01-12 16:55:36 -08001751 onClickPendingAppItem(v, packageName, info.installProgress >= 0);
Sunny Goyalff572272014-07-23 13:58:07 -07001752 }
1753 }
1754
Sunny Goyale6e72002017-01-12 16:55:36 -08001755 private void onClickPendingAppItem(final View v, final String packageName,
1756 boolean downloadStarted) {
1757 if (downloadStarted) {
1758 // If the download has started, simply direct to the market app.
1759 startMarketIntentForPackage(v, packageName);
1760 return;
1761 }
Sunny Goyale03b8122014-10-08 09:55:24 -07001762 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07001763 .setTitle(R.string.abandoned_promises_title)
1764 .setMessage(R.string.abandoned_promise_explanation)
Sunny Goyale6e72002017-01-12 16:55:36 -08001765 .setPositiveButton(R.string.abandoned_search, new DialogInterface.OnClickListener() {
1766 @Override
1767 public void onClick(DialogInterface dialogInterface, int i) {
1768 startMarketIntentForPackage(v, packageName);
1769 }
1770 })
Sunny Goyale7b8cd92014-08-27 14:04:33 -07001771 .setNeutralButton(R.string.abandoned_clean_this,
1772 new DialogInterface.OnClickListener() {
1773 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal7c74e4a2016-12-15 15:53:17 -08001774 final UserHandle user = Process.myUserHandle();
Sunny Goyale7b8cd92014-08-27 14:04:33 -07001775 mWorkspace.removeAbandonedPromise(packageName, user);
1776 }
1777 })
1778 .create().show();
Sunny Goyale6e72002017-01-12 16:55:36 -08001779 }
1780
1781 private void startMarketIntentForPackage(View v, String packageName) {
1782 ItemInfo item = (ItemInfo) v.getTag();
1783 Intent intent = PackageManagerHelper.getMarketIntent(packageName);
Sunny Goyal3dce5f32017-10-05 11:40:05 -07001784 startActivitySafely(v, intent, item);
Sunny Goyale7b8cd92014-08-27 14:04:33 -07001785 }
1786
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001787 /**
1788 * Event handler for an app shortcut click.
1789 *
1790 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
1791 */
Chris Wren40c5ed32014-06-24 18:24:23 -04001792 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001793 if (LOGD) Log.d(TAG, "onClickAppShortcut");
1794 Object tag = v.getTag();
1795 if (!(tag instanceof ShortcutInfo)) {
1796 throw new IllegalArgumentException("Input must be a Shortcut");
1797 }
1798
1799 // Open shortcut
1800 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07001801
Sunny Goyal076839c2017-10-30 13:52:20 -07001802 if (shortcut.isDisabled()) {
Tony Makf6308652017-12-02 16:56:22 +00001803 final int disabledFlags = shortcut.runtimeStatusFlags & ShortcutInfo.FLAG_DISABLED_MASK;
1804 if ((disabledFlags &
Sunny Goyal076839c2017-10-30 13:52:20 -07001805 ~FLAG_DISABLED_SUSPENDED &
1806 ~FLAG_DISABLED_QUIET_USER) == 0) {
Sunny Goyald3b87ef2016-07-28 12:11:54 -07001807 // If the app is only disabled because of the above flags, launch activity anyway.
1808 // Framework will tell the user why the app is suspended.
Kenny Guy44cba692016-01-21 19:50:02 +00001809 } else {
Tony Wickham4efffc52016-08-04 16:34:49 -07001810 if (!TextUtils.isEmpty(shortcut.disabledMessage)) {
1811 // Use a message specific to this shortcut, if it has one.
1812 Toast.makeText(this, shortcut.disabledMessage, Toast.LENGTH_SHORT).show();
1813 return;
1814 }
1815 // Otherwise just use a generic error message.
Kenny Guy44cba692016-01-21 19:50:02 +00001816 int error = R.string.activity_not_available;
Sunny Goyal076839c2017-10-30 13:52:20 -07001817 if ((shortcut.runtimeStatusFlags & FLAG_DISABLED_SAFEMODE) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00001818 error = R.string.safemode_shortcut_error;
Sunny Goyal076839c2017-10-30 13:52:20 -07001819 } else if ((shortcut.runtimeStatusFlags & FLAG_DISABLED_BY_PUBLISHER) != 0 ||
1820 (shortcut.runtimeStatusFlags & FLAG_DISABLED_LOCKED_USER) != 0) {
Sunny Goyal70a7c9b2016-07-28 10:07:32 -07001821 error = R.string.shortcut_not_available;
Kenny Guy44cba692016-01-21 19:50:02 +00001822 }
1823 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
1824 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07001825 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07001826 }
1827
Chris Wren40c5ed32014-06-24 18:24:23 -04001828 // Check for abandoned promise
Mario Bertschler8ff9e1d2017-08-08 16:26:18 -07001829 if ((v instanceof BubbleTextView) && shortcut.hasPromiseIconUi()) {
Sunny Goyale6e72002017-01-12 16:55:36 -08001830 String packageName = shortcut.intent.getComponent() != null ?
1831 shortcut.intent.getComponent().getPackageName() : shortcut.intent.getPackage();
1832 if (!TextUtils.isEmpty(packageName)) {
1833 onClickPendingAppItem(v, packageName,
1834 shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE));
1835 return;
1836 }
Chris Wren40c5ed32014-06-24 18:24:23 -04001837 }
1838
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001839 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07001840 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04001841 }
1842
Sunny Goyala7ce1662016-05-31 15:01:35 -07001843 private void startAppShortcutOrInfoActivity(View v) {
1844 ItemInfo item = (ItemInfo) v.getTag();
Mario Bertschler08ffaae2017-03-20 11:30:27 -07001845 Intent intent;
1846 if (item instanceof PromiseAppInfo) {
1847 PromiseAppInfo promiseAppInfo = (PromiseAppInfo) item;
1848 intent = promiseAppInfo.getMarketIntent();
1849 } else {
1850 intent = item.getIntent();
1851 }
Sunny Goyala7ce1662016-05-31 15:01:35 -07001852 if (intent == null) {
1853 throw new IllegalArgumentException("Input must have a valid intent");
Sunny Goyal508da152014-08-14 10:53:27 -07001854 }
Sunny Goyal3dce5f32017-10-05 11:40:05 -07001855 startActivitySafely(v, intent, item);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001856 }
1857
1858 /**
1859 * Event handler for a folder icon click.
1860 *
1861 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
1862 */
1863 protected void onClickFolderIcon(View v) {
1864 if (LOGD) Log.d(TAG, "onClickFolder");
1865 if (!(v instanceof FolderIcon)){
1866 throw new IllegalArgumentException("Input must be a FolderIcon");
1867 }
1868
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001869 Folder folder = ((FolderIcon) v).getFolder();
1870 if (!folder.isOpen() && !folder.isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001871 // Open the requested folder
Sunny Goyal740ac7f2016-09-28 16:47:32 -07001872 folder.animateOpen();
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001873 }
Michael Jurka5130e402011-10-13 04:55:35 -07001874 }
1875
Sandeep Siddharthad8058372014-01-28 10:41:15 -08001876 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001877 * Event handler for the wallpaper picker button that appears after a long press
1878 * on the home screen.
1879 */
Sunny Goyald0a6ae72016-06-16 12:29:03 -07001880 public void onClickWallpaperPicker(View v) {
Hyunyoung Song0de01172016-10-05 16:27:48 -07001881 if (!Utilities.isWallpaperAllowed(this)) {
Sunny Goyal1ed6c4a2016-04-21 15:16:11 -07001882 Toast.makeText(this, R.string.msg_disabled_by_admin, Toast.LENGTH_SHORT).show();
1883 return;
1884 }
1885
Tony Wickham785f7a52015-08-31 17:28:32 -07001886 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
1887 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
Sunny Goyal2100c782016-08-22 16:00:03 -07001888 setWaitingForResult(new PendingRequestArgs(new ItemInfo()));
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001889 Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER)
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001890 .putExtra(Utilities.EXTRA_WALLPAPER_OFFSET, offset);
Sunny Goyalc677b6b2016-10-17 09:59:01 +01001891
1892 String pickerPackage = getString(R.string.wallpaper_picker_package);
Tony85efb4b2017-06-02 13:06:10 -07001893 boolean hasTargetPackage = !TextUtils.isEmpty(pickerPackage);
1894 if (hasTargetPackage) {
Sunny Goyalc677b6b2016-10-17 09:59:01 +01001895 intent.setPackage(pickerPackage);
1896 }
1897
Sunny Goyala5ace712017-11-15 17:12:51 -08001898 final Bundle launchOptions;
1899 if (v != null) {
1900 intent.setSourceBounds(getViewBounds(v));
1901 // If there is no target package, use the default intent chooser animation
1902 launchOptions = hasTargetPackage ? getActivityLaunchOptions(v) : null;
1903 } else {
1904 launchOptions = null;
1905 }
Sunny Goyalc677b6b2016-10-17 09:59:01 +01001906 try {
Sunny Goyala5ace712017-11-15 17:12:51 -08001907 startActivityForResult(intent, REQUEST_PICK_WALLPAPER, launchOptions);
Sunny Goyalc677b6b2016-10-17 09:59:01 +01001908 } catch (ActivityNotFoundException e) {
1909 setWaitingForResult(null);
1910 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1911 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001912 }
1913
Sunny Goyala7ce1662016-05-31 15:01:35 -07001914 private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 try {
Sunny Goyala7ce1662016-05-31 15:01:35 -07001916 StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
1917 try {
1918 // Temporarily disable deathPenalty on all default checks. For eg, shortcuts
1919 // containing file Uri's would cause a crash as penaltyDeathOnFileUriExposure
1920 // is enabled by default on NYC.
1921 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
1922 .penaltyLog().build());
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001923
1924 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
1925 String id = ((ShortcutInfo) info).getDeepShortcutId();
1926 String packageName = intent.getPackage();
Sunny Goyaldde4fd92016-11-21 16:02:39 +05301927 DeepShortcutManager.getInstance(this).startShortcut(
Sunny Goyal9994b2b2016-06-23 14:17:24 -07001928 packageName, id, intent.getSourceBounds(), optsBundle, info.user);
Tony Wickhambfbf7f92016-05-19 11:19:39 -07001929 } else {
1930 // Could be launching some bookkeeping activity
1931 startActivity(intent, optsBundle);
1932 }
Sunny Goyala7ce1662016-05-31 15:01:35 -07001933 } finally {
1934 StrictMode.setVmPolicy(oldPolicy);
Kenny Guy1317e2d2014-05-08 18:52:50 +01001935 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 } catch (SecurityException e) {
Sunny Goyala7ce1662016-05-31 15:01:35 -07001937 // Due to legacy reasons, direct call shortcuts require Launchers to have the
1938 // corresponding permission. Show the appropriate permission prompt if that
1939 // is the case.
1940 if (intent.getComponent() == null
1941 && Intent.ACTION_CALL.equals(intent.getAction())
1942 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
1943 PackageManager.PERMISSION_GRANTED) {
Sunny Goyal2100c782016-08-22 16:00:03 -07001944
1945 setWaitingForResult(PendingRequestArgs
1946 .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
Sunny Goyala7ce1662016-05-31 15:01:35 -07001947 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
1948 REQUEST_PERMISSION_CALL_PHONE);
1949 } else {
1950 // No idea why this was thrown.
1951 throw e;
Sunny Goyal28c6b962015-10-12 11:42:05 -07001952 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953 }
1954 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001955
Sunny Goyalfe770c92016-09-27 14:38:58 -07001956 @TargetApi(Build.VERSION_CODES.M)
Tonye3c59252017-05-02 21:32:27 -07001957 public Bundle getActivityLaunchOptions(View v) {
Sunny Goyala7ce1662016-05-31 15:01:35 -07001958 if (Utilities.ATLEAST_MARSHMALLOW) {
1959 int left = 0, top = 0;
1960 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
Hyunyoung Song1322f9c2017-06-23 14:57:38 -07001961 if (v instanceof BubbleTextView) {
Sunny Goyala7ce1662016-05-31 15:01:35 -07001962 // Launch from center of icon, not entire view
Hyunyoung Song1322f9c2017-06-23 14:57:38 -07001963 Drawable icon = ((BubbleTextView) v).getIcon();
Sunny Goyala7ce1662016-05-31 15:01:35 -07001964 if (icon != null) {
1965 Rect bounds = icon.getBounds();
1966 left = (width - bounds.width()) / 2;
1967 top = v.getPaddingTop();
1968 width = bounds.width();
1969 height = bounds.height();
1970 }
1971 }
1972 return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height).toBundle();
1973 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
1974 // On L devices, we use the device default slide-up transition.
1975 // On L MR1 devices, we use a custom version of the slide-up transition which
1976 // doesn't have the delay present in the device default.
1977 return ActivityOptions.makeCustomAnimation(
1978 this, R.anim.task_open_enter, R.anim.no_anim).toBundle();
1979 }
1980 return null;
1981 }
1982
Tonye3c59252017-05-02 21:32:27 -07001983 public Rect getViewBounds(View v) {
Sunny Goyal0eca4e22016-07-20 11:43:06 -07001984 int[] pos = new int[2];
1985 v.getLocationOnScreen(pos);
1986 return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight());
1987 }
1988
Sunny Goyala7ce1662016-05-31 15:01:35 -07001989 public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -07001990 mAppLaunchSuccess = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001991 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
1992 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -07001993 return mAppLaunchSuccess;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001994 }
Sunny Goyala7ce1662016-05-31 15:01:35 -07001995 // Only launch using the new animation if the shortcut has not opted out (this is a
1996 // private contract between launcher and may be ignored in the future).
1997 boolean useLaunchAnimation = (v != null) &&
1998 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1999 Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null;
2000
Sunny Goyal24bb66a2017-03-21 15:12:01 -07002001 UserHandle user = item == null ? null : item.user;
Sunny Goyala7ce1662016-05-31 15:01:35 -07002002
2003 // Prepare intent
2004 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2005 if (v != null) {
Sunny Goyal0eca4e22016-07-20 11:43:06 -07002006 intent.setSourceBounds(getViewBounds(v));
Sunny Goyala7ce1662016-05-31 15:01:35 -07002007 }
2008 try {
Mario Bertschler0fc6f682017-02-17 12:16:13 -08002009 if (Utilities.ATLEAST_MARSHMALLOW
2010 && (item instanceof ShortcutInfo)
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002011 && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT
Mario Bertschler0fc6f682017-02-17 12:16:13 -08002012 || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT)
Sunny Goyale6e72002017-01-12 16:55:36 -08002013 && !((ShortcutInfo) item).isPromise()) {
Sunny Goyala7ce1662016-05-31 15:01:35 -07002014 // Shortcuts need some special checks due to legacy reasons.
2015 startShortcutIntentSafely(intent, optsBundle, item);
Sunny Goyal7c74e4a2016-12-15 15:53:17 -08002016 } else if (user == null || user.equals(Process.myUserHandle())) {
Sunny Goyala7ce1662016-05-31 15:01:35 -07002017 // Could be launching some bookkeeping activity
2018 startActivity(intent, optsBundle);
2019 } else {
2020 LauncherAppsCompat.getInstance(this).startActivityForProfile(
2021 intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
2022 }
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002023
2024 if (v instanceof BubbleTextView) {
2025 // This is set to the view that launched the activity that navigated the user away
2026 // from launcher. Since there is no callback for when the activity has finished
2027 // launching, enable the press state and keep this reference to reset the press
2028 // state when we return to launcher.
2029 BubbleTextView btv = (BubbleTextView) v;
2030 btv.setStayPressed(true);
2031 setOnResumeCallback(btv);
2032 }
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -07002033 mAppLaunchSuccess = true;
2034 getUserEventDispatcher().logAppLaunch(v, intent); // TODO for discovered apps b/35802115
Sunny Goyala7ce1662016-05-31 15:01:35 -07002035 } catch (ActivityNotFoundException|SecurityException e) {
2036 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2037 Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e);
2038 }
Hyunyoung Song7fb3ccc2017-10-17 15:39:46 -07002039 return mAppLaunchSuccess;
Michael Jurka86a720e2012-05-09 11:23:23 -07002040 }
2041
Tony Wickhamdadb3042016-02-24 11:07:00 -08002042 @Override
Jon Miranda379198e2016-09-23 08:54:40 -07002043 public boolean dispatchTouchEvent(MotionEvent ev) {
2044 mLastDispatchTouchEventX = ev.getX();
2045 return super.dispatchTouchEvent(ev);
2046 }
2047
2048 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002050 if (!isDraggingEnabled()) return false;
2051 if (isWorkspaceLocked()) return false;
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002052 if (!isInState(NORMAL) && !isInState(OVERVIEW)) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053
Jon Miranda51f037d2016-11-07 08:37:20 -08002054 boolean ignoreLongPressToOverview =
2055 mDeviceProfile.shouldIgnoreLongPressToOverview(mLastDispatchTouchEventX);
Jon Miranda379198e2016-09-23 08:54:40 -07002056
Adam Cohen1697b792013-09-17 19:08:21 -07002057 if (v instanceof Workspace) {
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002058 if (!isInState(OVERVIEW)) {
Jon Mirandacc42c5b2016-10-27 17:15:27 -07002059 if (!mWorkspace.isTouchActive() && !ignoreLongPressToOverview) {
Sunny Goyal6c46a6d2016-11-23 02:24:32 +05302060 getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS,
2061 Action.Direction.NONE, ContainerType.WORKSPACE,
Jon Mirandaf3e35d92016-10-05 14:08:11 -07002062 mWorkspace.getCurrentPage());
Sunny Goyala5ace712017-11-15 17:12:51 -08002063 UiFactory.onWorkspaceLongPress(this);
Adam Cohen93c97562013-09-26 13:48:01 -07002064 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2065 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2066 return true;
2067 } else {
2068 return false;
2069 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07002070 } else {
2071 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07002072 }
Adam Cohen1697b792013-09-17 19:08:21 -07002073 }
2074
Adam Cohene0aaa0d2014-05-12 12:44:22 -07002075 CellLayout.CellInfo longClickCellInfo = null;
2076 View itemUnderLongClick = null;
2077 if (v.getTag() instanceof ItemInfo) {
2078 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002079 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07002080 itemUnderLongClick = longClickCellInfo.cell;
Sunny Goyal2100c782016-08-22 16:00:03 -07002081 mPendingRequestArgs = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002082 }
2083
Winson Chung3d503fb2011-07-13 17:25:49 -07002084 // The hotseat touch handling does not go through Workspace, and we always allow long press
2085 // on hotseat items.
Sunny Goyal8e2133b2015-05-06 13:39:07 -07002086 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002087 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002088 // User long pressed on empty space
Sunny Goyalc99cb172017-10-19 16:15:09 -07002089 if (mWorkspace.isPageRearrangeEnabled()) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002090 mWorkspace.startReordering(v);
Sunny Goyal6c46a6d2016-11-23 02:24:32 +05302091 getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS,
2092 Action.Direction.NONE, ContainerType.OVERVIEW);
Adam Cohend3ecce92013-09-16 14:58:00 -07002093 } else {
Jon Mirandacc42c5b2016-10-27 17:15:27 -07002094 if (ignoreLongPressToOverview) {
Jon Miranda379198e2016-09-23 08:54:40 -07002095 return false;
2096 }
Sunny Goyal6c46a6d2016-11-23 02:24:32 +05302097 getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS,
2098 Action.Direction.NONE, ContainerType.WORKSPACE,
Jon Mirandaf3e35d92016-10-05 14:08:11 -07002099 mWorkspace.getCurrentPage());
Sunny Goyala5ace712017-11-15 17:12:51 -08002100 UiFactory.onWorkspaceLongPress(this);
Adam Cohendedbd962013-07-11 14:21:49 -07002101 }
Jon Miranda379198e2016-09-23 08:54:40 -07002102 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2103 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002104 } else {
Sunny Goyalbb011da2016-06-15 15:42:29 -07002105 final boolean isAllAppsButton =
2106 !FeatureFlags.NO_ALL_APPS_ICON && isHotseatLayout(v) &&
2107 mDeviceProfile.inv.isAllAppsButtonRank(mHotseat.getOrderInHotseat(
2108 longClickCellInfo.cellX, longClickCellInfo.cellY));
Dan Sandlere26d0942014-01-13 14:30:14 -05002109 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002110 // User long pressed on an item
Tony Wickham10236d62016-09-28 12:49:25 -07002111 mWorkspace.startDrag(longClickCellInfo, new DragOptions());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 }
2113 }
2114 }
2115 return true;
2116 }
2117
Winson Chung3d503fb2011-07-13 17:25:49 -07002118 boolean isHotseatLayout(View layout) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08002119 // TODO: Remove this method
Winson Chung3d503fb2011-07-13 17:25:49 -07002120 return mHotseat != null && layout != null &&
2121 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2122 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002123
Winson Chung3d503fb2011-07-13 17:25:49 -07002124 /**
2125 * Returns the CellLayout of the specified container at the specified screen.
2126 */
Sunny Goyal92820592015-03-02 11:31:35 -08002127 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002128 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2129 if (mHotseat != null) {
2130 return mHotseat.getLayout();
2131 } else {
2132 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002133 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002134 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002135 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002136 }
2137 }
2138
Michael Jurkae326f182011-11-21 14:05:46 -08002139 @Override
2140 public void onTrimMemory(int level) {
2141 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07002142 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2143 // The widget preview db can result in holding onto over
2144 // 3MB of memory for caching which isn't necessary.
2145 SQLiteDatabase.releaseMemory();
2146
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08002147 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07002148 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08002149 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01002150 if (mLauncherCallbacks != null) {
2151 mLauncherCallbacks.onTrimMemory(level);
2152 }
Michael Jurkae326f182011-11-21 14:05:46 -08002153 }
2154
Michael Jurkad7c28052012-04-27 15:43:36 -07002155 @Override
2156 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07002157 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07002158 final List<CharSequence> text = event.getText();
2159 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07002160 // Populate event with a fake title based on the current state.
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002161 // TODO: When can workspace be null?
2162 text.add(mWorkspace == null
2163 ? getString(R.string.all_apps_home_button_label)
Sunny Goyalea609262017-10-25 15:47:38 -07002164 : mStateManager.getState().getDescription(this));
Michael Jurkad7c28052012-04-27 15:43:36 -07002165 return result;
2166 }
2167
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002168 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07002169 * If the activity is currently paused, signal that we need to run the passed Runnable
2170 * in onResume.
2171 *
2172 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07002173 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
2174 * wrong when we're not running, and if the activity comes back to what the configuration was
2175 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07002176 *
2177 * Implementation of the method from LauncherModel.Callbacks.
2178 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07002179 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07002180 */
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002181 @Thunk boolean waitUntilResume(Runnable run) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07002182 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07002183 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002184 if (run instanceof RunnableWithId) {
2185 // Remove any runnables which have the same id
2186 while (mBindOnResumeCallbacks.remove(run)) { }
Michael Jurkac402cd92013-05-20 15:49:32 +02002187 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07002188 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07002189 return true;
2190 } else {
2191 return false;
2192 }
2193 }
2194
Sunny Goyal3dce5f32017-10-05 11:40:05 -07002195 public void setOnResumeCallback(OnResumeCallback callback) {
2196 if (mOnResumeCallback != null) {
2197 mOnResumeCallback.onLauncherResume();
2198 }
2199 mOnResumeCallback = callback;
Michael Jurka1e2f4652013-07-08 18:03:46 -07002200 }
2201
Michael Jurka7607c2f2013-04-03 14:33:19 -07002202 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002203 * If the activity is currently paused, signal that we need to re-run the loader
2204 * in onResume.
2205 *
2206 * This needs to be called from incoming places where resources might have been loaded
2207 * while we are paused. That is becaues the Configuration might be wrong
2208 * when we're not running, and if it comes back to what it was when we
2209 * were paused, we are not restarted.
2210 *
2211 * Implementation of the method from LauncherModel.Callbacks.
2212 *
2213 * @return true if we are currently paused. The caller might be able to
2214 * skip some work in that case since we will come back again.
2215 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07002216 @Override
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002217 public boolean setLoadOnResume() {
2218 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07002219 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002220 mOnResumeNeedsLoad = true;
2221 return true;
2222 } else {
2223 return false;
2224 }
2225 }
2226
2227 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002228 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002229 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07002230 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04002231 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002232 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002233 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002234 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07002235 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07002236 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002237 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002238
Joe Onorato9c1289c2009-08-17 11:03:03 -04002239 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07002240 * Clear any pending bind callbacks. This is called when is loader is planning to
2241 * perform a full rebind from scratch.
2242 */
2243 @Override
2244 public void clearPendingBinds() {
2245 mBindOnResumeCallbacks.clear();
2246 if (mPendingExecutor != null) {
2247 mPendingExecutor.markCompleted();
2248 mPendingExecutor = null;
2249 }
2250 }
2251
2252 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002253 * Refreshes the shortcuts shown on the workspace.
2254 *
2255 * Implementation of the method from LauncherModel.Callbacks.
2256 */
2257 public void startBinding() {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002258 TraceHelper.beginSection("startBinding");
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002259 // Floating panels (except the full widget sheet) are associated with individual icons. If
2260 // we are starting a fresh bind, close all such panels as all the icons are about
2261 // to go away.
2262 AbstractFloatingView.closeOpenViews(this, true,
Sunny Goyal7ede6112017-12-05 15:11:21 -08002263 AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE);
Jon Miranda6dc7f1e2017-02-21 12:37:51 -08002264
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002265 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08002266
Winson Chungd64d1762013-08-20 14:37:16 -07002267 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07002268 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07002269 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07002270
Winson Chung3d503fb2011-07-13 17:25:49 -07002271 if (mHotseat != null) {
2272 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002273 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002274 TraceHelper.endSection("startBinding");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002275 }
2276
Adam Cohendcd297f2013-06-18 13:13:40 -07002277 @Override
2278 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002279 // Make sure the first screen is always at the start.
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07002280 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
2281 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002282 orderedScreenIds.remove(Workspace.FIRST_SCREEN_ID);
2283 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
Rajeev Kumar43c0f582017-06-23 15:34:55 -07002284 LauncherModel.updateWorkspaceScreenOrder(this, orderedScreenIds);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07002285 } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
2286 // If there are no screens, we need to have an empty screen
2287 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07002288 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002289 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07002290
Winsonc7d2e832016-07-28 12:24:55 -07002291 // After we have added all the screens, if the wallpaper was locked to the default state,
2292 // then notify to indicate that it can be released and a proper wallpaper offset can be
2293 // computed before the next layout
2294 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07002295 }
2296
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002297 private void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07002298 int count = orderedScreenIds.size();
2299 for (int i = 0; i < count; i++) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002300 long screenId = orderedScreenIds.get(i);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07002301 if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002302 // No need to bind the first screen, as its always bound.
2303 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
2304 }
Adam Cohendcd297f2013-06-18 13:13:40 -07002305 }
Adam Cohendcd297f2013-06-18 13:13:40 -07002306 }
2307
Sunny Goyalb23980c2017-08-17 07:45:25 -07002308 @Override
Winson Chungd64d1762013-08-20 14:37:16 -07002309 public void bindAppsAdded(final ArrayList<Long> newScreens,
2310 final ArrayList<ItemInfo> addNotAnimated,
Sunny Goyalb23980c2017-08-17 07:45:25 -07002311 final ArrayList<ItemInfo> addAnimated) {
Winson Chungd64d1762013-08-20 14:37:16 -07002312 Runnable r = new Runnable() {
2313 public void run() {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002314 bindAppsAdded(newScreens, addNotAnimated, addAnimated);
Winson Chungd64d1762013-08-20 14:37:16 -07002315 }
2316 };
2317 if (waitUntilResume(r)) {
2318 return;
2319 }
2320
Winson Chungd64d1762013-08-20 14:37:16 -07002321 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08002322 if (newScreens != null) {
2323 bindAddScreens(newScreens);
2324 }
Winson Chungd64d1762013-08-20 14:37:16 -07002325
2326 // We add the items without animation on non-visible pages, and with
2327 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08002328 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002329 bindItems(addNotAnimated, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002330 }
Adam Cohen76a47a12014-02-05 11:47:43 -08002331 if (addAnimated != null && !addAnimated.isEmpty()) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002332 bindItems(addAnimated, true);
Winson Chungd64d1762013-08-20 14:37:16 -07002333 }
Winson Chungc58497e2013-09-03 17:48:37 -07002334
Winson Chung87412982013-10-03 18:34:14 -07002335 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07002336 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chungd64d1762013-08-20 14:37:16 -07002337 }
2338
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002339 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002340 * Bind the items start-end from the list.
2341 *
2342 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002343 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07002344 @Override
Sunny Goyalb23980c2017-08-17 07:45:25 -07002345 public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07002346 Runnable r = new Runnable() {
2347 public void run() {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002348 bindItems(items, forceAnimateIcons);
Winson Chungd64d1762013-08-20 14:37:16 -07002349 }
2350 };
2351 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07002352 return;
2353 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002354
Sunny Goyal3be633b2016-12-08 09:59:25 -08002355 // Get the list of added items and intersect them with the set of items here
Winson Chung64359a52013-07-08 17:17:08 -07002356 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
Rajeev Kumar43c0f582017-06-23 15:34:55 -07002357 final Collection<Animator> bounceAnims = new ArrayList<>();
Winson Chung997a9232013-07-24 15:33:46 -07002358 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07002359 Workspace workspace = mWorkspace;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002360 long newItemsScreenId = -1;
Sunny Goyalb23980c2017-08-17 07:45:25 -07002361 int end = items.size();
2362 for (int i = 0; i < end; i++) {
Sunny Goyal3be633b2016-12-08 09:59:25 -08002363 final ItemInfo item = items.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002364
2365 // Short circuit if we are loading dock items for a configuration which has no dock
2366 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2367 mHotseat == null) {
2368 continue;
2369 }
2370
Sunny Goyal639e9062015-08-19 19:17:06 -07002371 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002372 switch (item.itemType) {
2373 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2374 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Sunny Goyal3be633b2016-12-08 09:59:25 -08002375 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: {
Winson Chungf0c6ae02012-03-21 16:10:31 -07002376 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07002377 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002378 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002379 }
2380 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
Sunny Goyal639e9062015-08-19 19:17:06 -07002381 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002382 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Sunny Goyal1cd01b02016-11-09 10:43:58 -08002383 (FolderInfo) item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002384 break;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002385 }
Sunny Goyal952e63d2017-08-16 04:59:08 -07002386 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2387 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: {
Sunny Goyala9a1a212017-08-18 01:03:21 -07002388 view = inflateAppWidget((LauncherAppWidgetInfo) item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002389 if (view == null) {
2390 continue;
Sunny Goyal3be633b2016-12-08 09:59:25 -08002391 }
Sunny Goyal3be633b2016-12-08 09:59:25 -08002392 break;
2393 }
Winson Chungc763c4e2013-07-19 13:49:06 -07002394 default:
2395 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04002396 }
Sunny Goyal639e9062015-08-19 19:17:06 -07002397
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002398 /*
2399 * Remove colliding items.
2400 */
2401 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
2402 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
2403 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
2404 View v = cl.getChildAt(item.cellX, item.cellY);
2405 Object tag = v.getTag();
2406 String desc = "Collision while binding workspace item: " + item
2407 + ". Collides with " + tag;
Sunny Goyal3d706ad2017-03-06 16:56:39 -08002408 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002409 throw (new RuntimeException(desc));
2410 } else {
2411 Log.d(TAG, desc);
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002412 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002413 continue;
2414 }
2415 }
2416 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302417 workspace.addInScreenFromBind(view, item);
Sunny Goyal639e9062015-08-19 19:17:06 -07002418 if (animateIcons) {
2419 // Animate all the applications up now
2420 view.setAlpha(0f);
2421 view.setScaleX(0f);
2422 view.setScaleY(0f);
2423 bounceAnims.add(createNewAppBounceAnimation(view, i));
Sunny Goyal3be633b2016-12-08 09:59:25 -08002424 newItemsScreenId = item.screenId;
Sunny Goyal639e9062015-08-19 19:17:06 -07002425 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002426 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07002427
Winson Chung997a9232013-07-24 15:33:46 -07002428 if (animateIcons) {
2429 // Animate to the correct page
Sunny Goyal3be633b2016-12-08 09:59:25 -08002430 if (newItemsScreenId > -1) {
Winson Chung997a9232013-07-24 15:33:46 -07002431 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Sunny Goyal3be633b2016-12-08 09:59:25 -08002432 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07002433 final Runnable startBounceAnimRunnable = new Runnable() {
2434 public void run() {
2435 anim.playTogether(bounceAnims);
2436 anim.start();
2437 }
2438 };
Sunny Goyal3be633b2016-12-08 09:59:25 -08002439 if (newItemsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07002440 // We post the animation slightly delayed to prevent slowdowns
2441 // when we are loading right after we return to launcher.
2442 mWorkspace.postDelayed(new Runnable() {
2443 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00002444 if (mWorkspace != null) {
2445 mWorkspace.snapToPage(newScreenIndex);
2446 mWorkspace.postDelayed(startBounceAnimRunnable,
2447 NEW_APPS_ANIMATION_DELAY);
2448 }
Winson Chung94d67682013-09-25 16:29:40 -07002449 }
2450 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07002451 } else {
2452 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07002453 }
2454 }
Winson Chung64359a52013-07-08 17:17:08 -07002455 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002456 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002457 }
2458
Joe Onorato9c1289c2009-08-17 11:03:03 -04002459 /**
2460 * Add the views for a widget to the workspace.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002461 */
Sunny Goyala9a1a212017-08-18 01:03:21 -07002462 public void bindAppWidget(LauncherAppWidgetInfo item) {
2463 View view = inflateAppWidget(item);
2464 if (view != null) {
2465 mWorkspace.addInScreen(view, item);
2466 mWorkspace.requestLayout();
2467 }
2468 }
2469
2470 private View inflateAppWidget(LauncherAppWidgetInfo item) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002471 if (mIsSafeModeEnabled) {
Sunny Goyald5462aa2016-11-22 16:52:39 +05302472 PendingAppWidgetHostView view =
2473 new PendingAppWidgetHostView(this, item, mIconCache, true);
2474 prepareAppWidget(view, item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002475 return view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002476 }
2477
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002478 TraceHelper.beginSection("BIND_WIDGET");
Joe Onorato9c1289c2009-08-17 11:03:03 -04002479
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002480 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08002481
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002482 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
2483 // If the provider is not ready, bind as a pending widget.
2484 appWidgetInfo = null;
2485 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2486 // The widget id is not valid. Try to find the widget based on the provider info.
2487 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
2488 } else {
2489 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
2490 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002491
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002492 // If the provider is ready, but the width is not yet restored, try to restore it.
2493 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
2494 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07002495 if (appWidgetInfo == null) {
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002496 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
2497 + " belongs to component " + item.providerName
2498 + ", as the provider is null");
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002499 getModelWriter().deleteItemFromDatabase(item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002500 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002501 }
Sunny Goyalff572272014-07-23 13:58:07 -07002502
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002503 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002504 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyald478c832016-04-01 12:04:16 -07002505 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
2506 // Id has not been allocated yet. Allocate a new id.
2507 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
2508 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyalff572272014-07-23 13:58:07 -07002509
Sunny Goyald478c832016-04-01 12:04:16 -07002510 // Also try to bind the widget. If the bind fails, the user will be shown
2511 // a click to setup UI, which will ask for the bind permission.
Sunny Goyala52ecb02016-12-16 15:04:51 -08002512 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
Sunny Goyald478c832016-04-01 12:04:16 -07002513 pendingInfo.spanX = item.spanX;
2514 pendingInfo.spanY = item.spanY;
2515 pendingInfo.minSpanX = item.minSpanX;
2516 pendingInfo.minSpanY = item.minSpanY;
2517 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyal86df1382016-08-10 15:03:22 -07002518
2519 boolean isDirectConfig =
2520 item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
2521 if (isDirectConfig && item.bindOptions != null) {
2522 Bundle newOptions = item.bindOptions.getExtras();
2523 if (options != null) {
2524 newOptions.putAll(options);
2525 }
2526 options = newOptions;
2527 }
Sunny Goyald478c832016-04-01 12:04:16 -07002528 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2529 item.appWidgetId, appWidgetInfo, options);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002530
Sunny Goyal86df1382016-08-10 15:03:22 -07002531 // We tried to bind once. If we were not able to bind, we would need to
2532 // go through the permission dialog, which means we cannot skip the config
2533 // activity.
2534 item.bindOptions = null;
2535 item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
2536
Sunny Goyald478c832016-04-01 12:04:16 -07002537 // Bind succeeded
2538 if (success) {
2539 // If the widget has a configure activity, it is still needs to set it up,
2540 // otherwise the widget is ready to go.
Sunny Goyal86df1382016-08-10 15:03:22 -07002541 item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
Sunny Goyald478c832016-04-01 12:04:16 -07002542 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
2543 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002544 }
Sunny Goyald478c832016-04-01 12:04:16 -07002545
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002546 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002547 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002548 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002549 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002550 // The widget was marked as UI not ready, but there is no configure activity to
2551 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07002552 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002553 getModelWriter().updateItemInDatabase(item);
Sunny Goyalff572272014-07-23 13:58:07 -07002554 }
Sunny Goyalff572272014-07-23 13:58:07 -07002555 }
2556
Sunny Goyald5462aa2016-11-22 16:52:39 +05302557 final AppWidgetHostView view;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002558 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002559 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002560 if (appWidgetInfo == null) {
Sunny Goyal713edfc2016-05-06 09:58:34 -07002561 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Sunny Goyal56c73602015-09-25 12:55:01 -07002562 deleteWidgetInfo(item);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002563 return null;
Sunny Goyal56c73602015-09-25 12:55:01 -07002564 }
2565
Sunny Goyal233ee962015-08-03 13:05:01 -07002566 item.minSpanX = appWidgetInfo.minSpanX;
2567 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyald5462aa2016-11-22 16:52:39 +05302568 view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
Sunny Goyal651077b2014-06-30 14:15:31 -07002569 } else {
Sunny Goyald5462aa2016-11-22 16:52:39 +05302570 view = new PendingAppWidgetHostView(this, item, mIconCache, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07002571 }
Sunny Goyald5462aa2016-11-22 16:52:39 +05302572 prepareAppWidget(view, item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002573
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002574 TraceHelper.endSection("BIND_WIDGET", "id=" + item.appWidgetId);
Sunny Goyalb23980c2017-08-17 07:45:25 -07002575 return view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002576 }
2577
Sunny Goyalff572272014-07-23 13:58:07 -07002578 /**
2579 * Restores a pending widget.
2580 *
2581 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07002582 */
Sunny Goyald478c832016-04-01 12:04:16 -07002583 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07002584 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
2585 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
2586 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07002587 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07002588 }
2589
Sunny Goyal0fc1be12014-08-11 17:05:23 -07002590 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07002591 info.restoreStatus = finalRestoreFlag;
Jon Miranda2b823f42017-05-02 18:36:18 -07002592 if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
2593 info.pendingItemInfo = null;
2594 }
Sunny Goyalff572272014-07-23 13:58:07 -07002595
Sunny Goyalba47faa2017-10-04 16:50:57 -07002596 if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
2597 view.reinflate();
2598 }
2599
Sunny Goyal43bf11d2017-02-02 13:52:53 -08002600 getModelWriter().updateItemInDatabase(info);
Sunny Goyald478c832016-04-01 12:04:16 -07002601 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07002602 }
2603
Adam Cohen1462de32012-07-24 22:34:36 -07002604 public void onPageBoundSynchronously(int page) {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002605 mSynchronouslyBoundPage = page;
Adam Cohen1462de32012-07-24 22:34:36 -07002606 }
2607
Sunny Goyal527c7d32015-08-28 15:19:36 -07002608 @Override
2609 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
2610 if (mPendingExecutor != null) {
2611 mPendingExecutor.markCompleted();
2612 }
2613 mPendingExecutor = executor;
2614 executor.attachTo(this);
2615 }
2616
2617 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
2618 if (mPendingExecutor == executor) {
2619 mPendingExecutor = null;
2620 }
2621 }
2622
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07002623 @Override
2624 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
2625 Runnable r = new Runnable() {
2626 public void run() {
2627 finishFirstPageBind(executor);
2628 }
2629 };
2630 if (waitUntilResume(r)) {
2631 return;
2632 }
2633
2634 Runnable onComplete = new Runnable() {
2635 @Override
2636 public void run() {
2637 if (executor != null) {
2638 executor.onLoadAnimationCompleted();
2639 }
2640 }
2641 };
2642 if (mDragLayer.getAlpha() < 1) {
2643 mDragLayer.animate().alpha(1).withEndAction(onComplete).start();
2644 } else {
2645 onComplete.run();
2646 }
2647 }
2648
Joe Onorato9c1289c2009-08-17 11:03:03 -04002649 /**
2650 * Callback saying that there aren't any more items to bind.
2651 *
2652 * Implementation of the method from LauncherModel.Callbacks.
2653 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08002654 public void finishBindingItems() {
Sunny Goyalf4aceab2017-12-06 16:16:31 -08002655 Runnable r = this::finishBindingItems;
Winson Chungd64d1762013-08-20 14:37:16 -07002656 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07002657 return;
2658 }
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002659 TraceHelper.beginSection("finishBindingItems");
Adam Cohen1462de32012-07-24 22:34:36 -07002660 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002661
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002662 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07002663
Sunny Goyal2100c782016-08-22 16:00:03 -07002664 if (mPendingActivityResult != null) {
2665 handleActivityResult(mPendingActivityResult.requestCode,
2666 mPendingActivityResult.resultCode, mPendingActivityResult.data);
2667 mPendingActivityResult = null;
Adam Cohendb364c32014-05-20 14:23:40 -07002668 }
2669
Sunny Goyala474a9b2017-05-04 16:47:11 -07002670 InstallShortcutReceiver.disableAndFlushInstallQueue(
2671 InstallShortcutReceiver.FLAG_LOADER_RUNNING, this);
Adam Cohen9211d422014-10-07 18:14:53 -07002672
Tony Wickham010d2552017-01-20 08:15:28 -08002673 NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
Sunny Goyalfca6bc92017-09-28 16:28:34 -07002674 TraceHelper.endSection("finishBindingItems");
Winson Chungf0c6ae02012-03-21 16:10:31 -07002675 }
2676
Winson Chunga2413752012-04-03 14:22:34 -07002677 private boolean canRunNewAppsAnimation() {
2678 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07002679 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07002680 }
2681
Winson Chungc9168342013-06-26 14:54:55 -07002682 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07002683 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07002684 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
2685 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07002686 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07002687 return bounceAnim;
2688 }
2689
Adam Cohen27772732013-11-11 14:00:56 +00002690 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07002691 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00002692 }
2693
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002694 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002695 * Add the icons for all apps.
2696 *
2697 * Implementation of the method from LauncherModel.Callbacks.
2698 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002699 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002700 Runnable r = new RunnableWithId(RUNNABLE_ID_BIND_APPS) {
2701 public void run() {
2702 bindAllApplications(apps);
2703 }
2704 };
2705 if (waitUntilResume(r)) {
Winson Chungbb785c62015-05-05 10:05:08 -07002706 return;
2707 }
2708
Winson Chungb745afb2015-03-02 11:51:23 -08002709 if (mAppsView != null) {
Tony2917a8b2017-07-31 23:29:42 -07002710 Executor pendingExecutor = getPendingExecutor();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002711 if (pendingExecutor != null && !isInState(ALL_APPS)) {
Tony2917a8b2017-07-31 23:29:42 -07002712 // Wait until the fade in animation has finished before setting all apps list.
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002713 pendingExecutor.execute(r);
Tony2917a8b2017-07-31 23:29:42 -07002714 return;
2715 }
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002716
Winson Chungb745afb2015-03-02 11:51:23 -08002717 mAppsView.setApps(apps);
2718 }
Adam Cohen9211d422014-10-07 18:14:53 -07002719 if (mLauncherCallbacks != null) {
2720 mLauncherCallbacks.bindAllApplications(apps);
2721 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002722 }
2723
2724 /**
Tony2917a8b2017-07-31 23:29:42 -07002725 * Returns an Executor that will run after the launcher is first drawn (including after the
2726 * initial fade in animation). Returns null if the first draw has already occurred.
2727 */
2728 public @Nullable Executor getPendingExecutor() {
2729 return mPendingExecutor != null && mPendingExecutor.canQueue() ? mPendingExecutor : null;
2730 }
2731
2732 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002733 * Copies LauncherModel's map of activities to shortcut ids to Launcher's. This is necessary
2734 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
2735 */
2736 @Override
2737 public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMapCopy) {
Tony Wickham010d2552017-01-20 08:15:28 -08002738 mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
Tony Wickham1bce7fd2016-04-28 17:39:03 -07002739 }
2740
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002741 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002742 * A package was updated.
2743 *
2744 * Implementation of the method from LauncherModel.Callbacks.
2745 */
Sunny Goyalb23980c2017-08-17 07:45:25 -07002746 public void bindAppsAddedOrUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07002747 Runnable r = new Runnable() {
2748 public void run() {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002749 bindAppsAddedOrUpdated(apps);
Winson Chungd64d1762013-08-20 14:37:16 -07002750 }
2751 };
2752 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07002753 return;
2754 }
2755
Winson Chungb745afb2015-03-02 11:51:23 -08002756 if (mAppsView != null) {
Sunny Goyalb23980c2017-08-17 07:45:25 -07002757 mAppsView.addOrUpdateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07002758 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002759 }
2760
Sunny Goyal4390ace2014-10-13 11:33:11 -07002761 @Override
Mario Bertschler08ffaae2017-03-20 11:30:27 -07002762 public void bindPromiseAppProgressUpdated(final PromiseAppInfo app) {
2763 Runnable r = new Runnable() {
2764 public void run() {
2765 bindPromiseAppProgressUpdated(app);
2766 }
2767 };
2768 if (waitUntilResume(r)) {
2769 return;
2770 }
2771
2772 if (mAppsView != null) {
2773 mAppsView.updatePromiseAppProgress(app);
2774 }
2775 }
2776
2777 @Override
Sunny Goyal4390ace2014-10-13 11:33:11 -07002778 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
2779 Runnable r = new Runnable() {
2780 public void run() {
2781 bindWidgetsRestored(widgets);
2782 }
2783 };
2784 if (waitUntilResume(r)) {
2785 return;
2786 }
2787 mWorkspace.widgetsRestored(widgets);
2788 }
2789
Joe Onorato9c1289c2009-08-17 11:03:03 -04002790 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002791 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002792 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002793 *
2794 * @param updated list of shortcuts which have changed.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002795 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07002796 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002797 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated, final UserHandle user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002798 Runnable r = new Runnable() {
2799 public void run() {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002800 bindShortcutsChanged(updated, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002801 }
2802 };
2803 if (waitUntilResume(r)) {
2804 return;
2805 }
2806
Sunny Goyal4390ace2014-10-13 11:33:11 -07002807 if (!updated.isEmpty()) {
2808 mWorkspace.updateShortcuts(updated);
2809 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07002810 }
2811
2812 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002813 * Update the state of a package, typically related to install state.
2814 *
2815 * Implementation of the method from LauncherModel.Callbacks.
2816 */
Sunny Goyale755d462014-07-22 13:48:29 -07002817 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07002818 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
2819 Runnable r = new Runnable() {
2820 public void run() {
2821 bindRestoreItemsChange(updates);
2822 }
2823 };
2824 if (waitUntilResume(r)) {
2825 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002826 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05002827
Sunny Goyal756adbc2015-04-16 15:20:51 -07002828 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07002829 }
2830
2831 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002832 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07002833 * in addition to specific applications to remove, the reason being that
2834 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002835 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07002836 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04002837 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07002838 @Override
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002839 public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) {
Winson Chungd64d1762013-08-20 14:37:16 -07002840 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07002841 public void run() {
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002842 bindWorkspaceComponentsRemoved(matcher);
Winson Chung83892cc2013-05-01 16:53:33 -07002843 }
Winson Chungd64d1762013-08-20 14:37:16 -07002844 };
2845 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07002846 return;
2847 }
Sunny Goyal6e13dd32017-08-17 03:01:19 -07002848 mWorkspace.removeItemsByMatcher(matcher);
2849 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002850 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07002851
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07002852 @Override
2853 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
2854 Runnable r = new Runnable() {
2855 public void run() {
2856 bindAppInfosRemoved(appInfos);
2857 }
2858 };
2859 if (waitUntilResume(r)) {
2860 return;
Joe Onorato36115782010-06-17 13:28:48 -04002861 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002862
Winson Chungdf95eb12013-10-16 14:57:07 -07002863 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08002864 if (mAppsView != null) {
2865 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07002866 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002867 }
Joe Onoratobe386092009-11-17 17:32:16 -08002868
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002869 @Override
Sunny Goyalf1fbc3f2017-10-10 15:21:15 -07002870 public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) {
2871 mPopupDataProvider.setAllWidgets(allWidgets);
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002872 Runnable r = new RunnableWithId(RUNNABLE_ID_BIND_WIDGETS) {
2873 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07002874 public void run() {
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002875 bindAllWidgets(allWidgets);
Winson Chung83892cc2013-05-01 16:53:33 -07002876 }
Michael Jurkac402cd92013-05-20 15:49:32 +02002877 };
Sunny Goyal49fc3f72017-08-18 10:17:06 -07002878 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07002879 return;
2880 }
2881
Tony Wickham26b17462017-03-20 17:12:24 -07002882 AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
2883 if (topView != null) {
2884 topView.onWidgetsBound();
2885 }
2886 }
2887
Tony Wickham86222d22017-03-29 15:30:43 -07002888 /**
2889 * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only
2890 * refreshes the widgets and shortcuts associated with the given package/user
2891 */
2892 public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) {
Sunny Goyalc6e97692017-06-02 13:46:55 -07002893 mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002894 }
2895
Sunny Goyalc99cb172017-10-19 16:15:09 -07002896 public boolean isRotationEnabled () {
2897 return mRotationEnabled;
Winson Chung400438b2011-01-16 17:53:48 -08002898 }
2899
Winson Chung80baf5a2010-08-09 16:03:15 -07002900 /**
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002901 * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
Joe Onoratobe386092009-11-17 17:32:16 -08002902 */
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002903 @Override
2904 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2905 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002906
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002907 if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
2908 writer.println(prefix + "Workspace Items");
Sunny Goyal7ce471b2017-08-02 03:37:39 -07002909 for (int i = 0; i < mWorkspace.getPageCount(); i++) {
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002910 writer.println(prefix + " Homescreen " + i);
2911
2912 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
2913 for (int j = 0; j < layout.getChildCount(); j++) {
2914 Object tag = layout.getChildAt(j).getTag();
2915 if (tag != null) {
2916 writer.println(prefix + " " + tag.toString());
2917 }
2918 }
2919 }
2920
2921 writer.println(prefix + " Hotseat");
2922 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
Sunny Goyala1365452015-10-01 15:46:24 -07002923 for (int j = 0; j < layout.getChildCount(); j++) {
2924 Object tag = layout.getChildAt(j).getTag();
2925 if (tag != null) {
2926 writer.println(prefix + " " + tag.toString());
2927 }
Adam Cohen4caf2982013-08-20 18:54:31 -07002928 }
Sunny Goyala1365452015-10-01 15:46:24 -07002929
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002930 try {
2931 FileLog.flushAll(writer);
2932 } catch (Exception e) {
2933 // Ignore
Sunny Goyala1365452015-10-01 15:46:24 -07002934 }
2935 }
2936
Hyunyoung Song3c7d9cb2017-01-30 15:11:27 -08002937 writer.println(prefix + "Misc:");
2938 writer.print(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading);
2939 writer.print(" mPendingRequestArgs=" + mPendingRequestArgs);
2940 writer.println(" mPendingActivityResult=" + mPendingActivityResult);
2941
2942 mModel.dumpState(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07002943
Adam Cohen9211d422014-10-07 18:14:53 -07002944 if (mLauncherCallbacks != null) {
2945 mLauncherCallbacks.dump(prefix, fd, writer, args);
2946 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07002947 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07002948
Sunny Goyal66b24572016-09-21 15:57:55 -07002949 @Override
2950 @TargetApi(Build.VERSION_CODES.N)
2951 public void onProvideKeyboardShortcuts(
2952 List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
2953
2954 ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>();
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002955 if (isInState(NORMAL)) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002956 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label),
2957 KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON));
2958 }
2959 View currentFocus = getCurrentFocus();
2960 if (new CustomActionsPopup(this, currentFocus).canShow()) {
2961 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions),
2962 KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON));
2963 }
Tony18c4aa42017-05-10 21:23:57 -05002964 if (currentFocus.getTag() instanceof ItemInfo
2965 && DeepShortcutManager.supportsShortcuts((ItemInfo) currentFocus.getTag())) {
Sunny Goyal66b24572016-09-21 15:57:55 -07002966 shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.action_deep_shortcut),
2967 KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON));
2968 }
2969 if (!shortcutInfos.isEmpty()) {
2970 data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos));
2971 }
2972
2973 super.onProvideKeyboardShortcuts(data, menu, deviceId);
2974 }
2975
2976 @Override
2977 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2978 if (event.hasModifiers(KeyEvent.META_CTRL_ON)) {
2979 switch (keyCode) {
2980 case KeyEvent.KEYCODE_A:
Sunny Goyal3e3f44c2017-10-23 17:14:52 -07002981 if (isInState(NORMAL)) {
2982 getStateManager().goToState(ALL_APPS);
Sunny Goyal66b24572016-09-21 15:57:55 -07002983 return true;
2984 }
2985 break;
2986 case KeyEvent.KEYCODE_S: {
2987 View focusedView = getCurrentFocus();
2988 if (focusedView instanceof BubbleTextView
2989 && focusedView.getTag() instanceof ItemInfo
2990 && mAccessibilityDelegate.performAction(focusedView,
2991 (ItemInfo) focusedView.getTag(),
2992 LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) {
Sunny Goyal00ac9202017-11-09 15:24:06 -08002993 PopupContainerWithArrow.getOpen(this).requestFocus();
Sunny Goyal66b24572016-09-21 15:57:55 -07002994 return true;
2995 }
2996 break;
2997 }
2998 case KeyEvent.KEYCODE_O:
2999 if (new CustomActionsPopup(this, getCurrentFocus()).show()) {
3000 return true;
3001 }
3002 break;
3003 }
3004 }
3005 return super.onKeyShortcut(keyCode, event);
3006 }
3007
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07003008 public static Launcher getLauncher(Context context) {
3009 if (context instanceof Launcher) {
3010 return (Launcher) context;
3011 }
3012 return ((Launcher) ((ContextWrapper) context).getBaseContext());
3013 }
3014
Sunny Goyal5a81c382017-03-20 15:08:06 -07003015 private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener {
Sunny Goyal745bad92016-05-02 10:54:12 -07003016
3017 @Override
3018 public void onSharedPreferenceChanged(
3019 SharedPreferences sharedPreferences, String key) {
3020 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(key)) {
Sunny Goyale13d4642017-05-22 15:58:42 -07003021 // Recreate the activity so that it initializes the rotation preference again.
3022 recreate();
Sunny Goyal745bad92016-05-02 10:54:12 -07003023 }
3024 }
Sunny Goyal745bad92016-05-02 10:54:12 -07003025 }
Sunny Goyal3dce5f32017-10-05 11:40:05 -07003026
Sunny Goyal7c8a65e2017-12-22 11:11:33 -08003027 @Override
3028 public void onActionModeStarted(ActionMode mode) {
3029 super.onActionModeStarted(mode);
3030 mCurrentActionMode = mode;
3031 }
3032
3033 @Override
3034 public void onActionModeFinished(ActionMode mode) {
3035 super.onActionModeFinished(mode);
3036 mCurrentActionMode = null;
3037 }
3038
3039 public boolean finishAutoCancelActionMode() {
3040 if (mCurrentActionMode != null && AUTO_CANCEL_ACTION_MODE == mCurrentActionMode.getTag()) {
3041 mCurrentActionMode.finish();
3042 return true;
3043 }
3044 return false;
3045 }
3046
Sunny Goyal3dce5f32017-10-05 11:40:05 -07003047 /**
3048 * Callback for listening for onResume
3049 */
3050 public interface OnResumeCallback {
3051
3052 void onLauncherResume();
3053 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003054}