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