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