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 | cd2ac0f | 2022-04-14 21:21:47 -0700 | [diff] [blame] | 19 | import static android.app.PendingIntent.FLAG_IMMUTABLE; |
| 20 | import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 21 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 22 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.CONFIG_UI_MODE; |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 24 | import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO; |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 25 | import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; |
Vinit Nayak | 48b2802 | 2020-04-27 20:48:49 +0000 | [diff] [blame] | 26 | |
Pinyao Ting | a74b63a | 2019-07-17 23:26:06 -0700 | [diff] [blame] | 27 | import static com.android.launcher3.AbstractFloatingView.TYPE_ALL; |
Brian Isganitis | a85ae69 | 2021-09-23 19:56:24 -0400 | [diff] [blame] | 28 | import static com.android.launcher3.AbstractFloatingView.TYPE_FOLDER; |
Sunny Goyal | 30ac97d | 2020-06-24 23:47:46 -0700 | [diff] [blame] | 29 | import static com.android.launcher3.AbstractFloatingView.TYPE_ICON_SURFACE; |
Pinyao Ting | a74b63a | 2019-07-17 23:26:06 -0700 | [diff] [blame] | 30 | import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 31 | import static com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR; |
Brian Isganitis | a85ae69 | 2021-09-23 19:56:24 -0400 | [diff] [blame] | 32 | import static com.android.launcher3.AbstractFloatingView.getTopOpenViewWithType; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 33 | import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY; |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 34 | import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 35 | import static com.android.launcher3.LauncherState.ALL_APPS; |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 36 | import static com.android.launcher3.LauncherState.FLAG_CLOSE_POPUPS; |
| 37 | import static com.android.launcher3.LauncherState.FLAG_MULTI_PAGE; |
| 38 | import static com.android.launcher3.LauncherState.FLAG_NON_INTERACTIVE; |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 39 | import static com.android.launcher3.LauncherState.NORMAL; |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 40 | import static com.android.launcher3.LauncherState.NO_OFFSET; |
| 41 | import static com.android.launcher3.LauncherState.NO_SCALE; |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 42 | import static com.android.launcher3.LauncherState.SPRING_LOADED; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 43 | import static com.android.launcher3.Utilities.postAsyncCallback; |
Sunny Goyal | 384b578 | 2021-02-09 22:50:02 -0800 | [diff] [blame] | 44 | import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.getSupportedActions; |
Thiru Ramasamy | 5fbac63 | 2022-01-28 15:05:36 -0800 | [diff] [blame] | 45 | import static com.android.launcher3.logging.StatsLogManager.EventEnum; |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 46 | import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND; |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 47 | import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME; |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 48 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_ENTRY; |
thiruram | 9f53d61 | 2021-02-24 10:54:01 -0800 | [diff] [blame] | 49 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_ENTRY_WITH_DEVICE_SEARCH; |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 50 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_EXIT; |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 51 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ONRESUME; |
| 52 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ONSTOP; |
Yogisha Dixit | 4ff5ee3 | 2021-05-04 14:58:34 +0100 | [diff] [blame] | 53 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGET_RECONFIGURED; |
Sunny Goyal | 60e68c9 | 2020-08-12 13:59:27 -0700 | [diff] [blame] | 54 | import static com.android.launcher3.model.ItemInstallQueue.FLAG_ACTIVITY_PAUSED; |
| 55 | import static com.android.launcher3.model.ItemInstallQueue.FLAG_DRAG_AND_DROP; |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 56 | import static com.android.launcher3.popup.SystemShortcut.APP_INFO; |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 57 | import static com.android.launcher3.popup.SystemShortcut.INSTALL; |
| 58 | import static com.android.launcher3.popup.SystemShortcut.WIDGETS; |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 59 | import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK; |
Sunny Goyal | be8c340 | 2019-05-22 15:17:52 -0700 | [diff] [blame] | 60 | import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; |
Jon Miranda | 7ebe209 | 2022-03-10 08:46:01 -0800 | [diff] [blame] | 61 | import static com.android.launcher3.testing.TestProtocol.BAD_STATE; |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 62 | import static com.android.launcher3.util.ItemInfoMatcher.forFolderMatch; |
Sunny Goyal | 326403e | 2017-10-02 12:45:10 -0700 | [diff] [blame] | 63 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 64 | import android.animation.Animator; |
Sunny Goyal | 6001ea2 | 2018-05-10 16:31:00 -0700 | [diff] [blame] | 65 | import android.animation.AnimatorListenerAdapter; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 66 | import android.animation.AnimatorSet; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 67 | import android.animation.ValueAnimator; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 68 | import android.annotation.TargetApi; |
Tony Wickham | e78a70b | 2021-03-29 16:45:59 -0700 | [diff] [blame] | 69 | import android.app.Notification; |
| 70 | import android.app.NotificationChannel; |
| 71 | import android.app.NotificationManager; |
| 72 | import android.app.PendingIntent; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 73 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 74 | import android.appwidget.AppWidgetManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 75 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 76 | import android.content.BroadcastReceiver; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 77 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | import android.content.Context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 79 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 80 | import android.content.IntentFilter; |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 81 | import android.content.IntentSender; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 82 | import android.content.SharedPreferences; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 83 | import android.content.pm.PackageManager; |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 84 | import android.content.res.Configuration; |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 85 | import android.database.sqlite.SQLiteDatabase; |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 86 | import android.graphics.Bitmap; |
Tony Wickham | 1906cc3 | 2021-02-11 11:55:24 -0800 | [diff] [blame] | 87 | import android.graphics.Rect; |
Sunny Goyal | 831212e | 2021-05-14 14:24:09 -0700 | [diff] [blame] | 88 | import android.graphics.RectF; |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 89 | import android.os.Build; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 90 | import android.os.Bundle; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 91 | import android.os.CancellationSignal; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 92 | import android.os.Parcelable; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 93 | import android.os.Process; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 94 | import android.os.StrictMode; |
Riddle Hsu | 979da64 | 2020-09-22 21:52:40 +0800 | [diff] [blame] | 95 | import android.os.SystemClock; |
Schneider Victor-tulias | 927d6dc | 2021-08-26 11:56:47 -0700 | [diff] [blame] | 96 | import android.os.Trace; |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 97 | import android.os.UserHandle; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 98 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 99 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 100 | import android.util.Log; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 101 | import android.util.SparseArray; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 102 | import android.view.KeyEvent; |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 103 | import android.view.KeyboardShortcutGroup; |
| 104 | import android.view.KeyboardShortcutInfo; |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 105 | import android.view.LayoutInflater; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 106 | import android.view.Menu; |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 107 | import android.view.MotionEvent; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 108 | import android.view.View; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 109 | import android.view.ViewGroup; |
Sunny Goyal | 7b8d63f | 2022-04-14 16:37:32 -0700 | [diff] [blame] | 110 | import android.view.ViewTreeObserver.OnPreDrawListener; |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 111 | import android.view.WindowManager.LayoutParams; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 112 | import android.view.accessibility.AccessibilityEvent; |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 113 | import android.view.animation.OvershootInterpolator; |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 114 | import android.widget.ImageView; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 115 | import android.widget.Toast; |
Sunny Goyal | a1d1bf3 | 2015-06-26 13:24:53 -0700 | [diff] [blame] | 116 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 117 | import androidx.annotation.CallSuper; |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 118 | import androidx.annotation.NonNull; |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 119 | import androidx.annotation.Nullable; |
Pinyao Ting | c907427 | 2019-11-11 11:51:44 -0800 | [diff] [blame] | 120 | import androidx.annotation.StringRes; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 121 | import androidx.annotation.VisibleForTesting; |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 122 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 123 | import com.android.launcher3.DropTarget.DragObject; |
Schneider Victor-tulias | bdb0dd8 | 2021-11-03 16:26:41 -0700 | [diff] [blame] | 124 | import com.android.launcher3.accessibility.BaseAccessibilityDelegate.LauncherAction; |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 125 | import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; |
Brian Isganitis | 1664c9f | 2022-01-14 23:15:47 -0500 | [diff] [blame] | 126 | import com.android.launcher3.allapps.ActivityAllAppsContainerView; |
Jon Miranda | f58db15 | 2022-06-02 16:06:37 -0700 | [diff] [blame] | 127 | import com.android.launcher3.allapps.AllAppsRecyclerView; |
vadimt | d4c90e1 | 2019-06-04 13:59:43 -0700 | [diff] [blame] | 128 | import com.android.launcher3.allapps.AllAppsStore; |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 129 | import com.android.launcher3.allapps.AllAppsTransitionController; |
kholoud mohamed | ceec31b | 2022-02-03 15:44:25 +0000 | [diff] [blame] | 130 | import com.android.launcher3.allapps.BaseAllAppsContainerView; |
Sunny Goyal | 7ede611 | 2017-12-05 15:11:21 -0800 | [diff] [blame] | 131 | import com.android.launcher3.allapps.DiscoveryBounce; |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 132 | import com.android.launcher3.anim.PropertyListBuilder; |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 133 | import com.android.launcher3.compat.AccessibilityManagerCompat; |
Tony Wickham | e0c3323 | 2016-02-08 11:37:04 -0800 | [diff] [blame] | 134 | import com.android.launcher3.config.FeatureFlags; |
vadimt | 00d4255 | 2018-12-11 17:59:36 -0800 | [diff] [blame] | 135 | import com.android.launcher3.dot.DotInfo; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 136 | import com.android.launcher3.dragndrop.DragController; |
| 137 | import com.android.launcher3.dragndrop.DragLayer; |
Tony Wickham | 39938cb | 2021-02-26 09:15:31 -0800 | [diff] [blame] | 138 | import com.android.launcher3.dragndrop.DragOptions; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 139 | import com.android.launcher3.dragndrop.DragView; |
Sunny Goyal | 5996937 | 2021-05-06 12:11:44 -0700 | [diff] [blame] | 140 | import com.android.launcher3.dragndrop.LauncherDragController; |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 141 | import com.android.launcher3.folder.FolderGridOrganizer; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 142 | import com.android.launcher3.folder.FolderIcon; |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 143 | import com.android.launcher3.icons.BitmapRenderer; |
Sunny Goyal | f840f10 | 2018-09-21 14:41:05 -0700 | [diff] [blame] | 144 | import com.android.launcher3.icons.IconCache; |
Sunny Goyal | 3333b0c | 2016-05-09 20:43:21 -0700 | [diff] [blame] | 145 | import com.android.launcher3.keyboard.ViewGroupFocusHelper; |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 146 | import com.android.launcher3.logger.LauncherAtom; |
Thiru Ramasamy | 5fbac63 | 2022-01-28 15:05:36 -0800 | [diff] [blame] | 147 | import com.android.launcher3.logger.LauncherAtom.ContainerInfo; |
| 148 | import com.android.launcher3.logger.LauncherAtom.WorkspaceContainer; |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 149 | import com.android.launcher3.logging.FileLog; |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 150 | import com.android.launcher3.logging.InstanceId; |
| 151 | import com.android.launcher3.logging.InstanceIdSequence; |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 152 | import com.android.launcher3.logging.StatsLogManager; |
Sunny Goyal | 87dcde6 | 2019-07-17 20:35:56 -0700 | [diff] [blame] | 153 | import com.android.launcher3.model.BgDataModel.Callbacks; |
Sunny Goyal | 60e68c9 | 2020-08-12 13:59:27 -0700 | [diff] [blame] | 154 | import com.android.launcher3.model.ItemInstallQueue; |
Sunny Goyal | 53116c6 | 2020-08-07 16:32:18 -0700 | [diff] [blame] | 155 | import com.android.launcher3.model.ModelUtils; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 156 | import com.android.launcher3.model.ModelWriter; |
kholoud mohamed | c76b203 | 2021-12-20 16:47:38 +0000 | [diff] [blame] | 157 | import com.android.launcher3.model.StringCache; |
Pinyao Ting | bbb9a9c | 2021-05-11 15:42:54 -0700 | [diff] [blame] | 158 | import com.android.launcher3.model.WidgetsModel; |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 159 | import com.android.launcher3.model.data.AppInfo; |
| 160 | import com.android.launcher3.model.data.FolderInfo; |
| 161 | import com.android.launcher3.model.data.ItemInfo; |
| 162 | import com.android.launcher3.model.data.LauncherAppWidgetInfo; |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 163 | import com.android.launcher3.model.data.WorkspaceItemInfo; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 164 | import com.android.launcher3.notification.NotificationListener; |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 165 | import com.android.launcher3.pm.PinRequestHelper; |
Samuel Fufa | 41d909f | 2020-03-20 16:27:09 -0700 | [diff] [blame] | 166 | import com.android.launcher3.pm.UserCache; |
Brian Isganitis | 149dbcb | 2021-11-08 18:12:38 -0500 | [diff] [blame] | 167 | import com.android.launcher3.popup.ArrowPopup; |
Tony Wickham | 540913e | 2017-01-23 11:47:51 -0800 | [diff] [blame] | 168 | import com.android.launcher3.popup.PopupContainerWithArrow; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 169 | import com.android.launcher3.popup.PopupDataProvider; |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 170 | import com.android.launcher3.popup.SystemShortcut; |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 171 | import com.android.launcher3.qsb.QsbContainerView; |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 172 | import com.android.launcher3.statemanager.StateManager; |
| 173 | import com.android.launcher3.statemanager.StateManager.StateHandler; |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 174 | import com.android.launcher3.statemanager.StatefulActivity; |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 175 | import com.android.launcher3.states.RotationHelper; |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 176 | import com.android.launcher3.testing.TestLogging; |
vadimt | bc5d7e6 | 2019-12-09 13:53:05 -0800 | [diff] [blame] | 177 | import com.android.launcher3.testing.TestProtocol; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 178 | import com.android.launcher3.touch.AllAppsSwipeController; |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 179 | import com.android.launcher3.touch.ItemClickHandler; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 180 | import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 181 | import com.android.launcher3.util.ActivityResultInfo; |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 182 | import com.android.launcher3.util.ActivityTracker; |
Winson Chung | 6b1c73f | 2015-06-18 11:38:42 -0700 | [diff] [blame] | 183 | import com.android.launcher3.util.ComponentKey; |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 184 | import com.android.launcher3.util.IntArray; |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 185 | import com.android.launcher3.util.IntSet; |
Tony Wickham | 133cd54 | 2020-04-08 17:48:41 -0700 | [diff] [blame] | 186 | import com.android.launcher3.util.OnboardingPrefs; |
Sunny Goyal | 04cc3a7 | 2016-05-17 10:32:43 -0700 | [diff] [blame] | 187 | import com.android.launcher3.util.PackageManagerHelper; |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 188 | import com.android.launcher3.util.PackageUserKey; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 189 | import com.android.launcher3.util.PendingRequestArgs; |
Sunny Goyal | 4a48a98 | 2021-06-17 15:15:46 -0700 | [diff] [blame] | 190 | import com.android.launcher3.util.RunnableList; |
Samuel Fufa | 41d909f | 2020-03-20 16:27:09 -0700 | [diff] [blame] | 191 | import com.android.launcher3.util.SafeCloseable; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 192 | import com.android.launcher3.util.SystemUiController; |
Mario Bertschler | a693694 | 2017-05-31 14:48:19 -0700 | [diff] [blame] | 193 | import com.android.launcher3.util.Themes; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 194 | import com.android.launcher3.util.Thunk; |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 195 | import com.android.launcher3.util.TouchController; |
Sunny Goyal | fca6bc9 | 2017-09-28 16:28:34 -0700 | [diff] [blame] | 196 | import com.android.launcher3.util.TraceHelper; |
Sunny Goyal | 326403e | 2017-10-02 12:45:10 -0700 | [diff] [blame] | 197 | import com.android.launcher3.util.UiThreadHelper; |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 198 | import com.android.launcher3.util.ViewOnDrawExecutor; |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 199 | import com.android.launcher3.views.ActivityContext; |
Jon Miranda | f58db15 | 2022-06-02 16:06:37 -0700 | [diff] [blame] | 200 | import com.android.launcher3.views.FloatingIconView; |
Sunny Goyal | 30ac97d | 2020-06-24 23:47:46 -0700 | [diff] [blame] | 201 | import com.android.launcher3.views.FloatingSurfaceView; |
Sunny Goyal | 7c7be8c | 2018-03-07 19:58:07 -0800 | [diff] [blame] | 202 | import com.android.launcher3.views.OptionsPopupView; |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 203 | import com.android.launcher3.views.ScrimView; |
Yogisha Dixit | 741fae9 | 2021-02-22 14:03:44 +0000 | [diff] [blame] | 204 | import com.android.launcher3.widget.LauncherAppWidgetHost; |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 205 | import com.android.launcher3.widget.LauncherAppWidgetHostView; |
Yogisha Dixit | 741fae9 | 2021-02-22 14:03:44 +0000 | [diff] [blame] | 206 | import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 207 | import com.android.launcher3.widget.PendingAddShortcutInfo; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 208 | import com.android.launcher3.widget.PendingAddWidgetInfo; |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 209 | import com.android.launcher3.widget.PendingAppWidgetHostView; |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 210 | import com.android.launcher3.widget.WidgetAddFlowHandler; |
Sunny Goyal | 337c81f | 2019-12-10 12:19:13 -0800 | [diff] [blame] | 211 | import com.android.launcher3.widget.WidgetManagerHelper; |
Pinyao Ting | c7a6c29 | 2019-08-26 14:36:02 -0700 | [diff] [blame] | 212 | import com.android.launcher3.widget.custom.CustomWidgetManager; |
Steven Ng | 2f5648a | 2021-02-08 17:18:25 +0000 | [diff] [blame] | 213 | import com.android.launcher3.widget.model.WidgetsListBaseEntry; |
| 214 | import com.android.launcher3.widget.picker.WidgetsFullSheet; |
Sunny Goyal | 80a071b | 2021-12-27 13:30:08 +0530 | [diff] [blame] | 215 | import com.android.systemui.plugins.LauncherOverlayPlugin; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 216 | import com.android.systemui.plugins.PluginListener; |
| 217 | import com.android.systemui.plugins.shared.LauncherExterns; |
| 218 | import com.android.systemui.plugins.shared.LauncherOverlayManager; |
| 219 | import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay; |
| 220 | import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 221 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 222 | import java.io.FileDescriptor; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 223 | import java.io.PrintWriter; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 224 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 225 | import java.util.Collection; |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 226 | import java.util.Collections; |
Zak Cohen | 658c67a | 2018-10-19 14:21:05 -0700 | [diff] [blame] | 227 | import java.util.HashMap; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 228 | import java.util.HashSet; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 229 | import java.util.List; |
Thiru Ramasamy | 694407c | 2022-03-08 12:11:24 -0800 | [diff] [blame] | 230 | import java.util.Optional; |
Sunny Goyal | aae6fbb | 2019-01-31 16:05:58 -0800 | [diff] [blame] | 231 | import java.util.function.Predicate; |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 232 | import java.util.function.Supplier; |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 233 | import java.util.stream.Stream; |
Jon Miranda | f5197fc | 2019-09-04 16:55:41 -0700 | [diff] [blame] | 234 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 235 | /** |
| 236 | * Default launcher application. |
| 237 | */ |
Shikha Malhotra | 0f2e1b6 | 2022-03-27 21:02:21 +0000 | [diff] [blame] | 238 | public class Launcher extends StatefulActivity<LauncherState> |
| 239 | implements LauncherExterns, Callbacks, InvariantDeviceProfile.OnIDPChangeListener, |
Sunny Goyal | 80a071b | 2021-12-27 13:30:08 +0530 | [diff] [blame] | 240 | PluginListener<LauncherOverlayPlugin>, LauncherOverlayCallbacks { |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 241 | public static final String TAG = "Launcher"; |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 242 | |
| 243 | public static final ActivityTracker<Launcher> ACTIVITY_TRACKER = new ActivityTracker<>(); |
| 244 | |
Sunny Goyal | 2bba4c3 | 2015-05-18 15:42:48 -0700 | [diff] [blame] | 245 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 246 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 247 | static final boolean DEBUG_STRICT_MODE = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 248 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 249 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 250 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 251 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 252 | private static final int REQUEST_PICK_APPWIDGET = 9; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 253 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 254 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 255 | public static final int REQUEST_BIND_PENDING_APPWIDGET = 12; |
| 256 | public static final int REQUEST_RECONFIGURE_APPWIDGET = 13; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 257 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 258 | private static final int REQUEST_PERMISSION_CALL_PHONE = 14; |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 259 | |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 260 | private static final float BOUNCE_ANIMATION_TENSION = 1.3f; |
| 261 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 262 | /** |
| 263 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 264 | * request codes used internally. |
| 265 | */ |
| 266 | protected static final int REQUEST_LAST = 100; |
| 267 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 268 | // Type: int |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 269 | private static final String RUNTIME_STATE = "launcher.state"; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 270 | // Type: PendingRequestArgs |
| 271 | private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args"; |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 272 | // Type: int |
| 273 | private static final String RUNTIME_STATE_PENDING_REQUEST_CODE = "launcher.request_code"; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 274 | // Type: ActivityResultInfo |
| 275 | private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result"; |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 276 | // Type: SparseArray<Parcelable> |
| 277 | private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel"; |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 278 | // Type int[] |
| 279 | private static final String RUNTIME_STATE_CURRENT_SCREEN_IDS = "launcher.current_screen_ids"; |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 280 | |
vadimt | 00d4255 | 2018-12-11 17:59:36 -0800 | [diff] [blame] | 281 | public static final String ON_CREATE_EVT = "Launcher.onCreate"; |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 282 | public static final String ON_START_EVT = "Launcher.onStart"; |
| 283 | public static final String ON_RESUME_EVT = "Launcher.onResume"; |
| 284 | 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] | 285 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 286 | private StateManager<LauncherState> mStateManager; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 287 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 288 | 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] | 289 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 290 | // 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] | 291 | @VisibleForTesting public static final int NEW_APPS_PAGE_MOVE_DELAY = 500; |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 292 | private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Jon Miranda | f5197fc | 2019-09-04 16:55:41 -0700 | [diff] [blame] | 293 | @Thunk @VisibleForTesting public static final int NEW_APPS_ANIMATION_DELAY = 500; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 294 | |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 295 | private static final int THEME_CROSS_FADE_ANIMATION_DURATION = 375; |
| 296 | |
Schneider Victor-tulias | 927d6dc | 2021-08-26 11:56:47 -0700 | [diff] [blame] | 297 | private static final String DISPLAY_WORKSPACE_TRACE_METHOD_NAME = "DisplayWorkspaceFirstFrame"; |
| 298 | private static final String DISPLAY_ALL_APPS_TRACE_METHOD_NAME = "DisplayAllApps"; |
| 299 | public static final int DISPLAY_WORKSPACE_TRACE_COOKIE = 0; |
| 300 | public static final int DISPLAY_ALL_APPS_TRACE_COOKIE = 1; |
| 301 | |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 302 | private Configuration mOldConfig; |
Jon Miranda | 54441f5 | 2018-01-24 15:38:25 -0800 | [diff] [blame] | 303 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 304 | @Thunk |
Shikha Malhotra | 0f2e1b6 | 2022-03-27 21:02:21 +0000 | [diff] [blame] | 305 | Workspace<?> mWorkspace; |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 306 | @Thunk |
| 307 | DragLayer mDragLayer; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 308 | private DragController mDragController; |
Sunny Goyal | 322d556 | 2015-06-25 19:35:49 -0700 | [diff] [blame] | 309 | |
Sunny Goyal | 337c81f | 2019-12-10 12:19:13 -0800 | [diff] [blame] | 310 | private WidgetManagerHelper mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 311 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 312 | |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 313 | private final int[] mTmpAddItemCellCoordinates = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 314 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 315 | @Thunk |
| 316 | Hotseat mHotseat; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 317 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 318 | private DropTargetBar mDropTargetBar; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 319 | |
| 320 | // Main container view for the all apps screen. |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 321 | @Thunk |
Brian Isganitis | 1664c9f | 2022-01-14 23:15:47 -0500 | [diff] [blame] | 322 | ActivityAllAppsContainerView<Launcher> mAppsView; |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 323 | AllAppsTransitionController mAllAppsController; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 324 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 325 | // Scrim view for the all apps and overview state. |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 326 | @Thunk |
| 327 | ScrimView mScrimView; |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 328 | |
Winson Chung | 8ae4198 | 2017-11-10 11:42:13 -0800 | [diff] [blame] | 329 | // UI and state for the overview panel |
Sunny Goyal | 7c7be8c | 2018-03-07 19:58:07 -0800 | [diff] [blame] | 330 | private View mOverviewPanel; |
Winson Chung | 8ae4198 | 2017-11-10 11:42:13 -0800 | [diff] [blame] | 331 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 332 | @Thunk |
| 333 | boolean mWorkspaceLoading = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 334 | |
Winson Chung | c9bf6d4 | 2019-10-04 15:33:18 -0700 | [diff] [blame] | 335 | // Used to notify when an activity launch has been deferred because launcher is not yet resumed |
| 336 | // TODO: See if we can remove this later |
| 337 | private Runnable mOnDeferredActivityLaunchCallback; |
| 338 | |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 339 | private ViewOnDrawExecutor mPendingExecutor; |
Sunny Goyal | 7b8d63f | 2022-04-14 16:37:32 -0700 | [diff] [blame] | 340 | private OnPreDrawListener mOnInitialBindListener; |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 341 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 342 | private LauncherModel mModel; |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 343 | private ModelWriter mModelWriter; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 344 | private IconCache mIconCache; |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 345 | private LauncherAccessibilityDelegate mAccessibilityDelegate; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 346 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 347 | private PopupDataProvider mPopupDataProvider; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 348 | |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 349 | private IntSet mSynchronouslyBoundPages = new IntSet(); |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 350 | @NonNull private IntSet mPagesToBindSynchronously = new IntSet(); |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 351 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 352 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 353 | // it from the context. |
| 354 | private SharedPreferences mSharedPrefs; |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 355 | private OnboardingPrefs<? extends Launcher> mOnboardingPrefs; |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 356 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 357 | // Activity result which needs to be processed after workspace has loaded. |
| 358 | private ActivityResultInfo mPendingActivityResult; |
| 359 | /** |
| 360 | * Holds extra information required to handle a result from an external call, like |
| 361 | * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)} |
| 362 | */ |
| 363 | private PendingRequestArgs mPendingRequestArgs; |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 364 | // Request id for any pending activity result |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 365 | protected int mPendingActivityRequestCode = -1; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 366 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 367 | private ViewGroupFocusHelper mFocusHandler; |
Hyunyoung Song | 7fb3ccc | 2017-10-17 15:39:46 -0700 | [diff] [blame] | 368 | |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 369 | private RotationHelper mRotationHelper; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 370 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 371 | protected LauncherOverlayManager mOverlayManager; |
| 372 | // If true, overlay callbacks are deferred |
| 373 | private boolean mDeferOverlayCallbacks; |
| 374 | private final Runnable mDeferredOverlayCallbacks = this::checkIfOverlayStillDeferred; |
| 375 | |
Riddle Hsu | 979da64 | 2020-09-22 21:52:40 +0800 | [diff] [blame] | 376 | protected long mLastTouchUpTime = -1; |
Sunny Goyal | a306e59 | 2020-03-24 01:51:41 -0700 | [diff] [blame] | 377 | private boolean mTouchInProgress; |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 378 | |
Samuel Fufa | 41d909f | 2020-03-20 16:27:09 -0700 | [diff] [blame] | 379 | private SafeCloseable mUserChangedCallbackCloseable; |
| 380 | |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 381 | // New InstanceId is assigned to mAllAppsSessionLogId for each AllApps sessions. |
| 382 | // When Launcher is not in AllApps state mAllAppsSessionLogId will be null. |
| 383 | // User actions within AllApps state are logged with this InstanceId, to recreate AllApps |
| 384 | // session on the server side. |
| 385 | protected InstanceId mAllAppsSessionLogId; |
| 386 | private LauncherState mPrevLauncherState; |
| 387 | |
kholoud mohamed | c76b203 | 2021-12-20 16:47:38 +0000 | [diff] [blame] | 388 | private StringCache mStringCache; |
| 389 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 390 | @Override |
Schneider Victor-tulias | 927d6dc | 2021-08-26 11:56:47 -0700 | [diff] [blame] | 391 | @TargetApi(Build.VERSION_CODES.S) |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 392 | protected void onCreate(Bundle savedInstanceState) { |
Schneider Victor-tulias | 927d6dc | 2021-08-26 11:56:47 -0700 | [diff] [blame] | 393 | // Only use a hard-coded cookie since we only want to trace this once. |
| 394 | if (Utilities.ATLEAST_S) { |
| 395 | Trace.beginAsyncSection( |
| 396 | DISPLAY_WORKSPACE_TRACE_METHOD_NAME, DISPLAY_WORKSPACE_TRACE_COOKIE); |
| 397 | Trace.beginAsyncSection(DISPLAY_ALL_APPS_TRACE_METHOD_NAME, |
| 398 | DISPLAY_ALL_APPS_TRACE_COOKIE); |
| 399 | } |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 400 | Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT, |
| 401 | TraceHelper.FLAG_UI_EVENT); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 402 | if (DEBUG_STRICT_MODE) { |
| 403 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 404 | .detectDiskReads() |
| 405 | .detectDiskWrites() |
| 406 | .detectNetwork() // or .detectAll() for all detectable problems |
| 407 | .penaltyLog() |
| 408 | .build()); |
| 409 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 410 | .detectLeakedSqlLiteObjects() |
| 411 | .detectLeakedClosableObjects() |
| 412 | .penaltyLog() |
| 413 | .penaltyDeath() |
| 414 | .build()); |
| 415 | } |
| 416 | |
Tony Wickham | e78a70b | 2021-03-29 16:45:59 -0700 | [diff] [blame] | 417 | if (Utilities.IS_DEBUG_DEVICE && FeatureFlags.NOTIFY_CRASHES.get()) { |
| 418 | final String notificationChannelId = "com.android.launcher3.Debug"; |
| 419 | final String notificationChannelName = "Debug"; |
| 420 | final String notificationTag = "Debug"; |
| 421 | final int notificationId = 0; |
| 422 | |
| 423 | NotificationManager notificationManager = getSystemService(NotificationManager.class); |
| 424 | notificationManager.createNotificationChannel(new NotificationChannel( |
| 425 | notificationChannelId, notificationChannelName, |
| 426 | NotificationManager.IMPORTANCE_HIGH)); |
| 427 | |
| 428 | Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> { |
| 429 | String stackTrace = Log.getStackTraceString(throwable); |
| 430 | |
| 431 | Intent shareIntent = new Intent(Intent.ACTION_SEND); |
| 432 | shareIntent.setType("text/plain"); |
| 433 | shareIntent.putExtra(Intent.EXTRA_TEXT, stackTrace); |
| 434 | shareIntent = Intent.createChooser(shareIntent, null); |
| 435 | PendingIntent sharePendingIntent = PendingIntent.getActivity( |
Sunny Goyal | cd2ac0f | 2022-04-14 21:21:47 -0700 | [diff] [blame] | 436 | this, 0, shareIntent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE); |
Tony Wickham | e78a70b | 2021-03-29 16:45:59 -0700 | [diff] [blame] | 437 | |
| 438 | Notification notification = new Notification.Builder(this, notificationChannelId) |
| 439 | .setSmallIcon(android.R.drawable.ic_menu_close_clear_cancel) |
| 440 | .setContentTitle("Launcher crash detected!") |
| 441 | .setStyle(new Notification.BigTextStyle().bigText(stackTrace)) |
| 442 | .addAction(android.R.drawable.ic_menu_share, "Share", sharePendingIntent) |
| 443 | .build(); |
| 444 | notificationManager.notify(notificationTag, notificationId, notification); |
| 445 | |
| 446 | Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = |
| 447 | Thread.getDefaultUncaughtExceptionHandler(); |
| 448 | if (defaultUncaughtExceptionHandler != null) { |
| 449 | defaultUncaughtExceptionHandler.uncaughtException(thread, throwable); |
| 450 | } |
| 451 | }); |
| 452 | } |
| 453 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 454 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 455 | |
Sunny Goyal | 87f784c | 2017-01-11 10:48:34 -0800 | [diff] [blame] | 456 | LauncherAppState app = LauncherAppState.getInstance(this); |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 457 | mOldConfig = new Configuration(getResources().getConfiguration()); |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 458 | mModel = app.getModel(); |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 459 | |
Sunny Goyal | 41d51a0 | 2019-05-14 09:44:34 -0700 | [diff] [blame] | 460 | mRotationHelper = new RotationHelper(this); |
Hyunyoung Song | 31971a3 | 2019-01-27 12:31:12 -0800 | [diff] [blame] | 461 | InvariantDeviceProfile idp = app.getInvariantDeviceProfile(); |
| 462 | initDeviceProfile(idp); |
| 463 | idp.addOnChangeListener(this); |
Sunny Goyal | f725824 | 2015-10-19 16:59:07 -0700 | [diff] [blame] | 464 | mSharedPrefs = Utilities.getPrefs(this); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 465 | mIconCache = app.getIconCache(); |
Sunny Goyal | 384b578 | 2021-02-09 22:50:02 -0800 | [diff] [blame] | 466 | mAccessibilityDelegate = createAccessibilityDelegate(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 467 | |
Sunny Goyal | 5996937 | 2021-05-06 12:11:44 -0700 | [diff] [blame] | 468 | mDragController = new LauncherDragController(this); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 469 | mAllAppsController = new AllAppsTransitionController(this); |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 470 | mStateManager = new StateManager<>(this, NORMAL); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 471 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 472 | mOnboardingPrefs = createOnboardingPrefs(mSharedPrefs); |
Tony Wickham | 133cd54 | 2020-04-08 17:48:41 -0700 | [diff] [blame] | 473 | |
Sunny Goyal | 337c81f | 2019-12-10 12:19:13 -0800 | [diff] [blame] | 474 | mAppWidgetManager = new WidgetManagerHelper(this); |
Cyrus Boadway | 0d309db | 2021-04-14 12:29:14 +0000 | [diff] [blame] | 475 | mAppWidgetHost = createAppWidgetHost(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 476 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 477 | |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 478 | inflateRootView(R.layout.launcher); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 479 | setupViews(); |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 480 | crossFadeWithPreviousAppearance(); |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 481 | mPopupDataProvider = new PopupDataProvider(this::updateNotificationDots); |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 482 | |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 483 | boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this); |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 484 | if (internalStateHandled) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 485 | if (savedInstanceState != null) { |
| 486 | // InternalStateHandler has already set the appropriate state. |
| 487 | // We dont need to do anything. |
| 488 | savedInstanceState.remove(RUNTIME_STATE); |
| 489 | } |
| 490 | } |
| 491 | restoreState(savedInstanceState); |
Sunny Goyal | bbece86 | 2019-03-01 13:13:52 -0800 | [diff] [blame] | 492 | mStateManager.reapplyState(); |
Winson Chung | b63b44c | 2017-11-10 17:54:44 -0800 | [diff] [blame] | 493 | |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 494 | if (savedInstanceState != null) { |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 495 | int[] pageIds = savedInstanceState.getIntArray(RUNTIME_STATE_CURRENT_SCREEN_IDS); |
| 496 | if (pageIds != null) { |
| 497 | mPagesToBindSynchronously = IntSet.wrap(pageIds); |
| 498 | } |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 499 | } |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 500 | |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 501 | if (!mModel.addCallbacksAndLoad(this)) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 502 | if (!internalStateHandled) { |
Sunny Goyal | 7b8d63f | 2022-04-14 16:37:32 -0700 | [diff] [blame] | 503 | Log.d(BAD_STATE, "Launcher onCreate not binding sync, prevent drawing"); |
| 504 | // If we are not binding synchronously, pause drawing until initial bind complete, |
| 505 | // so that the system could continue to show the device loading prompt |
| 506 | mOnInitialBindListener = Boolean.FALSE::booleanValue; |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 507 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | // For handling default keys |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 511 | setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 512 | |
Sunny Goyal | 9d89f75 | 2020-06-19 11:09:24 -0700 | [diff] [blame] | 513 | setContentView(getRootView()); |
Sunny Goyal | 7b8d63f | 2022-04-14 16:37:32 -0700 | [diff] [blame] | 514 | if (mOnInitialBindListener != null) { |
| 515 | getRootView().getViewTreeObserver().addOnPreDrawListener(mOnInitialBindListener); |
| 516 | } |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 517 | getRootView().dispatchInsets(); |
Mario Bertschler | a693694 | 2017-05-31 14:48:19 -0700 | [diff] [blame] | 518 | |
Jon Miranda | 7fda285 | 2017-07-19 16:07:01 -0700 | [diff] [blame] | 519 | // Listen for broadcasts |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 520 | registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); |
Sunny Goyal | a616d2b | 2017-06-12 13:54:01 -0700 | [diff] [blame] | 521 | |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 522 | getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW, |
| 523 | Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText)); |
Sunny Goyal | 14b3240 | 2017-07-31 10:03:28 -0700 | [diff] [blame] | 524 | |
| 525 | if (mLauncherCallbacks != null) { |
| 526 | mLauncherCallbacks.onCreate(savedInstanceState); |
| 527 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 528 | mOverlayManager = getDefaultOverlay(); |
| 529 | PluginManagerWrapper.INSTANCE.get(this).addPluginListener(this, |
Sunny Goyal | 80a071b | 2021-12-27 13:30:08 +0530 | [diff] [blame] | 530 | LauncherOverlayPlugin.class, false /* allowedMultiple */); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 531 | |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 532 | mRotationHelper.initialize(); |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 533 | TraceHelper.INSTANCE.endSection(traceToken); |
Samuel Fufa | 41d909f | 2020-03-20 16:27:09 -0700 | [diff] [blame] | 534 | |
| 535 | mUserChangedCallbackCloseable = UserCache.INSTANCE.get(this).addUserChangeListener( |
| 536 | () -> getStateManager().goToState(NORMAL)); |
Schneider Victor-tulias | 8a35c76 | 2020-09-03 14:30:10 -0700 | [diff] [blame] | 537 | |
| 538 | if (Utilities.ATLEAST_R) { |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 539 | getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_NOTHING); |
Schneider Victor-tulias | 8a35c76 | 2020-09-03 14:30:10 -0700 | [diff] [blame] | 540 | } |
Stefan Andonian | 45fc301 | 2022-05-05 22:48:09 +0000 | [diff] [blame] | 541 | setTitle(R.string.home_screen); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 544 | protected LauncherOverlayManager getDefaultOverlay() { |
| 545 | return new LauncherOverlayManager() { }; |
| 546 | } |
| 547 | |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 548 | protected OnboardingPrefs<? extends Launcher> createOnboardingPrefs( |
| 549 | SharedPreferences sharedPrefs) { |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 550 | return new OnboardingPrefs<>(this, sharedPrefs); |
Tony Wickham | 133cd54 | 2020-04-08 17:48:41 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 553 | public OnboardingPrefs<? extends Launcher> getOnboardingPrefs() { |
Tony Wickham | 133cd54 | 2020-04-08 17:48:41 -0700 | [diff] [blame] | 554 | return mOnboardingPrefs; |
| 555 | } |
| 556 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 557 | @Override |
Sunny Goyal | 80a071b | 2021-12-27 13:30:08 +0530 | [diff] [blame] | 558 | public void onPluginConnected(LauncherOverlayPlugin overlayManager, Context context) { |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 559 | switchOverlay(() -> overlayManager.createOverlayManager(this, this)); |
| 560 | } |
| 561 | |
| 562 | @Override |
Sunny Goyal | 80a071b | 2021-12-27 13:30:08 +0530 | [diff] [blame] | 563 | public void onPluginDisconnected(LauncherOverlayPlugin plugin) { |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 564 | switchOverlay(this::getDefaultOverlay); |
| 565 | } |
| 566 | |
| 567 | private void switchOverlay(Supplier<LauncherOverlayManager> overlaySupplier) { |
| 568 | if (mOverlayManager != null) { |
| 569 | mOverlayManager.onActivityDestroyed(this); |
| 570 | } |
| 571 | mOverlayManager = overlaySupplier.get(); |
| 572 | if (getRootView().isAttachedToWindow()) { |
| 573 | mOverlayManager.onAttachedToWindow(); |
| 574 | } |
| 575 | mDeferOverlayCallbacks = true; |
| 576 | checkIfOverlayStillDeferred(); |
| 577 | } |
| 578 | |
| 579 | @Override |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 580 | public void dispatchDeviceProfileChanged() { |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 581 | super.dispatchDeviceProfileChanged(); |
| 582 | mOverlayManager.onDeviceProvideChanged(); |
| 583 | } |
| 584 | |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 585 | @Override |
Winson Chung | 8eb49e0 | 2018-07-16 13:33:31 -0700 | [diff] [blame] | 586 | public void onEnterAnimationComplete() { |
| 587 | super.onEnterAnimationComplete(); |
Sunny Goyal | be8c340 | 2019-05-22 15:17:52 -0700 | [diff] [blame] | 588 | mRotationHelper.setCurrentTransitionRequest(REQUEST_NONE); |
Sunny Goyal | 5c20fdd | 2022-04-05 20:58:03 -0700 | [diff] [blame] | 589 | // Starting with Android S, onEnterAnimationComplete is sent immediately |
| 590 | // causing the surface to get removed before the animation completed (b/175345344). |
| 591 | // Instead we rely on next user touch event to remove the view and optionally a callback |
| 592 | // from system from Android T onwards. |
| 593 | if (!Utilities.ATLEAST_S) { |
| 594 | AbstractFloatingView.closeOpenViews(this, false, TYPE_ICON_SURFACE); |
| 595 | } |
Winson Chung | 8eb49e0 | 2018-07-16 13:33:31 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | @Override |
Jerry Chang | 09b4024 | 2021-08-27 13:29:01 +0800 | [diff] [blame] | 599 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { |
| 600 | super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
| 601 | // Always update device profile when multi window mode changed. |
| 602 | initDeviceProfile(mDeviceProfile.inv); |
| 603 | dispatchDeviceProfileChanged(); |
| 604 | } |
| 605 | |
| 606 | @Override |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 607 | public void onConfigurationChanged(Configuration newConfig) { |
| 608 | int diff = newConfig.diff(mOldConfig); |
| 609 | if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 610 | onIdpChanged(false); |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | mOldConfig.setTo(newConfig); |
| 614 | super.onConfigurationChanged(newConfig); |
| 615 | } |
| 616 | |
Sunny Goyal | 605bcf3 | 2018-03-02 15:16:12 -0800 | [diff] [blame] | 617 | @Override |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 618 | public void onIdpChanged(boolean modelPropertiesChanged) { |
| 619 | initDeviceProfile(mDeviceProfile.inv); |
Sunny Goyal | 371ea05 | 2019-03-06 15:38:32 -0800 | [diff] [blame] | 620 | dispatchDeviceProfileChanged(); |
| 621 | reapplyUi(); |
| 622 | mDragLayer.recreateControllers(); |
| 623 | |
Sunny Goyal | 76ba0a3 | 2019-06-10 11:56:11 -0700 | [diff] [blame] | 624 | // Calling onSaveInstanceState ensures that static cache used by listWidgets is |
| 625 | // initialized properly. |
| 626 | onSaveInstanceState(new Bundle()); |
Sunny Goyal | c4d3201 | 2020-04-03 17:10:11 -0700 | [diff] [blame] | 627 | mModel.rebindCallbacks(); |
Hyunyoung Song | 31971a3 | 2019-01-27 12:31:12 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 630 | public void onAssistantVisibilityChanged(float visibility) { |
Sunny Goyal | 0b5b8d4 | 2021-03-31 14:56:47 -0700 | [diff] [blame] | 631 | mHotseat.getQsb().setAlpha(1f - visibility); |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 632 | } |
| 633 | |
Bill Lin | a1221bc | 2021-06-03 01:49:27 +0800 | [diff] [blame] | 634 | /** |
| 635 | * Called when one handed mode activated and deactivated. |
| 636 | * @param activated true if one handed mode activated, false otherwise. |
| 637 | */ |
| 638 | public void onOneHandedStateChanged(boolean activated) { |
| 639 | mDragLayer.onOneHandedModeStateChanged(activated); |
| 640 | } |
| 641 | |
Abhilasha Chahal | dfd154f | 2022-02-27 09:58:49 +0000 | [diff] [blame] | 642 | protected void initDeviceProfile(InvariantDeviceProfile idp) { |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 643 | // Load configuration-specific DeviceProfile |
Jerry Chang | bfac46a | 2021-09-08 08:20:58 +0800 | [diff] [blame] | 644 | mDeviceProfile = idp.getDeviceProfile(this); |
| 645 | if (isInMultiWindowMode()) { |
| 646 | mDeviceProfile = mDeviceProfile.getMultiWindowProfile( |
| 647 | this, getMultiWindowDisplaySize()); |
| 648 | } |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 649 | |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 650 | onDeviceProfileInitiated(); |
Sunny Goyal | 711c596 | 2021-06-23 12:36:18 -0700 | [diff] [blame] | 651 | mModelWriter = mModel.getWriter(getDeviceProfile().isVerticalBarLayout(), true, this); |
Sunny Goyal | f8d56fc | 2018-01-31 15:18:11 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 654 | public RotationHelper getRotationHelper() { |
| 655 | return mRotationHelper; |
| 656 | } |
| 657 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 658 | public ViewGroupFocusHelper getFocusHandler() { |
| 659 | return mFocusHandler; |
| 660 | } |
| 661 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 662 | @Override |
| 663 | public StateManager<LauncherState> getStateManager() { |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 664 | return mStateManager; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 667 | private LauncherCallbacks mLauncherCallbacks; |
| 668 | |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 669 | /** |
| 670 | * Call this after onCreate to set or clear overlay. |
| 671 | */ |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 672 | @Override |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 673 | public void setLauncherOverlay(LauncherOverlay overlay) { |
| 674 | if (overlay != null) { |
Lucas Dupin | 87d7520 | 2021-07-28 10:24:54 -0700 | [diff] [blame] | 675 | overlay.setOverlayCallbacks(this); |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 676 | } |
| 677 | mWorkspace.setLauncherOverlay(overlay); |
| 678 | } |
| 679 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 680 | @Override |
| 681 | public void runOnOverlayHidden(Runnable runnable) { |
| 682 | getWorkspace().runOnOverlayHidden(runnable); |
| 683 | } |
| 684 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 685 | public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { |
| 686 | mLauncherCallbacks = callbacks; |
| 687 | return true; |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 690 | public boolean isDraggingEnabled() { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 691 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 692 | // that is subsequently removed from the workspace in startBinding(). |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 693 | return !isWorkspaceLoading(); |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Schneider Victor-tulias | 5173fd8 | 2021-10-19 14:47:23 -0700 | [diff] [blame] | 696 | @NonNull |
| 697 | @Override |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 698 | public PopupDataProvider getPopupDataProvider() { |
| 699 | return mPopupDataProvider; |
| 700 | } |
| 701 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 702 | @Override |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 703 | public DotInfo getDotInfoForItem(ItemInfo info) { |
| 704 | return mPopupDataProvider.getDotInfoForItem(info); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | @Override |
| 708 | public void invalidateParent(ItemInfo info) { |
Jon Miranda | e6f3fa4 | 2019-03-04 09:14:40 -0800 | [diff] [blame] | 709 | if (info.container >= 0) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 710 | View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container); |
Jon Miranda | e6f3fa4 | 2019-03-04 09:14:40 -0800 | [diff] [blame] | 711 | if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) { |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 712 | if (new FolderGridOrganizer(getDeviceProfile().inv) |
| 713 | .setFolderInfo((FolderInfo) folderIcon.getTag()) |
| 714 | .isItemInPreview(info.rank)) { |
Jon Miranda | e6f3fa4 | 2019-03-04 09:14:40 -0800 | [diff] [blame] | 715 | folderIcon.invalidate(); |
| 716 | } |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | } |
| 720 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 721 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 722 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 723 | * a configuration step, this allows the proper animations to run after other transitions. |
| 724 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 725 | private int completeAdd( |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 726 | int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) { |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 727 | int screenId = info.screenId; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 728 | if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 729 | // When the screen id represents an actual screen (as opposed to a rank) we make sure |
| 730 | // that the drop page actually exists. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 731 | screenId = ensurePendingDropLayoutExists(info.screenId); |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 732 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 733 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 734 | switch (requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 735 | case REQUEST_CREATE_SHORTCUT: |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 736 | completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info); |
Pinyao Ting | c907427 | 2019-11-11 11:51:44 -0800 | [diff] [blame] | 737 | announceForAccessibility(R.string.item_added_to_workspace); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 738 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 739 | case REQUEST_CREATE_APPWIDGET: |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 740 | completeAddAppWidget(appWidgetId, info, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 741 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 742 | case REQUEST_RECONFIGURE_APPWIDGET: |
Yogisha Dixit | 4ff5ee3 | 2021-05-04 14:58:34 +0100 | [diff] [blame] | 743 | mStatsLogManager.logger().withItemInfo(info).log(LAUNCHER_WIDGET_RECONFIGURED); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 744 | completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 745 | break; |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 746 | case REQUEST_BIND_PENDING_APPWIDGET: { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 747 | int widgetId = appWidgetId; |
| 748 | LauncherAppWidgetInfo widgetInfo = |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 749 | completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 750 | if (widgetInfo != null) { |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 751 | // Since the view was just bound, also launch the configure activity if needed |
| 752 | LauncherAppWidgetProviderInfo provider = mAppWidgetManager |
| 753 | .getLauncherAppWidgetInfo(widgetId); |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 754 | if (provider != null) { |
| 755 | new WidgetAddFlowHandler(provider) |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 756 | .startConfigActivity(this, widgetInfo, |
| 757 | REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | break; |
| 761 | } |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 762 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 763 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 766 | private void handleActivityResult( |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 767 | final int requestCode, final int resultCode, final Intent data) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 768 | if (isWorkspaceLoading()) { |
| 769 | // process the result once the workspace has loaded. |
| 770 | mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data); |
| 771 | return; |
| 772 | } |
| 773 | mPendingActivityResult = null; |
| 774 | |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 775 | // Reset the startActivity waiting flag |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 776 | final PendingRequestArgs requestArgs = mPendingRequestArgs; |
| 777 | setWaitingForResult(null); |
| 778 | if (requestArgs == null) { |
| 779 | return; |
| 780 | } |
| 781 | |
| 782 | final int pendingAddWidgetId = requestArgs.getWidgetId(); |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 783 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 784 | Runnable exitSpringLoaded = new Runnable() { |
| 785 | @Override |
| 786 | public void run() { |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 787 | mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 788 | } |
| 789 | }; |
| 790 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 791 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Winson | a1f79d3 | 2015-08-05 14:00:45 -0700 | [diff] [blame] | 792 | // 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] | 793 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 794 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 795 | if (resultCode == RESULT_CANCELED) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 796 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs); |
Sunny Goyal | 6e379fc | 2020-03-19 16:08:14 -0700 | [diff] [blame] | 797 | mWorkspace.removeExtraEmptyScreenDelayed( |
| 798 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 799 | } else if (resultCode == RESULT_OK) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 800 | addAppWidgetImpl( |
| 801 | appWidgetId, requestArgs, null, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 802 | requestArgs.getWidgetHandler(), |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 803 | ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 804 | } |
| 805 | return; |
| 806 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 807 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 808 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
Sunny Goyal | 5c97f51 | 2015-05-19 16:03:28 -0700 | [diff] [blame] | 809 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 810 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 811 | // We have special handling for widgets |
| 812 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 813 | final int appWidgetId; |
| 814 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 815 | : -1; |
| 816 | if (widgetId < 0) { |
| 817 | appWidgetId = pendingAddWidgetId; |
| 818 | } else { |
| 819 | appWidgetId = widgetId; |
| 820 | } |
| 821 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 822 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 823 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 824 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 825 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 826 | result = RESULT_CANCELED; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 827 | completeTwoStageWidgetDrop(result, appWidgetId, requestArgs); |
Sunny Goyal | 6e379fc | 2020-03-19 16:08:14 -0700 | [diff] [blame] | 828 | mWorkspace.removeExtraEmptyScreenDelayed( |
| 829 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, |
| 830 | () -> getStateManager().goToState(NORMAL)); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 831 | } else { |
| 832 | if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 833 | // When the screen id represents an actual screen (as opposed to a rank) |
| 834 | // we make sure that the drop page actually exists. |
| 835 | requestArgs.screenId = |
| 836 | ensurePendingDropLayoutExists(requestArgs.screenId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 837 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 838 | final CellLayout dropLayout = |
| 839 | mWorkspace.getScreenWithId(requestArgs.screenId); |
| 840 | |
| 841 | dropLayout.setDropPending(true); |
| 842 | final Runnable onComplete = new Runnable() { |
| 843 | @Override |
| 844 | public void run() { |
| 845 | completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs); |
| 846 | dropLayout.setDropPending(false); |
| 847 | } |
| 848 | }; |
Sunny Goyal | 6e379fc | 2020-03-19 16:08:14 -0700 | [diff] [blame] | 849 | mWorkspace.removeExtraEmptyScreenDelayed( |
| 850 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, onComplete); |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 851 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 852 | return; |
| 853 | } |
| 854 | |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 855 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET |
| 856 | || requestCode == REQUEST_BIND_PENDING_APPWIDGET) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 857 | if (resultCode == RESULT_OK) { |
| 858 | // Update the widget view. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 859 | completeAdd(requestCode, data, pendingAddWidgetId, requestArgs); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 860 | } |
| 861 | // Leave the widget in the pending state if the user canceled the configure. |
| 862 | return; |
| 863 | } |
| 864 | |
Sunny Goyal | aad9058 | 2015-07-09 14:22:50 -0700 | [diff] [blame] | 865 | if (requestCode == REQUEST_CREATE_SHORTCUT) { |
| 866 | // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 867 | if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) { |
| 868 | completeAdd(requestCode, data, -1, requestArgs); |
Sunny Goyal | 6e379fc | 2020-03-19 16:08:14 -0700 | [diff] [blame] | 869 | mWorkspace.removeExtraEmptyScreenDelayed( |
| 870 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 871 | |
Sunny Goyal | aad9058 | 2015-07-09 14:22:50 -0700 | [diff] [blame] | 872 | } else if (resultCode == RESULT_CANCELED) { |
Sunny Goyal | 6e379fc | 2020-03-19 16:08:14 -0700 | [diff] [blame] | 873 | mWorkspace.removeExtraEmptyScreenDelayed( |
| 874 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 875 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 876 | } |
Hongming Jin | d91cb6e | 2020-01-27 16:23:03 -0800 | [diff] [blame] | 877 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 878 | mDragLayer.clearAnimatedView(); |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | @Override |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 882 | public void onActivityResult( |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 883 | final int requestCode, final int resultCode, final Intent data) { |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 884 | mPendingActivityRequestCode = -1; |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 885 | handleActivityResult(requestCode, resultCode, data); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 886 | } |
| 887 | |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 888 | @Override |
Sunny Goyal | dd2e6df | 2015-07-07 10:57:57 -0700 | [diff] [blame] | 889 | public void onRequestPermissionsResult(int requestCode, String[] permissions, |
Dave Hawkey | 3a43ed6 | 2015-06-26 10:27:47 -0600 | [diff] [blame] | 890 | int[] grantResults) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 891 | PendingRequestArgs pendingArgs = mPendingRequestArgs; |
| 892 | if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null |
| 893 | && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) { |
| 894 | setWaitingForResult(null); |
| 895 | |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 896 | View v = null; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 897 | CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 898 | if (layout != null) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 899 | v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 900 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 901 | Intent intent = pendingArgs.getPendingIntent(); |
| 902 | |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 903 | if (grantResults.length > 0 |
| 904 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 905 | startActivitySafely(v, intent, null); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 906 | } else { |
| 907 | // TODO: Show a snack bar with link to settings |
| 908 | Toast.makeText(this, getString(R.string.msg_no_phone_permission, |
Sunny Goyal | 112ce42 | 2016-08-22 16:45:29 -0700 | [diff] [blame] | 909 | getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show(); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
Dave Hawkey | 3a43ed6 | 2015-06-26 10:27:47 -0600 | [diff] [blame] | 912 | } |
| 913 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 914 | /** |
| 915 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 916 | * |
| 917 | * @param screenId the screen id to check |
| 918 | * @return the new screen, or screenId if it exists |
| 919 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 920 | private int ensurePendingDropLayoutExists(int screenId) { |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 921 | CellLayout dropLayout = mWorkspace.getScreenWithId(screenId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 922 | if (dropLayout == null) { |
| 923 | // it's possible that the add screen was removed because it was |
| 924 | // empty and a re-bind occurred |
Andras Kloczl | 408a54f | 2021-08-28 00:59:08 +0100 | [diff] [blame] | 925 | mWorkspace.addExtraEmptyScreens(); |
| 926 | IntSet emptyPagesAdded = mWorkspace.commitExtraEmptyScreens(); |
| 927 | return emptyPagesAdded.isEmpty() ? -1 : emptyPagesAdded.getArray().get(0); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 928 | } |
Andras Kloczl | 408a54f | 2021-08-28 00:59:08 +0100 | [diff] [blame] | 929 | return screenId; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 932 | @Thunk |
| 933 | void completeTwoStageWidgetDrop( |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 934 | final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) { |
| 935 | CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 936 | Runnable onCompleteRunnable = null; |
| 937 | int animationType = 0; |
| 938 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 939 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 940 | if (resultCode == RESULT_OK) { |
| 941 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 942 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 943 | requestArgs.getWidgetHandler().getProviderInfo(this)); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 944 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 945 | onCompleteRunnable = new Runnable() { |
| 946 | @Override |
| 947 | public void run() { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 948 | completeAddAppWidget(appWidgetId, requestArgs, layout, null); |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 949 | mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 950 | } |
| 951 | }; |
| 952 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 953 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 954 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 955 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 956 | if (mDragLayer.getAnimatedView() != null) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 957 | mWorkspace.animateWidgetDrop(requestArgs, cellLayout, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 958 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 959 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 960 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 961 | // The animated view may be null in the case of a rotation during widget configuration |
| 962 | onCompleteRunnable.run(); |
| 963 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 967 | protected void onStop() { |
| 968 | super.onStop(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 969 | if (mDeferOverlayCallbacks) { |
| 970 | checkIfOverlayStillDeferred(); |
| 971 | } else { |
| 972 | mOverlayManager.onActivityStopped(this); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 973 | } |
Hyunyoung Song | 5ee7c13 | 2021-05-11 13:52:36 -0700 | [diff] [blame] | 974 | hideKeyboard(); |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 975 | logStopAndResume(false /* isResume */); |
vadimt | 04ebcf4 | 2021-02-03 15:31:51 -0800 | [diff] [blame] | 976 | mAppWidgetHost.setActivityStarted(false); |
Schneider Victor-tulias | 5173fd8 | 2021-10-19 14:47:23 -0700 | [diff] [blame] | 977 | NotificationListener.removeNotificationsChangedListener(getPopupDataProvider()); |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | @Override |
| 981 | protected void onStart() { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 982 | Object traceToken = TraceHelper.INSTANCE.beginSection(ON_START_EVT, |
| 983 | TraceHelper.FLAG_UI_EVENT); |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 984 | super.onStart(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 985 | if (!mDeferOverlayCallbacks) { |
| 986 | mOverlayManager.onActivityStarted(this); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 987 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 988 | |
vadimt | 04ebcf4 | 2021-02-03 15:31:51 -0800 | [diff] [blame] | 989 | mAppWidgetHost.setActivityStarted(true); |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 990 | TraceHelper.INSTANCE.endSection(traceToken); |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 993 | @Override |
| 994 | @CallSuper |
| 995 | protected void onDeferredResumed() { |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 996 | logStopAndResume(true /* isResume */); |
Sunny Goyal | a002c6c | 2019-02-12 16:20:10 -0800 | [diff] [blame] | 997 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 998 | // Process any items that were added while Launcher was away. |
Sunny Goyal | 60e68c9 | 2020-08-12 13:59:27 -0700 | [diff] [blame] | 999 | ItemInstallQueue.INSTANCE.get(this) |
| 1000 | .resumeModelPush(FLAG_ACTIVITY_PAUSED); |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 1001 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 1002 | // Refresh shortcuts if the permission changed. |
Sunny Goyal | 8b74cc7 | 2020-07-27 17:50:33 -0700 | [diff] [blame] | 1003 | mModel.validateModelDataOnResume(); |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 1004 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 1005 | // Set the notification listener and fetch updated notifications when we resume |
Schneider Victor-tulias | 5173fd8 | 2021-10-19 14:47:23 -0700 | [diff] [blame] | 1006 | NotificationListener.addNotificationsChangedListener(mPopupDataProvider); |
Winson Chung | 8758311 | 2019-06-10 14:20:58 -0700 | [diff] [blame] | 1007 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 1008 | DiscoveryBounce.showForHomeIfNeeded(this); |
vadimt | 04ebcf4 | 2021-02-03 15:31:51 -0800 | [diff] [blame] | 1009 | mAppWidgetHost.setActivityResumed(true); |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 1012 | private void logStopAndResume(boolean isResume) { |
Hyunyoung Song | 77e2977 | 2020-08-25 00:53:48 -0700 | [diff] [blame] | 1013 | if (mPendingExecutor != null) return; |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 1014 | int pageIndex = mWorkspace.isOverlayShown() ? -1 : mWorkspace.getCurrentPage(); |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 1015 | int statsLogOrdinal = mStateManager.getState().statsLogOrdinal; |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 1016 | |
| 1017 | StatsLogManager.EventEnum event; |
| 1018 | StatsLogManager.StatsLogger logger = getStatsLogManager().logger(); |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 1019 | if (isResume) { |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 1020 | logger.withSrcState(LAUNCHER_STATE_BACKGROUND) |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 1021 | .withDstState(mStateManager.getState().statsLogOrdinal); |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 1022 | event = LAUNCHER_ONRESUME; |
| 1023 | } else { /* command == Action.Command.STOP */ |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 1024 | logger.withSrcState(mStateManager.getState().statsLogOrdinal) |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 1025 | .withDstState(LAUNCHER_STATE_BACKGROUND); |
| 1026 | event = LAUNCHER_ONSTOP; |
| 1027 | } |
| 1028 | |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 1029 | if (statsLogOrdinal == LAUNCHER_STATE_HOME && mWorkspace != null) { |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 1030 | logger.withContainerInfo(LauncherAtom.ContainerInfo.newBuilder() |
| 1031 | .setWorkspace( |
| 1032 | LauncherAtom.WorkspaceContainer.newBuilder() |
| 1033 | .setPageIndex(pageIndex)).build()); |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 1034 | } |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 1035 | logger.log(event); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1036 | } |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 1037 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1038 | private void scheduleDeferredCheck() { |
| 1039 | mHandler.removeCallbacks(mDeferredOverlayCallbacks); |
| 1040 | postAsyncCallback(mHandler, mDeferredOverlayCallbacks); |
| 1041 | } |
| 1042 | |
| 1043 | private void checkIfOverlayStillDeferred() { |
| 1044 | if (!mDeferOverlayCallbacks) { |
| 1045 | return; |
| 1046 | } |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 1047 | if (isStarted() && (!hasBeenResumed() |
| 1048 | || mStateManager.getState().hasFlag(FLAG_NON_INTERACTIVE))) { |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1049 | return; |
| 1050 | } |
| 1051 | mDeferOverlayCallbacks = false; |
| 1052 | |
| 1053 | // Move the client to the correct state. Calling the same method twice is no-op. |
| 1054 | if (isStarted()) { |
| 1055 | mOverlayManager.onActivityStarted(this); |
| 1056 | } |
| 1057 | if (hasBeenResumed()) { |
| 1058 | mOverlayManager.onActivityResumed(this); |
| 1059 | } else { |
| 1060 | mOverlayManager.onActivityPaused(this); |
| 1061 | } |
| 1062 | if (!isStarted()) { |
| 1063 | mOverlayManager.onActivityStopped(this); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | public void deferOverlayCallbacksUntilNextResumeOrStop() { |
| 1068 | mDeferOverlayCallbacks = true; |
| 1069 | } |
| 1070 | |
| 1071 | public LauncherOverlayManager getOverlayManager() { |
| 1072 | return mOverlayManager; |
Becky Qiu | bfc2da1 | 2019-08-01 11:09:38 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 1075 | @Override |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 1076 | public void onStateSetStart(LauncherState state) { |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 1077 | super.onStateSetStart(state); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1078 | if (mDeferOverlayCallbacks) { |
| 1079 | scheduleDeferredCheck(); |
Sunny Goyal | e9c6f4c | 2019-05-30 11:35:25 -0700 | [diff] [blame] | 1080 | } |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 1081 | addActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 1082 | |
| 1083 | if (state.hasFlag(FLAG_CLOSE_POPUPS)) { |
| 1084 | AbstractFloatingView.closeAllOpenViews(this, !state.hasFlag(FLAG_NON_INTERACTIVE)); |
| 1085 | } |
| 1086 | |
| 1087 | if (state == SPRING_LOADED) { |
| 1088 | // Prevent any Un/InstallShortcutReceivers from updating the db while we are |
| 1089 | // not on homescreen |
Sunny Goyal | 60e68c9 | 2020-08-12 13:59:27 -0700 | [diff] [blame] | 1090 | ItemInstallQueue.INSTANCE.get(this).pauseModelPush(FLAG_DRAG_AND_DROP); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 1091 | getRotationHelper().setCurrentStateRequest(REQUEST_LOCK); |
| 1092 | |
| 1093 | mWorkspace.showPageIndicatorAtCurrentScroll(); |
| 1094 | mWorkspace.setClipChildren(false); |
| 1095 | } |
| 1096 | // When multiple pages are visible, show persistent page indicator |
| 1097 | mWorkspace.getPageIndicator().setShouldAutoHide(!state.hasFlag(FLAG_MULTI_PAGE)); |
thiruram | 0eabc78 | 2021-04-02 14:30:10 -0700 | [diff] [blame] | 1098 | |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 1099 | mPrevLauncherState = mStateManager.getCurrentStableState(); |
thiruram | 0eabc78 | 2021-04-02 14:30:10 -0700 | [diff] [blame] | 1100 | if (mPrevLauncherState != state && ALL_APPS.equals(state) |
| 1101 | // Making sure mAllAppsSessionLogId is null to avoid double logging. |
| 1102 | && mAllAppsSessionLogId == null) { |
| 1103 | // creates new instance ID since new all apps session is started. |
| 1104 | mAllAppsSessionLogId = new InstanceIdSequence().newInstanceId(); |
Thiru Ramasamy | 694407c | 2022-03-08 12:11:24 -0800 | [diff] [blame] | 1105 | if (getAllAppsEntryEvent().isPresent()) { |
| 1106 | getStatsLogManager().logger() |
| 1107 | .withContainerInfo(ContainerInfo.newBuilder() |
| 1108 | .setWorkspace(WorkspaceContainer.newBuilder() |
| 1109 | .setPageIndex(getWorkspace().getCurrentPage())).build()) |
| 1110 | .log(getAllAppsEntryEvent().get()); |
| 1111 | } |
thiruram | 0eabc78 | 2021-04-02 14:30:10 -0700 | [diff] [blame] | 1112 | } |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Thiru Ramasamy | 5fbac63 | 2022-01-28 15:05:36 -0800 | [diff] [blame] | 1115 | /** |
| 1116 | * Returns {@link EventEnum} that should be logged when Launcher enters into AllApps state. |
| 1117 | */ |
Thiru Ramasamy | 694407c | 2022-03-08 12:11:24 -0800 | [diff] [blame] | 1118 | protected Optional<EventEnum> getAllAppsEntryEvent() { |
| 1119 | return Optional.of(FeatureFlags.ENABLE_DEVICE_SEARCH.get() |
Thiru Ramasamy | 5fbac63 | 2022-01-28 15:05:36 -0800 | [diff] [blame] | 1120 | ? LAUNCHER_ALLAPPS_ENTRY_WITH_DEVICE_SEARCH |
Thiru Ramasamy | 694407c | 2022-03-08 12:11:24 -0800 | [diff] [blame] | 1121 | : LAUNCHER_ALLAPPS_ENTRY); |
Thiru Ramasamy | 5fbac63 | 2022-01-28 15:05:36 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
Sunny Goyal | 35e7d38 | 2020-05-08 13:37:58 -0700 | [diff] [blame] | 1124 | @Override |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 1125 | public void onStateSetEnd(LauncherState state) { |
Sunny Goyal | fee1b25 | 2020-12-14 12:30:38 -0800 | [diff] [blame] | 1126 | super.onStateSetEnd(state); |
vadimt | 04ebcf4 | 2021-02-03 15:31:51 -0800 | [diff] [blame] | 1127 | getAppWidgetHost().setStateIsNormal(state == LauncherState.NORMAL); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 1128 | getWorkspace().setClipChildren(!state.hasFlag(FLAG_MULTI_PAGE)); |
| 1129 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 1130 | finishAutoCancelActionMode(); |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 1131 | removeActivityFlags(ACTIVITY_STATE_TRANSITION_ACTIVE); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 1132 | |
| 1133 | // dispatch window state changed |
| 1134 | getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED); |
| 1135 | AccessibilityManagerCompat.sendStateEventToTest(this, state.ordinal); |
| 1136 | |
| 1137 | if (state == NORMAL) { |
| 1138 | // Re-enable any Un/InstallShortcutReceiver and now process any queued items |
Sunny Goyal | 60e68c9 | 2020-08-12 13:59:27 -0700 | [diff] [blame] | 1139 | ItemInstallQueue.INSTANCE.get(this) |
| 1140 | .resumeModelPush(FLAG_DRAG_AND_DROP); |
Sunny Goyal | 8f96546 | 2020-04-23 19:00:36 -0700 | [diff] [blame] | 1141 | |
| 1142 | // Clear any rotation locks when going to normal state |
| 1143 | getRotationHelper().setCurrentStateRequest(REQUEST_NONE); |
| 1144 | } |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 1145 | |
thiruram | ea56f84 | 2021-06-02 16:02:37 -0700 | [diff] [blame] | 1146 | if (ALL_APPS.equals(mPrevLauncherState) && !ALL_APPS.equals(state) |
thiruram | 0eabc78 | 2021-04-02 14:30:10 -0700 | [diff] [blame] | 1147 | // Making sure mAllAppsSessionLogId is not null to avoid double logging. |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 1148 | && mAllAppsSessionLogId != null) { |
Samuel Fufa | ce820f5 | 2021-06-18 17:23:48 -0500 | [diff] [blame] | 1149 | getAppsView().reset(false); |
Thiru Ramasamy | 694407c | 2022-03-08 12:11:24 -0800 | [diff] [blame] | 1150 | getAllAppsExitEvent().ifPresent(getStatsLogManager().logger()::log); |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 1151 | mAllAppsSessionLogId = null; |
| 1152 | } |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Thiru Ramasamy | 694407c | 2022-03-08 12:11:24 -0800 | [diff] [blame] | 1155 | /** |
| 1156 | * Returns {@link EventEnum} that should be logged when Launcher exists from AllApps state. |
| 1157 | */ |
| 1158 | protected Optional<EventEnum> getAllAppsExitEvent() { |
| 1159 | return Optional.of(LAUNCHER_ALLAPPS_EXIT); |
| 1160 | } |
| 1161 | |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 1162 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1163 | protected void onResume() { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 1164 | Object traceToken = TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT, |
| 1165 | TraceHelper.FLAG_UI_EVENT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1166 | super.onResume(); |
Sunny Goyal | fca6bc9 | 2017-09-28 16:28:34 -0700 | [diff] [blame] | 1167 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1168 | if (mDeferOverlayCallbacks) { |
| 1169 | scheduleDeferredCheck(); |
| 1170 | } else { |
| 1171 | mOverlayManager.onActivityResumed(this); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1172 | } |
Mario Bertschler | 0fc6f68 | 2017-02-17 12:16:13 -0800 | [diff] [blame] | 1173 | |
Stefan Andonian | d123fbd | 2022-04-07 20:04:55 +0000 | [diff] [blame] | 1174 | AbstractFloatingView.closeAllOpenViewsExcept(this, false, TYPE_REBIND_SAFE); |
Jon Miranda | a82a7dc | 2022-05-10 11:48:32 -0700 | [diff] [blame] | 1175 | DragView.removeAllViews(this); |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 1176 | TraceHelper.INSTANCE.endSection(traceToken); |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1179 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1180 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1181 | // Ensure that items added to Launcher are queued until Launcher returns |
Sunny Goyal | 60e68c9 | 2020-08-12 13:59:27 -0700 | [diff] [blame] | 1182 | ItemInstallQueue.INSTANCE.get(this).pauseModelPush(FLAG_ACTIVITY_PAUSED); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1183 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1184 | super.onPause(); |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1185 | mDragController.cancelDrag(); |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 1186 | mLastTouchUpTime = -1; |
Hyunyoung Song | 497708c | 2019-05-01 16:16:53 -0700 | [diff] [blame] | 1187 | mDropTargetBar.animateToVisibility(false); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1188 | |
| 1189 | if (!mDeferOverlayCallbacks) { |
| 1190 | mOverlayManager.onActivityPaused(this); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1191 | } |
vadimt | 04ebcf4 | 2021-02-03 15:31:51 -0800 | [diff] [blame] | 1192 | mAppWidgetHost.setActivityResumed(false); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
Lucas Dupin | 87d7520 | 2021-07-28 10:24:54 -0700 | [diff] [blame] | 1195 | /** |
| 1196 | * {@code LauncherOverlayCallbacks} scroll amount. |
| 1197 | * Indicates transition progress to -1 screen. |
| 1198 | * @param progress From 0 to 1. |
| 1199 | */ |
| 1200 | @Override |
| 1201 | public void onScrollChanged(float progress) { |
| 1202 | if (mWorkspace != null) { |
| 1203 | mWorkspace.onOverlayScrollChanged(progress); |
Sunny Goyal | c86df47 | 2016-02-25 09:19:38 -0800 | [diff] [blame] | 1204 | } |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1207 | /** |
| 1208 | * Restores the previous state, if it exists. |
| 1209 | * |
| 1210 | * @param savedState The previous state. |
| 1211 | */ |
| 1212 | private void restoreState(Bundle savedState) { |
| 1213 | if (savedState == null) { |
| 1214 | return; |
| 1215 | } |
| 1216 | |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1217 | int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal); |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 1218 | LauncherState[] stateValues = LauncherState.values(); |
| 1219 | LauncherState state = stateValues[stateOrdinal]; |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 1220 | |
| 1221 | NonConfigInstance lastInstance = (NonConfigInstance) getLastNonConfigurationInstance(); |
| 1222 | boolean forceRestore = lastInstance != null |
| 1223 | && (lastInstance.config.diff(mOldConfig) & CONFIG_UI_MODE) != 0; |
| 1224 | if (forceRestore || !state.shouldDisableRestore()) { |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1225 | mStateManager.goToState(state, false /* animated */); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1226 | } |
| 1227 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1228 | PendingRequestArgs requestArgs = savedState.getParcelable( |
| 1229 | RUNTIME_STATE_PENDING_REQUEST_ARGS); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1230 | if (requestArgs != null) { |
| 1231 | setWaitingForResult(requestArgs); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1232 | } |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1233 | mPendingActivityRequestCode = savedState.getInt(RUNTIME_STATE_PENDING_REQUEST_CODE); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1234 | |
| 1235 | mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1236 | |
| 1237 | SparseArray<Parcelable> widgetsState = |
| 1238 | savedState.getSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL); |
| 1239 | if (widgetsState != null) { |
| 1240 | WidgetsFullSheet.show(this, false).restoreHierarchyState(widgetsState); |
| 1241 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Finds all the views we need and configure them properly. |
| 1246 | */ |
Tony Wickham | 04fca16 | 2020-02-05 15:06:52 -0800 | [diff] [blame] | 1247 | protected void setupViews() { |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 1248 | mDragLayer = findViewById(R.id.drag_layer); |
Sunny Goyal | 3333b0c | 2016-05-09 20:43:21 -0700 | [diff] [blame] | 1249 | mFocusHandler = mDragLayer.getFocusIndicatorHelper(); |
Sunny Goyal | 966d901 | 2017-06-06 16:43:59 -0700 | [diff] [blame] | 1250 | mWorkspace = mDragLayer.findViewById(R.id.workspace); |
Sunny Goyal | d0a6ae7 | 2016-06-16 12:29:03 -0700 | [diff] [blame] | 1251 | mWorkspace.initParentViews(mDragLayer); |
Sreyas | 321bfae | 2020-02-21 17:53:02 -0800 | [diff] [blame] | 1252 | mOverviewPanel = findViewById(R.id.overview_panel); |
Sunny Goyal | 7c7be8c | 2018-03-07 19:58:07 -0800 | [diff] [blame] | 1253 | mHotseat = findViewById(R.id.hotseat); |
Adam Cohen | b66675a | 2020-05-15 16:16:17 -0700 | [diff] [blame] | 1254 | mHotseat.setWorkspace(mWorkspace); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1255 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1256 | // Setup the drag layer |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1257 | mDragLayer.setup(mDragController, mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1258 | |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1259 | mWorkspace.setup(mDragController); |
Winson | c7d2e83 | 2016-07-28 12:24:55 -0700 | [diff] [blame] | 1260 | // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the |
| 1261 | // default state, otherwise we will update to the wrong offsets in RTL |
| 1262 | mWorkspace.lockWallpaperToDefaultPage(); |
Sunny Goyal | bb03056 | 2021-07-19 16:28:39 -0700 | [diff] [blame] | 1263 | mWorkspace.bindAndInitFirstWorkspaceScreen(); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1264 | mDragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1265 | |
Tony Wickham | 34d2c91 | 2015-09-11 09:27:58 -0700 | [diff] [blame] | 1266 | // Get the search/delete/uninstall bar |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1267 | mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1268 | |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1269 | // Setup Apps |
| 1270 | mAppsView = findViewById(R.id.apps_view); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1271 | |
Govinda Wasserman | c06e151 | 2019-04-09 09:56:53 -0400 | [diff] [blame] | 1272 | // Setup Scrim |
| 1273 | mScrimView = findViewById(R.id.scrim_view); |
| 1274 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1275 | // Setup the drag controller (drop targets have to be added in reverse order in priority) |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 1276 | mDropTargetBar.setup(mDragController); |
Samuel Fufa | acebd1f | 2021-05-06 10:02:03 -0500 | [diff] [blame] | 1277 | mAllAppsController.setupViews(mScrimView, mAppsView); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | /** |
| 1281 | * Creates a view representing a shortcut. |
| 1282 | * |
| 1283 | * @param info The data structure describing the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1284 | */ |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1285 | View createShortcut(WorkspaceItemInfo info) { |
Schneider Victor-tulias | 9f922d3 | 2022-04-27 16:39:29 -0700 | [diff] [blame] | 1286 | // This can be called before PagedView#pageScrollsInitialized returns true, so use the |
| 1287 | // first page, which we always assume to be present. |
| 1288 | return createShortcut((ViewGroup) mWorkspace.getChildAt(0), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /** |
| 1292 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1293 | * |
Schneider Victor-tulias | 9f922d3 | 2022-04-27 16:39:29 -0700 | [diff] [blame] | 1294 | * @param parent The group the shortcut belongs to. This is not necessarily the group where |
| 1295 | * the shortcut should be added. |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1296 | * @param info The data structure describing the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1297 | * @return A View inflated from layoutResId. |
| 1298 | */ |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1299 | public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) { |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 1300 | BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext()) |
| 1301 | .inflate(R.layout.app_icon, parent, false); |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1302 | favorite.applyFromWorkspaceItem(info); |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 1303 | favorite.setOnClickListener(ItemClickHandler.INSTANCE); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1304 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1305 | return favorite; |
| 1306 | } |
| 1307 | |
| 1308 | /** |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1309 | * 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] | 1310 | * |
| 1311 | * @param data The intent describing the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1312 | */ |
sfufa@google.com | d0a3323 | 2021-09-19 15:59:36 -0700 | [diff] [blame] | 1313 | protected void completeAddShortcut(Intent data, int container, int screenId, int cellX, |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 1314 | int cellY, PendingRequestArgs args) { |
Pinyao Ting | 5eee5f4 | 2019-10-31 16:47:35 -0700 | [diff] [blame] | 1315 | if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1316 | || args.getPendingIntent().getComponent() == null) { |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 1317 | return; |
| 1318 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1319 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1320 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1321 | CellLayout layout = getCellLayout(container, screenId); |
| 1322 | |
Sunny Goyal | eaf7a95 | 2020-07-29 16:54:20 -0700 | [diff] [blame] | 1323 | WorkspaceItemInfo info = PinRequestHelper.createWorkspaceItemFromPinItemRequest( |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 1324 | this, PinRequestHelper.getPinItemRequest(data), 0); |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1325 | |
| 1326 | if (info == null) { |
Sunny Goyal | b57645f | 2017-03-20 13:57:28 -0700 | [diff] [blame] | 1327 | // Legacy shortcuts are only supported for primary profile. |
| 1328 | info = Process.myUserHandle().equals(args.user) |
Sunny Goyal | 53116c6 | 2020-08-07 16:32:18 -0700 | [diff] [blame] | 1329 | ? ModelUtils.fromLegacyShortcutIntent(this, data) : null; |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1330 | |
Sunny Goyal | b57645f | 2017-03-20 13:57:28 -0700 | [diff] [blame] | 1331 | if (info == null) { |
| 1332 | Log.e(TAG, "Unable to parse a valid custom shortcut result"); |
| 1333 | return; |
| 1334 | } else if (!new PackageManagerHelper(this).hasPermissionForActivity( |
Sunny Goyal | 342e466 | 2017-02-02 15:21:08 -0800 | [diff] [blame] | 1335 | info.intent, args.getPendingIntent().getComponent().getPackageName())) { |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1336 | // The app is trying to add a shortcut without sufficient permissions |
| 1337 | Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0)); |
| 1338 | return; |
| 1339 | } |
| 1340 | } |
| 1341 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1342 | if (container < 0) { |
| 1343 | // Adding a shortcut to the Workspace. |
| 1344 | final View view = createShortcut(info); |
| 1345 | boolean foundCellSpan = false; |
| 1346 | // First we check if we already know the exact location where we want to add this item. |
| 1347 | if (cellX >= 0 && cellY >= 0) { |
| 1348 | cellXY[0] = cellX; |
| 1349 | cellXY[1] = cellY; |
| 1350 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1351 | |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 1352 | DragObject dragObject = new DragObject(getApplicationContext()); |
| 1353 | dragObject.dragInfo = info; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1354 | // If appropriate, either create a folder or add to an existing folder |
| 1355 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 1356 | true, dragObject)) { |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1357 | return; |
| 1358 | } |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1359 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1360 | true)) { |
| 1361 | return; |
| 1362 | } |
| 1363 | } else { |
| 1364 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
| 1365 | } |
| 1366 | |
| 1367 | if (!foundCellSpan) { |
Yogisha Dixit | 104d09f | 2021-07-19 14:05:17 +0100 | [diff] [blame] | 1368 | mWorkspace.onNoCellFound(layout, info, /* logInstanceId= */ null); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1369 | return; |
| 1370 | } |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1371 | |
| 1372 | getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]); |
| 1373 | mWorkspace.addInScreen(view, info); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1374 | } else { |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1375 | // Adding a shortcut to a Folder. |
Sunny Goyal | e29897f5 | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1376 | FolderIcon folderIcon = findFolderIcon(container); |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1377 | if (folderIcon != null) { |
| 1378 | FolderInfo folderInfo = (FolderInfo) folderIcon.getTag(); |
| 1379 | folderInfo.add(info, args.rank, false); |
| 1380 | } else { |
Sunny Goyal | e29897f5 | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1381 | 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] | 1382 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1383 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1384 | } |
| 1385 | |
Tony Wickham | c7cbf25 | 2021-05-24 15:46:48 -0700 | [diff] [blame] | 1386 | @Override |
| 1387 | public @Nullable FolderIcon findFolderIcon(final int folderIconId) { |
Sunny Goyal | 83fd25e | 2018-07-09 16:47:01 -0700 | [diff] [blame] | 1388 | return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId); |
Sunny Goyal | e29897f5 | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1391 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1392 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1393 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1394 | * @param appWidgetId The app widget id |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1395 | */ |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1396 | @Thunk |
| 1397 | void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1398 | AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) { |
| 1399 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1400 | if (appWidgetInfo == null) { |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1401 | appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1402 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1403 | |
Yogisha Dixit | 0b15c7e | 2021-05-10 12:01:58 +0100 | [diff] [blame] | 1404 | if (hostView == null) { |
| 1405 | // Perform actual inflation because we're live |
| 1406 | hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1407 | } |
| 1408 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1409 | LauncherAppWidgetInfo launcherInfo; |
Yogisha Dixit | 0b15c7e | 2021-05-10 12:01:58 +0100 | [diff] [blame] | 1410 | launcherInfo = |
| 1411 | new LauncherAppWidgetInfo( |
| 1412 | appWidgetId, appWidgetInfo.provider, appWidgetInfo, hostView); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1413 | launcherInfo.spanX = itemInfo.spanX; |
| 1414 | launcherInfo.spanY = itemInfo.spanY; |
| 1415 | launcherInfo.minSpanX = itemInfo.minSpanX; |
| 1416 | launcherInfo.minSpanY = itemInfo.minSpanY; |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 1417 | launcherInfo.user = appWidgetInfo.getProfile(); |
Yogisha Dixit | 658c5da | 2021-05-24 23:23:15 +0100 | [diff] [blame] | 1418 | if (itemInfo instanceof PendingAddWidgetInfo) { |
| 1419 | launcherInfo.sourceContainer = ((PendingAddWidgetInfo) itemInfo).sourceContainer; |
| 1420 | } else if (itemInfo instanceof PendingRequestArgs) { |
| 1421 | launcherInfo.sourceContainer = |
| 1422 | ((PendingRequestArgs) itemInfo).getWidgetSourceContainer(); |
| 1423 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1424 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1425 | getModelWriter().addItemToDatabase(launcherInfo, |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1426 | itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1427 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1428 | hostView.setVisibility(View.VISIBLE); |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 1429 | prepareAppWidget(hostView, launcherInfo); |
| 1430 | mWorkspace.addInScreen(hostView, launcherInfo); |
Pinyao Ting | c907427 | 2019-11-11 11:51:44 -0800 | [diff] [blame] | 1431 | announceForAccessibility(R.string.item_added_to_workspace); |
Yogisha Dixit | 037a536 | 2021-03-22 14:13:03 +0000 | [diff] [blame] | 1432 | |
| 1433 | // Show the widget resize frame. |
| 1434 | if (hostView instanceof LauncherAppWidgetHostView) { |
| 1435 | final LauncherAppWidgetHostView launcherHostView = (LauncherAppWidgetHostView) hostView; |
| 1436 | CellLayout cellLayout = getCellLayout(launcherInfo.container, launcherInfo.screenId); |
| 1437 | if (mStateManager.getState() == NORMAL) { |
Yogisha Dixit | 7b1d25b | 2021-10-14 13:06:40 +0100 | [diff] [blame] | 1438 | AppWidgetResizeFrame.showForWidget(launcherHostView, cellLayout); |
Yogisha Dixit | 037a536 | 2021-03-22 14:13:03 +0000 | [diff] [blame] | 1439 | } else { |
| 1440 | mStateManager.addStateListener(new StateManager.StateListener<LauncherState>() { |
| 1441 | @Override |
| 1442 | public void onStateTransitionComplete(LauncherState finalState) { |
| 1443 | if (mPrevLauncherState == SPRING_LOADED && finalState == NORMAL) { |
| 1444 | AppWidgetResizeFrame.showForWidget(launcherHostView, cellLayout); |
| 1445 | mStateManager.removeStateListener(this); |
| 1446 | } |
| 1447 | } |
| 1448 | }); |
| 1449 | } |
| 1450 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1451 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1452 | |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 1453 | private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) { |
Sunny Goyal | 87af0fd | 2016-05-16 14:56:02 -0700 | [diff] [blame] | 1454 | hostView.setTag(item); |
| 1455 | item.onBindAppWidget(this, hostView); |
Sunny Goyal | 87af0fd | 2016-05-16 14:56:02 -0700 | [diff] [blame] | 1456 | hostView.setFocusable(true); |
| 1457 | hostView.setOnFocusChangeListener(mFocusHandler); |
Sunny Goyal | 25c2e3e | 2015-10-28 23:28:21 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1460 | private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1461 | @Override |
| 1462 | public void onReceive(Context context, Intent intent) { |
Tracy Zhou | f20a4bd | 2021-04-19 21:37:08 -0700 | [diff] [blame] | 1463 | onScreenOff(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1464 | } |
| 1465 | }; |
| 1466 | |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 1467 | private void updateNotificationDots(Predicate<PackageUserKey> updatedDots) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 1468 | mWorkspace.updateNotificationDots(updatedDots); |
| 1469 | mAppsView.getAppsStore().updateNotificationDots(updatedDots); |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1472 | @Override |
| 1473 | public void onAttachedToWindow() { |
| 1474 | super.onAttachedToWindow(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1475 | mOverlayManager.onAttachedToWindow(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | @Override |
| 1479 | public void onDetachedFromWindow() { |
| 1480 | super.onDetachedFromWindow(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1481 | mOverlayManager.onDetachedFromWindow(); |
| 1482 | closeContextMenu(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 1485 | @Override |
| 1486 | public Object onRetainNonConfigurationInstance() { |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 1487 | NonConfigInstance instance = new NonConfigInstance(); |
| 1488 | instance.config = new Configuration(mOldConfig); |
| 1489 | |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 1490 | int width = mDragLayer.getWidth(); |
| 1491 | int height = mDragLayer.getHeight(); |
| 1492 | |
Schneider Victor-tulias | 5aad9d8 | 2020-12-15 10:47:44 -0500 | [diff] [blame] | 1493 | if (FeatureFlags.ENABLE_LAUNCHER_ACTIVITY_THEME_CROSSFADE.get() |
| 1494 | && width > 0 |
| 1495 | && height > 0) { |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 1496 | instance.snapshot = |
| 1497 | BitmapRenderer.createHardwareBitmap(width, height, mDragLayer::draw); |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 1498 | } |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 1499 | return instance; |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Sunny Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame] | 1502 | public AllAppsTransitionController getAllAppsController() { |
| 1503 | return mAllAppsController; |
| 1504 | } |
| 1505 | |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 1506 | @Override |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1507 | public DragLayer getDragLayer() { |
| 1508 | return mDragLayer; |
| 1509 | } |
| 1510 | |
Brian Isganitis | 1664c9f | 2022-01-14 23:15:47 -0500 | [diff] [blame] | 1511 | @Override |
| 1512 | public ActivityAllAppsContainerView<Launcher> getAppsView() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1513 | return mAppsView; |
| 1514 | } |
| 1515 | |
Shikha Malhotra | 0f2e1b6 | 2022-03-27 21:02:21 +0000 | [diff] [blame] | 1516 | public Workspace<?> getWorkspace() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1517 | return mWorkspace; |
| 1518 | } |
| 1519 | |
| 1520 | public Hotseat getHotseat() { |
| 1521 | return mHotseat; |
| 1522 | } |
| 1523 | |
Sunny Goyal | 7c7be8c | 2018-03-07 19:58:07 -0800 | [diff] [blame] | 1524 | public <T extends View> T getOverviewPanel() { |
Winson Chung | 8ae4198 | 2017-11-10 11:42:13 -0800 | [diff] [blame] | 1525 | return (T) mOverviewPanel; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1526 | } |
| 1527 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 1528 | public DropTargetBar getDropTargetBar() { |
| 1529 | return mDropTargetBar; |
Tony Wickham | 34d2c91 | 2015-09-11 09:27:58 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 1532 | @Override |
Tony Wickham | 490a8ab | 2020-04-01 17:03:58 -0700 | [diff] [blame] | 1533 | public ScrimView getScrimView() { |
| 1534 | return mScrimView; |
| 1535 | } |
| 1536 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1537 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1538 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1539 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1540 | |
Cyrus Boadway | 0d309db | 2021-04-14 12:29:14 +0000 | [diff] [blame] | 1541 | protected LauncherAppWidgetHost createAppWidgetHost() { |
| 1542 | return new LauncherAppWidgetHost(this, |
| 1543 | appWidgetId -> getWorkspace().removeWidget(appWidgetId)); |
| 1544 | } |
| 1545 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1546 | public LauncherModel getModel() { |
| 1547 | return mModel; |
| 1548 | } |
| 1549 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1550 | public ModelWriter getModelWriter() { |
| 1551 | return mModelWriter; |
| 1552 | } |
| 1553 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1554 | @Override |
Adam Cohen | 79d90c5 | 2016-04-22 13:29:20 -0700 | [diff] [blame] | 1555 | public SharedPreferences getSharedPrefs() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1556 | return mSharedPrefs; |
| 1557 | } |
| 1558 | |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1559 | @Override |
| 1560 | public SharedPreferences getDevicePrefs() { |
| 1561 | return Utilities.getDevicePrefs(this); |
| 1562 | } |
| 1563 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1564 | public int getOrientation() { |
| 1565 | return mOldConfig.orientation; |
| 1566 | } |
Jon Miranda | 6bed350 | 2017-09-19 14:43:17 -0700 | [diff] [blame] | 1567 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1568 | @Override |
| 1569 | protected void onNewIntent(Intent intent) { |
vadimt | baf5fbb | 2019-12-16 18:56:09 -0800 | [diff] [blame] | 1570 | if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { |
| 1571 | Log.d(TestProtocol.PERMANENT_DIAG_TAG, "Launcher.onNewIntent: " + intent); |
| 1572 | } |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 1573 | Object traceToken = TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1574 | super.onNewIntent(intent); |
| 1575 | |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 1576 | boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() & |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1577 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1578 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Sunny Goyal | 8531373 | 2016-09-28 12:00:07 -0700 | [diff] [blame] | 1579 | |
| 1580 | // Check this condition before handling isActionMain, as this will get reset. |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1581 | boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL) |
Sunny Goyal | f9403d9 | 2017-10-18 10:55:56 -0700 | [diff] [blame] | 1582 | && AbstractFloatingView.getTopOpenView(this) == null; |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1583 | boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction()); |
Winson Chung | 1c2d522 | 2021-06-08 11:50:13 -0700 | [diff] [blame] | 1584 | boolean internalStateHandled = ACTIVITY_TRACKER.handleNewIntent(this); |
Hyunyoung Song | 5ee7c13 | 2021-05-11 13:52:36 -0700 | [diff] [blame] | 1585 | hideKeyboard(); |
kholoud mohamed | ceec31b | 2022-02-03 15:44:25 +0000 | [diff] [blame] | 1586 | |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1587 | if (isActionMain) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1588 | if (!internalStateHandled) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1589 | // In all these cases, only animate if we're already on home |
Andy Wickham | 65ced1b | 2020-03-07 02:14:19 +0000 | [diff] [blame] | 1590 | closeOpenViews(isStarted()); |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 1591 | |
Sunny Goyal | a246727 | 2018-03-16 14:53:05 -0700 | [diff] [blame] | 1592 | if (!isInState(NORMAL)) { |
| 1593 | // Only change state, if not already the same. This prevents cancelling any |
| 1594 | // animations running as part of resume |
Sunny Goyal | fee1b25 | 2020-12-14 12:30:38 -0800 | [diff] [blame] | 1595 | mStateManager.goToState(NORMAL, mStateManager.shouldAnimateStateChange()); |
Sunny Goyal | a246727 | 2018-03-16 14:53:05 -0700 | [diff] [blame] | 1596 | } |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1597 | |
| 1598 | // Reset the apps view |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1599 | if (!alreadyOnHome) { |
Sunny Goyal | 7185dd6 | 2018-03-14 17:51:49 -0700 | [diff] [blame] | 1600 | mAppsView.reset(isStarted() /* animate */); |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1601 | } |
| 1602 | |
Sunny Goyal | aad3359 | 2018-08-07 17:20:35 -0700 | [diff] [blame] | 1603 | if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) { |
Sunny Goyal | d3864fa | 2017-11-14 15:06:36 -0800 | [diff] [blame] | 1604 | mWorkspace.post(mWorkspace::moveToDefaultScreen); |
| 1605 | } |
| 1606 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1607 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1608 | if (mLauncherCallbacks != null) { |
Sunny Goyal | 8546213 | 2018-04-24 11:39:37 -0700 | [diff] [blame] | 1609 | mLauncherCallbacks.onHomeIntent(internalStateHandled); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1610 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1611 | mOverlayManager.hideOverlay(isStarted() && !isForceInvisible()); |
Sunny Goyal | 30ac97d | 2020-06-24 23:47:46 -0700 | [diff] [blame] | 1612 | handleGestureContract(intent); |
Sunny Goyal | 512a2c1 | 2020-04-08 12:52:45 -0700 | [diff] [blame] | 1613 | } else if (Intent.ACTION_ALL_APPS.equals(intent.getAction())) { |
Winson Chung | dd15ace | 2020-08-04 15:52:01 -0700 | [diff] [blame] | 1614 | showAllAppsFromIntent(alreadyOnHome); |
kholoud mohamed | ceec31b | 2022-02-03 15:44:25 +0000 | [diff] [blame] | 1615 | } else if (Intent.ACTION_SHOW_WORK_APPS.equals(intent.getAction())) { |
| 1616 | showAllAppsWorkTabFromIntent(alreadyOnHome); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1617 | } |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1618 | |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 1619 | TraceHelper.INSTANCE.endSection(traceToken); |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
Winson Chung | dd15ace | 2020-08-04 15:52:01 -0700 | [diff] [blame] | 1622 | protected void showAllAppsFromIntent(boolean alreadyOnHome) { |
| 1623 | AbstractFloatingView.closeAllOpenViews(this); |
| 1624 | getStateManager().goToState(ALL_APPS, alreadyOnHome); |
| 1625 | } |
| 1626 | |
kholoud mohamed | ceec31b | 2022-02-03 15:44:25 +0000 | [diff] [blame] | 1627 | private void showAllAppsWorkTabFromIntent(boolean alreadyOnHome) { |
| 1628 | showAllAppsFromIntent(alreadyOnHome); |
| 1629 | mAppsView.switchToTab(BaseAllAppsContainerView.AdapterHolder.WORK); |
| 1630 | } |
| 1631 | |
Sunny Goyal | deb91c4 | 2020-03-24 02:17:59 -0700 | [diff] [blame] | 1632 | /** |
Sunny Goyal | 30ac97d | 2020-06-24 23:47:46 -0700 | [diff] [blame] | 1633 | * Handles gesture nav contract |
| 1634 | */ |
| 1635 | protected void handleGestureContract(Intent intent) { |
| 1636 | GestureNavContract gnc = GestureNavContract.fromIntent(intent); |
| 1637 | if (gnc != null) { |
| 1638 | AbstractFloatingView.closeOpenViews(this, false, TYPE_ICON_SURFACE); |
| 1639 | FloatingSurfaceView.show(this, gnc); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | /** |
Sunny Goyal | deb91c4 | 2020-03-24 02:17:59 -0700 | [diff] [blame] | 1644 | * Hides the keyboard if visible |
| 1645 | */ |
| 1646 | public void hideKeyboard() { |
| 1647 | final View v = getWindow().peekDecorView(); |
| 1648 | if (v != null && v.getWindowToken() != null) { |
| 1649 | UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken()); |
| 1650 | } |
| 1651 | } |
| 1652 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1653 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1654 | public void onRestoreInstanceState(Bundle state) { |
| 1655 | super.onRestoreInstanceState(state); |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 1656 | if (mSynchronouslyBoundPages != null) { |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 1657 | mSynchronouslyBoundPages.forEach(screenId -> { |
| 1658 | int pageIndex = mWorkspace.getPageIndexForScreenId(screenId); |
| 1659 | if (pageIndex != PagedView.INVALID_PAGE) { |
| 1660 | mWorkspace.restoreInstanceStateForChild(pageIndex); |
| 1661 | } |
| 1662 | }); |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 1663 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | @Override |
| 1667 | protected void onSaveInstanceState(Bundle outState) { |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 1668 | outState.putIntArray(RUNTIME_STATE_CURRENT_SCREEN_IDS, |
| 1669 | mWorkspace.getCurrentPageScreenIds().getArray().toArray()); |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 1670 | outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1671 | |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1672 | AbstractFloatingView widgets = AbstractFloatingView |
| 1673 | .getOpenView(this, AbstractFloatingView.TYPE_WIDGETS_FULL_SHEET); |
| 1674 | if (widgets != null) { |
| 1675 | SparseArray<Parcelable> widgetsState = new SparseArray<>(); |
| 1676 | widgets.saveHierarchyState(widgetsState); |
| 1677 | outState.putSparseParcelableArray(RUNTIME_STATE_WIDGET_PANEL, widgetsState); |
| 1678 | } else { |
| 1679 | outState.remove(RUNTIME_STATE_WIDGET_PANEL); |
| 1680 | } |
| 1681 | |
Pinyao Ting | a74b63a | 2019-07-17 23:26:06 -0700 | [diff] [blame] | 1682 | finishAutoCancelActionMode(); |
Tony Wickham | 49c8d29 | 2016-07-01 11:44:34 -0700 | [diff] [blame] | 1683 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1684 | if (mPendingRequestArgs != null) { |
| 1685 | outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs); |
| 1686 | } |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1687 | outState.putInt(RUNTIME_STATE_PENDING_REQUEST_CODE, mPendingActivityRequestCode); |
| 1688 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1689 | if (mPendingActivityResult != null) { |
| 1690 | outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1691 | } |
| 1692 | |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 1693 | super.onSaveInstanceState(outState); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1694 | mOverlayManager.onActivitySaveInstanceState(this, outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | @Override |
| 1698 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1699 | super.onDestroy(); |
Sunny Goyal | e84c5b8 | 2019-09-26 17:05:31 -0700 | [diff] [blame] | 1700 | ACTIVITY_TRACKER.onActivityDestroyed(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1701 | |
Sunny Goyal | 5d1873a | 2018-05-08 11:10:44 -0700 | [diff] [blame] | 1702 | unregisterReceiver(mScreenOffReceiver); |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 1703 | mWorkspace.removeFolderListeners(); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1704 | PluginManagerWrapper.INSTANCE.get(this).removePluginListener(this); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1705 | |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 1706 | mModel.removeCallbacks(this); |
Sunny Goyal | 623eddd | 2018-03-02 12:24:41 -0800 | [diff] [blame] | 1707 | mRotationHelper.destroy(); |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 1708 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1709 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1710 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1711 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1712 | 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] | 1713 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1714 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1715 | TextKeyListener.getInstance().release(); |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 1716 | clearPendingBinds(); |
Hyunyoung Song | 31971a3 | 2019-01-27 12:31:12 -0800 | [diff] [blame] | 1717 | LauncherAppState.getIDP(this).removeOnChangeListener(this); |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 1718 | |
| 1719 | mOverlayManager.onActivityDestroyed(this); |
Samuel Fufa | 41d909f | 2020-03-20 16:27:09 -0700 | [diff] [blame] | 1720 | mUserChangedCallbackCloseable.close(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1721 | } |
| 1722 | |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 1723 | public LauncherAccessibilityDelegate getAccessibilityDelegate() { |
| 1724 | return mAccessibilityDelegate; |
| 1725 | } |
| 1726 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1727 | public DragController getDragController() { |
| 1728 | return mDragController; |
| 1729 | } |
| 1730 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1731 | @Override |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 1732 | public void startActivityForResult(Intent intent, int requestCode, Bundle options) { |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1733 | if (requestCode != -1) { |
| 1734 | mPendingActivityRequestCode = requestCode; |
| 1735 | } |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 1736 | super.startActivityForResult(intent, requestCode, options); |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | @Override |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1740 | public void startIntentSenderForResult(IntentSender intent, int requestCode, |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 1741 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) { |
Sunny Goyal | dedda05 | 2019-05-14 15:23:48 -0700 | [diff] [blame] | 1742 | if (requestCode != -1) { |
| 1743 | mPendingActivityRequestCode = requestCode; |
| 1744 | } |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 1745 | try { |
| 1746 | super.startIntentSenderForResult(intent, requestCode, |
| 1747 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
| 1748 | } catch (IntentSender.SendIntentException e) { |
| 1749 | throw new ActivityNotFoundException(); |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 1750 | } |
| 1751 | } |
| 1752 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1753 | /** |
| 1754 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1755 | * argument for {@link #startSearch} to true. |
| 1756 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1757 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1758 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1759 | Bundle appSearchData, boolean globalSearch) { |
| 1760 | if (appSearchData == null) { |
| 1761 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 1762 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1763 | } |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 1764 | |
Sunny Goyal | 6f28e71 | 2016-09-13 14:19:29 -0700 | [diff] [blame] | 1765 | if (mLauncherCallbacks == null || |
| 1766 | !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) { |
| 1767 | // Starting search from the callbacks failed. Start the default global search. |
Sunny Goyal | f4aceab | 2017-12-06 16:16:31 -0800 | [diff] [blame] | 1768 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, true); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 1769 | } |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 1770 | |
| 1771 | // We need to show the workspace after starting the search |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1772 | mStateManager.goToState(NORMAL); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1773 | } |
| 1774 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1775 | public boolean isWorkspaceLocked() { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1776 | return mWorkspaceLoading || mPendingRequestArgs != null; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1777 | } |
| 1778 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 1779 | public boolean isWorkspaceLoading() { |
| 1780 | return mWorkspaceLoading; |
| 1781 | } |
| 1782 | |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 1783 | @Override |
| 1784 | public boolean isBindingItems() { |
| 1785 | return mWorkspaceLoading; |
| 1786 | } |
| 1787 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1788 | private void setWorkspaceLoading(boolean value) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1789 | mWorkspaceLoading = value; |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1792 | public void setWaitingForResult(PendingRequestArgs args) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1793 | mPendingRequestArgs = args; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1794 | } |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1795 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1796 | void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1797 | WidgetAddFlowHandler addFlowHandler) { |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 1798 | if (LOGD) { |
| 1799 | Log.d(TAG, "Adding widget from drop"); |
| 1800 | } |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1801 | addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1804 | void addAppWidgetImpl(int appWidgetId, ItemInfo info, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1805 | AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) { |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1806 | if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, |
| 1807 | REQUEST_CREATE_APPWIDGET)) { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1808 | // If the configuration flow was not started, add the widget |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1809 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1810 | Runnable onComplete = new Runnable() { |
| 1811 | @Override |
| 1812 | public void run() { |
| 1813 | // Exit spring loaded mode if necessary after adding the widget |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 1814 | mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1815 | } |
| 1816 | }; |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1817 | completeAddAppWidget(appWidgetId, info, boundWidget, |
| 1818 | addFlowHandler.getProviderInfo(this)); |
Sunny Goyal | 6e379fc | 2020-03-19 16:08:14 -0700 | [diff] [blame] | 1819 | mWorkspace.removeExtraEmptyScreenDelayed(delay, false, onComplete); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1820 | } |
| 1821 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1822 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 1823 | public void addPendingItem(PendingAddItemInfo info, int container, int screenId, |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1824 | int[] cell, int spanX, int spanY) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1825 | info.container = container; |
| 1826 | info.screenId = screenId; |
| 1827 | if (cell != null) { |
| 1828 | info.cellX = cell[0]; |
| 1829 | info.cellY = cell[1]; |
| 1830 | } |
| 1831 | info.spanX = spanX; |
| 1832 | info.spanY = spanY; |
| 1833 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1834 | switch (info.itemType) { |
| 1835 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: |
| 1836 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1837 | addAppWidgetFromDrop((PendingAddWidgetInfo) info); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1838 | break; |
| 1839 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1840 | processShortcutFromDrop((PendingAddShortcutInfo) info); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1841 | break; |
| 1842 | default: |
| 1843 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 1844 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 1845 | } |
| 1846 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1847 | /** |
| 1848 | * Process a shortcut drop. |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1849 | */ |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1850 | private void processShortcutFromDrop(PendingAddShortcutInfo info) { |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 1851 | Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName); |
| 1852 | setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info)); |
vadimt | cf275c1 | 2020-04-15 12:43:01 -0700 | [diff] [blame] | 1853 | TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "start: processShortcutFromDrop"); |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1854 | if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) { |
| 1855 | handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null); |
| 1856 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1859 | /** |
| 1860 | * Process a widget drop. |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1861 | */ |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1862 | private void addAppWidgetFromDrop(PendingAddWidgetInfo info) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1863 | AppWidgetHostView hostView = info.boundWidget; |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 1864 | final int appWidgetId; |
Sunny Goyal | 8a0dc38 | 2017-01-25 11:30:06 -0800 | [diff] [blame] | 1865 | WidgetAddFlowHandler addFlowHandler = info.getHandler(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1866 | if (hostView != null) { |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 1867 | // In the case where we've prebound the widget, we remove it from the DragLayer |
| 1868 | if (LOGD) { |
| 1869 | Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null"); |
| 1870 | } |
| 1871 | getDragLayer().removeView(hostView); |
| 1872 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1873 | appWidgetId = hostView.getAppWidgetId(); |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1874 | addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler); |
Sunny Goyal | 5b9ebca | 2015-06-01 18:37:32 -0700 | [diff] [blame] | 1875 | |
| 1876 | // Clear the boundWidget so that it doesn't get destroyed. |
| 1877 | info.boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1878 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1879 | // In this case, we either need to start an activity to get permission to bind |
| 1880 | // 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] | 1881 | if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) { |
| 1882 | appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider( |
| 1883 | info.componentName); |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 1884 | } else { |
| 1885 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
| 1886 | } |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 1887 | Bundle options = info.bindOptions; |
| 1888 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1889 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 1890 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 1891 | if (success) { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1892 | addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 1893 | } else { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1894 | addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 1895 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1896 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
Samuel Fufa | 746d420 | 2020-02-02 18:55:44 -0800 | [diff] [blame] | 1899 | /** |
| 1900 | * Creates and adds new folder to CellLayout |
| 1901 | */ |
Samuel Fufa | 28c3e45 | 2020-02-08 16:07:16 -0800 | [diff] [blame] | 1902 | public FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX, |
| 1903 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1904 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1905 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1906 | // Update the model |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1907 | getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1908 | |
| 1909 | // Create the view |
Samuel Fufa | 746d420 | 2020-02-02 18:55:44 -0800 | [diff] [blame] | 1910 | FolderIcon newFolder = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, this, layout, |
| 1911 | folderInfo); |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 1912 | mWorkspace.addInScreen(newFolder, folderInfo); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 1913 | // Force measure the new folder icon |
| 1914 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 1915 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1916 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1917 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1918 | |
Tony Wickham | 1906cc3 | 2021-02-11 11:55:24 -0800 | [diff] [blame] | 1919 | @Override |
| 1920 | public Rect getFolderBoundingBox() { |
| 1921 | // We need to bound the folder to the currently visible workspace area |
Andras Kloczl | 3a4ba0b | 2021-03-29 18:47:14 +0200 | [diff] [blame] | 1922 | return getWorkspace().getPageAreaRelativeToDragLayer(); |
Tony Wickham | 1906cc3 | 2021-02-11 11:55:24 -0800 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | @Override |
| 1926 | public void updateOpenFolderPosition(int[] inOutPosition, Rect bounds, int width, int height) { |
| 1927 | int left = inOutPosition[0]; |
| 1928 | int top = inOutPosition[1]; |
| 1929 | DeviceProfile grid = getDeviceProfile(); |
| 1930 | int distFromEdgeOfScreen = getWorkspace().getPaddingLeft(); |
| 1931 | if (grid.isPhone && (grid.availableWidthPx - width) < 4 * distFromEdgeOfScreen) { |
| 1932 | // Center the folder if it is very close to being centered anyway, by virtue of |
| 1933 | // filling the majority of the viewport. ie. remove it from the uncanny valley |
| 1934 | // of centeredness. |
| 1935 | left = (grid.availableWidthPx - width) / 2; |
| 1936 | } else if (width >= bounds.width()) { |
| 1937 | // If the folder doesn't fit within the bounds, center it about the desired bounds |
| 1938 | left = bounds.left + (bounds.width() - width) / 2; |
| 1939 | } |
| 1940 | if (height >= bounds.height()) { |
| 1941 | // Folder height is greater than page height, center on page |
| 1942 | top = bounds.top + (bounds.height() - height) / 2; |
| 1943 | } else { |
| 1944 | // Folder height is less than page height, so bound it to the absolute open folder |
| 1945 | // bounds if necessary |
| 1946 | Rect folderBounds = grid.getAbsoluteOpenFolderBounds(); |
| 1947 | left = Math.max(folderBounds.left, Math.min(left, folderBounds.right - width)); |
| 1948 | top = Math.max(folderBounds.top, Math.min(top, folderBounds.bottom - height)); |
| 1949 | } |
| 1950 | inOutPosition[0] = left; |
| 1951 | inOutPosition[1] = top; |
| 1952 | } |
| 1953 | |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1954 | /** |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 1955 | * Unbinds the view for the specified item, and removes the item and all its children. |
| 1956 | * |
| 1957 | * @param v the view being removed. |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 1958 | * @param itemInfo the {@link ItemInfo} for this view. |
| 1959 | * @param deleteFromDb whether or not to delete this item from the db. |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1960 | */ |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 1961 | public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) { |
Pinyao Ting | 6a41d56 | 2022-05-10 23:47:36 +0000 | [diff] [blame] | 1962 | return removeItem(v, itemInfo, deleteFromDb, null); |
| 1963 | } |
| 1964 | |
| 1965 | /** |
| 1966 | * Unbinds the view for the specified item, and removes the item and all its children. |
| 1967 | * |
| 1968 | * @param v the view being removed. |
| 1969 | * @param itemInfo the {@link ItemInfo} for this view. |
| 1970 | * @param deleteFromDb whether or not to delete this item from the db. |
| 1971 | * @param reason the resaon for removal. |
| 1972 | */ |
| 1973 | public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb, |
| 1974 | @Nullable final String reason) { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1975 | if (itemInfo instanceof WorkspaceItemInfo) { |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 1976 | // Remove the shortcut from the folder before removing it from launcher |
Sunny Goyal | 44c0643 | 2016-04-02 10:56:02 -0700 | [diff] [blame] | 1977 | View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container); |
| 1978 | if (folderIcon instanceof FolderIcon) { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 1979 | ((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true); |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 1980 | } else { |
| 1981 | mWorkspace.removeWorkspaceItem(v); |
| 1982 | } |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1983 | if (deleteFromDb) { |
Pinyao Ting | 6a41d56 | 2022-05-10 23:47:36 +0000 | [diff] [blame] | 1984 | getModelWriter().deleteItemFromDatabase(itemInfo, reason); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1985 | } |
| 1986 | } else if (itemInfo instanceof FolderInfo) { |
| 1987 | final FolderInfo folderInfo = (FolderInfo) itemInfo; |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 1988 | if (v instanceof FolderIcon) { |
| 1989 | ((FolderIcon) v).removeListeners(); |
| 1990 | } |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1991 | mWorkspace.removeWorkspaceItem(v); |
| 1992 | if (deleteFromDb) { |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1993 | getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1994 | } |
| 1995 | } else if (itemInfo instanceof LauncherAppWidgetInfo) { |
| 1996 | final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo; |
Winson | 44818e0 | 2015-10-02 11:25:46 -0700 | [diff] [blame] | 1997 | mWorkspace.removeWorkspaceItem(v); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 1998 | if (deleteFromDb) { |
Pinyao Ting | 6a41d56 | 2022-05-10 23:47:36 +0000 | [diff] [blame] | 1999 | getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost(), reason); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2000 | } |
| 2001 | } else { |
| 2002 | return false; |
| 2003 | } |
| 2004 | return true; |
| 2005 | } |
| 2006 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2007 | @Override |
| 2008 | public boolean dispatchKeyEvent(KeyEvent event) { |
vadimt | 6b534ee | 2021-08-06 15:49:02 -0700 | [diff] [blame] | 2009 | TestLogging.recordKeyEvent(TestProtocol.SEQUENCE_MAIN, "Key event", event); |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2010 | return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2011 | } |
| 2012 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2013 | @Override |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 2014 | public boolean dispatchTouchEvent(MotionEvent ev) { |
Sunny Goyal | a306e59 | 2020-03-24 01:51:41 -0700 | [diff] [blame] | 2015 | switch (ev.getAction()) { |
| 2016 | case MotionEvent.ACTION_DOWN: |
| 2017 | mTouchInProgress = true; |
| 2018 | break; |
| 2019 | case MotionEvent.ACTION_UP: |
Riddle Hsu | b30adcb | 2020-10-07 15:57:44 +0800 | [diff] [blame] | 2020 | mLastTouchUpTime = SystemClock.uptimeMillis(); |
Sunny Goyal | a306e59 | 2020-03-24 01:51:41 -0700 | [diff] [blame] | 2021 | // Follow through |
| 2022 | case MotionEvent.ACTION_CANCEL: |
| 2023 | mTouchInProgress = false; |
| 2024 | break; |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 2025 | } |
vadimt | d633c9c | 2020-01-22 18:00:37 -0800 | [diff] [blame] | 2026 | TestLogging.recordMotionEvent(TestProtocol.SEQUENCE_MAIN, "Touch event", ev); |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 2027 | return super.dispatchTouchEvent(ev); |
| 2028 | } |
| 2029 | |
Sunny Goyal | a306e59 | 2020-03-24 01:51:41 -0700 | [diff] [blame] | 2030 | /** |
| 2031 | * Returns true if a touch interaction is in progress |
| 2032 | */ |
| 2033 | public boolean isTouchInProgress() { |
| 2034 | return mTouchInProgress; |
| 2035 | } |
| 2036 | |
vadimt | 9af34a7 | 2020-01-21 11:19:13 -0800 | [diff] [blame] | 2037 | @Override |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2038 | public void onBackPressed() { |
Sunny Goyal | 7c8a65e | 2017-12-22 11:11:33 -0800 | [diff] [blame] | 2039 | if (finishAutoCancelActionMode()) { |
| 2040 | return; |
| 2041 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2042 | |
Sunny Goyal | 4547802 | 2015-06-08 16:52:41 -0700 | [diff] [blame] | 2043 | if (mDragController.isDragging()) { |
| 2044 | mDragController.cancelDrag(); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2045 | return; |
| 2046 | } |
| 2047 | |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 2048 | // Note: There should be at most one log per method call. This is enforced implicitly |
| 2049 | // by using if-else statements. |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 2050 | AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this); |
Sunny Goyal | 3f2637f | 2022-05-05 12:24:08 -0700 | [diff] [blame] | 2051 | if (topView == null || !topView.onBackPressed()) { |
| 2052 | // Not handled by the floating view. |
| 2053 | onStateBack(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2054 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2055 | } |
| 2056 | |
Sunny Goyal | 3f2637f | 2022-05-05 12:24:08 -0700 | [diff] [blame] | 2057 | protected void onStateBack() { |
| 2058 | mStateManager.getState().onBackPressed(this); |
| 2059 | } |
| 2060 | |
Tracy Zhou | f20a4bd | 2021-04-19 21:37:08 -0700 | [diff] [blame] | 2061 | protected void onScreenOff() { |
| 2062 | // Reset AllApps to its initial state only if we are not in the middle of |
| 2063 | // processing a multi-step drop |
| 2064 | if (mPendingRequestArgs == null) { |
| 2065 | if (!isInState(NORMAL)) { |
| 2066 | onUiChangedWhileSleeping(); |
| 2067 | } |
| 2068 | mStateManager.goToState(NORMAL); |
| 2069 | } |
| 2070 | } |
| 2071 | |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 2072 | @TargetApi(Build.VERSION_CODES.M) |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 2073 | @Override |
Brian Isganitis | bde3c8b | 2022-03-15 13:35:06 -0700 | [diff] [blame] | 2074 | public boolean onErrorStartingShortcut(Intent intent, ItemInfo info) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 2075 | // Due to legacy reasons, direct call shortcuts require Launchers to have the |
| 2076 | // corresponding permission. Show the appropriate permission prompt if that |
| 2077 | // is the case. |
| 2078 | if (intent.getComponent() == null |
| 2079 | && Intent.ACTION_CALL.equals(intent.getAction()) |
| 2080 | && checkSelfPermission(android.Manifest.permission.CALL_PHONE) != |
| 2081 | PackageManager.PERMISSION_GRANTED) { |
| 2082 | |
| 2083 | setWaitingForResult(PendingRequestArgs |
| 2084 | .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info)); |
| 2085 | requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE}, |
| 2086 | REQUEST_PERMISSION_CALL_PHONE); |
| 2087 | return true; |
| 2088 | } else { |
| 2089 | return false; |
| 2090 | } |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 2093 | @Override |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 2094 | public boolean startActivitySafely(View v, Intent intent, ItemInfo item) { |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 2095 | if (!hasBeenResumed()) { |
| 2096 | // Workaround an issue where the WM launch animation is clobbered when finishing the |
| 2097 | // recents animation into launcher. Defer launching the activity until Launcher is |
| 2098 | // next resumed. |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 2099 | addOnResumeCallback(() -> startActivitySafely(v, intent, item)); |
Winson Chung | c9bf6d4 | 2019-10-04 15:33:18 -0700 | [diff] [blame] | 2100 | if (mOnDeferredActivityLaunchCallback != null) { |
| 2101 | mOnDeferredActivityLaunchCallback.run(); |
| 2102 | mOnDeferredActivityLaunchCallback = null; |
| 2103 | } |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 2104 | return true; |
| 2105 | } |
| 2106 | |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 2107 | boolean success = super.startActivitySafely(v, intent, item); |
Hyunyoung Song | 1241e61 | 2018-05-15 21:46:51 -0700 | [diff] [blame] | 2108 | if (success && v instanceof BubbleTextView) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 2109 | // This is set to the view that launched the activity that navigated the user away |
| 2110 | // from launcher. Since there is no callback for when the activity has finished |
| 2111 | // launching, enable the press state and keep this reference to reset the press |
| 2112 | // state when we return to launcher. |
| 2113 | BubbleTextView btv = (BubbleTextView) v; |
| 2114 | btv.setStayPressed(true); |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 2115 | addOnResumeCallback(() -> btv.setStayPressed(false)); |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2116 | } |
Hyunyoung Song | 1241e61 | 2018-05-15 21:46:51 -0700 | [diff] [blame] | 2117 | return success; |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2120 | boolean isHotseatLayout(View layout) { |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 2121 | // TODO: Remove this method |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 2122 | return mHotseat != null && (layout == mHotseat); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2123 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2124 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2125 | /** |
| 2126 | * Returns the CellLayout of the specified container at the specified screen. |
| 2127 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2128 | public CellLayout getCellLayout(int container, int screenId) { |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 2129 | return (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) |
| 2130 | ? mHotseat : mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2131 | } |
| 2132 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 2133 | @Override |
| 2134 | public void onTrimMemory(int level) { |
| 2135 | super.onTrimMemory(level); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 2136 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
| 2137 | // The widget preview db can result in holding onto over |
| 2138 | // 3MB of memory for caching which isn't necessary. |
| 2139 | SQLiteDatabase.releaseMemory(); |
| 2140 | |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 2141 | // This clears all widget bitmaps from the widget tray |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 2142 | // TODO(hyunyoungs) |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 2143 | } |
| 2144 | } |
| 2145 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 2146 | @Override |
| 2147 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 2148 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 2149 | final List<CharSequence> text = event.getText(); |
| 2150 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 2151 | // Populate event with a fake title based on the current state. |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 2152 | // TODO: When can workspace be null? |
| 2153 | text.add(mWorkspace == null |
Sunny Goyal | 52e2545 | 2020-07-20 12:38:01 -0700 | [diff] [blame] | 2154 | ? getString(R.string.home_screen) |
Sunny Goyal | ea60926 | 2017-10-25 15:47:38 -0700 | [diff] [blame] | 2155 | : mStateManager.getState().getDescription(this)); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 2156 | return result; |
| 2157 | } |
| 2158 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 2159 | /** |
Winson Chung | c9bf6d4 | 2019-10-04 15:33:18 -0700 | [diff] [blame] | 2160 | * Persistant callback which notifies when an activity launch is deferred because the activity |
| 2161 | * was not yet resumed. |
| 2162 | */ |
| 2163 | public void setOnDeferredActivityLaunchCallback(Runnable callback) { |
| 2164 | mOnDeferredActivityLaunchCallback = callback; |
| 2165 | } |
| 2166 | |
| 2167 | /** |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 2168 | * Sets the next pages to bind synchronously on next bind. |
| 2169 | * @param pages should not be null. |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 2170 | */ |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 2171 | public void setPagesToBindSynchronously(@NonNull IntSet pages) { |
| 2172 | mPagesToBindSynchronously = pages; |
Sunny Goyal | a7a5bf3 | 2020-01-05 15:35:29 +0530 | [diff] [blame] | 2173 | } |
| 2174 | |
Sunny Goyal | 93f878c | 2016-03-30 17:31:24 -0700 | [diff] [blame] | 2175 | @Override |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2176 | public IntSet getPagesToBindSynchronously(IntArray orderedScreenIds) { |
Alex Chau | 4935404 | 2021-08-25 13:21:58 +0100 | [diff] [blame] | 2177 | IntSet visibleIds; |
| 2178 | if (!mPagesToBindSynchronously.isEmpty()) { |
| 2179 | visibleIds = mPagesToBindSynchronously; |
| 2180 | } else if (!mWorkspaceLoading) { |
| 2181 | visibleIds = mWorkspace.getCurrentPageScreenIds(); |
| 2182 | } else { |
| 2183 | // If workspace binding is still in progress, getCurrentPageScreenIds won't be accurate, |
| 2184 | // and we should use mSynchronouslyBoundPages that's set during initial binding. |
| 2185 | visibleIds = mSynchronouslyBoundPages; |
| 2186 | } |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2187 | IntArray actualIds = new IntArray(); |
| 2188 | |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2189 | IntSet result = new IntSet(); |
| 2190 | if (visibleIds.isEmpty()) { |
Schneider Victor-tulias | 0021338 | 2021-09-27 13:41:10 -0700 | [diff] [blame] | 2191 | if (TestProtocol.sDebugTracing) { |
| 2192 | Log.d(TestProtocol.NULL_INT_SET, "getPagesToBindSynchronously (1): " |
| 2193 | + result); |
| 2194 | } |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2195 | return result; |
| 2196 | } |
| 2197 | for (int id : orderedScreenIds.toArray()) { |
Alex Chau | 1e44846 | 2021-08-13 21:48:35 +0100 | [diff] [blame] | 2198 | actualIds.add(id); |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2199 | } |
| 2200 | int firstId = visibleIds.getArray().get(0); |
Steven Ng | 4b34610 | 2021-09-14 19:17:09 +0100 | [diff] [blame] | 2201 | int pairId = mWorkspace.getScreenPair(firstId); |
Alex Chau | 62f129b | 2021-09-03 16:54:27 +0100 | [diff] [blame] | 2202 | // Double check that actual screenIds contains the visibleId, as empty screens are hidden |
| 2203 | // in single panel. |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2204 | if (actualIds.contains(firstId)) { |
| 2205 | result.add(firstId); |
Alex Chau | 62f129b | 2021-09-03 16:54:27 +0100 | [diff] [blame] | 2206 | if (mDeviceProfile.isTwoPanels && actualIds.contains(pairId)) { |
| 2207 | result.add(pairId); |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2208 | } |
Alex Chau | 62f129b | 2021-09-03 16:54:27 +0100 | [diff] [blame] | 2209 | } else if (LauncherAppState.getIDP(this).supportedProfiles.stream().anyMatch( |
| 2210 | deviceProfile -> deviceProfile.isTwoPanels) && actualIds.contains(pairId)) { |
| 2211 | // Add the right panel if left panel is hidden when switching display, due to empty |
| 2212 | // pages being hidden in single panel. |
| 2213 | result.add(pairId); |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2214 | } |
Schneider Victor-tulias | 0021338 | 2021-09-27 13:41:10 -0700 | [diff] [blame] | 2215 | if (TestProtocol.sDebugTracing) { |
| 2216 | Log.d(TestProtocol.NULL_INT_SET, "getPagesToBindSynchronously (2): " |
| 2217 | + result); |
| 2218 | } |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2219 | return result; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2220 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2221 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2222 | /** |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 2223 | * Clear any pending bind callbacks. This is called when is loader is planning to |
| 2224 | * perform a full rebind from scratch. |
| 2225 | */ |
| 2226 | @Override |
| 2227 | public void clearPendingBinds() { |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 2228 | if (mPendingExecutor != null) { |
Sunny Goyal | 4a48a98 | 2021-06-17 15:15:46 -0700 | [diff] [blame] | 2229 | mPendingExecutor.cancel(); |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 2230 | mPendingExecutor = null; |
Sunny Goyal | 6b6d0a3 | 2019-08-05 17:19:32 -0700 | [diff] [blame] | 2231 | |
| 2232 | // We might have set this flag previously and forgot to clear it. |
| 2233 | mAppsView.getAppsStore() |
| 2234 | .disableDeferUpdatesSilently(AllAppsStore.DEFER_UPDATES_NEXT_DRAW); |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2239 | * Refreshes the shortcuts shown on the workspace. |
| 2240 | * |
| 2241 | * Implementation of the method from LauncherModel.Callbacks. |
| 2242 | */ |
| 2243 | public void startBinding() { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2244 | Object traceToken = TraceHelper.INSTANCE.beginSection("startBinding"); |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 2245 | // Floating panels (except the full widget sheet) are associated with individual icons. If |
| 2246 | // we are starting a fresh bind, close all such panels as all the icons are about |
| 2247 | // to go away. |
Pinyao Ting | a74b63a | 2019-07-17 23:26:06 -0700 | [diff] [blame] | 2248 | AbstractFloatingView.closeOpenViews(this, true, TYPE_ALL & ~TYPE_REBIND_SAFE); |
Jon Miranda | 6dc7f1e | 2017-02-21 12:37:51 -0800 | [diff] [blame] | 2249 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2250 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2251 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2252 | // Clear the workspace because it's going to be rebound |
Sunny Goyal | 2db5342 | 2019-03-01 16:06:12 -0800 | [diff] [blame] | 2253 | mDragController.cancelDrag(); |
| 2254 | |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2255 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 2256 | mWorkspace.removeAllWorkspaceScreens(); |
Sunny Goyal | c11fac3 | 2018-02-27 19:20:15 -0800 | [diff] [blame] | 2257 | mAppWidgetHost.clearViews(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2258 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2259 | if (mHotseat != null) { |
Sunny Goyal | c4d3201 | 2020-04-03 17:10:11 -0700 | [diff] [blame] | 2260 | mHotseat.resetLayout(getDeviceProfile().isVerticalBarLayout()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2261 | } |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2262 | TraceHelper.INSTANCE.endSection(traceToken); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2263 | } |
| 2264 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2265 | @Override |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2266 | public void bindScreens(IntArray orderedScreenIds) { |
Alex Chau | 1e44846 | 2021-08-13 21:48:35 +0100 | [diff] [blame] | 2267 | int firstScreenPosition = 0; |
Jon Miranda | 7143ba6 | 2019-03-15 09:00:05 -0700 | [diff] [blame] | 2268 | if (FeatureFlags.QSB_ON_FIRST_SCREEN && |
Andras Kloczl | dbf577a | 2021-05-26 15:02:52 +0200 | [diff] [blame] | 2269 | orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != firstScreenPosition) { |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2270 | orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID); |
Andras Kloczl | dbf577a | 2021-05-26 15:02:52 +0200 | [diff] [blame] | 2271 | orderedScreenIds.add(firstScreenPosition, Workspace.FIRST_SCREEN_ID); |
Jon Miranda | 7143ba6 | 2019-03-15 09:00:05 -0700 | [diff] [blame] | 2272 | } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) { |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 2273 | // If there are no screens, we need to have an empty screen |
Andras Kloczl | 408a54f | 2021-08-28 00:59:08 +0100 | [diff] [blame] | 2274 | mWorkspace.addExtraEmptyScreens(); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 2275 | } |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2276 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 2277 | |
Winson | c7d2e83 | 2016-07-28 12:24:55 -0700 | [diff] [blame] | 2278 | // After we have added all the screens, if the wallpaper was locked to the default state, |
| 2279 | // then notify to indicate that it can be released and a proper wallpaper offset can be |
| 2280 | // computed before the next layout |
| 2281 | mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout(); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2284 | private void bindAddScreens(IntArray orderedScreenIds) { |
Andras Kloczl | 8c574de | 2021-08-17 23:12:17 +0200 | [diff] [blame] | 2285 | if (mDeviceProfile.isTwoPanels) { |
| 2286 | // Some empty pages might have been removed while the phone was in a single panel |
| 2287 | // mode, so we want to add those empty pages back. |
| 2288 | IntSet screenIds = IntSet.wrap(orderedScreenIds); |
Steven Ng | 4b34610 | 2021-09-14 19:17:09 +0100 | [diff] [blame] | 2289 | orderedScreenIds.forEach(screenId -> screenIds.add(mWorkspace.getScreenPair(screenId))); |
Andras Kloczl | 8c574de | 2021-08-17 23:12:17 +0200 | [diff] [blame] | 2290 | orderedScreenIds = screenIds.getArray(); |
| 2291 | } |
| 2292 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2293 | int count = orderedScreenIds.size(); |
| 2294 | for (int i = 0; i < count; i++) { |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2295 | int screenId = orderedScreenIds.get(i); |
Andras Kloczl | dbf577a | 2021-05-26 15:02:52 +0200 | [diff] [blame] | 2296 | if (FeatureFlags.QSB_ON_FIRST_SCREEN && screenId == Workspace.FIRST_SCREEN_ID) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2297 | // No need to bind the first screen, as its always bound. |
Andras Kloczl | dbf577a | 2021-05-26 15:02:52 +0200 | [diff] [blame] | 2298 | continue; |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2299 | } |
Andras Kloczl | dbf577a | 2021-05-26 15:02:52 +0200 | [diff] [blame] | 2300 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2301 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2304 | @Override |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 2305 | public void preAddApps() { |
| 2306 | // If there's an undo snackbar, force it to complete to ensure empty screens are removed |
| 2307 | // before trying to add new items. |
| 2308 | mModelWriter.commitDelete(); |
| 2309 | AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR); |
| 2310 | if (snackbar != null) { |
| 2311 | snackbar.post(() -> snackbar.close(true)); |
| 2312 | } |
| 2313 | } |
| 2314 | |
| 2315 | @Override |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2316 | public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated, |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2317 | ArrayList<ItemInfo> addAnimated) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2318 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 2319 | if (newScreens != null) { |
Alex Chau | 817e0fa | 2021-09-08 20:46:32 +0100 | [diff] [blame] | 2320 | // newScreens can contain an empty right panel that is already bound, but not known |
| 2321 | // by BgDataModel. |
| 2322 | newScreens.removeAllValues(mWorkspace.mScreenOrder); |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 2323 | bindAddScreens(newScreens); |
| 2324 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2325 | |
| 2326 | // We add the items without animation on non-visible pages, and with |
| 2327 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 2328 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2329 | bindItems(addNotAnimated, false); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2330 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 2331 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2332 | bindItems(addAnimated, true); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2333 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 2334 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 2335 | // Remove the extra empty screen |
Sunny Goyal | 6e379fc | 2020-03-19 16:08:14 -0700 | [diff] [blame] | 2336 | mWorkspace.removeExtraEmptyScreen(false); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2339 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2340 | * Bind the items start-end from the list. |
| 2341 | * |
| 2342 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2343 | */ |
Tony Wickham | 0bb211a | 2015-10-02 16:22:08 -0700 | [diff] [blame] | 2344 | @Override |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2345 | public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) { |
Schneider Victor-tulias | 68706eb | 2021-04-29 15:24:54 -0700 | [diff] [blame] | 2346 | bindItems(items, forceAnimateIcons, /* focusFirstItemForAccessibility= */ false); |
| 2347 | } |
| 2348 | |
| 2349 | |
| 2350 | /** |
| 2351 | * Bind the items start-end from the list. |
| 2352 | * |
| 2353 | * Implementation of the method from LauncherModel.Callbacks. |
| 2354 | * |
| 2355 | * @param focusFirstItemForAccessibility true iff the first item to be added to the workspace |
| 2356 | * should be focused for accessibility. |
| 2357 | */ |
| 2358 | public void bindItems( |
| 2359 | final List<ItemInfo> items, |
| 2360 | final boolean forceAnimateIcons, |
| 2361 | final boolean focusFirstItemForAccessibility) { |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2362 | // 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] | 2363 | final Collection<Animator> bounceAnims = new ArrayList<>(); |
Schneider Victor-tulias | 68fb416 | 2021-09-16 13:24:01 -0700 | [diff] [blame] | 2364 | boolean canAnimatePageChange = canAnimatePageChange(); |
Shikha Malhotra | f78da1b | 2022-04-11 10:23:18 +0000 | [diff] [blame] | 2365 | Workspace<?> workspace = mWorkspace; |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2366 | int newItemsScreenId = -1; |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2367 | int end = items.size(); |
Schneider Victor-tulias | 68706eb | 2021-04-29 15:24:54 -0700 | [diff] [blame] | 2368 | View newView = null; |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2369 | for (int i = 0; i < end; i++) { |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2370 | final ItemInfo item = items.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 2371 | |
| 2372 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 2373 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 2374 | mHotseat == null) { |
| 2375 | continue; |
| 2376 | } |
| 2377 | |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2378 | final View view; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2379 | switch (item.itemType) { |
| 2380 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 2381 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2382 | case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 2383 | WorkspaceItemInfo info = (WorkspaceItemInfo) item; |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2384 | view = createShortcut(info); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2385 | break; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2386 | } |
| 2387 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: { |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 2388 | view = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2389 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Sunny Goyal | 1cd01b0 | 2016-11-09 10:43:58 -0800 | [diff] [blame] | 2390 | (FolderInfo) item); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2391 | break; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2392 | } |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 2393 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
| 2394 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: { |
Sunny Goyal | a9a1a21 | 2017-08-18 01:03:21 -0700 | [diff] [blame] | 2395 | view = inflateAppWidget((LauncherAppWidgetInfo) item); |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2396 | if (view == null) { |
| 2397 | continue; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2398 | } |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2399 | break; |
| 2400 | } |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 2401 | default: |
| 2402 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2403 | } |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2404 | |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 2405 | /* |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2406 | * Remove colliding items. |
| 2407 | */ |
| 2408 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 2409 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 2410 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
| 2411 | View v = cl.getChildAt(item.cellX, item.cellY); |
Jon Miranda | 0aff115 | 2021-11-05 16:36:07 -0700 | [diff] [blame] | 2412 | if (v == null) { |
| 2413 | Log.e(TAG, "bindItems failed when removing colliding item=" + item); |
| 2414 | } |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2415 | Object tag = v.getTag(); |
| 2416 | String desc = "Collision while binding workspace item: " + item |
| 2417 | + ". Collides with " + tag; |
Zak Cohen | 3eeb41d | 2020-02-14 14:15:13 -0800 | [diff] [blame] | 2418 | if (FeatureFlags.IS_STUDIO_BUILD) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2419 | throw (new RuntimeException(desc)); |
| 2420 | } else { |
Pinyao Ting | 6a41d56 | 2022-05-10 23:47:36 +0000 | [diff] [blame] | 2421 | getModelWriter().deleteItemFromDatabase(item, desc); |
Jon Miranda | 701774d | 2022-02-10 11:09:04 -0800 | [diff] [blame] | 2422 | if (TestProtocol.sDebugTracing) { |
| 2423 | Log.d(TestProtocol.MISSING_PROMISE_ICON, |
| 2424 | TAG + "bindItems failed for item=" + item); |
| 2425 | } |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 2426 | continue; |
| 2427 | } |
| 2428 | } |
| 2429 | } |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 2430 | workspace.addInScreenFromBind(view, item); |
Schneider Victor-tulias | 68fb416 | 2021-09-16 13:24:01 -0700 | [diff] [blame] | 2431 | if (forceAnimateIcons) { |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2432 | // Animate all the applications up now |
| 2433 | view.setAlpha(0f); |
| 2434 | view.setScaleX(0f); |
| 2435 | view.setScaleY(0f); |
| 2436 | bounceAnims.add(createNewAppBounceAnimation(view, i)); |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 2437 | newItemsScreenId = item.screenId; |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 2438 | } |
Schneider Victor-tulias | 68706eb | 2021-04-29 15:24:54 -0700 | [diff] [blame] | 2439 | |
| 2440 | if (newView == null) { |
| 2441 | newView = view; |
| 2442 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2443 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2444 | |
Schneider Victor-tulias | 68706eb | 2021-04-29 15:24:54 -0700 | [diff] [blame] | 2445 | View viewToFocus = newView; |
| 2446 | // Animate to the correct pager |
Schneider Victor-tulias | 68fb416 | 2021-09-16 13:24:01 -0700 | [diff] [blame] | 2447 | if (forceAnimateIcons && newItemsScreenId > -1) { |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2448 | AnimatorSet anim = new AnimatorSet(); |
| 2449 | anim.playTogether(bounceAnims); |
Schneider Victor-tulias | 68706eb | 2021-04-29 15:24:54 -0700 | [diff] [blame] | 2450 | if (focusFirstItemForAccessibility && viewToFocus != null) { |
| 2451 | anim.addListener(new AnimatorListenerAdapter() { |
| 2452 | @Override |
| 2453 | public void onAnimationEnd(Animator animation) { |
| 2454 | viewToFocus.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 2455 | } |
| 2456 | }); |
| 2457 | } |
Jon Miranda | 64eb8ea | 2018-03-29 11:43:58 -0700 | [diff] [blame] | 2458 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 2459 | int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2460 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId); |
| 2461 | final Runnable startBounceAnimRunnable = anim::start; |
| 2462 | |
Schneider Victor-tulias | 68fb416 | 2021-09-16 13:24:01 -0700 | [diff] [blame] | 2463 | if (canAnimatePageChange && newItemsScreenId != currentScreenId) { |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2464 | // We post the animation slightly delayed to prevent slowdowns |
| 2465 | // when we are loading right after we return to launcher. |
| 2466 | mWorkspace.postDelayed(new Runnable() { |
| 2467 | public void run() { |
| 2468 | if (mWorkspace != null) { |
Andy Wickham | 65ced1b | 2020-03-07 02:14:19 +0000 | [diff] [blame] | 2469 | closeOpenViews(false); |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2470 | |
| 2471 | mWorkspace.snapToPage(newScreenIndex); |
| 2472 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 2473 | NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 2474 | } |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2475 | } |
| 2476 | }, NEW_APPS_PAGE_MOVE_DELAY); |
| 2477 | } else { |
| 2478 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 2479 | } |
Schneider Victor-tulias | 68706eb | 2021-04-29 15:24:54 -0700 | [diff] [blame] | 2480 | } else if (focusFirstItemForAccessibility && viewToFocus != null) { |
| 2481 | viewToFocus.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 2482 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2483 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2484 | } |
| 2485 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2486 | /** |
| 2487 | * Add the views for a widget to the workspace. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2488 | */ |
Sunny Goyal | a9a1a21 | 2017-08-18 01:03:21 -0700 | [diff] [blame] | 2489 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
| 2490 | View view = inflateAppWidget(item); |
| 2491 | if (view != null) { |
| 2492 | mWorkspace.addInScreen(view, item); |
| 2493 | mWorkspace.requestLayout(); |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | private View inflateAppWidget(LauncherAppWidgetInfo item) { |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 2498 | if (item.hasOptionFlag(LauncherAppWidgetInfo.OPTION_SEARCH_WIDGET)) { |
| 2499 | item.providerName = QsbContainerView.getSearchComponentName(this); |
| 2500 | if (item.providerName == null) { |
Pinyao Ting | 6a41d56 | 2022-05-10 23:47:36 +0000 | [diff] [blame] | 2501 | getModelWriter().deleteItemFromDatabase(item, |
| 2502 | "search widget removed because search component cannot be found"); |
Samuel Fufa | ca37b8a | 2019-08-19 17:04:36 -0700 | [diff] [blame] | 2503 | return null; |
| 2504 | } |
| 2505 | } |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2506 | final AppWidgetHostView view; |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 2507 | if (mIsSafeModeEnabled) { |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2508 | view = new PendingAppWidgetHostView(this, item, mIconCache, true); |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 2509 | prepareAppWidget(view, item); |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2510 | return view; |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 2511 | } |
| 2512 | |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2513 | Object traceToken = TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2514 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2515 | try { |
| 2516 | final LauncherAppWidgetProviderInfo appWidgetInfo; |
Steven Ng | acd9d79 | 2021-06-25 11:51:44 +0100 | [diff] [blame] | 2517 | String removalReason = ""; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2518 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2519 | if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) { |
| 2520 | // If the provider is not ready, bind as a pending widget. |
| 2521 | appWidgetInfo = null; |
Steven Ng | acd9d79 | 2021-06-25 11:51:44 +0100 | [diff] [blame] | 2522 | removalReason = "the provider isn't ready."; |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2523 | } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { |
| 2524 | // The widget id is not valid. Try to find the widget based on the provider info. |
| 2525 | appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user); |
Pinyao Ting | bbb9a9c | 2021-05-11 15:42:54 -0700 | [diff] [blame] | 2526 | if (appWidgetInfo == null) { |
| 2527 | if (WidgetsModel.GO_DISABLE_WIDGETS) { |
Steven Ng | acd9d79 | 2021-06-25 11:51:44 +0100 | [diff] [blame] | 2528 | removalReason = "widgets are disabled on go device."; |
Pinyao Ting | bbb9a9c | 2021-05-11 15:42:54 -0700 | [diff] [blame] | 2529 | } else { |
Steven Ng | acd9d79 | 2021-06-25 11:51:44 +0100 | [diff] [blame] | 2530 | removalReason = |
| 2531 | "WidgetManagerHelper cannot find a provider from provider info."; |
Pinyao Ting | bbb9a9c | 2021-05-11 15:42:54 -0700 | [diff] [blame] | 2532 | } |
| 2533 | } |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2534 | } else { |
| 2535 | appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId); |
Pinyao Ting | bbb9a9c | 2021-05-11 15:42:54 -0700 | [diff] [blame] | 2536 | if (appWidgetInfo == null) { |
| 2537 | if (item.appWidgetId <= LauncherAppWidgetInfo.CUSTOM_WIDGET_ID) { |
Steven Ng | acd9d79 | 2021-06-25 11:51:44 +0100 | [diff] [blame] | 2538 | removalReason = |
| 2539 | "CustomWidgetManager cannot find provider from that widget id."; |
Pinyao Ting | bbb9a9c | 2021-05-11 15:42:54 -0700 | [diff] [blame] | 2540 | } else { |
Steven Ng | acd9d79 | 2021-06-25 11:51:44 +0100 | [diff] [blame] | 2541 | removalReason = "AppWidgetManager cannot find provider for that widget id." |
| 2542 | + " It could be because AppWidgetService is not available, or the" |
Pinyao Ting | bbb9a9c | 2021-05-11 15:42:54 -0700 | [diff] [blame] | 2543 | + " appWidgetId has not been bound to a the provider yet, or you" |
| 2544 | + " don't have access to that appWidgetId."; |
| 2545 | } |
| 2546 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2547 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2548 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2549 | // If the provider is ready, but the width is not yet restored, try to restore it. |
| 2550 | if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) |
| 2551 | && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) { |
| 2552 | if (appWidgetInfo == null) { |
Pinyao Ting | 6a41d56 | 2022-05-10 23:47:36 +0000 | [diff] [blame] | 2553 | getModelWriter().deleteItemFromDatabase(item, |
| 2554 | "Removing restored widget: id=" + item.appWidgetId |
Pinyao Ting | bbb9a9c | 2021-05-11 15:42:54 -0700 | [diff] [blame] | 2555 | + " belongs to component " + item.providerName + " user " + item.user |
Steven Ng | acd9d79 | 2021-06-25 11:51:44 +0100 | [diff] [blame] | 2556 | + ", as the provider is null and " + removalReason); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2557 | return null; |
| 2558 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2559 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2560 | // If we do not have a valid id, try to bind an id. |
| 2561 | if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { |
| 2562 | if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) { |
| 2563 | // Id has not been allocated yet. Allocate a new id. |
| 2564 | item.appWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 2565 | item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED; |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 2566 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2567 | // Also try to bind the widget. If the bind fails, the user will be shown |
| 2568 | // a click to setup UI, which will ask for the bind permission. |
Yogisha Dixit | 658c5da | 2021-05-24 23:23:15 +0100 | [diff] [blame] | 2569 | PendingAddWidgetInfo pendingInfo = |
| 2570 | new PendingAddWidgetInfo(appWidgetInfo, item.sourceContainer); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2571 | pendingInfo.spanX = item.spanX; |
| 2572 | pendingInfo.spanY = item.spanY; |
| 2573 | pendingInfo.minSpanX = item.minSpanX; |
| 2574 | pendingInfo.minSpanY = item.minSpanY; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2575 | Bundle options = pendingInfo.getDefaultSizeOptions(this); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2576 | |
| 2577 | boolean isDirectConfig = |
| 2578 | item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG); |
| 2579 | if (isDirectConfig && item.bindOptions != null) { |
| 2580 | Bundle newOptions = item.bindOptions.getExtras(); |
| 2581 | if (options != null) { |
| 2582 | newOptions.putAll(options); |
| 2583 | } |
| 2584 | options = newOptions; |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 2585 | } |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2586 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2587 | item.appWidgetId, appWidgetInfo, options); |
| 2588 | |
| 2589 | // We tried to bind once. If we were not able to bind, we would need to |
| 2590 | // go through the permission dialog, which means we cannot skip the config |
| 2591 | // activity. |
| 2592 | item.bindOptions = null; |
| 2593 | item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG; |
| 2594 | |
| 2595 | // Bind succeeded |
| 2596 | if (success) { |
| 2597 | // If the widget has a configure activity, it is still needs to set it |
| 2598 | // up, otherwise the widget is ready to go. |
| 2599 | item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig |
| 2600 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 2601 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 2602 | } |
| 2603 | |
| 2604 | getModelWriter().updateItemInDatabase(item); |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 2605 | } |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2606 | } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY) |
| 2607 | && (appWidgetInfo.configure == null)) { |
| 2608 | // The widget was marked as UI not ready, but there is no configure activity to |
| 2609 | // update the UI. |
| 2610 | item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2611 | getModelWriter().updateItemInDatabase(item); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2612 | } |
Samuel Fufa | 9151c01 | 2020-02-24 17:06:28 -0800 | [diff] [blame] | 2613 | else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY) |
| 2614 | && appWidgetInfo.configure != null) { |
| 2615 | if (mAppWidgetManager.isAppWidgetRestored(item.appWidgetId)) { |
| 2616 | item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 2617 | getModelWriter().updateItemInDatabase(item); |
| 2618 | } |
| 2619 | } |
Sunny Goyal | 56c7360 | 2015-09-25 12:55:01 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2622 | if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 2623 | // Verify that we own the widget |
| 2624 | if (appWidgetInfo == null) { |
Pinyao Ting | 0d97f8d | 2020-12-04 15:12:26 -0800 | [diff] [blame] | 2625 | FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId); |
Pinyao Ting | 6a41d56 | 2022-05-10 23:47:36 +0000 | [diff] [blame] | 2626 | getModelWriter().deleteWidgetInfo(item, getAppWidgetHost(), removalReason); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2627 | return null; |
| 2628 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2629 | |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2630 | item.minSpanX = appWidgetInfo.minSpanX; |
| 2631 | item.minSpanY = appWidgetInfo.minSpanY; |
| 2632 | view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo); |
Samuel Fufa | 9151c01 | 2020-02-24 17:06:28 -0800 | [diff] [blame] | 2633 | } else if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) |
| 2634 | && appWidgetInfo != null) { |
| 2635 | mAppWidgetHost.addPendingView(item.appWidgetId, |
| 2636 | new PendingAppWidgetHostView(this, item, mIconCache, false)); |
| 2637 | view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2638 | } else { |
| 2639 | view = new PendingAppWidgetHostView(this, item, mIconCache, false); |
| 2640 | } |
| 2641 | prepareAppWidget(view, item); |
| 2642 | } finally { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2643 | TraceHelper.INSTANCE.endSection(traceToken); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 2646 | return view; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2647 | } |
| 2648 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2649 | /** |
| 2650 | * Restores a pending widget. |
| 2651 | * |
| 2652 | * @param appWidgetId The app widget id |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2653 | */ |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2654 | private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2655 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 2656 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 2657 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2658 | return null; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 2661 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2662 | info.restoreStatus = finalRestoreFlag; |
Jon Miranda | 2b823f4 | 2017-05-02 18:36:18 -0700 | [diff] [blame] | 2663 | if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 2664 | info.pendingItemInfo = null; |
| 2665 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2666 | |
Sunny Goyal | ba47faa | 2017-10-04 16:50:57 -0700 | [diff] [blame] | 2667 | if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) { |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2668 | view.reInflate(); |
Sunny Goyal | ba47faa | 2017-10-04 16:50:57 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2671 | getModelWriter().updateItemInDatabase(info); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2672 | return info; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 2675 | public void clearPendingExecutor(ViewOnDrawExecutor executor) { |
| 2676 | if (mPendingExecutor == executor) { |
| 2677 | mPendingExecutor = null; |
| 2678 | } |
| 2679 | } |
| 2680 | |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 2681 | @Override |
Schneider Victor-tulias | 927d6dc | 2021-08-26 11:56:47 -0700 | [diff] [blame] | 2682 | @TargetApi(Build.VERSION_CODES.S) |
Sunny Goyal | 4a48a98 | 2021-06-17 15:15:46 -0700 | [diff] [blame] | 2683 | public void onInitialBindComplete(IntSet boundPages, RunnableList pendingTasks) { |
| 2684 | mSynchronouslyBoundPages = boundPages; |
Sunny Goyal | 4a48a98 | 2021-06-17 15:15:46 -0700 | [diff] [blame] | 2685 | mPagesToBindSynchronously = new IntSet(); |
| 2686 | |
| 2687 | clearPendingBinds(); |
| 2688 | ViewOnDrawExecutor executor = new ViewOnDrawExecutor(pendingTasks); |
| 2689 | mPendingExecutor = executor; |
| 2690 | if (!isInState(ALL_APPS)) { |
| 2691 | mAppsView.getAppsStore().enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW); |
| 2692 | pendingTasks.add(() -> mAppsView.getAppsStore().disableDeferUpdates( |
| 2693 | AllAppsStore.DEFER_UPDATES_NEXT_DRAW)); |
| 2694 | } |
| 2695 | |
Sunny Goyal | 7b8d63f | 2022-04-14 16:37:32 -0700 | [diff] [blame] | 2696 | if (mOnInitialBindListener != null) { |
| 2697 | getRootView().getViewTreeObserver().removeOnPreDrawListener(mOnInitialBindListener); |
| 2698 | mOnInitialBindListener = null; |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 2699 | } |
Sunny Goyal | 7b8d63f | 2022-04-14 16:37:32 -0700 | [diff] [blame] | 2700 | |
| 2701 | executor.onLoadAnimationCompleted(); |
Sunny Goyal | 4a48a98 | 2021-06-17 15:15:46 -0700 | [diff] [blame] | 2702 | executor.attachTo(this); |
Schneider Victor-tulias | 927d6dc | 2021-08-26 11:56:47 -0700 | [diff] [blame] | 2703 | if (Utilities.ATLEAST_S) { |
| 2704 | Trace.endAsyncSection(DISPLAY_WORKSPACE_TRACE_METHOD_NAME, |
| 2705 | DISPLAY_WORKSPACE_TRACE_COOKIE); |
| 2706 | } |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2709 | /** |
| 2710 | * Callback saying that there aren't any more items to bind. |
| 2711 | * |
| 2712 | * Implementation of the method from LauncherModel.Callbacks. |
| 2713 | */ |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 2714 | public void finishBindingItems(IntSet pagesBoundFirst) { |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2715 | Object traceToken = TraceHelper.INSTANCE.beginSection("finishBindingItems"); |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2716 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2717 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2718 | setWorkspaceLoading(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 2719 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2720 | if (mPendingActivityResult != null) { |
| 2721 | handleActivityResult(mPendingActivityResult.requestCode, |
| 2722 | mPendingActivityResult.resultCode, mPendingActivityResult.data); |
| 2723 | mPendingActivityResult = null; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 2726 | int currentPage = pagesBoundFirst != null && !pagesBoundFirst.isEmpty() |
Sunny Goyal | 12e3f1f | 2021-07-15 14:31:58 -0700 | [diff] [blame] | 2727 | ? mWorkspace.getPageIndexForScreenId(pagesBoundFirst.getArray().get(0)) |
| 2728 | : PagedView.INVALID_PAGE; |
Tony | f80e893 | 2018-12-21 11:58:04 -0800 | [diff] [blame] | 2729 | // 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] | 2730 | // Since we are just resetting the current page without user interaction, |
| 2731 | // override the previous page so we don't log the page switch. |
Andras Kloczl | 55edfe5 | 2021-05-14 12:21:30 +0200 | [diff] [blame] | 2732 | mWorkspace.setCurrentPage(currentPage, currentPage /* overridePrevPage */); |
| 2733 | mPagesToBindSynchronously = new IntSet(); |
Tony Wickham | 6a71a5b | 2018-08-21 11:40:23 -0700 | [diff] [blame] | 2734 | |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 2735 | // Cache one page worth of icons |
| 2736 | getViewCache().setCacheSize(R.layout.folder_application, |
| 2737 | mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows); |
| 2738 | getViewCache().setCacheSize(R.layout.folder_page, 2); |
| 2739 | |
Winson Chung | 5cc62c7 | 2019-10-16 11:32:41 -0700 | [diff] [blame] | 2740 | TraceHelper.INSTANCE.endSection(traceToken); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Schneider Victor-tulias | 68fb416 | 2021-09-16 13:24:01 -0700 | [diff] [blame] | 2743 | private boolean canAnimatePageChange() { |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 2744 | if (mDragController.isDragging()) { |
| 2745 | return false; |
| 2746 | } else { |
Riddle Hsu | 979da64 | 2020-09-22 21:52:40 +0800 | [diff] [blame] | 2747 | return (SystemClock.uptimeMillis() - mLastTouchUpTime) |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 2748 | > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 2749 | } |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2752 | /** |
| 2753 | * Similar to {@link #getFirstMatch} but optimized to finding a suitable view for the app close |
| 2754 | * animation. |
| 2755 | * |
| 2756 | * @param preferredItemId The id of the preferred item to match to if it exists. |
| 2757 | * @param packageName The package name of the app to match. |
| 2758 | * @param user The user of the app to match. |
Jon Miranda | b42e124 | 2022-03-08 16:37:35 -0800 | [diff] [blame] | 2759 | * @param supportsAllAppsState If true and we are in All Apps state, looks for view in All Apps. |
| 2760 | * Else we only looks on the workspace. |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2761 | */ |
Jon Miranda | f58db15 | 2022-06-02 16:06:37 -0700 | [diff] [blame] | 2762 | public @Nullable View getFirstMatchForAppClose(int preferredItemId, String packageName, |
| 2763 | UserHandle user, boolean supportsAllAppsState) { |
Sunny Goyal | 32084d4 | 2022-05-02 10:00:07 -0700 | [diff] [blame] | 2764 | final Predicate<ItemInfo> preferredItem = info -> |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2765 | info != null && info.id == preferredItemId; |
Sunny Goyal | 32084d4 | 2022-05-02 10:00:07 -0700 | [diff] [blame] | 2766 | final Predicate<ItemInfo> packageAndUserAndApp = info -> |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2767 | info != null |
| 2768 | && info.itemType == ITEM_TYPE_APPLICATION |
| 2769 | && info.user.equals(user) |
| 2770 | && info.getTargetComponent() != null |
| 2771 | && TextUtils.equals(info.getTargetComponent().getPackageName(), |
| 2772 | packageName); |
| 2773 | |
Jon Miranda | b42e124 | 2022-03-08 16:37:35 -0800 | [diff] [blame] | 2774 | if (supportsAllAppsState && isInState(LauncherState.ALL_APPS)) { |
Jon Miranda | f58db15 | 2022-06-02 16:06:37 -0700 | [diff] [blame] | 2775 | AllAppsRecyclerView activeRecyclerView = mAppsView.getActiveRecyclerView(); |
| 2776 | View v = getFirstMatch(Collections.singletonList(activeRecyclerView), |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2777 | preferredItem, packageAndUserAndApp); |
Jon Miranda | f58db15 | 2022-06-02 16:06:37 -0700 | [diff] [blame] | 2778 | |
Jon Miranda | f26bdcb | 2022-06-09 16:09:30 -0700 | [diff] [blame^] | 2779 | if (v != null && activeRecyclerView.getCurrentScrollY() > 0) { |
Jon Miranda | f58db15 | 2022-06-02 16:06:37 -0700 | [diff] [blame] | 2780 | RectF locationBounds = new RectF(); |
| 2781 | FloatingIconView.getLocationBoundsForView(this, v, false, locationBounds, |
| 2782 | new Rect()); |
| 2783 | if (locationBounds.top < mAppsView.getHeaderBottom()) { |
| 2784 | // Icon is covered by scrim, return null to play fallback animation. |
| 2785 | return null; |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | return v; |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2790 | } else { |
| 2791 | List<ViewGroup> containers = new ArrayList<>(mWorkspace.getPanelCount() + 1); |
| 2792 | containers.add(mWorkspace.getHotseat().getShortcutsAndWidgets()); |
| 2793 | mWorkspace.forEachVisiblePage(page |
| 2794 | -> containers.add(((CellLayout) page).getShortcutsAndWidgets())); |
| 2795 | |
| 2796 | // Order: Preferred item by itself or in folder, then by matching package/user |
Jon Miranda | 78d0d4f | 2022-01-24 18:00:04 -0800 | [diff] [blame] | 2797 | return getFirstMatch(containers, preferredItem, forFolderMatch(preferredItem), |
| 2798 | packageAndUserAndApp, forFolderMatch(packageAndUserAndApp)); |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | /** |
| 2803 | * Finds the first view matching the ordered operators across the given viewgroups in order. |
| 2804 | * @param containers List of ViewGroups to scan, in order of preference. |
| 2805 | * @param operators List of operators, in order starting from best matching operator. |
| 2806 | */ |
Jon Miranda | f26bdcb | 2022-06-09 16:09:30 -0700 | [diff] [blame^] | 2807 | @Nullable |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2808 | private static View getFirstMatch(Iterable<ViewGroup> containers, |
Sunny Goyal | 32084d4 | 2022-05-02 10:00:07 -0700 | [diff] [blame] | 2809 | final Predicate<ItemInfo>... operators) { |
| 2810 | for (Predicate<ItemInfo> operator : operators) { |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2811 | for (ViewGroup container : containers) { |
| 2812 | View match = mapOverViewGroup(container, operator); |
| 2813 | if (match != null) { |
| 2814 | return match; |
| 2815 | } |
| 2816 | } |
| 2817 | } |
| 2818 | return null; |
| 2819 | } |
| 2820 | |
| 2821 | /** |
| 2822 | * Returns the first view matching the operator in the given ViewGroups, or null if none. |
| 2823 | * Forward iteration matters. |
| 2824 | */ |
Jon Miranda | f26bdcb | 2022-06-09 16:09:30 -0700 | [diff] [blame^] | 2825 | @Nullable |
Sunny Goyal | 32084d4 | 2022-05-02 10:00:07 -0700 | [diff] [blame] | 2826 | private static View mapOverViewGroup(ViewGroup container, Predicate<ItemInfo> op) { |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2827 | final int itemCount = container.getChildCount(); |
| 2828 | for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) { |
| 2829 | View item = container.getChildAt(itemIdx); |
Sunny Goyal | 32084d4 | 2022-05-02 10:00:07 -0700 | [diff] [blame] | 2830 | if (op.test((ItemInfo) item.getTag())) { |
Jon Miranda | c4a99bf | 2021-11-04 16:53:45 -0700 | [diff] [blame] | 2831 | return item; |
| 2832 | } |
| 2833 | } |
| 2834 | return null; |
| 2835 | } |
| 2836 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 2837 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 2838 | ValueAnimator bounceAnim = new PropertyListBuilder().alpha(1).scale(1).build(v) |
Sunny Goyal | 60e68c9 | 2020-08-12 13:59:27 -0700 | [diff] [blame] | 2839 | .setDuration(ItemInstallQueue.NEW_SHORTCUT_BOUNCE_DURATION); |
| 2840 | bounceAnim.setStartDelay(i * ItemInstallQueue.NEW_SHORTCUT_STAGGER_DELAY); |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 2841 | bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION)); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 2842 | return bounceAnim; |
| 2843 | } |
| 2844 | |
Pinyao Ting | c907427 | 2019-11-11 11:51:44 -0800 | [diff] [blame] | 2845 | private void announceForAccessibility(@StringRes int stringResId) { |
| 2846 | getDragLayer().announceForAccessibility(getString(stringResId)); |
| 2847 | } |
| 2848 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2849 | /** |
Josh Tsuji | 231c922 | 2022-01-11 20:43:59 -0500 | [diff] [blame] | 2850 | * Informs us that the overlay (-1 screen, typically), has either become visible or invisible. |
| 2851 | */ |
| 2852 | public void onOverlayVisibilityChanged(boolean visible) {} |
| 2853 | |
| 2854 | /** |
| 2855 | * Informs us that the page transition has ended, so that we can react to the newly selected |
| 2856 | * page if we want to. |
| 2857 | */ |
| 2858 | public void onPageEndTransition() {} |
| 2859 | |
| 2860 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2861 | * Add the icons for all apps. |
| 2862 | * |
| 2863 | * Implementation of the method from LauncherModel.Callbacks. |
| 2864 | */ |
Sunny Goyal | 28daf4a | 2020-06-08 17:06:09 -0700 | [diff] [blame] | 2865 | @Override |
Schneider Victor-tulias | 927d6dc | 2021-08-26 11:56:47 -0700 | [diff] [blame] | 2866 | @TargetApi(Build.VERSION_CODES.S) |
Sunny Goyal | 28daf4a | 2020-06-08 17:06:09 -0700 | [diff] [blame] | 2867 | public void bindAllApplications(AppInfo[] apps, int flags) { |
| 2868 | mAppsView.getAppsStore().setApps(apps, flags); |
Sunny Goyal | 1818fb7 | 2020-11-09 14:32:48 -0800 | [diff] [blame] | 2869 | PopupContainerWithArrow.dismissInvalidPopup(this); |
Schneider Victor-tulias | 927d6dc | 2021-08-26 11:56:47 -0700 | [diff] [blame] | 2870 | if (Utilities.ATLEAST_S) { |
| 2871 | Trace.endAsyncSection(DISPLAY_ALL_APPS_TRACE_METHOD_NAME, |
| 2872 | DISPLAY_ALL_APPS_TRACE_COOKIE); |
| 2873 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | /** |
Zak Cohen | 658c67a | 2018-10-19 14:21:05 -0700 | [diff] [blame] | 2877 | * 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] | 2878 | * because LauncherModel's map is updated in the background, while Launcher runs on the UI. |
| 2879 | */ |
| 2880 | @Override |
Zak Cohen | 658c67a | 2018-10-19 14:21:05 -0700 | [diff] [blame] | 2881 | public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) { |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 2882 | mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy); |
Tony Wickham | 1bce7fd | 2016-04-28 17:39:03 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2885 | @Override |
Schneider Victor-tulias | 6a5f431 | 2021-01-12 19:30:02 +0000 | [diff] [blame] | 2886 | public void bindIncrementalDownloadProgressUpdated(AppInfo app) { |
| 2887 | mAppsView.getAppsStore().updateProgressBar(app); |
Mario Bertschler | 08ffaae | 2017-03-20 11:30:27 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | @Override |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2891 | public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2892 | mWorkspace.widgetsRestored(widgets); |
| 2893 | } |
| 2894 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2895 | /** |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 2896 | * Some shortcuts were updated in the background. |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 2897 | * Implementation of the method from LauncherModel.Callbacks. |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 2898 | * |
| 2899 | * @param updated list of shortcuts which have changed. |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 2900 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2901 | @Override |
Sunny Goyal | 28f5075 | 2020-07-21 14:15:13 -0700 | [diff] [blame] | 2902 | public void bindWorkspaceItemsChanged(List<WorkspaceItemInfo> updated) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2903 | if (!updated.isEmpty()) { |
Sunny Goyal | 711c596 | 2021-06-23 12:36:18 -0700 | [diff] [blame] | 2904 | mWorkspace.updateWorkspaceItems(updated, this); |
Sunny Goyal | 1818fb7 | 2020-11-09 14:32:48 -0800 | [diff] [blame] | 2905 | PopupContainerWithArrow.dismissInvalidPopup(this); |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2906 | } |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 2910 | * Update the state of a package, typically related to install state. |
| 2911 | * |
| 2912 | * Implementation of the method from LauncherModel.Callbacks. |
| 2913 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 2914 | @Override |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 2915 | public void bindRestoreItemsChange(HashSet<ItemInfo> updates) { |
Sunny Goyal | 711c596 | 2021-06-23 12:36:18 -0700 | [diff] [blame] | 2916 | mWorkspace.updateRestoreItems(updates, this); |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | /** |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 2920 | * 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] | 2921 | * in addition to specific applications to remove, the reason being that |
| 2922 | * 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] | 2923 | * we only remove specific components from the workspace and hotseat, where as |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 2924 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2925 | */ |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2926 | @Override |
Sunny Goyal | 32084d4 | 2022-05-02 10:00:07 -0700 | [diff] [blame] | 2927 | public void bindWorkspaceComponentsRemoved(Predicate<ItemInfo> matcher) { |
Sunny Goyal | 6e13dd3 | 2017-08-17 03:01:19 -0700 | [diff] [blame] | 2928 | mWorkspace.removeItemsByMatcher(matcher); |
| 2929 | mDragController.onAppsRemoved(matcher); |
Sunny Goyal | 1818fb7 | 2020-11-09 14:32:48 -0800 | [diff] [blame] | 2930 | PopupContainerWithArrow.dismissInvalidPopup(this); |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 2931 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 2932 | |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 2933 | @Override |
Steven Ng | 2f5648a | 2021-02-08 17:18:25 +0000 | [diff] [blame] | 2934 | public void bindAllWidgets(final List<WidgetsListBaseEntry> allWidgets) { |
Sunny Goyal | f1fbc3f | 2017-10-10 15:21:15 -0700 | [diff] [blame] | 2935 | mPopupDataProvider.setAllWidgets(allWidgets); |
Tony Wickham | 26b1746 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
kholoud mohamed | c76b203 | 2021-12-20 16:47:38 +0000 | [diff] [blame] | 2938 | @Override |
| 2939 | public void bindStringCache(StringCache cache) { |
| 2940 | mStringCache = cache; |
| 2941 | } |
| 2942 | |
| 2943 | @Override |
| 2944 | public StringCache getStringCache() { |
| 2945 | return mStringCache; |
| 2946 | } |
| 2947 | |
Tony Wickham | 86222d2 | 2017-03-29 15:30:43 -0700 | [diff] [blame] | 2948 | /** |
| 2949 | * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only |
| 2950 | * refreshes the widgets and shortcuts associated with the given package/user |
| 2951 | */ |
| 2952 | public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame] | 2953 | mModel.refreshAndBindWidgetsAndShortcuts(packageUser); |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 2954 | } |
| 2955 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 2956 | /** |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2957 | * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all] |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2958 | */ |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 2959 | @Override |
| 2960 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 2961 | super.dump(prefix, fd, writer, args); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 2962 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2963 | if (args.length > 0 && TextUtils.equals(args[0], "--all")) { |
| 2964 | writer.println(prefix + "Workspace Items"); |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 2965 | for (int i = 0; i < mWorkspace.getPageCount(); i++) { |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2966 | writer.println(prefix + " Homescreen " + i); |
| 2967 | |
| 2968 | ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets(); |
| 2969 | for (int j = 0; j < layout.getChildCount(); j++) { |
| 2970 | Object tag = layout.getChildAt(j).getTag(); |
| 2971 | if (tag != null) { |
| 2972 | writer.println(prefix + " " + tag.toString()); |
| 2973 | } |
| 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | writer.println(prefix + " Hotseat"); |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 2978 | ViewGroup layout = mHotseat.getShortcutsAndWidgets(); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 2979 | for (int j = 0; j < layout.getChildCount(); j++) { |
| 2980 | Object tag = layout.getChildAt(j).getTag(); |
| 2981 | if (tag != null) { |
| 2982 | writer.println(prefix + " " + tag.toString()); |
| 2983 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 2984 | } |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2987 | writer.println(prefix + "Misc:"); |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 2988 | dumpMisc(prefix + "\t", writer); |
| 2989 | writer.println(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading); |
| 2990 | writer.println(prefix + "\tmPendingRequestArgs=" + mPendingRequestArgs |
| 2991 | + " mPendingActivityResult=" + mPendingActivityResult); |
| 2992 | writer.println(prefix + "\tmRotationHelper: " + mRotationHelper); |
| 2993 | writer.println(prefix + "\tmAppWidgetHost.isListening: " + mAppWidgetHost.isListening()); |
| 2994 | |
Tony Wickham | 646e448 | 2020-04-06 17:25:53 -0700 | [diff] [blame] | 2995 | // Extra logging for general debugging |
Hyunyoung Song | a310a80 | 2019-04-25 13:57:16 -0700 | [diff] [blame] | 2996 | mDragLayer.dump(prefix, writer); |
| 2997 | mStateManager.dump(prefix, writer); |
Tony Wickham | 646e448 | 2020-04-06 17:25:53 -0700 | [diff] [blame] | 2998 | mPopupDataProvider.dump(prefix, writer); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2999 | mDeviceProfile.dump(prefix, writer); |
Sunny Goyal | 2bba190 | 2018-02-27 12:20:50 -0800 | [diff] [blame] | 3000 | |
| 3001 | try { |
| 3002 | FileLog.flushAll(writer); |
| 3003 | } catch (Exception e) { |
| 3004 | // Ignore |
| 3005 | } |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 3006 | |
| 3007 | mModel.dumpState(prefix, fd, writer, args); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 3008 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3009 | if (mLauncherCallbacks != null) { |
| 3010 | mLauncherCallbacks.dump(prefix, fd, writer, args); |
| 3011 | } |
Sunny Goyal | b1d7de2 | 2019-09-06 10:36:54 -0700 | [diff] [blame] | 3012 | mOverlayManager.dump(prefix, writer); |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 3013 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 3014 | |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3015 | @Override |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3016 | public void onProvideKeyboardShortcuts( |
| 3017 | List<KeyboardShortcutGroup> data, Menu menu, int deviceId) { |
| 3018 | |
| 3019 | ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>(); |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 3020 | if (isInState(NORMAL)) { |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3021 | shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label), |
| 3022 | KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON)); |
Vadim Tryshev | 74c261c | 2018-06-12 13:44:43 -0700 | [diff] [blame] | 3023 | shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.widget_button_text), |
| 3024 | KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON)); |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3025 | } |
Sunny Goyal | 384b578 | 2021-02-09 22:50:02 -0800 | [diff] [blame] | 3026 | getSupportedActions(this, getCurrentFocus()).forEach(la -> |
Vadim Tryshev | 3455f8d | 2018-05-11 20:02:20 -0700 | [diff] [blame] | 3027 | shortcutInfos.add(new KeyboardShortcutInfo( |
Sunny Goyal | 384b578 | 2021-02-09 22:50:02 -0800 | [diff] [blame] | 3028 | la.accessibilityAction.getLabel(), la.keyCode, KeyEvent.META_CTRL_ON))); |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3029 | if (!shortcutInfos.isEmpty()) { |
| 3030 | data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos)); |
| 3031 | } |
| 3032 | |
| 3033 | super.onProvideKeyboardShortcuts(data, menu, deviceId); |
| 3034 | } |
| 3035 | |
| 3036 | @Override |
| 3037 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 3038 | if (event.hasModifiers(KeyEvent.META_CTRL_ON)) { |
| 3039 | switch (keyCode) { |
| 3040 | case KeyEvent.KEYCODE_A: |
Sunny Goyal | 3e3f44c | 2017-10-23 17:14:52 -0700 | [diff] [blame] | 3041 | if (isInState(NORMAL)) { |
| 3042 | getStateManager().goToState(ALL_APPS); |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3043 | return true; |
| 3044 | } |
| 3045 | break; |
Vadim Tryshev | 74c261c | 2018-06-12 13:44:43 -0700 | [diff] [blame] | 3046 | case KeyEvent.KEYCODE_W: |
| 3047 | if (isInState(NORMAL)) { |
| 3048 | OptionsPopupView.openWidgets(this); |
| 3049 | return true; |
| 3050 | } |
| 3051 | break; |
Sunny Goyal | 384b578 | 2021-02-09 22:50:02 -0800 | [diff] [blame] | 3052 | default: |
| 3053 | for (LauncherAction la : getSupportedActions(this, getCurrentFocus())) { |
| 3054 | if (la.keyCode == keyCode) { |
| 3055 | return la.invokeFromKeyboard(getCurrentFocus()); |
| 3056 | } |
| 3057 | } |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3058 | } |
| 3059 | } |
| 3060 | return super.onKeyShortcut(keyCode, event); |
| 3061 | } |
| 3062 | |
Vadim Tryshev | 646a0dd | 2018-02-05 16:27:50 -0800 | [diff] [blame] | 3063 | @Override |
| 3064 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 3065 | if (keyCode == KeyEvent.KEYCODE_MENU) { |
| 3066 | // KEYCODE_MENU is sent by some tests, for example |
| 3067 | // LauncherJankTests#testWidgetsContainerFling. Don't just remove its handling. |
| 3068 | if (!mDragController.isDragging() && !mWorkspace.isSwitchingState() && |
| 3069 | isInState(NORMAL)) { |
| 3070 | // Close any open floating views. |
Andy Wickham | 65ced1b | 2020-03-07 02:14:19 +0000 | [diff] [blame] | 3071 | closeOpenViews(); |
Vadim Tryshev | 646a0dd | 2018-02-05 16:27:50 -0800 | [diff] [blame] | 3072 | |
| 3073 | // Setting the touch point to (-1, -1) will show the options popup in the center of |
| 3074 | // the screen. |
vadimt | bc5d7e6 | 2019-12-09 13:53:05 -0800 | [diff] [blame] | 3075 | if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { |
| 3076 | Log.d(TestProtocol.PERMANENT_DIAG_TAG, "Opening options popup on key up"); |
| 3077 | } |
Sunny Goyal | 831212e | 2021-05-14 14:24:09 -0700 | [diff] [blame] | 3078 | showDefaultOptions(-1, -1); |
Vadim Tryshev | 646a0dd | 2018-02-05 16:27:50 -0800 | [diff] [blame] | 3079 | } |
| 3080 | return true; |
| 3081 | } |
| 3082 | return super.onKeyUp(keyCode, event); |
| 3083 | } |
| 3084 | |
Sunny Goyal | 831212e | 2021-05-14 14:24:09 -0700 | [diff] [blame] | 3085 | /** |
| 3086 | * Shows the default options popup |
| 3087 | */ |
| 3088 | public void showDefaultOptions(float x, float y) { |
Brian Isganitis | a85ae69 | 2021-09-23 19:56:24 -0400 | [diff] [blame] | 3089 | OptionsPopupView.show(this, getPopupTarget(x, y), OptionsPopupView.getOptions(this), |
| 3090 | false); |
| 3091 | } |
| 3092 | |
| 3093 | /** |
| 3094 | * Returns target rectangle for anchoring a popup menu. |
| 3095 | */ |
| 3096 | protected RectF getPopupTarget(float x, float y) { |
Sunny Goyal | 831212e | 2021-05-14 14:24:09 -0700 | [diff] [blame] | 3097 | float halfSize = getResources().getDimension(R.dimen.options_menu_thumb_size) / 2; |
| 3098 | if (x < 0 || y < 0) { |
| 3099 | x = mDragLayer.getWidth() / 2; |
| 3100 | y = mDragLayer.getHeight() / 2; |
| 3101 | } |
Brian Isganitis | a85ae69 | 2021-09-23 19:56:24 -0400 | [diff] [blame] | 3102 | return new RectF(x - halfSize, y - halfSize, x + halfSize, y + halfSize); |
| 3103 | } |
| 3104 | |
| 3105 | @Override |
| 3106 | public boolean shouldUseColorExtractionForPopup() { |
| 3107 | return getTopOpenViewWithType(this, TYPE_FOLDER) == null |
| 3108 | && getStateManager().getState() != LauncherState.ALL_APPS; |
Sunny Goyal | 831212e | 2021-05-14 14:24:09 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
Sunny Goyal | b5181c8 | 2021-03-10 07:39:12 +0000 | [diff] [blame] | 3111 | @Override |
| 3112 | protected void collectStateHandlers(List<StateHandler> out) { |
| 3113 | out.add(getAllAppsController()); |
| 3114 | out.add(getWorkspace()); |
Andrew Sapperstein | abef55a | 2016-06-19 12:49:00 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 3117 | public TouchController[] createTouchControllers() { |
| 3118 | return new TouchController[] {getDragController(), new AllAppsSwipeController(this)}; |
| 3119 | } |
| 3120 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 3121 | public void useFadeOutAnimationForLauncherStart(CancellationSignal signal) { } |
| 3122 | |
| 3123 | public void onDragLayerHierarchyChanged() { } |
| 3124 | |
Vinit Nayak | f9b585b | 2019-07-10 14:25:32 -0700 | [diff] [blame] | 3125 | @Override |
| 3126 | public void returnToHomescreen() { |
| 3127 | super.returnToHomescreen(); |
| 3128 | getStateManager().goToState(LauncherState.NORMAL); |
| 3129 | } |
| 3130 | |
Andy Wickham | 65ced1b | 2020-03-07 02:14:19 +0000 | [diff] [blame] | 3131 | private void closeOpenViews() { |
| 3132 | closeOpenViews(true); |
| 3133 | } |
| 3134 | |
| 3135 | protected void closeOpenViews(boolean animate) { |
| 3136 | AbstractFloatingView.closeAllOpenViews(this, animate); |
| 3137 | } |
| 3138 | |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 3139 | public Stream<SystemShortcut.Factory> getSupportedShortcuts() { |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame] | 3140 | return Stream.of(APP_INFO, WIDGETS, INSTALL); |
Sunny Goyal | 3a1eadd | 2019-10-23 17:44:27 -0700 | [diff] [blame] | 3141 | } |
| 3142 | |
Sunny Goyal | 384b578 | 2021-02-09 22:50:02 -0800 | [diff] [blame] | 3143 | protected LauncherAccessibilityDelegate createAccessibilityDelegate() { |
| 3144 | return new LauncherAccessibilityDelegate(this); |
| 3145 | } |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 3146 | |
| 3147 | /** |
| 3148 | * @see LauncherState#getOverviewScaleAndOffset(Launcher) |
| 3149 | */ |
| 3150 | public float[] getNormalOverviewScaleAndOffset() { |
Tony Wickham | 82d5a06 | 2021-05-14 14:37:12 -0700 | [diff] [blame] | 3151 | return new float[] {NO_SCALE, NO_OFFSET}; |
Sunny Goyal | f2393f1 | 2020-04-01 20:13:12 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 3154 | public static Launcher getLauncher(Context context) { |
Winson Chung | 8687bc2 | 2020-02-27 23:34:24 -0800 | [diff] [blame] | 3155 | return fromContext(context); |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 3158 | /** |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 3159 | * Just a wrapper around the type cast to allow easier tracking of calls. |
| 3160 | */ |
| 3161 | public static <T extends Launcher> T cast(ActivityContext activityContext) { |
| 3162 | return (T) activityContext; |
| 3163 | } |
| 3164 | |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 3165 | /** |
| 3166 | * Cross-fades the launcher's updated appearance with its previous appearance. |
| 3167 | * |
| 3168 | * This method is used to cross-fade UI updates on activity creation, specifically dark mode |
| 3169 | * updates. |
| 3170 | */ |
| 3171 | private void crossFadeWithPreviousAppearance() { |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 3172 | NonConfigInstance lastInstance = (NonConfigInstance) getLastNonConfigurationInstance(); |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 3173 | |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 3174 | if (lastInstance == null || lastInstance.snapshot == null) { |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 3175 | return; |
| 3176 | } |
| 3177 | |
| 3178 | ImageView crossFadeHelper = new ImageView(this); |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 3179 | crossFadeHelper.setImageBitmap(lastInstance.snapshot); |
Schneider Victor-tulias | 25ecae1 | 2020-09-14 14:07:38 -0700 | [diff] [blame] | 3180 | crossFadeHelper.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
| 3181 | |
| 3182 | InsettableFrameLayout.LayoutParams layoutParams = new InsettableFrameLayout.LayoutParams( |
| 3183 | InsettableFrameLayout.LayoutParams.MATCH_PARENT, |
| 3184 | InsettableFrameLayout.LayoutParams.MATCH_PARENT); |
| 3185 | |
| 3186 | layoutParams.ignoreInsets = true; |
| 3187 | |
| 3188 | crossFadeHelper.setLayoutParams(layoutParams); |
| 3189 | |
| 3190 | getRootView().addView(crossFadeHelper); |
| 3191 | |
| 3192 | crossFadeHelper |
| 3193 | .animate() |
| 3194 | .setDuration(THEME_CROSS_FADE_ANIMATION_DURATION) |
| 3195 | .alpha(0f) |
| 3196 | .withEndAction(() -> getRootView().removeView(crossFadeHelper)) |
| 3197 | .start(); |
| 3198 | } |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 3199 | |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 3200 | public boolean supportsAdaptiveIconAnimation(View clickedView) { |
| 3201 | return false; |
| 3202 | } |
| 3203 | |
Tony Wickham | 39938cb | 2021-02-26 09:15:31 -0800 | [diff] [blame] | 3204 | public DragOptions getDefaultWorkspaceDragOptions() { |
| 3205 | return new DragOptions(); |
| 3206 | } |
| 3207 | |
Schneider Victor-tulias | 9b6babf | 2022-03-24 14:47:32 -0700 | [diff] [blame] | 3208 | /** |
| 3209 | * Animates Launcher elements during a transition to the All Apps page. |
| 3210 | * |
| 3211 | * @param progress Transition progress from 0 to 1; where 0 => home and 1 => all apps. |
| 3212 | */ |
| 3213 | public void onAllAppsTransition(float progress) { |
| 3214 | // No-Op |
| 3215 | } |
| 3216 | |
| 3217 | /** |
| 3218 | * Animates Launcher elements during a transition to the Widgets pages. |
| 3219 | * |
| 3220 | * @param progress Transition progress from 0 to 1; where 0 => home and 1 => widgets. |
| 3221 | */ |
| 3222 | public void onWidgetsTransition(float progress) { |
| 3223 | // No-Op |
| 3224 | } |
| 3225 | |
Sunny Goyal | 6c0c61a | 2020-12-08 19:19:56 -0800 | [diff] [blame] | 3226 | private static class NonConfigInstance { |
| 3227 | public Configuration config; |
| 3228 | public Bitmap snapshot; |
| 3229 | } |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 3230 | |
| 3231 | @Override |
| 3232 | public StatsLogManager getStatsLogManager() { |
| 3233 | return super.getStatsLogManager().withDefaultInstanceId(mAllAppsSessionLogId); |
| 3234 | } |
Brian Isganitis | 149dbcb | 2021-11-08 18:12:38 -0500 | [diff] [blame] | 3235 | |
| 3236 | /** |
| 3237 | * Returns the current popup for testing, if any. |
| 3238 | */ |
| 3239 | @VisibleForTesting |
| 3240 | @Nullable |
| 3241 | public ArrowPopup<?> getOptionsPopup() { |
| 3242 | return findViewById(R.id.popup_container); |
| 3243 | } |
Schneider Victor-tulias | 789a6a9 | 2022-03-04 12:06:09 -0800 | [diff] [blame] | 3244 | |
| 3245 | /** Pauses view updates that should not be run during the app launch animation. */ |
| 3246 | public void pauseExpensiveViewUpdates() { |
| 3247 | // Pause page indicator animations as they lead to layer trashing. |
Shikha Malhotra | e957b60 | 2022-04-11 07:57:18 +0000 | [diff] [blame] | 3248 | getWorkspace().getPageIndicator().pauseAnimations(); |
Jon Miranda | 46ecc0c | 2022-06-02 11:34:15 -0700 | [diff] [blame] | 3249 | |
| 3250 | getWorkspace().mapOverItems((info, view) -> { |
| 3251 | if (view instanceof LauncherAppWidgetHostView) { |
| 3252 | ((LauncherAppWidgetHostView) view).beginDeferringUpdates(); |
| 3253 | } |
| 3254 | return false; // Return false to continue iterating through all the items. |
| 3255 | }); |
Schneider Victor-tulias | 789a6a9 | 2022-03-04 12:06:09 -0800 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | /** Resumes view updates at the end of the app launch animation. */ |
| 3259 | public void resumeExpensiveViewUpdates() { |
Shikha Malhotra | e957b60 | 2022-04-11 07:57:18 +0000 | [diff] [blame] | 3260 | getWorkspace().getPageIndicator().skipAnimationsToEnd(); |
Shikha Malhotra | 0f2e1b6 | 2022-03-27 21:02:21 +0000 | [diff] [blame] | 3261 | |
Jon Miranda | 46ecc0c | 2022-06-02 11:34:15 -0700 | [diff] [blame] | 3262 | getWorkspace().mapOverItems((info, view) -> { |
| 3263 | if (view instanceof LauncherAppWidgetHostView) { |
| 3264 | ((LauncherAppWidgetHostView) view).endDeferringUpdates(); |
| 3265 | } |
| 3266 | return false; // Return false to continue iterating through all the items. |
| 3267 | }); |
| 3268 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3269 | } |