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