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