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