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