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