Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 18 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 20 | import android.animation.Animator; |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 21 | import android.animation.AnimatorListenerAdapter; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 22 | import android.animation.AnimatorSet; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
| 24 | import android.animation.PropertyValuesHolder; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 25 | import android.animation.TimeInterpolator; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 26 | import android.animation.ValueAnimator; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 27 | import android.annotation.TargetApi; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 28 | import android.app.Activity; |
Brett Chabot | 2a9e228 | 2011-08-23 15:03:13 -0700 | [diff] [blame] | 29 | import android.app.ActivityManager; |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 30 | import android.app.ActivityOptions; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 31 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | import android.app.SearchManager; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 33 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 34 | import android.appwidget.AppWidgetManager; |
| 35 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 37 | import android.content.BroadcastReceiver; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 38 | import android.content.ComponentCallbacks2; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 39 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 40 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.content.Context; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 42 | import android.content.DialogInterface; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 44 | import android.content.IntentFilter; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 45 | import android.content.SharedPreferences; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 46 | import android.content.pm.ActivityInfo; |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 47 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 49 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 51 | import android.content.res.Resources; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 52 | import android.database.ContentObserver; |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 53 | import android.database.sqlite.SQLiteDatabase; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 54 | import android.graphics.Bitmap; |
| 55 | import android.graphics.Canvas; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame] | 56 | import android.graphics.Color; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 57 | import android.graphics.PorterDuff; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 58 | import android.graphics.Rect; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 59 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 60 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 61 | import android.os.AsyncTask; |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 62 | import android.os.Build; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 63 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 64 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 65 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 66 | import android.os.Message; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 67 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 68 | import android.os.SystemClock; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | import android.text.Selection; |
| 70 | import android.text.SpannableStringBuilder; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 71 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 73 | import android.util.Log; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 74 | import android.view.Display; |
| 75 | import android.view.Gravity; |
| 76 | import android.view.HapticFeedbackConstants; |
| 77 | import android.view.KeyEvent; |
| 78 | import android.view.LayoutInflater; |
| 79 | import android.view.Menu; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 80 | import android.view.MotionEvent; |
| 81 | import android.view.Surface; |
| 82 | import android.view.View; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 83 | import android.view.View.OnClickListener; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 84 | import android.view.View.OnLongClickListener; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 85 | import android.view.ViewAnimationUtils; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 86 | import android.view.ViewGroup; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 87 | import android.view.ViewStub; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 88 | import android.view.ViewTreeObserver; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 89 | import android.view.Window; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 90 | import android.view.WindowManager; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 91 | import android.view.accessibility.AccessibilityEvent; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 92 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 93 | import android.view.animation.DecelerateInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 95 | import android.widget.Advanceable; |
| 96 | import android.widget.FrameLayout; |
| 97 | import android.widget.ImageView; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 98 | import android.widget.Toast; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 99 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 100 | import com.android.launcher3.DropTarget.DragObject; |
| 101 | import com.android.launcher3.PagedView.PageSwitchListener; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 102 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 103 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 104 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 105 | import com.android.launcher3.compat.PackageInstallerCompat; |
| 106 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 107 | import com.android.launcher3.compat.UserHandleCompat; |
| 108 | import com.android.launcher3.compat.UserManagerCompat; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 109 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 110 | import java.io.DataInputStream; |
| 111 | import java.io.DataOutputStream; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 112 | import java.io.File; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 113 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 114 | import java.io.FileNotFoundException; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 115 | import java.io.FileOutputStream; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 116 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 117 | import java.io.PrintWriter; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 118 | import java.lang.reflect.Field; |
| 119 | import java.lang.reflect.InvocationTargetException; |
| 120 | import java.lang.reflect.Method; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 121 | import java.text.DateFormat; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 122 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 123 | import java.util.Collection; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 124 | import java.util.Date; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 125 | import java.util.HashMap; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 126 | import java.util.HashSet; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 127 | import java.util.List; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 128 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 129 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 130 | /** |
| 131 | * Default launcher application. |
| 132 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 133 | public class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 134 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 135 | View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 136 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 137 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 138 | |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 139 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 140 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 141 | static final boolean DEBUG_STRICT_MODE = false; |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 142 | static final boolean DEBUG_RESUME_TIME = false; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 143 | static final boolean DEBUG_DUMP_LOG = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 144 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 145 | static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run |
| 146 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 147 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 148 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 149 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 150 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 151 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 152 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 153 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 154 | private static final int REQUEST_RECONFIGURE_APPWIDGET = 12; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 155 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 156 | /** |
| 157 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 158 | * request codes used internally. |
| 159 | */ |
| 160 | protected static final int REQUEST_LAST = 100; |
| 161 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 162 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 163 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 164 | static final int SCREEN_COUNT = 5; |
| 165 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 166 | |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 167 | // To turn on these properties, type |
| 168 | // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS] |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 169 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 170 | static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 171 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 172 | // The Intent extra that defines whether to ignore the launch animation |
| 173 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 174 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 175 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 176 | // Type: int |
| 177 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 178 | // Type: int |
| 179 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 180 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 181 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 182 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 183 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 184 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 185 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 186 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 187 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 188 | // Type: boolean |
| 189 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 190 | // Type: long |
| 191 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 192 | // Type: int |
| 193 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 194 | // Type: int |
| 195 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 196 | // Type: parcelable |
| 197 | private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info"; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 198 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 199 | private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id"; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 200 | // Type: int[] |
| 201 | private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 202 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 203 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 204 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 205 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 206 | static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete"; |
| 207 | static final String ACTION_FIRST_LOAD_COMPLETE = |
| 208 | "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; |
| 209 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 210 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 211 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 212 | |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 213 | private static final String QSB_WIDGET_ID = "qsb_widget_id"; |
| 214 | private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider"; |
| 215 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 216 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 217 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 218 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 219 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 220 | private State mState = State.WORKSPACE; |
| 221 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 222 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 223 | private boolean mIsSafeModeEnabled; |
| 224 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 225 | LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl(); |
| 226 | LauncherOverlay mLauncherOverlay; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 227 | InsettableFrameLayout mLauncherOverlayContainer; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 228 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 229 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 230 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 231 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 232 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 233 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 234 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 235 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 236 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 237 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 238 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 239 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 240 | // 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] | 241 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 242 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 243 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 244 | private static final int SINGLE_FRAME_DELAY = 16; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 245 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 246 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 247 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 248 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 249 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 250 | private LayoutInflater mInflater; |
| 251 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 252 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 253 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 254 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 255 | private DragLayer mDragLayer; |
| 256 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 257 | private View mWeightWatcher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 258 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 259 | private AppWidgetManagerCompat mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 260 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 261 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 262 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 263 | private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 264 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 265 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 266 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 267 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 268 | private FolderInfo mFolderInfo; |
| 269 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 270 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 271 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 272 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 273 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 274 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 275 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 276 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 277 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 278 | private boolean mAutoAdvanceRunning = false; |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 279 | private AppWidgetHostView mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 280 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 281 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 282 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 283 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 284 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 285 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 286 | |
| 287 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 288 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 289 | private boolean mWorkspaceLoading = true; |
| 290 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 291 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 292 | private boolean mRestoring; |
| 293 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 294 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 295 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 296 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 297 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 298 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 299 | private Bundle mSavedInstanceState; |
| 300 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 301 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 302 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 303 | private boolean mUserPresent = true; |
| 304 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 305 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 306 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 307 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 308 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 309 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 310 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 311 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 312 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 313 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 314 | // Related to the auto-advancing of widgets |
| 315 | private final int ADVANCE_MSG = 1; |
| 316 | private final int mAdvanceInterval = 20000; |
| 317 | private final int mAdvanceStagger = 250; |
| 318 | private long mAutoAdvanceSentTime; |
| 319 | private long mAutoAdvanceTimeLeft = -1; |
| 320 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 321 | new HashMap<View, AppWidgetProviderInfo>(); |
| 322 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 323 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 324 | // match the sensor state. |
| 325 | private final int mRestoreScreenOrientationDelay = 500; |
| 326 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 327 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 328 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 329 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 330 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 331 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 332 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 333 | static Date sDateStamp = new Date(); |
| 334 | static DateFormat sDateFormat = |
| 335 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 336 | static long sRunStart = System.currentTimeMillis(); |
| 337 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 338 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 339 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 340 | // it from the context. |
| 341 | private SharedPreferences mSharedPrefs; |
| 342 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 343 | private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null; |
| 344 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 345 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 346 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 347 | private ImageView mFolderIconImageView; |
| 348 | private Bitmap mFolderIconBitmap; |
| 349 | private Canvas mFolderIconCanvas; |
| 350 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 351 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 352 | private BubbleTextView mWaitingForResume; |
| 353 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 354 | protected static HashMap<String, CustomAppWidget> sCustomAppWidgets = |
| 355 | new HashMap<String, CustomAppWidget>(); |
| 356 | |
| 357 | private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false; |
| 358 | static { |
| 359 | if (ENABLE_CUSTOM_WIDGET_TEST) { |
| 360 | sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget()); |
| 361 | } |
| 362 | } |
| 363 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 364 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 365 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 366 | if (mWorkspace != null) { |
| 367 | mWorkspace.buildPageHardwareLayers(); |
| 368 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 369 | } |
| 370 | }; |
| 371 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 372 | private static PendingAddArguments sPendingAddItem; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 373 | |
| 374 | private static class PendingAddArguments { |
| 375 | int requestCode; |
| 376 | Intent intent; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 377 | long container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 378 | long screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 379 | int cellX; |
| 380 | int cellY; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 381 | int appWidgetId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 384 | private Stats mStats; |
| 385 | |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 386 | FocusIndicatorView mFocusHandler; |
| 387 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 388 | @Override |
| 389 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 390 | if (DEBUG_STRICT_MODE) { |
| 391 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 392 | .detectDiskReads() |
| 393 | .detectDiskWrites() |
| 394 | .detectNetwork() // or .detectAll() for all detectable problems |
| 395 | .penaltyLog() |
| 396 | .build()); |
| 397 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 398 | .detectLeakedSqlLiteObjects() |
| 399 | .detectLeakedClosableObjects() |
| 400 | .penaltyLog() |
| 401 | .penaltyDeath() |
| 402 | .build()); |
| 403 | } |
| 404 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 405 | if (mLauncherCallbacks != null) { |
| 406 | mLauncherCallbacks.preOnCreate(); |
| 407 | } |
| 408 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 409 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 410 | |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 411 | LauncherAppState.setApplicationContext(getApplicationContext()); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 412 | LauncherAppState app = LauncherAppState.getInstance(); |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 413 | LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 414 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 415 | // Lazy-initialize the dynamic grid |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 416 | DeviceProfile grid = app.initDynamicGrid(this); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 417 | |
| 418 | // 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] | 419 | mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 420 | Context.MODE_PRIVATE); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 421 | mIsSafeModeEnabled = getPackageManager().isSafeMode(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 422 | mModel = app.setLauncher(this); |
| 423 | mIconCache = app.getIconCache(); |
Winson Chung | e5467dc | 2013-10-14 17:03:04 -0700 | [diff] [blame] | 424 | mIconCache.flushInvalidIcons(grid); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 425 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 426 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 427 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 428 | mStats = new Stats(this); |
| 429 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 430 | mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 431 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 432 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 433 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 434 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 435 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 436 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 437 | // LauncherModel load. |
| 438 | mPaused = false; |
| 439 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 440 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 441 | android.os.Debug.startMethodTracing( |
| 442 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 446 | setContentView(R.layout.launcher); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 447 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 448 | setupViews(); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 449 | grid.layout(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 450 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 451 | registerContentObservers(); |
| 452 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 453 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 454 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 455 | mSavedState = savedInstanceState; |
| 456 | restoreState(mSavedState); |
| 457 | |
| 458 | if (PROFILE_STARTUP) { |
| 459 | android.os.Debug.stopMethodTracing(); |
| 460 | } |
| 461 | |
| 462 | if (!mRestoring) { |
Adam Cohen | db78dc8 | 2014-06-19 14:50:51 -0700 | [diff] [blame] | 463 | if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 464 | // If the user leaves launcher, then we should just load items asynchronously when |
| 465 | // they return. |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 466 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 467 | } else { |
| 468 | // We only load the page synchronously if the user rotates (or triggers a |
| 469 | // configuration change) while launcher is in the foreground |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 470 | mModel.startLoader(true, mWorkspace.getRestorePage()); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 471 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | // For handling default keys |
| 475 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 476 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 477 | |
| 478 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 479 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 480 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 481 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 482 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 483 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 484 | if (mLauncherCallbacks != null) { |
| 485 | mLauncherCallbacks.onCreate(savedInstanceState); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 486 | if (mLauncherCallbacks.hasLauncherOverlay()) { |
| 487 | ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub); |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 488 | mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate(); |
| 489 | mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView( |
| 490 | mLauncherOverlayContainer, mLauncherOverlayCallbacks); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 491 | mWorkspace.setLauncherOverlay(mLauncherOverlay); |
| 492 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 493 | } |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 494 | |
| 495 | if (shouldShowIntroScreen()) { |
| 496 | showIntroScreen(); |
| 497 | } else { |
| 498 | showFirstRunActivity(); |
| 499 | showFirstRunClings(); |
| 500 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | private LauncherCallbacks mLauncherCallbacks; |
| 504 | |
| 505 | public void onPostCreate(Bundle savedInstanceState) { |
| 506 | super.onPostCreate(savedInstanceState); |
| 507 | if (mLauncherCallbacks != null) { |
| 508 | mLauncherCallbacks.onPostCreate(savedInstanceState); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { |
| 513 | mLauncherCallbacks = callbacks; |
| 514 | return true; |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 517 | @Override |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 518 | public void onLauncherProviderChange() { |
| 519 | if (mLauncherCallbacks != null) { |
| 520 | mLauncherCallbacks.onLauncherProviderChange(); |
| 521 | } |
| 522 | } |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 523 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 524 | /** 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] | 525 | protected boolean hasCustomContentToLeft() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 526 | if (mLauncherCallbacks != null) { |
| 527 | return mLauncherCallbacks.hasCustomContentToLeft(); |
| 528 | } |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 529 | return false; |
| 530 | } |
| 531 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 532 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 533 | * 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] | 534 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 535 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 536 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 537 | protected void populateCustomContentContainer() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 538 | if (mLauncherCallbacks != null) { |
| 539 | mLauncherCallbacks.populateCustomContentContainer(); |
| 540 | } |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 545 | * ensure the custom content page is added or removed if necessary. |
| 546 | */ |
| 547 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 548 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 549 | // Not bound yet, wait for bindScreens to be called. |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 554 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 555 | mWorkspace.createCustomContentContainer(); |
| 556 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 557 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 558 | mWorkspace.removeCustomContentPage(); |
| 559 | } |
| 560 | } |
| 561 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 562 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 563 | if (sLocaleConfiguration == null) { |
| 564 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 565 | @Override |
| 566 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 567 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 568 | readConfiguration(Launcher.this, localeConfiguration); |
| 569 | return localeConfiguration; |
| 570 | } |
| 571 | |
| 572 | @Override |
| 573 | protected void onPostExecute(LocaleConfiguration result) { |
| 574 | sLocaleConfiguration = result; |
| 575 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 576 | } |
| 577 | }.execute(); |
| 578 | return; |
| 579 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 580 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 581 | final Configuration configuration = getResources().getConfiguration(); |
| 582 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 583 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 584 | final String locale = configuration.locale.toString(); |
| 585 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 586 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 587 | final int mcc = configuration.mcc; |
| 588 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 589 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 590 | final int mnc = configuration.mnc; |
| 591 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 592 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 593 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 594 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 595 | sLocaleConfiguration.locale = locale; |
| 596 | sLocaleConfiguration.mcc = mcc; |
| 597 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 598 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 599 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 600 | |
| 601 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 602 | new AsyncTask<Void, Void, Void>() { |
| 603 | public Void doInBackground(Void ... args) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 604 | writeConfiguration(Launcher.this, localeConfiguration); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 605 | return null; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 606 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 607 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
| 611 | private static class LocaleConfiguration { |
| 612 | public String locale; |
| 613 | public int mcc = -1; |
| 614 | public int mnc = -1; |
| 615 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 616 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 617 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 618 | DataInputStream in = null; |
| 619 | try { |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 620 | in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 621 | configuration.locale = in.readUTF(); |
| 622 | configuration.mcc = in.readInt(); |
| 623 | configuration.mnc = in.readInt(); |
| 624 | } catch (FileNotFoundException e) { |
| 625 | // Ignore |
| 626 | } catch (IOException e) { |
| 627 | // Ignore |
| 628 | } finally { |
| 629 | if (in != null) { |
| 630 | try { |
| 631 | in.close(); |
| 632 | } catch (IOException e) { |
| 633 | // Ignore |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 640 | DataOutputStream out = null; |
| 641 | try { |
Helena Josol | 4fbbb3e | 2014-10-06 16:06:46 +0100 | [diff] [blame] | 642 | out = new DataOutputStream(context.openFileOutput( |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 643 | LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 644 | out.writeUTF(configuration.locale); |
| 645 | out.writeInt(configuration.mcc); |
| 646 | out.writeInt(configuration.mnc); |
| 647 | out.flush(); |
| 648 | } catch (FileNotFoundException e) { |
| 649 | // Ignore |
| 650 | } catch (IOException e) { |
| 651 | //noinspection ResultOfMethodCallIgnored |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 652 | context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 653 | } finally { |
| 654 | if (out != null) { |
| 655 | try { |
| 656 | out.close(); |
| 657 | } catch (IOException e) { |
| 658 | // Ignore |
| 659 | } |
| 660 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 664 | public Stats getStats() { |
| 665 | return mStats; |
| 666 | } |
| 667 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 668 | public LayoutInflater getInflater() { |
| 669 | return mInflater; |
| 670 | } |
| 671 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 672 | boolean isDraggingEnabled() { |
| 673 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 674 | // that is subsequently removed from the workspace in startBinding(). |
| 675 | return !mModel.isLoadingWorkspace(); |
| 676 | } |
| 677 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 678 | static int getScreen() { |
| 679 | synchronized (sLock) { |
| 680 | return sScreen; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | static void setScreen(int screen) { |
| 685 | synchronized (sLock) { |
| 686 | sScreen = screen; |
| 687 | } |
| 688 | } |
| 689 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 690 | public static int generateViewId() { |
Ian Parkinson | 0c2918f | 2014-10-06 14:24:31 +0100 | [diff] [blame] | 691 | if (Build.VERSION.SDK_INT >= 17) { |
| 692 | return View.generateViewId(); |
| 693 | } else { |
| 694 | // View.generateViewId() is not available. The following fallback logic is a copy |
| 695 | // of its implementation. |
| 696 | for (;;) { |
| 697 | final int result = sNextGeneratedId.get(); |
| 698 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 699 | int newValue = result + 1; |
| 700 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 701 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 702 | return result; |
| 703 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | public int getViewIdForItem(ItemInfo info) { |
| 709 | // This cast is safe given the > 2B range for int. |
| 710 | int itemId = (int) info.id; |
| 711 | if (mItemIdToViewId.containsKey(itemId)) { |
| 712 | return mItemIdToViewId.get(itemId); |
| 713 | } |
| 714 | int viewId = generateViewId(); |
| 715 | mItemIdToViewId.put(itemId, viewId); |
| 716 | return viewId; |
| 717 | } |
| 718 | |
| 719 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 720 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 721 | * a configuration step, this allows the proper animations to run after other transitions. |
| 722 | */ |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 723 | private long completeAdd(PendingAddArguments args) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 724 | long screenId = args.screenId; |
| 725 | if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 726 | // When the screen id represents an actual screen (as opposed to a rank) we make sure |
| 727 | // that the drop page actually exists. |
| 728 | screenId = ensurePendingDropLayoutExists(args.screenId); |
| 729 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 730 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 731 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 732 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 733 | completeAddShortcut(args.intent, args.container, screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 734 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 735 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 736 | case REQUEST_CREATE_APPWIDGET: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 737 | completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 738 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 739 | case REQUEST_RECONFIGURE_APPWIDGET: |
| 740 | completeRestoreAppWidget(args.appWidgetId); |
| 741 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 742 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 743 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 744 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 745 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 746 | resetAddInfo(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 747 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 750 | private void handleActivityResult( |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 751 | final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 752 | // Reset the startActivity waiting flag |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 753 | setWaitingForResult(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 754 | final int pendingAddWidgetId = mPendingAddWidgetId; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 755 | mPendingAddWidgetId = -1; |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 756 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 757 | Runnable exitSpringLoaded = new Runnable() { |
| 758 | @Override |
| 759 | public void run() { |
| 760 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 761 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 762 | } |
| 763 | }; |
| 764 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 765 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 766 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 767 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 768 | if (resultCode == RESULT_CANCELED) { |
| 769 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 770 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 771 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 772 | } else if (resultCode == RESULT_OK) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 773 | addAppWidgetImpl(appWidgetId, (PendingAddWidgetInfo) mPendingAddInfo, null, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 774 | mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 775 | } |
| 776 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 777 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 778 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
| 779 | mWorkspace.exitOverviewMode(false); |
| 780 | } |
| 781 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 782 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 783 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 784 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 785 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 786 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 787 | final boolean workspaceLocked = isWorkspaceLocked(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 788 | // We have special handling for widgets |
| 789 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 790 | final int appWidgetId; |
| 791 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 792 | : -1; |
| 793 | if (widgetId < 0) { |
| 794 | appWidgetId = pendingAddWidgetId; |
| 795 | } else { |
| 796 | appWidgetId = widgetId; |
| 797 | } |
| 798 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 799 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 800 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 801 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 802 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 803 | result = RESULT_CANCELED; |
| 804 | completeTwoStageWidgetDrop(result, appWidgetId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 805 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 806 | @Override |
| 807 | public void run() { |
| 808 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 809 | } |
| 810 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 811 | if (workspaceLocked) { |
| 812 | // No need to remove the empty screen if we're mid-binding, as the |
| 813 | // the bind will not add the empty screen. |
| 814 | mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
| 815 | } else { |
| 816 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 817 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 818 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 819 | } else { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 820 | if (!workspaceLocked) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 821 | if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 822 | // When the screen id represents an actual screen (as opposed to a rank) |
| 823 | // we make sure that the drop page actually exists. |
| 824 | mPendingAddInfo.screenId = |
| 825 | ensurePendingDropLayoutExists(mPendingAddInfo.screenId); |
| 826 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 827 | final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
| 828 | |
| 829 | dropLayout.setDropPending(true); |
| 830 | final Runnable onComplete = new Runnable() { |
| 831 | @Override |
| 832 | public void run() { |
| 833 | completeTwoStageWidgetDrop(resultCode, appWidgetId); |
| 834 | dropLayout.setDropPending(false); |
| 835 | } |
| 836 | }; |
| 837 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 838 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 839 | } else { |
| 840 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId, |
| 841 | mPendingAddInfo); |
| 842 | sPendingAddItem = args; |
| 843 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 844 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 845 | return; |
| 846 | } |
| 847 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 848 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) { |
| 849 | if (resultCode == RESULT_OK) { |
| 850 | // Update the widget view. |
| 851 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, |
| 852 | pendingAddWidgetId, mPendingAddInfo); |
| 853 | if (workspaceLocked) { |
| 854 | sPendingAddItem = args; |
| 855 | } else { |
| 856 | completeAdd(args); |
| 857 | } |
| 858 | } |
| 859 | // Leave the widget in the pending state if the user canceled the configure. |
| 860 | return; |
| 861 | } |
| 862 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 863 | // The pattern used here is that a user PICKs a specific application, |
| 864 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 865 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 866 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 867 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Winson Chung | c7da555 | 2011-08-10 15:28:45 -0700 | [diff] [blame] | 868 | if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 869 | final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1, |
| 870 | mPendingAddInfo); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 871 | if (isWorkspaceLocked()) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 872 | sPendingAddItem = args; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 873 | } else { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 874 | completeAdd(args); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 875 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 876 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 877 | } |
Adam Cohen | 0007472 | 2013-10-11 17:46:09 -0700 | [diff] [blame] | 878 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 879 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 880 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 881 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 882 | mDragLayer.clearAnimatedView(); |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 883 | |
| 884 | } |
| 885 | |
| 886 | @Override |
| 887 | protected void onActivityResult( |
| 888 | final int requestCode, final int resultCode, final Intent data) { |
| 889 | handleActivityResult(requestCode, resultCode, data); |
| 890 | if (mLauncherCallbacks != null) { |
| 891 | mLauncherCallbacks.onActivityResult(requestCode, resultCode, data); |
| 892 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 893 | } |
| 894 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 895 | private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int |
| 896 | appWidgetId, ItemInfo info) { |
| 897 | PendingAddArguments args = new PendingAddArguments(); |
| 898 | args.requestCode = requestCode; |
| 899 | args.intent = data; |
| 900 | args.container = info.container; |
| 901 | args.screenId = info.screenId; |
| 902 | args.cellX = info.cellX; |
| 903 | args.cellY = info.cellY; |
| 904 | args.appWidgetId = appWidgetId; |
| 905 | return args; |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 910 | * |
| 911 | * @param screenId the screen id to check |
| 912 | * @return the new screen, or screenId if it exists |
| 913 | */ |
| 914 | private long ensurePendingDropLayoutExists(long screenId) { |
| 915 | CellLayout dropLayout = |
| 916 | (CellLayout) mWorkspace.getScreenWithId(screenId); |
| 917 | if (dropLayout == null) { |
| 918 | // it's possible that the add screen was removed because it was |
| 919 | // empty and a re-bind occurred |
| 920 | mWorkspace.addExtraEmptyScreen(); |
| 921 | return mWorkspace.commitExtraEmptyScreen(); |
| 922 | } else { |
| 923 | return screenId; |
| 924 | } |
| 925 | } |
| 926 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 927 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 928 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 929 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 930 | Runnable onCompleteRunnable = null; |
| 931 | int animationType = 0; |
| 932 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 933 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 934 | if (resultCode == RESULT_OK) { |
| 935 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 936 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 937 | mPendingAddWidgetInfo); |
| 938 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 939 | onCompleteRunnable = new Runnable() { |
| 940 | @Override |
| 941 | public void run() { |
| 942 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 943 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 944 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 945 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 946 | } |
| 947 | }; |
| 948 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 949 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 950 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 951 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 952 | if (mDragLayer.getAnimatedView() != null) { |
| 953 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 954 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 955 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 956 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 957 | // The animated view may be null in the case of a rotation during widget configuration |
| 958 | onCompleteRunnable.run(); |
| 959 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 963 | protected void onStop() { |
| 964 | super.onStop(); |
| 965 | FirstFrameAnimatorHelper.setIsVisible(false); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 966 | |
| 967 | if (mLauncherCallbacks != null) { |
| 968 | mLauncherCallbacks.onStop(); |
| 969 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | @Override |
| 973 | protected void onStart() { |
| 974 | super.onStart(); |
| 975 | FirstFrameAnimatorHelper.setIsVisible(true); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 976 | |
| 977 | if (mLauncherCallbacks != null) { |
| 978 | mLauncherCallbacks.onStart(); |
| 979 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 983 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 984 | long startTime = 0; |
| 985 | if (DEBUG_RESUME_TIME) { |
| 986 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 987 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 988 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 989 | |
| 990 | if (mLauncherCallbacks != null) { |
| 991 | mLauncherCallbacks.preOnResume(); |
| 992 | } |
| 993 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 994 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 995 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 996 | // Restore the previous launcher state |
| 997 | if (mOnResumeState == State.WORKSPACE) { |
| 998 | showWorkspace(false); |
| 999 | } else if (mOnResumeState == State.APPS_CUSTOMIZE) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 1000 | showAllApps(false, mAppsCustomizeContent.getContentType(), false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1001 | } |
| 1002 | mOnResumeState = State.NONE; |
| 1003 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1004 | // Background was set to gradient in onPause(), restore to black if in all apps. |
| 1005 | setWorkspaceBackground(mState == State.WORKSPACE); |
| 1006 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1007 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1008 | if (mRestoring || mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1009 | setWorkspaceLoading(true); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 1010 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1011 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1012 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1013 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1014 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1015 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 1016 | // execute them here |
| 1017 | long startTimeCallbacks = 0; |
| 1018 | if (DEBUG_RESUME_TIME) { |
| 1019 | startTimeCallbacks = System.currentTimeMillis(); |
| 1020 | } |
| 1021 | |
| 1022 | if (mAppsCustomizeContent != null) { |
| 1023 | mAppsCustomizeContent.setBulkBind(true); |
| 1024 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1025 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 1026 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1027 | } |
| 1028 | if (mAppsCustomizeContent != null) { |
| 1029 | mAppsCustomizeContent.setBulkBind(false); |
| 1030 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1031 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1032 | if (DEBUG_RESUME_TIME) { |
| 1033 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 1034 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 1035 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1036 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 1037 | if (mOnResumeCallbacks.size() > 0) { |
| 1038 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 1039 | mOnResumeCallbacks.get(i).run(); |
| 1040 | } |
| 1041 | mOnResumeCallbacks.clear(); |
| 1042 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1043 | |
| 1044 | // Reset the pressed state of icons that were locked in the press state while activities |
| 1045 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1046 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1047 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1048 | mWaitingForResume.setStayPressed(false); |
| 1049 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 1050 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1051 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 1052 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 1053 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 1054 | // orientation. |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1055 | getWorkspace().reinflateWidgetsIfNecessary(); |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1056 | |
Winson Chung | 780fe59 | 2013-09-26 14:48:44 -0700 | [diff] [blame] | 1057 | // Process any items that were added while Launcher was away. |
| 1058 | InstallShortcutReceiver.disableAndFlushInstallQueue(this); |
| 1059 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1060 | if (DEBUG_RESUME_TIME) { |
| 1061 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1062 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1063 | |
| 1064 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1065 | // If we are resuming and the custom content is the current page, we call onShow(). |
| 1066 | // It is also poassible that onShow will instead be called slightly after first layout |
| 1067 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1068 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1069 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 1072 | mWorkspace.updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1073 | mWorkspace.onResume(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1074 | |
| 1075 | PackageInstallerCompat.getInstance(this).onResume(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1076 | |
| 1077 | if (mLauncherCallbacks != null) { |
| 1078 | mLauncherCallbacks.onResume(); |
| 1079 | } |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1082 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1083 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1084 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1085 | InstallShortcutReceiver.enableInstallQueue(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1086 | PackageInstallerCompat.getInstance(this).onPause(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1087 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1088 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1089 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1090 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1091 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1092 | |
| 1093 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1094 | // debounce excess onHide calls. |
| 1095 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1096 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1097 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1098 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1099 | if (mLauncherCallbacks != null) { |
| 1100 | mLauncherCallbacks.onPause(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1101 | } |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1105 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1106 | // by a onResume or by scrolling otherwise. |
| 1107 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1108 | |
| 1109 | // Custom content is completely hidden |
| 1110 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1111 | |
| 1112 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1113 | public void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1114 | |
| 1115 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1116 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1119 | public interface LauncherOverlay { |
| 1120 | |
| 1121 | /** |
| 1122 | * Touch interaction leading to overscroll has begun |
| 1123 | */ |
| 1124 | public void onScrollInteractionBegin(); |
| 1125 | |
| 1126 | /** |
| 1127 | * Touch interaction related to overscroll has ended |
| 1128 | */ |
| 1129 | public void onScrollInteractionEnd(); |
| 1130 | |
| 1131 | /** |
| 1132 | * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost |
| 1133 | * screen (or in the case of RTL, the rightmost screen). |
| 1134 | */ |
| 1135 | public void onScrollChange(int progress, boolean rtl); |
| 1136 | |
| 1137 | /** |
| 1138 | * Screen has stopped scrolling |
| 1139 | */ |
| 1140 | public void onScrollSettled(); |
| 1141 | |
| 1142 | /** |
| 1143 | * This method can be called by the Launcher in order to force the LauncherOverlay |
| 1144 | * to exit fully immersive mode. |
| 1145 | */ |
| 1146 | public void forceExitFullImmersion(); |
| 1147 | } |
| 1148 | |
| 1149 | public interface LauncherOverlayCallbacks { |
| 1150 | /** |
| 1151 | * This method indicates whether a call to {@link #enterFullImmersion()} will succeed, |
| 1152 | * however it doesn't modify any state within the launcher. |
| 1153 | */ |
| 1154 | public boolean canEnterFullImmersion(); |
| 1155 | |
| 1156 | /** |
| 1157 | * Should be called to tell Launcher that the LauncherOverlay will take over interaction, |
| 1158 | * eg. by occupying the full screen and handling all touch events. |
| 1159 | * |
| 1160 | * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this |
| 1161 | * case, Launcher will modify any necessary state and assumes the overlay is |
| 1162 | * handling all interaction. If false, the LauncherOverlay should cancel any |
| 1163 | * |
| 1164 | */ |
| 1165 | public boolean enterFullImmersion(); |
| 1166 | |
| 1167 | /** |
| 1168 | * Must be called when exiting fully immersive mode. Indicates to Launcher that it has |
| 1169 | * full control over UI and state. |
| 1170 | */ |
| 1171 | public void exitFullImmersion(); |
| 1172 | } |
| 1173 | |
| 1174 | class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks { |
| 1175 | |
| 1176 | @Override |
| 1177 | public boolean canEnterFullImmersion() { |
| 1178 | return mState == State.WORKSPACE; |
| 1179 | } |
| 1180 | |
| 1181 | @Override |
| 1182 | public boolean enterFullImmersion() { |
| 1183 | if (mState == State.WORKSPACE) { |
| 1184 | // When fully immersed, disregard any touches which fall through. |
| 1185 | mDragLayer.setBlockTouch(true); |
| 1186 | return true; |
| 1187 | } |
| 1188 | return false; |
| 1189 | } |
| 1190 | |
| 1191 | @Override |
| 1192 | public void exitFullImmersion() { |
| 1193 | mDragLayer.setBlockTouch(false); |
| 1194 | } |
| 1195 | } |
| 1196 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1197 | protected boolean hasSettings() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1198 | if (mLauncherCallbacks != null) { |
| 1199 | return mLauncherCallbacks.hasSettings(); |
| 1200 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1201 | return false; |
| 1202 | } |
| 1203 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1204 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1205 | public void addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1206 | CustomContentCallbacks callbacks, String description) { |
| 1207 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1210 | // The custom content needs to offset its content to account for the QSB |
| 1211 | public int getTopOffsetForCustomContent() { |
| 1212 | return mWorkspace.getPaddingTop(); |
| 1213 | } |
| 1214 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1215 | @Override |
| 1216 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1217 | // Flag the loader to stop early before switching |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1218 | if (mModel.isCurrentCallbacks(this)) { |
| 1219 | mModel.stopLoader(); |
| 1220 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1221 | if (mAppsCustomizeContent != null) { |
| 1222 | mAppsCustomizeContent.surrender(); |
| 1223 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1224 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1225 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1226 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1227 | // 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] | 1228 | @Override |
| 1229 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1230 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1231 | mHasFocus = hasFocus; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1232 | |
| 1233 | if (mLauncherCallbacks != null) { |
| 1234 | mLauncherCallbacks.onWindowFocusChanged(hasFocus); |
| 1235 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1236 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1237 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1238 | private boolean acceptFilter() { |
| 1239 | final InputMethodManager inputManager = (InputMethodManager) |
| 1240 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1241 | return !inputManager.isFullscreenMode(); |
| 1242 | } |
| 1243 | |
| 1244 | @Override |
| 1245 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1246 | final int uniChar = event.getUnicodeChar(); |
| 1247 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1248 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1249 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1250 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1251 | keyCode, event); |
| 1252 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1253 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1254 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1255 | // showSearchDialog() |
| 1256 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1257 | // onSearchRequested() will be called for every keystroke, |
| 1258 | // but it is idempotent, so it's fine. |
| 1259 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1260 | } |
| 1261 | } |
| 1262 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1263 | // Eat the long press event so the keyboard doesn't come up. |
| 1264 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1265 | return true; |
| 1266 | } |
| 1267 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1268 | return handled; |
| 1269 | } |
| 1270 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1271 | private String getTypedText() { |
| 1272 | return mDefaultKeySsb.toString(); |
| 1273 | } |
| 1274 | |
| 1275 | private void clearTypedText() { |
| 1276 | mDefaultKeySsb.clear(); |
| 1277 | mDefaultKeySsb.clearSpans(); |
| 1278 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1279 | } |
| 1280 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1281 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1282 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1283 | * State |
| 1284 | */ |
| 1285 | private static State intToState(int stateOrdinal) { |
| 1286 | State state = State.WORKSPACE; |
| 1287 | final State[] stateValues = State.values(); |
| 1288 | for (int i = 0; i < stateValues.length; i++) { |
| 1289 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1290 | state = stateValues[i]; |
| 1291 | break; |
| 1292 | } |
| 1293 | } |
| 1294 | return state; |
| 1295 | } |
| 1296 | |
| 1297 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1298 | * Restores the previous state, if it exists. |
| 1299 | * |
| 1300 | * @param savedState The previous state. |
| 1301 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1302 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1303 | private void restoreState(Bundle savedState) { |
| 1304 | if (savedState == null) { |
| 1305 | return; |
| 1306 | } |
| 1307 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1308 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1309 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1310 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1313 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1314 | PagedView.INVALID_RESTORE_PAGE); |
| 1315 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1316 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1317 | } |
| 1318 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1319 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1320 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1321 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1322 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1323 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1324 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1325 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1326 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1327 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1328 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 1329 | mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1330 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1331 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1332 | mRestoring = true; |
| 1333 | } |
| 1334 | |
| 1335 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1336 | if (renameFolder) { |
| 1337 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1338 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1339 | mRestoring = true; |
| 1340 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1341 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1342 | // Restore the AppsCustomize tab |
| 1343 | if (mAppsCustomizeTabHost != null) { |
| 1344 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1345 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1346 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1347 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1348 | mAppsCustomizeContent.loadAssociatedPages( |
| 1349 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1352 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1353 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1354 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1355 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1356 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | /** |
| 1360 | * Finds all the views we need and configure them properly. |
| 1361 | */ |
| 1362 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1363 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1364 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1365 | mLauncherView = findViewById(R.id.launcher); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1366 | mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1367 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1368 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1369 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1370 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1371 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1372 | mLauncherView.setSystemUiVisibility( |
| 1373 | 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] | 1374 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1375 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1376 | // Setup the drag layer |
| 1377 | mDragLayer.setup(this, dragController); |
| 1378 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1379 | // Setup the hotseat |
| 1380 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1381 | if (mHotseat != null) { |
| 1382 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1383 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1386 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1387 | View widgetButton = findViewById(R.id.widget_button); |
| 1388 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1389 | @Override |
| 1390 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1391 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1392 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1393 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1394 | } |
| 1395 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1396 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1397 | |
| 1398 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1399 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1400 | @Override |
| 1401 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1402 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1403 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1404 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1405 | } |
| 1406 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1407 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1408 | |
| 1409 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1410 | if (hasSettings()) { |
| 1411 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1412 | @Override |
| 1413 | public void onClick(View arg0) { |
| 1414 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1415 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1416 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1417 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1418 | }); |
| 1419 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1420 | } else { |
| 1421 | settingsButton.setVisibility(View.GONE); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1424 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1425 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1426 | // Setup the workspace |
| 1427 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1428 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1429 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1430 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1431 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1432 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1433 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1434 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1435 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1436 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1437 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1438 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1439 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1440 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1441 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1442 | // 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] | 1443 | dragController.setDragScoller(mWorkspace); |
| 1444 | dragController.setScrollView(mDragLayer); |
| 1445 | dragController.setMoveTarget(mWorkspace); |
| 1446 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1447 | if (mSearchDropTargetBar != null) { |
| 1448 | mSearchDropTargetBar.setup(this, dragController); |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 1449 | mSearchDropTargetBar.setQsbSearchBar(getQsbBar()); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1450 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1451 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1452 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1453 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1454 | mWeightWatcher = new WeightWatcher(this); |
| 1455 | mWeightWatcher.setAlpha(0.5f); |
| 1456 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1457 | new FrameLayout.LayoutParams( |
| 1458 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1459 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1460 | Gravity.BOTTOM) |
| 1461 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1462 | |
| 1463 | boolean show = shouldShowWeightWatcher(); |
| 1464 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1465 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1469 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1470 | */ |
| 1471 | public void setAllAppsButton(View allAppsButton) { |
| 1472 | mAllAppsButton = allAppsButton; |
| 1473 | } |
| 1474 | |
| 1475 | public View getAllAppsButton() { |
| 1476 | return mAllAppsButton; |
| 1477 | } |
| 1478 | |
| 1479 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1480 | * Creates a view representing a shortcut. |
| 1481 | * |
| 1482 | * @param info The data structure describing the shortcut. |
| 1483 | * |
| 1484 | * @return A View inflated from R.layout.application. |
| 1485 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1486 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1487 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1488 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /** |
| 1492 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1493 | * |
| 1494 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1495 | * @param parent The group the shortcut belongs to. |
| 1496 | * @param info The data structure describing the shortcut. |
| 1497 | * |
| 1498 | * @return A View inflated from layoutResId. |
| 1499 | */ |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1500 | public View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1501 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 1502 | favorite.applyFromShortcutInfo(info, mIconCache, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1503 | favorite.setOnClickListener(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1504 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1505 | return favorite; |
| 1506 | } |
| 1507 | |
| 1508 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1509 | * Add a shortcut to the workspace. |
| 1510 | * |
| 1511 | * @param data The intent describing the shortcut. |
| 1512 | * @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] | 1513 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1514 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1515 | int cellY) { |
| 1516 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1517 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1518 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1519 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1520 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1521 | |
Sunny Goyal | 2350bc9 | 2014-10-14 16:42:54 -0700 | [diff] [blame] | 1522 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1523 | if (info == null) { |
| 1524 | return; |
| 1525 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1526 | final View view = createShortcut(info); |
| 1527 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1528 | // First we check if we already know the exact location where we want to add this item. |
| 1529 | if (cellX >= 0 && cellY >= 0) { |
| 1530 | cellXY[0] = cellX; |
| 1531 | cellXY[1] = cellY; |
| 1532 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1533 | |
| 1534 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1535 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1536 | true, null,null)) { |
| 1537 | return; |
| 1538 | } |
| 1539 | DragObject dragObject = new DragObject(); |
| 1540 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1541 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1542 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1543 | return; |
| 1544 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1545 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1546 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1547 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1548 | foundCellSpan = (result != null); |
| 1549 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1550 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1554 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1555 | return; |
| 1556 | } |
| 1557 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1558 | LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1559 | |
| 1560 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1561 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1562 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1566 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1567 | int minHeight) { |
| 1568 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1569 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1570 | // to ensure that it gets the full amount of space that it has requested |
| 1571 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1572 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1573 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1576 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1577 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1580 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1581 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1584 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1585 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1588 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1589 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1590 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1593 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1594 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1595 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1596 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1597 | * @param cellInfo The position on screen where to create the widget. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1598 | */ |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1599 | private void completeAddAppWidget(int appWidgetId, long container, long screenId, |
| 1600 | AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) { |
| 1601 | |
| 1602 | ItemInfo info = mPendingAddInfo; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1603 | if (appWidgetInfo == null) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1604 | appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this, |
| 1605 | mAppWidgetManager.getAppWidgetInfo(appWidgetId)); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1606 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1607 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1608 | if (appWidgetInfo.isCustomWidget) { |
| 1609 | appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1612 | LauncherAppWidgetInfo launcherInfo; |
| 1613 | launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider); |
| 1614 | launcherInfo.spanX = info.spanX; |
| 1615 | launcherInfo.spanY = info.spanY; |
| 1616 | launcherInfo.minSpanX = info.minSpanX; |
| 1617 | launcherInfo.minSpanY = info.minSpanY; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1618 | launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1619 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1620 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1621 | container, screenId, info.cellX, info.cellY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1622 | |
| 1623 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1624 | if (hostView == null) { |
| 1625 | // Perform actual inflation because we're live |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1626 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, |
| 1627 | appWidgetInfo); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1628 | } else { |
| 1629 | // The AppWidgetHostView has already been inflated and instantiated |
| 1630 | launcherInfo.hostView = hostView; |
| 1631 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1632 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1633 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1634 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1635 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1636 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX, |
| 1637 | info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1638 | |
| 1639 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1640 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1641 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1642 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1643 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1644 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1645 | @Override |
| 1646 | public void onReceive(Context context, Intent intent) { |
| 1647 | final String action = intent.getAction(); |
| 1648 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1649 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1650 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1651 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1652 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1653 | // 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] | 1654 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1655 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1656 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1657 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1658 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1659 | mUserPresent = true; |
| 1660 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1661 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1662 | mModel.resetLoadedState(false, true); |
| 1663 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1664 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1665 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1666 | mModel.resetLoadedState(false, true); |
| 1667 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1668 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1669 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1670 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1671 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1672 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1673 | } |
| 1674 | } |
| 1675 | }; |
| 1676 | |
| 1677 | @Override |
| 1678 | public void onAttachedToWindow() { |
| 1679 | super.onAttachedToWindow(); |
| 1680 | |
| 1681 | // Listen for broadcasts related to user-presence |
| 1682 | final IntentFilter filter = new IntentFilter(); |
| 1683 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1684 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1685 | // For handling managed profiles |
| 1686 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1687 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1688 | if (ENABLE_DEBUG_INTENTS) { |
| 1689 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1690 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1691 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1692 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1693 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1694 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1695 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1696 | mVisible = true; |
| 1697 | } |
| 1698 | |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1699 | /** |
| 1700 | * Sets up transparent navigation and status bars in LMP. |
| 1701 | * This method is a no-op for other platform versions. |
| 1702 | */ |
| 1703 | @TargetApi(19) |
| 1704 | private void setupTransparentSystemBarsForLmp() { |
| 1705 | // TODO(sansid): use the APIs directly when compiling against L sdk. |
| 1706 | // Currently we use reflection to access the flags and the API to set the transparency |
| 1707 | // on the System bars. |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 1708 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1709 | try { |
| 1710 | getWindow().getAttributes().systemUiVisibility |= |
| 1711 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1712 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1713 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1714 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
| 1715 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
| 1716 | Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( |
| 1717 | "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); |
| 1718 | getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); |
| 1719 | |
| 1720 | Method setStatusBarColorMethod = |
| 1721 | Window.class.getDeclaredMethod("setStatusBarColor", int.class); |
| 1722 | Method setNavigationBarColorMethod = |
| 1723 | Window.class.getDeclaredMethod("setNavigationBarColor", int.class); |
| 1724 | setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1725 | setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1726 | } catch (NoSuchFieldException e) { |
| 1727 | Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); |
| 1728 | } catch (NoSuchMethodException ex) { |
| 1729 | Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); |
| 1730 | } catch (IllegalAccessException e) { |
| 1731 | Log.w(TAG, "IllegalAccessException while setting up transparent bars"); |
| 1732 | } catch (IllegalArgumentException e) { |
| 1733 | Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); |
| 1734 | } catch (InvocationTargetException e) { |
| 1735 | Log.w(TAG, "InvocationTargetException while setting up transparent bars"); |
| 1736 | } finally {} |
| 1737 | } |
| 1738 | } |
| 1739 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1740 | @Override |
| 1741 | public void onDetachedFromWindow() { |
| 1742 | super.onDetachedFromWindow(); |
| 1743 | mVisible = false; |
| 1744 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1745 | if (mAttached) { |
| 1746 | unregisterReceiver(mReceiver); |
| 1747 | mAttached = false; |
| 1748 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1749 | updateRunning(); |
| 1750 | } |
| 1751 | |
| 1752 | public void onWindowVisibilityChanged(int visibility) { |
| 1753 | mVisible = visibility == View.VISIBLE; |
| 1754 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1755 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1756 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1757 | // is a more appropriate event to handle |
| 1758 | if (mVisible) { |
| 1759 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1760 | if (!mWorkspaceLoading) { |
| 1761 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1762 | // We want to let Launcher draw itself at least once before we force it to build |
| 1763 | // 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] | 1764 | // apps is nice and speedy. |
| 1765 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1766 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1767 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1768 | if (mStarted) return; |
| 1769 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1770 | // We delay the layer building a bit in order to give |
| 1771 | // other message processing a time to run. In particular |
| 1772 | // this avoids a delay in hiding the IME if it was |
| 1773 | // currently shown, because doing that may involve |
| 1774 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1775 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1776 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1777 | mWorkspace.post(new Runnable() { |
| 1778 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1779 | if (mWorkspace != null && |
| 1780 | mWorkspace.getViewTreeObserver() != null) { |
| 1781 | mWorkspace.getViewTreeObserver(). |
| 1782 | removeOnDrawListener(listener); |
| 1783 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1784 | } |
| 1785 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1786 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1787 | } |
| 1788 | }); |
| 1789 | } |
| 1790 | clearTypedText(); |
| 1791 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | private void sendAdvanceMessage(long delay) { |
| 1795 | mHandler.removeMessages(ADVANCE_MSG); |
| 1796 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1797 | mHandler.sendMessageDelayed(msg, delay); |
| 1798 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1799 | } |
| 1800 | |
| 1801 | private void updateRunning() { |
| 1802 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1803 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1804 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1805 | if (autoAdvanceRunning) { |
| 1806 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1807 | sendAdvanceMessage(delay); |
| 1808 | } else { |
| 1809 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1810 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1811 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1812 | } |
| 1813 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1814 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | private final Handler mHandler = new Handler() { |
| 1820 | @Override |
| 1821 | public void handleMessage(Message msg) { |
| 1822 | if (msg.what == ADVANCE_MSG) { |
| 1823 | int i = 0; |
| 1824 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1825 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1826 | final int delay = mAdvanceStagger * i; |
| 1827 | if (v instanceof Advanceable) { |
| 1828 | postDelayed(new Runnable() { |
| 1829 | public void run() { |
| 1830 | ((Advanceable) v).advance(); |
| 1831 | } |
| 1832 | }, delay); |
| 1833 | } |
| 1834 | i++; |
| 1835 | } |
| 1836 | sendAdvanceMessage(mAdvanceInterval); |
| 1837 | } |
| 1838 | } |
| 1839 | }; |
| 1840 | |
| 1841 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1842 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1843 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1844 | if (v instanceof Advanceable) { |
| 1845 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1846 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1847 | updateRunning(); |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | void removeWidgetToAutoAdvance(View hostView) { |
| 1852 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1853 | mWidgetsToAdvance.remove(hostView); |
| 1854 | updateRunning(); |
| 1855 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1858 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1859 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1860 | launcherInfo.hostView = null; |
| 1861 | } |
| 1862 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1863 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1864 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1865 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1868 | public ArrayList<AppInfo> getAllAppsList() { |
| 1869 | return mAppsCustomizeContent.getApps(); |
| 1870 | } |
| 1871 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1872 | public DragLayer getDragLayer() { |
| 1873 | return mDragLayer; |
| 1874 | } |
| 1875 | |
| 1876 | public Workspace getWorkspace() { |
| 1877 | return mWorkspace; |
| 1878 | } |
| 1879 | |
| 1880 | public Hotseat getHotseat() { |
| 1881 | return mHotseat; |
| 1882 | } |
| 1883 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1884 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1885 | return mOverviewPanel; |
| 1886 | } |
| 1887 | |
| 1888 | public SearchDropTargetBar getSearchBar() { |
| 1889 | return mSearchDropTargetBar; |
| 1890 | } |
| 1891 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1892 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1893 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1894 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1895 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1896 | public LauncherModel getModel() { |
| 1897 | return mModel; |
| 1898 | } |
| 1899 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1900 | protected SharedPreferences getSharedPrefs() { |
| 1901 | return mSharedPrefs; |
| 1902 | } |
| 1903 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1904 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1905 | getWindow().closeAllPanels(); |
| 1906 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1907 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1908 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1909 | } |
| 1910 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1911 | @Override |
| 1912 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1913 | long startTime = 0; |
| 1914 | if (DEBUG_RESUME_TIME) { |
| 1915 | startTime = System.currentTimeMillis(); |
| 1916 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1917 | super.onNewIntent(intent); |
| 1918 | |
| 1919 | // Close the menu |
| 1920 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1921 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1922 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1923 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1924 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1925 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1926 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1927 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1928 | if (mWorkspace == null) { |
| 1929 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1930 | return; |
| 1931 | } |
| 1932 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1933 | // In all these cases, only animate if we're already on home |
| 1934 | mWorkspace.exitWidgetResizeMode(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1935 | |
| 1936 | boolean moveToDefaultScreen = mLauncherCallbacks != null ? |
| 1937 | mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true; |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1938 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1939 | openFolder == null && moveToDefaultScreen) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1940 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1941 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1942 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1943 | closeFolder(); |
| 1944 | exitSpringLoadedDragMode(); |
| 1945 | |
| 1946 | // If we are already on home, then just animate back to the workspace, |
| 1947 | // otherwise, just wait until onResume to set the state back to Workspace |
| 1948 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1949 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1950 | } else { |
| 1951 | mOnResumeState = State.WORKSPACE; |
| 1952 | } |
| 1953 | |
| 1954 | final View v = getWindow().peekDecorView(); |
| 1955 | if (v != null && v.getWindowToken() != null) { |
| 1956 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1957 | INPUT_METHOD_SERVICE); |
| 1958 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 1959 | } |
| 1960 | |
| 1961 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 1962 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1963 | mAppsCustomizeTabHost.reset(); |
| 1964 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1965 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1966 | if (mLauncherCallbacks != null) { |
| 1967 | mLauncherCallbacks.onHomeIntent(); |
| 1968 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1969 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1970 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1971 | if (DEBUG_RESUME_TIME) { |
| 1972 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 1973 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1974 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1975 | if (mLauncherCallbacks != null) { |
| 1976 | mLauncherCallbacks.onNewIntent(intent); |
| 1977 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1980 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1981 | public void onRestoreInstanceState(Bundle state) { |
| 1982 | super.onRestoreInstanceState(state); |
| 1983 | for (int page: mSynchronouslyBoundPages) { |
| 1984 | mWorkspace.restoreInstanceStateForChild(page); |
| 1985 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | @Override |
| 1989 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1990 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 1991 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1992 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1993 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1994 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1995 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1996 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 1997 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 1998 | // this state is reflected. |
| 1999 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2000 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2001 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2002 | mWaitingForResult) { |
| 2003 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2004 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2005 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 2006 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2007 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 2008 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 2009 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2010 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | if (mFolderInfo != null && mWaitingForResult) { |
| 2014 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 2015 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 2016 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 2017 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2018 | // Save the current AppsCustomize tab |
| 2019 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 2020 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 2021 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2022 | if (currentTabTag != null) { |
| 2023 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 2024 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 2025 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 2026 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2027 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 2028 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2029 | |
| 2030 | if (mLauncherCallbacks != null) { |
| 2031 | mLauncherCallbacks.onSaveInstanceState(outState); |
| 2032 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | @Override |
| 2036 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2037 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2038 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2039 | // Remove all pending runnables |
| 2040 | mHandler.removeMessages(ADVANCE_MSG); |
| 2041 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 2042 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2043 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2044 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 2045 | LauncherAppState app = (LauncherAppState.getInstance()); |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 2046 | |
| 2047 | // It's possible to receive onDestroy after a new Launcher activity has |
| 2048 | // been created. In this case, don't interfere with the new Launcher. |
| 2049 | if (mModel.isCurrentCallbacks(this)) { |
| 2050 | mModel.stopLoader(); |
| 2051 | app.setLauncher(null); |
| 2052 | } |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2053 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2054 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2055 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2056 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2057 | 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] | 2058 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2059 | mAppWidgetHost = null; |
| 2060 | |
| 2061 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2062 | |
| 2063 | TextKeyListener.getInstance().release(); |
| 2064 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 2065 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 2066 | // to prevent leaking Launcher activities on orientation change. |
| 2067 | if (mModel != null) { |
| 2068 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 2069 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2070 | |
| 2071 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2072 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2073 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 2074 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2075 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 2076 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2077 | mWorkspace = null; |
| 2078 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 2079 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2080 | LauncherAnimUtils.onDestroyActivity(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2081 | |
| 2082 | if (mLauncherCallbacks != null) { |
| 2083 | mLauncherCallbacks.onDestroy(); |
| 2084 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2085 | } |
| 2086 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2087 | public DragController getDragController() { |
| 2088 | return mDragController; |
| 2089 | } |
| 2090 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2091 | @Override |
| 2092 | public void startActivityForResult(Intent intent, int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2093 | if (requestCode >= 0) { |
| 2094 | setWaitingForResult(true); |
| 2095 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2096 | super.startActivityForResult(intent, requestCode); |
| 2097 | } |
| 2098 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2099 | /** |
| 2100 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2101 | * argument for {@link #startSearch} to true. |
| 2102 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2103 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2104 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2105 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2106 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2107 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2108 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2109 | if (initialQuery == null) { |
| 2110 | // Use any text typed in the launcher as the initial query |
| 2111 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2112 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2113 | if (appSearchData == null) { |
| 2114 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2115 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2116 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2117 | Rect sourceBounds = new Rect(); |
| 2118 | if (mSearchDropTargetBar != null) { |
| 2119 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2120 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2121 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2122 | boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2123 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2124 | if (clearTextImmediately) { |
| 2125 | clearTypedText(); |
| 2126 | } |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2127 | } |
| 2128 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2129 | /** |
| 2130 | * Start a text search. |
| 2131 | * |
| 2132 | * @return {@code true} if the search will start immediately, so any further keypresses |
| 2133 | * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue |
| 2134 | * to buffer keypresses. |
| 2135 | */ |
| 2136 | public boolean startSearch(String initialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2137 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2138 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 2139 | return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData, |
| 2140 | sourceBounds); |
| 2141 | } |
| 2142 | |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2143 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2144 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2145 | return false; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | /** |
| 2149 | * Starts the global search activity. This code is a copied from SearchManager |
| 2150 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2151 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2152 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2153 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2154 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2155 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2156 | if (globalSearchActivity == null) { |
| 2157 | Log.w(TAG, "No global search activity found."); |
| 2158 | return; |
| 2159 | } |
| 2160 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2161 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2162 | intent.setComponent(globalSearchActivity); |
| 2163 | // Make sure that we have a Bundle to put source in |
| 2164 | if (appSearchData == null) { |
| 2165 | appSearchData = new Bundle(); |
| 2166 | } else { |
| 2167 | appSearchData = new Bundle(appSearchData); |
| 2168 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2169 | // 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] | 2170 | if (!appSearchData.containsKey("source")) { |
| 2171 | appSearchData.putString("source", getPackageName()); |
| 2172 | } |
| 2173 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2174 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2175 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2176 | } |
| 2177 | if (selectInitialQuery) { |
| 2178 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2179 | } |
| 2180 | intent.setSourceBounds(sourceBounds); |
| 2181 | try { |
| 2182 | startActivity(intent); |
| 2183 | } catch (ActivityNotFoundException ex) { |
| 2184 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2185 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2186 | } |
| 2187 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2188 | public boolean isOnCustomContent() { |
| 2189 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2190 | } |
| 2191 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2192 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2193 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2194 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2195 | if (!isOnCustomContent()) { |
| 2196 | // Close any open folders |
| 2197 | closeFolder(); |
| 2198 | // Stop resizing any widgets |
| 2199 | mWorkspace.exitWidgetResizeMode(); |
| 2200 | if (!mWorkspace.isInOverviewMode()) { |
| 2201 | // Show the overview mode |
| 2202 | showOverviewMode(true); |
| 2203 | } else { |
| 2204 | showWorkspace(true); |
| 2205 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2206 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2207 | if (mLauncherCallbacks != null) { |
| 2208 | return mLauncherCallbacks.onPrepareOptionsMenu(menu); |
| 2209 | } |
| 2210 | |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2211 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2212 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2213 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2214 | @Override |
| 2215 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2216 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2217 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2218 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2221 | public boolean isWorkspaceLocked() { |
| 2222 | return mWorkspaceLoading || mWaitingForResult; |
| 2223 | } |
| 2224 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2225 | public boolean isWorkspaceLoading() { |
| 2226 | return mWorkspaceLoading; |
| 2227 | } |
| 2228 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2229 | private void setWorkspaceLoading(boolean value) { |
| 2230 | boolean isLocked = isWorkspaceLocked(); |
| 2231 | mWorkspaceLoading = value; |
| 2232 | if (isLocked != isWorkspaceLocked()) { |
| 2233 | onWorkspaceLockedChanged(); |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | private void setWaitingForResult(boolean value) { |
| 2238 | boolean isLocked = isWorkspaceLocked(); |
| 2239 | mWaitingForResult = value; |
| 2240 | if (isLocked != isWorkspaceLocked()) { |
| 2241 | onWorkspaceLockedChanged(); |
| 2242 | } |
| 2243 | } |
| 2244 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2245 | protected void onWorkspaceLockedChanged() { |
| 2246 | if (mLauncherCallbacks != null) { |
| 2247 | mLauncherCallbacks.onWorkspaceLockedChanged(); |
| 2248 | } |
| 2249 | } |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2250 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2251 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2252 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2253 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2254 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2255 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2256 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2257 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2258 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2259 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2260 | void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info, final |
| 2261 | AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2262 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2263 | } |
| 2264 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2265 | void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info, |
| 2266 | final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo, |
| 2267 | int delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2268 | if (appWidgetInfo.configure != null) { |
| 2269 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2270 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2271 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2272 | // Launch over to configure widget, if needed |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2273 | mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this, |
| 2274 | mAppWidgetHost, REQUEST_CREATE_APPWIDGET); |
| 2275 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2276 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2277 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2278 | Runnable onComplete = new Runnable() { |
| 2279 | @Override |
| 2280 | public void run() { |
| 2281 | // Exit spring loaded mode if necessary after adding the widget |
| 2282 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2283 | null); |
| 2284 | } |
| 2285 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2286 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2287 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2288 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2289 | } |
| 2290 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2291 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2292 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2293 | // Close any folders that may be open. |
| 2294 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2295 | mWorkspace.moveToCustomContentScreen(animate); |
| 2296 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2297 | /** |
| 2298 | * Process a shortcut drop. |
| 2299 | * |
| 2300 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2301 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2302 | * @param cell The cell it should be added to, optional |
| 2303 | * @param position The location on the screen where it was dropped, optional |
| 2304 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2305 | void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2306 | int[] cell, int[] loc) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2307 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2308 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2309 | mPendingAddInfo.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2310 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2311 | |
| 2312 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2313 | mPendingAddInfo.cellX = cell[0]; |
| 2314 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2315 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2316 | |
| 2317 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2318 | createShortcutIntent.setComponent(componentName); |
| 2319 | processShortcut(createShortcutIntent); |
| 2320 | } |
| 2321 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2322 | /** |
| 2323 | * Process a widget drop. |
| 2324 | * |
| 2325 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2326 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2327 | * @param cell The cell it should be added to, optional |
| 2328 | * @param position The location on the screen where it was dropped, optional |
| 2329 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2330 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2331 | int[] cell, int[] span, int[] loc) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2332 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2333 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2334 | mPendingAddInfo.screenId = info.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2335 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2336 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2337 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2338 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2339 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2340 | mPendingAddInfo.cellX = cell[0]; |
| 2341 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2342 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2343 | if (span != null) { |
| 2344 | mPendingAddInfo.spanX = span[0]; |
| 2345 | mPendingAddInfo.spanY = span[1]; |
| 2346 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2347 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2348 | AppWidgetHostView hostView = info.boundWidget; |
| 2349 | int appWidgetId; |
| 2350 | if (hostView != null) { |
| 2351 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2352 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2353 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2354 | // In this case, we either need to start an activity to get permission to bind |
| 2355 | // 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] | 2356 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2357 | Bundle options = info.bindOptions; |
| 2358 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2359 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2360 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2361 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2362 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2363 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2364 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2365 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2366 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2367 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2368 | mAppWidgetManager.getUser(mPendingAddWidgetInfo) |
| 2369 | .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2370 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2371 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2372 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2373 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2374 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2375 | } |
| 2376 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2377 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2378 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2379 | } |
| 2380 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2381 | void processWallpaper(Intent intent) { |
| 2382 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2383 | } |
| 2384 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2385 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2386 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2387 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2388 | folderInfo.title = getText(R.string.folder_name); |
| 2389 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2390 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2391 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2392 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2393 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2394 | |
| 2395 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2396 | FolderIcon newFolder = |
| 2397 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2398 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2399 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2400 | // Force measure the new folder icon |
| 2401 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2402 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2403 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2404 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2405 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2406 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2407 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2408 | } |
| 2409 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2410 | protected ComponentName getWallpaperPickerComponent() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2411 | if (mLauncherCallbacks != null) { |
| 2412 | return mLauncherCallbacks.getWallpaperPickerComponent(); |
| 2413 | } |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2414 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2415 | } |
| 2416 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2417 | /** |
| 2418 | * Registers various content observers. The current implementation registers |
| 2419 | * only a favorites observer to keep track of the favorites applications. |
| 2420 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2421 | private void registerContentObservers() { |
| 2422 | ContentResolver resolver = getContentResolver(); |
| 2423 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2424 | true, mWidgetObserver); |
| 2425 | } |
| 2426 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2427 | @Override |
| 2428 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2429 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2430 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2431 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2432 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2433 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 2434 | if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2435 | dumpState(); |
| 2436 | return true; |
| 2437 | } |
| 2438 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2439 | } |
| 2440 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2441 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2442 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2443 | return true; |
| 2444 | } |
| 2445 | } |
| 2446 | |
| 2447 | return super.dispatchKeyEvent(event); |
| 2448 | } |
| 2449 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2450 | @Override |
| 2451 | public void onBackPressed() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2452 | if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) { |
| 2453 | return; |
| 2454 | } |
| 2455 | |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2456 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2457 | if (mAppsCustomizeContent.getContentType() == |
| 2458 | AppsCustomizePagedView.ContentType.Applications) { |
| 2459 | showWorkspace(true); |
| 2460 | } else { |
| 2461 | showOverviewMode(true); |
| 2462 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2463 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2464 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2465 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2466 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2467 | if (openFolder.isEditingName()) { |
| 2468 | openFolder.dismissEditingName(); |
| 2469 | } else { |
| 2470 | closeFolder(); |
| 2471 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2472 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2473 | mWorkspace.exitWidgetResizeMode(); |
| 2474 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2475 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2476 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2477 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2478 | } |
| 2479 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2480 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2481 | * Re-listen when widgets are reset. |
| 2482 | */ |
| 2483 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2484 | if (mAppWidgetHost != null) { |
| 2485 | mAppWidgetHost.startListening(); |
| 2486 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2490 | * Launches the intent referred by the clicked shortcut. |
| 2491 | * |
| 2492 | * @param v The view representing the clicked shortcut. |
| 2493 | */ |
| 2494 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2495 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2496 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2497 | if (v.getWindowToken() == null) { |
| 2498 | return; |
| 2499 | } |
| 2500 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2501 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2502 | return; |
| 2503 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2504 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2505 | if (v instanceof Workspace) { |
| 2506 | if (mWorkspace.isInOverviewMode()) { |
| 2507 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2508 | } |
| 2509 | return; |
| 2510 | } |
| 2511 | |
| 2512 | if (v instanceof CellLayout) { |
| 2513 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2514 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2515 | } |
| 2516 | } |
| 2517 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2518 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2519 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2520 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2521 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2522 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2523 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2524 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2525 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2526 | onClickAllAppsButton(v); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2527 | } else if (tag instanceof AppInfo) { |
| 2528 | startAppShortcutOrInfoActivity(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2529 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2530 | if (v instanceof PendingAppWidgetHostView) { |
| 2531 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2532 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2533 | } |
| 2534 | } |
| 2535 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2536 | public void onClickPagedViewIcon(View v) { |
| 2537 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2538 | if (mLauncherCallbacks != null) { |
| 2539 | mLauncherCallbacks.onClickPagedViewIcon(v); |
| 2540 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2541 | } |
| 2542 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2543 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2544 | return false; |
| 2545 | } |
| 2546 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2547 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2548 | * Event handler for the app widget view which has not fully restored. |
| 2549 | */ |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2550 | public void onClickPendingWidget(final PendingAppWidgetHostView v) { |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2551 | if (mIsSafeModeEnabled) { |
| 2552 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2553 | return; |
| 2554 | } |
| 2555 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2556 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2557 | if (v.isReadyForClickSetup()) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2558 | int widgetId = info.appWidgetId; |
| 2559 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
| 2560 | if (appWidgetInfo != null) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2561 | mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo( |
| 2562 | this, appWidgetInfo); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2563 | mPendingAddInfo.copyFrom(info); |
| 2564 | mPendingAddWidgetId = widgetId; |
| 2565 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2566 | AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo, |
| 2567 | info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2568 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2569 | } else if (info.installProgress < 0) { |
| 2570 | // The install has not been queued |
| 2571 | final String packageName = info.providerName.getPackageName(); |
| 2572 | showBrokenAppInstallDialog(packageName, |
| 2573 | new DialogInterface.OnClickListener() { |
| 2574 | public void onClick(DialogInterface dialog, int id) { |
| 2575 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
| 2576 | } |
| 2577 | }); |
| 2578 | } else { |
| 2579 | // Download has started. |
| 2580 | final String packageName = info.providerName.getPackageName(); |
| 2581 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2586 | * Event handler for the "grid" button that appears on the home screen, which |
| 2587 | * enters all apps mode. |
| 2588 | * |
| 2589 | * @param v The view that was clicked. |
| 2590 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2591 | protected void onClickAllAppsButton(View v) { |
| 2592 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2593 | if (isAllAppsVisible()) { |
| 2594 | showWorkspace(true); |
| 2595 | } else { |
| 2596 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2597 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2598 | if (mLauncherCallbacks != null) { |
| 2599 | mLauncherCallbacks.onClickAllAppsButton(v); |
| 2600 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2601 | } |
| 2602 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2603 | private void showBrokenAppInstallDialog(final String packageName, |
| 2604 | DialogInterface.OnClickListener onSearchClickListener) { |
Sunny Goyal | e03b812 | 2014-10-08 09:55:24 -0700 | [diff] [blame] | 2605 | new AlertDialog.Builder(this) |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2606 | .setTitle(R.string.abandoned_promises_title) |
| 2607 | .setMessage(R.string.abandoned_promise_explanation) |
| 2608 | .setPositiveButton(R.string.abandoned_search, onSearchClickListener) |
| 2609 | .setNeutralButton(R.string.abandoned_clean_this, |
| 2610 | new DialogInterface.OnClickListener() { |
| 2611 | public void onClick(DialogInterface dialog, int id) { |
| 2612 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 2613 | mWorkspace.removeAbandonedPromise(packageName, user); |
| 2614 | } |
| 2615 | }) |
| 2616 | .create().show(); |
| 2617 | return; |
| 2618 | } |
| 2619 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2620 | /** |
| 2621 | * Event handler for an app shortcut click. |
| 2622 | * |
| 2623 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2624 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2625 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2626 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2627 | Object tag = v.getTag(); |
| 2628 | if (!(tag instanceof ShortcutInfo)) { |
| 2629 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2630 | } |
| 2631 | |
| 2632 | // Open shortcut |
| 2633 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2634 | |
| 2635 | if (shortcut.isDisabled != 0) { |
| 2636 | int error = R.string.activity_not_available; |
| 2637 | if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) { |
| 2638 | error = R.string.safemode_shortcut_error; |
| 2639 | } |
| 2640 | Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); |
| 2641 | return; |
| 2642 | } |
| 2643 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2644 | final Intent intent = shortcut.intent; |
| 2645 | |
| 2646 | // Check for special shortcuts |
| 2647 | if (intent.getComponent() != null) { |
| 2648 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2649 | |
| 2650 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2651 | MemoryDumpActivity.startDump(this); |
| 2652 | return; |
| 2653 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2654 | toggleShowWeightWatcher(); |
| 2655 | return; |
| 2656 | } |
| 2657 | } |
| 2658 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2659 | // Check for abandoned promise |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2660 | if ((v instanceof BubbleTextView) |
| 2661 | && shortcut.isPromise() |
| 2662 | && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2663 | showBrokenAppInstallDialog( |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2664 | shortcut.getTargetComponent().getPackageName(), |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2665 | new DialogInterface.OnClickListener() { |
| 2666 | public void onClick(DialogInterface dialog, int id) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2667 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2668 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2669 | }); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2670 | return; |
| 2671 | } |
| 2672 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2673 | // Start activities |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2674 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2675 | |
| 2676 | if (mLauncherCallbacks != null) { |
| 2677 | mLauncherCallbacks.onClickAppShortcut(v); |
| 2678 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2679 | } |
| 2680 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2681 | private void startAppShortcutOrInfoActivity(View v) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2682 | Object tag = v.getTag(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2683 | final ShortcutInfo shortcut; |
| 2684 | final Intent intent; |
| 2685 | if (tag instanceof ShortcutInfo) { |
| 2686 | shortcut = (ShortcutInfo) tag; |
| 2687 | intent = shortcut.intent; |
| 2688 | int[] pos = new int[2]; |
| 2689 | v.getLocationOnScreen(pos); |
| 2690 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2691 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2692 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2693 | } else if (tag instanceof AppInfo) { |
| 2694 | shortcut = null; |
| 2695 | intent = ((AppInfo) tag).intent; |
| 2696 | } else { |
| 2697 | throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); |
| 2698 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2699 | |
| 2700 | boolean success = startActivitySafely(v, intent, tag); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2701 | mStats.recordLaunch(intent, shortcut); |
| 2702 | |
| 2703 | if (success && v instanceof BubbleTextView) { |
| 2704 | mWaitingForResume = (BubbleTextView) v; |
| 2705 | mWaitingForResume.setStayPressed(true); |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * Event handler for a folder icon click. |
| 2711 | * |
| 2712 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2713 | */ |
| 2714 | protected void onClickFolderIcon(View v) { |
| 2715 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2716 | if (!(v instanceof FolderIcon)){ |
| 2717 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2718 | } |
| 2719 | |
| 2720 | FolderIcon folderIcon = (FolderIcon) v; |
| 2721 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2722 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2723 | |
| 2724 | // If the folder info reports that the associated folder is open, then verify that |
| 2725 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2726 | if (info.opened && openFolder == null) { |
| 2727 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2728 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2729 | info.opened = false; |
| 2730 | } |
| 2731 | |
| 2732 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2733 | // Close any open folder |
| 2734 | closeFolder(); |
| 2735 | // Open the requested folder |
| 2736 | openFolder(folderIcon); |
| 2737 | } else { |
| 2738 | // Find the open folder... |
| 2739 | int folderScreen; |
| 2740 | if (openFolder != null) { |
| 2741 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2742 | // .. and close it |
| 2743 | closeFolder(openFolder); |
| 2744 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2745 | // Close any folder open on the current screen |
| 2746 | closeFolder(); |
| 2747 | // Pull the folder onto this screen |
| 2748 | openFolder(folderIcon); |
| 2749 | } |
| 2750 | } |
| 2751 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2752 | |
| 2753 | if (mLauncherCallbacks != null) { |
| 2754 | mLauncherCallbacks.onClickFolderIcon(v); |
| 2755 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2758 | /** |
| 2759 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2760 | * on the home screen. |
| 2761 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2762 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2763 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2764 | if (mIsSafeModeEnabled) { |
| 2765 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2766 | } else { |
| 2767 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2768 | if (mLauncherCallbacks != null) { |
| 2769 | mLauncherCallbacks.onClickAddWidgetButton(view); |
| 2770 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2771 | } |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2772 | } |
| 2773 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2774 | /** |
| 2775 | * Event handler for the wallpaper picker button that appears after a long press |
| 2776 | * on the home screen. |
| 2777 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2778 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2779 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2780 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2781 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2782 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2783 | |
| 2784 | if (mLauncherCallbacks != null) { |
| 2785 | mLauncherCallbacks.onClickWallpaperPicker(v); |
| 2786 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | /** |
| 2790 | * Event handler for a click on the settings button that appears after a long press |
| 2791 | * on the home screen. |
| 2792 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2793 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2794 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2795 | if (mLauncherCallbacks != null) { |
| 2796 | mLauncherCallbacks.onClickSettingsButton(v); |
| 2797 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2798 | } |
| 2799 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2800 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2801 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2802 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2803 | } |
| 2804 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2805 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2806 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2807 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2808 | } |
| 2809 | |
| 2810 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2811 | if (mHapticFeedbackTouchListener == null) { |
| 2812 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2813 | @Override |
| 2814 | public boolean onTouch(View v, MotionEvent event) { |
| 2815 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2816 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2817 | } |
| 2818 | return false; |
| 2819 | } |
| 2820 | }; |
| 2821 | } |
| 2822 | return mHapticFeedbackTouchListener; |
| 2823 | } |
| 2824 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2825 | public void onDragStarted(View view) { |
| 2826 | if (isOnCustomContent()) { |
| 2827 | // Custom content screen doesn't participate in drag and drop. If on custom |
| 2828 | // content screen, move to default. |
| 2829 | moveWorkspaceToDefaultScreen(); |
| 2830 | } |
| 2831 | |
| 2832 | if (mLauncherCallbacks != null) { |
| 2833 | mLauncherCallbacks.onDragStarted(view); |
| 2834 | } |
| 2835 | } |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2836 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2837 | /** |
| 2838 | * Called when the user stops interacting with the launcher. |
| 2839 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2840 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2841 | protected void onInteractionEnd() { |
| 2842 | if (mLauncherCallbacks != null) { |
| 2843 | mLauncherCallbacks.onInteractionEnd(); |
| 2844 | } |
| 2845 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2846 | |
| 2847 | /** |
| 2848 | * Called when the user starts interacting with the launcher. |
| 2849 | * The possible interactions are: |
| 2850 | * - open all apps |
| 2851 | * - reorder an app shortcut, or a widget |
| 2852 | * - open the overview mode. |
| 2853 | * This is a good time to stop doing things that only make sense |
| 2854 | * when the user is on the homescreen and not doing housekeeping. |
| 2855 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2856 | protected void onInteractionBegin() { |
| 2857 | if (mLauncherCallbacks != null) { |
| 2858 | mLauncherCallbacks.onInteractionBegin(); |
| 2859 | } |
| 2860 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2861 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2862 | void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2863 | try { |
| 2864 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2865 | launcherApps.showAppDetailsForProfile(componentName, user); |
| 2866 | } catch (SecurityException e) { |
| 2867 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2868 | Log.e(TAG, "Launcher does not have permission to launch settings"); |
| 2869 | } catch (ActivityNotFoundException e) { |
| 2870 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2871 | Log.e(TAG, "Unable to launch settings"); |
| 2872 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2873 | } |
| 2874 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2875 | // returns true if the activity was started |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2876 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags, |
| 2877 | UserHandleCompat user) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2878 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2879 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2880 | // We may give them the option of disabling apps this way. |
| 2881 | int messageId = R.string.uninstall_system_app_text; |
| 2882 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2883 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2884 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2885 | String packageName = componentName.getPackageName(); |
| 2886 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2887 | Intent intent = new Intent( |
| 2888 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2889 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2890 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2891 | if (user != null) { |
| 2892 | user.addToIntent(intent, Intent.EXTRA_USER); |
| 2893 | } |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2894 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2895 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2896 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2897 | } |
| 2898 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2899 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 2900 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2901 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2902 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 2903 | // private contract between launcher and may be ignored in the future). |
| 2904 | boolean useLaunchAnimation = (v != null) && |
| 2905 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2906 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2907 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2908 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2909 | UserHandleCompat user = null; |
| 2910 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 2911 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 2912 | user = userManager.getUserForSerialNumber(serialNumber); |
| 2913 | } |
| 2914 | |
| 2915 | Bundle optsBundle = null; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2916 | if (useLaunchAnimation) { |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 2917 | ActivityOptions opts = Utilities.isLmpOrAbove() ? |
Adam Cohen | 4da294d | 2014-07-28 10:56:19 -0700 | [diff] [blame] | 2918 | ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) : |
| 2919 | ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 2920 | optsBundle = opts.toBundle(); |
| 2921 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2922 | |
| 2923 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 2924 | // Could be launching some bookkeeping activity |
| 2925 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2926 | } else { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2927 | // TODO Component can be null when shortcuts are supported for secondary user |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 2928 | launcherApps.startActivityForProfile(intent.getComponent(), user, |
| 2929 | intent.getSourceBounds(), optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2930 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2931 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2932 | } catch (SecurityException e) { |
| 2933 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2934 | 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] | 2935 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2936 | "or use the exported attribute for this activity. " |
| 2937 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2938 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2939 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2940 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2941 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2942 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 2943 | boolean success = false; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2944 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 2945 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 2946 | return false; |
| 2947 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2948 | try { |
| 2949 | success = startActivity(v, intent, tag); |
| 2950 | } catch (ActivityNotFoundException e) { |
| 2951 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2952 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 2953 | } |
| 2954 | return success; |
| 2955 | } |
| 2956 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2957 | /** |
| 2958 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 2959 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 2960 | */ |
| 2961 | private void copyFolderIconToImage(FolderIcon fi) { |
| 2962 | final int width = fi.getMeasuredWidth(); |
| 2963 | final int height = fi.getMeasuredHeight(); |
| 2964 | |
| 2965 | // Lazy load ImageView, Bitmap and Canvas |
| 2966 | if (mFolderIconImageView == null) { |
| 2967 | mFolderIconImageView = new ImageView(this); |
| 2968 | } |
| 2969 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 2970 | mFolderIconBitmap.getHeight() != height) { |
| 2971 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 2972 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 2973 | } |
| 2974 | |
| 2975 | DragLayer.LayoutParams lp; |
| 2976 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 2977 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 2978 | } else { |
| 2979 | lp = new DragLayer.LayoutParams(width, height); |
| 2980 | } |
| 2981 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2982 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 2983 | // view size by this scale factor. |
| 2984 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2985 | lp.customPosition = true; |
| 2986 | lp.x = mRectForFolderAnimation.left; |
| 2987 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2988 | lp.width = (int) (scale * width); |
| 2989 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2990 | |
| 2991 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2992 | fi.draw(mFolderIconCanvas); |
| 2993 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2994 | if (fi.getFolder() != null) { |
| 2995 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 2996 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2997 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2998 | // Just in case this image view is still in the drag layer from a previous animation, |
| 2999 | // we remove it and re-add it. |
| 3000 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 3001 | mDragLayer.removeView(mFolderIconImageView); |
| 3002 | } |
| 3003 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3004 | if (fi.getFolder() != null) { |
| 3005 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3006 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3009 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3010 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3011 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 3012 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 3013 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 3014 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3015 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 3016 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3017 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 3018 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 3019 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3022 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 3023 | copyFolderIconToImage(fi); |
| 3024 | fi.setVisibility(View.INVISIBLE); |
| 3025 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3026 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3027 | scaleX, scaleY); |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3028 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3029 | oa.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3030 | } |
| 3031 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3032 | oa.start(); |
| 3033 | } |
| 3034 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3035 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3036 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3037 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 3038 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 3039 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 3040 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3041 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3042 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3043 | // We remove and re-draw the FolderIcon in-case it has changed |
| 3044 | mDragLayer.removeView(mFolderIconImageView); |
| 3045 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3046 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3047 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3048 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3049 | oa.addListener(new AnimatorListenerAdapter() { |
| 3050 | @Override |
| 3051 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3052 | if (cl != null) { |
| 3053 | cl.clearFolderLeaveBehind(); |
| 3054 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 3055 | mDragLayer.removeView(mFolderIconImageView); |
| 3056 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3057 | } |
| 3058 | } |
| 3059 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3060 | oa.start(); |
| 3061 | } |
| 3062 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3063 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 3064 | * 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] | 3065 | * is animated relative to the specified View. If the View is null, no animation |
| 3066 | * is played. |
| 3067 | * |
| 3068 | * @param folderInfo The FolderInfo describing the folder to open. |
| 3069 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3070 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3071 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3072 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3073 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3074 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3075 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3076 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 3077 | // There was a one-off crash where the folder had a parent already. |
| 3078 | if (folder.getParent() == null) { |
| 3079 | mDragLayer.addView(folder); |
| 3080 | mDragController.addDropTarget((DropTarget) folder); |
| 3081 | } else { |
| 3082 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 3083 | folder.getParent() + ")."); |
| 3084 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3085 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3086 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3087 | |
| 3088 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 3089 | // the workspace items |
| 3090 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 3091 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 3095 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3096 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 3097 | if (folder.isEditingName()) { |
| 3098 | folder.dismissEditingName(); |
| 3099 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3100 | closeFolder(folder); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | void closeFolder(Folder folder) { |
| 3105 | folder.getInfo().opened = false; |
| 3106 | |
| 3107 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 3108 | if (parent != null) { |
| 3109 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 3110 | shrinkAndFadeInFolderIcon(fi); |
| 3111 | } |
| 3112 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3113 | |
| 3114 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 3115 | // longer occludeds the workspace items |
| 3116 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3117 | } |
| 3118 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3119 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 3120 | if (!isDraggingEnabled()) return false; |
| 3121 | if (isWorkspaceLocked()) return false; |
| 3122 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3123 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3124 | if (v instanceof Workspace) { |
| 3125 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 3126 | if (mWorkspace.enterOverviewMode()) { |
| 3127 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3128 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 3129 | return true; |
| 3130 | } else { |
| 3131 | return false; |
| 3132 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 3133 | } else { |
| 3134 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3135 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3136 | } |
| 3137 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 3138 | CellLayout.CellInfo longClickCellInfo = null; |
| 3139 | View itemUnderLongClick = null; |
| 3140 | if (v.getTag() instanceof ItemInfo) { |
| 3141 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3142 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 3143 | itemUnderLongClick = longClickCellInfo.cell; |
| 3144 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3145 | } |
| 3146 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3147 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 3148 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3149 | final boolean inHotseat = isHotseatLayout(v); |
| 3150 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3151 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3152 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3153 | // User long pressed on empty space |
| 3154 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3155 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3156 | if (mWorkspace.isInOverviewMode()) { |
| 3157 | mWorkspace.startReordering(v); |
| 3158 | } else { |
| 3159 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 3160 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3161 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3162 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 3163 | mHotseat.getOrderInHotseat( |
| 3164 | longClickCellInfo.cellX, |
| 3165 | longClickCellInfo.cellY)); |
| 3166 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3167 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3168 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | } |
| 3172 | return true; |
| 3173 | } |
| 3174 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3175 | boolean isHotseatLayout(View layout) { |
| 3176 | return mHotseat != null && layout != null && |
| 3177 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 3178 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 3179 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3180 | /** |
| 3181 | * Returns the CellLayout of the specified container at the specified screen. |
| 3182 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3183 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3184 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3185 | if (mHotseat != null) { |
| 3186 | return mHotseat.getLayout(); |
| 3187 | } else { |
| 3188 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 3189 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3190 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3191 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 3192 | } |
| 3193 | } |
| 3194 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3195 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3196 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 3197 | } |
| 3198 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3199 | private void setWorkspaceBackground(boolean workspace) { |
| 3200 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 3201 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 3204 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3205 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 3206 | int curflags = getWindow().getAttributes().flags |
| 3207 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 3208 | if (wpflags != curflags) { |
| 3209 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 3210 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3211 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3212 | } |
| 3213 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3214 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3215 | if (v instanceof LauncherTransitionable) { |
| 3216 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3217 | } |
| 3218 | } |
| 3219 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3220 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3221 | if (v instanceof LauncherTransitionable) { |
| 3222 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3223 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3224 | |
| 3225 | // Update the workspace transition step as well |
| 3226 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3227 | } |
| 3228 | |
| 3229 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3230 | if (v instanceof LauncherTransitionable) { |
| 3231 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3232 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3236 | if (v instanceof LauncherTransitionable) { |
| 3237 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3238 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3239 | |
| 3240 | // Update the workspace transition step as well |
| 3241 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3242 | } |
| 3243 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3244 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3245 | * Things to test when changing the following seven functions. |
| 3246 | * - Home from workspace |
| 3247 | * - from center screen |
| 3248 | * - from other screens |
| 3249 | * - Home from all apps |
| 3250 | * - from center screen |
| 3251 | * - from other screens |
| 3252 | * - Back from all apps |
| 3253 | * - from center screen |
| 3254 | * - from other screens |
| 3255 | * - Launch app from workspace and quit |
| 3256 | * - with back |
| 3257 | * - with home |
| 3258 | * - Launch app from all apps and quit |
| 3259 | * - with back |
| 3260 | * - with home |
| 3261 | * - Go to a screen that's not the default, then all |
| 3262 | * apps, and launch and app, and go back |
| 3263 | * - with back |
| 3264 | * -with home |
| 3265 | * - On workspace, long press power and go back |
| 3266 | * - with back |
| 3267 | * - with home |
| 3268 | * - On all apps, long press power and go back |
| 3269 | * - with back |
| 3270 | * - with home |
| 3271 | * - On workspace, power off |
| 3272 | * - On all apps, power off |
| 3273 | * - Launch an app and turn off the screen while in that app |
| 3274 | * - Go back with home key |
| 3275 | * - Go back with back key TODO: make this not go to workspace |
| 3276 | * - From all apps |
| 3277 | * - From workspace |
| 3278 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3279 | * - From all apps |
| 3280 | * - From the center workspace |
| 3281 | * - From another workspace |
| 3282 | */ |
| 3283 | |
| 3284 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3285 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3286 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3287 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3288 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3289 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3290 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3291 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3292 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3293 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3294 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3295 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3296 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3297 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3298 | mStateAnimation.cancel(); |
| 3299 | mStateAnimation = null; |
| 3300 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3301 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3302 | boolean material = Utilities.isLmpOrAbove(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3303 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3304 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3305 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3306 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); |
| 3307 | final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3308 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3309 | final int itemsAlphaStagger = |
| 3310 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3311 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3312 | final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3313 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3314 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3315 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3316 | final ArrayList<View> layerViews = new ArrayList<View>(); |
| 3317 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3318 | Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? |
| 3319 | Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3320 | Animator workspaceAnim = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3321 | mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3322 | if (!LauncherAppState.isDisableAllApps() |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3323 | || contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3324 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3325 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3326 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3327 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3328 | // If for some reason our views aren't initialized, don't animate |
| 3329 | boolean initialized = getAllAppsButton() != null; |
| 3330 | |
| 3331 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3332 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3333 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3334 | toView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3335 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3336 | final View page = content.getPageAt(content.getCurrentPage()); |
| 3337 | final View revealView = toView.findViewById(R.id.fake_page); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3338 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3339 | final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; |
| 3340 | if (isWidgetTray) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3341 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3342 | } else { |
| 3343 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3344 | } |
| 3345 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3346 | // Hide the real page background, and swap in the fake one |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3347 | content.setPageBackgroundsVisible(false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3348 | revealView.setVisibility(View.VISIBLE); |
| 3349 | // We need to hide this view as the animation start will be posted. |
| 3350 | revealView.setAlpha(0); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3351 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3352 | int width = revealView.getMeasuredWidth(); |
| 3353 | int height = revealView.getMeasuredHeight(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3354 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3355 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3356 | revealView.setTranslationY(0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3357 | revealView.setTranslationX(0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3358 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3359 | // Get the y delta between the center of the page and the center of the all apps button |
| 3360 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3361 | getAllAppsButton(), null); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3362 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3363 | float alpha = 0; |
| 3364 | float xDrift = 0; |
| 3365 | float yDrift = 0; |
| 3366 | if (material) { |
| 3367 | alpha = isWidgetTray ? 0.3f : 1f; |
| 3368 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3369 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3370 | } else { |
| 3371 | yDrift = 2 * height / 3; |
| 3372 | xDrift = 0; |
| 3373 | } |
| 3374 | final float initAlpha = alpha; |
| 3375 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3376 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3377 | layerViews.add(revealView); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3378 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3379 | PropertyValuesHolder panelDriftY = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3380 | PropertyValuesHolder.ofFloat("translationY", yDrift, 0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3381 | PropertyValuesHolder panelDriftX = |
| 3382 | PropertyValuesHolder.ofFloat("translationX", xDrift, 0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3383 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3384 | ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, |
| 3385 | panelAlpha, panelDriftY, panelDriftX); |
| 3386 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3387 | panelAlphaAndDrift.setDuration(revealDuration); |
| 3388 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3389 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3390 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3391 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3392 | if (page != null) { |
| 3393 | page.setVisibility(View.VISIBLE); |
| 3394 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3395 | layerViews.add(page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3396 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3397 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0); |
| 3398 | page.setTranslationY(yDrift); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3399 | pageDrift.setDuration(revealDuration); |
| 3400 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3401 | pageDrift.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3402 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3403 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3404 | page.setAlpha(0f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3405 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3406 | itemsAlpha.setDuration(revealDuration); |
| 3407 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 3408 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
| 3409 | mStateAnimation.play(itemsAlpha); |
| 3410 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3411 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3412 | View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); |
| 3413 | pageIndicators.setAlpha(0.01f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3414 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3415 | ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3416 | indicatorsAlpha.setDuration(revealDuration); |
| 3417 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3418 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3419 | if (material) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3420 | final View allApps = getAllAppsButton(); |
| 3421 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3422 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3423 | float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3424 | Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3425 | height / 2, startRadius, revealRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3426 | reveal.setDuration(revealDuration); |
| 3427 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3428 | |
| 3429 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3430 | public void onAnimationStart(Animator animation) { |
| 3431 | if (!isWidgetTray) { |
| 3432 | allApps.setVisibility(View.INVISIBLE); |
| 3433 | } |
| 3434 | } |
| 3435 | public void onAnimationEnd(Animator animation) { |
| 3436 | if (!isWidgetTray) { |
| 3437 | allApps.setVisibility(View.VISIBLE); |
| 3438 | } |
| 3439 | } |
| 3440 | }); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3441 | mStateAnimation.play(reveal); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3442 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3443 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3444 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
| 3445 | @Override |
| 3446 | public void onAnimationEnd(Animator animation) { |
| 3447 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3448 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 3449 | |
| 3450 | revealView.setVisibility(View.INVISIBLE); |
| 3451 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3452 | if (page != null) { |
| 3453 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3454 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3455 | content.setPageBackgroundsVisible(true); |
| 3456 | |
| 3457 | // Hide the search bar |
| 3458 | if (mSearchDropTargetBar != null) { |
| 3459 | mSearchDropTargetBar.hideSearchBar(false); |
| 3460 | } |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3461 | |
| 3462 | // This can hold unnecessary references to views. |
| 3463 | mStateAnimation = null; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3466 | }); |
| 3467 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3468 | if (workspaceAnim != null) { |
| 3469 | mStateAnimation.play(workspaceAnim); |
| 3470 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3471 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3472 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3473 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3474 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3475 | final Runnable startAnimRunnable = new Runnable() { |
| 3476 | public void run() { |
| 3477 | // Check that mStateAnimation hasn't changed while |
| 3478 | // we waited for a layout/draw pass |
| 3479 | if (mStateAnimation != stateAnimation) |
| 3480 | return; |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3481 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3482 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3483 | |
| 3484 | revealView.setAlpha(initAlpha); |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3485 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3486 | for (int i = 0; i < layerViews.size(); i++) { |
| 3487 | View v = layerViews.get(i); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3488 | if (v != null) { |
Sunny Goyal | fafca52 | 2014-11-03 11:30:01 -0800 | [diff] [blame] | 3489 | if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3490 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3491 | } |
| 3492 | } |
| 3493 | mStateAnimation.start(); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3494 | } |
| 3495 | }; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3496 | toView.bringToFront(); |
| 3497 | toView.setVisibility(View.VISIBLE); |
| 3498 | toView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3499 | } else { |
| 3500 | toView.setTranslationX(0.0f); |
| 3501 | toView.setTranslationY(0.0f); |
| 3502 | toView.setScaleX(1.0f); |
| 3503 | toView.setScaleY(1.0f); |
| 3504 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3505 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3506 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3507 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3508 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3509 | if (mSearchDropTargetBar != null) { |
| 3510 | mSearchDropTargetBar.hideSearchBar(false); |
| 3511 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3512 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3513 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3514 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3515 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3516 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3517 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3518 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3519 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | /** |
| 3523 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3524 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3525 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3526 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3527 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3528 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3529 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3530 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3531 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3532 | mStateAnimation.cancel(); |
| 3533 | mStateAnimation = null; |
| 3534 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3535 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3536 | boolean material = Utilities.isLmpOrAbove(); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3537 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3538 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3539 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3540 | final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3541 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3542 | final int itemsAlphaStagger = |
| 3543 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3544 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3545 | final float scaleFactor = (float) |
| 3546 | res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
| 3547 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3548 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3549 | Animator workspaceAnim = null; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3550 | final ArrayList<View> layerViews = new ArrayList<View>(); |
| 3551 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3552 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3553 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3554 | toState, animated, layerViews); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3555 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3556 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3557 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3558 | toState, animated, layerViews); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3559 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3560 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3561 | // If for some reason our views aren't initialized, don't animate |
| 3562 | boolean initialized = getAllAppsButton() != null; |
| 3563 | |
| 3564 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3565 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3566 | if (workspaceAnim != null) { |
| 3567 | mStateAnimation.play(workspaceAnim); |
| 3568 | } |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3569 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3570 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3571 | fromView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3572 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3573 | final View page = content.getPageAt(content.getNextPage()); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3574 | |
| 3575 | // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases |
| 3576 | int count = content.getChildCount(); |
| 3577 | for (int i = 0; i < count; i++) { |
| 3578 | View child = content.getChildAt(i); |
| 3579 | if (child != page) { |
| 3580 | child.setVisibility(View.INVISIBLE); |
| 3581 | } |
| 3582 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3583 | final View revealView = fromView.findViewById(R.id.fake_page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3584 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3585 | // hideAppsCustomizeHelper is called in some cases when it is already hidden |
| 3586 | // don't perform all these no-op animations. In particularly, this was causing |
| 3587 | // the all-apps button to pop in and out. |
| 3588 | if (fromView.getVisibility() == View.VISIBLE) { |
| 3589 | AppsCustomizePagedView.ContentType contentType = content.getContentType(); |
| 3590 | final boolean isWidgetTray = |
| 3591 | contentType == AppsCustomizePagedView.ContentType.Widgets; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3592 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3593 | if (isWidgetTray) { |
| 3594 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3595 | } else { |
| 3596 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3597 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3598 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3599 | int width = revealView.getMeasuredWidth(); |
| 3600 | int height = revealView.getMeasuredHeight(); |
| 3601 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
| 3602 | |
| 3603 | // Hide the real page background, and swap in the fake one |
| 3604 | revealView.setVisibility(View.VISIBLE); |
| 3605 | content.setPageBackgroundsVisible(false); |
| 3606 | |
| 3607 | final View allAppsButton = getAllAppsButton(); |
| 3608 | revealView.setTranslationY(0); |
| 3609 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3610 | allAppsButton, null); |
| 3611 | |
| 3612 | float xDrift = 0; |
| 3613 | float yDrift = 0; |
| 3614 | if (material) { |
| 3615 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3616 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3617 | } else { |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3618 | yDrift = 2 * height / 3; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3619 | xDrift = 0; |
| 3620 | } |
| 3621 | |
| 3622 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3623 | TimeInterpolator decelerateInterpolator = material ? |
| 3624 | new LogDecelerateInterpolator(100, 0) : |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3625 | new DecelerateInterpolator(1f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3626 | |
| 3627 | // The vertical motion of the apps panel should be delayed by one frame |
| 3628 | // from the conceal animation in order to give the right feel. We correpsondingly |
| 3629 | // shorten the duration so that the slide and conceal end at the same time. |
| 3630 | ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", |
| 3631 | 0, yDrift); |
| 3632 | panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3633 | panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3634 | panelDriftY.setInterpolator(decelerateInterpolator); |
| 3635 | mStateAnimation.play(panelDriftY); |
| 3636 | |
| 3637 | ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", |
| 3638 | 0, xDrift); |
| 3639 | panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3640 | panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3641 | panelDriftX.setInterpolator(decelerateInterpolator); |
| 3642 | mStateAnimation.play(panelDriftX); |
| 3643 | |
| 3644 | if (isWidgetTray || !material) { |
| 3645 | float finalAlpha = material ? 0.4f : 0f; |
| 3646 | revealView.setAlpha(1f); |
| 3647 | ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", |
| 3648 | 1f, finalAlpha); |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3649 | panelAlpha.setDuration(material ? revealDuration : 150); |
| 3650 | panelAlpha.setInterpolator(decelerateInterpolator); |
| 3651 | panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3652 | mStateAnimation.play(panelAlpha); |
| 3653 | } |
| 3654 | |
| 3655 | if (page != null) { |
| 3656 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3657 | |
| 3658 | ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", |
| 3659 | 0, yDrift); |
| 3660 | page.setTranslationY(0); |
| 3661 | pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3662 | pageDrift.setInterpolator(decelerateInterpolator); |
| 3663 | pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3664 | mStateAnimation.play(pageDrift); |
| 3665 | |
| 3666 | page.setAlpha(1f); |
| 3667 | ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f); |
| 3668 | itemsAlpha.setDuration(100); |
| 3669 | itemsAlpha.setInterpolator(decelerateInterpolator); |
| 3670 | mStateAnimation.play(itemsAlpha); |
| 3671 | } |
| 3672 | |
| 3673 | View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); |
| 3674 | pageIndicators.setAlpha(1f); |
| 3675 | ObjectAnimator indicatorsAlpha = |
| 3676 | LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f); |
| 3677 | indicatorsAlpha.setDuration(revealDuration); |
| 3678 | indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 3679 | mStateAnimation.play(indicatorsAlpha); |
| 3680 | |
| 3681 | width = revealView.getMeasuredWidth(); |
| 3682 | |
| 3683 | if (material) { |
| 3684 | if (!isWidgetTray) { |
| 3685 | allAppsButton.setVisibility(View.INVISIBLE); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3686 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3687 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3688 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3689 | float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
| 3690 | Animator reveal = |
| 3691 | LauncherAnimUtils.createCircularReveal(revealView, width / 2, |
| 3692 | height / 2, revealRadius, finalRadius); |
| 3693 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3694 | reveal.setDuration(revealDuration); |
| 3695 | reveal.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3696 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3697 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3698 | public void onAnimationEnd(Animator animation) { |
| 3699 | revealView.setVisibility(View.INVISIBLE); |
| 3700 | if (!isWidgetTray) { |
| 3701 | allAppsButton.setVisibility(View.VISIBLE); |
| 3702 | } |
| 3703 | } |
| 3704 | }); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3705 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3706 | mStateAnimation.play(reveal); |
| 3707 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3708 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3709 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3710 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 3711 | mAppsCustomizeContent.stopScrolling(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3712 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3713 | |
| 3714 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3715 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3716 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3717 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3718 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3719 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3720 | if (onCompleteRunnable != null) { |
| 3721 | onCompleteRunnable.run(); |
| 3722 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3723 | |
| 3724 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3725 | if (page != null) { |
| 3726 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3727 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3728 | content.setPageBackgroundsVisible(true); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3729 | // Unhide side pages |
| 3730 | int count = content.getChildCount(); |
| 3731 | for (int i = 0; i < count; i++) { |
| 3732 | View child = content.getChildAt(i); |
| 3733 | child.setVisibility(View.VISIBLE); |
| 3734 | } |
| 3735 | |
| 3736 | // Reset page transforms |
Adam Cohen | 493f6bc | 2014-09-18 08:11:05 -0700 | [diff] [blame] | 3737 | if (page != null) { |
| 3738 | page.setTranslationX(0); |
| 3739 | page.setTranslationY(0); |
| 3740 | page.setAlpha(1); |
| 3741 | } |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3742 | content.setCurrentPage(content.getNextPage()); |
| 3743 | |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3744 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3745 | |
| 3746 | // This can hold unnecessary references to views. |
| 3747 | mStateAnimation = null; |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3748 | } |
| 3749 | }); |
| 3750 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3751 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3752 | final Runnable startAnimRunnable = new Runnable() { |
| 3753 | public void run() { |
| 3754 | // Check that mStateAnimation hasn't changed while |
| 3755 | // we waited for a layout/draw pass |
| 3756 | if (mStateAnimation != stateAnimation) |
| 3757 | return; |
| 3758 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3759 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3760 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3761 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3762 | for (int i = 0; i < layerViews.size(); i++) { |
| 3763 | View v = layerViews.get(i); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3764 | if (v != null) { |
Sunny Goyal | fafca52 | 2014-11-03 11:30:01 -0800 | [diff] [blame] | 3765 | if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3766 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3767 | } |
| 3768 | } |
| 3769 | mStateAnimation.start(); |
| 3770 | } |
| 3771 | }; |
| 3772 | fromView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3773 | } else { |
| 3774 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3775 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3776 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3777 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3778 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3779 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3780 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3781 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3784 | @Override |
| 3785 | public void onTrimMemory(int level) { |
| 3786 | super.onTrimMemory(level); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3787 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
| 3788 | // The widget preview db can result in holding onto over |
| 3789 | // 3MB of memory for caching which isn't necessary. |
| 3790 | SQLiteDatabase.releaseMemory(); |
| 3791 | |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 3792 | // This clears all widget bitmaps from the widget tray |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3793 | if (mAppsCustomizeTabHost != null) { |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 3794 | mAppsCustomizeTabHost.trimMemory(); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3795 | } |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3799 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3800 | showWorkspace(animated, null); |
| 3801 | } |
| 3802 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3803 | protected void showWorkspace() { |
| 3804 | showWorkspace(true); |
| 3805 | } |
| 3806 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3807 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 3808 | if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3809 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3810 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3811 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3812 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3813 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3814 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3815 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3816 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3817 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3818 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3819 | // Set focus to the AppsCustomize button |
| 3820 | if (mAllAppsButton != null) { |
| 3821 | mAllAppsButton.requestFocus(); |
| 3822 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3823 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3824 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3825 | // Change the state *after* we've called all the transition code |
| 3826 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3827 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3828 | // Resume the auto-advance of widgets |
| 3829 | mUserPresent = true; |
| 3830 | updateRunning(); |
| 3831 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3832 | // Send an accessibility event to announce the context change |
| 3833 | getWindow().getDecorView() |
| 3834 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3835 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3836 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3837 | } |
| 3838 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3839 | void showOverviewMode(boolean animated) { |
| 3840 | mWorkspace.setVisibility(View.VISIBLE); |
| 3841 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3842 | mState = State.WORKSPACE; |
| 3843 | onWorkspaceShown(animated); |
| 3844 | } |
| 3845 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3846 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3847 | } |
| 3848 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3849 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3850 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3851 | if (mState != State.WORKSPACE) return; |
| 3852 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3853 | if (resetPageToZero) { |
| 3854 | mAppsCustomizeTabHost.reset(); |
| 3855 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3856 | showAppsCustomizeHelper(animated, false, contentType); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 3857 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3858 | @Override |
| 3859 | public void run() { |
| 3860 | // We post this in-case the all apps view isn't yet constructed. |
| 3861 | mAppsCustomizeTabHost.requestFocus(); |
| 3862 | } |
| 3863 | }); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3864 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3865 | // Change the state *after* we've called all the transition code |
| 3866 | mState = State.APPS_CUSTOMIZE; |
| 3867 | |
| 3868 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3869 | mUserPresent = false; |
| 3870 | updateRunning(); |
| 3871 | closeFolder(); |
| 3872 | |
| 3873 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3874 | getWindow().getDecorView() |
| 3875 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3876 | } |
| 3877 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3878 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3879 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3880 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3881 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3882 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3883 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3884 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3885 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3886 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3887 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 3888 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 3889 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3890 | @Override |
| 3891 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3892 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3893 | // Before we show workspace, hide all apps again because |
| 3894 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 3895 | // clean up our state transition functions |
| 3896 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3897 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3898 | } else { |
| 3899 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3900 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3901 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3902 | }, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3903 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3904 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3905 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3906 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3907 | final boolean animated = true; |
| 3908 | final boolean springLoaded = true; |
| 3909 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3910 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3911 | } |
| 3912 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 3913 | } |
| 3914 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3915 | void lockAllApps() { |
| 3916 | // TODO |
| 3917 | } |
| 3918 | |
| 3919 | void unlockAllApps() { |
| 3920 | // TODO |
| 3921 | } |
| 3922 | |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3923 | protected void disableVoiceButtonProxy(boolean disable) { |
| 3924 | // NO-OP |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3925 | } |
| 3926 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3927 | public View getQsbBar() { |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 3928 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 3929 | return mLauncherCallbacks.getQsbBar(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3930 | } |
| 3931 | |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3932 | if (mQsb == null) { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3933 | AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this); |
| 3934 | if (searchProvider == null) { |
| 3935 | return null; |
| 3936 | } |
| 3937 | |
| 3938 | Bundle opts = new Bundle(); |
| 3939 | opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, |
| 3940 | AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); |
| 3941 | |
| 3942 | SharedPreferences sp = getSharedPreferences( |
| 3943 | LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE); |
| 3944 | int widgetId = sp.getInt(QSB_WIDGET_ID, -1); |
Sunny Goyal | 416541c | 2014-11-14 11:59:57 -0800 | [diff] [blame] | 3945 | AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3946 | if (!searchProvider.provider.flattenToString().equals( |
| 3947 | sp.getString(QSB_WIDGET_PROVIDER, null)) |
Sunny Goyal | 416541c | 2014-11-14 11:59:57 -0800 | [diff] [blame] | 3948 | || (widgetInfo == null) |
| 3949 | || !widgetInfo.provider.equals(searchProvider.provider)) { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3950 | // A valid widget is not already bound. |
| 3951 | if (widgetId > -1) { |
| 3952 | mAppWidgetHost.deleteAppWidgetId(widgetId); |
| 3953 | widgetId = -1; |
| 3954 | } |
| 3955 | |
| 3956 | // Try to bind a new widget |
| 3957 | widgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 3958 | |
| 3959 | if (!AppWidgetManagerCompat.getInstance(this) |
| 3960 | .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) { |
| 3961 | mAppWidgetHost.deleteAppWidgetId(widgetId); |
| 3962 | widgetId = -1; |
| 3963 | } |
| 3964 | |
| 3965 | sp.edit() |
| 3966 | .putInt(QSB_WIDGET_ID, widgetId) |
| 3967 | .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString()) |
| 3968 | .commit(); |
| 3969 | } |
| 3970 | |
| 3971 | if (widgetId != -1) { |
| 3972 | mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider); |
| 3973 | mQsb.updateAppWidgetOptions(opts); |
| 3974 | mQsb.setPadding(0, 0, 0, 0); |
| 3975 | mSearchDropTargetBar.addView(mQsb); |
| 3976 | } |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3977 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3978 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3979 | } |
| 3980 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3981 | @Override |
| 3982 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3983 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3984 | final List<CharSequence> text = event.getText(); |
| 3985 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3986 | // Populate event with a fake title based on the current state. |
| 3987 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3988 | text.add(mAppsCustomizeTabHost.getContentTag()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3989 | } else { |
| 3990 | text.add(getString(R.string.all_apps_home_button_label)); |
| 3991 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3992 | return result; |
| 3993 | } |
| 3994 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3995 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 3996 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3997 | */ |
| 3998 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 3999 | @Override |
| 4000 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4001 | closeSystemDialogs(); |
| 4002 | } |
| 4003 | } |
| 4004 | |
| 4005 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 4006 | * Receives notifications whenever the appwidgets are reset. |
| 4007 | */ |
| 4008 | private class AppWidgetResetObserver extends ContentObserver { |
| 4009 | public AppWidgetResetObserver() { |
| 4010 | super(new Handler()); |
| 4011 | } |
| 4012 | |
| 4013 | @Override |
| 4014 | public void onChange(boolean selfChange) { |
| 4015 | onAppWidgetReset(); |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4020 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 4021 | * in onResume. |
| 4022 | * |
| 4023 | * This needs to be called from incoming places where resources might have been loaded |
| 4024 | * while we are paused. That is becaues the Configuration might be wrong |
| 4025 | * when we're not running, and if it comes back to what it was when we |
| 4026 | * were paused, we are not restarted. |
| 4027 | * |
| 4028 | * Implementation of the method from LauncherModel.Callbacks. |
| 4029 | * |
| 4030 | * @return true if we are currently paused. The caller might be able to |
| 4031 | * skip some work in that case since we will come back again. |
| 4032 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4033 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4034 | if (mPaused) { |
| 4035 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4036 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4037 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4038 | } |
| 4039 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4040 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4041 | return true; |
| 4042 | } else { |
| 4043 | return false; |
| 4044 | } |
| 4045 | } |
| 4046 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4047 | private boolean waitUntilResume(Runnable run) { |
| 4048 | return waitUntilResume(run, false); |
| 4049 | } |
| 4050 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4051 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 4052 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4055 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4056 | * If the activity is currently paused, signal that we need to re-run the loader |
| 4057 | * in onResume. |
| 4058 | * |
| 4059 | * This needs to be called from incoming places where resources might have been loaded |
| 4060 | * while we are paused. That is becaues the Configuration might be wrong |
| 4061 | * when we're not running, and if it comes back to what it was when we |
| 4062 | * were paused, we are not restarted. |
| 4063 | * |
| 4064 | * Implementation of the method from LauncherModel.Callbacks. |
| 4065 | * |
| 4066 | * @return true if we are currently paused. The caller might be able to |
| 4067 | * skip some work in that case since we will come back again. |
| 4068 | */ |
| 4069 | public boolean setLoadOnResume() { |
| 4070 | if (mPaused) { |
| 4071 | Log.i(TAG, "setLoadOnResume"); |
| 4072 | mOnResumeNeedsLoad = true; |
| 4073 | return true; |
| 4074 | } else { |
| 4075 | return false; |
| 4076 | } |
| 4077 | } |
| 4078 | |
| 4079 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4080 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4081 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4082 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4083 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4084 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4085 | } else { |
| 4086 | return SCREEN_COUNT / 2; |
| 4087 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4088 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4089 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4090 | /** |
| 4091 | * Refreshes the shortcuts shown on the workspace. |
| 4092 | * |
| 4093 | * Implementation of the method from LauncherModel.Callbacks. |
| 4094 | */ |
| 4095 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4096 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 4097 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4098 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 4099 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 4100 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4101 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4102 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4103 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4104 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 4105 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4106 | |
Michael Jurka | 05bf644 | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 4107 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4108 | if (mHotseat != null) { |
| 4109 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4110 | } |
| 4111 | } |
| 4112 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4113 | @Override |
| 4114 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4115 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4116 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 4117 | // If there are no screens, we need to have an empty screen |
| 4118 | if (orderedScreenIds.size() == 0) { |
| 4119 | mWorkspace.addExtraEmptyScreen(); |
| 4120 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4121 | |
| 4122 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4123 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 4124 | if (hasCustomContentToLeft()) { |
| 4125 | mWorkspace.createCustomContentContainer(); |
| 4126 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4127 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | @Override |
| 4131 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 4132 | // Log to disk |
| 4133 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 4134 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 4135 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4136 | int count = orderedScreenIds.size(); |
| 4137 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 4138 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4139 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4140 | } |
| 4141 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4142 | private boolean shouldShowWeightWatcher() { |
| 4143 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4144 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 4145 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4146 | |
| 4147 | return show; |
| 4148 | } |
| 4149 | |
| 4150 | private void toggleShowWeightWatcher() { |
| 4151 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4152 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 4153 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 4154 | |
| 4155 | show = !show; |
| 4156 | |
| 4157 | SharedPreferences.Editor editor = sp.edit(); |
| 4158 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 4159 | editor.commit(); |
| 4160 | |
| 4161 | if (mWeightWatcher != null) { |
| 4162 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 4163 | } |
| 4164 | } |
| 4165 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4166 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 4167 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4168 | final ArrayList<ItemInfo> addAnimated, |
| 4169 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4170 | Runnable r = new Runnable() { |
| 4171 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4172 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4173 | } |
| 4174 | }; |
| 4175 | if (waitUntilResume(r)) { |
| 4176 | return; |
| 4177 | } |
| 4178 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4179 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4180 | if (newScreens != null) { |
| 4181 | bindAddScreens(newScreens); |
| 4182 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4183 | |
| 4184 | // We add the items without animation on non-visible pages, and with |
| 4185 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4186 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4187 | bindItems(addNotAnimated, 0, |
| 4188 | addNotAnimated.size(), false); |
| 4189 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4190 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4191 | bindItems(addAnimated, 0, |
| 4192 | addAnimated.size(), true); |
| 4193 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4194 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4195 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 4196 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4197 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4198 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4199 | addedApps != null && mAppsCustomizeContent != null) { |
| 4200 | mAppsCustomizeContent.addApps(addedApps); |
| 4201 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4202 | } |
| 4203 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4204 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4205 | * Bind the items start-end from the list. |
| 4206 | * |
| 4207 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4208 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4209 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 4210 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4211 | Runnable r = new Runnable() { |
| 4212 | public void run() { |
| 4213 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 4214 | } |
| 4215 | }; |
| 4216 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4217 | return; |
| 4218 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4219 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4220 | // 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] | 4221 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 4222 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4223 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4224 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4225 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4226 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4227 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4228 | |
| 4229 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4230 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4231 | mHotseat == null) { |
| 4232 | continue; |
| 4233 | } |
| 4234 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4235 | switch (item.itemType) { |
| 4236 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4237 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4238 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4239 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4240 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4241 | /* |
| 4242 | * TODO: FIX collision case |
| 4243 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4244 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4245 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4246 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4247 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4248 | Object tag = v.getTag(); |
| 4249 | String desc = "Collision while binding workspace item: " + item |
| 4250 | + ". Collides with " + tag; |
| 4251 | if (LauncherAppState.isDogfoodBuild()) { |
| 4252 | throw (new RuntimeException(desc)); |
| 4253 | } else { |
| 4254 | Log.d(TAG, desc); |
| 4255 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4256 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4259 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4260 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4261 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4262 | // Animate all the applications up now |
| 4263 | shortcut.setAlpha(0f); |
| 4264 | shortcut.setScaleX(0f); |
| 4265 | shortcut.setScaleY(0f); |
| 4266 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4267 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4268 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4269 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4270 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4271 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4272 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4273 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4274 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4275 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4276 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4277 | default: |
| 4278 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4279 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4280 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4281 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4282 | if (animateIcons) { |
| 4283 | // Animate to the correct page |
| 4284 | if (newShortcutsScreenId > -1) { |
| 4285 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4286 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4287 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4288 | public void run() { |
| 4289 | anim.playTogether(bounceAnims); |
| 4290 | anim.start(); |
| 4291 | } |
| 4292 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4293 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4294 | // We post the animation slightly delayed to prevent slowdowns |
| 4295 | // when we are loading right after we return to launcher. |
| 4296 | mWorkspace.postDelayed(new Runnable() { |
| 4297 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4298 | if (mWorkspace != null) { |
| 4299 | mWorkspace.snapToPage(newScreenIndex); |
| 4300 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4301 | NEW_APPS_ANIMATION_DELAY); |
| 4302 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4303 | } |
| 4304 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4305 | } else { |
| 4306 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4307 | } |
| 4308 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4309 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4310 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4311 | } |
| 4312 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4313 | /** |
| 4314 | * Implementation of the method from LauncherModel.Callbacks. |
| 4315 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4316 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4317 | Runnable r = new Runnable() { |
| 4318 | public void run() { |
| 4319 | bindFolders(folders); |
| 4320 | } |
| 4321 | }; |
| 4322 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4323 | return; |
| 4324 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4325 | sFolders.clear(); |
| 4326 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4327 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4328 | |
| 4329 | /** |
| 4330 | * Add the views for a widget to the workspace. |
| 4331 | * |
| 4332 | * Implementation of the method from LauncherModel.Callbacks. |
| 4333 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4334 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4335 | Runnable r = new Runnable() { |
| 4336 | public void run() { |
| 4337 | bindAppWidget(item); |
| 4338 | } |
| 4339 | }; |
| 4340 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4341 | return; |
| 4342 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4343 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4344 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4345 | if (DEBUG_WIDGETS) { |
| 4346 | Log.d(TAG, "bindAppWidget: " + item); |
| 4347 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4348 | final Workspace workspace = mWorkspace; |
| 4349 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4350 | LauncherAppWidgetProviderInfo appWidgetInfo = |
| 4351 | LauncherModel.getProviderInfo(this, item.providerName); |
| 4352 | |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4353 | if (!mIsSafeModeEnabled |
| 4354 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) |
| 4355 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4356 | if (appWidgetInfo == null) { |
| 4357 | if (DEBUG_WIDGETS) { |
| 4358 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4359 | + " belongs to component " + item.providerName |
| 4360 | + ", as the povider is null"); |
| 4361 | } |
| 4362 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4363 | return; |
| 4364 | } |
| 4365 | // Note: This assumes that the id remap broadcast is received before this step. |
| 4366 | // If that is not the case, the id remap will be ignored and user may see the |
| 4367 | // click to setup view. |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4368 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4369 | pendingInfo.spanX = item.spanX; |
| 4370 | pendingInfo.spanY = item.spanY; |
| 4371 | pendingInfo.minSpanX = item.minSpanX; |
| 4372 | pendingInfo.minSpanY = item.minSpanY; |
| 4373 | Bundle options = |
| 4374 | AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo); |
| 4375 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4376 | int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 4377 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 4378 | newWidgetId, appWidgetInfo, options); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4379 | |
| 4380 | // TODO consider showing a permission dialog when the widget is clicked. |
| 4381 | if (!success) { |
| 4382 | mAppWidgetHost.deleteAppWidgetId(newWidgetId); |
| 4383 | if (DEBUG_WIDGETS) { |
| 4384 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4385 | + " belongs to component " + item.providerName |
| 4386 | + ", as the launcher is unable to bing a new widget id"); |
| 4387 | } |
| 4388 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4389 | return; |
| 4390 | } |
| 4391 | |
| 4392 | item.appWidgetId = newWidgetId; |
| 4393 | |
| 4394 | // If the widget has a configure activity, it is still needs to set it up, otherwise |
| 4395 | // the widget is ready to go. |
| 4396 | item.restoreStatus = (appWidgetInfo.configure == null) |
| 4397 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 4398 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 4399 | |
| 4400 | LauncherModel.updateItemInDatabase(this, item); |
| 4401 | } |
| 4402 | |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4403 | if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4404 | final int appWidgetId = item.appWidgetId; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4405 | if (DEBUG_WIDGETS) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4406 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " |
| 4407 | + appWidgetInfo.provider); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4408 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4409 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4410 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4411 | } else { |
| 4412 | appWidgetInfo = null; |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4413 | PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, |
| 4414 | mIsSafeModeEnabled); |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4415 | view.updateIcon(mIconCache); |
| 4416 | item.hostView = view; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4417 | item.hostView.updateAppWidget(null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4418 | item.hostView.setOnClickListener(this); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4419 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4420 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4421 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4422 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4423 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4424 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4425 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4426 | if (!item.isCustomWidget()) { |
| 4427 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4428 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4429 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4430 | workspace.requestLayout(); |
| 4431 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4432 | if (DEBUG_WIDGETS) { |
| 4433 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4434 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4435 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4436 | } |
| 4437 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4438 | /** |
| 4439 | * Restores a pending widget. |
| 4440 | * |
| 4441 | * @param appWidgetId The app widget id |
| 4442 | * @param cellInfo The position on screen where to create the widget. |
| 4443 | */ |
| 4444 | private void completeRestoreAppWidget(final int appWidgetId) { |
| 4445 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 4446 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 4447 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
| 4448 | return; |
| 4449 | } |
| 4450 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4451 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4452 | info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 4453 | |
| 4454 | mWorkspace.reinflateWidgetsIfNecessary(); |
| 4455 | LauncherModel.updateItemInDatabase(this, info); |
| 4456 | } |
| 4457 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4458 | public void onPageBoundSynchronously(int page) { |
| 4459 | mSynchronouslyBoundPages.add(page); |
| 4460 | } |
| 4461 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4462 | /** |
| 4463 | * Callback saying that there aren't any more items to bind. |
| 4464 | * |
| 4465 | * Implementation of the method from LauncherModel.Callbacks. |
| 4466 | */ |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4467 | public void finishBindingItems(final boolean upgradePath) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4468 | Runnable r = new Runnable() { |
| 4469 | public void run() { |
| 4470 | finishBindingItems(upgradePath); |
| 4471 | } |
| 4472 | }; |
| 4473 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4474 | return; |
| 4475 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4476 | if (mSavedState != null) { |
| 4477 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4478 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4479 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4480 | mSavedState = null; |
| 4481 | } |
| 4482 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4483 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4484 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4485 | setWorkspaceLoading(false); |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4486 | sendLoadingCompleteBroadcastIfNecessary(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 4487 | |
| 4488 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4489 | // widget configuration forced an orientation change), process them now. |
| 4490 | if (sPendingAddItem != null) { |
| 4491 | final long screenId = completeAdd(sPendingAddItem); |
| 4492 | |
| 4493 | // TODO: this moves the user to the page where the pending item was added. Ideally, |
| 4494 | // the screen would be guaranteed to exist after bind, and the page would be set through |
| 4495 | // the workspace restore process. |
| 4496 | mWorkspace.post(new Runnable() { |
| 4497 | @Override |
| 4498 | public void run() { |
| 4499 | mWorkspace.snapToScreenId(screenId); |
| 4500 | } |
| 4501 | }); |
| 4502 | sPendingAddItem = null; |
| 4503 | } |
| 4504 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4505 | if (upgradePath) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4506 | mWorkspace.getUniqueComponents(true, null); |
| 4507 | mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4508 | } |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4509 | PackageInstallerCompat.getInstance(this).onFinishBind(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4510 | |
| 4511 | if (mLauncherCallbacks != null) { |
| 4512 | mLauncherCallbacks.finishBindingItems(upgradePath); |
| 4513 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4516 | private void sendLoadingCompleteBroadcastIfNecessary() { |
| 4517 | if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) { |
| 4518 | String permission = |
| 4519 | getResources().getString(R.string.receive_first_load_broadcast_permission); |
| 4520 | Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE); |
| 4521 | sendBroadcast(intent, permission); |
| 4522 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4523 | editor.putBoolean(FIRST_LOAD_COMPLETE, true); |
| 4524 | editor.apply(); |
| 4525 | } |
| 4526 | } |
| 4527 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4528 | public boolean isAllAppsButtonRank(int rank) { |
| 4529 | if (mHotseat != null) { |
| 4530 | return mHotseat.isAllAppsButtonRank(rank); |
| 4531 | } |
| 4532 | return false; |
| 4533 | } |
| 4534 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4535 | private boolean canRunNewAppsAnimation() { |
| 4536 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4537 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4538 | } |
| 4539 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4540 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4541 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4542 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4543 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4544 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4545 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4546 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4547 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4548 | return bounceAnim; |
| 4549 | } |
| 4550 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4551 | public boolean useVerticalBarLayout() { |
| 4552 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4553 | getDeviceProfile().isVerticalBarLayout(); |
| 4554 | } |
| 4555 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4556 | protected Rect getSearchBarBounds() { |
| 4557 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4558 | getDeviceProfile().getSearchBarBounds(); |
| 4559 | } |
| 4560 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4561 | public void bindSearchablesChanged() { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 4562 | if (mSearchDropTargetBar == null) { |
| 4563 | return; |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4564 | } |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 4565 | if (mQsb != null) { |
| 4566 | mSearchDropTargetBar.removeView(mQsb); |
| 4567 | mQsb = null; |
| 4568 | } |
| 4569 | mSearchDropTargetBar.setQsbSearchBar(getQsbBar()); |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4570 | } |
| 4571 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4572 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4573 | * Add the icons for all apps. |
| 4574 | * |
| 4575 | * Implementation of the method from LauncherModel.Callbacks. |
| 4576 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4577 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4578 | if (LauncherAppState.isDisableAllApps()) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4579 | if (mIntentsOnWorkspaceFromUpgradePath != null) { |
| 4580 | if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) { |
| 4581 | getHotseat().addAllAppsFolder(mIconCache, apps, |
| 4582 | mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace); |
| 4583 | } |
| 4584 | mIntentsOnWorkspaceFromUpgradePath = null; |
Daniel Sandler | 8707e0f | 2013-08-15 15:54:18 -0700 | [diff] [blame] | 4585 | } |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4586 | if (mAppsCustomizeContent != null) { |
| 4587 | mAppsCustomizeContent.onPackagesUpdated( |
| 4588 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
| 4589 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4590 | } else { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 4591 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4592 | mAppsCustomizeContent.setApps(apps); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 4593 | mAppsCustomizeContent.onPackagesUpdated( |
| 4594 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4595 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4596 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4597 | if (mLauncherCallbacks != null) { |
| 4598 | mLauncherCallbacks.bindAllApplications(apps); |
| 4599 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | /** |
| 4603 | * A package was updated. |
| 4604 | * |
| 4605 | * Implementation of the method from LauncherModel.Callbacks. |
| 4606 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4607 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4608 | Runnable r = new Runnable() { |
| 4609 | public void run() { |
| 4610 | bindAppsUpdated(apps); |
| 4611 | } |
| 4612 | }; |
| 4613 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4614 | return; |
| 4615 | } |
| 4616 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4617 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4618 | mAppsCustomizeContent != null) { |
| 4619 | mAppsCustomizeContent.updateApps(apps); |
| 4620 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4621 | } |
| 4622 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4623 | @Override |
| 4624 | public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) { |
| 4625 | Runnable r = new Runnable() { |
| 4626 | public void run() { |
| 4627 | bindWidgetsRestored(widgets); |
| 4628 | } |
| 4629 | }; |
| 4630 | if (waitUntilResume(r)) { |
| 4631 | return; |
| 4632 | } |
| 4633 | mWorkspace.widgetsRestored(widgets); |
| 4634 | } |
| 4635 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4636 | /** |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4637 | * Some shortcuts were updated in the background. |
| 4638 | * |
| 4639 | * Implementation of the method from LauncherModel.Callbacks. |
| 4640 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4641 | @Override |
| 4642 | public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated, |
| 4643 | final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4644 | Runnable r = new Runnable() { |
| 4645 | public void run() { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4646 | bindShortcutsChanged(updated, removed, user); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4647 | } |
| 4648 | }; |
| 4649 | if (waitUntilResume(r)) { |
| 4650 | return; |
| 4651 | } |
| 4652 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4653 | if (!updated.isEmpty()) { |
| 4654 | mWorkspace.updateShortcuts(updated); |
| 4655 | } |
| 4656 | |
| 4657 | if (!removed.isEmpty()) { |
| 4658 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 4659 | for (ShortcutInfo si : removed) { |
| 4660 | removedComponents.add(si.getTargetComponent()); |
| 4661 | } |
| 4662 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
| 4663 | // Notify the drag controller |
| 4664 | mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4669 | * Update the state of a package, typically related to install state. |
| 4670 | * |
| 4671 | * Implementation of the method from LauncherModel.Callbacks. |
| 4672 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4673 | @Override |
| 4674 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4675 | if (mWorkspace != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4676 | mWorkspace.updatePackageState(installInfo); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | /** |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 4681 | * Update the label and icon of all the icons in a package |
| 4682 | * |
| 4683 | * Implementation of the method from LauncherModel.Callbacks. |
| 4684 | */ |
| 4685 | @Override |
| 4686 | public void updatePackageBadge(String packageName) { |
| 4687 | if (mWorkspace != null) { |
| 4688 | mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle()); |
| 4689 | } |
| 4690 | } |
| 4691 | |
| 4692 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4693 | * A package was uninstalled. We take both the super set of packageNames |
| 4694 | * in addition to specific applications to remove, the reason being that |
| 4695 | * this can be called when a package is updated as well. In that scenario, |
| 4696 | * we only remove specific components from the workspace, where as |
| 4697 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4698 | * |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4699 | * @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] | 4700 | * Implementation of the method from LauncherModel.Callbacks. |
| 4701 | */ |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4702 | @Override |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4703 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4704 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4705 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4706 | public void run() { |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4707 | bindComponentsRemoved(packageNames, appInfos, user, reason); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4708 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4709 | }; |
| 4710 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4711 | return; |
| 4712 | } |
| 4713 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4714 | if (reason == 0) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4715 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 4716 | for (AppInfo info : appInfos) { |
| 4717 | removedComponents.add(info.componentName); |
| 4718 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4719 | if (!packageNames.isEmpty()) { |
| 4720 | mWorkspace.removeItemsByPackageName(packageNames, user); |
| 4721 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4722 | if (!removedComponents.isEmpty()) { |
| 4723 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4724 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4725 | // Notify the drag controller |
| 4726 | mDragController.onAppsRemoved(packageNames, removedComponents); |
| 4727 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4728 | } else { |
| 4729 | mWorkspace.disableShortcutsByPackageName(packageNames, user, reason); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 4730 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4731 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4732 | // Update AllApps |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4733 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4734 | mAppsCustomizeContent != null) { |
| 4735 | mAppsCustomizeContent.removeApps(appInfos); |
| 4736 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4737 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4738 | |
| 4739 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4740 | * A number of packages were updated. |
| 4741 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4742 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 4743 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4744 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4745 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 4746 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4747 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4748 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4749 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 4750 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 4751 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4752 | return; |
| 4753 | } |
| 4754 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4755 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4756 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4757 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4758 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4759 | } |
| 4760 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4761 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 4762 | final Display d = getWindowManager().getDefaultDisplay(); |
| 4763 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 4764 | switch (d.getRotation()) { |
| 4765 | case Surface.ROTATION_0: |
| 4766 | case Surface.ROTATION_180: |
| 4767 | // We are currently in the same basic orientation as the natural orientation |
| 4768 | naturalOri = configOri; |
| 4769 | break; |
| 4770 | case Surface.ROTATION_90: |
| 4771 | case Surface.ROTATION_270: |
| 4772 | // We are currently in the other basic orientation to the natural orientation |
| 4773 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 4774 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 4775 | break; |
| 4776 | } |
| 4777 | |
| 4778 | int[] oriMap = { |
| 4779 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 4780 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 4781 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 4782 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 4783 | }; |
| 4784 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 4785 | // is landscape. |
| 4786 | int indexOffset = 0; |
| 4787 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 4788 | indexOffset = 1; |
| 4789 | } |
| 4790 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 4791 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 4792 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4793 | public void lockScreenOrientation() { |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 4794 | if (Utilities.isRotationEnabled(this)) { |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4795 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 4796 | .getConfiguration().orientation)); |
| 4797 | } |
| 4798 | } |
| 4799 | public void unlockScreenOrientation(boolean immediate) { |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 4800 | if (Utilities.isRotationEnabled(this)) { |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4801 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4802 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4803 | } else { |
| 4804 | mHandler.postDelayed(new Runnable() { |
| 4805 | public void run() { |
| 4806 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 4807 | } |
| 4808 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4809 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4810 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4811 | } |
| 4812 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4813 | protected boolean isLauncherPreinstalled() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4814 | if (mLauncherCallbacks != null) { |
| 4815 | return mLauncherCallbacks.isLauncherPreinstalled(); |
| 4816 | } |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4817 | PackageManager pm = getPackageManager(); |
| 4818 | try { |
| 4819 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 4820 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4821 | return true; |
| 4822 | } else { |
| 4823 | return false; |
| 4824 | } |
| 4825 | } catch (NameNotFoundException e) { |
| 4826 | e.printStackTrace(); |
| 4827 | return false; |
| 4828 | } |
| 4829 | } |
| 4830 | |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4831 | /** |
| 4832 | * This method indicates whether or not we should suggest default wallpaper dimensions |
| 4833 | * when our wallpaper cropper was not yet used to set a wallpaper. |
| 4834 | */ |
| 4835 | protected boolean overrideWallpaperDimensions() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4836 | if (mLauncherCallbacks != null) { |
| 4837 | return mLauncherCallbacks.overrideWallpaperDimensions(); |
| 4838 | } |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4839 | return true; |
| 4840 | } |
| 4841 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4842 | /** |
| 4843 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 4844 | * before showing the standard launcher experience. |
| 4845 | */ |
| 4846 | protected boolean hasFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4847 | if (mLauncherCallbacks != null) { |
| 4848 | return mLauncherCallbacks.hasFirstRunActivity(); |
| 4849 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4850 | return false; |
| 4851 | } |
| 4852 | |
| 4853 | /** |
| 4854 | * To be overridden by subclasses to launch any first run activity |
| 4855 | */ |
| 4856 | protected Intent getFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4857 | if (mLauncherCallbacks != null) { |
| 4858 | return mLauncherCallbacks.getFirstRunActivity(); |
| 4859 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4860 | return null; |
| 4861 | } |
| 4862 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4863 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4864 | return !ActivityManager.isRunningInTestHarness() && |
| 4865 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4866 | } |
| 4867 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 4868 | protected boolean hasRunFirstRunActivity() { |
| 4869 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 4870 | } |
| 4871 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4872 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4873 | if (shouldRunFirstRunActivity() && |
| 4874 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4875 | Intent firstRunIntent = getFirstRunActivity(); |
| 4876 | if (firstRunIntent != null) { |
| 4877 | startActivity(firstRunIntent); |
| 4878 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4879 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4880 | } |
| 4881 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4882 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | private void markFirstRunActivityShown() { |
| 4886 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4887 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 4888 | editor.apply(); |
| 4889 | } |
| 4890 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4891 | /** |
| 4892 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 4893 | * screen that must be displayed and dismissed. |
| 4894 | */ |
| 4895 | protected boolean hasDismissableIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4896 | if (mLauncherCallbacks != null) { |
| 4897 | return mLauncherCallbacks.hasDismissableIntroScreen(); |
| 4898 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4899 | return false; |
| 4900 | } |
| 4901 | |
| 4902 | /** |
| 4903 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 4904 | */ |
| 4905 | protected View getIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4906 | if (mLauncherCallbacks != null) { |
| 4907 | return mLauncherCallbacks.getIntroScreen(); |
| 4908 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4909 | return null; |
| 4910 | } |
| 4911 | |
| 4912 | /** |
| 4913 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 4914 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 4915 | */ |
| 4916 | private boolean shouldShowIntroScreen() { |
| 4917 | return hasDismissableIntroScreen() && |
| 4918 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 4919 | } |
| 4920 | |
| 4921 | protected void showIntroScreen() { |
| 4922 | View introScreen = getIntroScreen(); |
| 4923 | changeWallpaperVisiblity(false); |
| 4924 | if (introScreen != null) { |
| 4925 | mDragLayer.showOverlayView(introScreen); |
| 4926 | } |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 4927 | if (mLauncherOverlayContainer != null) { |
| 4928 | mLauncherOverlayContainer.setVisibility(View.INVISIBLE); |
| 4929 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | public void dismissIntroScreen() { |
| 4933 | markIntroScreenDismissed(); |
| 4934 | if (showFirstRunActivity()) { |
| 4935 | // We delay hiding the intro view until the first run activity is showing. This |
| 4936 | // avoids a blip. |
| 4937 | mWorkspace.postDelayed(new Runnable() { |
| 4938 | @Override |
| 4939 | public void run() { |
| 4940 | mDragLayer.dismissOverlayView(); |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 4941 | if (mLauncherOverlayContainer != null) { |
| 4942 | mLauncherOverlayContainer.setVisibility(View.VISIBLE); |
| 4943 | } |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 4944 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4945 | } |
| 4946 | }, ACTIVITY_START_DELAY); |
| 4947 | } else { |
| 4948 | mDragLayer.dismissOverlayView(); |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 4949 | if (mLauncherOverlayContainer != null) { |
| 4950 | mLauncherOverlayContainer.setVisibility(View.VISIBLE); |
| 4951 | } |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 4952 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4953 | } |
| 4954 | changeWallpaperVisiblity(true); |
| 4955 | } |
| 4956 | |
| 4957 | private void markIntroScreenDismissed() { |
| 4958 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4959 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 4960 | editor.apply(); |
| 4961 | } |
| 4962 | |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 4963 | private void showFirstRunClings() { |
| 4964 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 4965 | // on the device, then we always show the first run cling experience (or if there is no |
| 4966 | // launcher2). Otherwise, we prompt the user upon started for migration |
| 4967 | LauncherClings launcherClings = new LauncherClings(this); |
| 4968 | if (launcherClings.shouldShowFirstRunOrMigrationClings()) { |
| 4969 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
| 4970 | launcherClings.showMigrationCling(); |
| 4971 | } else { |
Sunny Goyal | af0628f | 2014-09-19 10:14:48 -0700 | [diff] [blame] | 4972 | launcherClings.showLongPressCling(true); |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 4973 | } |
| 4974 | } |
| 4975 | } |
| 4976 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4977 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4978 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 4979 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 4980 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 4981 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4982 | } |
| 4983 | |
| 4984 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4985 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 4986 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 4987 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 4988 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4989 | } |
| 4990 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4991 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4992 | // Called from search suggestion, not supported in other profiles. |
| 4993 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 4994 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 4995 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 4996 | myUser); |
| 4997 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4998 | return null; |
| 4999 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5000 | return new AppInfo(this, activityInfo, myUser, mIconCache, null); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5001 | } |
| 5002 | |
| 5003 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5004 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5005 | // Called from search suggestion, not supported in other profiles. |
| 5006 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 5007 | UserHandleCompat.myUserHandle()); |
| 5008 | } |
| 5009 | |
| 5010 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5011 | Bitmap icon, UserHandleCompat user) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5012 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 5013 | CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5014 | return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5015 | } |
| 5016 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 5017 | protected void moveWorkspaceToDefaultScreen() { |
| 5018 | mWorkspace.moveToDefaultScreen(false); |
| 5019 | } |
| 5020 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5021 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 5022 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 5023 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 5024 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5025 | } |
| 5026 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5027 | @Override |
| 5028 | public void onPageSwitch(View newPage, int newPageIndex) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5029 | if (mLauncherCallbacks != null) { |
| 5030 | mLauncherCallbacks.onPageSwitch(newPage, newPageIndex); |
| 5031 | } |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5032 | } |
| 5033 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5034 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5035 | * Prints out out state for debugging. |
| 5036 | */ |
| 5037 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5038 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5039 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5040 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 5041 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 5042 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 5043 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 5044 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5045 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5046 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5047 | if (mAppsCustomizeContent != null) { |
| 5048 | mAppsCustomizeContent.dumpState(); |
| 5049 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5050 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5051 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5052 | |
| 5053 | @Override |
| 5054 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5055 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5056 | synchronized (sDumpLogs) { |
| 5057 | writer.println(" "); |
| 5058 | writer.println("Debug logs: "); |
| 5059 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5060 | writer.println(" " + sDumpLogs.get(i)); |
| 5061 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5062 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5063 | if (mLauncherCallbacks != null) { |
| 5064 | mLauncherCallbacks.dump(prefix, fd, writer, args); |
| 5065 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5066 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5067 | |
| 5068 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5069 | if (DEBUG_DUMP_LOG) { |
| 5070 | synchronized (sDumpLogs) { |
| 5071 | Log.d(TAG, ""); |
| 5072 | Log.d(TAG, "*********************"); |
| 5073 | Log.d(TAG, "Launcher debug logs: "); |
| 5074 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5075 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 5076 | } |
| 5077 | Log.d(TAG, "*********************"); |
| 5078 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5079 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5080 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
| 5083 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5084 | addDumpLog(tag, log, null, debugLog); |
| 5085 | } |
| 5086 | |
| 5087 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5088 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5089 | if (e != null) { |
| 5090 | Log.d(tag, log, e); |
| 5091 | } else { |
| 5092 | Log.d(tag, log); |
| 5093 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5094 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5095 | if (DEBUG_DUMP_LOG) { |
| 5096 | sDateStamp.setTime(System.currentTimeMillis()); |
| 5097 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5098 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 5099 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5100 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5101 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 5104 | public static CustomAppWidget getCustomAppWidget(String name) { |
| 5105 | return sCustomAppWidgets.get(name); |
| 5106 | } |
| 5107 | |
| 5108 | public static HashMap<String, CustomAppWidget> getCustomAppWidgets() { |
| 5109 | return sCustomAppWidgets; |
| 5110 | } |
| 5111 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5112 | public void dumpLogsToLocalData() { |
| 5113 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5114 | new AsyncTask<Void, Void, Void>() { |
| 5115 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5116 | boolean success = false; |
| 5117 | sDateStamp.setTime(sRunStart); |
| 5118 | String FILENAME = sDateStamp.getMonth() + "-" |
| 5119 | + sDateStamp.getDay() + "_" |
| 5120 | + sDateStamp.getHours() + "-" |
| 5121 | + sDateStamp.getMinutes() + "_" |
| 5122 | + sDateStamp.getSeconds() + ".txt"; |
| 5123 | |
| 5124 | FileOutputStream fos = null; |
| 5125 | File outFile = null; |
| 5126 | try { |
| 5127 | outFile = new File(getFilesDir(), FILENAME); |
| 5128 | outFile.createNewFile(); |
| 5129 | fos = new FileOutputStream(outFile); |
| 5130 | } catch (Exception e) { |
| 5131 | e.printStackTrace(); |
| 5132 | } |
| 5133 | if (fos != null) { |
| 5134 | PrintWriter writer = new PrintWriter(fos); |
| 5135 | |
| 5136 | writer.println(" "); |
| 5137 | writer.println("Debug logs: "); |
| 5138 | synchronized (sDumpLogs) { |
| 5139 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5140 | writer.println(" " + sDumpLogs.get(i)); |
| 5141 | } |
| 5142 | } |
| 5143 | writer.close(); |
| 5144 | } |
| 5145 | try { |
| 5146 | if (fos != null) { |
| 5147 | fos.close(); |
| 5148 | success = true; |
| 5149 | } |
| 5150 | } catch (IOException e) { |
| 5151 | e.printStackTrace(); |
| 5152 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5153 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5154 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5155 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5156 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5157 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5158 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5159 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 5160 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 5161 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 5162 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5163 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 5164 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5165 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5166 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 5167 | |
| 5168 | interface DebugIntents { |
| 5169 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 5170 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 5171 | } |