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