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