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; |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 45 | import android.content.IntentSender; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 46 | import android.content.SharedPreferences; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 47 | import android.content.pm.ActivityInfo; |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 48 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 49 | import android.content.pm.PackageManager; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 50 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 51 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 52 | import android.content.res.Resources; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 53 | import android.database.ContentObserver; |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 54 | import android.database.sqlite.SQLiteDatabase; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 55 | import android.graphics.Bitmap; |
| 56 | import android.graphics.Canvas; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame] | 57 | import android.graphics.Color; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 58 | import android.graphics.PorterDuff; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 59 | import android.graphics.Rect; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 60 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 61 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 62 | import android.os.AsyncTask; |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 63 | import android.os.Build; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 64 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 65 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 66 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 67 | import android.os.Message; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 68 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 69 | import android.os.SystemClock; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | import android.text.Selection; |
| 71 | import android.text.SpannableStringBuilder; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 72 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 73 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 74 | import android.util.Log; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 75 | import android.view.Display; |
| 76 | import android.view.Gravity; |
| 77 | import android.view.HapticFeedbackConstants; |
| 78 | import android.view.KeyEvent; |
| 79 | import android.view.LayoutInflater; |
| 80 | import android.view.Menu; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 81 | import android.view.MotionEvent; |
| 82 | import android.view.Surface; |
| 83 | import android.view.View; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 84 | import android.view.View.OnClickListener; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 85 | import android.view.View.OnLongClickListener; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 86 | import android.view.ViewAnimationUtils; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 87 | import android.view.ViewGroup; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 88 | import android.view.ViewStub; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 89 | import android.view.ViewTreeObserver; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 90 | import android.view.Window; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 91 | import android.view.WindowManager; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 92 | import android.view.accessibility.AccessibilityEvent; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 93 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 94 | import android.view.animation.DecelerateInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 95 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 96 | import android.widget.Advanceable; |
| 97 | import android.widget.FrameLayout; |
| 98 | import android.widget.ImageView; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 99 | import android.widget.Toast; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 100 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 101 | import com.android.launcher3.DropTarget.DragObject; |
| 102 | import com.android.launcher3.PagedView.PageSwitchListener; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 103 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 104 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 105 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 106 | import com.android.launcher3.compat.PackageInstallerCompat; |
| 107 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 108 | import com.android.launcher3.compat.UserHandleCompat; |
| 109 | import com.android.launcher3.compat.UserManagerCompat; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 110 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 111 | import java.io.DataInputStream; |
| 112 | import java.io.DataOutputStream; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 113 | import java.io.File; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 114 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 115 | import java.io.FileNotFoundException; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 116 | import java.io.FileOutputStream; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 117 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 118 | import java.io.PrintWriter; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 119 | import java.lang.reflect.Field; |
| 120 | import java.lang.reflect.InvocationTargetException; |
| 121 | import java.lang.reflect.Method; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 122 | import java.text.DateFormat; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 123 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 124 | import java.util.Collection; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 125 | import java.util.Date; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 126 | import java.util.HashMap; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 127 | import java.util.HashSet; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 128 | import java.util.List; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 129 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 130 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 131 | /** |
| 132 | * Default launcher application. |
| 133 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 134 | public class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 135 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 136 | View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 137 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 138 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 139 | |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 140 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 141 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 142 | static final boolean DEBUG_STRICT_MODE = false; |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 143 | static final boolean DEBUG_RESUME_TIME = false; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_DUMP_LOG = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 145 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 146 | static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run |
| 147 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 148 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 149 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 150 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 151 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 152 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 154 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 155 | private static final int REQUEST_RECONFIGURE_APPWIDGET = 12; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 156 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 157 | /** |
| 158 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 159 | * request codes used internally. |
| 160 | */ |
| 161 | protected static final int REQUEST_LAST = 100; |
| 162 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 163 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 164 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 165 | static final int SCREEN_COUNT = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 166 | |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 167 | // To turn on these properties, type |
| 168 | // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS] |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 169 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 170 | static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 171 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 172 | // The Intent extra that defines whether to ignore the launch animation |
| 173 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 174 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 175 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 176 | // Type: int |
| 177 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 178 | // Type: int |
| 179 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 180 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 181 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 182 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 183 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 184 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 185 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 186 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 187 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 188 | // Type: boolean |
| 189 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 190 | // Type: long |
| 191 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 192 | // Type: int |
| 193 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 194 | // Type: int |
| 195 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 196 | // Type: parcelable |
| 197 | private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info"; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 198 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 199 | private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id"; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 200 | // Type: int[] |
| 201 | private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 202 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 203 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 204 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 205 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 206 | static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete"; |
| 207 | static final String ACTION_FIRST_LOAD_COMPLETE = |
| 208 | "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; |
| 209 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 210 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 211 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 212 | |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 213 | private static final String QSB_WIDGET_ID = "qsb_widget_id"; |
| 214 | private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider"; |
| 215 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 216 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 217 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 218 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 219 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 220 | private State mState = State.WORKSPACE; |
| 221 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 222 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 223 | private boolean mIsSafeModeEnabled; |
| 224 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 225 | LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl(); |
| 226 | LauncherOverlay mLauncherOverlay; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 227 | InsettableFrameLayout mLauncherOverlayContainer; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 228 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 229 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 230 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 231 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 232 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 233 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 234 | private static final Object sLock = new Object(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 235 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 236 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 237 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 238 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 239 | // 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] | 240 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 241 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 242 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 243 | private static final int SINGLE_FRAME_DELAY = 16; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 244 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 245 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 246 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 247 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 248 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 249 | private LayoutInflater mInflater; |
| 250 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 251 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 252 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 253 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 254 | private DragLayer mDragLayer; |
| 255 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 256 | private View mWeightWatcher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 257 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 258 | private AppWidgetManagerCompat mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 259 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 260 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 261 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 262 | private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 263 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 264 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 265 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 266 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 267 | private FolderInfo mFolderInfo; |
| 268 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 269 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 270 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 271 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 272 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 273 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 274 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 275 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 276 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 277 | private boolean mAutoAdvanceRunning = false; |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 278 | private AppWidgetHostView mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 279 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 280 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 281 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 282 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 283 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 284 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 285 | |
| 286 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 287 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 288 | private boolean mWorkspaceLoading = true; |
| 289 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 290 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 291 | private boolean mRestoring; |
| 292 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 293 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 294 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 295 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 296 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 297 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 298 | private Bundle mSavedInstanceState; |
| 299 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 300 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 301 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 302 | private boolean mUserPresent = true; |
| 303 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 304 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 305 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 306 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 307 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 308 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 309 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 310 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 311 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 312 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 313 | public static final int BUILD_LAYER = 0; |
| 314 | public static final int BUILD_AND_SET_LAYER = 1; |
| 315 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 316 | // Related to the auto-advancing of widgets |
| 317 | private final int ADVANCE_MSG = 1; |
| 318 | private final int mAdvanceInterval = 20000; |
| 319 | private final int mAdvanceStagger = 250; |
| 320 | private long mAutoAdvanceSentTime; |
| 321 | private long mAutoAdvanceTimeLeft = -1; |
| 322 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 323 | new HashMap<View, AppWidgetProviderInfo>(); |
| 324 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 325 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 326 | // match the sensor state. |
| 327 | private final int mRestoreScreenOrientationDelay = 500; |
| 328 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 329 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 330 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 331 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 332 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 333 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 334 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 335 | static Date sDateStamp = new Date(); |
| 336 | static DateFormat sDateFormat = |
| 337 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 338 | static long sRunStart = System.currentTimeMillis(); |
| 339 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 340 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 341 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 342 | // it from the context. |
| 343 | private SharedPreferences mSharedPrefs; |
| 344 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 345 | private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null; |
| 346 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 347 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 348 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 349 | private ImageView mFolderIconImageView; |
| 350 | private Bitmap mFolderIconBitmap; |
| 351 | private Canvas mFolderIconCanvas; |
| 352 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 353 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 354 | private BubbleTextView mWaitingForResume; |
| 355 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 356 | protected static HashMap<String, CustomAppWidget> sCustomAppWidgets = |
| 357 | new HashMap<String, CustomAppWidget>(); |
| 358 | |
| 359 | private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false; |
| 360 | static { |
| 361 | if (ENABLE_CUSTOM_WIDGET_TEST) { |
| 362 | sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget()); |
| 363 | } |
| 364 | } |
| 365 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 366 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 367 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 368 | if (mWorkspace != null) { |
| 369 | mWorkspace.buildPageHardwareLayers(); |
| 370 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 371 | } |
| 372 | }; |
| 373 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 374 | private static PendingAddArguments sPendingAddItem; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 375 | |
| 376 | private static class PendingAddArguments { |
| 377 | int requestCode; |
| 378 | Intent intent; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 379 | long container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 380 | long screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 381 | int cellX; |
| 382 | int cellY; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 383 | int appWidgetId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 386 | private Stats mStats; |
| 387 | |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 388 | FocusIndicatorView mFocusHandler; |
| 389 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 390 | @Override |
| 391 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 392 | if (DEBUG_STRICT_MODE) { |
| 393 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 394 | .detectDiskReads() |
| 395 | .detectDiskWrites() |
| 396 | .detectNetwork() // or .detectAll() for all detectable problems |
| 397 | .penaltyLog() |
| 398 | .build()); |
| 399 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 400 | .detectLeakedSqlLiteObjects() |
| 401 | .detectLeakedClosableObjects() |
| 402 | .penaltyLog() |
| 403 | .penaltyDeath() |
| 404 | .build()); |
| 405 | } |
| 406 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 407 | if (mLauncherCallbacks != null) { |
| 408 | mLauncherCallbacks.preOnCreate(); |
| 409 | } |
| 410 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 411 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 412 | |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 413 | LauncherAppState.setApplicationContext(getApplicationContext()); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 414 | LauncherAppState app = LauncherAppState.getInstance(); |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 415 | LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 416 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 417 | // Lazy-initialize the dynamic grid |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 418 | DeviceProfile grid = app.initDynamicGrid(this); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 419 | |
| 420 | // 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] | 421 | mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 422 | Context.MODE_PRIVATE); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 423 | mIsSafeModeEnabled = getPackageManager().isSafeMode(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 424 | mModel = app.setLauncher(this); |
| 425 | mIconCache = app.getIconCache(); |
Winson Chung | e5467dc | 2013-10-14 17:03:04 -0700 | [diff] [blame] | 426 | mIconCache.flushInvalidIcons(grid); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 427 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 428 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 429 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 430 | mStats = new Stats(this); |
| 431 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 432 | mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 433 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 434 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 435 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 436 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 437 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 438 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 439 | // LauncherModel load. |
| 440 | mPaused = false; |
| 441 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 442 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 443 | android.os.Debug.startMethodTracing( |
| 444 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 448 | setContentView(R.layout.launcher); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 449 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 450 | setupViews(); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 451 | grid.layout(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 452 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 453 | registerContentObservers(); |
| 454 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 455 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 456 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 457 | mSavedState = savedInstanceState; |
| 458 | restoreState(mSavedState); |
| 459 | |
| 460 | if (PROFILE_STARTUP) { |
| 461 | android.os.Debug.stopMethodTracing(); |
| 462 | } |
| 463 | |
| 464 | if (!mRestoring) { |
Adam Cohen | db78dc8 | 2014-06-19 14:50:51 -0700 | [diff] [blame] | 465 | if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 466 | // If the user leaves launcher, then we should just load items asynchronously when |
| 467 | // they return. |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 468 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 469 | } else { |
| 470 | // We only load the page synchronously if the user rotates (or triggers a |
| 471 | // configuration change) while launcher is in the foreground |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 472 | mModel.startLoader(true, mWorkspace.getRestorePage()); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 473 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | // For handling default keys |
| 477 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 478 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 479 | |
| 480 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 481 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 482 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 483 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 484 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 485 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 486 | if (mLauncherCallbacks != null) { |
| 487 | mLauncherCallbacks.onCreate(savedInstanceState); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 488 | if (mLauncherCallbacks.hasLauncherOverlay()) { |
| 489 | ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub); |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 490 | mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate(); |
| 491 | mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView( |
| 492 | mLauncherOverlayContainer, mLauncherOverlayCallbacks); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 493 | mWorkspace.setLauncherOverlay(mLauncherOverlay); |
| 494 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 495 | } |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 496 | |
| 497 | if (shouldShowIntroScreen()) { |
| 498 | showIntroScreen(); |
| 499 | } else { |
| 500 | showFirstRunActivity(); |
| 501 | showFirstRunClings(); |
| 502 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | private LauncherCallbacks mLauncherCallbacks; |
| 506 | |
| 507 | public void onPostCreate(Bundle savedInstanceState) { |
| 508 | super.onPostCreate(savedInstanceState); |
| 509 | if (mLauncherCallbacks != null) { |
| 510 | mLauncherCallbacks.onPostCreate(savedInstanceState); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { |
| 515 | mLauncherCallbacks = callbacks; |
| 516 | return true; |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 519 | @Override |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 520 | public void onLauncherProviderChange() { |
| 521 | if (mLauncherCallbacks != null) { |
| 522 | mLauncherCallbacks.onLauncherProviderChange(); |
| 523 | } |
| 524 | } |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 525 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 526 | /** 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] | 527 | protected boolean hasCustomContentToLeft() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 528 | if (mLauncherCallbacks != null) { |
| 529 | return mLauncherCallbacks.hasCustomContentToLeft(); |
| 530 | } |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 531 | return false; |
| 532 | } |
| 533 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 534 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 535 | * 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] | 536 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 537 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 538 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 539 | protected void populateCustomContentContainer() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 540 | if (mLauncherCallbacks != null) { |
| 541 | mLauncherCallbacks.populateCustomContentContainer(); |
| 542 | } |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 547 | * ensure the custom content page is added or removed if necessary. |
| 548 | */ |
| 549 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 550 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 551 | // Not bound yet, wait for bindScreens to be called. |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 556 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 557 | mWorkspace.createCustomContentContainer(); |
| 558 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 559 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 560 | mWorkspace.removeCustomContentPage(); |
| 561 | } |
| 562 | } |
| 563 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 564 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 565 | if (sLocaleConfiguration == null) { |
| 566 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 567 | @Override |
| 568 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 569 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 570 | readConfiguration(Launcher.this, localeConfiguration); |
| 571 | return localeConfiguration; |
| 572 | } |
| 573 | |
| 574 | @Override |
| 575 | protected void onPostExecute(LocaleConfiguration result) { |
| 576 | sLocaleConfiguration = result; |
| 577 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 578 | } |
| 579 | }.execute(); |
| 580 | return; |
| 581 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 582 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 583 | final Configuration configuration = getResources().getConfiguration(); |
| 584 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 585 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 586 | final String locale = configuration.locale.toString(); |
| 587 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 588 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 589 | final int mcc = configuration.mcc; |
| 590 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 591 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 592 | final int mnc = configuration.mnc; |
| 593 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 594 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 595 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 596 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 597 | sLocaleConfiguration.locale = locale; |
| 598 | sLocaleConfiguration.mcc = mcc; |
| 599 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 600 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 601 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 602 | |
| 603 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 604 | new AsyncTask<Void, Void, Void>() { |
| 605 | public Void doInBackground(Void ... args) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 606 | writeConfiguration(Launcher.this, localeConfiguration); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 607 | return null; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 608 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 609 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
| 613 | private static class LocaleConfiguration { |
| 614 | public String locale; |
| 615 | public int mcc = -1; |
| 616 | public int mnc = -1; |
| 617 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 618 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 619 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 620 | DataInputStream in = null; |
| 621 | try { |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 622 | in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 623 | configuration.locale = in.readUTF(); |
| 624 | configuration.mcc = in.readInt(); |
| 625 | configuration.mnc = in.readInt(); |
| 626 | } catch (FileNotFoundException e) { |
| 627 | // Ignore |
| 628 | } catch (IOException e) { |
| 629 | // Ignore |
| 630 | } finally { |
| 631 | if (in != null) { |
| 632 | try { |
| 633 | in.close(); |
| 634 | } catch (IOException e) { |
| 635 | // Ignore |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 642 | DataOutputStream out = null; |
| 643 | try { |
Helena Josol | 4fbbb3e | 2014-10-06 16:06:46 +0100 | [diff] [blame] | 644 | out = new DataOutputStream(context.openFileOutput( |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 645 | LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 646 | out.writeUTF(configuration.locale); |
| 647 | out.writeInt(configuration.mcc); |
| 648 | out.writeInt(configuration.mnc); |
| 649 | out.flush(); |
| 650 | } catch (FileNotFoundException e) { |
| 651 | // Ignore |
| 652 | } catch (IOException e) { |
| 653 | //noinspection ResultOfMethodCallIgnored |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 654 | context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 655 | } finally { |
| 656 | if (out != null) { |
| 657 | try { |
| 658 | out.close(); |
| 659 | } catch (IOException e) { |
| 660 | // Ignore |
| 661 | } |
| 662 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 666 | public Stats getStats() { |
| 667 | return mStats; |
| 668 | } |
| 669 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 670 | public LayoutInflater getInflater() { |
| 671 | return mInflater; |
| 672 | } |
| 673 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 674 | boolean isDraggingEnabled() { |
| 675 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 676 | // that is subsequently removed from the workspace in startBinding(). |
| 677 | return !mModel.isLoadingWorkspace(); |
| 678 | } |
| 679 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 680 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 681 | public static int generateViewId() { |
Ian Parkinson | 0c2918f | 2014-10-06 14:24:31 +0100 | [diff] [blame] | 682 | if (Build.VERSION.SDK_INT >= 17) { |
| 683 | return View.generateViewId(); |
| 684 | } else { |
| 685 | // View.generateViewId() is not available. The following fallback logic is a copy |
| 686 | // of its implementation. |
| 687 | for (;;) { |
| 688 | final int result = sNextGeneratedId.get(); |
| 689 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 690 | int newValue = result + 1; |
| 691 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 692 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 693 | return result; |
| 694 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | public int getViewIdForItem(ItemInfo info) { |
| 700 | // This cast is safe given the > 2B range for int. |
| 701 | int itemId = (int) info.id; |
| 702 | if (mItemIdToViewId.containsKey(itemId)) { |
| 703 | return mItemIdToViewId.get(itemId); |
| 704 | } |
| 705 | int viewId = generateViewId(); |
| 706 | mItemIdToViewId.put(itemId, viewId); |
| 707 | return viewId; |
| 708 | } |
| 709 | |
| 710 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 711 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 712 | * a configuration step, this allows the proper animations to run after other transitions. |
| 713 | */ |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 714 | private long completeAdd(PendingAddArguments args) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 715 | long screenId = args.screenId; |
| 716 | if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 717 | // When the screen id represents an actual screen (as opposed to a rank) we make sure |
| 718 | // that the drop page actually exists. |
| 719 | screenId = ensurePendingDropLayoutExists(args.screenId); |
| 720 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 721 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 722 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 723 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 724 | completeAddShortcut(args.intent, args.container, screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 725 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 726 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 727 | case REQUEST_CREATE_APPWIDGET: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 728 | completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 729 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 730 | case REQUEST_RECONFIGURE_APPWIDGET: |
| 731 | completeRestoreAppWidget(args.appWidgetId); |
| 732 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 733 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 734 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 735 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 736 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 737 | resetAddInfo(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 738 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 741 | private void handleActivityResult( |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 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) { |
Sunny Goyal | 8f9a787 | 2015-01-16 16:14:29 -0800 | [diff] [blame] | 764 | addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 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 | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 874 | |
| 875 | } |
| 876 | |
| 877 | @Override |
| 878 | protected void onActivityResult( |
| 879 | final int requestCode, final int resultCode, final Intent data) { |
| 880 | handleActivityResult(requestCode, resultCode, data); |
| 881 | if (mLauncherCallbacks != null) { |
| 882 | mLauncherCallbacks.onActivityResult(requestCode, resultCode, data); |
| 883 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 884 | } |
| 885 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 886 | private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int |
| 887 | appWidgetId, ItemInfo info) { |
| 888 | PendingAddArguments args = new PendingAddArguments(); |
| 889 | args.requestCode = requestCode; |
| 890 | args.intent = data; |
| 891 | args.container = info.container; |
| 892 | args.screenId = info.screenId; |
| 893 | args.cellX = info.cellX; |
| 894 | args.cellY = info.cellY; |
| 895 | args.appWidgetId = appWidgetId; |
| 896 | return args; |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 901 | * |
| 902 | * @param screenId the screen id to check |
| 903 | * @return the new screen, or screenId if it exists |
| 904 | */ |
| 905 | private long ensurePendingDropLayoutExists(long screenId) { |
| 906 | CellLayout dropLayout = |
| 907 | (CellLayout) mWorkspace.getScreenWithId(screenId); |
| 908 | if (dropLayout == null) { |
| 909 | // it's possible that the add screen was removed because it was |
| 910 | // empty and a re-bind occurred |
| 911 | mWorkspace.addExtraEmptyScreen(); |
| 912 | return mWorkspace.commitExtraEmptyScreen(); |
| 913 | } else { |
| 914 | return screenId; |
| 915 | } |
| 916 | } |
| 917 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 918 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 919 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 920 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 921 | Runnable onCompleteRunnable = null; |
| 922 | int animationType = 0; |
| 923 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 924 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 925 | if (resultCode == RESULT_OK) { |
| 926 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 927 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 928 | mPendingAddWidgetInfo); |
| 929 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 930 | onCompleteRunnable = new Runnable() { |
| 931 | @Override |
| 932 | public void run() { |
| 933 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 934 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 935 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 936 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 937 | } |
| 938 | }; |
| 939 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 940 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 941 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 942 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 943 | if (mDragLayer.getAnimatedView() != null) { |
| 944 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 945 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 946 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 947 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 948 | // The animated view may be null in the case of a rotation during widget configuration |
| 949 | onCompleteRunnable.run(); |
| 950 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 954 | protected void onStop() { |
| 955 | super.onStop(); |
| 956 | FirstFrameAnimatorHelper.setIsVisible(false); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 957 | |
| 958 | if (mLauncherCallbacks != null) { |
| 959 | mLauncherCallbacks.onStop(); |
| 960 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | @Override |
| 964 | protected void onStart() { |
| 965 | super.onStart(); |
| 966 | FirstFrameAnimatorHelper.setIsVisible(true); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 967 | |
| 968 | if (mLauncherCallbacks != null) { |
| 969 | mLauncherCallbacks.onStart(); |
| 970 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 974 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 975 | long startTime = 0; |
| 976 | if (DEBUG_RESUME_TIME) { |
| 977 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 978 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 979 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 980 | |
| 981 | if (mLauncherCallbacks != null) { |
| 982 | mLauncherCallbacks.preOnResume(); |
| 983 | } |
| 984 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 985 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 986 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 987 | // Restore the previous launcher state |
| 988 | if (mOnResumeState == State.WORKSPACE) { |
| 989 | showWorkspace(false); |
| 990 | } else if (mOnResumeState == State.APPS_CUSTOMIZE) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 991 | showAllApps(false, mAppsCustomizeContent.getContentType(), false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 992 | } |
| 993 | mOnResumeState = State.NONE; |
| 994 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 995 | // Background was set to gradient in onPause(), restore to black if in all apps. |
| 996 | setWorkspaceBackground(mState == State.WORKSPACE); |
| 997 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 998 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 999 | if (mRestoring || mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1000 | setWorkspaceLoading(true); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 1001 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1002 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1003 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1004 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1005 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1006 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 1007 | // execute them here |
| 1008 | long startTimeCallbacks = 0; |
| 1009 | if (DEBUG_RESUME_TIME) { |
| 1010 | startTimeCallbacks = System.currentTimeMillis(); |
| 1011 | } |
| 1012 | |
| 1013 | if (mAppsCustomizeContent != null) { |
| 1014 | mAppsCustomizeContent.setBulkBind(true); |
| 1015 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1016 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 1017 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1018 | } |
| 1019 | if (mAppsCustomizeContent != null) { |
| 1020 | mAppsCustomizeContent.setBulkBind(false); |
| 1021 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1022 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1023 | if (DEBUG_RESUME_TIME) { |
| 1024 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 1025 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 1026 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1027 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 1028 | if (mOnResumeCallbacks.size() > 0) { |
| 1029 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 1030 | mOnResumeCallbacks.get(i).run(); |
| 1031 | } |
| 1032 | mOnResumeCallbacks.clear(); |
| 1033 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1034 | |
| 1035 | // Reset the pressed state of icons that were locked in the press state while activities |
| 1036 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1037 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1038 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1039 | mWaitingForResume.setStayPressed(false); |
| 1040 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 1041 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1042 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 1043 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 1044 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 1045 | // orientation. |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1046 | getWorkspace().reinflateWidgetsIfNecessary(); |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1047 | |
Winson Chung | 780fe59 | 2013-09-26 14:48:44 -0700 | [diff] [blame] | 1048 | // Process any items that were added while Launcher was away. |
| 1049 | InstallShortcutReceiver.disableAndFlushInstallQueue(this); |
| 1050 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1051 | if (DEBUG_RESUME_TIME) { |
| 1052 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1053 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1054 | |
| 1055 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1056 | // If we are resuming and the custom content is the current page, we call onShow(). |
| 1057 | // It is also poassible that onShow will instead be called slightly after first layout |
| 1058 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1059 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1060 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1061 | } |
| 1062 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 1063 | mWorkspace.updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1064 | mWorkspace.onResume(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1065 | |
| 1066 | PackageInstallerCompat.getInstance(this).onResume(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1067 | |
| 1068 | if (mLauncherCallbacks != null) { |
| 1069 | mLauncherCallbacks.onResume(); |
| 1070 | } |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1073 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1074 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1075 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1076 | InstallShortcutReceiver.enableInstallQueue(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1077 | PackageInstallerCompat.getInstance(this).onPause(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1078 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1079 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1080 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1081 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1082 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1083 | |
| 1084 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1085 | // debounce excess onHide calls. |
| 1086 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1087 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1088 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1089 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1090 | if (mLauncherCallbacks != null) { |
| 1091 | mLauncherCallbacks.onPause(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1092 | } |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1096 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1097 | // by a onResume or by scrolling otherwise. |
| 1098 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1099 | |
| 1100 | // Custom content is completely hidden |
| 1101 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1102 | |
| 1103 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1104 | public void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1105 | |
| 1106 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1107 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1110 | public interface LauncherOverlay { |
| 1111 | |
| 1112 | /** |
| 1113 | * Touch interaction leading to overscroll has begun |
| 1114 | */ |
| 1115 | public void onScrollInteractionBegin(); |
| 1116 | |
| 1117 | /** |
| 1118 | * Touch interaction related to overscroll has ended |
| 1119 | */ |
| 1120 | public void onScrollInteractionEnd(); |
| 1121 | |
| 1122 | /** |
| 1123 | * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost |
| 1124 | * screen (or in the case of RTL, the rightmost screen). |
| 1125 | */ |
| 1126 | public void onScrollChange(int progress, boolean rtl); |
| 1127 | |
| 1128 | /** |
| 1129 | * Screen has stopped scrolling |
| 1130 | */ |
| 1131 | public void onScrollSettled(); |
| 1132 | |
| 1133 | /** |
| 1134 | * This method can be called by the Launcher in order to force the LauncherOverlay |
| 1135 | * to exit fully immersive mode. |
| 1136 | */ |
| 1137 | public void forceExitFullImmersion(); |
| 1138 | } |
| 1139 | |
| 1140 | public interface LauncherOverlayCallbacks { |
| 1141 | /** |
| 1142 | * This method indicates whether a call to {@link #enterFullImmersion()} will succeed, |
| 1143 | * however it doesn't modify any state within the launcher. |
| 1144 | */ |
| 1145 | public boolean canEnterFullImmersion(); |
| 1146 | |
| 1147 | /** |
| 1148 | * Should be called to tell Launcher that the LauncherOverlay will take over interaction, |
| 1149 | * eg. by occupying the full screen and handling all touch events. |
| 1150 | * |
| 1151 | * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this |
| 1152 | * case, Launcher will modify any necessary state and assumes the overlay is |
| 1153 | * handling all interaction. If false, the LauncherOverlay should cancel any |
| 1154 | * |
| 1155 | */ |
| 1156 | public boolean enterFullImmersion(); |
| 1157 | |
| 1158 | /** |
| 1159 | * Must be called when exiting fully immersive mode. Indicates to Launcher that it has |
| 1160 | * full control over UI and state. |
| 1161 | */ |
| 1162 | public void exitFullImmersion(); |
| 1163 | } |
| 1164 | |
| 1165 | class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks { |
| 1166 | |
| 1167 | @Override |
| 1168 | public boolean canEnterFullImmersion() { |
| 1169 | return mState == State.WORKSPACE; |
| 1170 | } |
| 1171 | |
| 1172 | @Override |
| 1173 | public boolean enterFullImmersion() { |
| 1174 | if (mState == State.WORKSPACE) { |
| 1175 | // When fully immersed, disregard any touches which fall through. |
| 1176 | mDragLayer.setBlockTouch(true); |
| 1177 | return true; |
| 1178 | } |
| 1179 | return false; |
| 1180 | } |
| 1181 | |
| 1182 | @Override |
| 1183 | public void exitFullImmersion() { |
| 1184 | mDragLayer.setBlockTouch(false); |
| 1185 | } |
| 1186 | } |
| 1187 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1188 | protected boolean hasSettings() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1189 | if (mLauncherCallbacks != null) { |
| 1190 | return mLauncherCallbacks.hasSettings(); |
| 1191 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1192 | return false; |
| 1193 | } |
| 1194 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1195 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1196 | public void addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1197 | CustomContentCallbacks callbacks, String description) { |
| 1198 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1201 | // The custom content needs to offset its content to account for the QSB |
| 1202 | public int getTopOffsetForCustomContent() { |
| 1203 | return mWorkspace.getPaddingTop(); |
| 1204 | } |
| 1205 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1206 | @Override |
| 1207 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1208 | // Flag the loader to stop early before switching |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1209 | if (mModel.isCurrentCallbacks(this)) { |
| 1210 | mModel.stopLoader(); |
| 1211 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1212 | if (mAppsCustomizeContent != null) { |
| 1213 | mAppsCustomizeContent.surrender(); |
| 1214 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1215 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1216 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1217 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1218 | // 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] | 1219 | @Override |
| 1220 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1221 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1222 | mHasFocus = hasFocus; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1223 | |
| 1224 | if (mLauncherCallbacks != null) { |
| 1225 | mLauncherCallbacks.onWindowFocusChanged(hasFocus); |
| 1226 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1227 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1228 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1229 | private boolean acceptFilter() { |
| 1230 | final InputMethodManager inputManager = (InputMethodManager) |
| 1231 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1232 | return !inputManager.isFullscreenMode(); |
| 1233 | } |
| 1234 | |
| 1235 | @Override |
| 1236 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1237 | final int uniChar = event.getUnicodeChar(); |
| 1238 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1239 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1240 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1241 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1242 | keyCode, event); |
| 1243 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1244 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1245 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1246 | // showSearchDialog() |
| 1247 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1248 | // onSearchRequested() will be called for every keystroke, |
| 1249 | // but it is idempotent, so it's fine. |
| 1250 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1254 | // Eat the long press event so the keyboard doesn't come up. |
| 1255 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1256 | return true; |
| 1257 | } |
| 1258 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1259 | return handled; |
| 1260 | } |
| 1261 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1262 | private String getTypedText() { |
| 1263 | return mDefaultKeySsb.toString(); |
| 1264 | } |
| 1265 | |
| 1266 | private void clearTypedText() { |
| 1267 | mDefaultKeySsb.clear(); |
| 1268 | mDefaultKeySsb.clearSpans(); |
| 1269 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1270 | } |
| 1271 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1272 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1273 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1274 | * State |
| 1275 | */ |
| 1276 | private static State intToState(int stateOrdinal) { |
| 1277 | State state = State.WORKSPACE; |
| 1278 | final State[] stateValues = State.values(); |
| 1279 | for (int i = 0; i < stateValues.length; i++) { |
| 1280 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1281 | state = stateValues[i]; |
| 1282 | break; |
| 1283 | } |
| 1284 | } |
| 1285 | return state; |
| 1286 | } |
| 1287 | |
| 1288 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1289 | * Restores the previous state, if it exists. |
| 1290 | * |
| 1291 | * @param savedState The previous state. |
| 1292 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1293 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1294 | private void restoreState(Bundle savedState) { |
| 1295 | if (savedState == null) { |
| 1296 | return; |
| 1297 | } |
| 1298 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1299 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1300 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1301 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1302 | } |
| 1303 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1304 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1305 | PagedView.INVALID_RESTORE_PAGE); |
| 1306 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1307 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1308 | } |
| 1309 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1310 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1311 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1312 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1313 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1314 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1315 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1316 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1317 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1318 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1319 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
Adam Cohen | b823ae4 | 2015-03-27 18:07:52 -0700 | [diff] [blame] | 1320 | AppWidgetProviderInfo info = savedState.getParcelable( |
| 1321 | RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Sunny Goyal | a609596 | 2015-05-12 13:30:07 -0700 | [diff] [blame] | 1322 | mPendingAddWidgetInfo = info == null ? |
| 1323 | null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info); |
| 1324 | |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1325 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1326 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1327 | mRestoring = true; |
| 1328 | } |
| 1329 | |
| 1330 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1331 | if (renameFolder) { |
| 1332 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1333 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1334 | mRestoring = true; |
| 1335 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1336 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1337 | // Restore the AppsCustomize tab |
| 1338 | if (mAppsCustomizeTabHost != null) { |
| 1339 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1340 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1341 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1342 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1343 | mAppsCustomizeContent.loadAssociatedPages( |
| 1344 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1347 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1348 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1349 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1350 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1351 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /** |
| 1355 | * Finds all the views we need and configure them properly. |
| 1356 | */ |
| 1357 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1358 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1359 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1360 | mLauncherView = findViewById(R.id.launcher); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1361 | mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1362 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1363 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1364 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1365 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1366 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1367 | mLauncherView.setSystemUiVisibility( |
| 1368 | 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] | 1369 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1370 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1371 | // Setup the drag layer |
| 1372 | mDragLayer.setup(this, dragController); |
| 1373 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1374 | // Setup the hotseat |
| 1375 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1376 | if (mHotseat != null) { |
| 1377 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1378 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1381 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1382 | View widgetButton = findViewById(R.id.widget_button); |
| 1383 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1384 | @Override |
| 1385 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1386 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1387 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1388 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1389 | } |
| 1390 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1391 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1392 | |
| 1393 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1394 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1395 | @Override |
| 1396 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1397 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1398 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1399 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1400 | } |
| 1401 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1402 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1403 | |
| 1404 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1405 | if (hasSettings()) { |
| 1406 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1407 | @Override |
| 1408 | public void onClick(View arg0) { |
| 1409 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1410 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1411 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1412 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1413 | }); |
| 1414 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1415 | } else { |
| 1416 | settingsButton.setVisibility(View.GONE); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1417 | } |
| 1418 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1419 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1420 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1421 | // Setup the workspace |
| 1422 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1423 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1424 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1425 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1426 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1427 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1428 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1429 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1430 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1431 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1432 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1433 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1434 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1435 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1436 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1437 | // 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] | 1438 | dragController.setDragScoller(mWorkspace); |
| 1439 | dragController.setScrollView(mDragLayer); |
| 1440 | dragController.setMoveTarget(mWorkspace); |
| 1441 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1442 | if (mSearchDropTargetBar != null) { |
| 1443 | mSearchDropTargetBar.setup(this, dragController); |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 1444 | mSearchDropTargetBar.setQsbSearchBar(getQsbBar()); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1445 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1446 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1447 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1448 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1449 | mWeightWatcher = new WeightWatcher(this); |
| 1450 | mWeightWatcher.setAlpha(0.5f); |
| 1451 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1452 | new FrameLayout.LayoutParams( |
| 1453 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1454 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1455 | Gravity.BOTTOM) |
| 1456 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1457 | |
| 1458 | boolean show = shouldShowWeightWatcher(); |
| 1459 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1460 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1464 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1465 | */ |
| 1466 | public void setAllAppsButton(View allAppsButton) { |
| 1467 | mAllAppsButton = allAppsButton; |
| 1468 | } |
| 1469 | |
| 1470 | public View getAllAppsButton() { |
| 1471 | return mAllAppsButton; |
| 1472 | } |
| 1473 | |
| 1474 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1475 | * Creates a view representing a shortcut. |
| 1476 | * |
| 1477 | * @param info The data structure describing the shortcut. |
| 1478 | * |
| 1479 | * @return A View inflated from R.layout.application. |
| 1480 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1481 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1482 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1483 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1488 | * |
| 1489 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1490 | * @param parent The group the shortcut belongs to. |
| 1491 | * @param info The data structure describing the shortcut. |
| 1492 | * |
| 1493 | * @return A View inflated from layoutResId. |
| 1494 | */ |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1495 | public View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1496 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 1497 | favorite.applyFromShortcutInfo(info, mIconCache, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1498 | favorite.setOnClickListener(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1499 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1500 | return favorite; |
| 1501 | } |
| 1502 | |
| 1503 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1504 | * Add a shortcut to the workspace. |
| 1505 | * |
| 1506 | * @param data The intent describing the shortcut. |
| 1507 | * @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] | 1508 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1509 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1510 | int cellY) { |
| 1511 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1512 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1513 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1514 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1515 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1516 | |
Sunny Goyal | 2350bc9 | 2014-10-14 16:42:54 -0700 | [diff] [blame] | 1517 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1518 | if (info == null) { |
| 1519 | return; |
| 1520 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1521 | final View view = createShortcut(info); |
| 1522 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1523 | // First we check if we already know the exact location where we want to add this item. |
| 1524 | if (cellX >= 0 && cellY >= 0) { |
| 1525 | cellXY[0] = cellX; |
| 1526 | cellXY[1] = cellY; |
| 1527 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1528 | |
| 1529 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1530 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1531 | true, null,null)) { |
| 1532 | return; |
| 1533 | } |
| 1534 | DragObject dragObject = new DragObject(); |
| 1535 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1536 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1537 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1538 | return; |
| 1539 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1540 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1541 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1542 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1543 | foundCellSpan = (result != null); |
| 1544 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1545 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1549 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1550 | return; |
| 1551 | } |
| 1552 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1553 | 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] | 1554 | |
| 1555 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1556 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1557 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1558 | } |
| 1559 | } |
| 1560 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1561 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1562 | int minHeight) { |
| 1563 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1564 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1565 | // to ensure that it gets the full amount of space that it has requested |
| 1566 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1567 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1568 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1571 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1572 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1575 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1576 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1579 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1580 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1583 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1584 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1585 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1586 | } |
| 1587 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1588 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1589 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1590 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1591 | * @param appWidgetId The app widget id |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1592 | */ |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1593 | private void completeAddAppWidget(int appWidgetId, long container, long screenId, |
| 1594 | AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) { |
| 1595 | |
| 1596 | ItemInfo info = mPendingAddInfo; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1597 | if (appWidgetInfo == null) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1598 | appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this, |
| 1599 | mAppWidgetManager.getAppWidgetInfo(appWidgetId)); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1600 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1601 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1602 | if (appWidgetInfo.isCustomWidget) { |
| 1603 | appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1606 | LauncherAppWidgetInfo launcherInfo; |
| 1607 | launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider); |
| 1608 | launcherInfo.spanX = info.spanX; |
| 1609 | launcherInfo.spanY = info.spanY; |
| 1610 | launcherInfo.minSpanX = info.minSpanX; |
| 1611 | launcherInfo.minSpanY = info.minSpanY; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1612 | launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1613 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1614 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1615 | container, screenId, info.cellX, info.cellY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1616 | |
| 1617 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1618 | if (hostView == null) { |
| 1619 | // Perform actual inflation because we're live |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1620 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, |
| 1621 | appWidgetInfo); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1622 | } else { |
| 1623 | // The AppWidgetHostView has already been inflated and instantiated |
| 1624 | launcherInfo.hostView = hostView; |
| 1625 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1626 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1627 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1628 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1629 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1630 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX, |
| 1631 | info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1632 | |
| 1633 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1634 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1635 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1636 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1637 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1638 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1639 | @Override |
| 1640 | public void onReceive(Context context, Intent intent) { |
| 1641 | final String action = intent.getAction(); |
| 1642 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1643 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1644 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1645 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1646 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1647 | // 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] | 1648 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1649 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1650 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1651 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1652 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1653 | mUserPresent = true; |
| 1654 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1655 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1656 | mModel.resetLoadedState(false, true); |
| 1657 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1658 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1659 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1660 | mModel.resetLoadedState(false, true); |
| 1661 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1662 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1663 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1664 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1665 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1666 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | }; |
| 1670 | |
| 1671 | @Override |
| 1672 | public void onAttachedToWindow() { |
| 1673 | super.onAttachedToWindow(); |
| 1674 | |
| 1675 | // Listen for broadcasts related to user-presence |
| 1676 | final IntentFilter filter = new IntentFilter(); |
| 1677 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1678 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1679 | // For handling managed profiles |
| 1680 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1681 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1682 | if (ENABLE_DEBUG_INTENTS) { |
| 1683 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1684 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1685 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1686 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1687 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1688 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1689 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1690 | mVisible = true; |
| 1691 | } |
| 1692 | |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1693 | /** |
| 1694 | * Sets up transparent navigation and status bars in LMP. |
| 1695 | * This method is a no-op for other platform versions. |
| 1696 | */ |
| 1697 | @TargetApi(19) |
| 1698 | private void setupTransparentSystemBarsForLmp() { |
| 1699 | // TODO(sansid): use the APIs directly when compiling against L sdk. |
| 1700 | // Currently we use reflection to access the flags and the API to set the transparency |
| 1701 | // on the System bars. |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 1702 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1703 | try { |
| 1704 | getWindow().getAttributes().systemUiVisibility |= |
| 1705 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1706 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1707 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1708 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
| 1709 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
| 1710 | Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( |
| 1711 | "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); |
| 1712 | getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); |
| 1713 | |
| 1714 | Method setStatusBarColorMethod = |
| 1715 | Window.class.getDeclaredMethod("setStatusBarColor", int.class); |
| 1716 | Method setNavigationBarColorMethod = |
| 1717 | Window.class.getDeclaredMethod("setNavigationBarColor", int.class); |
| 1718 | setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1719 | setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1720 | } catch (NoSuchFieldException e) { |
| 1721 | Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); |
| 1722 | } catch (NoSuchMethodException ex) { |
| 1723 | Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); |
| 1724 | } catch (IllegalAccessException e) { |
| 1725 | Log.w(TAG, "IllegalAccessException while setting up transparent bars"); |
| 1726 | } catch (IllegalArgumentException e) { |
| 1727 | Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); |
| 1728 | } catch (InvocationTargetException e) { |
| 1729 | Log.w(TAG, "InvocationTargetException while setting up transparent bars"); |
| 1730 | } finally {} |
| 1731 | } |
| 1732 | } |
| 1733 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1734 | @Override |
| 1735 | public void onDetachedFromWindow() { |
| 1736 | super.onDetachedFromWindow(); |
| 1737 | mVisible = false; |
| 1738 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1739 | if (mAttached) { |
| 1740 | unregisterReceiver(mReceiver); |
| 1741 | mAttached = false; |
| 1742 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1743 | updateRunning(); |
| 1744 | } |
| 1745 | |
| 1746 | public void onWindowVisibilityChanged(int visibility) { |
| 1747 | mVisible = visibility == View.VISIBLE; |
| 1748 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1749 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1750 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1751 | // is a more appropriate event to handle |
| 1752 | if (mVisible) { |
| 1753 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1754 | if (!mWorkspaceLoading) { |
| 1755 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1756 | // We want to let Launcher draw itself at least once before we force it to build |
| 1757 | // layers on all the workspace pages, so that transitioning to Launcher from other |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1758 | // apps is nice and speedy. |
| 1759 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1760 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1761 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1762 | if (mStarted) return; |
| 1763 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1764 | // We delay the layer building a bit in order to give |
| 1765 | // other message processing a time to run. In particular |
| 1766 | // this avoids a delay in hiding the IME if it was |
| 1767 | // currently shown, because doing that may involve |
| 1768 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1769 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1770 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1771 | mWorkspace.post(new Runnable() { |
| 1772 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1773 | if (mWorkspace != null && |
| 1774 | mWorkspace.getViewTreeObserver() != null) { |
| 1775 | mWorkspace.getViewTreeObserver(). |
| 1776 | removeOnDrawListener(listener); |
| 1777 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1778 | } |
| 1779 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1780 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1781 | } |
| 1782 | }); |
| 1783 | } |
| 1784 | clearTypedText(); |
| 1785 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | private void sendAdvanceMessage(long delay) { |
| 1789 | mHandler.removeMessages(ADVANCE_MSG); |
| 1790 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1791 | mHandler.sendMessageDelayed(msg, delay); |
| 1792 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1793 | } |
| 1794 | |
| 1795 | private void updateRunning() { |
| 1796 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1797 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1798 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1799 | if (autoAdvanceRunning) { |
| 1800 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1801 | sendAdvanceMessage(delay); |
| 1802 | } else { |
| 1803 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1804 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1805 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1806 | } |
| 1807 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1808 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | private final Handler mHandler = new Handler() { |
| 1814 | @Override |
| 1815 | public void handleMessage(Message msg) { |
| 1816 | if (msg.what == ADVANCE_MSG) { |
| 1817 | int i = 0; |
| 1818 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1819 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1820 | final int delay = mAdvanceStagger * i; |
| 1821 | if (v instanceof Advanceable) { |
| 1822 | postDelayed(new Runnable() { |
| 1823 | public void run() { |
| 1824 | ((Advanceable) v).advance(); |
| 1825 | } |
| 1826 | }, delay); |
| 1827 | } |
| 1828 | i++; |
| 1829 | } |
| 1830 | sendAdvanceMessage(mAdvanceInterval); |
| 1831 | } |
| 1832 | } |
| 1833 | }; |
| 1834 | |
| 1835 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1836 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1837 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1838 | if (v instanceof Advanceable) { |
| 1839 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1840 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1841 | updateRunning(); |
| 1842 | } |
| 1843 | } |
| 1844 | |
| 1845 | void removeWidgetToAutoAdvance(View hostView) { |
| 1846 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1847 | mWidgetsToAdvance.remove(hostView); |
| 1848 | updateRunning(); |
| 1849 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1852 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1853 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1854 | launcherInfo.hostView = null; |
| 1855 | } |
| 1856 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1857 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1858 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1859 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1862 | public ArrayList<AppInfo> getAllAppsList() { |
| 1863 | return mAppsCustomizeContent.getApps(); |
| 1864 | } |
| 1865 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1866 | public DragLayer getDragLayer() { |
| 1867 | return mDragLayer; |
| 1868 | } |
| 1869 | |
| 1870 | public Workspace getWorkspace() { |
| 1871 | return mWorkspace; |
| 1872 | } |
| 1873 | |
| 1874 | public Hotseat getHotseat() { |
| 1875 | return mHotseat; |
| 1876 | } |
| 1877 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1878 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1879 | return mOverviewPanel; |
| 1880 | } |
| 1881 | |
| 1882 | public SearchDropTargetBar getSearchBar() { |
| 1883 | return mSearchDropTargetBar; |
| 1884 | } |
| 1885 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1886 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1887 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1888 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1889 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1890 | public LauncherModel getModel() { |
| 1891 | return mModel; |
| 1892 | } |
| 1893 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1894 | protected SharedPreferences getSharedPrefs() { |
| 1895 | return mSharedPrefs; |
| 1896 | } |
| 1897 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1898 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1899 | getWindow().closeAllPanels(); |
| 1900 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1901 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1902 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1903 | } |
| 1904 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1905 | @Override |
| 1906 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1907 | long startTime = 0; |
| 1908 | if (DEBUG_RESUME_TIME) { |
| 1909 | startTime = System.currentTimeMillis(); |
| 1910 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1911 | super.onNewIntent(intent); |
| 1912 | |
| 1913 | // Close the menu |
| 1914 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1915 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1916 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1917 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1918 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1919 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1920 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1921 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1922 | if (mWorkspace == null) { |
| 1923 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1924 | return; |
| 1925 | } |
| 1926 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1927 | // In all these cases, only animate if we're already on home |
| 1928 | mWorkspace.exitWidgetResizeMode(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1929 | |
| 1930 | boolean moveToDefaultScreen = mLauncherCallbacks != null ? |
| 1931 | mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true; |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1932 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1933 | openFolder == null && moveToDefaultScreen) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1934 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1935 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1936 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1937 | closeFolder(); |
| 1938 | exitSpringLoadedDragMode(); |
| 1939 | |
| 1940 | // If we are already on home, then just animate back to the workspace, |
| 1941 | // otherwise, just wait until onResume to set the state back to Workspace |
| 1942 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1943 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1944 | } else { |
| 1945 | mOnResumeState = State.WORKSPACE; |
| 1946 | } |
| 1947 | |
| 1948 | final View v = getWindow().peekDecorView(); |
| 1949 | if (v != null && v.getWindowToken() != null) { |
| 1950 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1951 | INPUT_METHOD_SERVICE); |
| 1952 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 1953 | } |
| 1954 | |
| 1955 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 1956 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1957 | mAppsCustomizeTabHost.reset(); |
| 1958 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1959 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1960 | if (mLauncherCallbacks != null) { |
| 1961 | mLauncherCallbacks.onHomeIntent(); |
| 1962 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1963 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1964 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1965 | if (DEBUG_RESUME_TIME) { |
| 1966 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 1967 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1968 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1969 | if (mLauncherCallbacks != null) { |
| 1970 | mLauncherCallbacks.onNewIntent(intent); |
| 1971 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1974 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1975 | public void onRestoreInstanceState(Bundle state) { |
| 1976 | super.onRestoreInstanceState(state); |
| 1977 | for (int page: mSynchronouslyBoundPages) { |
| 1978 | mWorkspace.restoreInstanceStateForChild(page); |
| 1979 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | @Override |
| 1983 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1984 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 1985 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1986 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1987 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1988 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1989 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1990 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 1991 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 1992 | // this state is reflected. |
| 1993 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1994 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1995 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1996 | mWaitingForResult) { |
| 1997 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1998 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1999 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 2000 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2001 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 2002 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 2003 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2004 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | if (mFolderInfo != null && mWaitingForResult) { |
| 2008 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 2009 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 2010 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 2011 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2012 | // Save the current AppsCustomize tab |
| 2013 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 2014 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 2015 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2016 | if (currentTabTag != null) { |
| 2017 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 2018 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 2019 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 2020 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2021 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 2022 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2023 | |
| 2024 | if (mLauncherCallbacks != null) { |
| 2025 | mLauncherCallbacks.onSaveInstanceState(outState); |
| 2026 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | @Override |
| 2030 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2031 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2032 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2033 | // Remove all pending runnables |
| 2034 | mHandler.removeMessages(ADVANCE_MSG); |
| 2035 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 2036 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2037 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2038 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 2039 | LauncherAppState app = (LauncherAppState.getInstance()); |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 2040 | |
| 2041 | // It's possible to receive onDestroy after a new Launcher activity has |
| 2042 | // been created. In this case, don't interfere with the new Launcher. |
| 2043 | if (mModel.isCurrentCallbacks(this)) { |
| 2044 | mModel.stopLoader(); |
| 2045 | app.setLauncher(null); |
| 2046 | } |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2047 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2048 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2049 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2050 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2051 | 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] | 2052 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2053 | mAppWidgetHost = null; |
| 2054 | |
| 2055 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2056 | |
| 2057 | TextKeyListener.getInstance().release(); |
| 2058 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 2059 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 2060 | // to prevent leaking Launcher activities on orientation change. |
| 2061 | if (mModel != null) { |
| 2062 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 2063 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2064 | |
| 2065 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2066 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2067 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 2068 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2069 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 2070 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2071 | mWorkspace = null; |
| 2072 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 2073 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2074 | LauncherAnimUtils.onDestroyActivity(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2075 | |
| 2076 | if (mLauncherCallbacks != null) { |
| 2077 | mLauncherCallbacks.onDestroy(); |
| 2078 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2079 | } |
| 2080 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2081 | public DragController getDragController() { |
| 2082 | return mDragController; |
| 2083 | } |
| 2084 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2085 | @Override |
| 2086 | public void startActivityForResult(Intent intent, int requestCode) { |
Adam Cohen | 173f711 | 2015-03-27 15:14:00 -0700 | [diff] [blame] | 2087 | onStartForResult(requestCode); |
| 2088 | super.startActivityForResult(intent, requestCode); |
| 2089 | } |
| 2090 | |
| 2091 | @Override |
| 2092 | public void startIntentSenderForResult (IntentSender intent, int requestCode, |
| 2093 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) { |
| 2094 | onStartForResult(requestCode); |
| 2095 | try { |
| 2096 | super.startIntentSenderForResult(intent, requestCode, |
| 2097 | fillInIntent, flagsMask, flagsValues, extraFlags, options); |
| 2098 | } catch (IntentSender.SendIntentException e) { |
| 2099 | throw new ActivityNotFoundException(); |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | private void onStartForResult(int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2104 | if (requestCode >= 0) { |
| 2105 | setWaitingForResult(true); |
| 2106 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2107 | } |
| 2108 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2109 | /** |
| 2110 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2111 | * argument for {@link #startSearch} to true. |
| 2112 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2113 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2114 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2115 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2116 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2117 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2118 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2119 | if (initialQuery == null) { |
| 2120 | // Use any text typed in the launcher as the initial query |
| 2121 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2122 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2123 | if (appSearchData == null) { |
| 2124 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2125 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2126 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2127 | Rect sourceBounds = new Rect(); |
| 2128 | if (mSearchDropTargetBar != null) { |
| 2129 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2130 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2131 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2132 | boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2133 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2134 | if (clearTextImmediately) { |
| 2135 | clearTypedText(); |
| 2136 | } |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2137 | } |
| 2138 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2139 | /** |
| 2140 | * Start a text search. |
| 2141 | * |
| 2142 | * @return {@code true} if the search will start immediately, so any further keypresses |
| 2143 | * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue |
| 2144 | * to buffer keypresses. |
| 2145 | */ |
| 2146 | public boolean startSearch(String initialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2147 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2148 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 2149 | return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData, |
| 2150 | sourceBounds); |
| 2151 | } |
| 2152 | |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2153 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2154 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2155 | return false; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | /** |
| 2159 | * Starts the global search activity. This code is a copied from SearchManager |
| 2160 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2161 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2162 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2163 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2164 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2165 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2166 | if (globalSearchActivity == null) { |
| 2167 | Log.w(TAG, "No global search activity found."); |
| 2168 | return; |
| 2169 | } |
| 2170 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2171 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2172 | intent.setComponent(globalSearchActivity); |
| 2173 | // Make sure that we have a Bundle to put source in |
| 2174 | if (appSearchData == null) { |
| 2175 | appSearchData = new Bundle(); |
| 2176 | } else { |
| 2177 | appSearchData = new Bundle(appSearchData); |
| 2178 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2179 | // 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] | 2180 | if (!appSearchData.containsKey("source")) { |
| 2181 | appSearchData.putString("source", getPackageName()); |
| 2182 | } |
| 2183 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2184 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2185 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2186 | } |
| 2187 | if (selectInitialQuery) { |
| 2188 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2189 | } |
| 2190 | intent.setSourceBounds(sourceBounds); |
| 2191 | try { |
| 2192 | startActivity(intent); |
| 2193 | } catch (ActivityNotFoundException ex) { |
| 2194 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2195 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2196 | } |
| 2197 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2198 | public boolean isOnCustomContent() { |
| 2199 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2200 | } |
| 2201 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2202 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2203 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2204 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2205 | if (!isOnCustomContent()) { |
| 2206 | // Close any open folders |
| 2207 | closeFolder(); |
| 2208 | // Stop resizing any widgets |
| 2209 | mWorkspace.exitWidgetResizeMode(); |
| 2210 | if (!mWorkspace.isInOverviewMode()) { |
| 2211 | // Show the overview mode |
| 2212 | showOverviewMode(true); |
| 2213 | } else { |
| 2214 | showWorkspace(true); |
| 2215 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2216 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2217 | if (mLauncherCallbacks != null) { |
| 2218 | return mLauncherCallbacks.onPrepareOptionsMenu(menu); |
| 2219 | } |
| 2220 | |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2221 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2222 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2223 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2224 | @Override |
| 2225 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2226 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2227 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2228 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2231 | public boolean isWorkspaceLocked() { |
| 2232 | return mWorkspaceLoading || mWaitingForResult; |
| 2233 | } |
| 2234 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2235 | public boolean isWorkspaceLoading() { |
| 2236 | return mWorkspaceLoading; |
| 2237 | } |
| 2238 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2239 | private void setWorkspaceLoading(boolean value) { |
| 2240 | boolean isLocked = isWorkspaceLocked(); |
| 2241 | mWorkspaceLoading = value; |
| 2242 | if (isLocked != isWorkspaceLocked()) { |
| 2243 | onWorkspaceLockedChanged(); |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | private void setWaitingForResult(boolean value) { |
| 2248 | boolean isLocked = isWorkspaceLocked(); |
| 2249 | mWaitingForResult = value; |
| 2250 | if (isLocked != isWorkspaceLocked()) { |
| 2251 | onWorkspaceLockedChanged(); |
| 2252 | } |
| 2253 | } |
| 2254 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2255 | protected void onWorkspaceLockedChanged() { |
| 2256 | if (mLauncherCallbacks != null) { |
| 2257 | mLauncherCallbacks.onWorkspaceLockedChanged(); |
| 2258 | } |
| 2259 | } |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2260 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2261 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2262 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2263 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2264 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2265 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2266 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2267 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2268 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2269 | |
Sunny Goyal | 8f9a787 | 2015-01-16 16:14:29 -0800 | [diff] [blame] | 2270 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, final |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2271 | AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2272 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2273 | } |
| 2274 | |
Sunny Goyal | 8f9a787 | 2015-01-16 16:14:29 -0800 | [diff] [blame] | 2275 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2276 | final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo, |
| 2277 | int delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2278 | if (appWidgetInfo.configure != null) { |
| 2279 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2280 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2281 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2282 | // Launch over to configure widget, if needed |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2283 | mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this, |
| 2284 | mAppWidgetHost, REQUEST_CREATE_APPWIDGET); |
| 2285 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2286 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2287 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2288 | Runnable onComplete = new Runnable() { |
| 2289 | @Override |
| 2290 | public void run() { |
| 2291 | // Exit spring loaded mode if necessary after adding the widget |
| 2292 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2293 | null); |
| 2294 | } |
| 2295 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2296 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2297 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2298 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2299 | } |
| 2300 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2301 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2302 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2303 | // Close any folders that may be open. |
| 2304 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2305 | mWorkspace.moveToCustomContentScreen(animate); |
| 2306 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2307 | |
| 2308 | public void addPendingItem(PendingAddItemInfo info, long container, long screenId, |
| 2309 | int[] cell, int spanX, int spanY) { |
| 2310 | switch (info.itemType) { |
| 2311 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: |
| 2312 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
| 2313 | int span[] = new int[2]; |
| 2314 | span[0] = spanX; |
| 2315 | span[1] = spanY; |
| 2316 | addAppWidgetFromDrop((PendingAddWidgetInfo) info, |
| 2317 | container, screenId, cell, span); |
| 2318 | break; |
| 2319 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 2320 | processShortcutFromDrop(info.componentName, container, screenId, cell); |
| 2321 | break; |
| 2322 | default: |
| 2323 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
| 2324 | } |
| 2325 | } |
| 2326 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2327 | /** |
| 2328 | * Process a shortcut drop. |
| 2329 | * |
| 2330 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2331 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2332 | * @param cell The cell it should be added to, optional |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2333 | */ |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2334 | private void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
| 2335 | int[] cell) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2336 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2337 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2338 | mPendingAddInfo.screenId = screenId; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2339 | mPendingAddInfo.dropPos = null; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2340 | |
| 2341 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2342 | mPendingAddInfo.cellX = cell[0]; |
| 2343 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2344 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2345 | |
| 2346 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2347 | createShortcutIntent.setComponent(componentName); |
| 2348 | processShortcut(createShortcutIntent); |
| 2349 | } |
| 2350 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2351 | /** |
| 2352 | * Process a widget drop. |
| 2353 | * |
| 2354 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2355 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2356 | * @param cell The cell it should be added to, optional |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2357 | */ |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2358 | private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
| 2359 | int[] cell, int[] span) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2360 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2361 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2362 | mPendingAddInfo.screenId = info.screenId = screenId; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2363 | mPendingAddInfo.dropPos = null; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2364 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2365 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2366 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2367 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2368 | mPendingAddInfo.cellX = cell[0]; |
| 2369 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2370 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2371 | if (span != null) { |
| 2372 | mPendingAddInfo.spanX = span[0]; |
| 2373 | mPendingAddInfo.spanY = span[1]; |
| 2374 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2375 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2376 | AppWidgetHostView hostView = info.boundWidget; |
| 2377 | int appWidgetId; |
| 2378 | if (hostView != null) { |
| 2379 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2380 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2381 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2382 | // In this case, we either need to start an activity to get permission to bind |
| 2383 | // 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] | 2384 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2385 | Bundle options = info.bindOptions; |
| 2386 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2387 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2388 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2389 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2390 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2391 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2392 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2393 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2394 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2395 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2396 | mAppWidgetManager.getUser(mPendingAddWidgetInfo) |
| 2397 | .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2398 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2399 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2400 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2401 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2402 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2405 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2406 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2407 | } |
| 2408 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2409 | void processWallpaper(Intent intent) { |
| 2410 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2411 | } |
| 2412 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2413 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2414 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2415 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2416 | folderInfo.title = getText(R.string.folder_name); |
| 2417 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2418 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2419 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2420 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2421 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2422 | |
| 2423 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2424 | FolderIcon newFolder = |
| 2425 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2426 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2427 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2428 | // Force measure the new folder icon |
| 2429 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2430 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2431 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2432 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2433 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2434 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2435 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2436 | } |
| 2437 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2438 | protected ComponentName getWallpaperPickerComponent() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2439 | if (mLauncherCallbacks != null) { |
| 2440 | return mLauncherCallbacks.getWallpaperPickerComponent(); |
| 2441 | } |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2442 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2443 | } |
| 2444 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2445 | /** |
| 2446 | * Registers various content observers. The current implementation registers |
| 2447 | * only a favorites observer to keep track of the favorites applications. |
| 2448 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2449 | private void registerContentObservers() { |
| 2450 | ContentResolver resolver = getContentResolver(); |
| 2451 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2452 | true, mWidgetObserver); |
| 2453 | } |
| 2454 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2455 | @Override |
| 2456 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2457 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2458 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2459 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2460 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2461 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 2462 | if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2463 | dumpState(); |
| 2464 | return true; |
| 2465 | } |
| 2466 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2467 | } |
| 2468 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2469 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2470 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2471 | return true; |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | return super.dispatchKeyEvent(event); |
| 2476 | } |
| 2477 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2478 | @Override |
| 2479 | public void onBackPressed() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2480 | if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) { |
| 2481 | return; |
| 2482 | } |
| 2483 | |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2484 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2485 | if (mAppsCustomizeContent.getContentType() == |
| 2486 | AppsCustomizePagedView.ContentType.Applications) { |
| 2487 | showWorkspace(true); |
| 2488 | } else { |
| 2489 | showOverviewMode(true); |
| 2490 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2491 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2492 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2493 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2494 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2495 | if (openFolder.isEditingName()) { |
| 2496 | openFolder.dismissEditingName(); |
| 2497 | } else { |
| 2498 | closeFolder(); |
| 2499 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2500 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2501 | mWorkspace.exitWidgetResizeMode(); |
| 2502 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2503 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2504 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2505 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2506 | } |
| 2507 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2508 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2509 | * Re-listen when widgets are reset. |
| 2510 | */ |
| 2511 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2512 | if (mAppWidgetHost != null) { |
| 2513 | mAppWidgetHost.startListening(); |
| 2514 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2518 | * Launches the intent referred by the clicked shortcut. |
| 2519 | * |
| 2520 | * @param v The view representing the clicked shortcut. |
| 2521 | */ |
| 2522 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2523 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2524 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2525 | if (v.getWindowToken() == null) { |
| 2526 | return; |
| 2527 | } |
| 2528 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2529 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2530 | return; |
| 2531 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2532 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2533 | if (v instanceof Workspace) { |
| 2534 | if (mWorkspace.isInOverviewMode()) { |
| 2535 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2536 | } |
| 2537 | return; |
| 2538 | } |
| 2539 | |
| 2540 | if (v instanceof CellLayout) { |
| 2541 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2542 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2543 | } |
| 2544 | } |
| 2545 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2546 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2547 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2548 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2549 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2550 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2551 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2552 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2553 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2554 | onClickAllAppsButton(v); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2555 | } else if (tag instanceof AppInfo) { |
| 2556 | startAppShortcutOrInfoActivity(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2557 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2558 | if (v instanceof PendingAppWidgetHostView) { |
| 2559 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2560 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2561 | } |
| 2562 | } |
| 2563 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2564 | public void onClickPagedViewIcon(View v) { |
| 2565 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2566 | if (mLauncherCallbacks != null) { |
| 2567 | mLauncherCallbacks.onClickPagedViewIcon(v); |
| 2568 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2571 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2572 | return false; |
| 2573 | } |
| 2574 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2575 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2576 | * Event handler for the app widget view which has not fully restored. |
| 2577 | */ |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2578 | public void onClickPendingWidget(final PendingAppWidgetHostView v) { |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2579 | if (mIsSafeModeEnabled) { |
| 2580 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2581 | return; |
| 2582 | } |
| 2583 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2584 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2585 | if (v.isReadyForClickSetup()) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2586 | int widgetId = info.appWidgetId; |
| 2587 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
| 2588 | if (appWidgetInfo != null) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2589 | mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo( |
| 2590 | this, appWidgetInfo); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2591 | mPendingAddInfo.copyFrom(info); |
| 2592 | mPendingAddWidgetId = widgetId; |
| 2593 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2594 | AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo, |
| 2595 | info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2596 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2597 | } else if (info.installProgress < 0) { |
| 2598 | // The install has not been queued |
| 2599 | final String packageName = info.providerName.getPackageName(); |
| 2600 | showBrokenAppInstallDialog(packageName, |
| 2601 | new DialogInterface.OnClickListener() { |
| 2602 | public void onClick(DialogInterface dialog, int id) { |
| 2603 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
| 2604 | } |
| 2605 | }); |
| 2606 | } else { |
| 2607 | // Download has started. |
| 2608 | final String packageName = info.providerName.getPackageName(); |
| 2609 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2614 | * Event handler for the "grid" button that appears on the home screen, which |
| 2615 | * enters all apps mode. |
| 2616 | * |
| 2617 | * @param v The view that was clicked. |
| 2618 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2619 | protected void onClickAllAppsButton(View v) { |
| 2620 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2621 | if (isAllAppsVisible()) { |
| 2622 | showWorkspace(true); |
| 2623 | } else { |
| 2624 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2625 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2626 | if (mLauncherCallbacks != null) { |
| 2627 | mLauncherCallbacks.onClickAllAppsButton(v); |
| 2628 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2629 | } |
| 2630 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2631 | private void showBrokenAppInstallDialog(final String packageName, |
| 2632 | DialogInterface.OnClickListener onSearchClickListener) { |
Sunny Goyal | e03b812 | 2014-10-08 09:55:24 -0700 | [diff] [blame] | 2633 | new AlertDialog.Builder(this) |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2634 | .setTitle(R.string.abandoned_promises_title) |
| 2635 | .setMessage(R.string.abandoned_promise_explanation) |
| 2636 | .setPositiveButton(R.string.abandoned_search, onSearchClickListener) |
| 2637 | .setNeutralButton(R.string.abandoned_clean_this, |
| 2638 | new DialogInterface.OnClickListener() { |
| 2639 | public void onClick(DialogInterface dialog, int id) { |
| 2640 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 2641 | mWorkspace.removeAbandonedPromise(packageName, user); |
| 2642 | } |
| 2643 | }) |
| 2644 | .create().show(); |
| 2645 | return; |
| 2646 | } |
| 2647 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2648 | /** |
| 2649 | * Event handler for an app shortcut click. |
| 2650 | * |
| 2651 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2652 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2653 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2654 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2655 | Object tag = v.getTag(); |
| 2656 | if (!(tag instanceof ShortcutInfo)) { |
| 2657 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2658 | } |
| 2659 | |
| 2660 | // Open shortcut |
| 2661 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2662 | |
| 2663 | if (shortcut.isDisabled != 0) { |
| 2664 | int error = R.string.activity_not_available; |
| 2665 | if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) { |
| 2666 | error = R.string.safemode_shortcut_error; |
| 2667 | } |
| 2668 | Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); |
| 2669 | return; |
| 2670 | } |
| 2671 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2672 | final Intent intent = shortcut.intent; |
| 2673 | |
| 2674 | // Check for special shortcuts |
| 2675 | if (intent.getComponent() != null) { |
| 2676 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2677 | |
| 2678 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2679 | MemoryDumpActivity.startDump(this); |
| 2680 | return; |
| 2681 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2682 | toggleShowWeightWatcher(); |
| 2683 | return; |
| 2684 | } |
| 2685 | } |
| 2686 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2687 | // Check for abandoned promise |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2688 | if ((v instanceof BubbleTextView) |
| 2689 | && shortcut.isPromise() |
| 2690 | && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2691 | showBrokenAppInstallDialog( |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2692 | shortcut.getTargetComponent().getPackageName(), |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2693 | new DialogInterface.OnClickListener() { |
| 2694 | public void onClick(DialogInterface dialog, int id) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2695 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2696 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2697 | }); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2698 | return; |
| 2699 | } |
| 2700 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2701 | // Start activities |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2702 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2703 | |
| 2704 | if (mLauncherCallbacks != null) { |
| 2705 | mLauncherCallbacks.onClickAppShortcut(v); |
| 2706 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2707 | } |
| 2708 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2709 | private void startAppShortcutOrInfoActivity(View v) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2710 | Object tag = v.getTag(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2711 | final ShortcutInfo shortcut; |
| 2712 | final Intent intent; |
| 2713 | if (tag instanceof ShortcutInfo) { |
| 2714 | shortcut = (ShortcutInfo) tag; |
| 2715 | intent = shortcut.intent; |
| 2716 | int[] pos = new int[2]; |
| 2717 | v.getLocationOnScreen(pos); |
| 2718 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2719 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2720 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2721 | } else if (tag instanceof AppInfo) { |
| 2722 | shortcut = null; |
| 2723 | intent = ((AppInfo) tag).intent; |
| 2724 | } else { |
| 2725 | throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); |
| 2726 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2727 | |
| 2728 | boolean success = startActivitySafely(v, intent, tag); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2729 | mStats.recordLaunch(intent, shortcut); |
| 2730 | |
| 2731 | if (success && v instanceof BubbleTextView) { |
| 2732 | mWaitingForResume = (BubbleTextView) v; |
| 2733 | mWaitingForResume.setStayPressed(true); |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | /** |
| 2738 | * Event handler for a folder icon click. |
| 2739 | * |
| 2740 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2741 | */ |
| 2742 | protected void onClickFolderIcon(View v) { |
| 2743 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2744 | if (!(v instanceof FolderIcon)){ |
| 2745 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2746 | } |
| 2747 | |
| 2748 | FolderIcon folderIcon = (FolderIcon) v; |
| 2749 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2750 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2751 | |
| 2752 | // If the folder info reports that the associated folder is open, then verify that |
| 2753 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2754 | if (info.opened && openFolder == null) { |
| 2755 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2756 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2757 | info.opened = false; |
| 2758 | } |
| 2759 | |
| 2760 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2761 | // Close any open folder |
| 2762 | closeFolder(); |
| 2763 | // Open the requested folder |
| 2764 | openFolder(folderIcon); |
| 2765 | } else { |
| 2766 | // Find the open folder... |
| 2767 | int folderScreen; |
| 2768 | if (openFolder != null) { |
| 2769 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2770 | // .. and close it |
| 2771 | closeFolder(openFolder); |
| 2772 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2773 | // Close any folder open on the current screen |
| 2774 | closeFolder(); |
| 2775 | // Pull the folder onto this screen |
| 2776 | openFolder(folderIcon); |
| 2777 | } |
| 2778 | } |
| 2779 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2780 | |
| 2781 | if (mLauncherCallbacks != null) { |
| 2782 | mLauncherCallbacks.onClickFolderIcon(v); |
| 2783 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2786 | /** |
| 2787 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2788 | * on the home screen. |
| 2789 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2790 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2791 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2792 | if (mIsSafeModeEnabled) { |
| 2793 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2794 | } else { |
| 2795 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2796 | if (mLauncherCallbacks != null) { |
| 2797 | mLauncherCallbacks.onClickAddWidgetButton(view); |
| 2798 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2799 | } |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2800 | } |
| 2801 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2802 | /** |
| 2803 | * Event handler for the wallpaper picker button that appears after a long press |
| 2804 | * on the home screen. |
| 2805 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2806 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2807 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2808 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2809 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2810 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2811 | |
| 2812 | if (mLauncherCallbacks != null) { |
| 2813 | mLauncherCallbacks.onClickWallpaperPicker(v); |
| 2814 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | /** |
| 2818 | * Event handler for a click on the settings button that appears after a long press |
| 2819 | * on the home screen. |
| 2820 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2821 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2822 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2823 | if (mLauncherCallbacks != null) { |
| 2824 | mLauncherCallbacks.onClickSettingsButton(v); |
| 2825 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2826 | } |
| 2827 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2828 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2829 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2830 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2833 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2834 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2835 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2836 | } |
| 2837 | |
| 2838 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2839 | if (mHapticFeedbackTouchListener == null) { |
| 2840 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2841 | @Override |
| 2842 | public boolean onTouch(View v, MotionEvent event) { |
| 2843 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2844 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2845 | } |
| 2846 | return false; |
| 2847 | } |
| 2848 | }; |
| 2849 | } |
| 2850 | return mHapticFeedbackTouchListener; |
| 2851 | } |
| 2852 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2853 | public void onDragStarted(View view) { |
| 2854 | if (isOnCustomContent()) { |
| 2855 | // Custom content screen doesn't participate in drag and drop. If on custom |
| 2856 | // content screen, move to default. |
| 2857 | moveWorkspaceToDefaultScreen(); |
| 2858 | } |
| 2859 | |
| 2860 | if (mLauncherCallbacks != null) { |
| 2861 | mLauncherCallbacks.onDragStarted(view); |
| 2862 | } |
| 2863 | } |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2864 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2865 | /** |
| 2866 | * Called when the user stops interacting with the launcher. |
| 2867 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2868 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2869 | protected void onInteractionEnd() { |
| 2870 | if (mLauncherCallbacks != null) { |
| 2871 | mLauncherCallbacks.onInteractionEnd(); |
| 2872 | } |
| 2873 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2874 | |
| 2875 | /** |
| 2876 | * Called when the user starts interacting with the launcher. |
| 2877 | * The possible interactions are: |
| 2878 | * - open all apps |
| 2879 | * - reorder an app shortcut, or a widget |
| 2880 | * - open the overview mode. |
| 2881 | * This is a good time to stop doing things that only make sense |
| 2882 | * when the user is on the homescreen and not doing housekeeping. |
| 2883 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2884 | protected void onInteractionBegin() { |
| 2885 | if (mLauncherCallbacks != null) { |
| 2886 | mLauncherCallbacks.onInteractionBegin(); |
| 2887 | } |
| 2888 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2889 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2890 | void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2891 | try { |
| 2892 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2893 | launcherApps.showAppDetailsForProfile(componentName, user); |
| 2894 | } catch (SecurityException e) { |
| 2895 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2896 | Log.e(TAG, "Launcher does not have permission to launch settings"); |
| 2897 | } catch (ActivityNotFoundException e) { |
| 2898 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2899 | Log.e(TAG, "Unable to launch settings"); |
| 2900 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2901 | } |
| 2902 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2903 | // returns true if the activity was started |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2904 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags, |
| 2905 | UserHandleCompat user) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2906 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2907 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2908 | // We may give them the option of disabling apps this way. |
| 2909 | int messageId = R.string.uninstall_system_app_text; |
| 2910 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2911 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2912 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2913 | String packageName = componentName.getPackageName(); |
| 2914 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2915 | Intent intent = new Intent( |
| 2916 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2917 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2918 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2919 | if (user != null) { |
| 2920 | user.addToIntent(intent, Intent.EXTRA_USER); |
| 2921 | } |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2922 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2923 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2924 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2927 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 2928 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2929 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2930 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 2931 | // private contract between launcher and may be ignored in the future). |
| 2932 | boolean useLaunchAnimation = (v != null) && |
| 2933 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2934 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2935 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2936 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2937 | UserHandleCompat user = null; |
| 2938 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 2939 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 2940 | user = userManager.getUserForSerialNumber(serialNumber); |
| 2941 | } |
| 2942 | |
| 2943 | Bundle optsBundle = null; |
Adam Cohen | 68fdeaa | 2015-04-02 11:53:23 -0700 | [diff] [blame] | 2944 | if (useLaunchAnimation && !Utilities.isLmpOrAbove()) { |
| 2945 | // On pre-L devices, we use the scale up transition. |
Adam Cohen | 68fdeaa | 2015-04-02 11:53:23 -0700 | [diff] [blame] | 2946 | ActivityOptions opts = |
Adam Cohen | 4da294d | 2014-07-28 10:56:19 -0700 | [diff] [blame] | 2947 | ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 2948 | optsBundle = opts.toBundle(); |
Adam Cohen | c3d4553 | 2015-05-22 14:36:14 -0700 | [diff] [blame] | 2949 | } else if (useLaunchAnimation && Utilities.isLmpMr1()) { |
| 2950 | // On L-MR1 devices, we use custom slide up animation without a delay |
| 2951 | // On L devices, we use the system default slide up. |
| 2952 | ActivityOptions opts = ActivityOptions.makeCustomAnimation(this, |
| 2953 | R.anim.task_open_enter, R.anim.no_anim); |
| 2954 | optsBundle = opts.toBundle(); |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 2955 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2956 | |
| 2957 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 2958 | // Could be launching some bookkeeping activity |
| 2959 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2960 | } else { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2961 | // TODO Component can be null when shortcuts are supported for secondary user |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 2962 | launcherApps.startActivityForProfile(intent.getComponent(), user, |
| 2963 | intent.getSourceBounds(), optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2964 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2965 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2966 | } catch (SecurityException e) { |
| 2967 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2968 | 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] | 2969 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2970 | "or use the exported attribute for this activity. " |
| 2971 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2972 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2973 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2974 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2975 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2976 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 2977 | boolean success = false; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2978 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 2979 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 2980 | return false; |
| 2981 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2982 | try { |
| 2983 | success = startActivity(v, intent, tag); |
| 2984 | } catch (ActivityNotFoundException e) { |
| 2985 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2986 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 2987 | } |
| 2988 | return success; |
| 2989 | } |
| 2990 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2991 | /** |
| 2992 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 2993 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 2994 | */ |
| 2995 | private void copyFolderIconToImage(FolderIcon fi) { |
| 2996 | final int width = fi.getMeasuredWidth(); |
| 2997 | final int height = fi.getMeasuredHeight(); |
| 2998 | |
| 2999 | // Lazy load ImageView, Bitmap and Canvas |
| 3000 | if (mFolderIconImageView == null) { |
| 3001 | mFolderIconImageView = new ImageView(this); |
| 3002 | } |
| 3003 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 3004 | mFolderIconBitmap.getHeight() != height) { |
| 3005 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 3006 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 3007 | } |
| 3008 | |
| 3009 | DragLayer.LayoutParams lp; |
| 3010 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 3011 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 3012 | } else { |
| 3013 | lp = new DragLayer.LayoutParams(width, height); |
| 3014 | } |
| 3015 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 3016 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 3017 | // view size by this scale factor. |
| 3018 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3019 | lp.customPosition = true; |
| 3020 | lp.x = mRectForFolderAnimation.left; |
| 3021 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 3022 | lp.width = (int) (scale * width); |
| 3023 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3024 | |
| 3025 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 3026 | fi.draw(mFolderIconCanvas); |
| 3027 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3028 | if (fi.getFolder() != null) { |
| 3029 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 3030 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3031 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3032 | // Just in case this image view is still in the drag layer from a previous animation, |
| 3033 | // we remove it and re-add it. |
| 3034 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 3035 | mDragLayer.removeView(mFolderIconImageView); |
| 3036 | } |
| 3037 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3038 | if (fi.getFolder() != null) { |
| 3039 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3040 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3043 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3044 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3045 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 3046 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 3047 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 3048 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3049 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 3050 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3051 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 3052 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 3053 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3054 | } |
| 3055 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3056 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 3057 | copyFolderIconToImage(fi); |
| 3058 | fi.setVisibility(View.INVISIBLE); |
| 3059 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3060 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3061 | scaleX, scaleY); |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3062 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3063 | oa.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3064 | } |
| 3065 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3066 | oa.start(); |
| 3067 | } |
| 3068 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3069 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3070 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3071 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 3072 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 3073 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 3074 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3075 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3076 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3077 | // We remove and re-draw the FolderIcon in-case it has changed |
| 3078 | mDragLayer.removeView(mFolderIconImageView); |
| 3079 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3080 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3081 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3082 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3083 | oa.addListener(new AnimatorListenerAdapter() { |
| 3084 | @Override |
| 3085 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3086 | if (cl != null) { |
| 3087 | cl.clearFolderLeaveBehind(); |
| 3088 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 3089 | mDragLayer.removeView(mFolderIconImageView); |
| 3090 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3094 | oa.start(); |
| 3095 | } |
| 3096 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3097 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 3098 | * 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] | 3099 | * is animated relative to the specified View. If the View is null, no animation |
| 3100 | * is played. |
| 3101 | * |
| 3102 | * @param folderInfo The FolderInfo describing the folder to open. |
| 3103 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3104 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3105 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3106 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3107 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3108 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3109 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3110 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 3111 | // There was a one-off crash where the folder had a parent already. |
| 3112 | if (folder.getParent() == null) { |
| 3113 | mDragLayer.addView(folder); |
| 3114 | mDragController.addDropTarget((DropTarget) folder); |
| 3115 | } else { |
| 3116 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 3117 | folder.getParent() + ")."); |
| 3118 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3119 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3120 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3121 | |
| 3122 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 3123 | // the workspace items |
| 3124 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 3125 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 3129 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3130 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 3131 | if (folder.isEditingName()) { |
| 3132 | folder.dismissEditingName(); |
| 3133 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3134 | closeFolder(folder); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | void closeFolder(Folder folder) { |
| 3139 | folder.getInfo().opened = false; |
| 3140 | |
| 3141 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 3142 | if (parent != null) { |
| 3143 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 3144 | shrinkAndFadeInFolderIcon(fi); |
| 3145 | } |
| 3146 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3147 | |
| 3148 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 3149 | // longer occludeds the workspace items |
| 3150 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3151 | } |
| 3152 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3153 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 3154 | if (!isDraggingEnabled()) return false; |
| 3155 | if (isWorkspaceLocked()) return false; |
| 3156 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3157 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3158 | if (v instanceof Workspace) { |
| 3159 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 3160 | if (mWorkspace.enterOverviewMode()) { |
| 3161 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3162 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 3163 | return true; |
| 3164 | } else { |
| 3165 | return false; |
| 3166 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 3167 | } else { |
| 3168 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3169 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3170 | } |
| 3171 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 3172 | CellLayout.CellInfo longClickCellInfo = null; |
| 3173 | View itemUnderLongClick = null; |
| 3174 | if (v.getTag() instanceof ItemInfo) { |
| 3175 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3176 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 3177 | itemUnderLongClick = longClickCellInfo.cell; |
| 3178 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3179 | } |
| 3180 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3181 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 3182 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3183 | final boolean inHotseat = isHotseatLayout(v); |
| 3184 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3185 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3186 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3187 | // User long pressed on empty space |
| 3188 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3189 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3190 | if (mWorkspace.isInOverviewMode()) { |
| 3191 | mWorkspace.startReordering(v); |
| 3192 | } else { |
| 3193 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 3194 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3195 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3196 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 3197 | mHotseat.getOrderInHotseat( |
| 3198 | longClickCellInfo.cellX, |
| 3199 | longClickCellInfo.cellY)); |
| 3200 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3201 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3202 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3203 | } |
| 3204 | } |
| 3205 | } |
| 3206 | return true; |
| 3207 | } |
| 3208 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3209 | boolean isHotseatLayout(View layout) { |
| 3210 | return mHotseat != null && layout != null && |
| 3211 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 3212 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 3213 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3214 | /** |
| 3215 | * Returns the CellLayout of the specified container at the specified screen. |
| 3216 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3217 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3218 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3219 | if (mHotseat != null) { |
| 3220 | return mHotseat.getLayout(); |
| 3221 | } else { |
| 3222 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 3223 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3224 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3225 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 3226 | } |
| 3227 | } |
| 3228 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3229 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3230 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 3231 | } |
| 3232 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3233 | private void setWorkspaceBackground(boolean workspace) { |
| 3234 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 3235 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3236 | } |
| 3237 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 3238 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3239 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 3240 | int curflags = getWindow().getAttributes().flags |
| 3241 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 3242 | if (wpflags != curflags) { |
| 3243 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 3244 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3245 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3246 | } |
| 3247 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3248 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3249 | if (v instanceof LauncherTransitionable) { |
| 3250 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3251 | } |
| 3252 | } |
| 3253 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3254 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3255 | if (v instanceof LauncherTransitionable) { |
| 3256 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3257 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3258 | |
| 3259 | // Update the workspace transition step as well |
| 3260 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3261 | } |
| 3262 | |
| 3263 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3264 | if (v instanceof LauncherTransitionable) { |
| 3265 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3266 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3270 | if (v instanceof LauncherTransitionable) { |
| 3271 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3272 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3273 | |
| 3274 | // Update the workspace transition step as well |
| 3275 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3276 | } |
| 3277 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3278 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3279 | * Things to test when changing the following seven functions. |
| 3280 | * - Home from workspace |
| 3281 | * - from center screen |
| 3282 | * - from other screens |
| 3283 | * - Home from all apps |
| 3284 | * - from center screen |
| 3285 | * - from other screens |
| 3286 | * - Back from all apps |
| 3287 | * - from center screen |
| 3288 | * - from other screens |
| 3289 | * - Launch app from workspace and quit |
| 3290 | * - with back |
| 3291 | * - with home |
| 3292 | * - Launch app from all apps and quit |
| 3293 | * - with back |
| 3294 | * - with home |
| 3295 | * - Go to a screen that's not the default, then all |
| 3296 | * apps, and launch and app, and go back |
| 3297 | * - with back |
| 3298 | * -with home |
| 3299 | * - On workspace, long press power and go back |
| 3300 | * - with back |
| 3301 | * - with home |
| 3302 | * - On all apps, long press power and go back |
| 3303 | * - with back |
| 3304 | * - with home |
| 3305 | * - On workspace, power off |
| 3306 | * - On all apps, power off |
| 3307 | * - Launch an app and turn off the screen while in that app |
| 3308 | * - Go back with home key |
| 3309 | * - Go back with back key TODO: make this not go to workspace |
| 3310 | * - From all apps |
| 3311 | * - From workspace |
| 3312 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3313 | * - From all apps |
| 3314 | * - From the center workspace |
| 3315 | * - From another workspace |
| 3316 | */ |
| 3317 | |
| 3318 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3319 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3320 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3321 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3322 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3323 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3324 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3325 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3326 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3327 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 3328 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3329 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3330 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3331 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3332 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3333 | mStateAnimation.cancel(); |
| 3334 | mStateAnimation = null; |
| 3335 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3336 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3337 | boolean material = Utilities.isLmpOrAbove(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3338 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3339 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3340 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3341 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3342 | final int itemsAlphaStagger = |
| 3343 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3344 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3345 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3346 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3347 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3348 | final HashMap<View, Integer> layerViews = new HashMap<View, Integer>(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3349 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3350 | Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? |
| 3351 | Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3352 | Animator workspaceAnim = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3353 | mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3354 | if (!LauncherAppState.isDisableAllApps() |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3355 | || contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3356 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3357 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3358 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3359 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3360 | // If for some reason our views aren't initialized, don't animate |
| 3361 | boolean initialized = getAllAppsButton() != null; |
| 3362 | |
| 3363 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3364 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3365 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3366 | toView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3367 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3368 | final View page = content.getPageAt(content.getCurrentPage()); |
| 3369 | final View revealView = toView.findViewById(R.id.fake_page); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3370 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3371 | final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; |
| 3372 | if (isWidgetTray) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3373 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3374 | } else { |
| 3375 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3376 | } |
| 3377 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3378 | // Hide the real page background, and swap in the fake one |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3379 | content.setPageBackgroundsVisible(false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3380 | revealView.setVisibility(View.VISIBLE); |
| 3381 | // We need to hide this view as the animation start will be posted. |
| 3382 | revealView.setAlpha(0); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3383 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3384 | int width = revealView.getMeasuredWidth(); |
| 3385 | int height = revealView.getMeasuredHeight(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3386 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3387 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3388 | revealView.setTranslationY(0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3389 | revealView.setTranslationX(0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3390 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3391 | // Get the y delta between the center of the page and the center of the all apps button |
| 3392 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3393 | getAllAppsButton(), null); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3394 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3395 | float alpha = 0; |
| 3396 | float xDrift = 0; |
| 3397 | float yDrift = 0; |
| 3398 | if (material) { |
| 3399 | alpha = isWidgetTray ? 0.3f : 1f; |
| 3400 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3401 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3402 | } else { |
| 3403 | yDrift = 2 * height / 3; |
| 3404 | xDrift = 0; |
| 3405 | } |
| 3406 | final float initAlpha = alpha; |
| 3407 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3408 | layerViews.put(revealView, BUILD_AND_SET_LAYER); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3409 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3410 | PropertyValuesHolder panelDriftY = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3411 | PropertyValuesHolder.ofFloat("translationY", yDrift, 0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3412 | PropertyValuesHolder panelDriftX = |
| 3413 | PropertyValuesHolder.ofFloat("translationX", xDrift, 0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3414 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3415 | ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, |
| 3416 | panelAlpha, panelDriftY, panelDriftX); |
| 3417 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3418 | panelAlphaAndDrift.setDuration(revealDuration); |
| 3419 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3420 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3421 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3422 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3423 | if (page != null) { |
| 3424 | page.setVisibility(View.VISIBLE); |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3425 | layerViews.put(page, BUILD_AND_SET_LAYER); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3426 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3427 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0); |
| 3428 | page.setTranslationY(yDrift); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3429 | pageDrift.setDuration(revealDuration); |
| 3430 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3431 | pageDrift.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3432 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3433 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3434 | page.setAlpha(0f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3435 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3436 | itemsAlpha.setDuration(revealDuration); |
| 3437 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 3438 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
| 3439 | mStateAnimation.play(itemsAlpha); |
| 3440 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3441 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3442 | View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); |
| 3443 | pageIndicators.setAlpha(0.01f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3444 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3445 | ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3446 | indicatorsAlpha.setDuration(revealDuration); |
| 3447 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3448 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3449 | if (material) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3450 | final View allApps = getAllAppsButton(); |
| 3451 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3452 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3453 | float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3454 | Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3455 | height / 2, startRadius, revealRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3456 | reveal.setDuration(revealDuration); |
| 3457 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3458 | |
| 3459 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3460 | public void onAnimationStart(Animator animation) { |
| 3461 | if (!isWidgetTray) { |
| 3462 | allApps.setVisibility(View.INVISIBLE); |
| 3463 | } |
| 3464 | } |
| 3465 | public void onAnimationEnd(Animator animation) { |
| 3466 | if (!isWidgetTray) { |
| 3467 | allApps.setVisibility(View.VISIBLE); |
| 3468 | } |
| 3469 | } |
| 3470 | }); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3471 | mStateAnimation.play(reveal); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3472 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3473 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3474 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
| 3475 | @Override |
| 3476 | public void onAnimationEnd(Animator animation) { |
| 3477 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3478 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 3479 | |
| 3480 | revealView.setVisibility(View.INVISIBLE); |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3481 | |
| 3482 | for (View v : layerViews.keySet()) { |
| 3483 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 3484 | v.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3485 | } |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3486 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3487 | content.setPageBackgroundsVisible(true); |
| 3488 | |
| 3489 | // Hide the search bar |
| 3490 | if (mSearchDropTargetBar != null) { |
| 3491 | mSearchDropTargetBar.hideSearchBar(false); |
| 3492 | } |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3493 | |
| 3494 | // This can hold unnecessary references to views. |
| 3495 | mStateAnimation = null; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3498 | }); |
| 3499 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3500 | if (workspaceAnim != null) { |
| 3501 | mStateAnimation.play(workspaceAnim); |
| 3502 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3503 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3504 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3505 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3506 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3507 | final Runnable startAnimRunnable = new Runnable() { |
| 3508 | public void run() { |
| 3509 | // Check that mStateAnimation hasn't changed while |
| 3510 | // we waited for a layout/draw pass |
| 3511 | if (mStateAnimation != stateAnimation) |
| 3512 | return; |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3513 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3514 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3515 | |
| 3516 | revealView.setAlpha(initAlpha); |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3517 | |
| 3518 | for (View v : layerViews.keySet()) { |
| 3519 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 3520 | v.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3521 | } |
| 3522 | } |
| 3523 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3524 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3525 | for (View v : layerViews.keySet()) { |
| 3526 | if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3527 | } |
| 3528 | } |
| 3529 | mStateAnimation.start(); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3530 | } |
| 3531 | }; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3532 | toView.bringToFront(); |
| 3533 | toView.setVisibility(View.VISIBLE); |
| 3534 | toView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3535 | } else { |
| 3536 | toView.setTranslationX(0.0f); |
| 3537 | toView.setTranslationY(0.0f); |
| 3538 | toView.setScaleX(1.0f); |
| 3539 | toView.setScaleY(1.0f); |
| 3540 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3541 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3542 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3543 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3544 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3545 | if (mSearchDropTargetBar != null) { |
| 3546 | mSearchDropTargetBar.hideSearchBar(false); |
| 3547 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3548 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3549 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3550 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3551 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3552 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3553 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3554 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3555 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | /** |
| 3559 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3560 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3561 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3562 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3563 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3564 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3565 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3566 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3567 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3568 | mStateAnimation.cancel(); |
| 3569 | mStateAnimation = null; |
| 3570 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3571 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3572 | boolean material = Utilities.isLmpOrAbove(); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3573 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3574 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3575 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3576 | final int itemsAlphaStagger = |
| 3577 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3578 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3579 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3580 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3581 | Animator workspaceAnim = null; |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3582 | final HashMap<View, Integer> layerViews = new HashMap<View, Integer>(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3583 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3584 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3585 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3586 | toState, animated, layerViews); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3587 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3588 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3589 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3590 | toState, animated, layerViews); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3591 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3592 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3593 | // If for some reason our views aren't initialized, don't animate |
| 3594 | boolean initialized = getAllAppsButton() != null; |
| 3595 | |
| 3596 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3597 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3598 | if (workspaceAnim != null) { |
| 3599 | mStateAnimation.play(workspaceAnim); |
| 3600 | } |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3601 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3602 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3603 | fromView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3604 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3605 | final View page = content.getPageAt(content.getNextPage()); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3606 | |
| 3607 | // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases |
| 3608 | int count = content.getChildCount(); |
| 3609 | for (int i = 0; i < count; i++) { |
| 3610 | View child = content.getChildAt(i); |
| 3611 | if (child != page) { |
| 3612 | child.setVisibility(View.INVISIBLE); |
| 3613 | } |
| 3614 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3615 | final View revealView = fromView.findViewById(R.id.fake_page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3616 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3617 | // hideAppsCustomizeHelper is called in some cases when it is already hidden |
| 3618 | // don't perform all these no-op animations. In particularly, this was causing |
| 3619 | // the all-apps button to pop in and out. |
| 3620 | if (fromView.getVisibility() == View.VISIBLE) { |
| 3621 | AppsCustomizePagedView.ContentType contentType = content.getContentType(); |
| 3622 | final boolean isWidgetTray = |
| 3623 | contentType == AppsCustomizePagedView.ContentType.Widgets; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3624 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3625 | if (isWidgetTray) { |
| 3626 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3627 | } else { |
| 3628 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3629 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3630 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3631 | int width = revealView.getMeasuredWidth(); |
| 3632 | int height = revealView.getMeasuredHeight(); |
| 3633 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
| 3634 | |
| 3635 | // Hide the real page background, and swap in the fake one |
| 3636 | revealView.setVisibility(View.VISIBLE); |
| 3637 | content.setPageBackgroundsVisible(false); |
| 3638 | |
| 3639 | final View allAppsButton = getAllAppsButton(); |
| 3640 | revealView.setTranslationY(0); |
| 3641 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3642 | allAppsButton, null); |
| 3643 | |
| 3644 | float xDrift = 0; |
| 3645 | float yDrift = 0; |
| 3646 | if (material) { |
| 3647 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3648 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3649 | } else { |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3650 | yDrift = 2 * height / 3; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3651 | xDrift = 0; |
| 3652 | } |
| 3653 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3654 | layerViews.put(revealView, BUILD_AND_SET_LAYER); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3655 | TimeInterpolator decelerateInterpolator = material ? |
| 3656 | new LogDecelerateInterpolator(100, 0) : |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3657 | new DecelerateInterpolator(1f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3658 | |
| 3659 | // The vertical motion of the apps panel should be delayed by one frame |
| 3660 | // from the conceal animation in order to give the right feel. We correpsondingly |
| 3661 | // shorten the duration so that the slide and conceal end at the same time. |
| 3662 | ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", |
| 3663 | 0, yDrift); |
| 3664 | panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3665 | panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3666 | panelDriftY.setInterpolator(decelerateInterpolator); |
| 3667 | mStateAnimation.play(panelDriftY); |
| 3668 | |
| 3669 | ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", |
| 3670 | 0, xDrift); |
| 3671 | panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3672 | panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3673 | panelDriftX.setInterpolator(decelerateInterpolator); |
| 3674 | mStateAnimation.play(panelDriftX); |
| 3675 | |
| 3676 | if (isWidgetTray || !material) { |
| 3677 | float finalAlpha = material ? 0.4f : 0f; |
| 3678 | revealView.setAlpha(1f); |
| 3679 | ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", |
| 3680 | 1f, finalAlpha); |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3681 | panelAlpha.setDuration(material ? revealDuration : 150); |
| 3682 | panelAlpha.setInterpolator(decelerateInterpolator); |
| 3683 | panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3684 | mStateAnimation.play(panelAlpha); |
| 3685 | } |
| 3686 | |
| 3687 | if (page != null) { |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3688 | layerViews.put(page, BUILD_AND_SET_LAYER); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3689 | |
| 3690 | ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", |
| 3691 | 0, yDrift); |
| 3692 | page.setTranslationY(0); |
| 3693 | pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3694 | pageDrift.setInterpolator(decelerateInterpolator); |
| 3695 | pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3696 | mStateAnimation.play(pageDrift); |
| 3697 | |
| 3698 | page.setAlpha(1f); |
| 3699 | ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f); |
| 3700 | itemsAlpha.setDuration(100); |
| 3701 | itemsAlpha.setInterpolator(decelerateInterpolator); |
| 3702 | mStateAnimation.play(itemsAlpha); |
| 3703 | } |
| 3704 | |
| 3705 | View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); |
| 3706 | pageIndicators.setAlpha(1f); |
| 3707 | ObjectAnimator indicatorsAlpha = |
| 3708 | LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f); |
| 3709 | indicatorsAlpha.setDuration(revealDuration); |
| 3710 | indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 3711 | mStateAnimation.play(indicatorsAlpha); |
| 3712 | |
| 3713 | width = revealView.getMeasuredWidth(); |
| 3714 | |
| 3715 | if (material) { |
| 3716 | if (!isWidgetTray) { |
| 3717 | allAppsButton.setVisibility(View.INVISIBLE); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3718 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3719 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3720 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3721 | float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
| 3722 | Animator reveal = |
| 3723 | LauncherAnimUtils.createCircularReveal(revealView, width / 2, |
| 3724 | height / 2, revealRadius, finalRadius); |
| 3725 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3726 | reveal.setDuration(revealDuration); |
| 3727 | reveal.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3728 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3729 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3730 | public void onAnimationEnd(Animator animation) { |
| 3731 | revealView.setVisibility(View.INVISIBLE); |
| 3732 | if (!isWidgetTray) { |
| 3733 | allAppsButton.setVisibility(View.VISIBLE); |
| 3734 | } |
| 3735 | } |
| 3736 | }); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3737 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3738 | mStateAnimation.play(reveal); |
| 3739 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3740 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3741 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3742 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 3743 | mAppsCustomizeContent.stopScrolling(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3744 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3745 | |
| 3746 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3747 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3748 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3749 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3750 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3751 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3752 | if (onCompleteRunnable != null) { |
| 3753 | onCompleteRunnable.run(); |
| 3754 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3755 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3756 | for (View v : layerViews.keySet()) { |
| 3757 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 3758 | v.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3759 | } |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3760 | } |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3761 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3762 | content.setPageBackgroundsVisible(true); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3763 | // Unhide side pages |
| 3764 | int count = content.getChildCount(); |
| 3765 | for (int i = 0; i < count; i++) { |
| 3766 | View child = content.getChildAt(i); |
| 3767 | child.setVisibility(View.VISIBLE); |
| 3768 | } |
| 3769 | |
| 3770 | // Reset page transforms |
Adam Cohen | 493f6bc | 2014-09-18 08:11:05 -0700 | [diff] [blame] | 3771 | if (page != null) { |
| 3772 | page.setTranslationX(0); |
| 3773 | page.setTranslationY(0); |
| 3774 | page.setAlpha(1); |
| 3775 | } |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3776 | content.setCurrentPage(content.getNextPage()); |
| 3777 | |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3778 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3779 | |
| 3780 | // This can hold unnecessary references to views. |
| 3781 | mStateAnimation = null; |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3782 | } |
| 3783 | }); |
| 3784 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3785 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3786 | final Runnable startAnimRunnable = new Runnable() { |
| 3787 | public void run() { |
| 3788 | // Check that mStateAnimation hasn't changed while |
| 3789 | // we waited for a layout/draw pass |
| 3790 | if (mStateAnimation != stateAnimation) |
| 3791 | return; |
| 3792 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3793 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3794 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3795 | for (View v : layerViews.keySet()) { |
| 3796 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 3797 | v.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3798 | } |
| 3799 | } |
| 3800 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3801 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3802 | for (View v : layerViews.keySet()) { |
| 3803 | if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | mStateAnimation.start(); |
| 3807 | } |
| 3808 | }; |
| 3809 | fromView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3810 | } else { |
| 3811 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3812 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3813 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3814 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3815 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3816 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3817 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3818 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3821 | @Override |
| 3822 | public void onTrimMemory(int level) { |
| 3823 | super.onTrimMemory(level); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3824 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
| 3825 | // The widget preview db can result in holding onto over |
| 3826 | // 3MB of memory for caching which isn't necessary. |
| 3827 | SQLiteDatabase.releaseMemory(); |
| 3828 | |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 3829 | // This clears all widget bitmaps from the widget tray |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3830 | if (mAppsCustomizeTabHost != null) { |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 3831 | mAppsCustomizeTabHost.trimMemory(); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3832 | } |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3833 | } |
Robert Kozikowski | 67c3086 | 2015-03-30 23:46:46 +0100 | [diff] [blame] | 3834 | if (mLauncherCallbacks != null) { |
| 3835 | mLauncherCallbacks.onTrimMemory(level); |
| 3836 | } |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3837 | } |
| 3838 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3839 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3840 | showWorkspace(animated, null); |
| 3841 | } |
| 3842 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3843 | protected void showWorkspace() { |
| 3844 | showWorkspace(true); |
| 3845 | } |
| 3846 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3847 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 3848 | if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3849 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3850 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3851 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3852 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3853 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3854 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3855 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3856 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3857 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3858 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3859 | // Set focus to the AppsCustomize button |
| 3860 | if (mAllAppsButton != null) { |
| 3861 | mAllAppsButton.requestFocus(); |
| 3862 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3863 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3864 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3865 | // Change the state *after* we've called all the transition code |
| 3866 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3867 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3868 | // Resume the auto-advance of widgets |
| 3869 | mUserPresent = true; |
| 3870 | updateRunning(); |
| 3871 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3872 | // Send an accessibility event to announce the context change |
| 3873 | getWindow().getDecorView() |
| 3874 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3875 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3876 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3877 | } |
| 3878 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3879 | void showOverviewMode(boolean animated) { |
| 3880 | mWorkspace.setVisibility(View.VISIBLE); |
| 3881 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3882 | mState = State.WORKSPACE; |
| 3883 | onWorkspaceShown(animated); |
| 3884 | } |
| 3885 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3886 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3887 | } |
| 3888 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3889 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3890 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3891 | if (mState != State.WORKSPACE) return; |
| 3892 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3893 | if (resetPageToZero) { |
| 3894 | mAppsCustomizeTabHost.reset(); |
| 3895 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3896 | showAppsCustomizeHelper(animated, false, contentType); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 3897 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3898 | @Override |
| 3899 | public void run() { |
| 3900 | // We post this in-case the all apps view isn't yet constructed. |
| 3901 | mAppsCustomizeTabHost.requestFocus(); |
| 3902 | } |
| 3903 | }); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3904 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3905 | // Change the state *after* we've called all the transition code |
| 3906 | mState = State.APPS_CUSTOMIZE; |
| 3907 | |
| 3908 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3909 | mUserPresent = false; |
| 3910 | updateRunning(); |
| 3911 | closeFolder(); |
| 3912 | |
| 3913 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3914 | getWindow().getDecorView() |
| 3915 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3918 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3919 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3920 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3921 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3922 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3923 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3924 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3925 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3926 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3927 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 3928 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 3929 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3930 | @Override |
| 3931 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3932 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3933 | // Before we show workspace, hide all apps again because |
| 3934 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 3935 | // clean up our state transition functions |
| 3936 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3937 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3938 | } else { |
| 3939 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3940 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3941 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3942 | }, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3943 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3944 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3945 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3946 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3947 | final boolean animated = true; |
| 3948 | final boolean springLoaded = true; |
| 3949 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3950 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3951 | } |
| 3952 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 3953 | } |
| 3954 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3955 | void lockAllApps() { |
| 3956 | // TODO |
| 3957 | } |
| 3958 | |
| 3959 | void unlockAllApps() { |
| 3960 | // TODO |
| 3961 | } |
| 3962 | |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3963 | protected void disableVoiceButtonProxy(boolean disable) { |
| 3964 | // NO-OP |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3965 | } |
| 3966 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3967 | public View getQsbBar() { |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 3968 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 3969 | return mLauncherCallbacks.getQsbBar(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3972 | if (mQsb == null) { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3973 | AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this); |
| 3974 | if (searchProvider == null) { |
| 3975 | return null; |
| 3976 | } |
| 3977 | |
| 3978 | Bundle opts = new Bundle(); |
| 3979 | opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, |
| 3980 | AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); |
| 3981 | |
| 3982 | SharedPreferences sp = getSharedPreferences( |
| 3983 | LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE); |
| 3984 | int widgetId = sp.getInt(QSB_WIDGET_ID, -1); |
Sunny Goyal | 416541c | 2014-11-14 11:59:57 -0800 | [diff] [blame] | 3985 | AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3986 | if (!searchProvider.provider.flattenToString().equals( |
| 3987 | sp.getString(QSB_WIDGET_PROVIDER, null)) |
Sunny Goyal | 416541c | 2014-11-14 11:59:57 -0800 | [diff] [blame] | 3988 | || (widgetInfo == null) |
| 3989 | || !widgetInfo.provider.equals(searchProvider.provider)) { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3990 | // A valid widget is not already bound. |
| 3991 | if (widgetId > -1) { |
| 3992 | mAppWidgetHost.deleteAppWidgetId(widgetId); |
| 3993 | widgetId = -1; |
| 3994 | } |
| 3995 | |
| 3996 | // Try to bind a new widget |
| 3997 | widgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 3998 | |
| 3999 | if (!AppWidgetManagerCompat.getInstance(this) |
| 4000 | .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) { |
| 4001 | mAppWidgetHost.deleteAppWidgetId(widgetId); |
| 4002 | widgetId = -1; |
| 4003 | } |
| 4004 | |
| 4005 | sp.edit() |
| 4006 | .putInt(QSB_WIDGET_ID, widgetId) |
| 4007 | .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString()) |
| 4008 | .commit(); |
| 4009 | } |
| 4010 | |
| 4011 | if (widgetId != -1) { |
| 4012 | mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider); |
| 4013 | mQsb.updateAppWidgetOptions(opts); |
| 4014 | mQsb.setPadding(0, 0, 0, 0); |
| 4015 | mSearchDropTargetBar.addView(mQsb); |
| 4016 | } |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4017 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 4018 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4019 | } |
| 4020 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4021 | @Override |
| 4022 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4023 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4024 | final List<CharSequence> text = event.getText(); |
| 4025 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4026 | // Populate event with a fake title based on the current state. |
| 4027 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4028 | text.add(mAppsCustomizeTabHost.getContentTag()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4029 | } else { |
| 4030 | text.add(getString(R.string.all_apps_home_button_label)); |
| 4031 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4032 | return result; |
| 4033 | } |
| 4034 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4035 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 4036 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4037 | */ |
| 4038 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 4039 | @Override |
| 4040 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4041 | closeSystemDialogs(); |
| 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 4046 | * Receives notifications whenever the appwidgets are reset. |
| 4047 | */ |
| 4048 | private class AppWidgetResetObserver extends ContentObserver { |
| 4049 | public AppWidgetResetObserver() { |
| 4050 | super(new Handler()); |
| 4051 | } |
| 4052 | |
| 4053 | @Override |
| 4054 | public void onChange(boolean selfChange) { |
| 4055 | onAppWidgetReset(); |
| 4056 | } |
| 4057 | } |
| 4058 | |
| 4059 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4060 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 4061 | * in onResume. |
| 4062 | * |
| 4063 | * This needs to be called from incoming places where resources might have been loaded |
| 4064 | * while we are paused. That is becaues the Configuration might be wrong |
| 4065 | * when we're not running, and if it comes back to what it was when we |
| 4066 | * were paused, we are not restarted. |
| 4067 | * |
| 4068 | * Implementation of the method from LauncherModel.Callbacks. |
| 4069 | * |
| 4070 | * @return true if we are currently paused. The caller might be able to |
| 4071 | * skip some work in that case since we will come back again. |
| 4072 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4073 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4074 | if (mPaused) { |
| 4075 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4076 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4077 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4078 | } |
| 4079 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4080 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4081 | return true; |
| 4082 | } else { |
| 4083 | return false; |
| 4084 | } |
| 4085 | } |
| 4086 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4087 | private boolean waitUntilResume(Runnable run) { |
| 4088 | return waitUntilResume(run, false); |
| 4089 | } |
| 4090 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4091 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 4092 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4095 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4096 | * If the activity is currently paused, signal that we need to re-run the loader |
| 4097 | * in onResume. |
| 4098 | * |
| 4099 | * This needs to be called from incoming places where resources might have been loaded |
| 4100 | * while we are paused. That is becaues the Configuration might be wrong |
| 4101 | * when we're not running, and if it comes back to what it was when we |
| 4102 | * were paused, we are not restarted. |
| 4103 | * |
| 4104 | * Implementation of the method from LauncherModel.Callbacks. |
| 4105 | * |
| 4106 | * @return true if we are currently paused. The caller might be able to |
| 4107 | * skip some work in that case since we will come back again. |
| 4108 | */ |
| 4109 | public boolean setLoadOnResume() { |
| 4110 | if (mPaused) { |
| 4111 | Log.i(TAG, "setLoadOnResume"); |
| 4112 | mOnResumeNeedsLoad = true; |
| 4113 | return true; |
| 4114 | } else { |
| 4115 | return false; |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4120 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4121 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4122 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4123 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4124 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4125 | } else { |
| 4126 | return SCREEN_COUNT / 2; |
| 4127 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4128 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4129 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4130 | /** |
| 4131 | * Refreshes the shortcuts shown on the workspace. |
| 4132 | * |
| 4133 | * Implementation of the method from LauncherModel.Callbacks. |
| 4134 | */ |
| 4135 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4136 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 4137 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4138 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 4139 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 4140 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4141 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4142 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4143 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4144 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 4145 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4146 | |
Michael Jurka | 05bf644 | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 4147 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4148 | if (mHotseat != null) { |
| 4149 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4150 | } |
| 4151 | } |
| 4152 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4153 | @Override |
| 4154 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4155 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4156 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 4157 | // If there are no screens, we need to have an empty screen |
| 4158 | if (orderedScreenIds.size() == 0) { |
| 4159 | mWorkspace.addExtraEmptyScreen(); |
| 4160 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4161 | |
| 4162 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4163 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 4164 | if (hasCustomContentToLeft()) { |
| 4165 | mWorkspace.createCustomContentContainer(); |
| 4166 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4167 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | @Override |
| 4171 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 4172 | // Log to disk |
| 4173 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 4174 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 4175 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4176 | int count = orderedScreenIds.size(); |
| 4177 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 4178 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4179 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4180 | } |
| 4181 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 4182 | @Override |
| 4183 | public void bindAddPendingItem(final PendingAddItemInfo info, final long container, |
| 4184 | final long screenId, final int[] cell, final int spanX, final int spanY) { |
| 4185 | showWorkspace(true, new Runnable() { |
| 4186 | |
| 4187 | @Override |
| 4188 | public void run() { |
| 4189 | mWorkspace.snapToPage(mWorkspace.getPageIndexForScreenId(screenId)); |
| 4190 | addPendingItem(info, container, screenId, cell, spanX, spanY); |
| 4191 | } |
| 4192 | }); |
| 4193 | } |
| 4194 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4195 | private boolean shouldShowWeightWatcher() { |
| 4196 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4197 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 4198 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4199 | |
| 4200 | return show; |
| 4201 | } |
| 4202 | |
| 4203 | private void toggleShowWeightWatcher() { |
| 4204 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4205 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 4206 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 4207 | |
| 4208 | show = !show; |
| 4209 | |
| 4210 | SharedPreferences.Editor editor = sp.edit(); |
| 4211 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 4212 | editor.commit(); |
| 4213 | |
| 4214 | if (mWeightWatcher != null) { |
| 4215 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 4216 | } |
| 4217 | } |
| 4218 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4219 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 4220 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4221 | final ArrayList<ItemInfo> addAnimated, |
| 4222 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4223 | Runnable r = new Runnable() { |
| 4224 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4225 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4226 | } |
| 4227 | }; |
| 4228 | if (waitUntilResume(r)) { |
| 4229 | return; |
| 4230 | } |
| 4231 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4232 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4233 | if (newScreens != null) { |
| 4234 | bindAddScreens(newScreens); |
| 4235 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4236 | |
| 4237 | // We add the items without animation on non-visible pages, and with |
| 4238 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4239 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4240 | bindItems(addNotAnimated, 0, |
| 4241 | addNotAnimated.size(), false); |
| 4242 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4243 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4244 | bindItems(addAnimated, 0, |
| 4245 | addAnimated.size(), true); |
| 4246 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4247 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4248 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 4249 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4250 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4251 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4252 | addedApps != null && mAppsCustomizeContent != null) { |
| 4253 | mAppsCustomizeContent.addApps(addedApps); |
| 4254 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4257 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4258 | * Bind the items start-end from the list. |
| 4259 | * |
| 4260 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4261 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4262 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 4263 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4264 | Runnable r = new Runnable() { |
| 4265 | public void run() { |
| 4266 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 4267 | } |
| 4268 | }; |
| 4269 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4270 | return; |
| 4271 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4272 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4273 | // 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] | 4274 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 4275 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4276 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4277 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4278 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4279 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4280 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4281 | |
| 4282 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4283 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4284 | mHotseat == null) { |
| 4285 | continue; |
| 4286 | } |
| 4287 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4288 | switch (item.itemType) { |
| 4289 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4290 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4291 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4292 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4293 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4294 | /* |
| 4295 | * TODO: FIX collision case |
| 4296 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4297 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4298 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4299 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4300 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4301 | Object tag = v.getTag(); |
| 4302 | String desc = "Collision while binding workspace item: " + item |
| 4303 | + ". Collides with " + tag; |
| 4304 | if (LauncherAppState.isDogfoodBuild()) { |
| 4305 | throw (new RuntimeException(desc)); |
| 4306 | } else { |
| 4307 | Log.d(TAG, desc); |
| 4308 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4309 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4310 | } |
| 4311 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4312 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4313 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4314 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4315 | // Animate all the applications up now |
| 4316 | shortcut.setAlpha(0f); |
| 4317 | shortcut.setScaleX(0f); |
| 4318 | shortcut.setScaleY(0f); |
| 4319 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4320 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4321 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4322 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4323 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4324 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4325 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4326 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4327 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4328 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4329 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4330 | default: |
| 4331 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4332 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4333 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4334 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4335 | if (animateIcons) { |
| 4336 | // Animate to the correct page |
| 4337 | if (newShortcutsScreenId > -1) { |
| 4338 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4339 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4340 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4341 | public void run() { |
| 4342 | anim.playTogether(bounceAnims); |
| 4343 | anim.start(); |
| 4344 | } |
| 4345 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4346 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4347 | // We post the animation slightly delayed to prevent slowdowns |
| 4348 | // when we are loading right after we return to launcher. |
| 4349 | mWorkspace.postDelayed(new Runnable() { |
| 4350 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4351 | if (mWorkspace != null) { |
| 4352 | mWorkspace.snapToPage(newScreenIndex); |
| 4353 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4354 | NEW_APPS_ANIMATION_DELAY); |
| 4355 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4356 | } |
| 4357 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4358 | } else { |
| 4359 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4360 | } |
| 4361 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4362 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4363 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4364 | } |
| 4365 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4366 | /** |
| 4367 | * Implementation of the method from LauncherModel.Callbacks. |
| 4368 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4369 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4370 | Runnable r = new Runnable() { |
| 4371 | public void run() { |
| 4372 | bindFolders(folders); |
| 4373 | } |
| 4374 | }; |
| 4375 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4376 | return; |
| 4377 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4378 | sFolders.clear(); |
| 4379 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4380 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4381 | |
| 4382 | /** |
| 4383 | * Add the views for a widget to the workspace. |
| 4384 | * |
| 4385 | * Implementation of the method from LauncherModel.Callbacks. |
| 4386 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4387 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4388 | Runnable r = new Runnable() { |
| 4389 | public void run() { |
| 4390 | bindAppWidget(item); |
| 4391 | } |
| 4392 | }; |
| 4393 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4394 | return; |
| 4395 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4396 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4397 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4398 | if (DEBUG_WIDGETS) { |
| 4399 | Log.d(TAG, "bindAppWidget: " + item); |
| 4400 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4401 | final Workspace workspace = mWorkspace; |
| 4402 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4403 | LauncherAppWidgetProviderInfo appWidgetInfo = |
Robin Lee | 2dd9f01 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 4404 | LauncherModel.getProviderInfo(this, item.providerName, item.user); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4405 | |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4406 | if (!mIsSafeModeEnabled |
| 4407 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) |
| 4408 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4409 | if (appWidgetInfo == null) { |
| 4410 | if (DEBUG_WIDGETS) { |
| 4411 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4412 | + " belongs to component " + item.providerName |
| 4413 | + ", as the povider is null"); |
| 4414 | } |
| 4415 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4416 | return; |
| 4417 | } |
| 4418 | // Note: This assumes that the id remap broadcast is received before this step. |
| 4419 | // If that is not the case, the id remap will be ignored and user may see the |
| 4420 | // click to setup view. |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4421 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4422 | pendingInfo.spanX = item.spanX; |
| 4423 | pendingInfo.spanY = item.spanY; |
| 4424 | pendingInfo.minSpanX = item.minSpanX; |
| 4425 | pendingInfo.minSpanY = item.minSpanY; |
| 4426 | Bundle options = |
| 4427 | AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo); |
| 4428 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4429 | int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 4430 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 4431 | newWidgetId, appWidgetInfo, options); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4432 | |
| 4433 | // TODO consider showing a permission dialog when the widget is clicked. |
| 4434 | if (!success) { |
| 4435 | mAppWidgetHost.deleteAppWidgetId(newWidgetId); |
| 4436 | if (DEBUG_WIDGETS) { |
| 4437 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4438 | + " belongs to component " + item.providerName |
| 4439 | + ", as the launcher is unable to bing a new widget id"); |
| 4440 | } |
| 4441 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4442 | return; |
| 4443 | } |
| 4444 | |
| 4445 | item.appWidgetId = newWidgetId; |
| 4446 | |
| 4447 | // If the widget has a configure activity, it is still needs to set it up, otherwise |
| 4448 | // the widget is ready to go. |
| 4449 | item.restoreStatus = (appWidgetInfo.configure == null) |
| 4450 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 4451 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 4452 | |
| 4453 | LauncherModel.updateItemInDatabase(this, item); |
| 4454 | } |
| 4455 | |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4456 | if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4457 | final int appWidgetId = item.appWidgetId; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4458 | if (DEBUG_WIDGETS) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4459 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " |
| 4460 | + appWidgetInfo.provider); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4461 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4462 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4463 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4464 | } else { |
| 4465 | appWidgetInfo = null; |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4466 | PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, |
| 4467 | mIsSafeModeEnabled); |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4468 | view.updateIcon(mIconCache); |
| 4469 | item.hostView = view; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4470 | item.hostView.updateAppWidget(null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4471 | item.hostView.setOnClickListener(this); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4472 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4473 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4474 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4475 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4476 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4477 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4478 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4479 | if (!item.isCustomWidget()) { |
| 4480 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4481 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4482 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4483 | workspace.requestLayout(); |
| 4484 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4485 | if (DEBUG_WIDGETS) { |
| 4486 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4487 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4488 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4489 | } |
| 4490 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4491 | /** |
| 4492 | * Restores a pending widget. |
| 4493 | * |
| 4494 | * @param appWidgetId The app widget id |
| 4495 | * @param cellInfo The position on screen where to create the widget. |
| 4496 | */ |
| 4497 | private void completeRestoreAppWidget(final int appWidgetId) { |
| 4498 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 4499 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 4500 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
| 4501 | return; |
| 4502 | } |
| 4503 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4504 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4505 | info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 4506 | |
| 4507 | mWorkspace.reinflateWidgetsIfNecessary(); |
| 4508 | LauncherModel.updateItemInDatabase(this, info); |
| 4509 | } |
| 4510 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4511 | public void onPageBoundSynchronously(int page) { |
| 4512 | mSynchronouslyBoundPages.add(page); |
| 4513 | } |
| 4514 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4515 | /** |
| 4516 | * Callback saying that there aren't any more items to bind. |
| 4517 | * |
| 4518 | * Implementation of the method from LauncherModel.Callbacks. |
| 4519 | */ |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4520 | public void finishBindingItems(final boolean upgradePath) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4521 | Runnable r = new Runnable() { |
| 4522 | public void run() { |
| 4523 | finishBindingItems(upgradePath); |
| 4524 | } |
| 4525 | }; |
| 4526 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4527 | return; |
| 4528 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4529 | if (mSavedState != null) { |
| 4530 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4531 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4532 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4533 | mSavedState = null; |
| 4534 | } |
| 4535 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4536 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4537 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4538 | setWorkspaceLoading(false); |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4539 | sendLoadingCompleteBroadcastIfNecessary(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 4540 | |
| 4541 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4542 | // widget configuration forced an orientation change), process them now. |
| 4543 | if (sPendingAddItem != null) { |
| 4544 | final long screenId = completeAdd(sPendingAddItem); |
| 4545 | |
| 4546 | // TODO: this moves the user to the page where the pending item was added. Ideally, |
| 4547 | // the screen would be guaranteed to exist after bind, and the page would be set through |
| 4548 | // the workspace restore process. |
| 4549 | mWorkspace.post(new Runnable() { |
| 4550 | @Override |
| 4551 | public void run() { |
| 4552 | mWorkspace.snapToScreenId(screenId); |
| 4553 | } |
| 4554 | }); |
| 4555 | sPendingAddItem = null; |
| 4556 | } |
| 4557 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4558 | if (upgradePath) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4559 | mWorkspace.getUniqueComponents(true, null); |
| 4560 | mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4561 | } |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4562 | PackageInstallerCompat.getInstance(this).onFinishBind(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4563 | |
| 4564 | if (mLauncherCallbacks != null) { |
| 4565 | mLauncherCallbacks.finishBindingItems(upgradePath); |
| 4566 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4567 | } |
| 4568 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4569 | private void sendLoadingCompleteBroadcastIfNecessary() { |
| 4570 | if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) { |
| 4571 | String permission = |
| 4572 | getResources().getString(R.string.receive_first_load_broadcast_permission); |
| 4573 | Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE); |
| 4574 | sendBroadcast(intent, permission); |
| 4575 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4576 | editor.putBoolean(FIRST_LOAD_COMPLETE, true); |
| 4577 | editor.apply(); |
| 4578 | } |
| 4579 | } |
| 4580 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4581 | public boolean isAllAppsButtonRank(int rank) { |
| 4582 | if (mHotseat != null) { |
| 4583 | return mHotseat.isAllAppsButtonRank(rank); |
| 4584 | } |
| 4585 | return false; |
| 4586 | } |
| 4587 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4588 | private boolean canRunNewAppsAnimation() { |
| 4589 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4590 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4591 | } |
| 4592 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4593 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4594 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4595 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4596 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4597 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4598 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4599 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4600 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4601 | return bounceAnim; |
| 4602 | } |
| 4603 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4604 | public boolean useVerticalBarLayout() { |
| 4605 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4606 | getDeviceProfile().isVerticalBarLayout(); |
| 4607 | } |
| 4608 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4609 | protected Rect getSearchBarBounds() { |
| 4610 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4611 | getDeviceProfile().getSearchBarBounds(); |
| 4612 | } |
| 4613 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4614 | public void bindSearchablesChanged() { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 4615 | if (mSearchDropTargetBar == null) { |
| 4616 | return; |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4617 | } |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 4618 | if (mQsb != null) { |
| 4619 | mSearchDropTargetBar.removeView(mQsb); |
| 4620 | mQsb = null; |
| 4621 | } |
| 4622 | mSearchDropTargetBar.setQsbSearchBar(getQsbBar()); |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4623 | } |
| 4624 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4625 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4626 | * Add the icons for all apps. |
| 4627 | * |
| 4628 | * Implementation of the method from LauncherModel.Callbacks. |
| 4629 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4630 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4631 | if (LauncherAppState.isDisableAllApps()) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4632 | if (mIntentsOnWorkspaceFromUpgradePath != null) { |
| 4633 | if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) { |
| 4634 | getHotseat().addAllAppsFolder(mIconCache, apps, |
| 4635 | mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace); |
| 4636 | } |
| 4637 | mIntentsOnWorkspaceFromUpgradePath = null; |
Daniel Sandler | 8707e0f | 2013-08-15 15:54:18 -0700 | [diff] [blame] | 4638 | } |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4639 | if (mAppsCustomizeContent != null) { |
| 4640 | mAppsCustomizeContent.onPackagesUpdated( |
Hyunyoung Song | fe1dcbf | 2015-03-11 16:36:52 -0700 | [diff] [blame] | 4641 | LauncherModel.getSortedWidgetsAndShortcuts(this, false /* refresh */)); |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4642 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4643 | } else { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 4644 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4645 | mAppsCustomizeContent.setApps(apps); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 4646 | mAppsCustomizeContent.onPackagesUpdated( |
Hyunyoung Song | fe1dcbf | 2015-03-11 16:36:52 -0700 | [diff] [blame] | 4647 | LauncherModel.getSortedWidgetsAndShortcuts(this, false /* refresh */)); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4648 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4649 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4650 | if (mLauncherCallbacks != null) { |
| 4651 | mLauncherCallbacks.bindAllApplications(apps); |
| 4652 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | /** |
| 4656 | * A package was updated. |
| 4657 | * |
| 4658 | * Implementation of the method from LauncherModel.Callbacks. |
| 4659 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4660 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4661 | Runnable r = new Runnable() { |
| 4662 | public void run() { |
| 4663 | bindAppsUpdated(apps); |
| 4664 | } |
| 4665 | }; |
| 4666 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4667 | return; |
| 4668 | } |
| 4669 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4670 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4671 | mAppsCustomizeContent != null) { |
| 4672 | mAppsCustomizeContent.updateApps(apps); |
| 4673 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4674 | } |
| 4675 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4676 | @Override |
| 4677 | public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) { |
| 4678 | Runnable r = new Runnable() { |
| 4679 | public void run() { |
| 4680 | bindWidgetsRestored(widgets); |
| 4681 | } |
| 4682 | }; |
| 4683 | if (waitUntilResume(r)) { |
| 4684 | return; |
| 4685 | } |
| 4686 | mWorkspace.widgetsRestored(widgets); |
| 4687 | } |
| 4688 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4689 | /** |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4690 | * Some shortcuts were updated in the background. |
| 4691 | * |
| 4692 | * Implementation of the method from LauncherModel.Callbacks. |
| 4693 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4694 | @Override |
| 4695 | public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated, |
| 4696 | final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4697 | Runnable r = new Runnable() { |
| 4698 | public void run() { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4699 | bindShortcutsChanged(updated, removed, user); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4700 | } |
| 4701 | }; |
| 4702 | if (waitUntilResume(r)) { |
| 4703 | return; |
| 4704 | } |
| 4705 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4706 | if (!updated.isEmpty()) { |
| 4707 | mWorkspace.updateShortcuts(updated); |
| 4708 | } |
| 4709 | |
| 4710 | if (!removed.isEmpty()) { |
| 4711 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 4712 | for (ShortcutInfo si : removed) { |
| 4713 | removedComponents.add(si.getTargetComponent()); |
| 4714 | } |
| 4715 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
| 4716 | // Notify the drag controller |
| 4717 | mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4718 | } |
| 4719 | } |
| 4720 | |
| 4721 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4722 | * Update the state of a package, typically related to install state. |
| 4723 | * |
| 4724 | * Implementation of the method from LauncherModel.Callbacks. |
| 4725 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4726 | @Override |
| 4727 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4728 | if (mWorkspace != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4729 | mWorkspace.updatePackageState(installInfo); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | /** |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 4734 | * Update the label and icon of all the icons in a package |
| 4735 | * |
| 4736 | * Implementation of the method from LauncherModel.Callbacks. |
| 4737 | */ |
| 4738 | @Override |
| 4739 | public void updatePackageBadge(String packageName) { |
| 4740 | if (mWorkspace != null) { |
| 4741 | mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle()); |
| 4742 | } |
| 4743 | } |
| 4744 | |
| 4745 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4746 | * A package was uninstalled. We take both the super set of packageNames |
| 4747 | * in addition to specific applications to remove, the reason being that |
| 4748 | * this can be called when a package is updated as well. In that scenario, |
| 4749 | * we only remove specific components from the workspace, where as |
| 4750 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4751 | * |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4752 | * @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] | 4753 | * Implementation of the method from LauncherModel.Callbacks. |
| 4754 | */ |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4755 | @Override |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4756 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4757 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4758 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4759 | public void run() { |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4760 | bindComponentsRemoved(packageNames, appInfos, user, reason); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4761 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4762 | }; |
| 4763 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4764 | return; |
| 4765 | } |
| 4766 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4767 | if (reason == 0) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4768 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 4769 | for (AppInfo info : appInfos) { |
| 4770 | removedComponents.add(info.componentName); |
| 4771 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4772 | if (!packageNames.isEmpty()) { |
| 4773 | mWorkspace.removeItemsByPackageName(packageNames, user); |
| 4774 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4775 | if (!removedComponents.isEmpty()) { |
| 4776 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4777 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4778 | // Notify the drag controller |
| 4779 | mDragController.onAppsRemoved(packageNames, removedComponents); |
| 4780 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4781 | } else { |
| 4782 | mWorkspace.disableShortcutsByPackageName(packageNames, user, reason); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 4783 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4784 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4785 | // Update AllApps |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4786 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4787 | mAppsCustomizeContent != null) { |
| 4788 | mAppsCustomizeContent.removeApps(appInfos); |
| 4789 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4790 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4791 | |
| 4792 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4793 | * A number of packages were updated. |
| 4794 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4795 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 4796 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4797 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4798 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 4799 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4800 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4801 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4802 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 4803 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 4804 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4805 | return; |
| 4806 | } |
| 4807 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4808 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4809 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4810 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4811 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4814 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 4815 | final Display d = getWindowManager().getDefaultDisplay(); |
| 4816 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 4817 | switch (d.getRotation()) { |
| 4818 | case Surface.ROTATION_0: |
| 4819 | case Surface.ROTATION_180: |
| 4820 | // We are currently in the same basic orientation as the natural orientation |
| 4821 | naturalOri = configOri; |
| 4822 | break; |
| 4823 | case Surface.ROTATION_90: |
| 4824 | case Surface.ROTATION_270: |
| 4825 | // We are currently in the other basic orientation to the natural orientation |
| 4826 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 4827 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 4828 | break; |
| 4829 | } |
| 4830 | |
| 4831 | int[] oriMap = { |
| 4832 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 4833 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 4834 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 4835 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 4836 | }; |
| 4837 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 4838 | // is landscape. |
| 4839 | int indexOffset = 0; |
| 4840 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 4841 | indexOffset = 1; |
| 4842 | } |
| 4843 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 4844 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 4845 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4846 | public void lockScreenOrientation() { |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 4847 | if (Utilities.isRotationEnabled(this)) { |
Sunny Goyal | 7470c81 | 2015-02-10 14:28:44 -0800 | [diff] [blame] | 4848 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { |
| 4849 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 4850 | .getConfiguration().orientation)); |
| 4851 | } else { |
| 4852 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
| 4853 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | public void unlockScreenOrientation(boolean immediate) { |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 4857 | if (Utilities.isRotationEnabled(this)) { |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4858 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4859 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4860 | } else { |
| 4861 | mHandler.postDelayed(new Runnable() { |
| 4862 | public void run() { |
| 4863 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 4864 | } |
| 4865 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4866 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4867 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4868 | } |
| 4869 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4870 | protected boolean isLauncherPreinstalled() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4871 | if (mLauncherCallbacks != null) { |
| 4872 | return mLauncherCallbacks.isLauncherPreinstalled(); |
| 4873 | } |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4874 | PackageManager pm = getPackageManager(); |
| 4875 | try { |
| 4876 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 4877 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4878 | return true; |
| 4879 | } else { |
| 4880 | return false; |
| 4881 | } |
| 4882 | } catch (NameNotFoundException e) { |
| 4883 | e.printStackTrace(); |
| 4884 | return false; |
| 4885 | } |
| 4886 | } |
| 4887 | |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4888 | /** |
| 4889 | * This method indicates whether or not we should suggest default wallpaper dimensions |
| 4890 | * when our wallpaper cropper was not yet used to set a wallpaper. |
| 4891 | */ |
| 4892 | protected boolean overrideWallpaperDimensions() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4893 | if (mLauncherCallbacks != null) { |
| 4894 | return mLauncherCallbacks.overrideWallpaperDimensions(); |
| 4895 | } |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4896 | return true; |
| 4897 | } |
| 4898 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4899 | /** |
| 4900 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 4901 | * before showing the standard launcher experience. |
| 4902 | */ |
| 4903 | protected boolean hasFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4904 | if (mLauncherCallbacks != null) { |
| 4905 | return mLauncherCallbacks.hasFirstRunActivity(); |
| 4906 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4907 | return false; |
| 4908 | } |
| 4909 | |
| 4910 | /** |
| 4911 | * To be overridden by subclasses to launch any first run activity |
| 4912 | */ |
| 4913 | protected Intent getFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4914 | if (mLauncherCallbacks != null) { |
| 4915 | return mLauncherCallbacks.getFirstRunActivity(); |
| 4916 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4917 | return null; |
| 4918 | } |
| 4919 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4920 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4921 | return !ActivityManager.isRunningInTestHarness() && |
| 4922 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4923 | } |
| 4924 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 4925 | protected boolean hasRunFirstRunActivity() { |
| 4926 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 4927 | } |
| 4928 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4929 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4930 | if (shouldRunFirstRunActivity() && |
| 4931 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4932 | Intent firstRunIntent = getFirstRunActivity(); |
| 4933 | if (firstRunIntent != null) { |
| 4934 | startActivity(firstRunIntent); |
| 4935 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4936 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4937 | } |
| 4938 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4939 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | private void markFirstRunActivityShown() { |
| 4943 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4944 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 4945 | editor.apply(); |
| 4946 | } |
| 4947 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4948 | /** |
| 4949 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 4950 | * screen that must be displayed and dismissed. |
| 4951 | */ |
| 4952 | protected boolean hasDismissableIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4953 | if (mLauncherCallbacks != null) { |
| 4954 | return mLauncherCallbacks.hasDismissableIntroScreen(); |
| 4955 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4956 | return false; |
| 4957 | } |
| 4958 | |
| 4959 | /** |
| 4960 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 4961 | */ |
| 4962 | protected View getIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4963 | if (mLauncherCallbacks != null) { |
| 4964 | return mLauncherCallbacks.getIntroScreen(); |
| 4965 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4966 | return null; |
| 4967 | } |
| 4968 | |
| 4969 | /** |
| 4970 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 4971 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 4972 | */ |
| 4973 | private boolean shouldShowIntroScreen() { |
| 4974 | return hasDismissableIntroScreen() && |
| 4975 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 4976 | } |
| 4977 | |
| 4978 | protected void showIntroScreen() { |
| 4979 | View introScreen = getIntroScreen(); |
| 4980 | changeWallpaperVisiblity(false); |
| 4981 | if (introScreen != null) { |
| 4982 | mDragLayer.showOverlayView(introScreen); |
| 4983 | } |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 4984 | if (mLauncherOverlayContainer != null) { |
| 4985 | mLauncherOverlayContainer.setVisibility(View.INVISIBLE); |
| 4986 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | public void dismissIntroScreen() { |
| 4990 | markIntroScreenDismissed(); |
| 4991 | if (showFirstRunActivity()) { |
| 4992 | // We delay hiding the intro view until the first run activity is showing. This |
| 4993 | // avoids a blip. |
| 4994 | mWorkspace.postDelayed(new Runnable() { |
| 4995 | @Override |
| 4996 | public void run() { |
| 4997 | mDragLayer.dismissOverlayView(); |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 4998 | if (mLauncherOverlayContainer != null) { |
| 4999 | mLauncherOverlayContainer.setVisibility(View.VISIBLE); |
| 5000 | } |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5001 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5002 | } |
| 5003 | }, ACTIVITY_START_DELAY); |
| 5004 | } else { |
| 5005 | mDragLayer.dismissOverlayView(); |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 5006 | if (mLauncherOverlayContainer != null) { |
| 5007 | mLauncherOverlayContainer.setVisibility(View.VISIBLE); |
| 5008 | } |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5009 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5010 | } |
| 5011 | changeWallpaperVisiblity(true); |
| 5012 | } |
| 5013 | |
| 5014 | private void markIntroScreenDismissed() { |
| 5015 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 5016 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 5017 | editor.apply(); |
| 5018 | } |
| 5019 | |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5020 | private void showFirstRunClings() { |
| 5021 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 5022 | // on the device, then we always show the first run cling experience (or if there is no |
| 5023 | // launcher2). Otherwise, we prompt the user upon started for migration |
| 5024 | LauncherClings launcherClings = new LauncherClings(this); |
| 5025 | if (launcherClings.shouldShowFirstRunOrMigrationClings()) { |
| 5026 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
| 5027 | launcherClings.showMigrationCling(); |
| 5028 | } else { |
Sunny Goyal | af0628f | 2014-09-19 10:14:48 -0700 | [diff] [blame] | 5029 | launcherClings.showLongPressCling(true); |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5030 | } |
| 5031 | } |
| 5032 | } |
| 5033 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5034 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 5035 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 5036 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 5037 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 5038 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5039 | } |
| 5040 | |
| 5041 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 5042 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 5043 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 5044 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 5045 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5046 | } |
| 5047 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5048 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5049 | // Called from search suggestion, not supported in other profiles. |
| 5050 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 5051 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 5052 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 5053 | myUser); |
| 5054 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5055 | return null; |
| 5056 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5057 | return new AppInfo(this, activityInfo, myUser, mIconCache, null); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5061 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5062 | // Called from search suggestion, not supported in other profiles. |
| 5063 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 5064 | UserHandleCompat.myUserHandle()); |
| 5065 | } |
| 5066 | |
| 5067 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5068 | Bitmap icon, UserHandleCompat user) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5069 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 5070 | CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5071 | return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 5074 | protected void moveWorkspaceToDefaultScreen() { |
| 5075 | mWorkspace.moveToDefaultScreen(false); |
| 5076 | } |
| 5077 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5078 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 5079 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 5080 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 5081 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5082 | } |
| 5083 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5084 | @Override |
| 5085 | public void onPageSwitch(View newPage, int newPageIndex) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5086 | if (mLauncherCallbacks != null) { |
| 5087 | mLauncherCallbacks.onPageSwitch(newPage, newPageIndex); |
| 5088 | } |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5089 | } |
| 5090 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5091 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5092 | * Prints out out state for debugging. |
| 5093 | */ |
| 5094 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5095 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5096 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5097 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 5098 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 5099 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 5100 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 5101 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5102 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5103 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5104 | if (mAppsCustomizeContent != null) { |
| 5105 | mAppsCustomizeContent.dumpState(); |
| 5106 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5107 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5108 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5109 | |
| 5110 | @Override |
| 5111 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5112 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5113 | synchronized (sDumpLogs) { |
| 5114 | writer.println(" "); |
| 5115 | writer.println("Debug logs: "); |
| 5116 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5117 | writer.println(" " + sDumpLogs.get(i)); |
| 5118 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5119 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5120 | if (mLauncherCallbacks != null) { |
| 5121 | mLauncherCallbacks.dump(prefix, fd, writer, args); |
| 5122 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5123 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5124 | |
| 5125 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5126 | if (DEBUG_DUMP_LOG) { |
| 5127 | synchronized (sDumpLogs) { |
| 5128 | Log.d(TAG, ""); |
| 5129 | Log.d(TAG, "*********************"); |
| 5130 | Log.d(TAG, "Launcher debug logs: "); |
| 5131 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5132 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 5133 | } |
| 5134 | Log.d(TAG, "*********************"); |
| 5135 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5136 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5137 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5141 | addDumpLog(tag, log, null, debugLog); |
| 5142 | } |
| 5143 | |
| 5144 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5145 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5146 | if (e != null) { |
| 5147 | Log.d(tag, log, e); |
| 5148 | } else { |
| 5149 | Log.d(tag, log); |
| 5150 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5151 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5152 | if (DEBUG_DUMP_LOG) { |
| 5153 | sDateStamp.setTime(System.currentTimeMillis()); |
| 5154 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5155 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 5156 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5157 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5158 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 5161 | public static CustomAppWidget getCustomAppWidget(String name) { |
| 5162 | return sCustomAppWidgets.get(name); |
| 5163 | } |
| 5164 | |
| 5165 | public static HashMap<String, CustomAppWidget> getCustomAppWidgets() { |
| 5166 | return sCustomAppWidgets; |
| 5167 | } |
| 5168 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5169 | public void dumpLogsToLocalData() { |
| 5170 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5171 | new AsyncTask<Void, Void, Void>() { |
| 5172 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5173 | boolean success = false; |
| 5174 | sDateStamp.setTime(sRunStart); |
| 5175 | String FILENAME = sDateStamp.getMonth() + "-" |
| 5176 | + sDateStamp.getDay() + "_" |
| 5177 | + sDateStamp.getHours() + "-" |
| 5178 | + sDateStamp.getMinutes() + "_" |
| 5179 | + sDateStamp.getSeconds() + ".txt"; |
| 5180 | |
| 5181 | FileOutputStream fos = null; |
| 5182 | File outFile = null; |
| 5183 | try { |
| 5184 | outFile = new File(getFilesDir(), FILENAME); |
| 5185 | outFile.createNewFile(); |
| 5186 | fos = new FileOutputStream(outFile); |
| 5187 | } catch (Exception e) { |
| 5188 | e.printStackTrace(); |
| 5189 | } |
| 5190 | if (fos != null) { |
| 5191 | PrintWriter writer = new PrintWriter(fos); |
| 5192 | |
| 5193 | writer.println(" "); |
| 5194 | writer.println("Debug logs: "); |
| 5195 | synchronized (sDumpLogs) { |
| 5196 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5197 | writer.println(" " + sDumpLogs.get(i)); |
| 5198 | } |
| 5199 | } |
| 5200 | writer.close(); |
| 5201 | } |
| 5202 | try { |
| 5203 | if (fos != null) { |
| 5204 | fos.close(); |
| 5205 | success = true; |
| 5206 | } |
| 5207 | } catch (IOException e) { |
| 5208 | e.printStackTrace(); |
| 5209 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5210 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5211 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5212 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5213 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5214 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5215 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5216 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 5217 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 5218 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 5219 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5220 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 5221 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5222 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5223 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 5224 | |
| 5225 | interface DebugIntents { |
| 5226 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 5227 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 5228 | } |