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