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