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