The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 20 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
vadimt | 00d4255 | 2018-12-11 17:59:36 -0800 | [diff] [blame] | 21 | |
Pinyao Ting | a74b63a | 2019-07-17 23:26:06 -0700 | [diff] [blame] | 22 | import static com.android.launcher3.AbstractFloatingView.TYPE_ALL; |
| 23 | import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 24 | import static com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 25 | import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY; |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 26 | import static com.android.launcher3.LauncherState.ALL_APPS; |
| 27 | import static com.android.launcher3.LauncherState.NORMAL; |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 28 | import static com.android.launcher3.LauncherState.OVERVIEW; |
| 29 | import static com.android.launcher3.LauncherState.OVERVIEW_PEEK; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 30 | import static com.android.launcher3.Utilities.postAsyncCallback; |
Sunny Goyal | 6001ea2 | 2018-05-10 16:31:00 -0700 | [diff] [blame] | 31 | import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 32 | import static com.android.launcher3.logging.LoggerUtils.newContainerTarget; |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 33 | import static com.android.launcher3.logging.LoggerUtils.newTarget; |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 34 | import static com.android.launcher3.popup.SystemShortcut.APP_INFO; |
| 35 | import static com.android.launcher3.popup.SystemShortcut.DISMISS_PREDICTION; |
| 36 | import static com.android.launcher3.popup.SystemShortcut.INSTALL; |
| 37 | import static com.android.launcher3.popup.SystemShortcut.WIDGETS; |
Sunny Goyal | be8c340 | 2019-05-22 15:17:52 -0700 | [diff] [blame] | 38 | import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; |
Sunny Goyal | 326403e | 2017-10-02 12:45:10 -0700 | [diff] [blame] | 39 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 40 | import android.animation.Animator; |
Sunny Goyal | 6001ea2 | 2018-05-10 16:31:00 -0700 | [diff] [blame] | 41 | import android.animation.AnimatorListenerAdapter; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 42 | import android.animation.AnimatorSet; |
Sunny Goyal | 6001ea2 | 2018-05-10 16:31:00 -0700 | [diff] [blame] | 43 | import android.animation.ObjectAnimator; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 44 | import android.animation.ValueAnimator; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 45 | import android.annotation.TargetApi; |
Tony Wickham | 005df0b | 2018-02-13 11:28:12 -0800 | [diff] [blame] | 46 | import android.app.ActivityOptions; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 47 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 48 | import android.appwidget.AppWidgetManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 49 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 50 | import android.content.BroadcastReceiver; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 51 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | import android.content.Context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 53 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 54 | import android.content.IntentFilter; |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 55 | import android.content.IntentSender; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 56 | import android.content.SharedPreferences; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | import android.content.pm.PackageManager; |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 58 | import android.content.res.Configuration; |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 59 | import android.database.sqlite.SQLiteDatabase; |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 60 | import android.graphics.Point; |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 61 | import android.graphics.Rect; |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 62 | import android.os.Build; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 63 | import android.os.Bundle; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 64 | import android.os.CancellationSignal; |
Hyunyoung Song | bd6fba9 | 2018-05-16 15:54:31 -0700 | [diff] [blame] | 65 | import android.os.Handler; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 66 | import android.os.Parcelable; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 67 | import android.os.Process; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 68 | import android.os.StrictMode; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 69 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 71 | import android.util.Log; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 72 | import android.util.SparseArray; |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 73 | import android.view.Display; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 74 | import android.view.KeyEvent; |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 75 | import android.view.KeyboardShortcutGroup; |
| 76 | import android.view.KeyboardShortcutInfo; |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 77 | import android.view.LayoutInflater; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 78 | import android.view.Menu; |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 79 | import android.view.MotionEvent; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 80 | import android.view.View; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 81 | import android.view.ViewGroup; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 82 | import android.view.accessibility.AccessibilityEvent; |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 83 | import android.view.animation.OvershootInterpolator; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 84 | import android.widget.Toast; |
Sunny Goyal | a1d1bf3 | 2015-06-26 13:24:53 -0700 | [diff] [blame] | 85 | |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 86 | import androidx.annotation.Nullable; |
Pinyao Ting | c907427 | 2019-11-11 11:51:44 -0800 | [diff] [blame] | 87 | import androidx.annotation.StringRes; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 88 | import androidx.annotation.VisibleForTesting; |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 89 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 90 | import com.android.launcher3.DropTarget.DragObject; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 91 | import com.android.launcher3.LauncherState.ScaleAndTranslation; |
| 92 | import com.android.launcher3.LauncherStateManager.StateHandler; |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 93 | import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 94 | import com.android.launcher3.allapps.AllAppsContainerView; |
vadimt | d4c90e1 | 2019-06-04 13:59:43 -0700 | [diff] [blame] | 95 | import com.android.launcher3.allapps.AllAppsStore; |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 96 | import com.android.launcher3.allapps.AllAppsTransitionController; |
Sunny Goyal | 7ede611 | 2017-12-05 15:11:21 -0800 | [diff] [blame] | 97 | import com.android.launcher3.allapps.DiscoveryBounce; |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 98 | import com.android.launcher3.anim.PropertyListBuilder; |
Tony Wickham | e0c3323 | 2016-02-08 11:37:04 -0800 | [diff] [blame] | 99 | import com.android.launcher3.config.FeatureFlags; |
vadimt | 00d4255 | 2018-12-11 17:59:36 -0800 | [diff] [blame] | 100 | import com.android.launcher3.dot.DotInfo; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 101 | import com.android.launcher3.dragndrop.DragController; |
| 102 | import com.android.launcher3.dragndrop.DragLayer; |
| 103 | import com.android.launcher3.dragndrop.DragView; |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 104 | import com.android.launcher3.folder.FolderGridOrganizer; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 105 | import com.android.launcher3.folder.FolderIcon; |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 106 | import com.android.launcher3.graphics.RotationMode; |
Sunny Goyal | f840f10 | 2018-09-21 14:41:05 -0700 | [diff] [blame] | 107 | import com.android.launcher3.icons.IconCache; |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 108 | import com.android.launcher3.keyboard.CustomActionsPopup; |
Sunny Goyal | 3333b0c | 2016-05-09 20:43:21 -0700 | [diff] [blame] | 109 | import com.android.launcher3.keyboard.ViewGroupFocusHelper; |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 110 | import com.android.launcher3.logging.FileLog; |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 111 | import com.android.launcher3.logging.StatsLogUtils; |
Hyunyoung Song | aa95365 | 2016-04-19 18:30:24 -0700 | [diff] [blame] | 112 | import com.android.launcher3.logging.UserEventDispatcher; |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 113 | import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate; |
Sunny Goyal | 369212a | 2019-03-26 15:03:57 -0700 | [diff] [blame] | 114 | import com.android.launcher3.model.AppLaunchTracker; |
Sunny Goyal | 87dcde6 | 2019-07-17 20:35:56 -0700 | [diff] [blame] | 115 | import com.android.launcher3.model.BgDataModel.Callbacks; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 116 | import com.android.launcher3.model.ModelWriter; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 117 | import com.android.launcher3.notification.NotificationListener; |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 118 | import com.android.launcher3.pm.PinRequestHelper; |
Tony Wickham | 540913e | 2017-01-23 11:47:51 -0800 | [diff] [blame] | 119 | import com.android.launcher3.popup.PopupContainerWithArrow; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 120 | import com.android.launcher3.popup.PopupDataProvider; |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 121 | import com.android.launcher3.popup.SystemShortcut; |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 122 | import com.android.launcher3.qsb.QsbContainerView; |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 123 | import com.android.launcher3.states.RotationHelper; |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 124 | import com.android.launcher3.testing.TestLogging; |
vadimt | bc5d7e6 | 2019-12-09 13:53:05 -0800 | [diff] [blame] | 125 | import com.android.launcher3.testing.TestProtocol; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 126 | import com.android.launcher3.touch.AllAppsSwipeController; |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 127 | import com.android.launcher3.touch.ItemClickHandler; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 128 | import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 129 | import com.android.launcher3.userevent.nano.LauncherLogProto; |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 130 | import com.android.launcher3.userevent.nano.LauncherLogProto.Action; |
| 131 | import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 132 | import com.android.launcher3.userevent.nano.LauncherLogProto.Target; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 133 | import com.android.launcher3.util.ActivityResultInfo; |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 134 | import com.android.launcher3.util.ActivityTracker; |
Winson Chung | 6b1c73f | 2015-06-18 11:38:42 -0700 | [diff] [blame] | 135 | import com.android.launcher3.util.ComponentKey; |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 136 | import com.android.launcher3.util.IntArray; |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 137 | import com.android.launcher3.util.ItemInfoMatcher; |
Sunny Goyal | 6001ea2 | 2018-05-10 16:31:00 -0700 | [diff] [blame] | 138 | import com.android.launcher3.util.MultiValueAlpha; |
| 139 | import com.android.launcher3.util.MultiValueAlpha.AlphaProperty; |
Sunny Goyal | 04cc3a7 | 2016-05-17 10:32:43 -0700 | [diff] [blame] | 140 | import com.android.launcher3.util.PackageManagerHelper; |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 141 | import com.android.launcher3.util.PackageUserKey; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 142 | import com.android.launcher3.util.PendingRequestArgs; |
Pinyao Ting | 49a3e69 | 2019-07-26 12:28:38 -0700 | [diff] [blame] | 143 | import com.android.launcher3.util.ShortcutUtil; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 144 | import com.android.launcher3.util.SystemUiController; |
Mario Bertschler | a693694 | 2017-05-31 14:48:19 -0700 | [diff] [blame] | 145 | import com.android.launcher3.util.Themes; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 146 | import com.android.launcher3.util.Thunk; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 147 | import com.android.launcher3.util.TouchController; |
Sunny Goyal | fca6bc9 | 2017-09-28 16:28:34 -0700 | [diff] [blame] | 148 | import com.android.launcher3.util.TraceHelper; |
Sunny Goyal | 326403e | 2017-10-02 12:45:10 -0700 | [diff] [blame] | 149 | import com.android.launcher3.util.UiThreadHelper; |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 150 | import com.android.launcher3.util.ViewOnDrawExecutor; |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 151 | import com.android.launcher3.views.ActivityContext; |
Sunny Goyal | 7c7be8c | 2018-03-07 19:58:07 -0800 | [diff] [blame] | 152 | import com.android.launcher3.views.OptionsPopupView; |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 153 | import com.android.launcher3.views.ScrimView; |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 154 | import com.android.launcher3.widget.LauncherAppWidgetHostView; |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 155 | import com.android.launcher3.widget.PendingAddShortcutInfo; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 156 | import com.android.launcher3.widget.PendingAddWidgetInfo; |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 157 | import com.android.launcher3.widget.PendingAppWidgetHostView; |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 158 | import com.android.launcher3.widget.WidgetAddFlowHandler; |
Hyunyoung Song | b99ff3e | 2015-04-23 15:17:50 -0700 | [diff] [blame] | 159 | import com.android.launcher3.widget.WidgetHostViewLoader; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 160 | import com.android.launcher3.widget.WidgetListRowEntry; |
Sunny Goyal | 337c81f | 2019-12-10 12:19:13 -0800 | [diff] [blame] | 161 | import com.android.launcher3.widget.WidgetManagerHelper; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 162 | import com.android.launcher3.widget.WidgetsFullSheet; |
Pinyao Ting | c7a6c29 | 2019-08-26 14:36:02 -0700 | [diff] [blame] | 163 | import com.android.launcher3.widget.custom.CustomWidgetManager; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 164 | import com.android.systemui.plugins.OverlayPlugin; |
| 165 | import com.android.systemui.plugins.PluginListener; |
| 166 | import com.android.systemui.plugins.shared.LauncherExterns; |
| 167 | import com.android.systemui.plugins.shared.LauncherOverlayManager; |
| 168 | import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay; |
| 169 | import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 170 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 171 | import java.io.FileDescriptor; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 172 | import java.io.PrintWriter; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 173 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 174 | import java.util.Collection; |
Zak Cohen | 658c67a | 2018-10-19 14:21:05 -0700 | [diff] [blame] | 175 | import java.util.HashMap; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 176 | import java.util.HashSet; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 177 | import java.util.List; |
Sunny Goyal | aae6fbb | 2019-01-31 16:05:58 -0800 | [diff] [blame] | 178 | import java.util.function.Predicate; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 179 | import java.util.function.Supplier; |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 180 | import java.util.stream.Stream; |
Jon Miranda | f5197fc | 2019-09-04 16:55:41 -0700 | [diff] [blame] | 181 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 182 | /** |
| 183 | * Default launcher application. |
| 184 | */ |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 185 | public class Launcher extends BaseDraggingActivity implements LauncherExterns, |
Sunny Goyal | 01615a6 | 2019-09-20 12:00:07 -0700 | [diff] [blame] | 186 | Callbacks, UserEventDelegate, |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 187 | InvariantDeviceProfile.OnIDPChangeListener, PluginListener<OverlayPlugin> { |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 188 | public static final String TAG = "Launcher"; |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 189 | |
| 190 | public static final ActivityTracker<Launcher> ACTIVITY_TRACKER = new ActivityTracker<>(); |
| 191 | |
Sunny Goyal | 2bba4c3 | 2015-05-18 15:42:48 -0700 | [diff] [blame] | 192 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 193 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 194 | static final boolean DEBUG_STRICT_MODE = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 195 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 196 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 197 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 198 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 199 | private static final int REQUEST_PICK_APPWIDGET = 9; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 200 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 201 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 202 | public static final int REQUEST_BIND_PENDING_APPWIDGET = 12; |
| 203 | public static final int REQUEST_RECONFIGURE_APPWIDGET = 13; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 204 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 205 | private static final int REQUEST_PERMISSION_CALL_PHONE = 14; |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 206 | |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 207 | private static final float BOUNCE_ANIMATION_TENSION = 1.3f; |
| 208 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 209 | /** |
| 210 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 211 | * request codes used internally. |
| 212 | */ |
| 213 | protected static final int REQUEST_LAST = 100; |
| 214 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 215 | // Type: int |
| 216 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 217 | // Type: int |
| 218 | private static final String RUNTIME_STATE = "launcher.state"; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 219 | // Type: PendingRequestArgs |
| 220 | private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args"; |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 221 | // Type: int |
| 222 | private static final String RUNTIME_STATE_PENDING_REQUEST_CODE = "launcher.request_code"; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 223 | // Type: ActivityResultInfo |
| 224 | private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result"; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 225 | // Type: SparseArray<Parcelable> |
| 226 | private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel"; |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 227 | |
vadimt | 00d4255 | 2018-12-11 17:59:36 -0800 | [diff] [blame] | 228 | public static final String ON_CREATE_EVT = "Launcher.onCreate"; |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 229 | public static final String ON_START_EVT = "Launcher.onStart"; |
| 230 | public static final String ON_RESUME_EVT = "Launcher.onResume"; |
| 231 | public static final String ON_NEW_INTENT_EVT = "Launcher.onNewIntent"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 232 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 233 | private LauncherStateManager mStateManager; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 234 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 235 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 236 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 237 | // How long to wait before the new-shortcut animation automatically pans the workspace |
Jon Miranda | f5197fc | 2019-09-04 16:55:41 -0700 | [diff] [blame] | 238 | @VisibleForTesting public static final int NEW_APPS_PAGE_MOVE_DELAY = 500; |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 239 | private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Jon Miranda | f5197fc | 2019-09-04 16:55:41 -0700 | [diff] [blame] | 240 | @Thunk @VisibleForTesting public static final int NEW_APPS_ANIMATION_DELAY = 500; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 241 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 242 | private static final int APPS_VIEW_ALPHA_CHANNEL_INDEX = 1; |
| 243 | private static final int SCRIM_VIEW_ALPHA_CHANNEL_INDEX = 0; |
| 244 | |
Jon Miranda | 54441f5 | 2018-01-24 15:38:25 -0800 | [diff] [blame] | 245 | private LauncherAppTransitionManager mAppTransitionManager; |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 246 | private Configuration mOldConfig; |
Jon Miranda | 54441f5 | 2018-01-24 15:38:25 -0800 | [diff] [blame] | 247 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 248 | @Thunk |
| 249 | Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 250 | private View mLauncherView; |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 251 | @Thunk |
| 252 | DragLayer mDragLayer; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 253 | private DragController mDragController; |
Sunny Goyal | 322d556 | 2015-06-25 19:35:49 -0700 | [diff] [blame] | 254 | |
Sunny Goyal | 337c81f | 2019-12-10 12:19:13 -0800 | [diff] [blame] | 255 | private WidgetManagerHelper mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 256 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 257 | |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 258 | private final int[] mTmpAddItemCellCoordinates = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 259 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 260 | @Thunk |
| 261 | Hotseat mHotseat; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 262 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 263 | private DropTargetBar mDropTargetBar; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 264 | |
| 265 | // Main container view for the all apps screen. |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 266 | @Thunk |
| 267 | AllAppsContainerView mAppsView; |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 268 | AllAppsTransitionController mAllAppsController; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 269 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 270 | // Scrim view for the all apps and overview state. |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 271 | @Thunk |
| 272 | ScrimView mScrimView; |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 273 | |
Winson Chung | 8ae4198 | 2017-11-10 11:42:13 -0800 | [diff] [blame] | 274 | // UI and state for the overview panel |
Sunny Goyal | 7c7be8c | 2018-03-07 19:58:07 -0800 | [diff] [blame] | 275 | private View mOverviewPanel; |
Winson Chung | 8ae4198 | 2017-11-10 11:42:13 -0800 | [diff] [blame] | 276 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 277 | @Thunk |
| 278 | boolean mWorkspaceLoading = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 279 | |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 280 | private ArrayList<OnResumeCallback> mOnResumeCallbacks = new ArrayList<>(); |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 281 | |
Winson Chung | c9bf6d4 | 2019-10-04 15:33:18 -0700 | [diff] [blame] | 282 | // Used to notify when an activity launch has been deferred because launcher is not yet resumed |
| 283 | // TODO: See if we can remove this later |
| 284 | private Runnable mOnDeferredActivityLaunchCallback; |
| 285 | |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 286 | private ViewOnDrawExecutor mPendingExecutor; |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 287 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 288 | private LauncherModel mModel; |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 289 | private ModelWriter mModelWriter; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 290 | private IconCache mIconCache; |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 291 | private LauncherAccessibilityDelegate mAccessibilityDelegate; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 292 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 293 | private PopupDataProvider mPopupDataProvider; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 294 | |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 295 | private int mSynchronouslyBoundPage = PagedView.INVALID_PAGE; |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 296 | private int mPageToBindSynchronously = PagedView.INVALID_PAGE; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 297 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 298 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 299 | // it from the context. |
| 300 | private SharedPreferences mSharedPrefs; |
| 301 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 302 | // Activity result which needs to be processed after workspace has loaded. |
| 303 | private ActivityResultInfo mPendingActivityResult; |
| 304 | /** |
| 305 | * Holds extra information required to handle a result from an external call, like |
| 306 | * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)} |
| 307 | */ |
| 308 | private PendingRequestArgs mPendingRequestArgs; |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 309 | // Request id for any pending activity result |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 310 | protected int mPendingActivityRequestCode = -1; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 311 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 312 | private ViewGroupFocusHelper mFocusHandler; |
Hyunyoung Song | 7fb3ccc | 2017-10-17 15:39:46 -0700 | [diff] [blame] | 313 | |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 314 | private RotationHelper mRotationHelper; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 315 | |
Sunny Goyal | 2db5342 | 2019-03-01 16:06:12 -0800 | [diff] [blame] | 316 | final Handler mHandler = new Handler(); |
Sunny Goyal | a002c6c | 2019-02-12 16:20:10 -0800 | [diff] [blame] | 317 | private final Runnable mHandleDeferredResume = this::handleDeferredResume; |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 318 | private boolean mDeferredResumePending; |
Hyunyoung Song | bd6fba9 | 2018-05-16 15:54:31 -0700 | [diff] [blame] | 319 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 320 | private float mCurrentAssistantVisibility = 0f; |
| 321 | |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 322 | private DeviceProfile mStableDeviceProfile; |
| 323 | private RotationMode mRotationMode = RotationMode.NORMAL; |
| 324 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 325 | protected LauncherOverlayManager mOverlayManager; |
| 326 | // If true, overlay callbacks are deferred |
| 327 | private boolean mDeferOverlayCallbacks; |
| 328 | private final Runnable mDeferredOverlayCallbacks = this::checkIfOverlayStillDeferred; |
| 329 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 330 | @Override |
| 331 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 332 | Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT, |
| 333 | TraceHelper.FLAG_UI_EVENT); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 334 | if (DEBUG_STRICT_MODE) { |
| 335 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 336 | .detectDiskReads() |
| 337 | .detectDiskWrites() |
| 338 | .detectNetwork() // or .detectAll() for all detectable problems |
| 339 | .penaltyLog() |
| 340 | .build()); |
| 341 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 342 | .detectLeakedSqlLiteObjects() |
| 343 | .detectLeakedClosableObjects() |
| 344 | .penaltyLog() |
| 345 | .penaltyDeath() |
| 346 | .build()); |
| 347 | } |
| 348 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 349 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 350 | |
Sunny Goyal | 87f784c | 2017-01-11 10:48:34 -0800 | [diff] [blame] | 351 | LauncherAppState app = LauncherAppState.getInstance(this); |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 352 | mOldConfig = new Configuration(getResources().getConfiguration()); |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 353 | mModel = app.getModel(); |
Sunny Goyal | 41d51a0 | 2019-05-14 09:44:34 -0700 | [diff] [blame] | 354 | mRotationHelper = new RotationHelper(this); |
Hyunyoung Song | 31971a3 | 2019-01-27 12:31:12 -0800 | [diff] [blame] | 355 | InvariantDeviceProfile idp = app.getInvariantDeviceProfile(); |
| 356 | initDeviceProfile(idp); |
| 357 | idp.addOnChangeListener(this); |
Sunny Goyal | f725824 | 2015-10-19 16:59:07 -0700 | [diff] [blame] | 358 | mSharedPrefs = Utilities.getPrefs(this); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 359 | mIconCache = app.getIconCache(); |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 360 | mAccessibilityDelegate = new LauncherAccessibilityDelegate(this); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 361 | |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 362 | mDragController = new DragController(this); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 363 | mAllAppsController = new AllAppsTransitionController(this); |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 364 | mStateManager = new LauncherStateManager(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 365 | |
Sunny Goyal | 337c81f | 2019-12-10 12:19:13 -0800 | [diff] [blame] | 366 | mAppWidgetManager = new WidgetManagerHelper(this); |
Samuel Fufa | 44043ec | 2019-08-26 15:00:30 -0700 | [diff] [blame] | 367 | mAppWidgetHost = new LauncherAppWidgetHost(this, |
| 368 | appWidgetId -> getWorkspace().removeWidget(appWidgetId)); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 369 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 370 | |
Sunny Goyal | 60820d7 | 2017-05-09 12:40:11 -0700 | [diff] [blame] | 371 | mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 372 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 373 | setupViews(); |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 374 | mPopupDataProvider = new PopupDataProvider(this); |
| 375 | |
Sunny Goyal | 9054843 | 2018-04-04 17:17:00 -0700 | [diff] [blame] | 376 | mAppTransitionManager = LauncherAppTransitionManager.newInstance(this); |
Winson Chung | 24ab40c | 2019-10-30 22:35:09 -0700 | [diff] [blame] | 377 | mAppTransitionManager.registerRemoteAnimations(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 378 | |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 379 | boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this); |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 380 | if (internalStateHandled) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 381 | if (savedInstanceState != null) { |
| 382 | // InternalStateHandler has already set the appropriate state. |
| 383 | // We dont need to do anything. |
| 384 | savedInstanceState.remove(RUNTIME_STATE); |
| 385 | } |
| 386 | } |
| 387 | restoreState(savedInstanceState); |
Sunny Goyal | bbece86 | 2019-03-01 13:13:52 -0800 | [diff] [blame] | 388 | mStateManager.reapplyState(); |
Winson Chung | b63b44c | 2017-11-10 17:54:44 -0800 | [diff] [blame] | 389 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 390 | // We only load the page synchronously if the user rotates (or triggers a |
| 391 | // configuration change) while launcher is in the foreground |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 392 | int currentScreen = PagedView.INVALID_PAGE; |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 393 | if (savedInstanceState != null) { |
| 394 | currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen); |
| 395 | } |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 396 | mPageToBindSynchronously = currentScreen; |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 397 | |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 398 | if (!mModel.addCallbacksAndLoad(this)) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 399 | if (!internalStateHandled) { |
| 400 | // If we are not binding synchronously, show a fade in animation when |
| 401 | // the first page bind completes. |
Sunny Goyal | 6001ea2 | 2018-05-10 16:31:00 -0700 | [diff] [blame] | 402 | mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0); |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 403 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | // For handling default keys |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 407 | setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 408 | |
Sunny Goyal | 0bbd554 | 2016-11-11 10:41:26 -0800 | [diff] [blame] | 409 | setContentView(mLauncherView); |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 410 | getRootView().dispatchInsets(); |
Mario Bertschler | a693694 | 2017-05-31 14:48:19 -0700 | [diff] [blame] | 411 | |
Jon Miranda | 7fda285 | 2017-07-19 16:07:01 -0700 | [diff] [blame] | 412 | // Listen for broadcasts |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 413 | registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); |
Sunny Goyal | a616d2b | 2017-06-12 13:54:01 -0700 | [diff] [blame] | 414 | |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 415 | getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW, |
| 416 | Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText)); |
Sunny Goyal | 14b3240 | 2017-07-31 10:03:28 -0700 | [diff] [blame] | 417 | |
| 418 | if (mLauncherCallbacks != null) { |
| 419 | mLauncherCallbacks.onCreate(savedInstanceState); |
| 420 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 421 | mOverlayManager = getDefaultOverlay(); |
| 422 | PluginManagerWrapper.INSTANCE.get(this).addPluginListener(this, |
| 423 | OverlayPlugin.class, false /* allowedMultiple */); |
| 424 | |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 425 | mRotationHelper.initialize(); |
Sunny Goyal | fca6bc9 | 2017-09-28 16:28:34 -0700 | [diff] [blame] | 426 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 427 | mStateManager.addStateListener(new LauncherStateManager.StateListener() { |
| 428 | @Override |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 429 | public void onStateTransitionStart(LauncherState toState) { |
| 430 | } |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 431 | |
| 432 | @Override |
| 433 | public void onStateTransitionComplete(LauncherState finalState) { |
| 434 | float alpha = 1f - mCurrentAssistantVisibility; |
| 435 | if (finalState == NORMAL) { |
| 436 | mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha); |
| 437 | } else if (finalState == OVERVIEW || finalState == OVERVIEW_PEEK) { |
| 438 | mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha); |
| 439 | mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha); |
| 440 | } else { |
| 441 | mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f); |
| 442 | mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f); |
| 443 | } |
| 444 | } |
| 445 | }); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 446 | |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 447 | TraceHelper.INSTANCE.endSection(traceToken); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 450 | protected LauncherOverlayManager getDefaultOverlay() { |
| 451 | return new LauncherOverlayManager() { }; |
| 452 | } |
| 453 | |
| 454 | @Override |
| 455 | public void onPluginConnected(OverlayPlugin overlayManager, Context context) { |
| 456 | switchOverlay(() -> overlayManager.createOverlayManager(this, this)); |
| 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public void onPluginDisconnected(OverlayPlugin plugin) { |
| 461 | switchOverlay(this::getDefaultOverlay); |
| 462 | } |
| 463 | |
| 464 | private void switchOverlay(Supplier<LauncherOverlayManager> overlaySupplier) { |
| 465 | if (mOverlayManager != null) { |
| 466 | mOverlayManager.onActivityDestroyed(this); |
| 467 | } |
| 468 | mOverlayManager = overlaySupplier.get(); |
| 469 | if (getRootView().isAttachedToWindow()) { |
| 470 | mOverlayManager.onAttachedToWindow(); |
| 471 | } |
| 472 | mDeferOverlayCallbacks = true; |
| 473 | checkIfOverlayStillDeferred(); |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | protected void dispatchDeviceProfileChanged() { |
| 478 | super.dispatchDeviceProfileChanged(); |
| 479 | mOverlayManager.onDeviceProvideChanged(); |
| 480 | } |
| 481 | |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 482 | @Override |
Winson Chung | 8eb49e0 | 2018-07-16 13:33:31 -0700 | [diff] [blame] | 483 | public void onEnterAnimationComplete() { |
| 484 | super.onEnterAnimationComplete(); |
arangelov | ad78305 | 2018-08-17 14:46:45 +0100 | [diff] [blame] | 485 | mAllAppsController.highlightWorkTabIfNecessary(); |
Sunny Goyal | be8c340 | 2019-05-22 15:17:52 -0700 | [diff] [blame] | 486 | mRotationHelper.setCurrentTransitionRequest(REQUEST_NONE); |
Winson Chung | 8eb49e0 | 2018-07-16 13:33:31 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | @Override |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 490 | public void onConfigurationChanged(Configuration newConfig) { |
| 491 | int diff = newConfig.diff(mOldConfig); |
Jon Miranda | aeb4dd0 | 2018-07-11 14:16:23 -0700 | [diff] [blame] | 492 | |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 493 | if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) { |
Sunny Goyal | 371ea05 | 2019-03-06 15:38:32 -0800 | [diff] [blame] | 494 | onIdpChanged(mDeviceProfile.inv); |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | mOldConfig.setTo(newConfig); |
| 498 | super.onConfigurationChanged(newConfig); |
| 499 | } |
| 500 | |
Sunny Goyal | 3e195d7 | 2019-06-19 14:24:38 -0700 | [diff] [blame] | 501 | public void reload() { |
| 502 | onIdpChanged(mDeviceProfile.inv); |
| 503 | } |
| 504 | |
Sunny Goyal | 41d51a0 | 2019-05-14 09:44:34 -0700 | [diff] [blame] | 505 | private boolean supportsFakeLandscapeUI() { |
| 506 | return FeatureFlags.FAKE_LANDSCAPE_UI.get() && !mRotationHelper.homeScreenCanRotate(); |
| 507 | } |
| 508 | |
Sunny Goyal | 605bcf3 | 2018-03-02 15:16:12 -0800 | [diff] [blame] | 509 | @Override |
Sunny Goyal | 41d51a0 | 2019-05-14 09:44:34 -0700 | [diff] [blame] | 510 | public void reapplyUi() { |
Tony Wickham | 4df42f8 | 2019-11-13 15:38:28 -0800 | [diff] [blame] | 511 | reapplyUi(true /* cancelCurrentAnimation */); |
| 512 | } |
| 513 | |
| 514 | public void reapplyUi(boolean cancelCurrentAnimation) { |
Sunny Goyal | 41d51a0 | 2019-05-14 09:44:34 -0700 | [diff] [blame] | 515 | if (supportsFakeLandscapeUI()) { |
Sunny Goyal | 7a39b1b | 2019-05-02 13:39:16 -0700 | [diff] [blame] | 516 | mRotationMode = mStableDeviceProfile == null |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 517 | ? RotationMode.NORMAL : getFakeRotationMode(mDeviceProfile); |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 518 | } |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 519 | getRootView().dispatchInsets(); |
Tony Wickham | 4df42f8 | 2019-11-13 15:38:28 -0800 | [diff] [blame] | 520 | getStateManager().reapplyState(cancelCurrentAnimation); |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | @Override |
Hyunyoung Song | 31971a3 | 2019-01-27 12:31:12 -0800 | [diff] [blame] | 524 | public void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) { |
Sunny Goyal | 371ea05 | 2019-03-06 15:38:32 -0800 | [diff] [blame] | 525 | onIdpChanged(idp); |
| 526 | } |
| 527 | |
| 528 | private void onIdpChanged(InvariantDeviceProfile idp) { |
| 529 | mUserEventDispatcher = null; |
| 530 | |
Sunny Goyal | c8502c1 | 2019-06-10 12:14:47 -0700 | [diff] [blame] | 531 | DeviceProfile oldWallpaperProfile = getWallpaperDeviceProfile(); |
Hyunyoung Song | 31971a3 | 2019-01-27 12:31:12 -0800 | [diff] [blame] | 532 | initDeviceProfile(idp); |
Sunny Goyal | 371ea05 | 2019-03-06 15:38:32 -0800 | [diff] [blame] | 533 | dispatchDeviceProfileChanged(); |
| 534 | reapplyUi(); |
| 535 | mDragLayer.recreateControllers(); |
| 536 | |
Sunny Goyal | 76ba0a3 | 2019-06-10 11:56:11 -0700 | [diff] [blame] | 537 | // Calling onSaveInstanceState ensures that static cache used by listWidgets is |
| 538 | // initialized properly. |
| 539 | onSaveInstanceState(new Bundle()); |
Sunny Goyal | c8502c1 | 2019-06-10 12:14:47 -0700 | [diff] [blame] | 540 | if (oldWallpaperProfile != getWallpaperDeviceProfile()) { |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 541 | mModel.rebindCallbacks(); |
Sunny Goyal | c8502c1 | 2019-06-10 12:14:47 -0700 | [diff] [blame] | 542 | } |
Hyunyoung Song | 31971a3 | 2019-01-27 12:31:12 -0800 | [diff] [blame] | 543 | } |
| 544 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 545 | public void onAssistantVisibilityChanged(float visibility) { |
| 546 | mCurrentAssistantVisibility = visibility; |
| 547 | float alpha = 1f - visibility; |
| 548 | LauncherState state = mStateManager.getState(); |
| 549 | if (state == NORMAL) { |
| 550 | mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha); |
| 551 | } else if (state == OVERVIEW || state == OVERVIEW_PEEK) { |
| 552 | mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha); |
| 553 | mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha); |
| 554 | } |
| 555 | } |
| 556 | |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 557 | private void initDeviceProfile(InvariantDeviceProfile idp) { |
| 558 | // Load configuration-specific DeviceProfile |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 559 | mDeviceProfile = idp.getDeviceProfile(this); |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame] | 560 | if (isInMultiWindowMode()) { |
Winson Chung | 13c1c2c | 2019-09-06 11:46:19 -0700 | [diff] [blame] | 561 | // Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return |
| 562 | // the app window size |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 563 | Display display = getWindowManager().getDefaultDisplay(); |
| 564 | Point mwSize = new Point(); |
| 565 | display.getSize(mwSize); |
| 566 | mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize); |
| 567 | } |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 568 | |
Sunny Goyal | da14cf8 | 2019-05-30 10:31:09 -0700 | [diff] [blame] | 569 | if (supportsFakeLandscapeUI() && mDeviceProfile.isVerticalBarLayout()) { |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 570 | mStableDeviceProfile = mDeviceProfile.inv.portraitProfile; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 571 | mRotationMode = getFakeRotationMode(mDeviceProfile); |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 572 | } else { |
| 573 | mStableDeviceProfile = null; |
| 574 | mRotationMode = RotationMode.NORMAL; |
| 575 | } |
| 576 | |
Sunny Goyal | da14cf8 | 2019-05-30 10:31:09 -0700 | [diff] [blame] | 577 | mRotationHelper.updateRotationAnimation(); |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 578 | onDeviceProfileInitiated(); |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 579 | mModelWriter = mModel.getWriter(getWallpaperDeviceProfile().isVerticalBarLayout(), true); |
| 580 | } |
| 581 | |
| 582 | public void updateInsets(Rect insets) { |
| 583 | mDeviceProfile.updateInsets(insets); |
| 584 | if (mStableDeviceProfile != null) { |
Sunny Goyal | 7a39b1b | 2019-05-02 13:39:16 -0700 | [diff] [blame] | 585 | Rect r = mStableDeviceProfile.getInsets(); |
| 586 | mRotationMode.mapInsets(this, insets, r); |
| 587 | mStableDeviceProfile.updateInsets(r); |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
| 591 | @Override |
| 592 | public RotationMode getRotationMode() { |
| 593 | return mRotationMode; |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * Device profile to be used by UI elements which are shown directly on top of the wallpaper |
| 598 | * and whose presentation is tied to the wallpaper (and physical device) and not the activity |
| 599 | * configuration. |
| 600 | */ |
| 601 | @Override |
| 602 | public DeviceProfile getWallpaperDeviceProfile() { |
| 603 | return mStableDeviceProfile == null ? mDeviceProfile : mStableDeviceProfile; |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 604 | } |
| 605 | |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 606 | public RotationHelper getRotationHelper() { |
| 607 | return mRotationHelper; |
| 608 | } |
| 609 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 610 | public ViewGroupFocusHelper getFocusHandler() { |
| 611 | return mFocusHandler; |
| 612 | } |
| 613 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 614 | public LauncherStateManager getStateManager() { |
| 615 | return mStateManager; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 618 | @Override |
Sunny Goyal | c7b8df8 | 2017-06-27 11:11:03 -0700 | [diff] [blame] | 619 | public <T extends View> T findViewById(int id) { |
Sunny Goyal | 0bbd554 | 2016-11-11 10:41:26 -0800 | [diff] [blame] | 620 | return mLauncherView.findViewById(id); |
| 621 | } |
| 622 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 623 | private LauncherCallbacks mLauncherCallbacks; |
| 624 | |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 625 | /** |
| 626 | * Call this after onCreate to set or clear overlay. |
| 627 | */ |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 628 | @Override |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 629 | public void setLauncherOverlay(LauncherOverlay overlay) { |
| 630 | if (overlay != null) { |
| 631 | overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl()); |
| 632 | } |
| 633 | mWorkspace.setLauncherOverlay(overlay); |
| 634 | } |
| 635 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 636 | @Override |
| 637 | public void runOnOverlayHidden(Runnable runnable) { |
| 638 | getWorkspace().runOnOverlayHidden(runnable); |
| 639 | } |
| 640 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 641 | public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { |
| 642 | mLauncherCallbacks = callbacks; |
| 643 | return true; |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 646 | public boolean isDraggingEnabled() { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 647 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 648 | // that is subsequently removed from the workspace in startBinding(). |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 649 | return !isWorkspaceLoading(); |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 652 | public PopupDataProvider getPopupDataProvider() { |
| 653 | return mPopupDataProvider; |
| 654 | } |
| 655 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 656 | @Override |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 657 | public DotInfo getDotInfoForItem(ItemInfo info) { |
| 658 | return mPopupDataProvider.getDotInfoForItem(info); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | @Override |
| 662 | public void invalidateParent(ItemInfo info) { |
Jon Miranda | e6f3fa4 | 2019-03-04 09:14:40 -0800 | [diff] [blame] | 663 | if (info.container >= 0) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 664 | View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container); |
Jon Miranda | e6f3fa4 | 2019-03-04 09:14:40 -0800 | [diff] [blame] | 665 | if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) { |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 666 | if (new FolderGridOrganizer(getDeviceProfile().inv) |
| 667 | .setFolderInfo((FolderInfo) folderIcon.getTag()) |
| 668 | .isItemInPreview(info.rank)) { |
Jon Miranda | e6f3fa4 | 2019-03-04 09:14:40 -0800 | [diff] [blame] | 669 | folderIcon.invalidate(); |
| 670 | } |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 675 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 676 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 677 | * a configuration step, this allows the proper animations to run after other transitions. |
| 678 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 679 | private int completeAdd( |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 680 | int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) { |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 681 | int screenId = info.screenId; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 682 | if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 683 | // When the screen id represents an actual screen (as opposed to a rank) we make sure |
| 684 | // that the drop page actually exists. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 685 | screenId = ensurePendingDropLayoutExists(info.screenId); |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 686 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 687 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 688 | switch (requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 689 | case REQUEST_CREATE_SHORTCUT: |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 690 | completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info); |
Pinyao Ting | c907427 | 2019-11-11 11:51:44 -0800 | [diff] [blame] | 691 | announceForAccessibility(R.string.item_added_to_workspace); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 692 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 693 | case REQUEST_CREATE_APPWIDGET: |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 694 | completeAddAppWidget(appWidgetId, info, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 695 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 696 | case REQUEST_RECONFIGURE_APPWIDGET: |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 697 | completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 698 | break; |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 699 | case REQUEST_BIND_PENDING_APPWIDGET: { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 700 | int widgetId = appWidgetId; |
| 701 | LauncherAppWidgetInfo widgetInfo = |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 702 | completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 703 | if (widgetInfo != null) { |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 704 | // Since the view was just bound, also launch the configure activity if needed |
| 705 | LauncherAppWidgetProviderInfo provider = mAppWidgetManager |
| 706 | .getLauncherAppWidgetInfo(widgetId); |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 707 | if (provider != null) { |
| 708 | new WidgetAddFlowHandler(provider) |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 709 | .startConfigActivity(this, widgetInfo, |
| 710 | REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | break; |
| 714 | } |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 715 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 716 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 717 | } |
| 718 | |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 719 | private void handleActivityResult( |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 720 | final int requestCode, final int resultCode, final Intent data) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 721 | if (isWorkspaceLoading()) { |
| 722 | // process the result once the workspace has loaded. |
| 723 | mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data); |
| 724 | return; |
| 725 | } |
| 726 | mPendingActivityResult = null; |
| 727 | |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 728 | // Reset the startActivity waiting flag |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 729 | final PendingRequestArgs requestArgs = mPendingRequestArgs; |
| 730 | setWaitingForResult(null); |
| 731 | if (requestArgs == null) { |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | final int pendingAddWidgetId = requestArgs.getWidgetId(); |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 736 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 737 | Runnable exitSpringLoaded = new Runnable() { |
| 738 | @Override |
| 739 | public void run() { |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 740 | mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 741 | } |
| 742 | }; |
| 743 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 744 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Winson | a1f79d3 | 2015-08-05 14:00:45 -0700 | [diff] [blame] | 745 | // This is called only if the user did not previously have permissions to bind widgets |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 746 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 747 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 748 | if (resultCode == RESULT_CANCELED) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 749 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 750 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 751 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 752 | } else if (resultCode == RESULT_OK) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 753 | addAppWidgetImpl( |
| 754 | appWidgetId, requestArgs, null, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 755 | requestArgs.getWidgetHandler(), |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 756 | ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 757 | } |
| 758 | return; |
| 759 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 760 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 761 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
Sunny Goyal | 5c97f51 | 2015-05-19 16:03:28 -0700 | [diff] [blame] | 762 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 763 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 764 | // We have special handling for widgets |
| 765 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 766 | final int appWidgetId; |
| 767 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 768 | : -1; |
| 769 | if (widgetId < 0) { |
| 770 | appWidgetId = pendingAddWidgetId; |
| 771 | } else { |
| 772 | appWidgetId = widgetId; |
| 773 | } |
| 774 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 775 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 776 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 777 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 778 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 779 | result = RESULT_CANCELED; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 780 | completeTwoStageWidgetDrop(result, appWidgetId, requestArgs); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 781 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 782 | @Override |
| 783 | public void run() { |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 784 | getStateManager().goToState(NORMAL); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 785 | } |
| 786 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 787 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 788 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 789 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 790 | } else { |
| 791 | if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 792 | // When the screen id represents an actual screen (as opposed to a rank) |
| 793 | // we make sure that the drop page actually exists. |
| 794 | requestArgs.screenId = |
| 795 | ensurePendingDropLayoutExists(requestArgs.screenId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 796 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 797 | final CellLayout dropLayout = |
| 798 | mWorkspace.getScreenWithId(requestArgs.screenId); |
| 799 | |
| 800 | dropLayout.setDropPending(true); |
| 801 | final Runnable onComplete = new Runnable() { |
| 802 | @Override |
| 803 | public void run() { |
| 804 | completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs); |
| 805 | dropLayout.setDropPending(false); |
| 806 | } |
| 807 | }; |
| 808 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 809 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 810 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 811 | return; |
| 812 | } |
| 813 | |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 814 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET |
| 815 | || requestCode == REQUEST_BIND_PENDING_APPWIDGET) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 816 | if (resultCode == RESULT_OK) { |
| 817 | // Update the widget view. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 818 | completeAdd(requestCode, data, pendingAddWidgetId, requestArgs); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 819 | } |
| 820 | // Leave the widget in the pending state if the user canceled the configure. |
| 821 | return; |
| 822 | } |
| 823 | |
Sunny Goyal | aad9058 | 2015-07-09 14:22:50 -0700 | [diff] [blame] | 824 | if (requestCode == REQUEST_CREATE_SHORTCUT) { |
| 825 | // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 826 | if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) { |
| 827 | completeAdd(requestCode, data, -1, requestArgs); |
| 828 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 829 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 830 | |
Sunny Goyal | aad9058 | 2015-07-09 14:22:50 -0700 | [diff] [blame] | 831 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 832 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 833 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 834 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 835 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 836 | mDragLayer.clearAnimatedView(); |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | @Override |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 840 | public void onActivityResult( |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 841 | final int requestCode, final int resultCode, final Intent data) { |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 842 | mPendingActivityRequestCode = -1; |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 843 | handleActivityResult(requestCode, resultCode, data); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 846 | @Override |
Sunny Goyal | dd2e6df | 2015-07-07 10:57:57 -0700 | [diff] [blame] | 847 | public void onRequestPermissionsResult(int requestCode, String[] permissions, |
Dave Hawkey | 3a43ed6 | 2015-06-26 10:27:47 -0600 | [diff] [blame] | 848 | int[] grantResults) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 849 | PendingRequestArgs pendingArgs = mPendingRequestArgs; |
| 850 | if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null |
| 851 | && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) { |
| 852 | setWaitingForResult(null); |
| 853 | |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 854 | View v = null; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 855 | CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 856 | if (layout != null) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 857 | v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 858 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 859 | Intent intent = pendingArgs.getPendingIntent(); |
| 860 | |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 861 | if (grantResults.length > 0 |
| 862 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
Sunny Goyal | 369212a | 2019-03-26 15:03:57 -0700 | [diff] [blame] | 863 | startActivitySafely(v, intent, null, null); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 864 | } else { |
| 865 | // TODO: Show a snack bar with link to settings |
| 866 | Toast.makeText(this, getString(R.string.msg_no_phone_permission, |
Sunny Goyal | 112ce42 | 2016-08-22 16:45:29 -0700 | [diff] [blame] | 867 | getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show(); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 868 | } |
| 869 | } |
Dave Hawkey | 3a43ed6 | 2015-06-26 10:27:47 -0600 | [diff] [blame] | 870 | } |
| 871 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 872 | /** |
| 873 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 874 | * |
| 875 | * @param screenId the screen id to check |
| 876 | * @return the new screen, or screenId if it exists |
| 877 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 878 | private int ensurePendingDropLayoutExists(int screenId) { |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 879 | CellLayout dropLayout = mWorkspace.getScreenWithId(screenId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 880 | if (dropLayout == null) { |
| 881 | // it's possible that the add screen was removed because it was |
| 882 | // empty and a re-bind occurred |
| 883 | mWorkspace.addExtraEmptyScreen(); |
| 884 | return mWorkspace.commitExtraEmptyScreen(); |
| 885 | } else { |
| 886 | return screenId; |
| 887 | } |
| 888 | } |
| 889 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 890 | @Thunk |
| 891 | void completeTwoStageWidgetDrop( |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 892 | final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) { |
| 893 | CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 894 | Runnable onCompleteRunnable = null; |
| 895 | int animationType = 0; |
| 896 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 897 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 898 | if (resultCode == RESULT_OK) { |
| 899 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 900 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 901 | requestArgs.getWidgetHandler().getProviderInfo(this)); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 902 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 903 | onCompleteRunnable = new Runnable() { |
| 904 | @Override |
| 905 | public void run() { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 906 | completeAddAppWidget(appWidgetId, requestArgs, layout, null); |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 907 | mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 908 | } |
| 909 | }; |
| 910 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 911 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 912 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 913 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 914 | if (mDragLayer.getAnimatedView() != null) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 915 | mWorkspace.animateWidgetDrop(requestArgs, cellLayout, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 916 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 917 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 918 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 919 | // The animated view may be null in the case of a rotation during widget configuration |
| 920 | onCompleteRunnable.run(); |
| 921 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 925 | protected void onStop() { |
| 926 | super.onStop(); |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 927 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 928 | if (mDeferOverlayCallbacks) { |
| 929 | checkIfOverlayStillDeferred(); |
| 930 | } else { |
| 931 | mOverlayManager.onActivityStopped(this); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 932 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 933 | |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 934 | logStopAndResume(Action.Command.STOP); |
Hyunyoung Song | bd6fba9 | 2018-05-16 15:54:31 -0700 | [diff] [blame] | 935 | |
| 936 | mAppWidgetHost.setListenIfResumed(false); |
| 937 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 938 | NotificationListener.removeNotificationsChangedListener(); |
Sunny Goyal | af161fd | 2018-02-05 16:34:57 -0800 | [diff] [blame] | 939 | getStateManager().moveToRestState(); |
Winson Chung | edb0d6b | 2018-03-21 17:32:55 -0700 | [diff] [blame] | 940 | |
Winson Chung | dea5135 | 2018-04-24 13:02:10 -0700 | [diff] [blame] | 941 | // Workaround for b/78520668, explicitly trim memory once UI is hidden |
Winson Chung | 473730f | 2018-04-26 11:54:22 -0700 | [diff] [blame] | 942 | onTrimMemory(TRIM_MEMORY_UI_HIDDEN); |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | @Override |
| 946 | protected void onStart() { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 947 | Object traceToken = TraceHelper.INSTANCE.beginSection(ON_START_EVT, |
| 948 | TraceHelper.FLAG_UI_EVENT); |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 949 | super.onStart(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 950 | if (!mDeferOverlayCallbacks) { |
| 951 | mOverlayManager.onActivityStarted(this); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 952 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 953 | |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 954 | mAppWidgetHost.setListenIfResumed(true); |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 955 | TraceHelper.INSTANCE.endSection(traceToken); |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Sunny Goyal | a002c6c | 2019-02-12 16:20:10 -0800 | [diff] [blame] | 958 | private void handleDeferredResume() { |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 959 | if (hasBeenResumed() && !mStateManager.getState().disableInteraction) { |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 960 | logStopAndResume(Action.Command.RESUME); |
Hyunyoung Song | bd6fba9 | 2018-05-16 15:54:31 -0700 | [diff] [blame] | 961 | getUserEventDispatcher().startSession(); |
Sunny Goyal | a002c6c | 2019-02-12 16:20:10 -0800 | [diff] [blame] | 962 | |
Sunny Goyal | 369212a | 2019-03-26 15:03:57 -0700 | [diff] [blame] | 963 | AppLaunchTracker.INSTANCE.get(this).onReturnedToHome(); |
Hyunyoung Song | bd6fba9 | 2018-05-16 15:54:31 -0700 | [diff] [blame] | 964 | |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 965 | // Process any items that were added while Launcher was away. |
| 966 | InstallShortcutReceiver.disableAndFlushInstallQueue( |
| 967 | InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this); |
| 968 | |
| 969 | // Refresh shortcuts if the permission changed. |
| 970 | mModel.refreshShortcutsIfRequired(); |
| 971 | |
Winson Chung | 8758311 | 2019-06-10 14:20:58 -0700 | [diff] [blame] | 972 | // Set the notification listener and fetch updated notifications when we resume |
| 973 | NotificationListener.setNotificationsChangedListener(mPopupDataProvider); |
| 974 | |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 975 | DiscoveryBounce.showForHomeIfNeeded(this); |
| 976 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 977 | onDeferredResumed(); |
| 978 | addActivityFlags(ACTIVITY_STATE_DEFERRED_RESUMED); |
| 979 | |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 980 | mDeferredResumePending = false; |
| 981 | } else { |
| 982 | mDeferredResumePending = true; |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 986 | protected void onDeferredResumed() { } |
| 987 | |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 988 | private void logStopAndResume(int command) { |
| 989 | int containerType = mStateManager.getState().containerType; |
| 990 | if (containerType == ContainerType.WORKSPACE && mWorkspace != null) { |
| 991 | getUserEventDispatcher().logActionCommand(command, |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 992 | containerType, -1, mWorkspace.isOverlayShown() ? -1 : 0); |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 993 | } else { |
| 994 | getUserEventDispatcher().logActionCommand(command, containerType, -1); |
| 995 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 996 | } |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 997 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 998 | private void scheduleDeferredCheck() { |
| 999 | mHandler.removeCallbacks(mDeferredOverlayCallbacks); |
| 1000 | postAsyncCallback(mHandler, mDeferredOverlayCallbacks); |
| 1001 | } |
| 1002 | |
| 1003 | private void checkIfOverlayStillDeferred() { |
| 1004 | if (!mDeferOverlayCallbacks) { |
| 1005 | return; |
| 1006 | } |
| 1007 | if (isStarted() && (!hasBeenResumed() || mStateManager.getState().disableInteraction)) { |
| 1008 | return; |
| 1009 | } |
| 1010 | mDeferOverlayCallbacks = false; |
| 1011 | |
| 1012 | // Move the client to the correct state. Calling the same method twice is no-op. |
| 1013 | if (isStarted()) { |
| 1014 | mOverlayManager.onActivityStarted(this); |
| 1015 | } |
| 1016 | if (hasBeenResumed()) { |
| 1017 | mOverlayManager.onActivityResumed(this); |
| 1018 | } else { |
| 1019 | mOverlayManager.onActivityPaused(this); |
| 1020 | } |
| 1021 | if (!isStarted()) { |
| 1022 | mOverlayManager.onActivityStopped(this); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | public void deferOverlayCallbacksUntilNextResumeOrStop() { |
| 1027 | mDeferOverlayCallbacks = true; |
| 1028 | } |
| 1029 | |
| 1030 | public LauncherOverlayManager getOverlayManager() { |
| 1031 | return mOverlayManager; |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 1034 | public void onStateSetStart(LauncherState state) { |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 1035 | if (mDeferredResumePending) { |
| 1036 | handleDeferredResume(); |
| 1037 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1038 | if (mDeferOverlayCallbacks) { |
| 1039 | scheduleDeferredCheck(); |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 1040 | } |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 1041 | addActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE); |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 1044 | public void onStateSetEnd(LauncherState state) { |
| 1045 | getAppWidgetHost().setResumed(state == LauncherState.NORMAL); |
| 1046 | getWorkspace().setClipChildren(!state.disablePageClipping); |
| 1047 | finishAutoCancelActionMode(); |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 1048 | removeActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE); |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 1051 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1052 | protected void onResume() { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 1053 | Object traceToken = TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT, |
| 1054 | TraceHelper.FLAG_UI_EVENT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1055 | super.onResume(); |
Sunny Goyal | fca6bc9 | 2017-09-28 16:28:34 -0700 | [diff] [blame] | 1056 | |
Sunny Goyal | a002c6c | 2019-02-12 16:20:10 -0800 | [diff] [blame] | 1057 | mHandler.removeCallbacks(mHandleDeferredResume); |
| 1058 | Utilities.postAsyncCallback(mHandler, mHandleDeferredResume); |
Hyunyoung Song | bd6fba9 | 2018-05-16 15:54:31 -0700 | [diff] [blame] | 1059 | |
Winson Chung | 940b0ac | 2019-07-09 11:33:50 -0700 | [diff] [blame] | 1060 | if (!mOnResumeCallbacks.isEmpty()) { |
| 1061 | final ArrayList<OnResumeCallback> resumeCallbacks = new ArrayList<>(mOnResumeCallbacks); |
| 1062 | mOnResumeCallbacks.clear(); |
| 1063 | for (int i = resumeCallbacks.size() - 1; i >= 0; i--) { |
| 1064 | resumeCallbacks.get(i).onLauncherResume(); |
| 1065 | } |
| 1066 | resumeCallbacks.clear(); |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 1067 | } |
Sunny Goyal | 95f3d6b | 2016-08-10 16:09:29 -0700 | [diff] [blame] | 1068 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1069 | if (mDeferOverlayCallbacks) { |
| 1070 | scheduleDeferredCheck(); |
| 1071 | } else { |
| 1072 | mOverlayManager.onActivityResumed(this); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1073 | } |
Mario Bertschler | 0fc6f68 | 2017-02-17 12:16:13 -0800 | [diff] [blame] | 1074 | |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 1075 | TraceHelper.INSTANCE.endSection(traceToken); |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1078 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1079 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1080 | // Ensure that items added to Launcher are queued until Launcher returns |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 1081 | InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1082 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1083 | super.onPause(); |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1084 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1085 | mDragController.resetLastGestureUpTime(); |
Hyunyoung Song | 497708c | 2019-05-01 16:16:53 -0700 | [diff] [blame] | 1086 | mDropTargetBar.animateToVisibility(false); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1087 | |
| 1088 | if (!mDeferOverlayCallbacks) { |
| 1089 | mOverlayManager.onActivityPaused(this); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1090 | } |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1093 | class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks { |
| 1094 | |
Sunny Goyal | c86df47 | 2016-02-25 09:19:38 -0800 | [diff] [blame] | 1095 | public void onScrollChanged(float progress) { |
| 1096 | if (mWorkspace != null) { |
| 1097 | mWorkspace.onOverlayScrollChanged(progress); |
| 1098 | } |
| 1099 | } |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 1102 | public boolean isInState(LauncherState state) { |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 1103 | return mStateManager.getState() == state; |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1106 | /** |
| 1107 | * Restores the previous state, if it exists. |
| 1108 | * |
| 1109 | * @param savedState The previous state. |
| 1110 | */ |
| 1111 | private void restoreState(Bundle savedState) { |
| 1112 | if (savedState == null) { |
| 1113 | return; |
| 1114 | } |
| 1115 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1116 | int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal); |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 1117 | LauncherState[] stateValues = LauncherState.values(); |
| 1118 | LauncherState state = stateValues[stateOrdinal]; |
Sunny Goyal | bc683e9 | 2017-12-06 10:25:07 -0800 | [diff] [blame] | 1119 | if (!state.disableRestore) { |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1120 | mStateManager.goToState(state, false /* animated */); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1121 | } |
| 1122 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1123 | PendingRequestArgs requestArgs = savedState.getParcelable( |
| 1124 | RUNTIME_STATE_PENDING_REQUEST_ARGS); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1125 | if (requestArgs != null) { |
| 1126 | setWaitingForResult(requestArgs); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1127 | } |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1128 | mPendingActivityRequestCode = savedState.getInt(RUNTIME_STATE_PENDING_REQUEST_CODE); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1129 | |
| 1130 | mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1131 | |
| 1132 | SparseArray<Parcelable> widgetsState = |
| 1133 | savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL); |
| 1134 | if (widgetsState != null) { |
| 1135 | WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState); |
| 1136 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * Finds all the views we need and configure them properly. |
| 1141 | */ |
| 1142 | private void setupViews() { |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 1143 | mDragLayer = findViewById(R.id.drag_layer); |
Sunny Goyal | 3333b0c | 2016-05-09 20:43:21 -0700 | [diff] [blame] | 1144 | mFocusHandler = mDragLayer.getFocusIndicatorHelper(); |
Sunny Goyal | 966d901 | 2017-06-06 16:43:59 -0700 | [diff] [blame] | 1145 | mWorkspace = mDragLayer.findViewById(R.id.workspace); |
Sunny Goyal | d0a6ae7 | 2016-06-16 12:29:03 -0700 | [diff] [blame] | 1146 | mWorkspace.initParentViews(mDragLayer); |
Sunny Goyal | 1676458 | 2017-11-06 16:00:34 -0800 | [diff] [blame] | 1147 | mOverviewPanel = findViewById(R.id.overview_panel); |
Sunny Goyal | 7c7be8c | 2018-03-07 19:58:07 -0800 | [diff] [blame] | 1148 | mHotseat = findViewById(R.id.hotseat); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1149 | |
Sunny Goyal | 784f9c3 | 2016-03-23 16:56:54 -0700 | [diff] [blame] | 1150 | mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1151 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 1152 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1153 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1154 | // Setup the drag layer |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1155 | mDragLayer.setup(mDragController, mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1156 | |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1157 | mWorkspace.setup(mDragController); |
Winson | c7d2e83 | 2016-07-28 12:24:55 -0700 | [diff] [blame] | 1158 | // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the |
| 1159 | // default state, otherwise we will update to the wrong offsets in RTL |
| 1160 | mWorkspace.lockWallpaperToDefaultPage(); |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 1161 | mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1162 | mDragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1163 | |
Tony Wickham | 34d2c91 | 2015-09-11 09:27:58 -0700 | [diff] [blame] | 1164 | // Get the search/delete/uninstall bar |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1165 | mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1166 | |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1167 | // Setup Apps |
| 1168 | mAppsView = findViewById(R.id.apps_view); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1169 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 1170 | // Setup Scrim |
| 1171 | mScrimView = findViewById(R.id.scrim_view); |
| 1172 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1173 | // Setup the drag controller (drop targets have to be added in reverse order in priority) |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1174 | mDragController.setMoveTarget(mWorkspace); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 1175 | mDropTargetBar.setup(mDragController); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1176 | |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 1177 | mAllAppsController.setupViews(mAppsView); |
Tony Wickham | 4fdba14 | 2019-11-04 16:23:51 -0800 | [diff] [blame] | 1178 | |
| 1179 | if (FeatureFlags.ENABLE_OVERVIEW_ACTIONS.get()) { |
| 1180 | // Overview is above all other launcher elements, including qsb, so move it to the top. |
| 1181 | mOverviewPanel.bringToFront(); |
| 1182 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Creates a view representing a shortcut. |
| 1187 | * |
| 1188 | * @param info The data structure describing the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1189 | */ |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1190 | View createShortcut(WorkspaceItemInfo info) { |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 1191 | return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1196 | * |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1197 | * @param parent The group the shortcut belongs to. |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1198 | * @param info The data structure describing the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1199 | * @return A View inflated from layoutResId. |
| 1200 | */ |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1201 | public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) { |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 1202 | BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext()) |
| 1203 | .inflate(R.layout.app_icon, parent, false); |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1204 | favorite.applyFromWorkspaceItem(info); |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 1205 | favorite.setOnClickListener(ItemClickHandler.INSTANCE); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1206 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1207 | return favorite; |
| 1208 | } |
| 1209 | |
| 1210 | /** |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1211 | * Add a shortcut to the workspace or to a Folder. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1212 | * |
| 1213 | * @param data The intent describing the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1214 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 1215 | private void completeAddShortcut(Intent data, int container, int screenId, int cellX, |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 1216 | int cellY, PendingRequestArgs args) { |
Pinyao Ting | 5eee5f4 | 2019-10-31 16:47:35 -0700 | [diff] [blame] | 1217 | if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1218 | || args.getPendingIntent().getComponent() == null) { |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 1219 | return; |
| 1220 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1221 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1222 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1223 | CellLayout layout = getCellLayout(container, screenId); |
| 1224 | |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1225 | WorkspaceItemInfo info = null; |
Hyunyoung Song | e24cb63 | 2017-09-11 11:18:03 -0700 | [diff] [blame] | 1226 | if (Utilities.ATLEAST_OREO) { |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 1227 | info = PinRequestHelper.createWorkspaceItemFromPinItemRequest( |
| 1228 | this, PinRequestHelper.getPinItemRequest(data), 0); |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | if (info == null) { |
Sunny Goyal | b57645f | 2017-03-20 13:57:28 -0700 | [diff] [blame] | 1232 | // Legacy shortcuts are only supported for primary profile. |
| 1233 | info = Process.myUserHandle().equals(args.user) |
| 1234 | ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null; |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1235 | |
Sunny Goyal | b57645f | 2017-03-20 13:57:28 -0700 | [diff] [blame] | 1236 | if (info == null) { |
| 1237 | Log.e(TAG, "Unable to parse a valid custom shortcut result"); |
| 1238 | return; |
| 1239 | } else if (!new PackageManagerHelper(this).hasPermissionForActivity( |
Sunny Goyal | 342e466 | 2017-02-02 15:21:08 -0800 | [diff] [blame] | 1240 | info.intent, args.getPendingIntent().getComponent().getPackageName())) { |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1241 | // The app is trying to add a shortcut without sufficient permissions |
| 1242 | Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0)); |
| 1243 | return; |
| 1244 | } |
| 1245 | } |
| 1246 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1247 | if (container < 0) { |
| 1248 | // Adding a shortcut to the Workspace. |
| 1249 | final View view = createShortcut(info); |
| 1250 | boolean foundCellSpan = false; |
| 1251 | // First we check if we already know the exact location where we want to add this item. |
| 1252 | if (cellX >= 0 && cellY >= 0) { |
| 1253 | cellXY[0] = cellX; |
| 1254 | cellXY[1] = cellY; |
| 1255 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1256 | |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 1257 | DragObject dragObject = new DragObject(getApplicationContext()); |
| 1258 | dragObject.dragInfo = info; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1259 | // If appropriate, either create a folder or add to an existing folder |
| 1260 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 1261 | true, dragObject)) { |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1262 | return; |
| 1263 | } |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1264 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1265 | true)) { |
| 1266 | return; |
| 1267 | } |
| 1268 | } else { |
| 1269 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
| 1270 | } |
| 1271 | |
| 1272 | if (!foundCellSpan) { |
| 1273 | mWorkspace.onNoCellFound(layout); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1274 | return; |
| 1275 | } |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1276 | |
| 1277 | getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]); |
| 1278 | mWorkspace.addInScreen(view, info); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1279 | } else { |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1280 | // Adding a shortcut to a Folder. |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1281 | FolderIcon folderIcon = findFolderIcon(container); |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1282 | if (folderIcon != null) { |
| 1283 | FolderInfo folderInfo = (FolderInfo) folderIcon.getTag(); |
| 1284 | folderInfo.add(info, args.rank, false); |
| 1285 | } else { |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1286 | Log.e(TAG, "Could not find folder with id " + container + " to add shortcut."); |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1287 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1288 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1289 | } |
| 1290 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 1291 | public FolderIcon findFolderIcon(final int folderIconId) { |
Sunny Goyal | 83fd25e | 2018-07-09 16:47:01 -0700 | [diff] [blame] | 1292 | return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId); |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1295 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1296 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1297 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1298 | * @param appWidgetId The app widget id |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1299 | */ |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1300 | @Thunk |
| 1301 | void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1302 | AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) { |
| 1303 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1304 | if (appWidgetInfo == null) { |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1305 | appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1306 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1307 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1308 | LauncherAppWidgetInfo launcherInfo; |
| 1309 | launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1310 | launcherInfo.spanX = itemInfo.spanX; |
| 1311 | launcherInfo.spanY = itemInfo.spanY; |
| 1312 | launcherInfo.minSpanX = itemInfo.minSpanX; |
| 1313 | launcherInfo.minSpanY = itemInfo.minSpanY; |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 1314 | launcherInfo.user = appWidgetInfo.getProfile(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1315 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1316 | getModelWriter().addItemToDatabase(launcherInfo, |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1317 | itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1318 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1319 | if (hostView == null) { |
| 1320 | // Perform actual inflation because we're live |
| 1321 | hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1322 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1323 | hostView.setVisibility(View.VISIBLE); |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 1324 | prepareAppWidget(hostView, launcherInfo); |
| 1325 | mWorkspace.addInScreen(hostView, launcherInfo); |
Pinyao Ting | c907427 | 2019-11-11 11:51:44 -0800 | [diff] [blame] | 1326 | announceForAccessibility(R.string.item_added_to_workspace); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1327 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1328 | |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 1329 | private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) { |
Sunny Goyal | 87af0fd | 2016-05-16 14:56:02 -0700 | [diff] [blame] | 1330 | hostView.setTag(item); |
| 1331 | item.onBindAppWidget(this, hostView); |
Sunny Goyal | 87af0fd | 2016-05-16 14:56:02 -0700 | [diff] [blame] | 1332 | hostView.setFocusable(true); |
| 1333 | hostView.setOnFocusChangeListener(mFocusHandler); |
Sunny Goyal | 25c2e3e | 2015-10-28 23:28:21 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1336 | private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1337 | @Override |
| 1338 | public void onReceive(Context context, Intent intent) { |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1339 | // Reset AllApps to its initial state only if we are not in the middle of |
| 1340 | // processing a multi-step drop |
| 1341 | if (mPendingRequestArgs == null) { |
| 1342 | mStateManager.goToState(NORMAL); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | }; |
| 1346 | |
Sunny Goyal | aae6fbb | 2019-01-31 16:05:58 -0800 | [diff] [blame] | 1347 | public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 1348 | mWorkspace.updateNotificationDots(updatedDots); |
| 1349 | mAppsView.getAppsStore().updateNotificationDots(updatedDots); |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 1350 | } |
| 1351 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1352 | @Override |
| 1353 | public void onAttachedToWindow() { |
| 1354 | super.onAttachedToWindow(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1355 | mOverlayManager.onAttachedToWindow(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | @Override |
| 1359 | public void onDetachedFromWindow() { |
| 1360 | super.onDetachedFromWindow(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1361 | mOverlayManager.onDetachedFromWindow(); |
| 1362 | closeContextMenu(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 1365 | public AllAppsTransitionController getAllAppsController() { |
| 1366 | return mAllAppsController; |
| 1367 | } |
| 1368 | |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 1369 | @Override |
Winson Chung | 1a34100 | 2018-01-17 10:00:23 -0800 | [diff] [blame] | 1370 | public LauncherRootView getRootView() { |
| 1371 | return (LauncherRootView) mLauncherView; |
| 1372 | } |
| 1373 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 1374 | @Override |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1375 | public DragLayer getDragLayer() { |
| 1376 | return mDragLayer; |
| 1377 | } |
| 1378 | |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 1379 | public AllAppsContainerView getAppsView() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1380 | return mAppsView; |
| 1381 | } |
| 1382 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1383 | public Workspace getWorkspace() { |
| 1384 | return mWorkspace; |
| 1385 | } |
| 1386 | |
| 1387 | public Hotseat getHotseat() { |
| 1388 | return mHotseat; |
| 1389 | } |
| 1390 | |
Sunny Goyal | 7c7be8c | 2018-03-07 19:58:07 -0800 | [diff] [blame] | 1391 | public <T extends View> T getOverviewPanel() { |
Winson Chung | 8ae4198 | 2017-11-10 11:42:13 -0800 | [diff] [blame] | 1392 | return (T) mOverviewPanel; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 1395 | public DropTargetBar getDropTargetBar() { |
| 1396 | return mDropTargetBar; |
Tony Wickham | 34d2c91 | 2015-09-11 09:27:58 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1399 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1400 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1401 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1402 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1403 | public LauncherModel getModel() { |
| 1404 | return mModel; |
| 1405 | } |
| 1406 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1407 | public ModelWriter getModelWriter() { |
| 1408 | return mModelWriter; |
| 1409 | } |
| 1410 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1411 | @Override |
Adam Cohen | 79d90c5 | 2016-04-22 13:29:20 -0700 | [diff] [blame] | 1412 | public SharedPreferences getSharedPrefs() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1413 | return mSharedPrefs; |
| 1414 | } |
| 1415 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1416 | @Override |
| 1417 | public SharedPreferences getDevicePrefs() { |
| 1418 | return Utilities.getDevicePrefs(this); |
| 1419 | } |
| 1420 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1421 | public int getOrientation() { |
| 1422 | return mOldConfig.orientation; |
| 1423 | } |
Jon Miranda | 6bed350 | 2017-09-19 14:43:17 -0700 | [diff] [blame] | 1424 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1425 | @Override |
| 1426 | protected void onNewIntent(Intent intent) { |
vadimt | baf5fbb | 2019-12-16 18:56:09 -0800 | [diff] [blame] | 1427 | if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { |
| 1428 | Log.d(TestProtocol.PERMANENT_DIAG_TAG, "Launcher.onNewIntent: " + intent); |
| 1429 | } |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 1430 | Object traceToken = TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1431 | super.onNewIntent(intent); |
| 1432 | |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 1433 | boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() & |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1434 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1435 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Sunny Goyal | 8531373 | 2016-09-28 12:00:07 -0700 | [diff] [blame] | 1436 | |
| 1437 | // Check this condition before handling isActionMain, as this will get reset. |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1438 | boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL) |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 1439 | && AbstractFloatingView.getTopOpenView(this) == null; |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1440 | boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction()); |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 1441 | boolean internalStateHandled = ACTIVITY_TRACKER.handleNewIntent(this, intent); |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1442 | |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1443 | if (isActionMain) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1444 | if (!internalStateHandled) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1445 | // In all these cases, only animate if we're already on home |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 1446 | AbstractFloatingView.closeAllOpenViews(this, isStarted()); |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 1447 | |
Sunny Goyal | a246727 | 2018-03-16 14:53:05 -0700 | [diff] [blame] | 1448 | if (!isInState(NORMAL)) { |
| 1449 | // Only change state, if not already the same. This prevents cancelling any |
| 1450 | // animations running as part of resume |
| 1451 | mStateManager.goToState(NORMAL); |
| 1452 | } |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1453 | |
| 1454 | // Reset the apps view |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1455 | if (!alreadyOnHome) { |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 1456 | mAppsView.reset(isStarted() /* animate */); |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1457 | } |
| 1458 | |
Sunny Goyal | aad3359 | 2018-08-07 17:20:35 -0700 | [diff] [blame] | 1459 | if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1460 | mWorkspace.post(mWorkspace::moveToDefaultScreen); |
| 1461 | } |
| 1462 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1463 | |
Hyunyoung Song | 2a70b3d | 2019-06-11 12:47:07 -0700 | [diff] [blame] | 1464 | // Handle HOME_INTENT |
| 1465 | UserEventDispatcher ued = getUserEventDispatcher(); |
| 1466 | Target target = newContainerTarget(mStateManager.getState().containerType); |
| 1467 | target.pageIndex = mWorkspace.getCurrentPage(); |
| 1468 | ued.logActionCommand(Action.Command.HOME_INTENT, target, |
| 1469 | newContainerTarget(ContainerType.WORKSPACE)); |
| 1470 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1471 | final View v = getWindow().peekDecorView(); |
| 1472 | if (v != null && v.getWindowToken() != null) { |
Sunny Goyal | 326403e | 2017-10-02 12:45:10 -0700 | [diff] [blame] | 1473 | UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken()); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1476 | if (mLauncherCallbacks != null) { |
Sunny Goyal | 8546213 | 2018-04-24 11:39:37 -0700 | [diff] [blame] | 1477 | mLauncherCallbacks.onHomeIntent(internalStateHandled); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1478 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1479 | mOverlayManager.hideOverlay(isStarted() && !isForceInvisible()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1480 | } |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1481 | |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 1482 | TraceHelper.INSTANCE.endSection(traceToken); |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1485 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1486 | public void onRestoreInstanceState(Bundle state) { |
| 1487 | super.onRestoreInstanceState(state); |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 1488 | mWorkspace.restoreInstanceStateForChild(mSynchronouslyBoundPage); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | @Override |
| 1492 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1493 | if (mWorkspace.getChildCount() > 0) { |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 1494 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage()); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1495 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1496 | } |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 1497 | outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1498 | |
| 1499 | |
| 1500 | AbstractFloatingView widgets = AbstractFloatingView |
| 1501 | .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET); |
| 1502 | if (widgets != null) { |
| 1503 | SparseArray<Parcelable> widgetsState = new SparseArray<>(); |
| 1504 | widgets.saveHierarchyState(widgetsState); |
| 1505 | outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState); |
| 1506 | } else { |
| 1507 | outState.remove(RUNTIME_STATE_WIDGET_PANEL); |
| 1508 | } |
| 1509 | |
Pinyao Ting | a74b63a | 2019-07-17 23:26:06 -0700 | [diff] [blame] | 1510 | // We close any open folders and shortcut containers that are not safe for rebind, |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 1511 | // and we need to make sure this state is reflected. |
Pinyao Ting | a74b63a | 2019-07-17 23:26:06 -0700 | [diff] [blame] | 1512 | AbstractFloatingView.closeOpenViews(this, false, TYPE_ALL & ~TYPE_REBIND_SAFE); |
| 1513 | finishAutoCancelActionMode(); |
Tony Wickham | 49c8d29 | 2016-07-01 11:44:34 -0700 | [diff] [blame] | 1514 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1515 | if (mPendingRequestArgs != null) { |
| 1516 | outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs); |
| 1517 | } |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1518 | outState.putInt(RUNTIME_STATE_PENDING_REQUEST_CODE, mPendingActivityRequestCode); |
| 1519 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1520 | if (mPendingActivityResult != null) { |
| 1521 | outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1522 | } |
| 1523 | |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1524 | super.onSaveInstanceState(outState); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1525 | mOverlayManager.onActivitySaveInstanceState(this, outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | @Override |
| 1529 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1530 | super.onDestroy(); |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 1531 | ACTIVITY_TRACKER.onActivityDestroyed(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1532 | |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1533 | unregisterReceiver(mScreenOffReceiver); |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 1534 | mWorkspace.removeFolderListeners(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1535 | PluginManagerWrapper.INSTANCE.get(this).removePluginListener(this); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1536 | |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 1537 | mModel.removeCallbacks(this); |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 1538 | mRotationHelper.destroy(); |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 1539 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1540 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1541 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1542 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1543 | Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1544 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1545 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1546 | TextKeyListener.getInstance().release(); |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 1547 | clearPendingBinds(); |
Hyunyoung Song | 31971a3 | 2019-01-27 12:31:12 -0800 | [diff] [blame] | 1548 | LauncherAppState.getIDP(this).removeOnChangeListener(this); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1549 | |
| 1550 | mOverlayManager.onActivityDestroyed(this); |
Winson Chung | 24ab40c | 2019-10-30 22:35:09 -0700 | [diff] [blame] | 1551 | mAppTransitionManager.unregisterRemoteAnimations(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1552 | } |
| 1553 | |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 1554 | public LauncherAccessibilityDelegate getAccessibilityDelegate() { |
| 1555 | return mAccessibilityDelegate; |
| 1556 | } |
| 1557 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1558 | public DragController getDragController() { |
| 1559 | return mDragController; |
| 1560 | } |
| 1561 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1562 | @Override |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 1563 | public void startActivityForResult(Intent intent, int requestCode, Bundle options) { |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1564 | if (requestCode != -1) { |
| 1565 | mPendingActivityRequestCode = requestCode; |
| 1566 | } |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 1567 | super.startActivityForResult(intent, requestCode, options); |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | @Override |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1571 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 1572 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) { |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1573 | if (requestCode != -1) { |
| 1574 | mPendingActivityRequestCode = requestCode; |
| 1575 | } |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 1576 | try { |
| 1577 | super.startIntentSenderForResult(intent, requestCode, |
| 1578 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
| 1579 | } catch (IntentSender.SendIntentException e) { |
| 1580 | throw new ActivityNotFoundException(); |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1584 | /** |
| 1585 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1586 | * argument for {@link #startSearch} to true. |
| 1587 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1588 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1589 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1590 | Bundle appSearchData, boolean globalSearch) { |
| 1591 | if (appSearchData == null) { |
| 1592 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 1593 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1594 | } |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 1595 | |
Sunny Goyal | 6f28e71 | 2016-09-13 14:19:29 -0700 | [diff] [blame] | 1596 | if (mLauncherCallbacks == null || |
| 1597 | !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) { |
| 1598 | // Starting search from the callbacks failed. Start the default global search. |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 1599 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, true); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 1600 | } |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 1601 | |
| 1602 | // We need to show the workspace after starting the search |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1603 | mStateManager.goToState(NORMAL); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1604 | } |
| 1605 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1606 | public boolean isWorkspaceLocked() { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1607 | return mWorkspaceLoading || mPendingRequestArgs != null; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1608 | } |
| 1609 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 1610 | public boolean isWorkspaceLoading() { |
| 1611 | return mWorkspaceLoading; |
| 1612 | } |
| 1613 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1614 | private void setWorkspaceLoading(boolean value) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1615 | mWorkspaceLoading = value; |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1618 | public void setWaitingForResult(PendingRequestArgs args) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1619 | mPendingRequestArgs = args; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1620 | } |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1621 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1622 | void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1623 | WidgetAddFlowHandler addFlowHandler) { |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 1624 | if (LOGD) { |
| 1625 | Log.d(TAG, "Adding widget from drop"); |
| 1626 | } |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1627 | addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1630 | void addAppWidgetImpl(int appWidgetId, ItemInfo info, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1631 | AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) { |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1632 | if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, |
| 1633 | REQUEST_CREATE_APPWIDGET)) { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1634 | // If the configuration flow was not started, add the widget |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1635 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1636 | Runnable onComplete = new Runnable() { |
| 1637 | @Override |
| 1638 | public void run() { |
| 1639 | // Exit spring loaded mode if necessary after adding the widget |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1640 | mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1641 | } |
| 1642 | }; |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1643 | completeAddAppWidget(appWidgetId, info, boundWidget, |
| 1644 | addFlowHandler.getProviderInfo(this)); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 1645 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1646 | } |
| 1647 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1648 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 1649 | public void addPendingItem(PendingAddItemInfo info, int container, int screenId, |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1650 | int[] cell, int spanX, int spanY) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1651 | info.container = container; |
| 1652 | info.screenId = screenId; |
| 1653 | if (cell != null) { |
| 1654 | info.cellX = cell[0]; |
| 1655 | info.cellY = cell[1]; |
| 1656 | } |
| 1657 | info.spanX = spanX; |
| 1658 | info.spanY = spanY; |
| 1659 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1660 | switch (info.itemType) { |
| 1661 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: |
| 1662 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1663 | addAppWidgetFromDrop((PendingAddWidgetInfo) info); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1664 | break; |
| 1665 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1666 | processShortcutFromDrop((PendingAddShortcutInfo) info); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1667 | break; |
| 1668 | default: |
| 1669 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1670 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1671 | } |
| 1672 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1673 | /** |
| 1674 | * Process a shortcut drop. |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1675 | */ |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1676 | private void processShortcutFromDrop(PendingAddShortcutInfo info) { |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 1677 | Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName); |
| 1678 | setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info)); |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1679 | if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) { |
| 1680 | handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null); |
| 1681 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1684 | /** |
| 1685 | * Process a widget drop. |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1686 | */ |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1687 | private void addAppWidgetFromDrop(PendingAddWidgetInfo info) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1688 | AppWidgetHostView hostView = info.boundWidget; |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 1689 | final int appWidgetId; |
Sunny Goyal | 8a0dc38 | 2017-01-25 11:30:06 -0800 | [diff] [blame] | 1690 | WidgetAddFlowHandler addFlowHandler = info.getHandler(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1691 | if (hostView != null) { |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 1692 | // In the case where we've prebound the widget, we remove it from the DragLayer |
| 1693 | if (LOGD) { |
| 1694 | Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null"); |
| 1695 | } |
| 1696 | getDragLayer().removeView(hostView); |
| 1697 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1698 | appWidgetId = hostView.getAppWidgetId(); |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1699 | addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler); |
Sunny Goyal | 5b9ebca | 2015-06-01 18:37:32 -0700 | [diff] [blame] | 1700 | |
| 1701 | // Clear the boundWidget so that it doesn't get destroyed. |
| 1702 | info.boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1703 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1704 | // In this case, we either need to start an activity to get permission to bind |
| 1705 | // the widget, or we need to start an activity to configure the widget, or both. |
Pinyao Ting | c7a6c29 | 2019-08-26 14:36:02 -0700 | [diff] [blame] | 1706 | if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) { |
| 1707 | appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider( |
| 1708 | info.componentName); |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 1709 | } else { |
| 1710 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
| 1711 | } |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 1712 | Bundle options = info.bindOptions; |
| 1713 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1714 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 1715 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 1716 | if (success) { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1717 | addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 1718 | } else { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1719 | addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 1720 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1721 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 1724 | FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1725 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1726 | final FolderInfo folderInfo = new FolderInfo(); |
Samuel Fufa | 84245e8 | 2019-08-14 13:44:12 -0700 | [diff] [blame] | 1727 | folderInfo.title = ""; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1728 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1729 | // Update the model |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1730 | getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1731 | |
| 1732 | // Create the view |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 1733 | FolderIcon newFolder = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, this, layout, folderInfo); |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 1734 | mWorkspace.addInScreen(newFolder, folderInfo); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 1735 | // Force measure the new folder icon |
| 1736 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 1737 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1738 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1739 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1740 | |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1741 | /** |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 1742 | * Unbinds the view for the specified item, and removes the item and all its children. |
| 1743 | * |
| 1744 | * @param v the view being removed. |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 1745 | * @param itemInfo the {@link ItemInfo} for this view. |
| 1746 | * @param deleteFromDb whether or not to delete this item from the db. |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1747 | */ |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1748 | public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1749 | if (itemInfo instanceof WorkspaceItemInfo) { |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 1750 | // Remove the shortcut from the folder before removing it from launcher |
Sunny Goyal | 44c0643 | 2016-04-02 10:56:02 -0700 | [diff] [blame] | 1751 | View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container); |
| 1752 | if (folderIcon instanceof FolderIcon) { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1753 | ((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true); |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 1754 | } else { |
| 1755 | mWorkspace.removeWorkspaceItem(v); |
| 1756 | } |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1757 | if (deleteFromDb) { |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1758 | getModelWriter().deleteItemFromDatabase(itemInfo); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1759 | } |
| 1760 | } else if (itemInfo instanceof FolderInfo) { |
| 1761 | final FolderInfo folderInfo = (FolderInfo) itemInfo; |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 1762 | if (v instanceof FolderIcon) { |
| 1763 | ((FolderIcon) v).removeListeners(); |
| 1764 | } |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1765 | mWorkspace.removeWorkspaceItem(v); |
| 1766 | if (deleteFromDb) { |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1767 | getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1768 | } |
| 1769 | } else if (itemInfo instanceof LauncherAppWidgetInfo) { |
| 1770 | final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo; |
Winson | 44818e0 | 2015-10-02 11:25:46 -0700 | [diff] [blame] | 1771 | mWorkspace.removeWorkspaceItem(v); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1772 | if (deleteFromDb) { |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 1773 | getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost()); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1774 | } |
| 1775 | } else { |
| 1776 | return false; |
| 1777 | } |
| 1778 | return true; |
| 1779 | } |
| 1780 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1781 | @Override |
| 1782 | public boolean dispatchKeyEvent(KeyEvent event) { |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 1783 | if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { |
| 1784 | TestLogging.recordEvent("Key event: " + event); |
| 1785 | } |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 1786 | return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1787 | } |
| 1788 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1789 | @Override |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 1790 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 1791 | if (Utilities.IS_RUNNING_IN_TEST_HARNESS && ev.getAction() != MotionEvent.ACTION_MOVE) { |
| 1792 | TestLogging.recordEvent("Touch event: " + ev); |
| 1793 | } |
| 1794 | return super.dispatchTouchEvent(ev); |
| 1795 | } |
| 1796 | |
| 1797 | @Override |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1798 | public void onBackPressed() { |
Sunny Goyal | 7c8a65e | 2017-12-22 11:11:33 -0800 | [diff] [blame] | 1799 | if (finishAutoCancelActionMode()) { |
| 1800 | return; |
| 1801 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1802 | |
Sunny Goyal | 4547802 | 2015-06-08 16:52:41 -0700 | [diff] [blame] | 1803 | if (mDragController.isDragging()) { |
| 1804 | mDragController.cancelDrag(); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 1805 | return; |
| 1806 | } |
| 1807 | |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 1808 | // Note: There should be at most one log per method call. This is enforced implicitly |
| 1809 | // by using if-else statements. |
| 1810 | UserEventDispatcher ued = getUserEventDispatcher(); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 1811 | AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this); |
Tony Wickham | 52c1b66 | 2018-05-21 13:13:58 -0700 | [diff] [blame] | 1812 | if (topView != null && topView.onBackPressed()) { |
| 1813 | // Handled by the floating view. |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1814 | } else { |
Sunny Goyal | e39690b | 2018-08-02 13:35:07 -0700 | [diff] [blame] | 1815 | mStateManager.getState().onBackPressed(this); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1816 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1817 | } |
| 1818 | |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 1819 | @TargetApi(Build.VERSION_CODES.M) |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 1820 | @Override |
Jon Miranda | 73c27ec | 2018-05-16 18:06:23 -0700 | [diff] [blame] | 1821 | public ActivityOptions getActivityLaunchOptions(View v) { |
| 1822 | return mAppTransitionManager.getActivityLaunchOptions(this, v); |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Tony Wickham | 3a6746a | 2018-03-29 09:39:56 -0700 | [diff] [blame] | 1825 | public LauncherAppTransitionManager getAppTransitionManager() { |
| 1826 | return mAppTransitionManager; |
| 1827 | } |
| 1828 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 1829 | @TargetApi(Build.VERSION_CODES.M) |
| 1830 | @Override |
| 1831 | protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) { |
| 1832 | // Due to legacy reasons, direct call shortcuts require Launchers to have the |
| 1833 | // corresponding permission. Show the appropriate permission prompt if that |
| 1834 | // is the case. |
| 1835 | if (intent.getComponent() == null |
| 1836 | && Intent.ACTION_CALL.equals(intent.getAction()) |
| 1837 | && checkSelfPermission(android.Manifest.permission.CALL_PHONE) != |
| 1838 | PackageManager.PERMISSION_GRANTED) { |
| 1839 | |
| 1840 | setWaitingForResult(PendingRequestArgs |
| 1841 | .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info)); |
| 1842 | requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE}, |
| 1843 | REQUEST_PERMISSION_CALL_PHONE); |
| 1844 | return true; |
| 1845 | } else { |
| 1846 | return false; |
| 1847 | } |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 1850 | @Override |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 1851 | public int getCurrentState() { |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1852 | if (mStateManager.getState() == LauncherState.ALL_APPS) { |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 1853 | return StatsLogUtils.LAUNCHER_STATE_ALLAPPS; |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 1854 | } else if (mStateManager.getState() == OVERVIEW) { |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 1855 | return StatsLogUtils.LAUNCHER_STATE_OVERVIEW; |
| 1856 | } |
Hyunyoung Song | 0ae3888 | 2018-11-05 14:45:19 -0800 | [diff] [blame] | 1857 | return StatsLogUtils.LAUNCHER_STATE_HOME; |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | @Override |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 1861 | public void modifyUserEvent(LauncherLogProto.LauncherEvent event) { |
| 1862 | if (event.srcTarget != null && event.srcTarget.length > 0 && |
| 1863 | event.srcTarget[1].containerType == ContainerType.PREDICTION) { |
| 1864 | Target[] targets = new Target[3]; |
| 1865 | targets[0] = event.srcTarget[0]; |
| 1866 | targets[1] = event.srcTarget[1]; |
| 1867 | targets[2] = newTarget(Target.Type.CONTAINER); |
| 1868 | event.srcTarget = targets; |
| 1869 | LauncherState state = mStateManager.getState(); |
| 1870 | if (state == LauncherState.ALL_APPS) { |
| 1871 | event.srcTarget[2].containerType = ContainerType.ALLAPPS; |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 1872 | } else if (state == OVERVIEW) { |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 1873 | event.srcTarget[2].containerType = ContainerType.TASKSWITCHER; |
| 1874 | } |
| 1875 | } |
| 1876 | } |
| 1877 | |
Sunny Goyal | 369212a | 2019-03-26 15:03:57 -0700 | [diff] [blame] | 1878 | public boolean startActivitySafely(View v, Intent intent, ItemInfo item, |
| 1879 | @Nullable String sourceContainer) { |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 1880 | if (!hasBeenResumed()) { |
| 1881 | // Workaround an issue where the WM launch animation is clobbered when finishing the |
| 1882 | // recents animation into launcher. Defer launching the activity until Launcher is |
| 1883 | // next resumed. |
| 1884 | addOnResumeCallback(() -> startActivitySafely(v, intent, item, sourceContainer)); |
Winson Chung | c9bf6d4 | 2019-10-04 15:33:18 -0700 | [diff] [blame] | 1885 | if (mOnDeferredActivityLaunchCallback != null) { |
| 1886 | mOnDeferredActivityLaunchCallback.run(); |
| 1887 | mOnDeferredActivityLaunchCallback = null; |
| 1888 | } |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 1889 | return true; |
| 1890 | } |
| 1891 | |
Sunny Goyal | 369212a | 2019-03-26 15:03:57 -0700 | [diff] [blame] | 1892 | boolean success = super.startActivitySafely(v, intent, item, sourceContainer); |
Hyunyoung Song | 1241e61 | 2018-05-15 21:46:51 -0700 | [diff] [blame] | 1893 | if (success && v instanceof BubbleTextView) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 1894 | // This is set to the view that launched the activity that navigated the user away |
| 1895 | // from launcher. Since there is no callback for when the activity has finished |
| 1896 | // launching, enable the press state and keep this reference to reset the press |
| 1897 | // state when we return to launcher. |
| 1898 | BubbleTextView btv = (BubbleTextView) v; |
| 1899 | btv.setStayPressed(true); |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 1900 | addOnResumeCallback(btv); |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 1901 | } |
Hyunyoung Song | 1241e61 | 2018-05-15 21:46:51 -0700 | [diff] [blame] | 1902 | return success; |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1905 | boolean isHotseatLayout(View layout) { |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1906 | // TODO: Remove this method |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 1907 | return mHotseat != null && (layout == mHotseat); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1908 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1909 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1910 | /** |
| 1911 | * Returns the CellLayout of the specified container at the specified screen. |
| 1912 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 1913 | public CellLayout getCellLayout(int container, int screenId) { |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 1914 | return (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) |
| 1915 | ? mHotseat : mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 1918 | @Override |
| 1919 | public void onTrimMemory(int level) { |
| 1920 | super.onTrimMemory(level); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 1921 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
| 1922 | // The widget preview db can result in holding onto over |
| 1923 | // 3MB of memory for caching which isn't necessary. |
| 1924 | SQLiteDatabase.releaseMemory(); |
| 1925 | |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 1926 | // This clears all widget bitmaps from the widget tray |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 1927 | // TODO(hyunyoungs) |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 1928 | } |
| 1929 | } |
| 1930 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 1931 | @Override |
| 1932 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 1933 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 1934 | final List<CharSequence> text = event.getText(); |
| 1935 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 1936 | // Populate event with a fake title based on the current state. |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1937 | // TODO: When can workspace be null? |
| 1938 | text.add(mWorkspace == null |
| 1939 | ? getString(R.string.all_apps_home_button_label) |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 1940 | : mStateManager.getState().getDescription(this)); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 1941 | return result; |
| 1942 | } |
| 1943 | |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 1944 | public void addOnResumeCallback(OnResumeCallback callback) { |
| 1945 | mOnResumeCallbacks.add(callback); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 1948 | /** |
Winson Chung | c9bf6d4 | 2019-10-04 15:33:18 -0700 | [diff] [blame] | 1949 | * Persistant callback which notifies when an activity launch is deferred because the activity |
| 1950 | * was not yet resumed. |
| 1951 | */ |
| 1952 | public void setOnDeferredActivityLaunchCallback(Runnable callback) { |
| 1953 | mOnDeferredActivityLaunchCallback = callback; |
| 1954 | } |
| 1955 | |
| 1956 | /** |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 1957 | * Sets the next page to bind synchronously on next bind. |
| 1958 | * @param page |
| 1959 | */ |
| 1960 | public void setPageToBindSynchronously(int page) { |
| 1961 | mPageToBindSynchronously = page; |
| 1962 | } |
| 1963 | |
| 1964 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1965 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1966 | */ |
Sunny Goyal | 93f878c | 2016-03-30 17:31:24 -0700 | [diff] [blame] | 1967 | @Override |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 1968 | public int getPageToBindSynchronously() { |
| 1969 | if (mPageToBindSynchronously != PagedView.INVALID_PAGE) { |
| 1970 | return mPageToBindSynchronously; |
| 1971 | } else if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1972 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 1973 | } else { |
Winson Chung | 882a52e | 2015-07-08 14:32:26 -0700 | [diff] [blame] | 1974 | return 0; |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 1975 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1976 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1977 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1978 | /** |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 1979 | * Clear any pending bind callbacks. This is called when is loader is planning to |
| 1980 | * perform a full rebind from scratch. |
| 1981 | */ |
| 1982 | @Override |
| 1983 | public void clearPendingBinds() { |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 1984 | if (mPendingExecutor != null) { |
| 1985 | mPendingExecutor.markCompleted(); |
| 1986 | mPendingExecutor = null; |
Sunny Goyal | 6b6d0a3 | 2019-08-05 17:19:32 -0700 | [diff] [blame] | 1987 | |
| 1988 | // We might have set this flag previously and forgot to clear it. |
| 1989 | mAppsView.getAppsStore() |
| 1990 | .disableDeferUpdatesSilently(AllAppsStore.DEFER_UPDATES_NEXT_DRAW); |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1995 | * Refreshes the shortcuts shown on the workspace. |
| 1996 | * |
| 1997 | * Implementation of the method from LauncherModel.Callbacks. |
| 1998 | */ |
| 1999 | public void startBinding() { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2000 | Object traceToken = TraceHelper.INSTANCE.beginSection("startBinding"); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 2001 | // Floating panels (except the full widget sheet) are associated with individual icons. If |
| 2002 | // we are starting a fresh bind, close all such panels as all the icons are about |
| 2003 | // to go away. |
Pinyao Ting | a74b63a | 2019-07-17 23:26:06 -0700 | [diff] [blame] | 2004 | AbstractFloatingView.closeOpenViews(this, true, TYPE_ALL & ~TYPE_REBIND_SAFE); |
Jon Miranda | 6dc7f1e | 2017-02-21 12:37:51 -0800 | [diff] [blame] | 2005 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2006 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2007 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2008 | // Clear the workspace because it's going to be rebound |
Sunny Goyal | 2db5342 | 2019-03-01 16:06:12 -0800 | [diff] [blame] | 2009 | mDragController.cancelDrag(); |
| 2010 | |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2011 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 2012 | mWorkspace.removeAllWorkspaceScreens(); |
Sunny Goyal | c11fac3 | 2018-02-27 19:20:15 -0800 | [diff] [blame] | 2013 | mAppWidgetHost.clearViews(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2014 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2015 | if (mHotseat != null) { |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 2016 | mHotseat.resetLayout(getWallpaperDeviceProfile().isVerticalBarLayout()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2017 | } |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2018 | TraceHelper.INSTANCE.endSection(traceToken); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2019 | } |
| 2020 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2021 | @Override |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2022 | public void bindScreens(IntArray orderedScreenIds) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2023 | // Make sure the first screen is always at the start. |
Jon Miranda | 7143ba6 | 2019-03-15 09:00:05 -0700 | [diff] [blame] | 2024 | if (FeatureFlags.QSB_ON_FIRST_SCREEN && |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 2025 | orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) { |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2026 | orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID); |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2027 | orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID); |
Jon Miranda | 7143ba6 | 2019-03-15 09:00:05 -0700 | [diff] [blame] | 2028 | } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) { |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 2029 | // If there are no screens, we need to have an empty screen |
| 2030 | mWorkspace.addExtraEmptyScreen(); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 2031 | } |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2032 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 2033 | |
Winson | c7d2e83 | 2016-07-28 12:24:55 -0700 | [diff] [blame] | 2034 | // After we have added all the screens, if the wallpaper was locked to the default state, |
| 2035 | // then notify to indicate that it can be released and a proper wallpaper offset can be |
| 2036 | // computed before the next layout |
| 2037 | mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout(); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2040 | private void bindAddScreens(IntArray orderedScreenIds) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2041 | int count = orderedScreenIds.size(); |
| 2042 | for (int i = 0; i < count; i++) { |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2043 | int screenId = orderedScreenIds.get(i); |
Jon Miranda | 7143ba6 | 2019-03-15 09:00:05 -0700 | [diff] [blame] | 2044 | if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2045 | // No need to bind the first screen, as its always bound. |
| 2046 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId); |
| 2047 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2048 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2051 | @Override |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 2052 | public void preAddApps() { |
| 2053 | // If there's an undo snackbar, force it to complete to ensure empty screens are removed |
| 2054 | // before trying to add new items. |
| 2055 | mModelWriter.commitDelete(); |
| 2056 | AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR); |
| 2057 | if (snackbar != null) { |
| 2058 | snackbar.post(() -> snackbar.close(true)); |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | @Override |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2063 | public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated, |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2064 | ArrayList<ItemInfo> addAnimated) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2065 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 2066 | if (newScreens != null) { |
| 2067 | bindAddScreens(newScreens); |
| 2068 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2069 | |
| 2070 | // We add the items without animation on non-visible pages, and with |
| 2071 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 2072 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2073 | bindItems(addNotAnimated, false); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2074 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 2075 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2076 | bindItems(addAnimated, true); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2077 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 2078 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 2079 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2080 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2083 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2084 | * Bind the items start-end from the list. |
| 2085 | * |
| 2086 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2087 | */ |
Tony Wickham | 0bb211a | 2015-10-02 16:22:08 -0700 | [diff] [blame] | 2088 | @Override |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2089 | public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) { |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2090 | // Get the list of added items and intersect them with the set of items here |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 2091 | final Collection<Animator> bounceAnims = new ArrayList<>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 2092 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2093 | Workspace workspace = mWorkspace; |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2094 | int newItemsScreenId = -1; |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2095 | int end = items.size(); |
| 2096 | for (int i = 0; i < end; i++) { |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2097 | final ItemInfo item = items.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 2098 | |
| 2099 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 2100 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 2101 | mHotseat == null) { |
| 2102 | continue; |
| 2103 | } |
| 2104 | |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2105 | final View view; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2106 | switch (item.itemType) { |
| 2107 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 2108 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2109 | case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 2110 | WorkspaceItemInfo info = (WorkspaceItemInfo) item; |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2111 | view = createShortcut(info); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2112 | break; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2113 | } |
| 2114 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: { |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 2115 | view = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2116 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Sunny Goyal | 1cd01b0 | 2016-11-09 10:43:58 -0800 | [diff] [blame] | 2117 | (FolderInfo) item); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2118 | break; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2119 | } |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 2120 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
| 2121 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: { |
Sunny Goyal | a9a1a21 | 2017-08-18 01:03:21 -0700 | [diff] [blame] | 2122 | view = inflateAppWidget((LauncherAppWidgetInfo) item); |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2123 | if (view == null) { |
| 2124 | continue; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2125 | } |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2126 | break; |
| 2127 | } |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 2128 | default: |
| 2129 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2130 | } |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2131 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 2132 | /* |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2133 | * Remove colliding items. |
| 2134 | */ |
| 2135 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 2136 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 2137 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
| 2138 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 2139 | Object tag = v.getTag(); |
| 2140 | String desc = "Collision while binding workspace item: " + item |
| 2141 | + ". Collides with " + tag; |
Sunny Goyal | 3d706ad | 2017-03-06 16:56:39 -0800 | [diff] [blame] | 2142 | if (FeatureFlags.IS_DOGFOOD_BUILD) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2143 | throw (new RuntimeException(desc)); |
| 2144 | } else { |
| 2145 | Log.d(TAG, desc); |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2146 | getModelWriter().deleteItemFromDatabase(item); |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2147 | continue; |
| 2148 | } |
| 2149 | } |
| 2150 | } |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 2151 | workspace.addInScreenFromBind(view, item); |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2152 | if (animateIcons) { |
| 2153 | // Animate all the applications up now |
| 2154 | view.setAlpha(0f); |
| 2155 | view.setScaleX(0f); |
| 2156 | view.setScaleY(0f); |
| 2157 | bounceAnims.add(createNewAppBounceAnimation(view, i)); |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2158 | newItemsScreenId = item.screenId; |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2159 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2160 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2161 | |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2162 | // Animate to the correct page |
| 2163 | if (animateIcons && newItemsScreenId > -1) { |
| 2164 | AnimatorSet anim = new AnimatorSet(); |
| 2165 | anim.playTogether(bounceAnims); |
Jon Miranda | 64eb8ea | 2018-03-29 11:43:58 -0700 | [diff] [blame] | 2166 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2167 | int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2168 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId); |
| 2169 | final Runnable startBounceAnimRunnable = anim::start; |
| 2170 | |
| 2171 | if (newItemsScreenId != currentScreenId) { |
| 2172 | // We post the animation slightly delayed to prevent slowdowns |
| 2173 | // when we are loading right after we return to launcher. |
| 2174 | mWorkspace.postDelayed(new Runnable() { |
| 2175 | public void run() { |
| 2176 | if (mWorkspace != null) { |
| 2177 | AbstractFloatingView.closeAllOpenViews(Launcher.this, false); |
| 2178 | |
| 2179 | mWorkspace.snapToPage(newScreenIndex); |
| 2180 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 2181 | NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 2182 | } |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2183 | } |
| 2184 | }, NEW_APPS_PAGE_MOVE_DELAY); |
| 2185 | } else { |
| 2186 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 2187 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2188 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2189 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2190 | } |
| 2191 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2192 | /** |
| 2193 | * Add the views for a widget to the workspace. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2194 | */ |
Sunny Goyal | a9a1a21 | 2017-08-18 01:03:21 -0700 | [diff] [blame] | 2195 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
| 2196 | View view = inflateAppWidget(item); |
| 2197 | if (view != null) { |
| 2198 | mWorkspace.addInScreen(view, item); |
| 2199 | mWorkspace.requestLayout(); |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | private View inflateAppWidget(LauncherAppWidgetInfo item) { |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 2204 | if (item.hasOptionFlag(LauncherAppWidgetInfo.OPTION_SEARCH_WIDGET)) { |
| 2205 | item.providerName = QsbContainerView.getSearchComponentName(this); |
| 2206 | if (item.providerName == null) { |
| 2207 | getModelWriter().deleteItemFromDatabase(item); |
| 2208 | return null; |
| 2209 | } |
| 2210 | } |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2211 | final AppWidgetHostView view; |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 2212 | if (mIsSafeModeEnabled) { |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2213 | view = new PendingAppWidgetHostView(this, item, mIconCache, true); |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 2214 | prepareAppWidget(view, item); |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2215 | return view; |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 2216 | } |
| 2217 | |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2218 | Object traceToken = TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2219 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2220 | try { |
| 2221 | final LauncherAppWidgetProviderInfo appWidgetInfo; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2222 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2223 | if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) { |
| 2224 | // If the provider is not ready, bind as a pending widget. |
| 2225 | appWidgetInfo = null; |
| 2226 | } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { |
| 2227 | // The widget id is not valid. Try to find the widget based on the provider info. |
| 2228 | appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user); |
| 2229 | } else { |
| 2230 | appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2231 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2232 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2233 | // If the provider is ready, but the width is not yet restored, try to restore it. |
| 2234 | if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) |
| 2235 | && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) { |
| 2236 | if (appWidgetInfo == null) { |
| 2237 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 2238 | + " belongs to component " + item.providerName |
| 2239 | + ", as the provider is null"); |
| 2240 | getModelWriter().deleteItemFromDatabase(item); |
| 2241 | return null; |
| 2242 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2243 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2244 | // If we do not have a valid id, try to bind an id. |
| 2245 | if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { |
| 2246 | if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) { |
| 2247 | // Id has not been allocated yet. Allocate a new id. |
| 2248 | item.appWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 2249 | item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED; |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 2250 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2251 | // Also try to bind the widget. If the bind fails, the user will be shown |
| 2252 | // a click to setup UI, which will ask for the bind permission. |
| 2253 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo); |
| 2254 | pendingInfo.spanX = item.spanX; |
| 2255 | pendingInfo.spanY = item.spanY; |
| 2256 | pendingInfo.minSpanX = item.minSpanX; |
| 2257 | pendingInfo.minSpanY = item.minSpanY; |
| 2258 | Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, |
| 2259 | pendingInfo); |
| 2260 | |
| 2261 | boolean isDirectConfig = |
| 2262 | item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG); |
| 2263 | if (isDirectConfig && item.bindOptions != null) { |
| 2264 | Bundle newOptions = item.bindOptions.getExtras(); |
| 2265 | if (options != null) { |
| 2266 | newOptions.putAll(options); |
| 2267 | } |
| 2268 | options = newOptions; |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 2269 | } |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2270 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2271 | item.appWidgetId, appWidgetInfo, options); |
| 2272 | |
| 2273 | // We tried to bind once. If we were not able to bind, we would need to |
| 2274 | // go through the permission dialog, which means we cannot skip the config |
| 2275 | // activity. |
| 2276 | item.bindOptions = null; |
| 2277 | item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG; |
| 2278 | |
| 2279 | // Bind succeeded |
| 2280 | if (success) { |
| 2281 | // If the widget has a configure activity, it is still needs to set it |
| 2282 | // up, otherwise the widget is ready to go. |
| 2283 | item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig |
| 2284 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 2285 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 2286 | } |
| 2287 | |
| 2288 | getModelWriter().updateItemInDatabase(item); |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 2289 | } |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2290 | } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY) |
| 2291 | && (appWidgetInfo.configure == null)) { |
| 2292 | // The widget was marked as UI not ready, but there is no configure activity to |
| 2293 | // update the UI. |
| 2294 | item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2295 | getModelWriter().updateItemInDatabase(item); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2296 | } |
Sunny Goyal | 56c7360 | 2015-09-25 12:55:01 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2299 | if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 2300 | // Verify that we own the widget |
| 2301 | if (appWidgetInfo == null) { |
| 2302 | FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId); |
| 2303 | getModelWriter().deleteWidgetInfo(item, getAppWidgetHost()); |
| 2304 | return null; |
| 2305 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2306 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2307 | item.minSpanX = appWidgetInfo.minSpanX; |
| 2308 | item.minSpanY = appWidgetInfo.minSpanY; |
| 2309 | view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo); |
| 2310 | } else { |
| 2311 | view = new PendingAppWidgetHostView(this, item, mIconCache, false); |
| 2312 | } |
| 2313 | prepareAppWidget(view, item); |
| 2314 | } finally { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2315 | TraceHelper.INSTANCE.endSection(traceToken); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2318 | return view; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2319 | } |
| 2320 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2321 | /** |
| 2322 | * Restores a pending widget. |
| 2323 | * |
| 2324 | * @param appWidgetId The app widget id |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2325 | */ |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2326 | private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2327 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 2328 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 2329 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2330 | return null; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 2333 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2334 | info.restoreStatus = finalRestoreFlag; |
Jon Miranda | 2b823f4 | 2017-05-02 18:36:18 -0700 | [diff] [blame] | 2335 | if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 2336 | info.pendingItemInfo = null; |
| 2337 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2338 | |
Sunny Goyal | ba47faa | 2017-10-04 16:50:57 -0700 | [diff] [blame] | 2339 | if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) { |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2340 | view.reInflate(); |
Sunny Goyal | ba47faa | 2017-10-04 16:50:57 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2343 | getModelWriter().updateItemInDatabase(info); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2344 | return info; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2347 | public void onPageBoundSynchronously(int page) { |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 2348 | mSynchronouslyBoundPage = page; |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 2349 | mWorkspace.setCurrentPage(page); |
| 2350 | mPageToBindSynchronously = PagedView.INVALID_PAGE; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 2353 | @Override |
| 2354 | public void executeOnNextDraw(ViewOnDrawExecutor executor) { |
Sunny Goyal | 6b6d0a3 | 2019-08-05 17:19:32 -0700 | [diff] [blame] | 2355 | clearPendingBinds(); |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 2356 | mPendingExecutor = executor; |
Sunny Goyal | 60180b0 | 2018-02-07 12:56:30 -0800 | [diff] [blame] | 2357 | if (!isInState(ALL_APPS)) { |
vadimt | d4c90e1 | 2019-06-04 13:59:43 -0700 | [diff] [blame] | 2358 | mAppsView.getAppsStore().enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW); |
| 2359 | mPendingExecutor.execute(() -> mAppsView.getAppsStore().disableDeferUpdates( |
| 2360 | AllAppsStore.DEFER_UPDATES_NEXT_DRAW)); |
Sunny Goyal | 60180b0 | 2018-02-07 12:56:30 -0800 | [diff] [blame] | 2361 | } |
| 2362 | |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 2363 | executor.attachTo(this); |
| 2364 | } |
| 2365 | |
| 2366 | public void clearPendingExecutor(ViewOnDrawExecutor executor) { |
| 2367 | if (mPendingExecutor == executor) { |
| 2368 | mPendingExecutor = null; |
| 2369 | } |
| 2370 | } |
| 2371 | |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 2372 | @Override |
| 2373 | public void finishFirstPageBind(final ViewOnDrawExecutor executor) { |
Sunny Goyal | 6001ea2 | 2018-05-10 16:31:00 -0700 | [diff] [blame] | 2374 | AlphaProperty property = mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD); |
| 2375 | if (property.getValue() < 1) { |
| 2376 | ObjectAnimator anim = ObjectAnimator.ofFloat(property, MultiValueAlpha.VALUE, 1); |
| 2377 | if (executor != null) { |
| 2378 | anim.addListener(new AnimatorListenerAdapter() { |
| 2379 | @Override |
| 2380 | public void onAnimationEnd(Animator animation) { |
| 2381 | executor.onLoadAnimationCompleted(); |
| 2382 | } |
| 2383 | }); |
| 2384 | } |
| 2385 | anim.start(); |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2386 | } else if (executor != null) { |
| 2387 | executor.onLoadAnimationCompleted(); |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 2388 | } |
| 2389 | } |
| 2390 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2391 | /** |
| 2392 | * Callback saying that there aren't any more items to bind. |
| 2393 | * |
| 2394 | * Implementation of the method from LauncherModel.Callbacks. |
| 2395 | */ |
Tony | f80e893 | 2018-12-21 11:58:04 -0800 | [diff] [blame] | 2396 | public void finishBindingItems(int pageBoundFirst) { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2397 | Object traceToken = TraceHelper.INSTANCE.beginSection("finishBindingItems"); |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2398 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2399 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2400 | setWorkspaceLoading(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 2401 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2402 | if (mPendingActivityResult != null) { |
| 2403 | handleActivityResult(mPendingActivityResult.requestCode, |
| 2404 | mPendingActivityResult.resultCode, mPendingActivityResult.data); |
| 2405 | mPendingActivityResult = null; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 2408 | InstallShortcutReceiver.disableAndFlushInstallQueue( |
| 2409 | InstallShortcutReceiver.FLAG_LOADER_RUNNING, this); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2410 | |
Tony | f80e893 | 2018-12-21 11:58:04 -0800 | [diff] [blame] | 2411 | // When undoing the removal of the last item on a page, return to that page. |
Tony Wickham | 03f2701 | 2019-04-25 14:22:54 -0700 | [diff] [blame] | 2412 | // Since we are just resetting the current page without user interaction, |
| 2413 | // override the previous page so we don't log the page switch. |
| 2414 | mWorkspace.setCurrentPage(pageBoundFirst, pageBoundFirst /* overridePrevPage */); |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 2415 | mPageToBindSynchronously = PagedView.INVALID_PAGE; |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 2416 | |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 2417 | // Cache one page worth of icons |
| 2418 | getViewCache().setCacheSize(R.layout.folder_application, |
| 2419 | mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows); |
| 2420 | getViewCache().setCacheSize(R.layout.folder_page, 2); |
| 2421 | |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2422 | TraceHelper.INSTANCE.endSection(traceToken); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 2425 | private boolean canRunNewAppsAnimation() { |
| 2426 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
Andrew Sapperstein | 932eb83 | 2016-06-30 18:10:09 -0700 | [diff] [blame] | 2427 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 2430 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2431 | ValueAnimator bounceAnim = new PropertyListBuilder().alpha(1).scale(1).build(v) |
| 2432 | .setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 2433 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 2434 | bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION)); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 2435 | return bounceAnim; |
| 2436 | } |
| 2437 | |
Pinyao Ting | c907427 | 2019-11-11 11:51:44 -0800 | [diff] [blame] | 2438 | private void announceForAccessibility(@StringRes int stringResId) { |
| 2439 | getDragLayer().announceForAccessibility(getString(stringResId)); |
| 2440 | } |
| 2441 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2442 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2443 | * Add the icons for all apps. |
| 2444 | * |
| 2445 | * Implementation of the method from LauncherModel.Callbacks. |
| 2446 | */ |
Sunny Goyal | 87dcde6 | 2019-07-17 20:35:56 -0700 | [diff] [blame] | 2447 | public void bindAllApplications(AppInfo[] apps) { |
Sunny Goyal | 60180b0 | 2018-02-07 12:56:30 -0800 | [diff] [blame] | 2448 | mAppsView.getAppsStore().setApps(apps); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | /** |
Zak Cohen | 658c67a | 2018-10-19 14:21:05 -0700 | [diff] [blame] | 2452 | * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 2453 | * because LauncherModel's map is updated in the background, while Launcher runs on the UI. |
| 2454 | */ |
| 2455 | @Override |
Zak Cohen | 658c67a | 2018-10-19 14:21:05 -0700 | [diff] [blame] | 2456 | public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) { |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 2457 | mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy); |
Tony Wickham | 1bce7fd | 2016-04-28 17:39:03 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2460 | @Override |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2461 | public void bindPromiseAppProgressUpdated(PromiseAppInfo app) { |
Sunny Goyal | 60180b0 | 2018-02-07 12:56:30 -0800 | [diff] [blame] | 2462 | mAppsView.getAppsStore().updatePromiseAppProgress(app); |
Mario Bertschler | 08ffaae | 2017-03-20 11:30:27 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | @Override |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2466 | public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2467 | mWorkspace.widgetsRestored(widgets); |
| 2468 | } |
| 2469 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2470 | /** |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 2471 | * Some shortcuts were updated in the background. |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 2472 | * Implementation of the method from LauncherModel.Callbacks. |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 2473 | * |
| 2474 | * @param updated list of shortcuts which have changed. |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 2475 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2476 | @Override |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 2477 | public void bindWorkspaceItemsChanged(ArrayList<WorkspaceItemInfo> updated) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2478 | if (!updated.isEmpty()) { |
| 2479 | mWorkspace.updateShortcuts(updated); |
| 2480 | } |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 2484 | * Update the state of a package, typically related to install state. |
| 2485 | * |
| 2486 | * Implementation of the method from LauncherModel.Callbacks. |
| 2487 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 2488 | @Override |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2489 | public void bindRestoreItemsChange(HashSet<ItemInfo> updates) { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 2490 | mWorkspace.updateRestoreItems(updates); |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | /** |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 2494 | * A package was uninstalled/updated. We take both the super set of packageNames |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 2495 | * in addition to specific applications to remove, the reason being that |
| 2496 | * this can be called when a package is updated as well. In that scenario, |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 2497 | * we only remove specific components from the workspace and hotseat, where as |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 2498 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2499 | */ |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2500 | @Override |
Sunny Goyal | 6e13dd3 | 2017-08-17 03:01:19 -0700 | [diff] [blame] | 2501 | public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) { |
Sunny Goyal | 6e13dd3 | 2017-08-17 03:01:19 -0700 | [diff] [blame] | 2502 | mWorkspace.removeItemsByMatcher(matcher); |
| 2503 | mDragController.onAppsRemoved(matcher); |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 2504 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2505 | |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 2506 | @Override |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 2507 | public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) { |
| 2508 | mPopupDataProvider.setAllWidgets(allWidgets); |
Tony Wickham | 26b1746 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
Tony Wickham | 86222d2 | 2017-03-29 15:30:43 -0700 | [diff] [blame] | 2511 | /** |
| 2512 | * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only |
| 2513 | * refreshes the widgets and shortcuts associated with the given package/user |
| 2514 | */ |
| 2515 | public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame] | 2516 | mModel.refreshAndBindWidgetsAndShortcuts(packageUser); |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 2517 | } |
| 2518 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 2519 | /** |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2520 | * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all] |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2521 | */ |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 2522 | @Override |
| 2523 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 2524 | super.dump(prefix, fd, writer, args); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 2525 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2526 | if (args.length > 0 && TextUtils.equals(args[0], "--all")) { |
| 2527 | writer.println(prefix + "Workspace Items"); |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 2528 | for (int i = 0; i < mWorkspace.getPageCount(); i++) { |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2529 | writer.println(prefix + " Homescreen " + i); |
| 2530 | |
| 2531 | ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets(); |
| 2532 | for (int j = 0; j < layout.getChildCount(); j++) { |
| 2533 | Object tag = layout.getChildAt(j).getTag(); |
| 2534 | if (tag != null) { |
| 2535 | writer.println(prefix + " " + tag.toString()); |
| 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | writer.println(prefix + " Hotseat"); |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 2541 | ViewGroup layout = mHotseat.getShortcutsAndWidgets(); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 2542 | for (int j = 0; j < layout.getChildCount(); j++) { |
| 2543 | Object tag = layout.getChildAt(j).getTag(); |
| 2544 | if (tag != null) { |
| 2545 | writer.println(prefix + " " + tag.toString()); |
| 2546 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 2547 | } |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2550 | writer.println(prefix + "Misc:"); |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 2551 | dumpMisc(prefix + "\t", writer); |
| 2552 | writer.println(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading); |
| 2553 | writer.println(prefix + "\tmPendingRequestArgs=" + mPendingRequestArgs |
| 2554 | + " mPendingActivityResult=" + mPendingActivityResult); |
| 2555 | writer.println(prefix + "\tmRotationHelper: " + mRotationHelper); |
| 2556 | writer.println(prefix + "\tmAppWidgetHost.isListening: " + mAppWidgetHost.isListening()); |
| 2557 | |
Sunny Goyal | cb2c505 | 2018-10-15 12:30:29 -0700 | [diff] [blame] | 2558 | // Extra logging for b/116853349 |
Hyunyoung Song | a310a80 | 2019-04-25 13:57:16 -0700 | [diff] [blame] | 2559 | mDragLayer.dump(prefix, writer); |
| 2560 | mStateManager.dump(prefix, writer); |
Sunny Goyal | 2bba190 | 2018-02-27 12:20:50 -0800 | [diff] [blame] | 2561 | |
| 2562 | try { |
| 2563 | FileLog.flushAll(writer); |
| 2564 | } catch (Exception e) { |
| 2565 | // Ignore |
| 2566 | } |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2567 | |
| 2568 | mModel.dumpState(prefix, fd, writer, args); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 2569 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2570 | if (mLauncherCallbacks != null) { |
| 2571 | mLauncherCallbacks.dump(prefix, fd, writer, args); |
| 2572 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 2573 | mOverlayManager.dump(prefix, writer); |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 2574 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 2575 | |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 2576 | @Override |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 2577 | public void onProvideKeyboardShortcuts( |
| 2578 | List<KeyboardShortcutGroup> data, Menu menu, int deviceId) { |
| 2579 | |
| 2580 | ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>(); |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 2581 | if (isInState(NORMAL)) { |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 2582 | shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label), |
| 2583 | KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON)); |
Vadim Tryshev | 74c261c | 2018-06-12 13:44:43 -0700 | [diff] [blame] | 2584 | shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text), |
| 2585 | KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON)); |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 2586 | } |
Vadim Tryshev | 3455f8d | 2018-05-11 20:02:20 -0700 | [diff] [blame] | 2587 | final View currentFocus = getCurrentFocus(); |
| 2588 | if (currentFocus != null) { |
| 2589 | if (new CustomActionsPopup(this, currentFocus).canShow()) { |
| 2590 | shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions), |
| 2591 | KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON)); |
| 2592 | } |
| 2593 | if (currentFocus.getTag() instanceof ItemInfo |
Pinyao Ting | 49a3e69 | 2019-07-26 12:28:38 -0700 | [diff] [blame] | 2594 | && ShortcutUtil.supportsShortcuts((ItemInfo) currentFocus.getTag())) { |
Vadim Tryshev | 3455f8d | 2018-05-11 20:02:20 -0700 | [diff] [blame] | 2595 | shortcutInfos.add(new KeyboardShortcutInfo( |
| 2596 | getString(R.string.shortcuts_menu_with_notifications_description), |
| 2597 | KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON)); |
| 2598 | } |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 2599 | } |
| 2600 | if (!shortcutInfos.isEmpty()) { |
| 2601 | data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos)); |
| 2602 | } |
| 2603 | |
| 2604 | super.onProvideKeyboardShortcuts(data, menu, deviceId); |
| 2605 | } |
| 2606 | |
| 2607 | @Override |
| 2608 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 2609 | if (event.hasModifiers(KeyEvent.META_CTRL_ON)) { |
| 2610 | switch (keyCode) { |
| 2611 | case KeyEvent.KEYCODE_A: |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 2612 | if (isInState(NORMAL)) { |
| 2613 | getStateManager().goToState(ALL_APPS); |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 2614 | return true; |
| 2615 | } |
| 2616 | break; |
| 2617 | case KeyEvent.KEYCODE_S: { |
| 2618 | View focusedView = getCurrentFocus(); |
| 2619 | if (focusedView instanceof BubbleTextView |
| 2620 | && focusedView.getTag() instanceof ItemInfo |
| 2621 | && mAccessibilityDelegate.performAction(focusedView, |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 2622 | (ItemInfo) focusedView.getTag(), |
| 2623 | LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) { |
Sunny Goyal | 00ac920 | 2017-11-09 15:24:06 -0800 | [diff] [blame] | 2624 | PopupContainerWithArrow.getOpen(this).requestFocus(); |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 2625 | return true; |
| 2626 | } |
| 2627 | break; |
| 2628 | } |
| 2629 | case KeyEvent.KEYCODE_O: |
| 2630 | if (new CustomActionsPopup(this, getCurrentFocus()).show()) { |
| 2631 | return true; |
| 2632 | } |
| 2633 | break; |
Vadim Tryshev | 74c261c | 2018-06-12 13:44:43 -0700 | [diff] [blame] | 2634 | case KeyEvent.KEYCODE_W: |
| 2635 | if (isInState(NORMAL)) { |
| 2636 | OptionsPopupView.openWidgets(this); |
| 2637 | return true; |
| 2638 | } |
| 2639 | break; |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 2640 | } |
| 2641 | } |
| 2642 | return super.onKeyShortcut(keyCode, event); |
| 2643 | } |
| 2644 | |
Vadim Tryshev | 646a0dd | 2018-02-05 16:27:50 -0800 | [diff] [blame] | 2645 | @Override |
| 2646 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 2647 | if (keyCode == KeyEvent.KEYCODE_MENU) { |
| 2648 | // KEYCODE_MENU is sent by some tests, for example |
| 2649 | // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling. |
| 2650 | if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() && |
| 2651 | isInState(NORMAL)) { |
| 2652 | // Close any open floating views. |
| 2653 | AbstractFloatingView.closeAllOpenViews(this); |
| 2654 | |
| 2655 | // Setting the touch point to (-1, -1) will show the options popup in the center of |
| 2656 | // the screen. |
vadimt | bc5d7e6 | 2019-12-09 13:53:05 -0800 | [diff] [blame] | 2657 | if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { |
| 2658 | Log.d(TestProtocol.PERMANENT_DIAG_TAG, "Opening options popup on key up"); |
| 2659 | } |
Sunny Goyal | 2fd7a8b | 2018-03-30 17:10:13 -0700 | [diff] [blame] | 2660 | OptionsPopupView.showDefaultOptions(this, -1, -1); |
Vadim Tryshev | 646a0dd | 2018-02-05 16:27:50 -0800 | [diff] [blame] | 2661 | } |
| 2662 | return true; |
| 2663 | } |
| 2664 | return super.onKeyUp(keyCode, event); |
| 2665 | } |
| 2666 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 2667 | protected StateHandler[] createStateHandlers() { |
| 2668 | return new StateHandler[] { getAllAppsController(), getWorkspace() }; |
Andrew Sapperstein | abef55a | 2016-06-19 12:49:00 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 2671 | public TouchController[] createTouchControllers() { |
| 2672 | return new TouchController[] {getDragController(), new AllAppsSwipeController(this)}; |
| 2673 | } |
| 2674 | |
| 2675 | protected RotationMode getFakeRotationMode(DeviceProfile deviceProfile) { |
| 2676 | return RotationMode.NORMAL; |
| 2677 | } |
| 2678 | |
| 2679 | protected ScaleAndTranslation getOverviewScaleAndTranslationForNormalState() { |
| 2680 | return new ScaleAndTranslation(1.1f, 0f, 0f); |
| 2681 | } |
| 2682 | |
| 2683 | public void useFadeOutAnimationForLauncherStart(CancellationSignal signal) { } |
| 2684 | |
| 2685 | public void onDragLayerHierarchyChanged() { } |
| 2686 | |
Vinit Nayak | f9b585b | 2019-07-10 14:25:32 -0700 | [diff] [blame] | 2687 | @Override |
| 2688 | public void returnToHomescreen() { |
| 2689 | super.returnToHomescreen(); |
| 2690 | getStateManager().goToState(LauncherState.NORMAL); |
| 2691 | } |
| 2692 | |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 2693 | public Stream<SystemShortcut.Factory> getSupportedShortcuts() { |
| 2694 | return Stream.of(APP_INFO, WIDGETS, INSTALL, DISMISS_PREDICTION); |
| 2695 | } |
| 2696 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 2697 | public static Launcher getLauncher(Context context) { |
| 2698 | return (Launcher) fromContext(context); |
| 2699 | } |
| 2700 | |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 2701 | /** |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 2702 | * Just a wrapper around the type cast to allow easier tracking of calls. |
| 2703 | */ |
| 2704 | public static <T extends Launcher> T cast(ActivityContext activityContext) { |
| 2705 | return (T) activityContext; |
| 2706 | } |
| 2707 | |
| 2708 | /** |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 2709 | * Callback for listening for onResume |
| 2710 | */ |
| 2711 | public interface OnResumeCallback { |
| 2712 | |
| 2713 | void onLauncherResume(); |
| 2714 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2715 | } |