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