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