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