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