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