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