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 | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 20 | import android.animation.Animator; |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 21 | import android.animation.AnimatorListenerAdapter; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 22 | import android.animation.AnimatorSet; |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 24 | import android.animation.ValueAnimator; |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 25 | import android.annotation.SuppressLint; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 26 | import android.annotation.TargetApi; |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 27 | import android.app.ActivityOptions; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 28 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 29 | import android.app.SearchManager; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 30 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 31 | import android.appwidget.AppWidgetManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 33 | import android.content.BroadcastReceiver; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 34 | import android.content.ComponentCallbacks2; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 35 | import android.content.ComponentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.content.Context; |
Andrew Sapperstein | abef55a | 2016-06-19 12:49:00 -0700 | [diff] [blame] | 37 | import android.content.ContextWrapper; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 38 | import android.content.DialogInterface; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 40 | import android.content.IntentFilter; |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 41 | import android.content.IntentSender; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 42 | import android.content.SharedPreferences; |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 43 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 44 | import android.content.pm.ActivityInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 46 | import android.database.sqlite.SQLiteDatabase; |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 47 | import android.graphics.Point; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 48 | import android.graphics.Rect; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 49 | import android.graphics.drawable.Drawable; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 50 | import android.os.AsyncTask; |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 51 | import android.os.Build; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | import android.os.Bundle; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 53 | import android.os.Handler; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 54 | import android.os.Process; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 55 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 56 | import android.os.SystemClock; |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 57 | import android.os.Trace; |
Sunny Goyal | a1d1bf3 | 2015-06-26 13:24:53 -0700 | [diff] [blame] | 58 | import android.os.UserHandle; |
Tony Wickham | 86222d2 | 2017-03-29 15:30:43 -0700 | [diff] [blame] | 59 | import android.support.annotation.Nullable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 60 | import android.text.Selection; |
| 61 | import android.text.SpannableStringBuilder; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 62 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 63 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 64 | import android.util.Log; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 65 | import android.view.Display; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 66 | import android.view.HapticFeedbackConstants; |
| 67 | import android.view.KeyEvent; |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 68 | import android.view.KeyboardShortcutGroup; |
| 69 | import android.view.KeyboardShortcutInfo; |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 70 | import android.view.LayoutInflater; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 71 | import android.view.Menu; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 72 | import android.view.MotionEvent; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 73 | import android.view.View; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 74 | import android.view.View.OnLongClickListener; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 75 | import android.view.ViewGroup; |
| 76 | import android.view.ViewTreeObserver; |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 77 | import android.view.WindowManager; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 78 | import android.view.accessibility.AccessibilityEvent; |
Tony Wickham | e221725 | 2016-03-22 16:34:23 -0700 | [diff] [blame] | 79 | import android.view.accessibility.AccessibilityManager; |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 80 | import android.view.animation.OvershootInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 81 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 82 | import android.widget.Toast; |
Sunny Goyal | a1d1bf3 | 2015-06-26 13:24:53 -0700 | [diff] [blame] | 83 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 84 | import com.android.launcher3.DropTarget.DragObject; |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 85 | import com.android.launcher3.LauncherSettings.Favorites; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 86 | import com.android.launcher3.Workspace.ItemOperator; |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 87 | import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 88 | import com.android.launcher3.allapps.AllAppsContainerView; |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 89 | import com.android.launcher3.allapps.AllAppsTransitionController; |
Sunny Goyal | b5e65c8 | 2016-10-26 18:32:38 -0700 | [diff] [blame] | 90 | import com.android.launcher3.anim.AnimationLayerSet; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 91 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 92 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | 22ca9ec | 2017-05-18 15:03:13 -0700 | [diff] [blame] | 93 | import com.android.launcher3.compat.LauncherAppsCompatVO; |
Tony Wickham | e0c3323 | 2016-02-08 11:37:04 -0800 | [diff] [blame] | 94 | import com.android.launcher3.config.FeatureFlags; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 95 | import com.android.launcher3.dragndrop.DragController; |
| 96 | import com.android.launcher3.dragndrop.DragLayer; |
Sunny Goyal | 94b510c | 2016-08-16 15:36:48 -0700 | [diff] [blame] | 97 | import com.android.launcher3.dragndrop.DragOptions; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 98 | import com.android.launcher3.dragndrop.DragView; |
Sunny Goyal | b38fab7 | 2017-01-20 19:32:31 -0800 | [diff] [blame] | 99 | import com.android.launcher3.dragndrop.PinItemDragListener; |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 100 | import com.android.launcher3.dynamicui.ExtractedColors; |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 101 | import com.android.launcher3.dynamicui.WallpaperColorInfo; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 102 | import com.android.launcher3.folder.Folder; |
| 103 | import com.android.launcher3.folder.FolderIcon; |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 104 | import com.android.launcher3.keyboard.CustomActionsPopup; |
Sunny Goyal | 3333b0c | 2016-05-09 20:43:21 -0700 | [diff] [blame] | 105 | import com.android.launcher3.keyboard.ViewGroupFocusHelper; |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 106 | import com.android.launcher3.logging.FileLog; |
Hyunyoung Song | aa95365 | 2016-04-19 18:30:24 -0700 | [diff] [blame] | 107 | import com.android.launcher3.logging.UserEventDispatcher; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 108 | import com.android.launcher3.model.ModelWriter; |
Sunny Goyal | d164b7f | 2016-10-12 20:49:31 -0700 | [diff] [blame] | 109 | import com.android.launcher3.model.PackageItemInfo; |
| 110 | import com.android.launcher3.model.WidgetItem; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 111 | import com.android.launcher3.notification.NotificationListener; |
Hyunyoung Song | 7d2fc81 | 2016-06-15 12:51:30 -0700 | [diff] [blame] | 112 | import com.android.launcher3.pageindicators.PageIndicator; |
Tony Wickham | 540913e | 2017-01-23 11:47:51 -0800 | [diff] [blame] | 113 | import com.android.launcher3.popup.PopupContainerWithArrow; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 114 | import com.android.launcher3.popup.PopupDataProvider; |
Tony Wickham | 1bce7fd | 2016-04-28 17:39:03 -0700 | [diff] [blame] | 115 | import com.android.launcher3.shortcuts.DeepShortcutManager; |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 116 | import com.android.launcher3.shortcuts.ShortcutKey; |
Jon Miranda | c6cf493 | 2017-02-07 17:12:36 -0800 | [diff] [blame] | 117 | import com.android.launcher3.userevent.nano.LauncherLogProto; |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 118 | import com.android.launcher3.userevent.nano.LauncherLogProto.Action; |
| 119 | import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; |
| 120 | import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 121 | import com.android.launcher3.util.ActivityResultInfo; |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 122 | import com.android.launcher3.util.RunnableWithId; |
Winson Chung | 6b1c73f | 2015-06-18 11:38:42 -0700 | [diff] [blame] | 123 | import com.android.launcher3.util.ComponentKey; |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 124 | import com.android.launcher3.util.ItemInfoMatcher; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 125 | import com.android.launcher3.util.MultiHashMap; |
Sunny Goyal | 04cc3a7 | 2016-05-17 10:32:43 -0700 | [diff] [blame] | 126 | import com.android.launcher3.util.PackageManagerHelper; |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 127 | import com.android.launcher3.util.PackageUserKey; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 128 | import com.android.launcher3.util.PendingRequestArgs; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 129 | import com.android.launcher3.util.SystemUiController; |
Sunny Goyal | 322d556 | 2015-06-25 19:35:49 -0700 | [diff] [blame] | 130 | import com.android.launcher3.util.TestingUtils; |
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 | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 133 | import com.android.launcher3.util.ViewOnDrawExecutor; |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 134 | import com.android.launcher3.widget.PendingAddShortcutInfo; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 135 | import com.android.launcher3.widget.PendingAddWidgetInfo; |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 136 | import com.android.launcher3.widget.WidgetAddFlowHandler; |
Hyunyoung Song | b99ff3e | 2015-04-23 15:17:50 -0700 | [diff] [blame] | 137 | import com.android.launcher3.widget.WidgetHostViewLoader; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 138 | import com.android.launcher3.widget.WidgetsContainerView; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 139 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 140 | import java.io.FileDescriptor; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 141 | import java.io.PrintWriter; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 142 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 143 | import java.util.Collection; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 144 | import java.util.HashMap; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 145 | import java.util.HashSet; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 146 | import java.util.List; |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 147 | import java.util.Set; |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 148 | import java.util.concurrent.Executor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 149 | |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 150 | import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS; |
| 151 | import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS; |
| 152 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | /** |
| 154 | * Default launcher application. |
| 155 | */ |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 156 | public class Launcher extends BaseActivity |
Adam Cohen | 79d90c5 | 2016-04-22 13:29:20 -0700 | [diff] [blame] | 157 | implements LauncherExterns, View.OnClickListener, OnLongClickListener, |
| 158 | LauncherModel.Callbacks, View.OnTouchListener, LauncherProviderChangeListener, |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 159 | AccessibilityManager.AccessibilityStateChangeListener, |
| 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 | |
Sunny Goyal | c84e6e1 | 2015-10-02 12:48:37 -0700 | [diff] [blame] | 164 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 165 | static final boolean DEBUG_STRICT_MODE = false; |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 166 | static final boolean DEBUG_RESUME_TIME = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 167 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 168 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 169 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 170 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 171 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 172 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 173 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 174 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 175 | private static final int REQUEST_BIND_PENDING_APPWIDGET = 12; |
| 176 | private static final int REQUEST_RECONFIGURE_APPWIDGET = 13; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 177 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 178 | private static final int REQUEST_PERMISSION_CALL_PHONE = 14; |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 179 | |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 180 | private static final float BOUNCE_ANIMATION_TENSION = 1.3f; |
| 181 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 182 | /** |
| 183 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 184 | * request codes used internally. |
| 185 | */ |
| 186 | protected static final int REQUEST_LAST = 100; |
| 187 | |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 188 | private static final int SOFT_INPUT_MODE_DEFAULT = |
Jon Miranda | fd51632 | 2017-03-09 13:14:50 -0800 | [diff] [blame] | 189 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 190 | private static final int SOFT_INPUT_MODE_ALL_APPS = |
Jon Miranda | fd51632 | 2017-03-09 13:14:50 -0800 | [diff] [blame] | 191 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 192 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 193 | // The Intent extra that defines whether to ignore the launch animation |
| 194 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 195 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 196 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 197 | // Type: int |
| 198 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 199 | // Type: int |
| 200 | private static final String RUNTIME_STATE = "launcher.state"; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 201 | // Type: PendingRequestArgs |
| 202 | private static final String RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args"; |
| 203 | // Type: ActivityResultInfo |
| 204 | private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 205 | |
Hyunyoung Song | c001cf5 | 2016-07-21 17:32:43 -0700 | [diff] [blame] | 206 | static final String APPS_VIEW_SHOWN = "launcher.apps_view_shown"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 207 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 208 | /** The different states that Launcher can be in. */ |
Tony Wickham | 94e0d37 | 2015-09-11 12:17:48 -0700 | [diff] [blame] | 209 | enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED, |
| 210 | WIDGETS, WIDGETS_SPRING_LOADED } |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 211 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 212 | @Thunk State mState = State.WORKSPACE; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 213 | @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 214 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 215 | private boolean mIsSafeModeEnabled; |
| 216 | |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 217 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 500; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 218 | 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] | 219 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 220 | // 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] | 221 | private static final int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 222 | private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
| 223 | @Thunk static final int NEW_APPS_ANIMATION_DELAY = 500; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 224 | |
Sunny Goyal | 60820d7 | 2017-05-09 12:40:11 -0700 | [diff] [blame] | 225 | private final ExtractedColors mExtractedColors = new ExtractedColors(); |
| 226 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 227 | @Thunk Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 228 | private View mLauncherView; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 229 | @Thunk DragLayer mDragLayer; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 230 | private DragController mDragController; |
Sunny Goyal | 322d556 | 2015-06-25 19:35:49 -0700 | [diff] [blame] | 231 | |
| 232 | public View mWeightWatcher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 233 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 234 | private AppWidgetManagerCompat mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 235 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 236 | |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 237 | private final int[] mTmpAddItemCellCoordinates = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 238 | |
Sunny Goyal | 316490e | 2015-06-02 09:38:28 -0700 | [diff] [blame] | 239 | @Thunk Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 240 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 241 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 242 | private View mAllAppsButton; |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 243 | private View mWidgetsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 244 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 245 | private DropTargetBar mDropTargetBar; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 246 | |
| 247 | // Main container view for the all apps screen. |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 248 | @Thunk AllAppsContainerView mAppsView; |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 249 | AllAppsTransitionController mAllAppsController; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 250 | |
Hyunyoung Song | 2bd3d7d | 2015-05-21 13:04:53 -0700 | [diff] [blame] | 251 | // Main container view and the model for the widget tray screen. |
| 252 | @Thunk WidgetsContainerView mWidgetsView; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 253 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 254 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 255 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 256 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 257 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 258 | |
| 259 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 260 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 261 | @Thunk boolean mWorkspaceLoading = true; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 262 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 263 | private boolean mPaused = true; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 264 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 265 | |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 266 | private final ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<>(); |
| 267 | private final ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<>(); |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 268 | private ViewOnDrawExecutor mPendingExecutor; |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 269 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 270 | private LauncherModel mModel; |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 271 | private ModelWriter mModelWriter; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 272 | private IconCache mIconCache; |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 273 | private LauncherAccessibilityDelegate mAccessibilityDelegate; |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 274 | private final Handler mHandler = new Handler(); |
Hyunyoung Song | c001cf5 | 2016-07-21 17:32:43 -0700 | [diff] [blame] | 275 | private boolean mIsResumeFromActionScreenOff; |
Sunny Goyal | 1acc56a | 2016-09-25 21:23:25 -0700 | [diff] [blame] | 276 | private boolean mHasFocus = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 277 | |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 278 | private ObjectAnimator mScrimAnimator; |
Jon Miranda | 7fda285 | 2017-07-19 16:07:01 -0700 | [diff] [blame] | 279 | private boolean mShouldFadeInScrim; |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 280 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 281 | private PopupDataProvider mPopupDataProvider; |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 282 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 283 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 284 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 285 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 286 | // match the sensor state. |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 287 | private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 288 | |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 289 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<>(); |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 290 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 291 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 292 | // it from the context. |
| 293 | private SharedPreferences mSharedPrefs; |
| 294 | |
Adam Cohen | 4b66bf3 | 2015-09-18 12:15:19 -0700 | [diff] [blame] | 295 | private boolean mMoveToDefaultScreenFromNewIntent; |
| 296 | |
Winson Chung | 13eb527 | 2015-05-11 16:30:13 -0700 | [diff] [blame] | 297 | // This is set to the view that launched the activity that navigated the user away from |
| 298 | // launcher. Since there is no callback for when the activity has finished launching, enable |
| 299 | // the press state and keep this reference to reset the press state when we return to launcher. |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 300 | private BubbleTextView mWaitingForResume; |
| 301 | |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 302 | protected static final HashMap<String, CustomAppWidget> sCustomAppWidgets = |
| 303 | new HashMap<>(); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 304 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 305 | static { |
Sunny Goyal | 322d556 | 2015-06-25 19:35:49 -0700 | [diff] [blame] | 306 | if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) { |
| 307 | TestingUtils.addDummyWidget(sCustomAppWidgets); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
Hyunyoung Song | 06ca756 | 2016-07-29 13:03:54 -0700 | [diff] [blame] | 311 | // Exiting spring loaded mode happens with a delay. This runnable object triggers the |
| 312 | // state transition. If another state transition happened during this delay, |
| 313 | // simply unregister this runnable. |
| 314 | private Runnable mExitSpringLoadedModeRunnable; |
| 315 | |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 316 | @Thunk final Runnable mBuildLayersRunnable = new Runnable() { |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 317 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 318 | if (mWorkspace != null) { |
| 319 | mWorkspace.buildPageHardwareLayers(); |
| 320 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 321 | } |
| 322 | }; |
| 323 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 324 | // Activity result which needs to be processed after workspace has loaded. |
| 325 | private ActivityResultInfo mPendingActivityResult; |
| 326 | /** |
| 327 | * Holds extra information required to handle a result from an external call, like |
| 328 | * {@link #startActivityForResult(Intent, int)} or {@link #requestPermissions(String[], int)} |
| 329 | */ |
| 330 | private PendingRequestArgs mPendingRequestArgs; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 331 | |
Jon Miranda | 379198e | 2016-09-23 08:54:40 -0700 | [diff] [blame] | 332 | private float mLastDispatchTouchEventX = 0.0f; |
Jon Miranda | 379198e | 2016-09-23 08:54:40 -0700 | [diff] [blame] | 333 | |
Sunny Goyal | 3333b0c | 2016-05-09 20:43:21 -0700 | [diff] [blame] | 334 | public ViewGroupFocusHelper mFocusHandler; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 335 | private boolean mRotationEnabled = false; |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 336 | |
| 337 | @Thunk void setOrientation() { |
| 338 | if (mRotationEnabled) { |
| 339 | unlockScreenOrientation(true); |
| 340 | } else { |
| 341 | setRequestedOrientation( |
| 342 | ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 343 | } |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 344 | } |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 345 | |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 346 | private RotationPrefChangeHandler mRotationPrefChangeHandler; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 347 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 348 | @Override |
| 349 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 350 | if (DEBUG_STRICT_MODE) { |
| 351 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 352 | .detectDiskReads() |
| 353 | .detectDiskWrites() |
| 354 | .detectNetwork() // or .detectAll() for all detectable problems |
| 355 | .penaltyLog() |
| 356 | .build()); |
| 357 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 358 | .detectLeakedSqlLiteObjects() |
| 359 | .detectLeakedClosableObjects() |
| 360 | .penaltyLog() |
| 361 | .penaltyDeath() |
| 362 | .build()); |
| 363 | } |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 364 | if (LauncherAppState.PROFILE_STARTUP) { |
| 365 | Trace.beginSection("Launcher-onCreate"); |
| 366 | } |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 367 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 368 | if (mLauncherCallbacks != null) { |
| 369 | mLauncherCallbacks.preOnCreate(); |
| 370 | } |
| 371 | |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 372 | WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this); |
| 373 | wallpaperColorInfo.setOnThemeChangeListener(this); |
Mario Bertschler | a693694 | 2017-05-31 14:48:19 -0700 | [diff] [blame] | 374 | overrideTheme(wallpaperColorInfo.isDark(), wallpaperColorInfo.supportsDarkText()); |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 375 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 376 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 377 | |
Sunny Goyal | 87f784c | 2017-01-11 10:48:34 -0800 | [diff] [blame] | 378 | LauncherAppState app = LauncherAppState.getInstance(this); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 379 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 380 | // Load configuration-specific DeviceProfile |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 381 | mDeviceProfile = app.getInvariantDeviceProfile().getDeviceProfile(this); |
Jon Miranda | fe96432 | 2017-03-22 10:25:17 -0700 | [diff] [blame] | 382 | if (isInMultiWindowModeCompat()) { |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 383 | Display display = getWindowManager().getDefaultDisplay(); |
| 384 | Point mwSize = new Point(); |
| 385 | display.getSize(mwSize); |
| 386 | mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize); |
| 387 | } |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 388 | |
Sunny Goyal | f725824 | 2015-10-19 16:59:07 -0700 | [diff] [blame] | 389 | mSharedPrefs = Utilities.getPrefs(this); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 390 | mIsSafeModeEnabled = getPackageManager().isSafeMode(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 391 | mModel = app.setLauncher(this); |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 392 | mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout()); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 393 | mIconCache = app.getIconCache(); |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 394 | mAccessibilityDelegate = new LauncherAccessibilityDelegate(this); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 395 | |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 396 | mDragController = new DragController(this); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 397 | mAllAppsController = new AllAppsTransitionController(this); |
| 398 | mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, mAllAppsController); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 399 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 400 | mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 401 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 402 | mAppWidgetHost = new LauncherAppWidgetHost(this); |
| 403 | if (Utilities.ATLEAST_MARSHMALLOW) { |
| 404 | mAppWidgetHost.addProviderChangeListener(this); |
| 405 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 406 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 407 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 408 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 409 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 410 | // LauncherModel load. |
| 411 | mPaused = false; |
| 412 | |
Sunny Goyal | 60820d7 | 2017-05-09 12:40:11 -0700 | [diff] [blame] | 413 | mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 414 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 415 | setupViews(); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 416 | mDeviceProfile.layout(this, false /* notifyListeners */); |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 417 | loadExtractedColorsAndColorItems(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 418 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 419 | mPopupDataProvider = new PopupDataProvider(this); |
| 420 | |
Tony Wickham | e221725 | 2016-03-22 16:34:23 -0700 | [diff] [blame] | 421 | ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)) |
| 422 | .addAccessibilityStateChangeListener(this); |
| 423 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 424 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 425 | |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 426 | restoreState(savedInstanceState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 427 | |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 428 | if (LauncherAppState.PROFILE_STARTUP) { |
| 429 | Trace.endSection(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 432 | // We only load the page synchronously if the user rotates (or triggers a |
| 433 | // configuration change) while launcher is in the foreground |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 434 | int currentScreen = PagedView.INVALID_RESTORE_PAGE; |
| 435 | if (savedInstanceState != null) { |
| 436 | currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen); |
| 437 | } |
| 438 | if (!mModel.startLoader(currentScreen)) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 439 | // If we are not binding synchronously, show a fade in animation when |
| 440 | // the first page bind completes. |
| 441 | mDragLayer.setAlpha(0); |
| 442 | } else { |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 443 | // Pages bound synchronously. |
| 444 | mWorkspace.setCurrentPage(currentScreen); |
| 445 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 446 | setWorkspaceLoading(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | // For handling default keys |
| 450 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 451 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 452 | |
Sunny Goyal | 8f3819b | 2016-02-23 14:49:22 -0800 | [diff] [blame] | 453 | mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation); |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 454 | // In case we are on a device with locked rotation, we should look at preferences to check |
| 455 | // if the user has specifically allowed rotation. |
| 456 | if (!mRotationEnabled) { |
Sunny Goyal | 21bf531 | 2015-08-21 11:08:24 -0700 | [diff] [blame] | 457 | mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext()); |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 458 | mRotationPrefChangeHandler = new RotationPrefChangeHandler(); |
| 459 | mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler); |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Sunny Goyal | 5a81c38 | 2017-03-20 15:08:06 -0700 | [diff] [blame] | 462 | if (PinItemDragListener.handleDragRequest(this, getIntent())) { |
| 463 | // Temporarily enable the rotation |
| 464 | mRotationEnabled = true; |
| 465 | } |
| 466 | |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 467 | // On large interfaces, or on devices that a user has specifically enabled screen rotation, |
| 468 | // we want the screen to auto-rotate based on the current orientation |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 469 | setOrientation(); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 470 | |
Sunny Goyal | 0bbd554 | 2016-11-11 10:41:26 -0800 | [diff] [blame] | 471 | setContentView(mLauncherView); |
Mario Bertschler | a693694 | 2017-05-31 14:48:19 -0700 | [diff] [blame] | 472 | |
Jon Miranda | 7fda285 | 2017-07-19 16:07:01 -0700 | [diff] [blame] | 473 | // Listen for broadcasts |
| 474 | IntentFilter filter = new IntentFilter(); |
| 475 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 476 | filter.addAction(Intent.ACTION_USER_PRESENT); // When the device wakes up + keyguard is gone |
| 477 | registerReceiver(mReceiver, filter); |
| 478 | mShouldFadeInScrim = true; |
Sunny Goyal | a616d2b | 2017-06-12 13:54:01 -0700 | [diff] [blame] | 479 | |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 480 | getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW, |
| 481 | Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText)); |
Sunny Goyal | 14b3240 | 2017-07-31 10:03:28 -0700 | [diff] [blame] | 482 | |
| 483 | if (mLauncherCallbacks != null) { |
| 484 | mLauncherCallbacks.onCreate(savedInstanceState); |
| 485 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 488 | @Override |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 489 | public void onThemeChanged() { |
| 490 | recreate(); |
| 491 | } |
| 492 | |
Mario Bertschler | a693694 | 2017-05-31 14:48:19 -0700 | [diff] [blame] | 493 | protected void overrideTheme(boolean isDark, boolean supportsDarkText) { |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 494 | if (isDark) { |
| 495 | setTheme(R.style.LauncherThemeDark); |
Mario Bertschler | a693694 | 2017-05-31 14:48:19 -0700 | [diff] [blame] | 496 | } else if (supportsDarkText) { |
| 497 | setTheme(R.style.LauncherThemeDarkText); |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| 501 | @Override |
Sunny Goyal | c7b8df8 | 2017-06-27 11:11:03 -0700 | [diff] [blame] | 502 | public <T extends View> T findViewById(int id) { |
Sunny Goyal | 0bbd554 | 2016-11-11 10:41:26 -0800 | [diff] [blame] | 503 | return mLauncherView.findViewById(id); |
| 504 | } |
| 505 | |
| 506 | @Override |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 507 | public void onExtractedColorsChanged() { |
| 508 | loadExtractedColorsAndColorItems(); |
Sunny Goyal | 60820d7 | 2017-05-09 12:40:11 -0700 | [diff] [blame] | 509 | mExtractedColors.notifyChange(); |
Sunny Goyal | 5e7b238 | 2017-04-25 23:09:06 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | public ExtractedColors getExtractedColors() { |
| 513 | return mExtractedColors; |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Sunny Goyal | 2e013ea | 2016-10-07 16:17:19 -0700 | [diff] [blame] | 516 | @Override |
| 517 | public void onAppWidgetHostReset() { |
| 518 | if (mAppWidgetHost != null) { |
| 519 | mAppWidgetHost.startListening(); |
| 520 | } |
| 521 | } |
| 522 | |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 523 | private void loadExtractedColorsAndColorItems() { |
Tony Wickham | 462b5cc | 2016-04-01 16:00:49 -0700 | [diff] [blame] | 524 | // TODO: do this in pre-N as well, once the extraction part is complete. |
Sunny Goyal | f5e3744 | 2016-11-02 10:31:24 -0700 | [diff] [blame] | 525 | if (Utilities.ATLEAST_NOUGAT) { |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 526 | mExtractedColors.load(this); |
Tony Wickham | 462b5cc | 2016-04-01 16:00:49 -0700 | [diff] [blame] | 527 | mHotseat.updateColor(mExtractedColors, !mPaused); |
Sunny Goyal | d0a6ae7 | 2016-06-16 12:29:03 -0700 | [diff] [blame] | 528 | mWorkspace.getPageIndicator().updateColor(mExtractedColors); |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 532 | private LauncherCallbacks mLauncherCallbacks; |
| 533 | |
| 534 | public void onPostCreate(Bundle savedInstanceState) { |
| 535 | super.onPostCreate(savedInstanceState); |
| 536 | if (mLauncherCallbacks != null) { |
| 537 | mLauncherCallbacks.onPostCreate(savedInstanceState); |
| 538 | } |
| 539 | } |
| 540 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 541 | public void onInsetsChanged(Rect insets) { |
| 542 | mDeviceProfile.updateInsets(insets); |
| 543 | mDeviceProfile.layout(this, true /* notifyListeners */); |
| 544 | } |
| 545 | |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 546 | /** |
| 547 | * Call this after onCreate to set or clear overlay. |
| 548 | */ |
| 549 | public void setLauncherOverlay(LauncherOverlay overlay) { |
| 550 | if (overlay != null) { |
| 551 | overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl()); |
| 552 | } |
| 553 | mWorkspace.setLauncherOverlay(overlay); |
| 554 | } |
| 555 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 556 | public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { |
| 557 | mLauncherCallbacks = callbacks; |
| 558 | return true; |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 561 | @Override |
Sunny Goyal | 2e013ea | 2016-10-07 16:17:19 -0700 | [diff] [blame] | 562 | public void onLauncherProviderChanged() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 563 | if (mLauncherCallbacks != null) { |
| 564 | mLauncherCallbacks.onLauncherProviderChange(); |
| 565 | } |
| 566 | } |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 567 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 568 | /** To be overridden by subclasses to hint to Launcher that we have custom content */ |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 569 | protected boolean hasCustomContentToLeft() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 570 | if (mLauncherCallbacks != null) { |
| 571 | return mLauncherCallbacks.hasCustomContentToLeft(); |
| 572 | } |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 573 | return false; |
| 574 | } |
| 575 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 576 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 577 | * To be overridden by subclasses to populate the custom content container and call |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 578 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 579 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 580 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 581 | protected void populateCustomContentContainer() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 582 | if (mLauncherCallbacks != null) { |
| 583 | mLauncherCallbacks.populateCustomContentContainer(); |
| 584 | } |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /** |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 588 | * Invoked by subclasses to signal a change to the {@link #addToCustomContentPage} value to |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 589 | * ensure the custom content page is added or removed if necessary. |
| 590 | */ |
| 591 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 592 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 593 | // Not bound yet, wait for bindScreens to be called. |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 598 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 599 | mWorkspace.createCustomContentContainer(); |
| 600 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 601 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 602 | mWorkspace.removeCustomContentPage(); |
| 603 | } |
| 604 | } |
| 605 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 606 | public boolean isDraggingEnabled() { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 607 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 608 | // that is subsequently removed from the workspace in startBinding(). |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 609 | return !isWorkspaceLoading(); |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 612 | public int getViewIdForItem(ItemInfo info) { |
Sunny Goyal | e2fd14b | 2015-08-27 17:45:46 -0700 | [diff] [blame] | 613 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 614 | // This cast is safe as long as the id < 0x00FFFFFF |
| 615 | // Since we jail all the dynamically generated views, there should be no clashes |
| 616 | // with any other views. |
| 617 | return (int) info.id; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 620 | public PopupDataProvider getPopupDataProvider() { |
| 621 | return mPopupDataProvider; |
| 622 | } |
| 623 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 624 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 625 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 626 | * a configuration step, this allows the proper animations to run after other transitions. |
| 627 | */ |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 628 | private long completeAdd( |
| 629 | int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) { |
| 630 | long screenId = info.screenId; |
| 631 | if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 632 | // When the screen id represents an actual screen (as opposed to a rank) we make sure |
| 633 | // that the drop page actually exists. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 634 | screenId = ensurePendingDropLayoutExists(info.screenId); |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 635 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 636 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 637 | switch (requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 638 | case REQUEST_CREATE_SHORTCUT: |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 639 | completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 640 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 641 | case REQUEST_CREATE_APPWIDGET: |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 642 | completeAddAppWidget(appWidgetId, info, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 643 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 644 | case REQUEST_RECONFIGURE_APPWIDGET: |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 645 | completeRestoreAppWidget(appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 646 | break; |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 647 | case REQUEST_BIND_PENDING_APPWIDGET: { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 648 | int widgetId = appWidgetId; |
| 649 | LauncherAppWidgetInfo widgetInfo = |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 650 | completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 651 | if (widgetInfo != null) { |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 652 | // Since the view was just bound, also launch the configure activity if needed |
| 653 | LauncherAppWidgetProviderInfo provider = mAppWidgetManager |
| 654 | .getLauncherAppWidgetInfo(widgetId); |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 655 | if (provider != null) { |
| 656 | new WidgetAddFlowHandler(provider) |
| 657 | .startConfigActivity(this, widgetInfo, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | break; |
| 661 | } |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 662 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 663 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 664 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 665 | } |
| 666 | |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 667 | private void handleActivityResult( |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 668 | final int requestCode, final int resultCode, final Intent data) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 669 | if (isWorkspaceLoading()) { |
| 670 | // process the result once the workspace has loaded. |
| 671 | mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data); |
| 672 | return; |
| 673 | } |
| 674 | mPendingActivityResult = null; |
| 675 | |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 676 | // Reset the startActivity waiting flag |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 677 | final PendingRequestArgs requestArgs = mPendingRequestArgs; |
| 678 | setWaitingForResult(null); |
| 679 | if (requestArgs == null) { |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | final int pendingAddWidgetId = requestArgs.getWidgetId(); |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 684 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 685 | Runnable exitSpringLoaded = new Runnable() { |
| 686 | @Override |
| 687 | public void run() { |
| 688 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 689 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 690 | } |
| 691 | }; |
| 692 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 693 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Winson | a1f79d3 | 2015-08-05 14:00:45 -0700 | [diff] [blame] | 694 | // 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] | 695 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 696 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 697 | if (resultCode == RESULT_CANCELED) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 698 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 699 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 700 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 701 | } else if (resultCode == RESULT_OK) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 702 | addAppWidgetImpl( |
| 703 | appWidgetId, requestArgs, null, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 704 | requestArgs.getWidgetHandler(), |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 705 | ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 706 | } |
| 707 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 708 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 709 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
Tony Wickham | e305441 | 2015-09-09 09:05:25 -0700 | [diff] [blame] | 710 | // User could have free-scrolled between pages before picking a wallpaper; make sure |
| 711 | // we move to the closest one now. |
| 712 | mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen()); |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 713 | showWorkspace(false); |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 714 | } |
| 715 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 716 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 717 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 718 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
Sunny Goyal | 5c97f51 | 2015-05-19 16:03:28 -0700 | [diff] [blame] | 719 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 720 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 721 | // We have special handling for widgets |
| 722 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 723 | final int appWidgetId; |
| 724 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 725 | : -1; |
| 726 | if (widgetId < 0) { |
| 727 | appWidgetId = pendingAddWidgetId; |
| 728 | } else { |
| 729 | appWidgetId = widgetId; |
| 730 | } |
| 731 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 732 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 733 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 734 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 735 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 736 | result = RESULT_CANCELED; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 737 | completeTwoStageWidgetDrop(result, appWidgetId, requestArgs); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 738 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 739 | @Override |
| 740 | public void run() { |
| 741 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 742 | } |
| 743 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 744 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 745 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 746 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 747 | } else { |
| 748 | if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 749 | // When the screen id represents an actual screen (as opposed to a rank) |
| 750 | // we make sure that the drop page actually exists. |
| 751 | requestArgs.screenId = |
| 752 | ensurePendingDropLayoutExists(requestArgs.screenId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 753 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 754 | final CellLayout dropLayout = |
| 755 | mWorkspace.getScreenWithId(requestArgs.screenId); |
| 756 | |
| 757 | dropLayout.setDropPending(true); |
| 758 | final Runnable onComplete = new Runnable() { |
| 759 | @Override |
| 760 | public void run() { |
| 761 | completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs); |
| 762 | dropLayout.setDropPending(false); |
| 763 | } |
| 764 | }; |
| 765 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 766 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 767 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 768 | return; |
| 769 | } |
| 770 | |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 771 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET |
| 772 | || requestCode == REQUEST_BIND_PENDING_APPWIDGET) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 773 | if (resultCode == RESULT_OK) { |
| 774 | // Update the widget view. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 775 | completeAdd(requestCode, data, pendingAddWidgetId, requestArgs); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 776 | } |
| 777 | // Leave the widget in the pending state if the user canceled the configure. |
| 778 | return; |
| 779 | } |
| 780 | |
Sunny Goyal | aad9058 | 2015-07-09 14:22:50 -0700 | [diff] [blame] | 781 | if (requestCode == REQUEST_CREATE_SHORTCUT) { |
| 782 | // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT. |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 783 | if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) { |
| 784 | completeAdd(requestCode, data, -1, requestArgs); |
| 785 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 786 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 787 | |
Sunny Goyal | aad9058 | 2015-07-09 14:22:50 -0700 | [diff] [blame] | 788 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 789 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 790 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 791 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 792 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 793 | mDragLayer.clearAnimatedView(); |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | @Override |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 797 | public void onActivityResult( |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 798 | final int requestCode, final int resultCode, final Intent data) { |
| 799 | handleActivityResult(requestCode, resultCode, data); |
| 800 | if (mLauncherCallbacks != null) { |
| 801 | mLauncherCallbacks.onActivityResult(requestCode, resultCode, data); |
| 802 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 803 | } |
| 804 | |
Dave Hawkey | 3a43ed6 | 2015-06-26 10:27:47 -0600 | [diff] [blame] | 805 | /** @Override for MNC */ |
Sunny Goyal | dd2e6df | 2015-07-07 10:57:57 -0700 | [diff] [blame] | 806 | public void onRequestPermissionsResult(int requestCode, String[] permissions, |
Dave Hawkey | 3a43ed6 | 2015-06-26 10:27:47 -0600 | [diff] [blame] | 807 | int[] grantResults) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 808 | PendingRequestArgs pendingArgs = mPendingRequestArgs; |
| 809 | if (requestCode == REQUEST_PERMISSION_CALL_PHONE && pendingArgs != null |
| 810 | && pendingArgs.getRequestCode() == REQUEST_PERMISSION_CALL_PHONE) { |
| 811 | setWaitingForResult(null); |
| 812 | |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 813 | View v = null; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 814 | CellLayout layout = getCellLayout(pendingArgs.container, pendingArgs.screenId); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 815 | if (layout != null) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 816 | v = layout.getChildAt(pendingArgs.cellX, pendingArgs.cellY); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 817 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 818 | Intent intent = pendingArgs.getPendingIntent(); |
| 819 | |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 820 | if (grantResults.length > 0 |
| 821 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
Sunny Goyal | 85fc55a | 2016-05-31 10:44:03 -0700 | [diff] [blame] | 822 | startActivitySafely(v, intent, null); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 823 | } else { |
| 824 | // TODO: Show a snack bar with link to settings |
| 825 | Toast.makeText(this, getString(R.string.msg_no_phone_permission, |
Sunny Goyal | 112ce42 | 2016-08-22 16:45:29 -0700 | [diff] [blame] | 826 | getString(R.string.derived_app_name)), Toast.LENGTH_SHORT).show(); |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
Dave Hawkey | 3a43ed6 | 2015-06-26 10:27:47 -0600 | [diff] [blame] | 829 | if (mLauncherCallbacks != null) { |
| 830 | mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions, |
| 831 | grantResults); |
| 832 | } |
| 833 | } |
| 834 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 835 | /** |
| 836 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 837 | * |
| 838 | * @param screenId the screen id to check |
| 839 | * @return the new screen, or screenId if it exists |
| 840 | */ |
| 841 | private long ensurePendingDropLayoutExists(long screenId) { |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 842 | CellLayout dropLayout = mWorkspace.getScreenWithId(screenId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 843 | if (dropLayout == null) { |
| 844 | // it's possible that the add screen was removed because it was |
| 845 | // empty and a re-bind occurred |
| 846 | mWorkspace.addExtraEmptyScreen(); |
| 847 | return mWorkspace.commitExtraEmptyScreen(); |
| 848 | } else { |
| 849 | return screenId; |
| 850 | } |
| 851 | } |
| 852 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 853 | @Thunk void completeTwoStageWidgetDrop( |
| 854 | final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) { |
| 855 | CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 856 | Runnable onCompleteRunnable = null; |
| 857 | int animationType = 0; |
| 858 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 859 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 860 | if (resultCode == RESULT_OK) { |
| 861 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 862 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 863 | requestArgs.getWidgetHandler().getProviderInfo(this)); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 864 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 865 | onCompleteRunnable = new Runnable() { |
| 866 | @Override |
| 867 | public void run() { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 868 | completeAddAppWidget(appWidgetId, requestArgs, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 869 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 870 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 871 | } |
| 872 | }; |
| 873 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 874 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 875 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 876 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 877 | if (mDragLayer.getAnimatedView() != null) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 878 | mWorkspace.animateWidgetDrop(requestArgs, cellLayout, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 879 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 880 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 881 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 882 | // The animated view may be null in the case of a rotation during widget configuration |
| 883 | onCompleteRunnable.run(); |
| 884 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 888 | protected void onStop() { |
| 889 | super.onStop(); |
| 890 | FirstFrameAnimatorHelper.setIsVisible(false); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 891 | |
| 892 | if (mLauncherCallbacks != null) { |
| 893 | mLauncherCallbacks.onStop(); |
| 894 | } |
Sunny Goyal | 5da78f4 | 2016-06-17 14:00:22 -0700 | [diff] [blame] | 895 | |
Sunny Goyal | f5e3744 | 2016-11-02 10:31:24 -0700 | [diff] [blame] | 896 | if (Utilities.ATLEAST_NOUGAT_MR1) { |
Sunny Goyal | 5da78f4 | 2016-06-17 14:00:22 -0700 | [diff] [blame] | 897 | mAppWidgetHost.stopListening(); |
| 898 | } |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 899 | |
| 900 | NotificationListener.removeNotificationsChangedListener(); |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | @Override |
| 904 | protected void onStart() { |
| 905 | super.onStart(); |
| 906 | FirstFrameAnimatorHelper.setIsVisible(true); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 907 | |
| 908 | if (mLauncherCallbacks != null) { |
| 909 | mLauncherCallbacks.onStart(); |
| 910 | } |
Sunny Goyal | 5da78f4 | 2016-06-17 14:00:22 -0700 | [diff] [blame] | 911 | |
Sunny Goyal | f5e3744 | 2016-11-02 10:31:24 -0700 | [diff] [blame] | 912 | if (Utilities.ATLEAST_NOUGAT_MR1) { |
Sunny Goyal | 5da78f4 | 2016-06-17 14:00:22 -0700 | [diff] [blame] | 913 | mAppWidgetHost.startListening(); |
| 914 | } |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 915 | |
| 916 | if (!isWorkspaceLoading()) { |
| 917 | NotificationListener.setNotificationsChangedListener(mPopupDataProvider); |
| 918 | } |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 919 | |
Jon Miranda | 7fda285 | 2017-07-19 16:07:01 -0700 | [diff] [blame] | 920 | if (mShouldFadeInScrim && mDragLayer.getBackground() != null) { |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 921 | if (mScrimAnimator != null) { |
| 922 | mScrimAnimator.cancel(); |
| 923 | } |
| 924 | mDragLayer.getBackground().setAlpha(0); |
| 925 | mScrimAnimator = ObjectAnimator.ofInt(mDragLayer.getBackground(), |
| 926 | LauncherAnimUtils.DRAWABLE_ALPHA, 0, 255); |
| 927 | mScrimAnimator.addListener(new AnimatorListenerAdapter() { |
| 928 | @Override |
| 929 | public void onAnimationEnd(Animator animation) { |
| 930 | mScrimAnimator = null; |
| 931 | } |
| 932 | }); |
| 933 | mScrimAnimator.setDuration(600); |
| 934 | mScrimAnimator.setStartDelay(getWindow().getTransitionBackgroundFadeDuration()); |
| 935 | mScrimAnimator.start(); |
| 936 | } |
Jon Miranda | 7fda285 | 2017-07-19 16:07:01 -0700 | [diff] [blame] | 937 | mShouldFadeInScrim = false; |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 941 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 942 | long startTime = 0; |
| 943 | if (DEBUG_RESUME_TIME) { |
| 944 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 945 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 946 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 947 | |
| 948 | if (mLauncherCallbacks != null) { |
| 949 | mLauncherCallbacks.preOnResume(); |
| 950 | } |
| 951 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 952 | super.onResume(); |
Hyunyoung Song | aa95365 | 2016-04-19 18:30:24 -0700 | [diff] [blame] | 953 | getUserEventDispatcher().resetElapsedSessionMillis(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 954 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 955 | // Restore the previous launcher state |
Winson Chung | 75cc825 | 2015-04-10 10:19:58 -0700 | [diff] [blame] | 956 | if (mOnResumeState == State.WORKSPACE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 957 | showWorkspace(false); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 958 | } else if (mOnResumeState == State.APPS) { |
Winson Chung | 13eb527 | 2015-05-11 16:30:13 -0700 | [diff] [blame] | 959 | boolean launchedFromApp = (mWaitingForResume != null); |
Winson Chung | 4ac3006 | 2015-05-08 17:34:17 -0700 | [diff] [blame] | 960 | // Don't update the predicted apps if the user is returning to launcher in the apps |
Winson Chung | 13eb527 | 2015-05-11 16:30:13 -0700 | [diff] [blame] | 961 | // view after launching an app, as they may be depending on the UI to be static to |
| 962 | // switch to another app, otherwise, if it was |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 963 | showAppsView(false /* animated */, !launchedFromApp /* updatePredictedApps */); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 964 | } else if (mOnResumeState == State.WIDGETS) { |
| 965 | showWidgetsView(false, false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 966 | } |
Jon Miranda | 7653a60 | 2017-07-28 10:09:34 -0700 | [diff] [blame] | 967 | if (mOnResumeState != State.APPS) { |
| 968 | tryAndUpdatePredictedApps(); |
| 969 | } |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 970 | mOnResumeState = State.NONE; |
| 971 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 972 | mPaused = false; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 973 | if (mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 974 | setWorkspaceLoading(true); |
Sunny Goyal | 93f878c | 2016-03-30 17:31:24 -0700 | [diff] [blame] | 975 | mModel.startLoader(getCurrentWorkspaceScreen()); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 976 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 977 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 978 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 979 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 980 | // execute them here |
| 981 | long startTimeCallbacks = 0; |
| 982 | if (DEBUG_RESUME_TIME) { |
| 983 | startTimeCallbacks = System.currentTimeMillis(); |
| 984 | } |
| 985 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 986 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 987 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 988 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 989 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 990 | if (DEBUG_RESUME_TIME) { |
| 991 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 992 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 993 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 994 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 995 | if (mOnResumeCallbacks.size() > 0) { |
| 996 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 997 | mOnResumeCallbacks.get(i).run(); |
| 998 | } |
| 999 | mOnResumeCallbacks.clear(); |
| 1000 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1001 | |
| 1002 | // Reset the pressed state of icons that were locked in the press state while activities |
| 1003 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1004 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1005 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1006 | mWaitingForResume.setStayPressed(false); |
| 1007 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 1008 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1009 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 1010 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 1011 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 1012 | // orientation. |
Sunny Goyal | 6bec75f | 2015-10-01 18:50:48 -0700 | [diff] [blame] | 1013 | if (!isWorkspaceLoading()) { |
| 1014 | getWorkspace().reinflateWidgetsIfNecessary(); |
| 1015 | } |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1016 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1017 | if (DEBUG_RESUME_TIME) { |
| 1018 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1019 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1020 | |
Adam Cohen | 4b66bf3 | 2015-09-18 12:15:19 -0700 | [diff] [blame] | 1021 | // We want to suppress callbacks about CustomContent being shown if we have just received |
| 1022 | // onNewIntent while the user was present within launcher. In that case, we post a call |
| 1023 | // to move the user to the main screen (which will occur after onResume). We don't want to |
| 1024 | // have onHide (from onPause), then onShow, then onHide again, which we get if we don't |
| 1025 | // suppress here. |
| 1026 | if (mWorkspace.getCustomContentCallbacks() != null |
| 1027 | && !mMoveToDefaultScreenFromNewIntent) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1028 | // If we are resuming and the custom content is the current page, we call onShow(). |
Adam Cohen | 4b66bf3 | 2015-09-18 12:15:19 -0700 | [diff] [blame] | 1029 | // It is also possible that onShow will instead be called slightly after first layout |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1030 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1031 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1032 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1033 | } |
| 1034 | } |
Adam Cohen | 4b66bf3 | 2015-09-18 12:15:19 -0700 | [diff] [blame] | 1035 | mMoveToDefaultScreenFromNewIntent = false; |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 1036 | updateInteraction(Workspace.State.NORMAL, mWorkspace.getState()); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1037 | mWorkspace.onResume(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1038 | |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 1039 | // Process any items that were added while Launcher was away. |
| 1040 | InstallShortcutReceiver.disableAndFlushInstallQueue( |
| 1041 | InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this); |
Sunny Goyal | 95f3d6b | 2016-08-10 16:09:29 -0700 | [diff] [blame] | 1042 | |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 1043 | // Refresh shortcuts if the permission changed. |
| 1044 | mModel.refreshShortcutsIfRequired(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1045 | |
Hyunyoung Song | c001cf5 | 2016-07-21 17:32:43 -0700 | [diff] [blame] | 1046 | if (shouldShowDiscoveryBounce()) { |
| 1047 | mAllAppsController.showDiscoveryBounce(); |
| 1048 | } |
| 1049 | mIsResumeFromActionScreenOff = false; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1050 | if (mLauncherCallbacks != null) { |
| 1051 | mLauncherCallbacks.onResume(); |
| 1052 | } |
Mario Bertschler | 0fc6f68 | 2017-02-17 12:16:13 -0800 | [diff] [blame] | 1053 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1056 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1057 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1058 | // Ensure that items added to Launcher are queued until Launcher returns |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 1059 | InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1060 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1061 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1062 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1063 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1064 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1065 | |
| 1066 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1067 | // debounce excess onHide calls. |
| 1068 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1069 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1070 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1071 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1072 | if (mLauncherCallbacks != null) { |
| 1073 | mLauncherCallbacks.onPause(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1074 | } |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1078 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1079 | // by a onResume or by scrolling otherwise. |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1080 | void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1081 | |
| 1082 | // Custom content is completely hidden |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1083 | void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1084 | |
| 1085 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1086 | void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1087 | |
| 1088 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1089 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1092 | public interface LauncherOverlay { |
| 1093 | |
| 1094 | /** |
| 1095 | * Touch interaction leading to overscroll has begun |
| 1096 | */ |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1097 | void onScrollInteractionBegin(); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1098 | |
| 1099 | /** |
| 1100 | * Touch interaction related to overscroll has ended |
| 1101 | */ |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1102 | void onScrollInteractionEnd(); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1103 | |
| 1104 | /** |
| 1105 | * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost |
| 1106 | * screen (or in the case of RTL, the rightmost screen). |
| 1107 | */ |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1108 | void onScrollChange(float progress, boolean rtl); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1109 | |
| 1110 | /** |
Sunny Goyal | 32554d1 | 2015-12-03 15:31:25 -0800 | [diff] [blame] | 1111 | * Called when the launcher is ready to use the overlay |
| 1112 | * @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] | 1113 | */ |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1114 | void setOverlayCallbacks(LauncherOverlayCallbacks callbacks); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | public interface LauncherOverlayCallbacks { |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1118 | void onScrollChanged(float progress); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks { |
| 1122 | |
Sunny Goyal | c86df47 | 2016-02-25 09:19:38 -0800 | [diff] [blame] | 1123 | public void onScrollChanged(float progress) { |
| 1124 | if (mWorkspace != null) { |
| 1125 | mWorkspace.onOverlayScrollChanged(progress); |
| 1126 | } |
| 1127 | } |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1130 | protected boolean hasSettings() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1131 | if (mLauncherCallbacks != null) { |
| 1132 | return mLauncherCallbacks.hasSettings(); |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 1133 | } else { |
Sunny Goyal | 4179e9b | 2017-03-08 14:25:09 -0800 | [diff] [blame] | 1134 | // On O and above we there is always some setting present settings (add icon to |
| 1135 | // home screen or icon badging). On earlier APIs we will have the allow rotation |
| 1136 | // setting, on devices with a locked orientation, |
| 1137 | return Utilities.isAtLeastO() || !getResources().getBoolean(R.bool.allow_rotation); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1138 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1139 | } |
| 1140 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1141 | public void addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1142 | CustomContentCallbacks callbacks, String description) { |
| 1143 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1146 | // The custom content needs to offset its content to account for the QSB |
| 1147 | public int getTopOffsetForCustomContent() { |
| 1148 | return mWorkspace.getPaddingTop(); |
| 1149 | } |
| 1150 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1151 | @Override |
| 1152 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1153 | // Flag the loader to stop early before switching |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1154 | if (mModel.isCurrentCallbacks(this)) { |
| 1155 | mModel.stopLoader(); |
| 1156 | } |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 1157 | //TODO(hyunyoungs): stop the widgets loader when there is a rotation. |
| 1158 | |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1159 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1160 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1161 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1162 | // We can't hide the IME if it was forced open. So don't bother |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1163 | @Override |
| 1164 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1165 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1166 | mHasFocus = hasFocus; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1167 | |
| 1168 | if (mLauncherCallbacks != null) { |
| 1169 | mLauncherCallbacks.onWindowFocusChanged(hasFocus); |
| 1170 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1171 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1172 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1173 | private boolean acceptFilter() { |
| 1174 | final InputMethodManager inputManager = (InputMethodManager) |
| 1175 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1176 | return !inputManager.isFullscreenMode(); |
| 1177 | } |
| 1178 | |
| 1179 | @Override |
| 1180 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1181 | final int uniChar = event.getUnicodeChar(); |
| 1182 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1183 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1184 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1185 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1186 | keyCode, event); |
| 1187 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1188 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1189 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1190 | // showSearchDialog() |
| 1191 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1192 | // onSearchRequested() will be called for every keystroke, |
| 1193 | // but it is idempotent, so it's fine. |
| 1194 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1198 | // Eat the long press event so the keyboard doesn't come up. |
| 1199 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1200 | return true; |
| 1201 | } |
| 1202 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1203 | return handled; |
| 1204 | } |
| 1205 | |
Winson | 4616347 | 2015-09-22 17:31:56 -0700 | [diff] [blame] | 1206 | @Override |
| 1207 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 1208 | if (keyCode == KeyEvent.KEYCODE_MENU) { |
| 1209 | // Ignore the menu key if we are currently dragging or are on the custom content screen |
| 1210 | if (!isOnCustomContent() && !mDragController.isDragging()) { |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 1211 | // Close any open floating view |
| 1212 | AbstractFloatingView.closeAllOpenViews(this); |
Tony Wickham | 49c8d29 | 2016-07-01 11:44:34 -0700 | [diff] [blame] | 1213 | |
Winson | 4616347 | 2015-09-22 17:31:56 -0700 | [diff] [blame] | 1214 | // Stop resizing any widgets |
| 1215 | mWorkspace.exitWidgetResizeMode(); |
| 1216 | |
| 1217 | // Show the overview mode if we are on the workspace |
| 1218 | if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() && |
| 1219 | !mWorkspace.isSwitchingState()) { |
| 1220 | mOverviewPanel.requestFocus(); |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1221 | showOverviewMode(true, true /* requestButtonFocus */); |
Winson | 4616347 | 2015-09-22 17:31:56 -0700 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | return true; |
| 1225 | } |
| 1226 | return super.onKeyUp(keyCode, event); |
| 1227 | } |
| 1228 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1229 | private String getTypedText() { |
| 1230 | return mDefaultKeySsb.toString(); |
| 1231 | } |
| 1232 | |
Sunny Goyal | 6f28e71 | 2016-09-13 14:19:29 -0700 | [diff] [blame] | 1233 | @Override |
| 1234 | public void clearTypedText() { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1235 | mDefaultKeySsb.clear(); |
| 1236 | mDefaultKeySsb.clearSpans(); |
| 1237 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1238 | } |
| 1239 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1240 | /** |
| 1241 | * Restores the previous state, if it exists. |
| 1242 | * |
| 1243 | * @param savedState The previous state. |
| 1244 | */ |
| 1245 | private void restoreState(Bundle savedState) { |
| 1246 | if (savedState == null) { |
| 1247 | return; |
| 1248 | } |
| 1249 | |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 1250 | int stateOrdinal = savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()); |
| 1251 | State[] stateValues = State.values(); |
| 1252 | State state = (stateOrdinal >= 0 && stateOrdinal < stateValues.length) |
| 1253 | ? stateValues[stateOrdinal] : State.WORKSPACE; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1254 | if (state == State.APPS || state == State.WIDGETS) { |
| 1255 | mOnResumeState = state; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1258 | PendingRequestArgs requestArgs = savedState.getParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS); |
| 1259 | if (requestArgs != null) { |
| 1260 | setWaitingForResult(requestArgs); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1261 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1262 | |
| 1263 | mPendingActivityResult = savedState.getParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * Finds all the views we need and configure them properly. |
| 1268 | */ |
| 1269 | private void setupViews() { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1270 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
Sunny Goyal | 3333b0c | 2016-05-09 20:43:21 -0700 | [diff] [blame] | 1271 | mFocusHandler = mDragLayer.getFocusIndicatorHelper(); |
Sunny Goyal | 966d901 | 2017-06-06 16:43:59 -0700 | [diff] [blame] | 1272 | mWorkspace = mDragLayer.findViewById(R.id.workspace); |
Sunny Goyal | d0a6ae7 | 2016-06-16 12:29:03 -0700 | [diff] [blame] | 1273 | mWorkspace.initParentViews(mDragLayer); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1274 | |
Sunny Goyal | 784f9c3 | 2016-03-23 16:56:54 -0700 | [diff] [blame] | 1275 | mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1276 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 1277 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1278 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1279 | // Setup the drag layer |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1280 | mDragLayer.setup(this, mDragController, mAllAppsController); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1281 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1282 | // Setup the hotseat |
| 1283 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1284 | if (mHotseat != null) { |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1285 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1288 | // Setup the overview panel |
| 1289 | setupOverviewPanel(); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1290 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1291 | // Setup the workspace |
| 1292 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1293 | mWorkspace.setOnLongClickListener(this); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1294 | mWorkspace.setup(mDragController); |
Winson | c7d2e83 | 2016-07-28 12:24:55 -0700 | [diff] [blame] | 1295 | // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the |
| 1296 | // default state, otherwise we will update to the wrong offsets in RTL |
| 1297 | mWorkspace.lockWallpaperToDefaultPage(); |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 1298 | mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1299 | mDragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1300 | |
Tony Wickham | 34d2c91 | 2015-09-11 09:27:58 -0700 | [diff] [blame] | 1301 | // Get the search/delete/uninstall bar |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1302 | mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1303 | |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 1304 | // Setup Apps and Widgets |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 1305 | mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view); |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 1306 | mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1307 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1308 | // 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] | 1309 | mDragController.setMoveTarget(mWorkspace); |
| 1310 | mDragController.addDropTarget(mWorkspace); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 1311 | mDropTargetBar.setup(mDragController); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1312 | |
Hyunyoung Song | d725f64 | 2017-08-17 22:26:35 -0700 | [diff] [blame] | 1313 | mAllAppsController.setupViews(mAppsView, mHotseat, mWorkspace); |
Hyunyoung Song | a0c5647 | 2016-06-20 13:54:42 -0700 | [diff] [blame] | 1314 | |
Sunny Goyal | 322d556 | 2015-06-25 19:35:49 -0700 | [diff] [blame] | 1315 | if (TestingUtils.MEMORY_DUMP_ENABLED) { |
| 1316 | TestingUtils.addWeightWatcher(this); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1317 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1318 | } |
| 1319 | |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1320 | private void setupOverviewPanel() { |
| 1321 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
| 1322 | |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1323 | // Bind wallpaper button actions |
| 1324 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 1325 | new OverviewButtonClickListener(ControlType.WALLPAPER_BUTTON) { |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1326 | @Override |
Jon Miranda | f3e35d9 | 2016-10-05 14:08:11 -0700 | [diff] [blame] | 1327 | public void handleViewClick(View view) { |
| 1328 | onClickWallpaperPicker(view); |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1329 | } |
Jon Miranda | f3e35d9 | 2016-10-05 14:08:11 -0700 | [diff] [blame] | 1330 | }.attachTo(wallpaperButton); |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1331 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1332 | |
| 1333 | // Bind widget button actions |
| 1334 | mWidgetsButton = findViewById(R.id.widget_button); |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 1335 | new OverviewButtonClickListener(ControlType.WIDGETS_BUTTON) { |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1336 | @Override |
Jon Miranda | f3e35d9 | 2016-10-05 14:08:11 -0700 | [diff] [blame] | 1337 | public void handleViewClick(View view) { |
| 1338 | onClickAddWidgetButton(view); |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1339 | } |
Jon Miranda | f3e35d9 | 2016-10-05 14:08:11 -0700 | [diff] [blame] | 1340 | }.attachTo(mWidgetsButton); |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1341 | mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1342 | |
| 1343 | // Bind settings actions |
| 1344 | View settingsButton = findViewById(R.id.settings_button); |
| 1345 | boolean hasSettings = hasSettings(); |
| 1346 | if (hasSettings) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 1347 | new OverviewButtonClickListener(ControlType.SETTINGS_BUTTON) { |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1348 | @Override |
Jon Miranda | f3e35d9 | 2016-10-05 14:08:11 -0700 | [diff] [blame] | 1349 | public void handleViewClick(View view) { |
| 1350 | onClickSettingsButton(view); |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1351 | } |
Jon Miranda | f3e35d9 | 2016-10-05 14:08:11 -0700 | [diff] [blame] | 1352 | }.attachTo(settingsButton); |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 1353 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1354 | } else { |
| 1355 | settingsButton.setVisibility(View.GONE); |
| 1356 | } |
| 1357 | |
| 1358 | mOverviewPanel.setAlpha(0f); |
| 1359 | } |
| 1360 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1361 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1362 | * Sets the all apps button. This method is called from {@link Hotseat}. |
Sunny Goyal | bb011da | 2016-06-15 15:42:29 -0700 | [diff] [blame] | 1363 | * TODO: Get rid of this. |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1364 | */ |
| 1365 | public void setAllAppsButton(View allAppsButton) { |
| 1366 | mAllAppsButton = allAppsButton; |
| 1367 | } |
| 1368 | |
Sunny Goyal | bb011da | 2016-06-15 15:42:29 -0700 | [diff] [blame] | 1369 | public View getStartViewForAllAppsRevealAnimation() { |
Sunny Goyal | 2e08409 | 2016-06-22 14:37:34 -0700 | [diff] [blame] | 1370 | return FeatureFlags.NO_ALL_APPS_ICON ? mWorkspace.getPageIndicator() : mAllAppsButton; |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Hyunyoung Song | 98ff38a | 2015-07-10 17:50:13 -0700 | [diff] [blame] | 1373 | public View getWidgetsButton() { |
| 1374 | return mWidgetsButton; |
| 1375 | } |
| 1376 | |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1377 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1378 | * Creates a view representing a shortcut. |
| 1379 | * |
| 1380 | * @param info The data structure describing the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1381 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1382 | View createShortcut(ShortcutInfo info) { |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 1383 | return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | /** |
| 1387 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1388 | * |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1389 | * @param parent The group the shortcut belongs to. |
| 1390 | * @param info The data structure describing the shortcut. |
| 1391 | * |
| 1392 | * @return A View inflated from layoutResId. |
| 1393 | */ |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 1394 | public View createShortcut(ViewGroup parent, ShortcutInfo info) { |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 1395 | BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext()) |
| 1396 | .inflate(R.layout.app_icon, parent, false); |
Sunny Goyal | 1cd01b0 | 2016-11-09 10:43:58 -0800 | [diff] [blame] | 1397 | favorite.applyFromShortcutInfo(info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1398 | favorite.setOnClickListener(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1399 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1400 | return favorite; |
| 1401 | } |
| 1402 | |
| 1403 | /** |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1404 | * 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] | 1405 | * |
| 1406 | * @param data The intent describing the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1407 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1408 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 1409 | int cellY, PendingRequestArgs args) { |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1410 | if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT |
| 1411 | || args.getPendingIntent().getComponent() == null) { |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 1412 | return; |
| 1413 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1414 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1415 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1416 | CellLayout layout = getCellLayout(container, screenId); |
| 1417 | |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1418 | ShortcutInfo info = null; |
| 1419 | if (Utilities.isAtLeastO()) { |
Sunny Goyal | 22ca9ec | 2017-05-18 15:03:13 -0700 | [diff] [blame] | 1420 | info = LauncherAppsCompatVO.createShortcutInfoFromPinItemRequest( |
| 1421 | this, LauncherAppsCompatVO.getPinItemRequest(data), 0); |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | if (info == null) { |
Sunny Goyal | b57645f | 2017-03-20 13:57:28 -0700 | [diff] [blame] | 1425 | // Legacy shortcuts are only supported for primary profile. |
| 1426 | info = Process.myUserHandle().equals(args.user) |
| 1427 | ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null; |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1428 | |
Sunny Goyal | b57645f | 2017-03-20 13:57:28 -0700 | [diff] [blame] | 1429 | if (info == null) { |
| 1430 | Log.e(TAG, "Unable to parse a valid custom shortcut result"); |
| 1431 | return; |
| 1432 | } else if (!new PackageManagerHelper(this).hasPermissionForActivity( |
Sunny Goyal | 342e466 | 2017-02-02 15:21:08 -0800 | [diff] [blame] | 1433 | info.intent, args.getPendingIntent().getComponent().getPackageName())) { |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 1434 | // The app is trying to add a shortcut without sufficient permissions |
| 1435 | Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0)); |
| 1436 | return; |
| 1437 | } |
| 1438 | } |
| 1439 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1440 | if (container < 0) { |
| 1441 | // Adding a shortcut to the Workspace. |
| 1442 | final View view = createShortcut(info); |
| 1443 | boolean foundCellSpan = false; |
| 1444 | // First we check if we already know the exact location where we want to add this item. |
| 1445 | if (cellX >= 0 && cellY >= 0) { |
| 1446 | cellXY[0] = cellX; |
| 1447 | cellXY[1] = cellY; |
| 1448 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1449 | |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1450 | // If appropriate, either create a folder or add to an existing folder |
| 1451 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
| 1452 | true, null, null)) { |
| 1453 | return; |
| 1454 | } |
| 1455 | DragObject dragObject = new DragObject(); |
| 1456 | dragObject.dragInfo = info; |
| 1457 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1458 | true)) { |
| 1459 | return; |
| 1460 | } |
| 1461 | } else { |
| 1462 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
| 1463 | } |
| 1464 | |
| 1465 | if (!foundCellSpan) { |
| 1466 | mWorkspace.onNoCellFound(layout); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1467 | return; |
| 1468 | } |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1469 | |
| 1470 | getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]); |
| 1471 | mWorkspace.addInScreen(view, info); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1472 | } else { |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1473 | // Adding a shortcut to a Folder. |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1474 | FolderIcon folderIcon = findFolderIcon(container); |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 1475 | if (folderIcon != null) { |
| 1476 | FolderInfo folderInfo = (FolderInfo) folderIcon.getTag(); |
| 1477 | folderInfo.add(info, args.rank, false); |
| 1478 | } else { |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1479 | 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] | 1480 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1481 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1482 | } |
| 1483 | |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 1484 | public FolderIcon findFolderIcon(final long folderIconId) { |
| 1485 | return (FolderIcon) mWorkspace.getFirstMatch(new ItemOperator() { |
| 1486 | @Override |
| 1487 | public boolean evaluate(ItemInfo info, View view) { |
| 1488 | return info != null && info.id == folderIconId; |
| 1489 | } |
| 1490 | }); |
| 1491 | } |
| 1492 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1493 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1494 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1495 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1496 | * @param appWidgetId The app widget id |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1497 | */ |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1498 | @Thunk void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1499 | AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) { |
| 1500 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1501 | if (appWidgetInfo == null) { |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 1502 | appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1503 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1504 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1505 | if (appWidgetInfo.isCustomWidget) { |
| 1506 | appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1509 | LauncherAppWidgetInfo launcherInfo; |
| 1510 | launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1511 | launcherInfo.spanX = itemInfo.spanX; |
| 1512 | launcherInfo.spanY = itemInfo.spanY; |
| 1513 | launcherInfo.minSpanX = itemInfo.minSpanX; |
| 1514 | launcherInfo.minSpanY = itemInfo.minSpanY; |
Sunny Goyal | a52ecb0 | 2016-12-16 15:04:51 -0800 | [diff] [blame] | 1515 | launcherInfo.user = appWidgetInfo.getUser(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1516 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1517 | getModelWriter().addItemToDatabase(launcherInfo, |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1518 | itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1519 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1520 | if (hostView == null) { |
| 1521 | // Perform actual inflation because we're live |
| 1522 | hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1523 | } |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1524 | hostView.setVisibility(View.VISIBLE); |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 1525 | prepareAppWidget(hostView, launcherInfo); |
| 1526 | mWorkspace.addInScreen(hostView, launcherInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1527 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1528 | |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 1529 | private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) { |
Sunny Goyal | 87af0fd | 2016-05-16 14:56:02 -0700 | [diff] [blame] | 1530 | hostView.setTag(item); |
| 1531 | item.onBindAppWidget(this, hostView); |
Sunny Goyal | 87af0fd | 2016-05-16 14:56:02 -0700 | [diff] [blame] | 1532 | hostView.setFocusable(true); |
| 1533 | hostView.setOnFocusChangeListener(mFocusHandler); |
Sunny Goyal | 25c2e3e | 2015-10-28 23:28:21 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1536 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1537 | @Override |
| 1538 | public void onReceive(Context context, Intent intent) { |
| 1539 | final String action = intent.getAction(); |
| 1540 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame] | 1541 | mDragLayer.clearResizeFrame(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1542 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1543 | // 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] | 1544 | // processing a multi-step drop |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1545 | if (mAppsView != null && mWidgetsView != null && mPendingRequestArgs == null) { |
Winson | 5c6bdbb | 2015-09-03 11:36:19 -0700 | [diff] [blame] | 1546 | if (!showWorkspace(false)) { |
| 1547 | // If we are already on the workspace, then manually reset all apps |
| 1548 | mAppsView.reset(); |
| 1549 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1550 | } |
Hyunyoung Song | c001cf5 | 2016-07-21 17:32:43 -0700 | [diff] [blame] | 1551 | mIsResumeFromActionScreenOff = true; |
Jon Miranda | 7fda285 | 2017-07-19 16:07:01 -0700 | [diff] [blame] | 1552 | mShouldFadeInScrim = true; |
| 1553 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1554 | // ACTION_USER_PRESENT is sent after onStart/onResume. This covers the case where |
| 1555 | // the user unlocked and the Launcher is not in the foreground. |
| 1556 | mShouldFadeInScrim = false; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1557 | } |
| 1558 | } |
| 1559 | }; |
| 1560 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 1561 | public void updateIconBadges(final Set<PackageUserKey> updatedBadges) { |
| 1562 | Runnable r = new Runnable() { |
| 1563 | @Override |
| 1564 | public void run() { |
| 1565 | mWorkspace.updateIconBadges(updatedBadges); |
| 1566 | mAppsView.updateIconBadges(updatedBadges); |
Tony Wickham | 2fe09f2 | 2017-04-25 12:46:04 -0700 | [diff] [blame] | 1567 | |
| 1568 | PopupContainerWithArrow popup = PopupContainerWithArrow.getOpen(Launcher.this); |
| 1569 | if (popup != null) { |
| 1570 | popup.updateNotificationHeader(updatedBadges); |
| 1571 | } |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 1572 | } |
| 1573 | }; |
| 1574 | if (!waitUntilResume(r)) { |
| 1575 | r.run(); |
| 1576 | } |
| 1577 | } |
| 1578 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1579 | @Override |
| 1580 | public void onAttachedToWindow() { |
| 1581 | super.onAttachedToWindow(); |
| 1582 | |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1583 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Sunny Goyal | c86df47 | 2016-02-25 09:19:38 -0800 | [diff] [blame] | 1584 | if (mLauncherCallbacks != null) { |
| 1585 | mLauncherCallbacks.onAttachedToWindow(); |
| 1586 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | @Override |
| 1590 | public void onDetachedFromWindow() { |
| 1591 | super.onDetachedFromWindow(); |
Sunny Goyal | c86df47 | 2016-02-25 09:19:38 -0800 | [diff] [blame] | 1592 | |
| 1593 | if (mLauncherCallbacks != null) { |
| 1594 | mLauncherCallbacks.onDetachedFromWindow(); |
| 1595 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | public void onWindowVisibilityChanged(int visibility) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1599 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1600 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1601 | // is a more appropriate event to handle |
Sunny Goyal | 1acc56a | 2016-09-25 21:23:25 -0700 | [diff] [blame] | 1602 | if (visibility == View.VISIBLE) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1603 | if (!mWorkspaceLoading) { |
| 1604 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1605 | // We want to let Launcher draw itself at least once before we force it to build |
| 1606 | // layers on all the workspace pages, so that transitioning to Launcher from other |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1607 | // apps is nice and speedy. |
| 1608 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1609 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1610 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1611 | if (mStarted) return; |
| 1612 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1613 | // We delay the layer building a bit in order to give |
| 1614 | // other message processing a time to run. In particular |
| 1615 | // this avoids a delay in hiding the IME if it was |
| 1616 | // currently shown, because doing that may involve |
| 1617 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1618 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1619 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1620 | mWorkspace.post(new Runnable() { |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 1621 | public void run() { |
| 1622 | if (mWorkspace != null && |
| 1623 | mWorkspace.getViewTreeObserver() != null) { |
| 1624 | mWorkspace.getViewTreeObserver(). |
| 1625 | removeOnDrawListener(listener); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1626 | } |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 1627 | } |
| 1628 | }); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1629 | } |
| 1630 | }); |
| 1631 | } |
| 1632 | clearTypedText(); |
| 1633 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1636 | public DragLayer getDragLayer() { |
| 1637 | return mDragLayer; |
| 1638 | } |
| 1639 | |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 1640 | public AllAppsContainerView getAppsView() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1641 | return mAppsView; |
| 1642 | } |
| 1643 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 1644 | public WidgetsContainerView getWidgetsView() { |
| 1645 | return mWidgetsView; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1646 | } |
| 1647 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1648 | public Workspace getWorkspace() { |
| 1649 | return mWorkspace; |
| 1650 | } |
| 1651 | |
| 1652 | public Hotseat getHotseat() { |
| 1653 | return mHotseat; |
| 1654 | } |
| 1655 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1656 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1657 | return mOverviewPanel; |
| 1658 | } |
| 1659 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 1660 | public DropTargetBar getDropTargetBar() { |
| 1661 | return mDropTargetBar; |
Tony Wickham | 34d2c91 | 2015-09-11 09:27:58 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1664 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1665 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1666 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1667 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1668 | public LauncherModel getModel() { |
| 1669 | return mModel; |
| 1670 | } |
| 1671 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 1672 | public ModelWriter getModelWriter() { |
| 1673 | return mModelWriter; |
| 1674 | } |
| 1675 | |
Adam Cohen | 79d90c5 | 2016-04-22 13:29:20 -0700 | [diff] [blame] | 1676 | public SharedPreferences getSharedPrefs() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1677 | return mSharedPrefs; |
| 1678 | } |
| 1679 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1680 | @Override |
| 1681 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1682 | long startTime = 0; |
| 1683 | if (DEBUG_RESUME_TIME) { |
| 1684 | startTime = System.currentTimeMillis(); |
| 1685 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1686 | super.onNewIntent(intent); |
| 1687 | |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1688 | boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1689 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1690 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Sunny Goyal | 8531373 | 2016-09-28 12:00:07 -0700 | [diff] [blame] | 1691 | |
| 1692 | // Check this condition before handling isActionMain, as this will get reset. |
| 1693 | boolean shouldMoveToDefaultScreen = alreadyOnHome && |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 1694 | mState == State.WORKSPACE && AbstractFloatingView.getTopOpenView(this) == null; |
Sunny Goyal | 8531373 | 2016-09-28 12:00:07 -0700 | [diff] [blame] | 1695 | |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1696 | boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction()); |
| 1697 | if (isActionMain) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1698 | if (mWorkspace == null) { |
| 1699 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1700 | return; |
| 1701 | } |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 1702 | |
| 1703 | // Note: There should be at most one log per method call. This is enforced implicitly |
| 1704 | // by using if-else statements. |
| 1705 | UserEventDispatcher ued = getUserEventDispatcher(); |
| 1706 | |
| 1707 | // TODO: Log this case. |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1708 | mWorkspace.exitWidgetResizeMode(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1709 | |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 1710 | AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(this); |
Tony Wickham | 540913e | 2017-01-23 11:47:51 -0800 | [diff] [blame] | 1711 | if (topOpenView instanceof PopupContainerWithArrow) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 1712 | ued.logActionCommand(Action.Command.HOME_INTENT, |
| 1713 | topOpenView.getExtendedTouchView(), ContainerType.DEEPSHORTCUTS); |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 1714 | } else if (topOpenView instanceof Folder) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 1715 | ued.logActionCommand(Action.Command.HOME_INTENT, |
| 1716 | ((Folder) topOpenView).getFolderIcon(), ContainerType.FOLDER); |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 1717 | } else if (alreadyOnHome) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 1718 | ued.logActionCommand(Action.Command.HOME_INTENT, |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 1719 | mWorkspace.getState().containerType, mWorkspace.getCurrentPage()); |
| 1720 | } |
| 1721 | |
| 1722 | // In all these cases, only animate if we're already on home |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 1723 | AbstractFloatingView.closeAllOpenViews(this, alreadyOnHome); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1724 | exitSpringLoadedDragMode(); |
| 1725 | |
| 1726 | // If we are already on home, then just animate back to the workspace, |
| 1727 | // otherwise, just wait until onResume to set the state back to Workspace |
| 1728 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1729 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1730 | } else { |
| 1731 | mOnResumeState = State.WORKSPACE; |
| 1732 | } |
| 1733 | |
| 1734 | final View v = getWindow().peekDecorView(); |
| 1735 | if (v != null && v.getWindowToken() != null) { |
Tony | c1739096 | 2015-10-25 17:39:37 -0700 | [diff] [blame] | 1736 | InputMethodManager imm = (InputMethodManager) getSystemService( |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1737 | INPUT_METHOD_SERVICE); |
| 1738 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 1739 | } |
| 1740 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1741 | // Reset the apps view |
| 1742 | if (!alreadyOnHome && mAppsView != null) { |
Sunny Goyal | 161f96b | 2017-05-07 11:56:00 -0700 | [diff] [blame] | 1743 | mAppsView.reset(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 1746 | // Reset the widgets view |
| 1747 | if (!alreadyOnHome && mWidgetsView != null) { |
| 1748 | mWidgetsView.scrollToTop(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1749 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1750 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1751 | if (mLauncherCallbacks != null) { |
| 1752 | mLauncherCallbacks.onHomeIntent(); |
| 1753 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1754 | } |
Sunny Goyal | 5a81c38 | 2017-03-20 15:08:06 -0700 | [diff] [blame] | 1755 | PinItemDragListener.handleDragRequest(this, intent); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1756 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1757 | if (mLauncherCallbacks != null) { |
| 1758 | mLauncherCallbacks.onNewIntent(intent); |
| 1759 | } |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1760 | |
| 1761 | // Defer moving to the default screen until after we callback to the LauncherCallbacks |
| 1762 | // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage |
| 1763 | // animation. |
| 1764 | if (isActionMain) { |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 1765 | boolean callbackAllowsMoveToDefaultScreen = |
| 1766 | mLauncherCallbacks == null || mLauncherCallbacks |
| 1767 | .shouldMoveToDefaultScreenOnHomeIntent(); |
Sunny Goyal | 8531373 | 2016-09-28 12:00:07 -0700 | [diff] [blame] | 1768 | if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive() |
| 1769 | && callbackAllowsMoveToDefaultScreen) { |
Adam Cohen | 4b66bf3 | 2015-09-18 12:15:19 -0700 | [diff] [blame] | 1770 | |
| 1771 | // We use this flag to suppress noisy callbacks above custom content state |
| 1772 | // from onResume. |
| 1773 | mMoveToDefaultScreenFromNewIntent = true; |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1774 | mWorkspace.post(new Runnable() { |
| 1775 | @Override |
| 1776 | public void run() { |
Tony | c1739096 | 2015-10-25 17:39:37 -0700 | [diff] [blame] | 1777 | if (mWorkspace != null) { |
| 1778 | mWorkspace.moveToDefaultScreen(true); |
| 1779 | } |
Winson | 15f8b17 | 2015-08-19 11:02:39 -0700 | [diff] [blame] | 1780 | } |
| 1781 | }); |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | if (DEBUG_RESUME_TIME) { |
| 1786 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 1787 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1790 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1791 | public void onRestoreInstanceState(Bundle state) { |
| 1792 | super.onRestoreInstanceState(state); |
| 1793 | for (int page: mSynchronouslyBoundPages) { |
| 1794 | mWorkspace.restoreInstanceStateForChild(page); |
| 1795 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | @Override |
| 1799 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1800 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 1801 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1802 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 1803 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1804 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1805 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1806 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1807 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 1808 | // We close any open folders and shortcut containers since they will not be re-opened, |
| 1809 | // and we need to make sure this state is reflected. |
| 1810 | AbstractFloatingView.closeAllOpenViews(this, false); |
Tony Wickham | 49c8d29 | 2016-07-01 11:44:34 -0700 | [diff] [blame] | 1811 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1812 | if (mPendingRequestArgs != null) { |
| 1813 | outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs); |
| 1814 | } |
| 1815 | if (mPendingActivityResult != null) { |
| 1816 | outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1817 | } |
| 1818 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1819 | if (mLauncherCallbacks != null) { |
| 1820 | mLauncherCallbacks.onSaveInstanceState(outState); |
| 1821 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | @Override |
| 1825 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1826 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1827 | |
Sunny Goyal | 5cc7bbd | 2017-06-12 09:50:39 -0700 | [diff] [blame] | 1828 | unregisterReceiver(mReceiver); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 1829 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 1830 | mWorkspace.removeFolderListeners(); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1831 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1832 | // Stop callbacks from LauncherModel |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1833 | // It's possible to receive onDestroy after a new Launcher activity has |
| 1834 | // been created. In this case, don't interfere with the new Launcher. |
| 1835 | if (mModel.isCurrentCallbacks(this)) { |
| 1836 | mModel.stopLoader(); |
Sunny Goyal | 87f784c | 2017-01-11 10:48:34 -0800 | [diff] [blame] | 1837 | LauncherAppState.getInstance(this).setLauncher(null); |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1838 | } |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1839 | |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 1840 | if (mRotationPrefChangeHandler != null) { |
| 1841 | mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler); |
| 1842 | } |
| 1843 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1844 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1845 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1846 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1847 | 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] | 1848 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1849 | mAppWidgetHost = null; |
| 1850 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1851 | TextKeyListener.getInstance().release(); |
| 1852 | |
Tony Wickham | e221725 | 2016-03-22 16:34:23 -0700 | [diff] [blame] | 1853 | ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)) |
| 1854 | .removeAccessibilityStateChangeListener(this); |
| 1855 | |
Mario Bertschler | 2728838 | 2017-05-24 15:35:09 -0700 | [diff] [blame] | 1856 | WallpaperColorInfo.getInstance(this).setOnThemeChangeListener(null); |
| 1857 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 1858 | LauncherAnimUtils.onDestroyActivity(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1859 | |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 1860 | clearPendingBinds(); |
| 1861 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1862 | if (mLauncherCallbacks != null) { |
| 1863 | mLauncherCallbacks.onDestroy(); |
| 1864 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
Sunny Goyal | ae50284 | 2016-06-17 08:43:56 -0700 | [diff] [blame] | 1867 | public LauncherAccessibilityDelegate getAccessibilityDelegate() { |
| 1868 | return mAccessibilityDelegate; |
| 1869 | } |
| 1870 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1871 | public DragController getDragController() { |
| 1872 | return mDragController; |
| 1873 | } |
| 1874 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1875 | @Override |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 1876 | public void startActivityForResult(Intent intent, int requestCode, Bundle options) { |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 1877 | super.startActivityForResult(intent, requestCode, options); |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | @Override |
| 1881 | public void startIntentSenderForResult (IntentSender intent, int requestCode, |
| 1882 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) { |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 1883 | try { |
| 1884 | super.startIntentSenderForResult(intent, requestCode, |
| 1885 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
| 1886 | } catch (IntentSender.SendIntentException e) { |
| 1887 | throw new ActivityNotFoundException(); |
| 1888 | } |
| 1889 | } |
| 1890 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1891 | /** |
| 1892 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1893 | * argument for {@link #startSearch} to true. |
| 1894 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1895 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1896 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1897 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1898 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1899 | if (initialQuery == null) { |
| 1900 | // Use any text typed in the launcher as the initial query |
| 1901 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1902 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1903 | if (appSearchData == null) { |
| 1904 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 1905 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1906 | } |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 1907 | |
Sunny Goyal | 6f28e71 | 2016-09-13 14:19:29 -0700 | [diff] [blame] | 1908 | if (mLauncherCallbacks == null || |
| 1909 | !mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData)) { |
| 1910 | // Starting search from the callbacks failed. Start the default global search. |
| 1911 | startGlobalSearch(initialQuery, selectInitialQuery, appSearchData, null); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 1912 | } |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 1913 | |
| 1914 | // We need to show the workspace after starting the search |
| 1915 | showWorkspace(true); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1916 | } |
| 1917 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 1918 | /** |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 1919 | * Starts the global search activity. This code is a copied from SearchManager |
| 1920 | */ |
Sunny Goyal | 6f28e71 | 2016-09-13 14:19:29 -0700 | [diff] [blame] | 1921 | public void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 1922 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1923 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 1924 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 1925 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 1926 | if (globalSearchActivity == null) { |
| 1927 | Log.w(TAG, "No global search activity found."); |
| 1928 | return; |
| 1929 | } |
| 1930 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 1931 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1932 | intent.setComponent(globalSearchActivity); |
| 1933 | // Make sure that we have a Bundle to put source in |
| 1934 | if (appSearchData == null) { |
| 1935 | appSearchData = new Bundle(); |
| 1936 | } else { |
| 1937 | appSearchData = new Bundle(appSearchData); |
| 1938 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1939 | // Set source to package name of app that starts global search if not set already. |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 1940 | if (!appSearchData.containsKey("source")) { |
| 1941 | appSearchData.putString("source", getPackageName()); |
| 1942 | } |
| 1943 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 1944 | if (!TextUtils.isEmpty(initialQuery)) { |
| 1945 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 1946 | } |
| 1947 | if (selectInitialQuery) { |
| 1948 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 1949 | } |
| 1950 | intent.setSourceBounds(sourceBounds); |
| 1951 | try { |
| 1952 | startActivity(intent); |
| 1953 | } catch (ActivityNotFoundException ex) { |
| 1954 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 1955 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1956 | } |
| 1957 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 1958 | public boolean isOnCustomContent() { |
| 1959 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 1960 | } |
| 1961 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1962 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1963 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 1964 | super.onPrepareOptionsMenu(menu); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1965 | if (mLauncherCallbacks != null) { |
| 1966 | return mLauncherCallbacks.onPrepareOptionsMenu(menu); |
| 1967 | } |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 1968 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1969 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1970 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1971 | @Override |
| 1972 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1973 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 1974 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1975 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1978 | public boolean isWorkspaceLocked() { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1979 | return mWorkspaceLoading || mPendingRequestArgs != null; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1980 | } |
| 1981 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 1982 | public boolean isWorkspaceLoading() { |
| 1983 | return mWorkspaceLoading; |
| 1984 | } |
| 1985 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1986 | private void setWorkspaceLoading(boolean value) { |
| 1987 | boolean isLocked = isWorkspaceLocked(); |
| 1988 | mWorkspaceLoading = value; |
| 1989 | if (isLocked != isWorkspaceLocked()) { |
| 1990 | onWorkspaceLockedChanged(); |
| 1991 | } |
| 1992 | } |
| 1993 | |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 1994 | public void setWaitingForResult(PendingRequestArgs args) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1995 | boolean isLocked = isWorkspaceLocked(); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 1996 | mPendingRequestArgs = args; |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1997 | if (isLocked != isWorkspaceLocked()) { |
| 1998 | onWorkspaceLockedChanged(); |
| 1999 | } |
| 2000 | } |
| 2001 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2002 | protected void onWorkspaceLockedChanged() { |
| 2003 | if (mLauncherCallbacks != null) { |
| 2004 | mLauncherCallbacks.onWorkspaceLockedChanged(); |
| 2005 | } |
| 2006 | } |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2007 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2008 | void addAppWidgetFromDropImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2009 | WidgetAddFlowHandler addFlowHandler) { |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 2010 | if (LOGD) { |
| 2011 | Log.d(TAG, "Adding widget from drop"); |
| 2012 | } |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2013 | addAppWidgetImpl(appWidgetId, info, boundWidget, addFlowHandler, 0); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2016 | void addAppWidgetImpl(int appWidgetId, ItemInfo info, |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2017 | AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) { |
| 2018 | if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, REQUEST_CREATE_APPWIDGET)) { |
| 2019 | // If the configuration flow was not started, add the widget |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2020 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2021 | Runnable onComplete = new Runnable() { |
| 2022 | @Override |
| 2023 | public void run() { |
| 2024 | // Exit spring loaded mode if necessary after adding the widget |
| 2025 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2026 | null); |
| 2027 | } |
| 2028 | }; |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2029 | completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this)); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2030 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2031 | } |
| 2032 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2033 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2034 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2035 | // Close any folders that may be open. |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 2036 | AbstractFloatingView.closeAllOpenViews(this, animate); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2037 | mWorkspace.moveToCustomContentScreen(animate); |
| 2038 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2039 | |
| 2040 | public void addPendingItem(PendingAddItemInfo info, long container, long screenId, |
| 2041 | int[] cell, int spanX, int spanY) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2042 | info.container = container; |
| 2043 | info.screenId = screenId; |
| 2044 | if (cell != null) { |
| 2045 | info.cellX = cell[0]; |
| 2046 | info.cellY = cell[1]; |
| 2047 | } |
| 2048 | info.spanX = spanX; |
| 2049 | info.spanY = spanY; |
| 2050 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2051 | switch (info.itemType) { |
| 2052 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: |
| 2053 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2054 | addAppWidgetFromDrop((PendingAddWidgetInfo) info); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2055 | break; |
| 2056 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 2057 | processShortcutFromDrop((PendingAddShortcutInfo) info); |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2058 | break; |
| 2059 | default: |
| 2060 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
| 2061 | } |
| 2062 | } |
| 2063 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2064 | /** |
| 2065 | * Process a shortcut drop. |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2066 | */ |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 2067 | private void processShortcutFromDrop(PendingAddShortcutInfo info) { |
Sunny Goyal | fb5096d | 2016-09-08 14:32:06 -0700 | [diff] [blame] | 2068 | Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName); |
| 2069 | setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info)); |
Sunny Goyal | 782f0c9 | 2017-01-19 10:27:54 -0800 | [diff] [blame] | 2070 | if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) { |
| 2071 | handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null); |
| 2072 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2075 | /** |
| 2076 | * Process a widget drop. |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2077 | */ |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2078 | private void addAppWidgetFromDrop(PendingAddWidgetInfo info) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2079 | AppWidgetHostView hostView = info.boundWidget; |
| 2080 | int appWidgetId; |
Sunny Goyal | 8a0dc38 | 2017-01-25 11:30:06 -0800 | [diff] [blame] | 2081 | WidgetAddFlowHandler addFlowHandler = info.getHandler(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2082 | if (hostView != null) { |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 2083 | // In the case where we've prebound the widget, we remove it from the DragLayer |
| 2084 | if (LOGD) { |
| 2085 | Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null"); |
| 2086 | } |
| 2087 | getDragLayer().removeView(hostView); |
| 2088 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2089 | appWidgetId = hostView.getAppWidgetId(); |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2090 | addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler); |
Sunny Goyal | 5b9ebca | 2015-06-01 18:37:32 -0700 | [diff] [blame] | 2091 | |
| 2092 | // Clear the boundWidget so that it doesn't get destroyed. |
| 2093 | info.boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2094 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2095 | // In this case, we either need to start an activity to get permission to bind |
| 2096 | // the widget, or we need to start an activity to configure the widget, or both. |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2097 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2098 | Bundle options = info.bindOptions; |
| 2099 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2100 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2101 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2102 | if (success) { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2103 | addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2104 | } else { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2105 | addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2106 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2107 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2110 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2111 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2112 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2113 | folderInfo.title = getText(R.string.folder_name); |
| 2114 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2115 | // Update the model |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2116 | getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2117 | |
| 2118 | // Create the view |
Sunny Goyal | 1cd01b0 | 2016-11-09 10:43:58 -0800 | [diff] [blame] | 2119 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo); |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 2120 | mWorkspace.addInScreen(newFolder, folderInfo); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2121 | // Force measure the new folder icon |
| 2122 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2123 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2124 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2125 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2126 | |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2127 | /** |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 2128 | * Unbinds the view for the specified item, and removes the item and all its children. |
| 2129 | * |
| 2130 | * @param v the view being removed. |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 2131 | * @param itemInfo the {@link ItemInfo} for this view. |
| 2132 | * @param deleteFromDb whether or not to delete this item from the db. |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2133 | */ |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 2134 | public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) { |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2135 | if (itemInfo instanceof ShortcutInfo) { |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 2136 | // Remove the shortcut from the folder before removing it from launcher |
Sunny Goyal | 44c0643 | 2016-04-02 10:56:02 -0700 | [diff] [blame] | 2137 | View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container); |
| 2138 | if (folderIcon instanceof FolderIcon) { |
Sunny Goyal | c52ba71 | 2016-04-05 15:59:05 -0700 | [diff] [blame] | 2139 | ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true); |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 2140 | } else { |
| 2141 | mWorkspace.removeWorkspaceItem(v); |
| 2142 | } |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2143 | if (deleteFromDb) { |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2144 | getModelWriter().deleteItemFromDatabase(itemInfo); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2145 | } |
| 2146 | } else if (itemInfo instanceof FolderInfo) { |
| 2147 | final FolderInfo folderInfo = (FolderInfo) itemInfo; |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 2148 | if (v instanceof FolderIcon) { |
| 2149 | ((FolderIcon) v).removeListeners(); |
| 2150 | } |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2151 | mWorkspace.removeWorkspaceItem(v); |
| 2152 | if (deleteFromDb) { |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2153 | getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2154 | } |
| 2155 | } else if (itemInfo instanceof LauncherAppWidgetInfo) { |
| 2156 | final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo; |
Winson | 44818e0 | 2015-10-02 11:25:46 -0700 | [diff] [blame] | 2157 | mWorkspace.removeWorkspaceItem(v); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2158 | if (deleteFromDb) { |
Sunny Goyal | 56c7360 | 2015-09-25 12:55:01 -0700 | [diff] [blame] | 2159 | deleteWidgetInfo(widgetInfo); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2160 | } |
| 2161 | } else { |
| 2162 | return false; |
| 2163 | } |
| 2164 | return true; |
| 2165 | } |
| 2166 | |
| 2167 | /** |
Sunny Goyal | 56c7360 | 2015-09-25 12:55:01 -0700 | [diff] [blame] | 2168 | * Deletes the widget info and the widget id. |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2169 | */ |
Sunny Goyal | 56c7360 | 2015-09-25 12:55:01 -0700 | [diff] [blame] | 2170 | private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) { |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2171 | final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost(); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2172 | if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdAllocated()) { |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2173 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 2174 | // to the caller... |
| 2175 | new AsyncTask<Void, Void, Void>() { |
| 2176 | public Void doInBackground(Void ... args) { |
| 2177 | appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId); |
| 2178 | return null; |
| 2179 | } |
Sunny Goyal | f27cb0e | 2015-09-23 16:12:02 -0700 | [diff] [blame] | 2180 | }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2181 | } |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 2182 | getModelWriter().deleteItemFromDatabase(widgetInfo); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2185 | @Override |
| 2186 | public boolean dispatchKeyEvent(KeyEvent event) { |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 2187 | return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2188 | } |
| 2189 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2190 | @Override |
| 2191 | public void onBackPressed() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2192 | if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) { |
| 2193 | return; |
| 2194 | } |
| 2195 | |
Sunny Goyal | 4547802 | 2015-06-08 16:52:41 -0700 | [diff] [blame] | 2196 | if (mDragController.isDragging()) { |
| 2197 | mDragController.cancelDrag(); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2198 | return; |
| 2199 | } |
| 2200 | |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 2201 | // Note: There should be at most one log per method call. This is enforced implicitly |
| 2202 | // by using if-else statements. |
| 2203 | UserEventDispatcher ued = getUserEventDispatcher(); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 2204 | AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this); |
| 2205 | if (topView != null) { |
| 2206 | if (topView.getActiveTextView() != null) { |
| 2207 | topView.getActiveTextView().dispatchBackKey(); |
| 2208 | } else { |
Tony Wickham | 540913e | 2017-01-23 11:47:51 -0800 | [diff] [blame] | 2209 | if (topView instanceof PopupContainerWithArrow) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2210 | ued.logActionCommand(Action.Command.BACK, |
| 2211 | topView.getExtendedTouchView(), ContainerType.DEEPSHORTCUTS); |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 2212 | } else if (topView instanceof Folder) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2213 | ued.logActionCommand(Action.Command.BACK, |
| 2214 | ((Folder) topView).getFolderIcon(), ContainerType.FOLDER); |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 2215 | } |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 2216 | topView.close(true); |
| 2217 | } |
Tony Wickham | 49c8d29 | 2016-07-01 11:44:34 -0700 | [diff] [blame] | 2218 | } else if (isAppsViewVisible()) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2219 | ued.logActionCommand(Action.Command.BACK, ContainerType.ALLAPPS); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2220 | showWorkspace(true); |
| 2221 | } else if (isWidgetsViewVisible()) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2222 | ued.logActionCommand(Action.Command.BACK, ContainerType.WIDGETS); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2223 | showOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2224 | } else if (mWorkspace.isInOverviewMode()) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2225 | ued.logActionCommand(Action.Command.BACK, ContainerType.OVERVIEW); |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2226 | showWorkspace(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2227 | } else { |
Jon Miranda | feba90f | 2016-10-06 10:53:29 -0700 | [diff] [blame] | 2228 | // TODO: Log this case. |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2229 | mWorkspace.exitWidgetResizeMode(); |
| 2230 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2231 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2232 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2233 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2234 | } |
| 2235 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2236 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2237 | * Launches the intent referred by the clicked shortcut. |
| 2238 | * |
| 2239 | * @param v The view representing the clicked shortcut. |
| 2240 | */ |
| 2241 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2242 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2243 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2244 | if (v.getWindowToken() == null) { |
| 2245 | return; |
| 2246 | } |
| 2247 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2248 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2249 | return; |
| 2250 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2251 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2252 | if (v instanceof Workspace) { |
| 2253 | if (mWorkspace.isInOverviewMode()) { |
Jon Miranda | 2e61fba | 2017-02-24 09:12:59 -0800 | [diff] [blame] | 2254 | getUserEventDispatcher().logActionOnContainer(LauncherLogProto.Action.Type.TOUCH, |
| 2255 | LauncherLogProto.Action.Direction.NONE, |
| 2256 | LauncherLogProto.ContainerType.OVERVIEW, mWorkspace.getCurrentPage()); |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2257 | showWorkspace(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2258 | } |
| 2259 | return; |
| 2260 | } |
| 2261 | |
| 2262 | if (v instanceof CellLayout) { |
| 2263 | if (mWorkspace.isInOverviewMode()) { |
Jon Miranda | c6cf493 | 2017-02-07 17:12:36 -0800 | [diff] [blame] | 2264 | int page = mWorkspace.indexOfChild(v); |
| 2265 | getUserEventDispatcher().logActionOnContainer(LauncherLogProto.Action.Type.TOUCH, |
| 2266 | LauncherLogProto.Action.Direction.NONE, |
| 2267 | LauncherLogProto.ContainerType.OVERVIEW, page); |
| 2268 | mWorkspace.snapToPageFromOverView(page); |
Sunny Goyal | ce5a7e5 | 2015-07-08 15:44:27 -0700 | [diff] [blame] | 2269 | showWorkspace(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2270 | } |
Sunny Goyal | ce5a7e5 | 2015-07-08 15:44:27 -0700 | [diff] [blame] | 2271 | return; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2274 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2275 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2276 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2277 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2278 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2279 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2280 | } |
Hyunyoung Song | d725f64 | 2017-08-17 22:26:35 -0700 | [diff] [blame] | 2281 | } else if ((v instanceof PageIndicator) || |
Adam Cohen | bf78f3c | 2017-07-14 15:58:48 -0700 | [diff] [blame] | 2282 | (v == mAllAppsButton && mAllAppsButton != null)) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2283 | onClickAllAppsButton(v); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2284 | } else if (tag instanceof AppInfo) { |
| 2285 | startAppShortcutOrInfoActivity(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2286 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2287 | if (v instanceof PendingAppWidgetHostView) { |
| 2288 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2289 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2290 | } |
| 2291 | } |
| 2292 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 2293 | @SuppressLint("ClickableViewAccessibility") |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2294 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2295 | return false; |
| 2296 | } |
| 2297 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2298 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2299 | * Event handler for the app widget view which has not fully restored. |
| 2300 | */ |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2301 | public void onClickPendingWidget(final PendingAppWidgetHostView v) { |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2302 | if (mIsSafeModeEnabled) { |
| 2303 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2304 | return; |
| 2305 | } |
| 2306 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2307 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2308 | if (v.isReadyForClickSetup()) { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2309 | LauncherAppWidgetProviderInfo appWidgetInfo = |
| 2310 | mAppWidgetManager.findProvider(info.providerName, info.user); |
| 2311 | if (appWidgetInfo == null) { |
| 2312 | return; |
| 2313 | } |
| 2314 | WidgetAddFlowHandler addFlowHandler = new WidgetAddFlowHandler(appWidgetInfo); |
| 2315 | |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2316 | if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { |
| 2317 | if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) { |
| 2318 | // This should not happen, as we make sure that an Id is allocated during bind. |
| 2319 | return; |
| 2320 | } |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2321 | addFlowHandler.startBindFlow(this, info.appWidgetId, info, |
| 2322 | REQUEST_BIND_PENDING_APPWIDGET); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 2323 | } else { |
Sunny Goyal | 04a324a | 2017-01-20 21:08:59 -0800 | [diff] [blame] | 2324 | addFlowHandler.startConfigActivity(this, info, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2325 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2326 | } else { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2327 | final String packageName = info.providerName.getPackageName(); |
Sunny Goyal | e6e7200 | 2017-01-12 16:55:36 -0800 | [diff] [blame] | 2328 | onClickPendingAppItem(v, packageName, info.installProgress >= 0); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | /** |
Adam Cohen | bf78f3c | 2017-07-14 15:58:48 -0700 | [diff] [blame] | 2333 | * Event handler for the "grid" button or "caret" that appears on the home screen, which |
| 2334 | * enters all apps mode. In verticalBarLayout the caret can be seen when all apps is open, and |
| 2335 | * so in that case reverses the action. |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2336 | * |
| 2337 | * @param v The view that was clicked. |
| 2338 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2339 | protected void onClickAllAppsButton(View v) { |
| 2340 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 2341 | if (!isAppsViewVisible()) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2342 | getUserEventDispatcher().logActionOnControl(Action.Touch.TAP, |
| 2343 | ControlType.ALL_APPS_BUTTON); |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 2344 | showAppsView(true /* animated */, true /* updatePredictedApps */); |
Adam Cohen | 5441a9d | 2017-07-14 14:22:05 -0700 | [diff] [blame] | 2345 | } else { |
| 2346 | showWorkspace(true); |
| 2347 | } |
| 2348 | } |
| 2349 | |
Sunny Goyal | e6e7200 | 2017-01-12 16:55:36 -0800 | [diff] [blame] | 2350 | private void onClickPendingAppItem(final View v, final String packageName, |
| 2351 | boolean downloadStarted) { |
| 2352 | if (downloadStarted) { |
| 2353 | // If the download has started, simply direct to the market app. |
| 2354 | startMarketIntentForPackage(v, packageName); |
| 2355 | return; |
| 2356 | } |
Sunny Goyal | e03b812 | 2014-10-08 09:55:24 -0700 | [diff] [blame] | 2357 | new AlertDialog.Builder(this) |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2358 | .setTitle(R.string.abandoned_promises_title) |
| 2359 | .setMessage(R.string.abandoned_promise_explanation) |
Sunny Goyal | e6e7200 | 2017-01-12 16:55:36 -0800 | [diff] [blame] | 2360 | .setPositiveButton(R.string.abandoned_search, new DialogInterface.OnClickListener() { |
| 2361 | @Override |
| 2362 | public void onClick(DialogInterface dialogInterface, int i) { |
| 2363 | startMarketIntentForPackage(v, packageName); |
| 2364 | } |
| 2365 | }) |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2366 | .setNeutralButton(R.string.abandoned_clean_this, |
| 2367 | new DialogInterface.OnClickListener() { |
| 2368 | public void onClick(DialogInterface dialog, int id) { |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 2369 | final UserHandle user = Process.myUserHandle(); |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2370 | mWorkspace.removeAbandonedPromise(packageName, user); |
| 2371 | } |
| 2372 | }) |
| 2373 | .create().show(); |
Sunny Goyal | e6e7200 | 2017-01-12 16:55:36 -0800 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | private void startMarketIntentForPackage(View v, String packageName) { |
| 2377 | ItemInfo item = (ItemInfo) v.getTag(); |
| 2378 | Intent intent = PackageManagerHelper.getMarketIntent(packageName); |
| 2379 | boolean success = startActivitySafely(v, intent, item); |
| 2380 | if (success && v instanceof BubbleTextView) { |
| 2381 | mWaitingForResume = (BubbleTextView) v; |
| 2382 | mWaitingForResume.setStayPressed(true); |
| 2383 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2386 | /** |
| 2387 | * Event handler for an app shortcut click. |
| 2388 | * |
| 2389 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2390 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2391 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2392 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2393 | Object tag = v.getTag(); |
| 2394 | if (!(tag instanceof ShortcutInfo)) { |
| 2395 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2396 | } |
| 2397 | |
| 2398 | // Open shortcut |
| 2399 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2400 | |
| 2401 | if (shortcut.isDisabled != 0) { |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 2402 | if ((shortcut.isDisabled & |
| 2403 | ~ShortcutInfo.FLAG_DISABLED_SUSPENDED & |
| 2404 | ~ShortcutInfo.FLAG_DISABLED_QUIET_USER) == 0) { |
| 2405 | // If the app is only disabled because of the above flags, launch activity anyway. |
| 2406 | // Framework will tell the user why the app is suspended. |
Kenny Guy | 44cba69 | 2016-01-21 19:50:02 +0000 | [diff] [blame] | 2407 | } else { |
Tony Wickham | 4efffc5 | 2016-08-04 16:34:49 -0700 | [diff] [blame] | 2408 | if (!TextUtils.isEmpty(shortcut.disabledMessage)) { |
| 2409 | // Use a message specific to this shortcut, if it has one. |
| 2410 | Toast.makeText(this, shortcut.disabledMessage, Toast.LENGTH_SHORT).show(); |
| 2411 | return; |
| 2412 | } |
| 2413 | // Otherwise just use a generic error message. |
Kenny Guy | 44cba69 | 2016-01-21 19:50:02 +0000 | [diff] [blame] | 2414 | int error = R.string.activity_not_available; |
| 2415 | if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) { |
| 2416 | error = R.string.safemode_shortcut_error; |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 2417 | } else if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_BY_PUBLISHER) != 0 || |
| 2418 | (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_LOCKED_USER) != 0) { |
Sunny Goyal | 70a7c9b | 2016-07-28 10:07:32 -0700 | [diff] [blame] | 2419 | error = R.string.shortcut_not_available; |
Kenny Guy | 44cba69 | 2016-01-21 19:50:02 +0000 | [diff] [blame] | 2420 | } |
| 2421 | Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); |
| 2422 | return; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2423 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2426 | // Check for abandoned promise |
Sunny Goyal | e6e7200 | 2017-01-12 16:55:36 -0800 | [diff] [blame] | 2427 | if ((v instanceof BubbleTextView) && shortcut.isPromise()) { |
| 2428 | String packageName = shortcut.intent.getComponent() != null ? |
| 2429 | shortcut.intent.getComponent().getPackageName() : shortcut.intent.getPackage(); |
| 2430 | if (!TextUtils.isEmpty(packageName)) { |
| 2431 | onClickPendingAppItem(v, packageName, |
| 2432 | shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)); |
| 2433 | return; |
| 2434 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2435 | } |
| 2436 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2437 | // Start activities |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2438 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2439 | } |
| 2440 | |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2441 | private void startAppShortcutOrInfoActivity(View v) { |
| 2442 | ItemInfo item = (ItemInfo) v.getTag(); |
Mario Bertschler | 08ffaae | 2017-03-20 11:30:27 -0700 | [diff] [blame] | 2443 | Intent intent; |
| 2444 | if (item instanceof PromiseAppInfo) { |
| 2445 | PromiseAppInfo promiseAppInfo = (PromiseAppInfo) item; |
| 2446 | intent = promiseAppInfo.getMarketIntent(); |
| 2447 | } else { |
| 2448 | intent = item.getIntent(); |
| 2449 | } |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2450 | if (intent == null) { |
| 2451 | throw new IllegalArgumentException("Input must have a valid intent"); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2452 | } |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2453 | boolean success = startActivitySafely(v, intent, item); |
Mario Bertschler | 0fc6f68 | 2017-02-17 12:16:13 -0800 | [diff] [blame] | 2454 | getUserEventDispatcher().logAppLaunch(v, intent); // TODO for discovered apps b/35802115 |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2455 | |
| 2456 | if (success && v instanceof BubbleTextView) { |
| 2457 | mWaitingForResume = (BubbleTextView) v; |
| 2458 | mWaitingForResume.setStayPressed(true); |
| 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | /** |
| 2463 | * Event handler for a folder icon click. |
| 2464 | * |
| 2465 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2466 | */ |
| 2467 | protected void onClickFolderIcon(View v) { |
| 2468 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2469 | if (!(v instanceof FolderIcon)){ |
| 2470 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2471 | } |
| 2472 | |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 2473 | Folder folder = ((FolderIcon) v).getFolder(); |
| 2474 | if (!folder.isOpen() && !folder.isDestroyed()) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2475 | // Open the requested folder |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 2476 | folder.animateOpen(); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2477 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2480 | /** |
| 2481 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2482 | * on the home screen. |
| 2483 | */ |
Sunny Goyal | d0a6ae7 | 2016-06-16 12:29:03 -0700 | [diff] [blame] | 2484 | public void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2485 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2486 | if (mIsSafeModeEnabled) { |
| 2487 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2488 | } else { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2489 | showWidgetsView(true /* animated */, true /* resetPageToZero */); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2490 | } |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2491 | } |
| 2492 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2493 | /** |
| 2494 | * Event handler for the wallpaper picker button that appears after a long press |
| 2495 | * on the home screen. |
| 2496 | */ |
Sunny Goyal | d0a6ae7 | 2016-06-16 12:29:03 -0700 | [diff] [blame] | 2497 | public void onClickWallpaperPicker(View v) { |
Hyunyoung Song | 0de0117 | 2016-10-05 16:27:48 -0700 | [diff] [blame] | 2498 | if (!Utilities.isWallpaperAllowed(this)) { |
Sunny Goyal | 1ed6c4a | 2016-04-21 15:16:11 -0700 | [diff] [blame] | 2499 | Toast.makeText(this, R.string.msg_disabled_by_admin, Toast.LENGTH_SHORT).show(); |
| 2500 | return; |
| 2501 | } |
| 2502 | |
Tony Wickham | 785f7a5 | 2015-08-31 17:28:32 -0700 | [diff] [blame] | 2503 | int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen()); |
| 2504 | float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll); |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2505 | setWaitingForResult(new PendingRequestArgs(new ItemInfo())); |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 2506 | Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER) |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 2507 | .putExtra(Utilities.EXTRA_WALLPAPER_OFFSET, offset); |
Sunny Goyal | c677b6b | 2016-10-17 09:59:01 +0100 | [diff] [blame] | 2508 | |
| 2509 | String pickerPackage = getString(R.string.wallpaper_picker_package); |
Tony | 85efb4b | 2017-06-02 13:06:10 -0700 | [diff] [blame] | 2510 | boolean hasTargetPackage = !TextUtils.isEmpty(pickerPackage); |
| 2511 | if (hasTargetPackage) { |
Sunny Goyal | c677b6b | 2016-10-17 09:59:01 +0100 | [diff] [blame] | 2512 | intent.setPackage(pickerPackage); |
| 2513 | } |
| 2514 | |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 2515 | intent.setSourceBounds(getViewBounds(v)); |
Sunny Goyal | c677b6b | 2016-10-17 09:59:01 +0100 | [diff] [blame] | 2516 | try { |
| 2517 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER, |
| 2518 | // If there is no target package, use the default intent chooser animation |
| 2519 | hasTargetPackage ? getActivityLaunchOptions(v) : null); |
| 2520 | } catch (ActivityNotFoundException e) { |
| 2521 | setWaitingForResult(null); |
| 2522 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2523 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | /** |
| 2527 | * Event handler for a click on the settings button that appears after a long press |
| 2528 | * on the home screen. |
| 2529 | */ |
Sunny Goyal | d0a6ae7 | 2016-06-16 12:29:03 -0700 | [diff] [blame] | 2530 | public void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2531 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
Sunny Goyal | f3a09f9 | 2016-08-25 09:45:14 -0700 | [diff] [blame] | 2532 | Intent intent = new Intent(Intent.ACTION_APPLICATION_PREFERENCES) |
| 2533 | .setPackage(getPackageName()); |
| 2534 | intent.setSourceBounds(getViewBounds(v)); |
Sunny Goyal | 53f93b9 | 2017-05-04 11:23:29 -0700 | [diff] [blame] | 2535 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Sunny Goyal | f3a09f9 | 2016-08-25 09:45:14 -0700 | [diff] [blame] | 2536 | startActivity(intent, getActivityLaunchOptions(v)); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2539 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2540 | if (mHapticFeedbackTouchListener == null) { |
| 2541 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 2542 | @SuppressLint("ClickableViewAccessibility") |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2543 | @Override |
| 2544 | public boolean onTouch(View v, MotionEvent event) { |
| 2545 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2546 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2547 | } |
| 2548 | return false; |
| 2549 | } |
| 2550 | }; |
| 2551 | } |
| 2552 | return mHapticFeedbackTouchListener; |
| 2553 | } |
| 2554 | |
Tony Wickham | e221725 | 2016-03-22 16:34:23 -0700 | [diff] [blame] | 2555 | @Override |
| 2556 | public void onAccessibilityStateChanged(boolean enabled) { |
| 2557 | mDragLayer.onAccessibilityStateChanged(enabled); |
| 2558 | } |
| 2559 | |
Sunny Goyal | 06e21a2 | 2016-08-11 16:02:02 -0700 | [diff] [blame] | 2560 | public void onDragStarted() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2561 | if (isOnCustomContent()) { |
| 2562 | // Custom content screen doesn't participate in drag and drop. If on custom |
| 2563 | // content screen, move to default. |
| 2564 | moveWorkspaceToDefaultScreen(); |
| 2565 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2566 | } |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2567 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2568 | /** |
| 2569 | * Called when the user stops interacting with the launcher. |
| 2570 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2571 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2572 | protected void onInteractionEnd() { |
| 2573 | if (mLauncherCallbacks != null) { |
| 2574 | mLauncherCallbacks.onInteractionEnd(); |
| 2575 | } |
| 2576 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2577 | |
| 2578 | /** |
| 2579 | * Called when the user starts interacting with the launcher. |
| 2580 | * The possible interactions are: |
| 2581 | * - open all apps |
| 2582 | * - reorder an app shortcut, or a widget |
| 2583 | * - open the overview mode. |
| 2584 | * This is a good time to stop doing things that only make sense |
| 2585 | * when the user is on the homescreen and not doing housekeeping. |
| 2586 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2587 | protected void onInteractionBegin() { |
| 2588 | if (mLauncherCallbacks != null) { |
| 2589 | mLauncherCallbacks.onInteractionBegin(); |
| 2590 | } |
| 2591 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2592 | |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 2593 | /** Updates the interaction state. */ |
| 2594 | public void updateInteraction(Workspace.State fromState, Workspace.State toState) { |
Winson Chung | 83f59ab | 2015-05-05 17:21:58 -0700 | [diff] [blame] | 2595 | // Only update the interacting state if we are transitioning to/from a view with an |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 2596 | // overlay |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 2597 | boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL; |
| 2598 | boolean toStateWithOverlay = toState != Workspace.State.NORMAL; |
Winson Chung | 83f59ab | 2015-05-05 17:21:58 -0700 | [diff] [blame] | 2599 | if (toStateWithOverlay) { |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 2600 | onInteractionBegin(); |
Winson Chung | 83f59ab | 2015-05-05 17:21:58 -0700 | [diff] [blame] | 2601 | } else if (fromStateWithOverlay) { |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 2602 | onInteractionEnd(); |
| 2603 | } |
| 2604 | } |
| 2605 | |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2606 | private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2607 | try { |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2608 | StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy(); |
| 2609 | try { |
| 2610 | // Temporarily disable deathPenalty on all default checks. For eg, shortcuts |
| 2611 | // containing file Uri's would cause a crash as penaltyDeathOnFileUriExposure |
| 2612 | // is enabled by default on NYC. |
| 2613 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll() |
| 2614 | .penaltyLog().build()); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 2615 | |
| 2616 | if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { |
| 2617 | String id = ((ShortcutInfo) info).getDeepShortcutId(); |
| 2618 | String packageName = intent.getPackage(); |
Sunny Goyal | dde4fd9 | 2016-11-21 16:02:39 +0530 | [diff] [blame] | 2619 | DeepShortcutManager.getInstance(this).startShortcut( |
Sunny Goyal | 9994b2b | 2016-06-23 14:17:24 -0700 | [diff] [blame] | 2620 | packageName, id, intent.getSourceBounds(), optsBundle, info.user); |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 2621 | } else { |
| 2622 | // Could be launching some bookkeeping activity |
| 2623 | startActivity(intent, optsBundle); |
| 2624 | } |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2625 | } finally { |
| 2626 | StrictMode.setVmPolicy(oldPolicy); |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2627 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2628 | } catch (SecurityException e) { |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2629 | // Due to legacy reasons, direct call shortcuts require Launchers to have the |
| 2630 | // corresponding permission. Show the appropriate permission prompt if that |
| 2631 | // is the case. |
| 2632 | if (intent.getComponent() == null |
| 2633 | && Intent.ACTION_CALL.equals(intent.getAction()) |
| 2634 | && checkSelfPermission(Manifest.permission.CALL_PHONE) != |
| 2635 | PackageManager.PERMISSION_GRANTED) { |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2636 | |
| 2637 | setWaitingForResult(PendingRequestArgs |
| 2638 | .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info)); |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2639 | requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, |
| 2640 | REQUEST_PERMISSION_CALL_PHONE); |
| 2641 | } else { |
| 2642 | // No idea why this was thrown. |
| 2643 | throw e; |
Sunny Goyal | 28c6b96 | 2015-10-12 11:42:05 -0700 | [diff] [blame] | 2644 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2645 | } |
| 2646 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2647 | |
Sunny Goyal | fe770c9 | 2016-09-27 14:38:58 -0700 | [diff] [blame] | 2648 | @TargetApi(Build.VERSION_CODES.M) |
Tony | e3c5925 | 2017-05-02 21:32:27 -0700 | [diff] [blame] | 2649 | public Bundle getActivityLaunchOptions(View v) { |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2650 | if (Utilities.ATLEAST_MARSHMALLOW) { |
| 2651 | int left = 0, top = 0; |
| 2652 | int width = v.getMeasuredWidth(), height = v.getMeasuredHeight(); |
Hyunyoung Song | 1322f9c | 2017-06-23 14:57:38 -0700 | [diff] [blame] | 2653 | if (v instanceof BubbleTextView) { |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2654 | // Launch from center of icon, not entire view |
Hyunyoung Song | 1322f9c | 2017-06-23 14:57:38 -0700 | [diff] [blame] | 2655 | Drawable icon = ((BubbleTextView) v).getIcon(); |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2656 | if (icon != null) { |
| 2657 | Rect bounds = icon.getBounds(); |
| 2658 | left = (width - bounds.width()) / 2; |
| 2659 | top = v.getPaddingTop(); |
| 2660 | width = bounds.width(); |
| 2661 | height = bounds.height(); |
| 2662 | } |
| 2663 | } |
| 2664 | return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height).toBundle(); |
| 2665 | } else if (Utilities.ATLEAST_LOLLIPOP_MR1) { |
| 2666 | // On L devices, we use the device default slide-up transition. |
| 2667 | // On L MR1 devices, we use a custom version of the slide-up transition which |
| 2668 | // doesn't have the delay present in the device default. |
| 2669 | return ActivityOptions.makeCustomAnimation( |
| 2670 | this, R.anim.task_open_enter, R.anim.no_anim).toBundle(); |
| 2671 | } |
| 2672 | return null; |
| 2673 | } |
| 2674 | |
Tony | e3c5925 | 2017-05-02 21:32:27 -0700 | [diff] [blame] | 2675 | public Rect getViewBounds(View v) { |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 2676 | int[] pos = new int[2]; |
| 2677 | v.getLocationOnScreen(pos); |
| 2678 | return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); |
| 2679 | } |
| 2680 | |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2681 | public boolean startActivitySafely(View v, Intent intent, ItemInfo item) { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2682 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 2683 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 2684 | return false; |
| 2685 | } |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2686 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 2687 | // private contract between launcher and may be ignored in the future). |
| 2688 | boolean useLaunchAnimation = (v != null) && |
| 2689 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
| 2690 | Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null; |
| 2691 | |
Sunny Goyal | 24bb66a | 2017-03-21 15:12:01 -0700 | [diff] [blame] | 2692 | UserHandle user = item == null ? null : item.user; |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2693 | |
| 2694 | // Prepare intent |
| 2695 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2696 | if (v != null) { |
Sunny Goyal | 0eca4e2 | 2016-07-20 11:43:06 -0700 | [diff] [blame] | 2697 | intent.setSourceBounds(getViewBounds(v)); |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2698 | } |
| 2699 | try { |
Mario Bertschler | 0fc6f68 | 2017-02-17 12:16:13 -0800 | [diff] [blame] | 2700 | if (Utilities.ATLEAST_MARSHMALLOW |
| 2701 | && (item instanceof ShortcutInfo) |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 2702 | && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT |
Mario Bertschler | 0fc6f68 | 2017-02-17 12:16:13 -0800 | [diff] [blame] | 2703 | || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) |
Sunny Goyal | e6e7200 | 2017-01-12 16:55:36 -0800 | [diff] [blame] | 2704 | && !((ShortcutInfo) item).isPromise()) { |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2705 | // Shortcuts need some special checks due to legacy reasons. |
| 2706 | startShortcutIntentSafely(intent, optsBundle, item); |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 2707 | } else if (user == null || user.equals(Process.myUserHandle())) { |
Sunny Goyal | a7ce166 | 2016-05-31 15:01:35 -0700 | [diff] [blame] | 2708 | // Could be launching some bookkeeping activity |
| 2709 | startActivity(intent, optsBundle); |
| 2710 | } else { |
| 2711 | LauncherAppsCompat.getInstance(this).startActivityForProfile( |
| 2712 | intent.getComponent(), user, intent.getSourceBounds(), optsBundle); |
| 2713 | } |
| 2714 | return true; |
| 2715 | } catch (ActivityNotFoundException|SecurityException e) { |
| 2716 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2717 | Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e); |
| 2718 | } |
| 2719 | return false; |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
Tony Wickham | dadb304 | 2016-02-24 11:07:00 -0800 | [diff] [blame] | 2722 | @Override |
Jon Miranda | 379198e | 2016-09-23 08:54:40 -0700 | [diff] [blame] | 2723 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 2724 | mLastDispatchTouchEventX = ev.getX(); |
| 2725 | return super.dispatchTouchEvent(ev); |
| 2726 | } |
| 2727 | |
| 2728 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2729 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 2730 | if (!isDraggingEnabled()) return false; |
| 2731 | if (isWorkspaceLocked()) return false; |
| 2732 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2733 | |
Jon Miranda | 51f037d | 2016-11-07 08:37:20 -0800 | [diff] [blame] | 2734 | boolean ignoreLongPressToOverview = |
| 2735 | mDeviceProfile.shouldIgnoreLongPressToOverview(mLastDispatchTouchEventX); |
Jon Miranda | 379198e | 2016-09-23 08:54:40 -0700 | [diff] [blame] | 2736 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2737 | if (v instanceof Workspace) { |
| 2738 | if (!mWorkspace.isInOverviewMode()) { |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 2739 | if (!mWorkspace.isTouchActive() && !ignoreLongPressToOverview) { |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2740 | getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS, |
| 2741 | Action.Direction.NONE, ContainerType.WORKSPACE, |
Jon Miranda | f3e35d9 | 2016-10-05 14:08:11 -0700 | [diff] [blame] | 2742 | mWorkspace.getCurrentPage()); |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2743 | showOverviewMode(true); |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 2744 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2745 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 2746 | return true; |
| 2747 | } else { |
| 2748 | return false; |
| 2749 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 2750 | } else { |
| 2751 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2752 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 2755 | CellLayout.CellInfo longClickCellInfo = null; |
| 2756 | View itemUnderLongClick = null; |
| 2757 | if (v.getTag() instanceof ItemInfo) { |
| 2758 | ItemInfo info = (ItemInfo) v.getTag(); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2759 | longClickCellInfo = new CellLayout.CellInfo(v, info); |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 2760 | itemUnderLongClick = longClickCellInfo.cell; |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 2761 | mPendingRequestArgs = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2762 | } |
| 2763 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2764 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 2765 | // on hotseat items. |
Sunny Goyal | 8e2133b | 2015-05-06 13:39:07 -0700 | [diff] [blame] | 2766 | if (!mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2767 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 2768 | // User long pressed on empty space |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 2769 | if (mWorkspace.isInOverviewMode()) { |
| 2770 | mWorkspace.startReordering(v); |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2771 | getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS, |
| 2772 | Action.Direction.NONE, ContainerType.OVERVIEW); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 2773 | } else { |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 2774 | if (ignoreLongPressToOverview) { |
Jon Miranda | 379198e | 2016-09-23 08:54:40 -0700 | [diff] [blame] | 2775 | return false; |
| 2776 | } |
Sunny Goyal | 6c46a6d | 2016-11-23 02:24:32 +0530 | [diff] [blame] | 2777 | getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS, |
| 2778 | Action.Direction.NONE, ContainerType.WORKSPACE, |
Jon Miranda | f3e35d9 | 2016-10-05 14:08:11 -0700 | [diff] [blame] | 2779 | mWorkspace.getCurrentPage()); |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2780 | showOverviewMode(true); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2781 | } |
Jon Miranda | 379198e | 2016-09-23 08:54:40 -0700 | [diff] [blame] | 2782 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2783 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2784 | } else { |
Sunny Goyal | bb011da | 2016-06-15 15:42:29 -0700 | [diff] [blame] | 2785 | final boolean isAllAppsButton = |
| 2786 | !FeatureFlags.NO_ALL_APPS_ICON && isHotseatLayout(v) && |
| 2787 | mDeviceProfile.inv.isAllAppsButtonRank(mHotseat.getOrderInHotseat( |
| 2788 | longClickCellInfo.cellX, longClickCellInfo.cellY)); |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 2789 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2790 | // User long pressed on an item |
Tony Wickham | 10236d6 | 2016-09-28 12:49:25 -0700 | [diff] [blame] | 2791 | mWorkspace.startDrag(longClickCellInfo, new DragOptions()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2792 | } |
| 2793 | } |
| 2794 | } |
| 2795 | return true; |
| 2796 | } |
| 2797 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2798 | boolean isHotseatLayout(View layout) { |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 2799 | // TODO: Remove this method |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2800 | return mHotseat != null && layout != null && |
| 2801 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 2802 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2803 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2804 | /** |
| 2805 | * Returns the CellLayout of the specified container at the specified screen. |
| 2806 | */ |
Sunny Goyal | 9282059 | 2015-03-02 11:31:35 -0800 | [diff] [blame] | 2807 | public CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2808 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2809 | if (mHotseat != null) { |
| 2810 | return mHotseat.getLayout(); |
| 2811 | } else { |
| 2812 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2813 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2814 | } else { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2815 | return mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2816 | } |
| 2817 | } |
| 2818 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2819 | /** |
| 2820 | * For overridden classes. |
| 2821 | */ |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2822 | public boolean isAllAppsVisible() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2823 | return isAppsViewVisible(); |
| 2824 | } |
| 2825 | |
| 2826 | public boolean isAppsViewVisible() { |
| 2827 | return (mState == State.APPS) || (mOnResumeState == State.APPS); |
| 2828 | } |
| 2829 | |
| 2830 | public boolean isWidgetsViewVisible() { |
| 2831 | return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 2834 | @Override |
| 2835 | public void onTrimMemory(int level) { |
| 2836 | super.onTrimMemory(level); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 2837 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
| 2838 | // The widget preview db can result in holding onto over |
| 2839 | // 3MB of memory for caching which isn't necessary. |
| 2840 | SQLiteDatabase.releaseMemory(); |
| 2841 | |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 2842 | // This clears all widget bitmaps from the widget tray |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 2843 | // TODO(hyunyoungs) |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 2844 | } |
Robert Kozikowski | 67c3086 | 2015-03-30 23:46:46 +0100 | [diff] [blame] | 2845 | if (mLauncherCallbacks != null) { |
| 2846 | mLauncherCallbacks.onTrimMemory(level); |
| 2847 | } |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 2848 | } |
| 2849 | |
Winson | 5c6bdbb | 2015-09-03 11:36:19 -0700 | [diff] [blame] | 2850 | public boolean showWorkspace(boolean animated) { |
Winson | 10612a7 | 2015-09-09 17:06:09 -0700 | [diff] [blame] | 2851 | return showWorkspace(animated, null); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Winson | 5c6bdbb | 2015-09-03 11:36:19 -0700 | [diff] [blame] | 2854 | public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 2855 | boolean changed = mState != State.WORKSPACE || |
| 2856 | mWorkspace.getState() != Workspace.State.NORMAL; |
Hyunyoung Song | 9dcf0a3 | 2016-07-27 10:55:51 -0700 | [diff] [blame] | 2857 | if (changed || mAllAppsController.isTransitioning()) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2858 | mWorkspace.setVisibility(View.VISIBLE); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 2859 | mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(), |
Winson | 2a87fe8 | 2015-08-07 10:37:21 -0700 | [diff] [blame] | 2860 | Workspace.State.NORMAL, animated, onCompleteRunnable); |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 2861 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2862 | // Set focus to the AppsCustomize button |
| 2863 | if (mAllAppsButton != null) { |
| 2864 | mAllAppsButton.requestFocus(); |
| 2865 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2866 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 2867 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2868 | // Change the state *after* we've called all the transition code |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 2869 | setState(State.WORKSPACE); |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 2870 | |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 2871 | if (changed) { |
| 2872 | // Send an accessibility event to announce the context change |
| 2873 | getWindow().getDecorView() |
| 2874 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 2875 | } |
Winson | 5c6bdbb | 2015-09-03 11:36:19 -0700 | [diff] [blame] | 2876 | return changed; |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2877 | } |
| 2878 | |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 2879 | /** |
| 2880 | * Shows the overview button. |
| 2881 | */ |
Sunny Goyal | d0a6ae7 | 2016-06-16 12:29:03 -0700 | [diff] [blame] | 2882 | public void showOverviewMode(boolean animated) { |
Winson | e9f2727 | 2015-10-13 10:47:51 -0700 | [diff] [blame] | 2883 | showOverviewMode(animated, false); |
| 2884 | } |
| 2885 | |
| 2886 | /** |
| 2887 | * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus |
| 2888 | * onto one of the overview panel buttons. |
| 2889 | */ |
| 2890 | void showOverviewMode(boolean animated, boolean requestButtonFocus) { |
| 2891 | Runnable postAnimRunnable = null; |
| 2892 | if (requestButtonFocus) { |
| 2893 | postAnimRunnable = new Runnable() { |
| 2894 | @Override |
| 2895 | public void run() { |
| 2896 | // Hitting the menu button when in touch mode does not trigger touch mode to |
| 2897 | // be disabled, so if requested, force focus on one of the overview panel |
| 2898 | // buttons. |
| 2899 | mOverviewPanel.requestFocusFromTouch(); |
| 2900 | } |
| 2901 | }; |
| 2902 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2903 | mWorkspace.setVisibility(View.VISIBLE); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 2904 | mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(), |
Winson | 6e6a9b4 | 2015-10-13 17:52:17 -0700 | [diff] [blame] | 2905 | Workspace.State.OVERVIEW, animated, postAnimRunnable); |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 2906 | setState(State.WORKSPACE); |
| 2907 | |
Hyunyoung Song | 0a9c092 | 2016-09-20 22:50:06 -0700 | [diff] [blame] | 2908 | // If animated from long press, then don't allow any of the controller in the drag |
| 2909 | // layer to intercept any remaining touch. |
| 2910 | mWorkspace.requestDisallowInterceptTouchEvent(animated); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2911 | } |
| 2912 | |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 2913 | private void setState(State state) { |
| 2914 | this.mState = state; |
| 2915 | updateSoftInputMode(); |
| 2916 | } |
| 2917 | |
| 2918 | private void updateSoftInputMode() { |
| 2919 | if (FeatureFlags.LAUNCHER3_UPDATE_SOFT_INPUT_MODE) { |
| 2920 | final int mode; |
| 2921 | if (isAppsViewVisible()) { |
| 2922 | mode = SOFT_INPUT_MODE_ALL_APPS; |
| 2923 | } else { |
| 2924 | mode = SOFT_INPUT_MODE_DEFAULT; |
| 2925 | } |
| 2926 | getWindow().setSoftInputMode(mode); |
| 2927 | } |
| 2928 | } |
| 2929 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2930 | /** |
| 2931 | * Shows the apps view. |
| 2932 | */ |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 2933 | public void showAppsView(boolean animated, boolean updatePredictedApps) { |
Hyunyoung Song | c001cf5 | 2016-07-21 17:32:43 -0700 | [diff] [blame] | 2934 | markAppsViewShown(); |
Winson Chung | 4ac3006 | 2015-05-08 17:34:17 -0700 | [diff] [blame] | 2935 | if (updatePredictedApps) { |
| 2936 | tryAndUpdatePredictedApps(); |
| 2937 | } |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 2938 | showAppsOrWidgets(State.APPS, animated); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2939 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2940 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2941 | /** |
| 2942 | * Shows the widgets view. |
| 2943 | */ |
| 2944 | void showWidgetsView(boolean animated, boolean resetPageToZero) { |
Sunny Goyal | 2bba4c3 | 2015-05-18 15:42:48 -0700 | [diff] [blame] | 2945 | if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero); |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 2946 | if (resetPageToZero) { |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 2947 | mWidgetsView.scrollToTop(); |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 2948 | } |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 2949 | showAppsOrWidgets(State.WIDGETS, animated); |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 2950 | |
| 2951 | mWidgetsView.post(new Runnable() { |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 2952 | @Override |
| 2953 | public void run() { |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 2954 | mWidgetsView.requestFocus(); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 2955 | } |
| 2956 | }); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | /** |
| 2960 | * Sets up the transition to show the apps/widgets view. |
Hyunyoung Song | b790083 | 2015-05-15 16:29:45 -0700 | [diff] [blame] | 2961 | * |
| 2962 | * @return whether the current from and to state allowed this operation |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2963 | */ |
Hyunyoung Song | b790083 | 2015-05-15 16:29:45 -0700 | [diff] [blame] | 2964 | // TODO: calling method should use the return value so that when {@code false} is returned |
| 2965 | // the workspace transition doesn't fall into invalid state. |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 2966 | private boolean showAppsOrWidgets(State toState, boolean animated) { |
Hyunyoung Song | 9dcf0a3 | 2016-07-27 10:55:51 -0700 | [diff] [blame] | 2967 | if (!(mState == State.WORKSPACE || |
| 2968 | mState == State.APPS_SPRING_LOADED || |
| 2969 | mState == State.WIDGETS_SPRING_LOADED || |
| 2970 | (mState == State.APPS && mAllAppsController.isTransitioning()))) { |
Hyunyoung Song | b790083 | 2015-05-15 16:29:45 -0700 | [diff] [blame] | 2971 | return false; |
| 2972 | } |
| 2973 | if (toState != State.APPS && toState != State.WIDGETS) { |
| 2974 | return false; |
| 2975 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2976 | |
Hyunyoung Song | 06ca756 | 2016-07-29 13:03:54 -0700 | [diff] [blame] | 2977 | // This is a safe and supported transition to bypass spring_loaded mode. |
| 2978 | if (mExitSpringLoadedModeRunnable != null) { |
| 2979 | mHandler.removeCallbacks(mExitSpringLoadedModeRunnable); |
| 2980 | mExitSpringLoadedModeRunnable = null; |
| 2981 | } |
| 2982 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2983 | if (toState == State.APPS) { |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 2984 | mStateTransitionAnimation.startAnimationToAllApps(animated); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2985 | } else { |
Sunny Goyal | db36437 | 2016-10-26 19:12:47 -0700 | [diff] [blame] | 2986 | mStateTransitionAnimation.startAnimationToWidgets(animated); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2987 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2988 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2989 | // Change the state *after* we've called all the transition code |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 2990 | setState(toState); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 2991 | AbstractFloatingView.closeAllOpenViews(this); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2992 | |
| 2993 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 2994 | getWindow().getDecorView() |
| 2995 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Hyunyoung Song | b790083 | 2015-05-15 16:29:45 -0700 | [diff] [blame] | 2996 | return true; |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 2999 | /** |
| 3000 | * Updates the workspace and interaction state on state change, and return the animation to this |
| 3001 | * new state. |
| 3002 | */ |
Sunny Goyal | ce5a7e5 | 2015-07-08 15:44:27 -0700 | [diff] [blame] | 3003 | public Animator startWorkspaceStateChangeAnimation(Workspace.State toState, |
Sunny Goyal | b5e65c8 | 2016-10-26 18:32:38 -0700 | [diff] [blame] | 3004 | boolean animated, AnimationLayerSet layerViews) { |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 3005 | Workspace.State fromState = mWorkspace.getState(); |
Winson | 2a87fe8 | 2015-08-07 10:37:21 -0700 | [diff] [blame] | 3006 | Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews); |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 3007 | updateInteraction(fromState, toState); |
| 3008 | return anim; |
| 3009 | } |
| 3010 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 3011 | public void enterSpringLoadedDragMode() { |
Sunny Goyal | 2bba4c3 | 2015-05-18 15:42:48 -0700 | [diff] [blame] | 3012 | if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name())); |
Tony Wickham | 94e0d37 | 2015-09-11 12:17:48 -0700 | [diff] [blame] | 3013 | if (isStateSpringLoaded()) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3014 | return; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3015 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3016 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 3017 | mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(), |
Winson | 2a87fe8 | 2015-08-07 10:37:21 -0700 | [diff] [blame] | 3018 | Workspace.State.SPRING_LOADED, true /* animated */, |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 3019 | null /* onCompleteRunnable */); |
Mario Bertschler | acbf570 | 2017-03-03 10:58:06 -0800 | [diff] [blame] | 3020 | setState(State.WORKSPACE_SPRING_LOADED); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3021 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3022 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 3023 | public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3024 | final Runnable onCompleteRunnable) { |
Tony Wickham | 94e0d37 | 2015-09-11 12:17:48 -0700 | [diff] [blame] | 3025 | if (!isStateSpringLoaded()) return; |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3026 | |
Hyunyoung Song | 06ca756 | 2016-07-29 13:03:54 -0700 | [diff] [blame] | 3027 | if (mExitSpringLoadedModeRunnable != null) { |
| 3028 | mHandler.removeCallbacks(mExitSpringLoadedModeRunnable); |
| 3029 | } |
| 3030 | mExitSpringLoadedModeRunnable = new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3031 | @Override |
| 3032 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3033 | if (successfulDrop) { |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 3034 | // TODO(hyunyoungs): verify if this hack is still needed, if not, delete. |
| 3035 | // |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3036 | // Before we show workspace, hide all apps again because |
| 3037 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 3038 | // clean up our state transition functions |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 3039 | mWidgetsView.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3040 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3041 | } else { |
| 3042 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3043 | } |
Hyunyoung Song | 06ca756 | 2016-07-29 13:03:54 -0700 | [diff] [blame] | 3044 | mExitSpringLoadedModeRunnable = null; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3045 | } |
Hyunyoung Song | 06ca756 | 2016-07-29 13:03:54 -0700 | [diff] [blame] | 3046 | }; |
| 3047 | mHandler.postDelayed(mExitSpringLoadedModeRunnable, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3048 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3049 | |
Tony Wickham | e0c3323 | 2016-02-08 11:37:04 -0800 | [diff] [blame] | 3050 | boolean isStateSpringLoaded() { |
Tony Wickham | 94e0d37 | 2015-09-11 12:17:48 -0700 | [diff] [blame] | 3051 | return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED |
| 3052 | || mState == State.WIDGETS_SPRING_LOADED; |
| 3053 | } |
| 3054 | |
Sunny Goyal | 0f76b56 | 2016-12-13 19:37:10 -0800 | [diff] [blame] | 3055 | public void exitSpringLoadedDragMode() { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3056 | if (mState == State.APPS_SPRING_LOADED) { |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 3057 | showAppsView(true /* animated */, false /* updatePredictedApps */); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3058 | } else if (mState == State.WIDGETS_SPRING_LOADED) { |
Winson Chung | cd99cd3 | 2015-04-29 11:03:24 -0700 | [diff] [blame] | 3059 | showWidgetsView(true, false); |
Tony Wickham | 94e0d37 | 2015-09-11 12:17:48 -0700 | [diff] [blame] | 3060 | } else if (mState == State.WORKSPACE_SPRING_LOADED) { |
| 3061 | showWorkspace(true); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3062 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3063 | } |
| 3064 | |
Winson Chung | 4ac3006 | 2015-05-08 17:34:17 -0700 | [diff] [blame] | 3065 | /** |
| 3066 | * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was |
| 3067 | * resumed. |
| 3068 | */ |
Hyunyoung Song | a9a8a42 | 2016-06-15 16:45:48 -0700 | [diff] [blame] | 3069 | public void tryAndUpdatePredictedApps() { |
Winson Chung | 4ac3006 | 2015-05-08 17:34:17 -0700 | [diff] [blame] | 3070 | if (mLauncherCallbacks != null) { |
Winson Chung | 6b1c73f | 2015-06-18 11:38:42 -0700 | [diff] [blame] | 3071 | List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps(); |
Winson Chung | 91c0595 | 2015-06-25 12:17:30 -0700 | [diff] [blame] | 3072 | if (apps != null) { |
Winson Chung | 4ac3006 | 2015-05-08 17:34:17 -0700 | [diff] [blame] | 3073 | mAppsView.setPredictedApps(apps); |
| 3074 | } |
| 3075 | } |
| 3076 | } |
| 3077 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3078 | void lockAllApps() { |
| 3079 | // TODO |
| 3080 | } |
| 3081 | |
| 3082 | void unlockAllApps() { |
| 3083 | // TODO |
| 3084 | } |
| 3085 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3086 | @Override |
| 3087 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3088 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3089 | final List<CharSequence> text = event.getText(); |
| 3090 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3091 | // Populate event with a fake title based on the current state. |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3092 | if (mState == State.APPS) { |
Sunny Goyal | c525d80 | 2015-04-29 11:05:34 -0700 | [diff] [blame] | 3093 | text.add(getString(R.string.all_apps_button_label)); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3094 | } else if (mState == State.WIDGETS) { |
Sunny Goyal | c525d80 | 2015-04-29 11:05:34 -0700 | [diff] [blame] | 3095 | text.add(getString(R.string.widget_button_text)); |
Hyunyoung Song | 166e648 | 2015-06-25 21:06:07 -0700 | [diff] [blame] | 3096 | } else if (mWorkspace != null) { |
| 3097 | text.add(mWorkspace.getCurrentPageDescription()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3098 | } else { |
| 3099 | text.add(getString(R.string.all_apps_home_button_label)); |
| 3100 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3101 | return result; |
| 3102 | } |
| 3103 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3104 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3105 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 3106 | * in onResume. |
| 3107 | * |
| 3108 | * This needs to be called from incoming places where resources might have been loaded |
Hyunyoung Song | 8821ca9 | 2015-05-04 16:28:20 -0700 | [diff] [blame] | 3109 | * while the activity is paused. That is because the Configuration (e.g., rotation) might be |
| 3110 | * wrong when we're not running, and if the activity comes back to what the configuration was |
| 3111 | * when we were paused, activity is not restarted. |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3112 | * |
| 3113 | * Implementation of the method from LauncherModel.Callbacks. |
| 3114 | * |
Hyunyoung Song | 8821ca9 | 2015-05-04 16:28:20 -0700 | [diff] [blame] | 3115 | * @return {@code true} if we are currently paused. The caller might be able to skip some work |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3116 | */ |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3117 | @Thunk boolean waitUntilResume(Runnable run) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3118 | if (mPaused) { |
Sunny Goyal | 2bba4c3 | 2015-05-18 15:42:48 -0700 | [diff] [blame] | 3119 | if (LOGD) Log.d(TAG, "Deferring update until onResume"); |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3120 | if (run instanceof RunnableWithId) { |
| 3121 | // Remove any runnables which have the same id |
| 3122 | while (mBindOnResumeCallbacks.remove(run)) { } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3123 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3124 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3125 | return true; |
| 3126 | } else { |
| 3127 | return false; |
| 3128 | } |
| 3129 | } |
| 3130 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3131 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 3132 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3133 | } |
| 3134 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3135 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3136 | * If the activity is currently paused, signal that we need to re-run the loader |
| 3137 | * in onResume. |
| 3138 | * |
| 3139 | * This needs to be called from incoming places where resources might have been loaded |
| 3140 | * while we are paused. That is becaues the Configuration might be wrong |
| 3141 | * when we're not running, and if it comes back to what it was when we |
| 3142 | * were paused, we are not restarted. |
| 3143 | * |
| 3144 | * Implementation of the method from LauncherModel.Callbacks. |
| 3145 | * |
| 3146 | * @return true if we are currently paused. The caller might be able to |
| 3147 | * skip some work in that case since we will come back again. |
| 3148 | */ |
Sunny Goyal | 93f878c | 2016-03-30 17:31:24 -0700 | [diff] [blame] | 3149 | @Override |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3150 | public boolean setLoadOnResume() { |
| 3151 | if (mPaused) { |
Sunny Goyal | 2bba4c3 | 2015-05-18 15:42:48 -0700 | [diff] [blame] | 3152 | if (LOGD) Log.d(TAG, "setLoadOnResume"); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3153 | mOnResumeNeedsLoad = true; |
| 3154 | return true; |
| 3155 | } else { |
| 3156 | return false; |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3161 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3162 | */ |
Sunny Goyal | 93f878c | 2016-03-30 17:31:24 -0700 | [diff] [blame] | 3163 | @Override |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3164 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3165 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3166 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3167 | } else { |
Winson Chung | 882a52e | 2015-07-08 14:32:26 -0700 | [diff] [blame] | 3168 | return 0; |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3169 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3170 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3171 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3172 | /** |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 3173 | * Clear any pending bind callbacks. This is called when is loader is planning to |
| 3174 | * perform a full rebind from scratch. |
| 3175 | */ |
| 3176 | @Override |
| 3177 | public void clearPendingBinds() { |
| 3178 | mBindOnResumeCallbacks.clear(); |
| 3179 | if (mPendingExecutor != null) { |
| 3180 | mPendingExecutor.markCompleted(); |
| 3181 | mPendingExecutor = null; |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3186 | * Refreshes the shortcuts shown on the workspace. |
| 3187 | * |
| 3188 | * Implementation of the method from LauncherModel.Callbacks. |
| 3189 | */ |
| 3190 | public void startBinding() { |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 3191 | if (LauncherAppState.PROFILE_STARTUP) { |
| 3192 | Trace.beginSection("Starting page bind"); |
| 3193 | } |
Jon Miranda | 6dc7f1e | 2017-02-21 12:37:51 -0800 | [diff] [blame] | 3194 | |
| 3195 | AbstractFloatingView.closeAllOpenViews(this); |
| 3196 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 3197 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 3198 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3199 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3200 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 3201 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3202 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3203 | if (mHotseat != null) { |
| 3204 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3205 | } |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 3206 | if (LauncherAppState.PROFILE_STARTUP) { |
| 3207 | Trace.endSection(); |
| 3208 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3209 | } |
| 3210 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3211 | @Override |
| 3212 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3213 | // Make sure the first screen is always at the start. |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 3214 | if (FeatureFlags.QSB_ON_FIRST_SCREEN && |
| 3215 | orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3216 | orderedScreenIds.remove(Workspace.FIRST_SCREEN_ID); |
| 3217 | orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID); |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 3218 | LauncherModel.updateWorkspaceScreenOrder(this, orderedScreenIds); |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 3219 | } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) { |
| 3220 | // If there are no screens, we need to have an empty screen |
| 3221 | mWorkspace.addExtraEmptyScreen(); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 3222 | } |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3223 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 3224 | |
| 3225 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 3226 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 3227 | if (hasCustomContentToLeft()) { |
| 3228 | mWorkspace.createCustomContentContainer(); |
| 3229 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 3230 | } |
Winson | c7d2e83 | 2016-07-28 12:24:55 -0700 | [diff] [blame] | 3231 | |
| 3232 | // After we have added all the screens, if the wallpaper was locked to the default state, |
| 3233 | // then notify to indicate that it can be released and a proper wallpaper offset can be |
| 3234 | // computed before the next layout |
| 3235 | mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout(); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3236 | } |
| 3237 | |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3238 | private void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3239 | int count = orderedScreenIds.size(); |
| 3240 | for (int i = 0; i < count; i++) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3241 | long screenId = orderedScreenIds.get(i); |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 3242 | if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3243 | // No need to bind the first screen, as its always bound. |
| 3244 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId); |
| 3245 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3246 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3249 | @Override |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3250 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 3251 | final ArrayList<ItemInfo> addNotAnimated, |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3252 | final ArrayList<ItemInfo> addAnimated) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3253 | Runnable r = new Runnable() { |
| 3254 | public void run() { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3255 | bindAppsAdded(newScreens, addNotAnimated, addAnimated); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3256 | } |
| 3257 | }; |
| 3258 | if (waitUntilResume(r)) { |
| 3259 | return; |
| 3260 | } |
| 3261 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3262 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 3263 | if (newScreens != null) { |
| 3264 | bindAddScreens(newScreens); |
| 3265 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3266 | |
| 3267 | // We add the items without animation on non-visible pages, and with |
| 3268 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 3269 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3270 | bindItems(addNotAnimated, false); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3271 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 3272 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3273 | bindItems(addAnimated, true); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3274 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3275 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 3276 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 3277 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3280 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3281 | * Bind the items start-end from the list. |
| 3282 | * |
| 3283 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3284 | */ |
Tony Wickham | 0bb211a | 2015-10-02 16:22:08 -0700 | [diff] [blame] | 3285 | @Override |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3286 | public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3287 | Runnable r = new Runnable() { |
| 3288 | public void run() { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3289 | bindItems(items, forceAnimateIcons); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3290 | } |
| 3291 | }; |
| 3292 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3293 | return; |
| 3294 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3295 | |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3296 | // 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] | 3297 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 3298 | final Collection<Animator> bounceAnims = new ArrayList<>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 3299 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3300 | Workspace workspace = mWorkspace; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3301 | long newItemsScreenId = -1; |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3302 | int end = items.size(); |
| 3303 | for (int i = 0; i < end; i++) { |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3304 | final ItemInfo item = items.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 3305 | |
| 3306 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 3307 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 3308 | mHotseat == null) { |
| 3309 | continue; |
| 3310 | } |
| 3311 | |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 3312 | final View view; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3313 | switch (item.itemType) { |
| 3314 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 3315 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3316 | case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: { |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3317 | ShortcutInfo info = (ShortcutInfo) item; |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 3318 | view = createShortcut(info); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3319 | break; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3320 | } |
| 3321 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: { |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 3322 | view = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3323 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Sunny Goyal | 1cd01b0 | 2016-11-09 10:43:58 -0800 | [diff] [blame] | 3324 | (FolderInfo) item); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3325 | break; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3326 | } |
| 3327 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: { |
Sunny Goyal | a9a1a21 | 2017-08-18 01:03:21 -0700 | [diff] [blame] | 3328 | view = inflateAppWidget((LauncherAppWidgetInfo) item); |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3329 | if (view == null) { |
| 3330 | continue; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3331 | } |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3332 | break; |
| 3333 | } |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 3334 | default: |
| 3335 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3336 | } |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 3337 | |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3338 | /* |
| 3339 | * Remove colliding items. |
| 3340 | */ |
| 3341 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 3342 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 3343 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
| 3344 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 3345 | Object tag = v.getTag(); |
| 3346 | String desc = "Collision while binding workspace item: " + item |
| 3347 | + ". Collides with " + tag; |
Sunny Goyal | 3d706ad | 2017-03-06 16:56:39 -0800 | [diff] [blame] | 3348 | if (FeatureFlags.IS_DOGFOOD_BUILD) { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3349 | throw (new RuntimeException(desc)); |
| 3350 | } else { |
| 3351 | Log.d(TAG, desc); |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 3352 | getModelWriter().deleteItemFromDatabase(item); |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame] | 3353 | continue; |
| 3354 | } |
| 3355 | } |
| 3356 | } |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 3357 | workspace.addInScreenFromBind(view, item); |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 3358 | if (animateIcons) { |
| 3359 | // Animate all the applications up now |
| 3360 | view.setAlpha(0f); |
| 3361 | view.setScaleX(0f); |
| 3362 | view.setScaleY(0f); |
| 3363 | bounceAnims.add(createNewAppBounceAnimation(view, i)); |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3364 | newItemsScreenId = item.screenId; |
Sunny Goyal | 639e906 | 2015-08-19 19:17:06 -0700 | [diff] [blame] | 3365 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3366 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3367 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 3368 | if (animateIcons) { |
| 3369 | // Animate to the correct page |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3370 | if (newItemsScreenId > -1) { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 3371 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3372 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 3373 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 3374 | public void run() { |
| 3375 | anim.playTogether(bounceAnims); |
| 3376 | anim.start(); |
| 3377 | } |
| 3378 | }; |
Sunny Goyal | 3be633b | 2016-12-08 09:59:25 -0800 | [diff] [blame] | 3379 | if (newItemsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 3380 | // We post the animation slightly delayed to prevent slowdowns |
| 3381 | // when we are loading right after we return to launcher. |
| 3382 | mWorkspace.postDelayed(new Runnable() { |
| 3383 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 3384 | if (mWorkspace != null) { |
| 3385 | mWorkspace.snapToPage(newScreenIndex); |
| 3386 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 3387 | NEW_APPS_ANIMATION_DELAY); |
| 3388 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 3389 | } |
| 3390 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 3391 | } else { |
| 3392 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 3393 | } |
| 3394 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3395 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3396 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3397 | } |
| 3398 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3399 | /** |
| 3400 | * Add the views for a widget to the workspace. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3401 | */ |
Sunny Goyal | a9a1a21 | 2017-08-18 01:03:21 -0700 | [diff] [blame] | 3402 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
| 3403 | View view = inflateAppWidget(item); |
| 3404 | if (view != null) { |
| 3405 | mWorkspace.addInScreen(view, item); |
| 3406 | mWorkspace.requestLayout(); |
| 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | private View inflateAppWidget(LauncherAppWidgetInfo item) { |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3411 | if (mIsSafeModeEnabled) { |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 3412 | PendingAppWidgetHostView view = |
| 3413 | new PendingAppWidgetHostView(this, item, mIconCache, true); |
| 3414 | prepareAppWidget(view, item); |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3415 | return view; |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3416 | } |
| 3417 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3418 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 3419 | if (DEBUG_WIDGETS) { |
| 3420 | Log.d(TAG, "bindAppWidget: " + item); |
| 3421 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3422 | |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3423 | final LauncherAppWidgetProviderInfo appWidgetInfo; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3424 | |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3425 | if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) { |
| 3426 | // If the provider is not ready, bind as a pending widget. |
| 3427 | appWidgetInfo = null; |
| 3428 | } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { |
| 3429 | // The widget id is not valid. Try to find the widget based on the provider info. |
| 3430 | appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user); |
| 3431 | } else { |
| 3432 | appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId); |
| 3433 | } |
Sunny Goyal | 84b4adc | 2015-08-12 15:12:16 -0700 | [diff] [blame] | 3434 | |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3435 | // If the provider is ready, but the width is not yet restored, try to restore it. |
| 3436 | if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) && |
| 3437 | (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3438 | if (appWidgetInfo == null) { |
| 3439 | if (DEBUG_WIDGETS) { |
| 3440 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 3441 | + " belongs to component " + item.providerName |
Hyunyoung Song | 0de0117 | 2016-10-05 16:27:48 -0700 | [diff] [blame] | 3442 | + ", as the provider is null"); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3443 | } |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 3444 | getModelWriter().deleteItemFromDatabase(item); |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3445 | return null; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3446 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3447 | |
Sunny Goyal | 84b4adc | 2015-08-12 15:12:16 -0700 | [diff] [blame] | 3448 | // 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] | 3449 | if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3450 | if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) { |
| 3451 | // Id has not been allocated yet. Allocate a new id. |
| 3452 | item.appWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 3453 | item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3454 | |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3455 | // Also try to bind the widget. If the bind fails, the user will be shown |
| 3456 | // a click to setup UI, which will ask for the bind permission. |
Sunny Goyal | a52ecb0 | 2016-12-16 15:04:51 -0800 | [diff] [blame] | 3457 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3458 | pendingInfo.spanX = item.spanX; |
| 3459 | pendingInfo.spanY = item.spanY; |
| 3460 | pendingInfo.minSpanX = item.minSpanX; |
| 3461 | pendingInfo.minSpanY = item.minSpanY; |
| 3462 | Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo); |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 3463 | |
| 3464 | boolean isDirectConfig = |
| 3465 | item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG); |
| 3466 | if (isDirectConfig && item.bindOptions != null) { |
| 3467 | Bundle newOptions = item.bindOptions.getExtras(); |
| 3468 | if (options != null) { |
| 3469 | newOptions.putAll(options); |
| 3470 | } |
| 3471 | options = newOptions; |
| 3472 | } |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3473 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 3474 | item.appWidgetId, appWidgetInfo, options); |
Sunny Goyal | 84b4adc | 2015-08-12 15:12:16 -0700 | [diff] [blame] | 3475 | |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 3476 | // We tried to bind once. If we were not able to bind, we would need to |
| 3477 | // go through the permission dialog, which means we cannot skip the config |
| 3478 | // activity. |
| 3479 | item.bindOptions = null; |
| 3480 | item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG; |
| 3481 | |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3482 | // Bind succeeded |
| 3483 | if (success) { |
| 3484 | // If the widget has a configure activity, it is still needs to set it up, |
| 3485 | // otherwise the widget is ready to go. |
Sunny Goyal | 86df138 | 2016-08-10 15:03:22 -0700 | [diff] [blame] | 3486 | item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3487 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 3488 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
Sunny Goyal | 84b4adc | 2015-08-12 15:12:16 -0700 | [diff] [blame] | 3489 | } |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3490 | |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 3491 | getModelWriter().updateItemInDatabase(item); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3492 | } |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3493 | } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY) |
Sunny Goyal | 84b4adc | 2015-08-12 15:12:16 -0700 | [diff] [blame] | 3494 | && (appWidgetInfo.configure == null)) { |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3495 | // The widget was marked as UI not ready, but there is no configure activity to |
| 3496 | // update the UI. |
Sunny Goyal | 84b4adc | 2015-08-12 15:12:16 -0700 | [diff] [blame] | 3497 | item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 3498 | getModelWriter().updateItemInDatabase(item); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3499 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 3502 | final AppWidgetHostView view; |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3503 | if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 3504 | if (DEBUG_WIDGETS) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3505 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " |
| 3506 | + appWidgetInfo.provider); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 3507 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3508 | |
Sunny Goyal | 56c7360 | 2015-09-25 12:55:01 -0700 | [diff] [blame] | 3509 | // Verify that we own the widget |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3510 | if (appWidgetInfo == null) { |
Sunny Goyal | 713edfc | 2016-05-06 09:58:34 -0700 | [diff] [blame] | 3511 | FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId); |
Sunny Goyal | 56c7360 | 2015-09-25 12:55:01 -0700 | [diff] [blame] | 3512 | deleteWidgetInfo(item); |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3513 | return null; |
Sunny Goyal | 56c7360 | 2015-09-25 12:55:01 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
Sunny Goyal | 233ee96 | 2015-08-03 13:05:01 -0700 | [diff] [blame] | 3516 | item.minSpanX = appWidgetInfo.minSpanX; |
| 3517 | item.minSpanY = appWidgetInfo.minSpanY; |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 3518 | view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 3519 | } else { |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 3520 | view = new PendingAppWidgetHostView(this, item, mIconCache, false); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 3521 | } |
Sunny Goyal | d5462aa | 2016-11-22 16:52:39 +0530 | [diff] [blame] | 3522 | prepareAppWidget(view, item); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3523 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3524 | if (DEBUG_WIDGETS) { |
| 3525 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 3526 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 3527 | } |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3528 | return view; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3529 | } |
| 3530 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3531 | /** |
| 3532 | * Restores a pending widget. |
| 3533 | * |
| 3534 | * @param appWidgetId The app widget id |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3535 | */ |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3536 | private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3537 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 3538 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 3539 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3540 | return null; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3541 | } |
| 3542 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 3543 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3544 | info.restoreStatus = finalRestoreFlag; |
Jon Miranda | 2b823f4 | 2017-05-02 18:36:18 -0700 | [diff] [blame] | 3545 | if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 3546 | info.pendingItemInfo = null; |
| 3547 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3548 | |
| 3549 | mWorkspace.reinflateWidgetsIfNecessary(); |
Sunny Goyal | 43bf11d | 2017-02-02 13:52:53 -0800 | [diff] [blame] | 3550 | getModelWriter().updateItemInDatabase(info); |
Sunny Goyal | d478c83 | 2016-04-01 12:04:16 -0700 | [diff] [blame] | 3551 | return info; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 3554 | public void onPageBoundSynchronously(int page) { |
| 3555 | mSynchronouslyBoundPages.add(page); |
| 3556 | } |
| 3557 | |
Sunny Goyal | 527c7d3 | 2015-08-28 15:19:36 -0700 | [diff] [blame] | 3558 | @Override |
| 3559 | public void executeOnNextDraw(ViewOnDrawExecutor executor) { |
| 3560 | if (mPendingExecutor != null) { |
| 3561 | mPendingExecutor.markCompleted(); |
| 3562 | } |
| 3563 | mPendingExecutor = executor; |
| 3564 | executor.attachTo(this); |
| 3565 | } |
| 3566 | |
| 3567 | public void clearPendingExecutor(ViewOnDrawExecutor executor) { |
| 3568 | if (mPendingExecutor == executor) { |
| 3569 | mPendingExecutor = null; |
| 3570 | } |
| 3571 | } |
| 3572 | |
Sunny Goyal | b5b9ad6 | 2016-04-02 11:23:39 -0700 | [diff] [blame] | 3573 | @Override |
| 3574 | public void finishFirstPageBind(final ViewOnDrawExecutor executor) { |
| 3575 | Runnable r = new Runnable() { |
| 3576 | public void run() { |
| 3577 | finishFirstPageBind(executor); |
| 3578 | } |
| 3579 | }; |
| 3580 | if (waitUntilResume(r)) { |
| 3581 | return; |
| 3582 | } |
| 3583 | |
| 3584 | Runnable onComplete = new Runnable() { |
| 3585 | @Override |
| 3586 | public void run() { |
| 3587 | if (executor != null) { |
| 3588 | executor.onLoadAnimationCompleted(); |
| 3589 | } |
| 3590 | } |
| 3591 | }; |
| 3592 | if (mDragLayer.getAlpha() < 1) { |
| 3593 | mDragLayer.animate().alpha(1).withEndAction(onComplete).start(); |
| 3594 | } else { |
| 3595 | onComplete.run(); |
| 3596 | } |
| 3597 | } |
| 3598 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3599 | /** |
| 3600 | * Callback saying that there aren't any more items to bind. |
| 3601 | * |
| 3602 | * Implementation of the method from LauncherModel.Callbacks. |
| 3603 | */ |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 3604 | public void finishBindingItems() { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3605 | Runnable r = new Runnable() { |
| 3606 | public void run() { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 3607 | finishBindingItems(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3608 | } |
| 3609 | }; |
| 3610 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3611 | return; |
| 3612 | } |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 3613 | if (LauncherAppState.PROFILE_STARTUP) { |
| 3614 | Trace.beginSection("Page bind completed"); |
| 3615 | } |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 3616 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3617 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 3618 | setWorkspaceLoading(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 3619 | |
Sunny Goyal | 2100c78 | 2016-08-22 16:00:03 -0700 | [diff] [blame] | 3620 | if (mPendingActivityResult != null) { |
| 3621 | handleActivityResult(mPendingActivityResult.requestCode, |
| 3622 | mPendingActivityResult.resultCode, mPendingActivityResult.data); |
| 3623 | mPendingActivityResult = null; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
Sunny Goyal | a474a9b | 2017-05-04 16:47:11 -0700 | [diff] [blame] | 3626 | InstallShortcutReceiver.disableAndFlushInstallQueue( |
| 3627 | InstallShortcutReceiver.FLAG_LOADER_RUNNING, this); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3628 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 3629 | NotificationListener.setNotificationsChangedListener(mPopupDataProvider); |
| 3630 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3631 | if (mLauncherCallbacks != null) { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 3632 | mLauncherCallbacks.finishBindingItems(false); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3633 | } |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 3634 | if (LauncherAppState.PROFILE_STARTUP) { |
| 3635 | Trace.endSection(); |
| 3636 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3639 | private boolean canRunNewAppsAnimation() { |
| 3640 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
Andrew Sapperstein | 932eb83 | 2016-06-30 18:10:09 -0700 | [diff] [blame] | 3641 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3642 | } |
| 3643 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 3644 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
Sunny Goyal | 5d2fc32 | 2015-07-06 22:52:49 -0700 | [diff] [blame] | 3645 | ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 3646 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 3647 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame] | 3648 | bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION)); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 3649 | return bounceAnim; |
| 3650 | } |
| 3651 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 3652 | public boolean useVerticalBarLayout() { |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 3653 | return mDeviceProfile.isVerticalBarLayout(); |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 3654 | } |
| 3655 | |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 3656 | public int getSearchBarHeight() { |
| 3657 | if (mLauncherCallbacks != null) { |
| 3658 | return mLauncherCallbacks.getSearchBarHeight(); |
| 3659 | } |
| 3660 | return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL; |
| 3661 | } |
| 3662 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3663 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3664 | * Add the icons for all apps. |
| 3665 | * |
| 3666 | * Implementation of the method from LauncherModel.Callbacks. |
| 3667 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 3668 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3669 | Runnable r = new RunnableWithId(RUNNABLE_ID_BIND_APPS) { |
| 3670 | public void run() { |
| 3671 | bindAllApplications(apps); |
| 3672 | } |
| 3673 | }; |
| 3674 | if (waitUntilResume(r)) { |
Winson Chung | bb785c6 | 2015-05-05 10:05:08 -0700 | [diff] [blame] | 3675 | return; |
| 3676 | } |
| 3677 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3678 | if (mAppsView != null) { |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 3679 | Executor pendingExecutor = getPendingExecutor(); |
| 3680 | if (pendingExecutor != null && mState != State.APPS) { |
| 3681 | // Wait until the fade in animation has finished before setting all apps list. |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3682 | pendingExecutor.execute(r); |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 3683 | return; |
| 3684 | } |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3685 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3686 | mAppsView.setApps(apps); |
| 3687 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3688 | if (mLauncherCallbacks != null) { |
| 3689 | mLauncherCallbacks.bindAllApplications(apps); |
| 3690 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | /** |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 3694 | * Returns an Executor that will run after the launcher is first drawn (including after the |
| 3695 | * initial fade in animation). Returns null if the first draw has already occurred. |
| 3696 | */ |
| 3697 | public @Nullable Executor getPendingExecutor() { |
| 3698 | return mPendingExecutor != null && mPendingExecutor.canQueue() ? mPendingExecutor : null; |
| 3699 | } |
| 3700 | |
| 3701 | /** |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 3702 | * Copies LauncherModel's map of activities to shortcut ids to Launcher's. This is necessary |
| 3703 | * because LauncherModel's map is updated in the background, while Launcher runs on the UI. |
| 3704 | */ |
| 3705 | @Override |
| 3706 | public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMapCopy) { |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 3707 | mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy); |
Tony Wickham | 1bce7fd | 2016-04-28 17:39:03 -0700 | [diff] [blame] | 3708 | } |
| 3709 | |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 3710 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3711 | * A package was updated. |
| 3712 | * |
| 3713 | * Implementation of the method from LauncherModel.Callbacks. |
| 3714 | */ |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3715 | public void bindAppsAddedOrUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3716 | Runnable r = new Runnable() { |
| 3717 | public void run() { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3718 | bindAppsAddedOrUpdated(apps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3719 | } |
| 3720 | }; |
| 3721 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3722 | return; |
| 3723 | } |
| 3724 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3725 | if (mAppsView != null) { |
Sunny Goyal | b23980c | 2017-08-17 07:45:25 -0700 | [diff] [blame] | 3726 | mAppsView.addOrUpdateApps(apps); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3727 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3728 | } |
| 3729 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3730 | @Override |
Mario Bertschler | 08ffaae | 2017-03-20 11:30:27 -0700 | [diff] [blame] | 3731 | public void bindPromiseAppProgressUpdated(final PromiseAppInfo app) { |
| 3732 | Runnable r = new Runnable() { |
| 3733 | public void run() { |
| 3734 | bindPromiseAppProgressUpdated(app); |
| 3735 | } |
| 3736 | }; |
| 3737 | if (waitUntilResume(r)) { |
| 3738 | return; |
| 3739 | } |
| 3740 | |
| 3741 | if (mAppsView != null) { |
| 3742 | mAppsView.updatePromiseAppProgress(app); |
| 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | @Override |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3747 | public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) { |
| 3748 | Runnable r = new Runnable() { |
| 3749 | public void run() { |
| 3750 | bindWidgetsRestored(widgets); |
| 3751 | } |
| 3752 | }; |
| 3753 | if (waitUntilResume(r)) { |
| 3754 | return; |
| 3755 | } |
| 3756 | mWorkspace.widgetsRestored(widgets); |
| 3757 | } |
| 3758 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3759 | /** |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3760 | * Some shortcuts were updated in the background. |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3761 | * Implementation of the method from LauncherModel.Callbacks. |
Sunny Goyal | d3b87ef | 2016-07-28 12:11:54 -0700 | [diff] [blame] | 3762 | * |
| 3763 | * @param updated list of shortcuts which have changed. |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3764 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3765 | @Override |
Sunny Goyal | 6e13dd3 | 2017-08-17 03:01:19 -0700 | [diff] [blame] | 3766 | public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated, final UserHandle user) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3767 | Runnable r = new Runnable() { |
| 3768 | public void run() { |
Sunny Goyal | 6e13dd3 | 2017-08-17 03:01:19 -0700 | [diff] [blame] | 3769 | bindShortcutsChanged(updated, user); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3770 | } |
| 3771 | }; |
| 3772 | if (waitUntilResume(r)) { |
| 3773 | return; |
| 3774 | } |
| 3775 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3776 | if (!updated.isEmpty()) { |
| 3777 | mWorkspace.updateShortcuts(updated); |
| 3778 | } |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 3782 | * Update the state of a package, typically related to install state. |
| 3783 | * |
| 3784 | * Implementation of the method from LauncherModel.Callbacks. |
| 3785 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 3786 | @Override |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 3787 | public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) { |
| 3788 | Runnable r = new Runnable() { |
| 3789 | public void run() { |
| 3790 | bindRestoreItemsChange(updates); |
| 3791 | } |
| 3792 | }; |
| 3793 | if (waitUntilResume(r)) { |
| 3794 | return; |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 3795 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 3796 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 3797 | mWorkspace.updateRestoreItems(updates); |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | /** |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 3801 | * 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] | 3802 | * in addition to specific applications to remove, the reason being that |
| 3803 | * 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] | 3804 | * we only remove specific components from the workspace and hotseat, where as |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3805 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3806 | */ |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 3807 | @Override |
Sunny Goyal | 6e13dd3 | 2017-08-17 03:01:19 -0700 | [diff] [blame] | 3808 | public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3809 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3810 | public void run() { |
Sunny Goyal | 6e13dd3 | 2017-08-17 03:01:19 -0700 | [diff] [blame] | 3811 | bindWorkspaceComponentsRemoved(matcher); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3812 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3813 | }; |
| 3814 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3815 | return; |
| 3816 | } |
Sunny Goyal | 6e13dd3 | 2017-08-17 03:01:19 -0700 | [diff] [blame] | 3817 | mWorkspace.removeItemsByMatcher(matcher); |
| 3818 | mDragController.onAppsRemoved(matcher); |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 3819 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 3820 | |
Sunny Goyal | 3bbbabc | 2016-03-15 09:16:30 -0700 | [diff] [blame] | 3821 | @Override |
| 3822 | public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) { |
| 3823 | Runnable r = new Runnable() { |
| 3824 | public void run() { |
| 3825 | bindAppInfosRemoved(appInfos); |
| 3826 | } |
| 3827 | }; |
| 3828 | if (waitUntilResume(r)) { |
| 3829 | return; |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3830 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3831 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 3832 | // Update AllApps |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 3833 | if (mAppsView != null) { |
| 3834 | mAppsView.removeApps(appInfos); |
Hyunyoung Song | 51114f2 | 2017-05-02 16:06:28 -0700 | [diff] [blame] | 3835 | tryAndUpdatePredictedApps(); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3836 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3837 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3838 | |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3839 | @Override |
| 3840 | public void bindAllWidgets(final MultiHashMap<PackageItemInfo, WidgetItem> allWidgets) { |
| 3841 | Runnable r = new RunnableWithId(RUNNABLE_ID_BIND_WIDGETS) { |
| 3842 | @Override |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3843 | public void run() { |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3844 | bindAllWidgets(allWidgets); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3845 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3846 | }; |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3847 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 3848 | return; |
| 3849 | } |
| 3850 | |
Sunny Goyal | d164b7f | 2016-10-12 20:49:31 -0700 | [diff] [blame] | 3851 | if (mWidgetsView != null && allWidgets != null) { |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 3852 | Executor pendingExecutor = getPendingExecutor(); |
| 3853 | if (pendingExecutor != null && mState != State.WIDGETS) { |
Sunny Goyal | 49fc3f7 | 2017-08-18 10:17:06 -0700 | [diff] [blame] | 3854 | pendingExecutor.execute(r); |
Tony | 2917a8b | 2017-07-31 23:29:42 -0700 | [diff] [blame] | 3855 | return; |
| 3856 | } |
Sunny Goyal | d164b7f | 2016-10-12 20:49:31 -0700 | [diff] [blame] | 3857 | mWidgetsView.setWidgets(allWidgets); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3858 | } |
Tony Wickham | 26b1746 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 3859 | |
| 3860 | AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this); |
| 3861 | if (topView != null) { |
| 3862 | topView.onWidgetsBound(); |
| 3863 | } |
| 3864 | } |
| 3865 | |
| 3866 | public List<WidgetItem> getWidgetsForPackageUser(PackageUserKey packageUserKey) { |
| 3867 | return mWidgetsView.getWidgetsForPackageUser(packageUserKey); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3868 | } |
| 3869 | |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3870 | @Override |
| 3871 | public void notifyWidgetProvidersChanged() { |
Tony Wickham | 86222d2 | 2017-03-29 15:30:43 -0700 | [diff] [blame] | 3872 | if (mWorkspace.getState().shouldUpdateWidget) { |
| 3873 | refreshAndBindWidgetsForPackageUser(null); |
| 3874 | } |
Tony Wickham | 26b1746 | 2017-03-20 17:12:24 -0700 | [diff] [blame] | 3875 | } |
| 3876 | |
Tony Wickham | 86222d2 | 2017-03-29 15:30:43 -0700 | [diff] [blame] | 3877 | /** |
| 3878 | * @param packageUser if null, refreshes all widgets and shortcuts, otherwise only |
| 3879 | * refreshes the widgets and shortcuts associated with the given package/user |
| 3880 | */ |
| 3881 | public void refreshAndBindWidgetsForPackageUser(@Nullable PackageUserKey packageUser) { |
Sunny Goyal | c6e9769 | 2017-06-02 13:46:55 -0700 | [diff] [blame] | 3882 | mModel.refreshAndBindWidgetsAndShortcuts(packageUser); |
Sunny Goyal | 2e1efb4 | 2016-03-03 16:58:55 -0800 | [diff] [blame] | 3883 | } |
| 3884 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 3885 | public void lockScreenOrientation() { |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 3886 | if (mRotationEnabled) { |
Sunny Goyal | a52ecb0 | 2016-12-16 15:04:51 -0800 | [diff] [blame] | 3887 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 3888 | } |
| 3889 | } |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 3890 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 3891 | public void unlockScreenOrientation(boolean immediate) { |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 3892 | if (mRotationEnabled) { |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 3893 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 3894 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 3895 | } else { |
| 3896 | mHandler.postDelayed(new Runnable() { |
| 3897 | public void run() { |
| 3898 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 3899 | } |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 3900 | }, RESTORE_SCREEN_ORIENTATION_DELAY); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 3901 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 3902 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 3903 | } |
| 3904 | |
Hyunyoung Song | c001cf5 | 2016-07-21 17:32:43 -0700 | [diff] [blame] | 3905 | private void markAppsViewShown() { |
| 3906 | if (mSharedPrefs.getBoolean(APPS_VIEW_SHOWN, false)) { |
| 3907 | return; |
| 3908 | } |
| 3909 | mSharedPrefs.edit().putBoolean(APPS_VIEW_SHOWN, true).apply(); |
| 3910 | } |
| 3911 | |
| 3912 | private boolean shouldShowDiscoveryBounce() { |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 3913 | if (mState != State.WORKSPACE) { |
Hyunyoung Song | c001cf5 | 2016-07-21 17:32:43 -0700 | [diff] [blame] | 3914 | return false; |
| 3915 | } |
| 3916 | if (mLauncherCallbacks != null && mLauncherCallbacks.shouldShowDiscoveryBounce()) { |
| 3917 | return true; |
| 3918 | } |
| 3919 | if (!mIsResumeFromActionScreenOff) { |
| 3920 | return false; |
| 3921 | } |
Rajeev Kumar | 43c0f58 | 2017-06-23 15:34:55 -0700 | [diff] [blame] | 3922 | return !mSharedPrefs.getBoolean(APPS_VIEW_SHOWN, false); |
Hyunyoung Song | c001cf5 | 2016-07-21 17:32:43 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Winson Chung | 5ffd51d | 2015-06-25 11:36:50 -0700 | [diff] [blame] | 3925 | protected void moveWorkspaceToDefaultScreen() { |
| 3926 | mWorkspace.moveToDefaultScreen(false); |
| 3927 | } |
| 3928 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3929 | /** |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 3930 | * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all] |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3931 | */ |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 3932 | @Override |
| 3933 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 3934 | super.dump(prefix, fd, writer, args); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 3935 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 3936 | if (args.length > 0 && TextUtils.equals(args[0], "--all")) { |
| 3937 | writer.println(prefix + "Workspace Items"); |
| 3938 | for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) { |
| 3939 | writer.println(prefix + " Homescreen " + i); |
| 3940 | |
| 3941 | ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets(); |
| 3942 | for (int j = 0; j < layout.getChildCount(); j++) { |
| 3943 | Object tag = layout.getChildAt(j).getTag(); |
| 3944 | if (tag != null) { |
| 3945 | writer.println(prefix + " " + tag.toString()); |
| 3946 | } |
| 3947 | } |
| 3948 | } |
| 3949 | |
| 3950 | writer.println(prefix + " Hotseat"); |
| 3951 | ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets(); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 3952 | for (int j = 0; j < layout.getChildCount(); j++) { |
| 3953 | Object tag = layout.getChildAt(j).getTag(); |
| 3954 | if (tag != null) { |
| 3955 | writer.println(prefix + " " + tag.toString()); |
| 3956 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 3957 | } |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 3958 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 3959 | try { |
| 3960 | FileLog.flushAll(writer); |
| 3961 | } catch (Exception e) { |
| 3962 | // Ignore |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 3963 | } |
| 3964 | } |
| 3965 | |
Hyunyoung Song | 3c7d9cb | 2017-01-30 15:11:27 -0800 | [diff] [blame] | 3966 | writer.println(prefix + "Misc:"); |
| 3967 | writer.print(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading); |
| 3968 | writer.print(" mPendingRequestArgs=" + mPendingRequestArgs); |
| 3969 | writer.println(" mPendingActivityResult=" + mPendingActivityResult); |
| 3970 | |
| 3971 | mModel.dumpState(prefix, fd, writer, args); |
Sunny Goyal | a136545 | 2015-10-01 15:46:24 -0700 | [diff] [blame] | 3972 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3973 | if (mLauncherCallbacks != null) { |
| 3974 | mLauncherCallbacks.dump(prefix, fd, writer, args); |
| 3975 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 3976 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 3977 | |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3978 | @Override |
| 3979 | @TargetApi(Build.VERSION_CODES.N) |
| 3980 | public void onProvideKeyboardShortcuts( |
| 3981 | List<KeyboardShortcutGroup> data, Menu menu, int deviceId) { |
| 3982 | |
| 3983 | ArrayList<KeyboardShortcutInfo> shortcutInfos = new ArrayList<>(); |
| 3984 | if (mState == State.WORKSPACE) { |
| 3985 | shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.all_apps_button_label), |
| 3986 | KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON)); |
| 3987 | } |
| 3988 | View currentFocus = getCurrentFocus(); |
| 3989 | if (new CustomActionsPopup(this, currentFocus).canShow()) { |
| 3990 | shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.custom_actions), |
| 3991 | KeyEvent.KEYCODE_O, KeyEvent.META_CTRL_ON)); |
| 3992 | } |
Tony | 18c4aa4 | 2017-05-10 21:23:57 -0500 | [diff] [blame] | 3993 | if (currentFocus.getTag() instanceof ItemInfo |
| 3994 | && DeepShortcutManager.supportsShortcuts((ItemInfo) currentFocus.getTag())) { |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 3995 | shortcutInfos.add(new KeyboardShortcutInfo(getString(R.string.action_deep_shortcut), |
| 3996 | KeyEvent.KEYCODE_S, KeyEvent.META_CTRL_ON)); |
| 3997 | } |
| 3998 | if (!shortcutInfos.isEmpty()) { |
| 3999 | data.add(new KeyboardShortcutGroup(getString(R.string.home_screen), shortcutInfos)); |
| 4000 | } |
| 4001 | |
| 4002 | super.onProvideKeyboardShortcuts(data, menu, deviceId); |
| 4003 | } |
| 4004 | |
| 4005 | @Override |
| 4006 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 4007 | if (event.hasModifiers(KeyEvent.META_CTRL_ON)) { |
| 4008 | switch (keyCode) { |
| 4009 | case KeyEvent.KEYCODE_A: |
| 4010 | if (mState == State.WORKSPACE) { |
Sunny Goyal | 5606e07 | 2017-06-15 14:24:21 -0700 | [diff] [blame] | 4011 | showAppsView(true, true); |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 4012 | return true; |
| 4013 | } |
| 4014 | break; |
| 4015 | case KeyEvent.KEYCODE_S: { |
| 4016 | View focusedView = getCurrentFocus(); |
| 4017 | if (focusedView instanceof BubbleTextView |
| 4018 | && focusedView.getTag() instanceof ItemInfo |
| 4019 | && mAccessibilityDelegate.performAction(focusedView, |
| 4020 | (ItemInfo) focusedView.getTag(), |
| 4021 | LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) { |
Tony Wickham | 540913e | 2017-01-23 11:47:51 -0800 | [diff] [blame] | 4022 | PopupContainerWithArrow.getOpen(this).requestFocus(); |
Sunny Goyal | 66b2457 | 2016-09-21 15:57:55 -0700 | [diff] [blame] | 4023 | return true; |
| 4024 | } |
| 4025 | break; |
| 4026 | } |
| 4027 | case KeyEvent.KEYCODE_O: |
| 4028 | if (new CustomActionsPopup(this, getCurrentFocus()).show()) { |
| 4029 | return true; |
| 4030 | } |
| 4031 | break; |
| 4032 | } |
| 4033 | } |
| 4034 | return super.onKeyShortcut(keyCode, event); |
| 4035 | } |
| 4036 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4037 | public static CustomAppWidget getCustomAppWidget(String name) { |
| 4038 | return sCustomAppWidgets.get(name); |
| 4039 | } |
| 4040 | |
| 4041 | public static HashMap<String, CustomAppWidget> getCustomAppWidgets() { |
| 4042 | return sCustomAppWidgets; |
| 4043 | } |
| 4044 | |
Andrew Sapperstein | abef55a | 2016-06-19 12:49:00 -0700 | [diff] [blame] | 4045 | public static Launcher getLauncher(Context context) { |
| 4046 | if (context instanceof Launcher) { |
| 4047 | return (Launcher) context; |
| 4048 | } |
| 4049 | return ((Launcher) ((ContextWrapper) context).getBaseContext()); |
| 4050 | } |
| 4051 | |
Sunny Goyal | 5a81c38 | 2017-03-20 15:08:06 -0700 | [diff] [blame] | 4052 | private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener { |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 4053 | |
| 4054 | @Override |
| 4055 | public void onSharedPreferenceChanged( |
| 4056 | SharedPreferences sharedPreferences, String key) { |
| 4057 | if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(key)) { |
Sunny Goyal | e13d464 | 2017-05-22 15:58:42 -0700 | [diff] [blame] | 4058 | // Recreate the activity so that it initializes the rotation preference again. |
| 4059 | recreate(); |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 4060 | } |
| 4061 | } |
Sunny Goyal | 745bad9 | 2016-05-02 10:54:12 -0700 | [diff] [blame] | 4062 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4063 | } |