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; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 25 | import android.animation.ValueAnimator; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 26 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 27 | import android.annotation.TargetApi; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 28 | import android.app.Activity; |
Brett Chabot | 2a9e228 | 2011-08-23 15:03:13 -0700 | [diff] [blame] | 29 | import android.app.ActivityManager; |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 30 | import android.app.ActivityOptions; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 31 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | import android.app.SearchManager; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 33 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 34 | import android.appwidget.AppWidgetManager; |
| 35 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 37 | import android.content.BroadcastReceiver; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 38 | import android.content.ComponentCallbacks2; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 39 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 40 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.content.Context; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 42 | import android.content.DialogInterface; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 44 | import android.content.IntentFilter; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 45 | import android.content.SharedPreferences; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 46 | import android.content.pm.ActivityInfo; |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 47 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 49 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 51 | import android.content.res.Resources; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 52 | import android.database.ContentObserver; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 53 | import android.graphics.Bitmap; |
| 54 | import android.graphics.Canvas; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame] | 55 | import android.graphics.Color; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 56 | import android.graphics.Point; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 57 | import android.graphics.PorterDuff; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 58 | import android.graphics.Rect; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 59 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 60 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 61 | import android.os.AsyncTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 62 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 63 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 64 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 65 | import android.os.Message; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 66 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 67 | import android.os.SystemClock; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 68 | import android.speech.RecognizerIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | import android.text.Selection; |
| 70 | import android.text.SpannableStringBuilder; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 71 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | import android.text.method.TextKeyListener; |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 73 | import android.util.DisplayMetrics; |
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; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -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; |
| 88 | import android.view.ViewTreeObserver; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 89 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
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 | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 93 | import android.view.animation.AccelerateDecelerateInterpolator; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 94 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 95 | import android.view.animation.DecelerateInterpolator; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 96 | import android.view.animation.LinearInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 98 | import android.widget.Advanceable; |
| 99 | import android.widget.FrameLayout; |
| 100 | import android.widget.ImageView; |
| 101 | import android.widget.TextView; |
| 102 | import android.widget.Toast; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 103 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 104 | import com.android.launcher3.DropTarget.DragObject; |
| 105 | import com.android.launcher3.PagedView.PageSwitchListener; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 106 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 107 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 108 | import com.android.launcher3.compat.PackageInstallerCompat; |
| 109 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 110 | import com.android.launcher3.compat.UserHandleCompat; |
| 111 | import com.android.launcher3.compat.UserManagerCompat; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 112 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 113 | import java.io.DataInputStream; |
| 114 | import java.io.DataOutputStream; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 115 | import java.io.File; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 116 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 117 | import java.io.FileNotFoundException; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 118 | import java.io.FileOutputStream; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 119 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 120 | import java.io.PrintWriter; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 121 | import java.lang.reflect.Field; |
| 122 | import java.lang.reflect.InvocationTargetException; |
| 123 | import java.lang.reflect.Method; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 124 | import java.text.DateFormat; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 125 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 126 | import java.util.Collection; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 127 | import java.util.Date; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 128 | import java.util.HashMap; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 129 | import java.util.List; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 130 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 131 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 132 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 133 | /** |
| 134 | * Default launcher application. |
| 135 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 136 | public class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 137 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 138 | View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 139 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 140 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 141 | |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 142 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 143 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_STRICT_MODE = false; |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 145 | static final boolean DEBUG_RESUME_TIME = false; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 146 | static final boolean DEBUG_DUMP_LOG = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 147 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 148 | static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run |
| 149 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 150 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 151 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 152 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 153 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 154 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 155 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 156 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 157 | private static final int REQUEST_RECONFIGURE_APPWIDGET = 12; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 158 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 159 | /** |
| 160 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 161 | * request codes used internally. |
| 162 | */ |
| 163 | protected static final int REQUEST_LAST = 100; |
| 164 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 165 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 166 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 167 | static final int SCREEN_COUNT = 5; |
| 168 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 169 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 170 | private static final String PREFERENCES = "launcher.preferences"; |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 171 | // To turn on these properties, type |
| 172 | // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS] |
| 173 | static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate"; |
| 174 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 175 | static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 176 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 177 | // The Intent extra that defines whether to ignore the launch animation |
| 178 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 179 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 180 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 181 | // Type: int |
| 182 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 183 | // Type: int |
| 184 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 185 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 186 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 187 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 188 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 189 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 190 | 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] | 191 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 192 | 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] | 193 | // Type: boolean |
| 194 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 195 | // Type: long |
| 196 | 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] | 197 | // Type: int |
| 198 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 199 | // Type: int |
| 200 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 201 | // Type: parcelable |
| 202 | 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] | 203 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 204 | 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] | 205 | // Type: int[] |
| 206 | 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] | 207 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 208 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 209 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 210 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 211 | static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete"; |
| 212 | static final String ACTION_FIRST_LOAD_COMPLETE = |
| 213 | "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; |
| 214 | |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 215 | private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 216 | private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 217 | "com.android.launcher.toolbar_search_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 218 | private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 219 | "com.android.launcher.toolbar_voice_search_icon"; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 220 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 221 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 222 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 223 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 224 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 225 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 226 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 227 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 228 | private State mState = State.WORKSPACE; |
| 229 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 230 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 231 | private boolean mIsSafeModeEnabled; |
| 232 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 233 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 234 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 235 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 236 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 237 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 238 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 239 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 240 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 241 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 242 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 243 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 244 | // 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] | 245 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 246 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 247 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 248 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 249 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 250 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 251 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 252 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 253 | private LayoutInflater mInflater; |
| 254 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 255 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 256 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 257 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 258 | private DragLayer mDragLayer; |
| 259 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 260 | private View mWeightWatcher; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 261 | private LauncherClings mLauncherClings; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 262 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 263 | private AppWidgetManager mAppWidgetManager; |
| 264 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 265 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 266 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 267 | private AppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 268 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 269 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 270 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 271 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 272 | private FolderInfo mFolderInfo; |
| 273 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 274 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 275 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 276 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 277 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 278 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 279 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 280 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 281 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 282 | private boolean mAutoAdvanceRunning = false; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 283 | private View mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 284 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 285 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 286 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 287 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 288 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 289 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 290 | |
| 291 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 292 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 293 | private boolean mWorkspaceLoading = true; |
| 294 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 295 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 296 | private boolean mRestoring; |
| 297 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 298 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 299 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 300 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 301 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 302 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 303 | private Bundle mSavedInstanceState; |
| 304 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 305 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 306 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 307 | private boolean mUserPresent = true; |
| 308 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 309 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 310 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 311 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 312 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 313 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 314 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 315 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 316 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 317 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 318 | // Related to the auto-advancing of widgets |
| 319 | private final int ADVANCE_MSG = 1; |
| 320 | private final int mAdvanceInterval = 20000; |
| 321 | private final int mAdvanceStagger = 250; |
| 322 | private long mAutoAdvanceSentTime; |
| 323 | private long mAutoAdvanceTimeLeft = -1; |
| 324 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 325 | new HashMap<View, AppWidgetProviderInfo>(); |
| 326 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 327 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 328 | // match the sensor state. |
| 329 | private final int mRestoreScreenOrientationDelay = 500; |
| 330 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 331 | // External icons saved in case of resource changes, orientation, etc. |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 332 | private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; |
| 333 | private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; |
| 334 | private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2]; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 335 | |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 336 | private Intent mAppMarketIntent = null; |
| 337 | private static final boolean DISABLE_MARKET_BUTTON = true; |
| 338 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 339 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 340 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 341 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 342 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 343 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 344 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 345 | static Date sDateStamp = new Date(); |
| 346 | static DateFormat sDateFormat = |
| 347 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 348 | static long sRunStart = System.currentTimeMillis(); |
| 349 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 350 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 351 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 352 | // it from the context. |
| 353 | private SharedPreferences mSharedPrefs; |
| 354 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 355 | private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null; |
| 356 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 357 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 358 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 359 | private ImageView mFolderIconImageView; |
| 360 | private Bitmap mFolderIconBitmap; |
| 361 | private Canvas mFolderIconCanvas; |
| 362 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 363 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 364 | private BubbleTextView mWaitingForResume; |
| 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 | |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 376 | public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 377 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 378 | private static class PendingAddArguments { |
| 379 | int requestCode; |
| 380 | Intent intent; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 381 | long container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 382 | long screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 383 | int cellX; |
| 384 | int cellY; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 385 | int appWidgetId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 388 | private Stats mStats; |
| 389 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 390 | static boolean isPropertyEnabled(String propertyName) { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 391 | return Log.isLoggable(propertyName, Log.VERBOSE); |
Michael Jurka | 9bc8eba | 2012-05-21 20:36:44 -0700 | [diff] [blame] | 392 | } |
| 393 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 394 | @Override |
| 395 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 396 | if (DEBUG_STRICT_MODE) { |
| 397 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 398 | .detectDiskReads() |
| 399 | .detectDiskWrites() |
| 400 | .detectNetwork() // or .detectAll() for all detectable problems |
| 401 | .penaltyLog() |
| 402 | .build()); |
| 403 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 404 | .detectLeakedSqlLiteObjects() |
| 405 | .detectLeakedClosableObjects() |
| 406 | .penaltyLog() |
| 407 | .penaltyDeath() |
| 408 | .build()); |
| 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 | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 416 | // Determine the dynamic grid properties |
| 417 | Point smallestSize = new Point(); |
| 418 | Point largestSize = new Point(); |
| 419 | Point realSize = new Point(); |
| 420 | Display display = getWindowManager().getDefaultDisplay(); |
| 421 | display.getCurrentSizeRange(smallestSize, largestSize); |
| 422 | display.getRealSize(realSize); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 423 | DisplayMetrics dm = new DisplayMetrics(); |
| 424 | display.getMetrics(dm); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 425 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 426 | // Lazy-initialize the dynamic grid |
| 427 | DeviceProfile grid = app.initDynamicGrid(this, |
| 428 | Math.min(smallestSize.x, smallestSize.y), |
| 429 | Math.min(largestSize.x, largestSize.y), |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 430 | realSize.x, realSize.y, |
| 431 | dm.widthPixels, dm.heightPixels); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 432 | |
| 433 | // 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] | 434 | mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 435 | Context.MODE_PRIVATE); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 436 | mIsSafeModeEnabled = getPackageManager().isSafeMode(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 437 | mModel = app.setLauncher(this); |
| 438 | mIconCache = app.getIconCache(); |
Winson Chung | e5467dc | 2013-10-14 17:03:04 -0700 | [diff] [blame] | 439 | mIconCache.flushInvalidIcons(grid); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 440 | mDragController = new DragController(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 441 | mLauncherClings = new LauncherClings(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 442 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 443 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 444 | mStats = new Stats(this); |
| 445 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 446 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 447 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 448 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 449 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 450 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 451 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 452 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 453 | // LauncherModel load. |
| 454 | mPaused = false; |
| 455 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 456 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 457 | android.os.Debug.startMethodTracing( |
| 458 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 461 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 462 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 463 | setContentView(R.layout.launcher); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 464 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 465 | setupViews(); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 466 | grid.layout(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 467 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 468 | registerContentObservers(); |
| 469 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 470 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 471 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 472 | mSavedState = savedInstanceState; |
| 473 | restoreState(mSavedState); |
| 474 | |
| 475 | if (PROFILE_STARTUP) { |
| 476 | android.os.Debug.stopMethodTracing(); |
| 477 | } |
| 478 | |
| 479 | if (!mRestoring) { |
Adam Cohen | db78dc8 | 2014-06-19 14:50:51 -0700 | [diff] [blame] | 480 | if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 481 | // If the user leaves launcher, then we should just load items asynchronously when |
| 482 | // they return. |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 483 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 484 | } else { |
| 485 | // We only load the page synchronously if the user rotates (or triggers a |
| 486 | // configuration change) while launcher is in the foreground |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 487 | mModel.startLoader(true, mWorkspace.getRestorePage()); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 488 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | // For handling default keys |
| 492 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 493 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 494 | |
| 495 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 496 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 497 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 498 | updateGlobalIcons(); |
| 499 | |
| 500 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 501 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 502 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 503 | if (shouldShowIntroScreen()) { |
| 504 | showIntroScreen(); |
| 505 | } else { |
| 506 | showFirstRunActivity(); |
| 507 | } |
| 508 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 509 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 510 | // on the device, then we always show the first run cling experience (or if there is no |
| 511 | // launcher2). Otherwise, we prompt the user upon started for migration |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 512 | if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) { |
| 513 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
| 514 | mLauncherClings.showMigrationCling(); |
| 515 | } else { |
| 516 | mLauncherClings.showFirstRunCling(); |
| 517 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 518 | } else { |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 519 | mLauncherClings.removeFirstRunAndMigrationClings(); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 520 | } |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 523 | @Override |
| 524 | public void onLauncherProviderChange() { } |
| 525 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 526 | /** To be overriden by subclasses to hint to Launcher that we have custom content */ |
| 527 | protected boolean hasCustomContentToLeft() { |
| 528 | return false; |
| 529 | } |
| 530 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 531 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 532 | * 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] | 533 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 534 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 535 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 536 | protected void populateCustomContentContainer() { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /** |
| 540 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 541 | * ensure the custom content page is added or removed if necessary. |
| 542 | */ |
| 543 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 544 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 545 | // Not bound yet, wait for bindScreens to be called. |
| 546 | return; |
| 547 | } |
| 548 | |
| 549 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 550 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 551 | mWorkspace.createCustomContentContainer(); |
| 552 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 553 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 554 | mWorkspace.removeCustomContentPage(); |
| 555 | } |
| 556 | } |
| 557 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 558 | private void updateGlobalIcons() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 559 | boolean searchVisible = false; |
| 560 | boolean voiceVisible = false; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 561 | // If we have a saved version of these external icons, we load them up immediately |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 562 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 563 | if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null || |
| 564 | sAppMarketIcon[coi] == null) { |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 565 | if (!DISABLE_MARKET_BUTTON) { |
| 566 | updateAppMarketIcon(); |
| 567 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 568 | searchVisible = updateGlobalSearchIcon(); |
| 569 | voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 570 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 571 | if (sGlobalSearchIcon[coi] != null) { |
| 572 | updateGlobalSearchIcon(sGlobalSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 573 | searchVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 574 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 575 | if (sVoiceSearchIcon[coi] != null) { |
| 576 | updateVoiceSearchIcon(sVoiceSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 577 | voiceVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 578 | } |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 579 | if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 580 | updateAppMarketIcon(sAppMarketIcon[coi]); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 581 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 582 | if (mSearchDropTargetBar != null) { |
| 583 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 584 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 585 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 586 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 587 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 588 | if (sLocaleConfiguration == null) { |
| 589 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 590 | @Override |
| 591 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 592 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 593 | readConfiguration(Launcher.this, localeConfiguration); |
| 594 | return localeConfiguration; |
| 595 | } |
| 596 | |
| 597 | @Override |
| 598 | protected void onPostExecute(LocaleConfiguration result) { |
| 599 | sLocaleConfiguration = result; |
| 600 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 601 | } |
| 602 | }.execute(); |
| 603 | return; |
| 604 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 605 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 606 | final Configuration configuration = getResources().getConfiguration(); |
| 607 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 608 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 609 | final String locale = configuration.locale.toString(); |
| 610 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 611 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 612 | final int mcc = configuration.mcc; |
| 613 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 614 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 615 | final int mnc = configuration.mnc; |
| 616 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 617 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 618 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 619 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 620 | sLocaleConfiguration.locale = locale; |
| 621 | sLocaleConfiguration.mcc = mcc; |
| 622 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 623 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 624 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 625 | |
| 626 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 627 | new AsyncTask<Void, Void, Void>() { |
| 628 | public Void doInBackground(Void ... args) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 629 | writeConfiguration(Launcher.this, localeConfiguration); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 630 | return null; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 631 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 632 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
| 636 | private static class LocaleConfiguration { |
| 637 | public String locale; |
| 638 | public int mcc = -1; |
| 639 | public int mnc = -1; |
| 640 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 641 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 642 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 643 | DataInputStream in = null; |
| 644 | try { |
| 645 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 646 | configuration.locale = in.readUTF(); |
| 647 | configuration.mcc = in.readInt(); |
| 648 | configuration.mnc = in.readInt(); |
| 649 | } catch (FileNotFoundException e) { |
| 650 | // Ignore |
| 651 | } catch (IOException e) { |
| 652 | // Ignore |
| 653 | } finally { |
| 654 | if (in != null) { |
| 655 | try { |
| 656 | in.close(); |
| 657 | } catch (IOException e) { |
| 658 | // Ignore |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 665 | DataOutputStream out = null; |
| 666 | try { |
| 667 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 668 | out.writeUTF(configuration.locale); |
| 669 | out.writeInt(configuration.mcc); |
| 670 | out.writeInt(configuration.mnc); |
| 671 | out.flush(); |
| 672 | } catch (FileNotFoundException e) { |
| 673 | // Ignore |
| 674 | } catch (IOException e) { |
| 675 | //noinspection ResultOfMethodCallIgnored |
| 676 | context.getFileStreamPath(PREFERENCES).delete(); |
| 677 | } finally { |
| 678 | if (out != null) { |
| 679 | try { |
| 680 | out.close(); |
| 681 | } catch (IOException e) { |
| 682 | // Ignore |
| 683 | } |
| 684 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 688 | public Stats getStats() { |
| 689 | return mStats; |
| 690 | } |
| 691 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 692 | public LayoutInflater getInflater() { |
| 693 | return mInflater; |
| 694 | } |
| 695 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 696 | boolean isDraggingEnabled() { |
| 697 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 698 | // that is subsequently removed from the workspace in startBinding(). |
| 699 | return !mModel.isLoadingWorkspace(); |
| 700 | } |
| 701 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 702 | static int getScreen() { |
| 703 | synchronized (sLock) { |
| 704 | return sScreen; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | static void setScreen(int screen) { |
| 709 | synchronized (sLock) { |
| 710 | sScreen = screen; |
| 711 | } |
| 712 | } |
| 713 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 714 | /** |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 715 | * Copied from View -- the View version of the method isn't called |
| 716 | * anywhere else in our process and only exists for API level 17+, |
| 717 | * so it's ok to keep our own version with no API requirement. |
| 718 | */ |
| 719 | public static int generateViewId() { |
| 720 | for (;;) { |
| 721 | final int result = sNextGeneratedId.get(); |
| 722 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 723 | int newValue = result + 1; |
| 724 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 725 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 726 | return result; |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | public int getViewIdForItem(ItemInfo info) { |
| 732 | // This cast is safe given the > 2B range for int. |
| 733 | int itemId = (int) info.id; |
| 734 | if (mItemIdToViewId.containsKey(itemId)) { |
| 735 | return mItemIdToViewId.get(itemId); |
| 736 | } |
| 737 | int viewId = generateViewId(); |
| 738 | mItemIdToViewId.put(itemId, viewId); |
| 739 | return viewId; |
| 740 | } |
| 741 | |
| 742 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 743 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 744 | * a configuration step, this allows the proper animations to run after other transitions. |
| 745 | */ |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 746 | private long completeAdd(PendingAddArguments args) { |
| 747 | |
| 748 | long screenId = ensurePendingDropLayoutExists(args.screenId); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 749 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 750 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 751 | completeAddShortcut(args.intent, args.container, screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 752 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 753 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 754 | case REQUEST_CREATE_APPWIDGET: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 755 | completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 756 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 757 | case REQUEST_RECONFIGURE_APPWIDGET: |
| 758 | completeRestoreAppWidget(args.appWidgetId); |
| 759 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 760 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 761 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 762 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 763 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 764 | resetAddInfo(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 765 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 766 | } |
| 767 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 768 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 769 | protected void onActivityResult( |
| 770 | final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 771 | // Reset the startActivity waiting flag |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 772 | setWaitingForResult(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 773 | final int pendingAddWidgetId = mPendingAddWidgetId; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 774 | mPendingAddWidgetId = -1; |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 775 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 776 | Runnable exitSpringLoaded = new Runnable() { |
| 777 | @Override |
| 778 | public void run() { |
| 779 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 780 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 781 | } |
| 782 | }; |
| 783 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 784 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 785 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 786 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 787 | if (resultCode == RESULT_CANCELED) { |
| 788 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 789 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 790 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 791 | } else if (resultCode == RESULT_OK) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 792 | addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, |
| 793 | mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 794 | } |
| 795 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 796 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 797 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
| 798 | mWorkspace.exitOverviewMode(false); |
| 799 | } |
| 800 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 801 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 802 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 803 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 804 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 805 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 806 | final boolean workspaceLocked = isWorkspaceLocked(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 807 | // We have special handling for widgets |
| 808 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 809 | final int appWidgetId; |
| 810 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 811 | : -1; |
| 812 | if (widgetId < 0) { |
| 813 | appWidgetId = pendingAddWidgetId; |
| 814 | } else { |
| 815 | appWidgetId = widgetId; |
| 816 | } |
| 817 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 818 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 819 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 820 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 821 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 822 | result = RESULT_CANCELED; |
| 823 | completeTwoStageWidgetDrop(result, appWidgetId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 824 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 825 | @Override |
| 826 | public void run() { |
| 827 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 828 | } |
| 829 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 830 | if (workspaceLocked) { |
| 831 | // No need to remove the empty screen if we're mid-binding, as the |
| 832 | // the bind will not add the empty screen. |
| 833 | mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
| 834 | } else { |
| 835 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 836 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 837 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 838 | } else { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 839 | if (!workspaceLocked) { |
| 840 | mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId); |
| 841 | final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
| 842 | |
| 843 | dropLayout.setDropPending(true); |
| 844 | final Runnable onComplete = new Runnable() { |
| 845 | @Override |
| 846 | public void run() { |
| 847 | completeTwoStageWidgetDrop(resultCode, appWidgetId); |
| 848 | dropLayout.setDropPending(false); |
| 849 | } |
| 850 | }; |
| 851 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 852 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 853 | } else { |
| 854 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId, |
| 855 | mPendingAddInfo); |
| 856 | sPendingAddItem = args; |
| 857 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 858 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 859 | return; |
| 860 | } |
| 861 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 862 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) { |
| 863 | if (resultCode == RESULT_OK) { |
| 864 | // Update the widget view. |
| 865 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, |
| 866 | pendingAddWidgetId, mPendingAddInfo); |
| 867 | if (workspaceLocked) { |
| 868 | sPendingAddItem = args; |
| 869 | } else { |
| 870 | completeAdd(args); |
| 871 | } |
| 872 | } |
| 873 | // Leave the widget in the pending state if the user canceled the configure. |
| 874 | return; |
| 875 | } |
| 876 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 877 | // The pattern used here is that a user PICKs a specific application, |
| 878 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 879 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 880 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 881 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Winson Chung | c7da555 | 2011-08-10 15:28:45 -0700 | [diff] [blame] | 882 | if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 883 | final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1, |
| 884 | mPendingAddInfo); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 885 | if (isWorkspaceLocked()) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 886 | sPendingAddItem = args; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 887 | } else { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 888 | completeAdd(args); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 889 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 890 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 891 | } |
Adam Cohen | 0007472 | 2013-10-11 17:46:09 -0700 | [diff] [blame] | 892 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 893 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 894 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 895 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 896 | mDragLayer.clearAnimatedView(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 897 | } |
| 898 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 899 | private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int |
| 900 | appWidgetId, ItemInfo info) { |
| 901 | PendingAddArguments args = new PendingAddArguments(); |
| 902 | args.requestCode = requestCode; |
| 903 | args.intent = data; |
| 904 | args.container = info.container; |
| 905 | args.screenId = info.screenId; |
| 906 | args.cellX = info.cellX; |
| 907 | args.cellY = info.cellY; |
| 908 | args.appWidgetId = appWidgetId; |
| 909 | return args; |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 914 | * |
| 915 | * @param screenId the screen id to check |
| 916 | * @return the new screen, or screenId if it exists |
| 917 | */ |
| 918 | private long ensurePendingDropLayoutExists(long screenId) { |
| 919 | CellLayout dropLayout = |
| 920 | (CellLayout) mWorkspace.getScreenWithId(screenId); |
| 921 | if (dropLayout == null) { |
| 922 | // it's possible that the add screen was removed because it was |
| 923 | // empty and a re-bind occurred |
| 924 | mWorkspace.addExtraEmptyScreen(); |
| 925 | return mWorkspace.commitExtraEmptyScreen(); |
| 926 | } else { |
| 927 | return screenId; |
| 928 | } |
| 929 | } |
| 930 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 931 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 932 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 933 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 934 | Runnable onCompleteRunnable = null; |
| 935 | int animationType = 0; |
| 936 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 937 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 938 | if (resultCode == RESULT_OK) { |
| 939 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 940 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 941 | mPendingAddWidgetInfo); |
| 942 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 943 | onCompleteRunnable = new Runnable() { |
| 944 | @Override |
| 945 | public void run() { |
| 946 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 947 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 948 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 949 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 950 | } |
| 951 | }; |
| 952 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 953 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 954 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 955 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 956 | if (mDragLayer.getAnimatedView() != null) { |
| 957 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 958 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 959 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 960 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 961 | // The animated view may be null in the case of a rotation during widget configuration |
| 962 | onCompleteRunnable.run(); |
| 963 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 967 | protected void onStop() { |
| 968 | super.onStop(); |
| 969 | FirstFrameAnimatorHelper.setIsVisible(false); |
| 970 | } |
| 971 | |
| 972 | @Override |
| 973 | protected void onStart() { |
| 974 | super.onStart(); |
| 975 | FirstFrameAnimatorHelper.setIsVisible(true); |
| 976 | } |
| 977 | |
| 978 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 979 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 980 | long startTime = 0; |
| 981 | if (DEBUG_RESUME_TIME) { |
| 982 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 983 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 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 | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1041 | if (mAppsCustomizeContent != null) { |
| 1042 | // Resets the previous all apps icon press state |
| 1043 | mAppsCustomizeContent.resetDrawableState(); |
| 1044 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 1045 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1046 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 1047 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 1048 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 1049 | // orientation. |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1050 | getWorkspace().reinflateWidgetsIfNecessary(); |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1051 | |
Winson Chung | 780fe59 | 2013-09-26 14:48:44 -0700 | [diff] [blame] | 1052 | // Process any items that were added while Launcher was away. |
| 1053 | InstallShortcutReceiver.disableAndFlushInstallQueue(this); |
| 1054 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 1055 | // Update the voice search button proxy |
| 1056 | updateVoiceButtonProxyVisible(false); |
| 1057 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1058 | // Again, as with the above scenario, it's possible that one or more of the global icons |
| 1059 | // were updated in the wrong orientation. |
| 1060 | updateGlobalIcons(); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1061 | if (DEBUG_RESUME_TIME) { |
| 1062 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1063 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1064 | |
| 1065 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1066 | // If we are resuming and the custom content is the current page, we call onShow(). |
| 1067 | // It is also poassible that onShow will instead be called slightly after first layout |
| 1068 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1069 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1070 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1071 | } |
| 1072 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 1073 | mWorkspace.updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1074 | mWorkspace.onResume(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1075 | |
| 1076 | PackageInstallerCompat.getInstance(this).onResume(); |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1079 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1080 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1081 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1082 | InstallShortcutReceiver.enableInstallQueue(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1083 | PackageInstallerCompat.getInstance(this).onPause(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1084 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1085 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1086 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1087 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1088 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1089 | |
| 1090 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1091 | // debounce excess onHide calls. |
| 1092 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1093 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1094 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1095 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1096 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1097 | QSBScroller mQsbScroller = new QSBScroller() { |
| 1098 | int scrollY = 0; |
| 1099 | |
| 1100 | @Override |
| 1101 | public void setScrollY(int scroll) { |
| 1102 | scrollY = scroll; |
| 1103 | |
| 1104 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
| 1105 | mSearchDropTargetBar.setTranslationY(- scrollY); |
Mark Brophy | d7dc681 | 2013-09-20 17:27:32 +0100 | [diff] [blame] | 1106 | getQsbBar().setTranslationY(-scrollY); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | }; |
| 1110 | |
| 1111 | public void resetQSBScroll() { |
| 1112 | mSearchDropTargetBar.animate().translationY(0).start(); |
Mark Brophy | d7dc681 | 2013-09-20 17:27:32 +0100 | [diff] [blame] | 1113 | getQsbBar().animate().translationY(0).start(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1117 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1118 | // by a onResume or by scrolling otherwise. |
| 1119 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1120 | |
| 1121 | // Custom content is completely hidden |
| 1122 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1123 | |
| 1124 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1125 | public void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1126 | |
| 1127 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1128 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1131 | protected boolean hasSettings() { |
| 1132 | return false; |
| 1133 | } |
| 1134 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1135 | public interface QSBScroller { |
| 1136 | public void setScrollY(int scrollY); |
| 1137 | } |
| 1138 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 1139 | public QSBScroller addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1140 | CustomContentCallbacks callbacks, String description) { |
| 1141 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1142 | return mQsbScroller; |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1145 | // The custom content needs to offset its content to account for the QSB |
| 1146 | public int getTopOffsetForCustomContent() { |
| 1147 | return mWorkspace.getPaddingTop(); |
| 1148 | } |
| 1149 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1150 | @Override |
| 1151 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1152 | // Flag the loader to stop early before switching |
| 1153 | mModel.stopLoader(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1154 | if (mAppsCustomizeContent != null) { |
| 1155 | mAppsCustomizeContent.surrender(); |
| 1156 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1157 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1158 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1159 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1160 | // 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] | 1161 | @Override |
| 1162 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1163 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1164 | mHasFocus = hasFocus; |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1165 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1166 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1167 | private boolean acceptFilter() { |
| 1168 | final InputMethodManager inputManager = (InputMethodManager) |
| 1169 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1170 | return !inputManager.isFullscreenMode(); |
| 1171 | } |
| 1172 | |
| 1173 | @Override |
| 1174 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1175 | final int uniChar = event.getUnicodeChar(); |
| 1176 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1177 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1178 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1179 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1180 | keyCode, event); |
| 1181 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1182 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1183 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1184 | // showSearchDialog() |
| 1185 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1186 | // onSearchRequested() will be called for every keystroke, |
| 1187 | // but it is idempotent, so it's fine. |
| 1188 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1192 | // Eat the long press event so the keyboard doesn't come up. |
| 1193 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1194 | return true; |
| 1195 | } |
| 1196 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1197 | return handled; |
| 1198 | } |
| 1199 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1200 | private String getTypedText() { |
| 1201 | return mDefaultKeySsb.toString(); |
| 1202 | } |
| 1203 | |
| 1204 | private void clearTypedText() { |
| 1205 | mDefaultKeySsb.clear(); |
| 1206 | mDefaultKeySsb.clearSpans(); |
| 1207 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1208 | } |
| 1209 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1210 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1211 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1212 | * State |
| 1213 | */ |
| 1214 | private static State intToState(int stateOrdinal) { |
| 1215 | State state = State.WORKSPACE; |
| 1216 | final State[] stateValues = State.values(); |
| 1217 | for (int i = 0; i < stateValues.length; i++) { |
| 1218 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1219 | state = stateValues[i]; |
| 1220 | break; |
| 1221 | } |
| 1222 | } |
| 1223 | return state; |
| 1224 | } |
| 1225 | |
| 1226 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1227 | * Restores the previous state, if it exists. |
| 1228 | * |
| 1229 | * @param savedState The previous state. |
| 1230 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1231 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1232 | private void restoreState(Bundle savedState) { |
| 1233 | if (savedState == null) { |
| 1234 | return; |
| 1235 | } |
| 1236 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1237 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1238 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1239 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1242 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1243 | PagedView.INVALID_RESTORE_PAGE); |
| 1244 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1245 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1246 | } |
| 1247 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1248 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1249 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1250 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1251 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1252 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1253 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1254 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1255 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1256 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1257 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 1258 | mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1259 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1260 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1261 | mRestoring = true; |
| 1262 | } |
| 1263 | |
| 1264 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1265 | if (renameFolder) { |
| 1266 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1267 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1268 | mRestoring = true; |
| 1269 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1270 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1271 | // Restore the AppsCustomize tab |
| 1272 | if (mAppsCustomizeTabHost != null) { |
| 1273 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1274 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1275 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1276 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1277 | mAppsCustomizeContent.loadAssociatedPages( |
| 1278 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1281 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1282 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1283 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1284 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1285 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | /** |
| 1289 | * Finds all the views we need and configure them properly. |
| 1290 | */ |
| 1291 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1292 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1293 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1294 | mLauncherView = findViewById(R.id.launcher); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1295 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1296 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1297 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1298 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1299 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1300 | mLauncherView.setSystemUiVisibility( |
| 1301 | 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] | 1302 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1303 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1304 | // Setup the drag layer |
| 1305 | mDragLayer.setup(this, dragController); |
| 1306 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1307 | // Setup the hotseat |
| 1308 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1309 | if (mHotseat != null) { |
| 1310 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1311 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1314 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1315 | View widgetButton = findViewById(R.id.widget_button); |
| 1316 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1317 | @Override |
| 1318 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1319 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1320 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1321 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1322 | } |
| 1323 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1324 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1325 | |
| 1326 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1327 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1328 | @Override |
| 1329 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1330 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1331 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1332 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1333 | } |
| 1334 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1335 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1336 | |
| 1337 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1338 | if (hasSettings()) { |
| 1339 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1340 | @Override |
| 1341 | public void onClick(View arg0) { |
| 1342 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1343 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1344 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1345 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1346 | }); |
| 1347 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1348 | } else { |
| 1349 | settingsButton.setVisibility(View.GONE); |
| 1350 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams(); |
| 1351 | lp.gravity = Gravity.END | Gravity.TOP; |
| 1352 | widgetButton.requestLayout(); |
| 1353 | } |
| 1354 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1355 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1356 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1357 | // Setup the workspace |
| 1358 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1359 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1360 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1361 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1362 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1363 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1364 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1365 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1366 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1367 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1368 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1369 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1370 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1371 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1372 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1373 | // 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] | 1374 | dragController.setDragScoller(mWorkspace); |
| 1375 | dragController.setScrollView(mDragLayer); |
| 1376 | dragController.setMoveTarget(mWorkspace); |
| 1377 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1378 | if (mSearchDropTargetBar != null) { |
| 1379 | mSearchDropTargetBar.setup(this, dragController); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1380 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1381 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1382 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1383 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1384 | mWeightWatcher = new WeightWatcher(this); |
| 1385 | mWeightWatcher.setAlpha(0.5f); |
| 1386 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1387 | new FrameLayout.LayoutParams( |
| 1388 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1389 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1390 | Gravity.BOTTOM) |
| 1391 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1392 | |
| 1393 | boolean show = shouldShowWeightWatcher(); |
| 1394 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1395 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1399 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1400 | */ |
| 1401 | public void setAllAppsButton(View allAppsButton) { |
| 1402 | mAllAppsButton = allAppsButton; |
| 1403 | } |
| 1404 | |
| 1405 | public View getAllAppsButton() { |
| 1406 | return mAllAppsButton; |
| 1407 | } |
| 1408 | |
| 1409 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1410 | * Creates a view representing a shortcut. |
| 1411 | * |
| 1412 | * @param info The data structure describing the shortcut. |
| 1413 | * |
| 1414 | * @return A View inflated from R.layout.application. |
| 1415 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1416 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1417 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1418 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | /** |
| 1422 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1423 | * |
| 1424 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1425 | * @param parent The group the shortcut belongs to. |
| 1426 | * @param info The data structure describing the shortcut. |
| 1427 | * |
| 1428 | * @return A View inflated from layoutResId. |
| 1429 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1430 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1431 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 1432 | favorite.applyFromShortcutInfo(info, mIconCache, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1433 | favorite.setOnClickListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1434 | return favorite; |
| 1435 | } |
| 1436 | |
| 1437 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1438 | * Add a shortcut to the workspace. |
| 1439 | * |
| 1440 | * @param data The intent describing the shortcut. |
| 1441 | * @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] | 1442 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1443 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1444 | int cellY) { |
| 1445 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1446 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1447 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1448 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1449 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1450 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1451 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1452 | if (info == null) { |
| 1453 | return; |
| 1454 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1455 | final View view = createShortcut(info); |
| 1456 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1457 | // First we check if we already know the exact location where we want to add this item. |
| 1458 | if (cellX >= 0 && cellY >= 0) { |
| 1459 | cellXY[0] = cellX; |
| 1460 | cellXY[1] = cellY; |
| 1461 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1462 | |
| 1463 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1464 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1465 | true, null,null)) { |
| 1466 | return; |
| 1467 | } |
| 1468 | DragObject dragObject = new DragObject(); |
| 1469 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1470 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1471 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1472 | return; |
| 1473 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1474 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1475 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1476 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1477 | foundCellSpan = (result != null); |
| 1478 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1479 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1483 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1484 | return; |
| 1485 | } |
| 1486 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1487 | 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] | 1488 | |
| 1489 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1490 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1491 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1495 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1496 | int minHeight) { |
| 1497 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1498 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1499 | // to ensure that it gets the full amount of space that it has requested |
| 1500 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1501 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1502 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1505 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1506 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1509 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1510 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1513 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1514 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1517 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1518 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1519 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1520 | } |
| 1521 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1522 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1523 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1524 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1525 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1526 | * @param cellInfo The position on screen where to create the widget. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1527 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1528 | private void completeAddAppWidget(final int appWidgetId, long container, long screenId, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1529 | AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1530 | if (appWidgetInfo == null) { |
| 1531 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1532 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1533 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1534 | // Calculate the grid spans needed to fit this widget |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1535 | CellLayout layout = getCellLayout(container, screenId); |
Adam Cohen | 0935386 | 2011-07-14 16:10:03 -0700 | [diff] [blame] | 1536 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1537 | int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo); |
| 1538 | int[] spanXY = getSpanForWidget(this, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1539 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1540 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1541 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1542 | // if we are placing widgets on a "spring-loaded" screen |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1543 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1544 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1545 | int[] finalSpan = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1546 | boolean foundCellSpan = false; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1547 | if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { |
| 1548 | cellXY[0] = mPendingAddInfo.cellX; |
| 1549 | cellXY[1] = mPendingAddInfo.cellY; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1550 | spanXY[0] = mPendingAddInfo.spanX; |
| 1551 | spanXY[1] = mPendingAddInfo.spanY; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1552 | foundCellSpan = true; |
| 1553 | } else if (touchXY != null) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1554 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1555 | int[] result = layout.findNearestVacantArea( |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1556 | touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], |
| 1557 | spanXY[1], cellXY, finalSpan); |
| 1558 | spanXY[0] = finalSpan[0]; |
| 1559 | spanXY[1] = finalSpan[1]; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1560 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1561 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1562 | foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1565 | if (!foundCellSpan) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1566 | if (appWidgetId != -1) { |
| 1567 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 1568 | // to the caller... |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1569 | new AsyncTask<Void, Void, Void>() { |
| 1570 | public Void doInBackground(Void ... args) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1571 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1572 | return null; |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1573 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1574 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1575 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1576 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1577 | return; |
| 1578 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1579 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1580 | // Build Launcher-specific widget info and save to database |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 1581 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, |
| 1582 | appWidgetInfo.provider); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1583 | launcherInfo.spanX = spanXY[0]; |
| 1584 | launcherInfo.spanY = spanXY[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1585 | launcherInfo.minSpanX = mPendingAddInfo.minSpanX; |
| 1586 | launcherInfo.minSpanY = mPendingAddInfo.minSpanY; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1587 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1588 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1589 | container, screenId, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1590 | |
| 1591 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1592 | if (hostView == null) { |
| 1593 | // Perform actual inflation because we're live |
| 1594 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1595 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1596 | } else { |
| 1597 | // The AppWidgetHostView has already been inflated and instantiated |
| 1598 | launcherInfo.hostView = hostView; |
| 1599 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1600 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1601 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1602 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1603 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1604 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1605 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1606 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1607 | |
| 1608 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1609 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1610 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1611 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1612 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1613 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1614 | @Override |
| 1615 | public void onReceive(Context context, Intent intent) { |
| 1616 | final String action = intent.getAction(); |
| 1617 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1618 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1619 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1620 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1621 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1622 | // 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] | 1623 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1624 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1625 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1626 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1627 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1628 | mUserPresent = true; |
| 1629 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1630 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1631 | mModel.resetLoadedState(false, true); |
| 1632 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1633 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1634 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1635 | mModel.resetLoadedState(false, true); |
| 1636 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1637 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1638 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1639 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1640 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1641 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | }; |
| 1645 | |
| 1646 | @Override |
| 1647 | public void onAttachedToWindow() { |
| 1648 | super.onAttachedToWindow(); |
| 1649 | |
| 1650 | // Listen for broadcasts related to user-presence |
| 1651 | final IntentFilter filter = new IntentFilter(); |
| 1652 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1653 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1654 | // For handling managed profiles |
| 1655 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1656 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1657 | if (ENABLE_DEBUG_INTENTS) { |
| 1658 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1659 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1660 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1661 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1662 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1663 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1664 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1665 | mVisible = true; |
| 1666 | } |
| 1667 | |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1668 | /** |
| 1669 | * Sets up transparent navigation and status bars in LMP. |
| 1670 | * This method is a no-op for other platform versions. |
| 1671 | */ |
| 1672 | @TargetApi(19) |
| 1673 | private void setupTransparentSystemBarsForLmp() { |
| 1674 | // TODO(sansid): use the APIs directly when compiling against L sdk. |
| 1675 | // Currently we use reflection to access the flags and the API to set the transparency |
| 1676 | // on the System bars. |
| 1677 | if (Utilities.isLmp()) { |
| 1678 | try { |
| 1679 | getWindow().getAttributes().systemUiVisibility |= |
| 1680 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1681 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1682 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1683 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
| 1684 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
| 1685 | Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( |
| 1686 | "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); |
| 1687 | getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); |
| 1688 | |
| 1689 | Method setStatusBarColorMethod = |
| 1690 | Window.class.getDeclaredMethod("setStatusBarColor", int.class); |
| 1691 | Method setNavigationBarColorMethod = |
| 1692 | Window.class.getDeclaredMethod("setNavigationBarColor", int.class); |
| 1693 | setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1694 | setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1695 | } catch (NoSuchFieldException e) { |
| 1696 | Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); |
| 1697 | } catch (NoSuchMethodException ex) { |
| 1698 | Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); |
| 1699 | } catch (IllegalAccessException e) { |
| 1700 | Log.w(TAG, "IllegalAccessException while setting up transparent bars"); |
| 1701 | } catch (IllegalArgumentException e) { |
| 1702 | Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); |
| 1703 | } catch (InvocationTargetException e) { |
| 1704 | Log.w(TAG, "InvocationTargetException while setting up transparent bars"); |
| 1705 | } finally {} |
| 1706 | } |
| 1707 | } |
| 1708 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1709 | @Override |
| 1710 | public void onDetachedFromWindow() { |
| 1711 | super.onDetachedFromWindow(); |
| 1712 | mVisible = false; |
| 1713 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1714 | if (mAttached) { |
| 1715 | unregisterReceiver(mReceiver); |
| 1716 | mAttached = false; |
| 1717 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1718 | updateRunning(); |
| 1719 | } |
| 1720 | |
| 1721 | public void onWindowVisibilityChanged(int visibility) { |
| 1722 | mVisible = visibility == View.VISIBLE; |
| 1723 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1724 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1725 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1726 | // is a more appropriate event to handle |
| 1727 | if (mVisible) { |
| 1728 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1729 | if (!mWorkspaceLoading) { |
| 1730 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1731 | // We want to let Launcher draw itself at least once before we force it to build |
| 1732 | // 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] | 1733 | // apps is nice and speedy. |
| 1734 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1735 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1736 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1737 | if (mStarted) return; |
| 1738 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1739 | // We delay the layer building a bit in order to give |
| 1740 | // other message processing a time to run. In particular |
| 1741 | // this avoids a delay in hiding the IME if it was |
| 1742 | // currently shown, because doing that may involve |
| 1743 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1744 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1745 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1746 | mWorkspace.post(new Runnable() { |
| 1747 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1748 | if (mWorkspace != null && |
| 1749 | mWorkspace.getViewTreeObserver() != null) { |
| 1750 | mWorkspace.getViewTreeObserver(). |
| 1751 | removeOnDrawListener(listener); |
| 1752 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1753 | } |
| 1754 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1755 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1756 | } |
| 1757 | }); |
| 1758 | } |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1759 | // When Launcher comes back to foreground, a different Activity might be responsible for |
| 1760 | // the app market intent, so refresh the icon |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 1761 | if (!DISABLE_MARKET_BUTTON) { |
| 1762 | updateAppMarketIcon(); |
| 1763 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1764 | clearTypedText(); |
| 1765 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | private void sendAdvanceMessage(long delay) { |
| 1769 | mHandler.removeMessages(ADVANCE_MSG); |
| 1770 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1771 | mHandler.sendMessageDelayed(msg, delay); |
| 1772 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1773 | } |
| 1774 | |
| 1775 | private void updateRunning() { |
| 1776 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1777 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1778 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1779 | if (autoAdvanceRunning) { |
| 1780 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1781 | sendAdvanceMessage(delay); |
| 1782 | } else { |
| 1783 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1784 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1785 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1786 | } |
| 1787 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1788 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1789 | } |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | private final Handler mHandler = new Handler() { |
| 1794 | @Override |
| 1795 | public void handleMessage(Message msg) { |
| 1796 | if (msg.what == ADVANCE_MSG) { |
| 1797 | int i = 0; |
| 1798 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1799 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1800 | final int delay = mAdvanceStagger * i; |
| 1801 | if (v instanceof Advanceable) { |
| 1802 | postDelayed(new Runnable() { |
| 1803 | public void run() { |
| 1804 | ((Advanceable) v).advance(); |
| 1805 | } |
| 1806 | }, delay); |
| 1807 | } |
| 1808 | i++; |
| 1809 | } |
| 1810 | sendAdvanceMessage(mAdvanceInterval); |
| 1811 | } |
| 1812 | } |
| 1813 | }; |
| 1814 | |
| 1815 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1816 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1817 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1818 | if (v instanceof Advanceable) { |
| 1819 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1820 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1821 | updateRunning(); |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | void removeWidgetToAutoAdvance(View hostView) { |
| 1826 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1827 | mWidgetsToAdvance.remove(hostView); |
| 1828 | updateRunning(); |
| 1829 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1832 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1833 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1834 | launcherInfo.hostView = null; |
| 1835 | } |
| 1836 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1837 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1838 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1839 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1842 | public DragLayer getDragLayer() { |
| 1843 | return mDragLayer; |
| 1844 | } |
| 1845 | |
| 1846 | public Workspace getWorkspace() { |
| 1847 | return mWorkspace; |
| 1848 | } |
| 1849 | |
| 1850 | public Hotseat getHotseat() { |
| 1851 | return mHotseat; |
| 1852 | } |
| 1853 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1854 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1855 | return mOverviewPanel; |
| 1856 | } |
| 1857 | |
| 1858 | public SearchDropTargetBar getSearchBar() { |
| 1859 | return mSearchDropTargetBar; |
| 1860 | } |
| 1861 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1862 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1863 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1864 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1865 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1866 | public LauncherModel getModel() { |
| 1867 | return mModel; |
| 1868 | } |
| 1869 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1870 | public LauncherClings getLauncherClings() { |
| 1871 | return mLauncherClings; |
| 1872 | } |
| 1873 | |
| 1874 | protected SharedPreferences getSharedPrefs() { |
| 1875 | return mSharedPrefs; |
| 1876 | } |
| 1877 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1878 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1879 | getWindow().closeAllPanels(); |
| 1880 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1881 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1882 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1883 | } |
| 1884 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1885 | @Override |
| 1886 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1887 | long startTime = 0; |
| 1888 | if (DEBUG_RESUME_TIME) { |
| 1889 | startTime = System.currentTimeMillis(); |
| 1890 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1891 | super.onNewIntent(intent); |
| 1892 | |
| 1893 | // Close the menu |
| 1894 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1895 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1896 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1897 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1898 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1899 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1900 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1901 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1902 | if (mWorkspace == null) { |
| 1903 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1904 | return; |
| 1905 | } |
| 1906 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1907 | // In all these cases, only animate if we're already on home |
| 1908 | mWorkspace.exitWidgetResizeMode(); |
| 1909 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1910 | openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1911 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1912 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1913 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1914 | closeFolder(); |
| 1915 | exitSpringLoadedDragMode(); |
| 1916 | |
| 1917 | // If we are already on home, then just animate back to the workspace, |
| 1918 | // otherwise, just wait until onResume to set the state back to Workspace |
| 1919 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1920 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1921 | } else { |
| 1922 | mOnResumeState = State.WORKSPACE; |
| 1923 | } |
| 1924 | |
| 1925 | final View v = getWindow().peekDecorView(); |
| 1926 | if (v != null && v.getWindowToken() != null) { |
| 1927 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1928 | INPUT_METHOD_SERVICE); |
| 1929 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 1930 | } |
| 1931 | |
| 1932 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 1933 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1934 | mAppsCustomizeTabHost.reset(); |
| 1935 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1936 | |
| 1937 | onHomeIntent(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1938 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1939 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1940 | if (DEBUG_RESUME_TIME) { |
| 1941 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 1942 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1943 | } |
| 1944 | |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1945 | /** |
| 1946 | * Override point for subclasses to prevent movement to the default screen when the home |
| 1947 | * button is pressed. Used (for example) in GEL, to prevent movement during a search. |
| 1948 | */ |
| 1949 | protected boolean shouldMoveToDefaultScreenOnHomeIntent() { |
| 1950 | return true; |
| 1951 | } |
| 1952 | |
| 1953 | /** |
| 1954 | * Override point for subclasses to provide custom behaviour for when a home intent is fired. |
| 1955 | */ |
| 1956 | protected void onHomeIntent() { |
| 1957 | // Do nothing |
| 1958 | } |
| 1959 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1960 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1961 | public void onRestoreInstanceState(Bundle state) { |
| 1962 | super.onRestoreInstanceState(state); |
| 1963 | for (int page: mSynchronouslyBoundPages) { |
| 1964 | mWorkspace.restoreInstanceStateForChild(page); |
| 1965 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | @Override |
| 1969 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1970 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 1971 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1972 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1973 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1974 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1975 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1976 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 1977 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 1978 | // this state is reflected. |
| 1979 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1980 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1981 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1982 | mWaitingForResult) { |
| 1983 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1984 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1985 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 1986 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1987 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 1988 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 1989 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1990 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | if (mFolderInfo != null && mWaitingForResult) { |
| 1994 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1995 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1996 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1997 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1998 | // Save the current AppsCustomize tab |
| 1999 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 2000 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 2001 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2002 | if (currentTabTag != null) { |
| 2003 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 2004 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 2005 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 2006 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2007 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 2008 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | @Override |
| 2012 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2013 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2014 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2015 | // Remove all pending runnables |
| 2016 | mHandler.removeMessages(ADVANCE_MSG); |
| 2017 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 2018 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2019 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2020 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 2021 | LauncherAppState app = (LauncherAppState.getInstance()); |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2022 | mModel.stopLoader(); |
| 2023 | app.setLauncher(null); |
| 2024 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2025 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2026 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2027 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2028 | 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] | 2029 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2030 | mAppWidgetHost = null; |
| 2031 | |
| 2032 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2033 | |
| 2034 | TextKeyListener.getInstance().release(); |
| 2035 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 2036 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 2037 | // to prevent leaking Launcher activities on orientation change. |
| 2038 | if (mModel != null) { |
| 2039 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 2040 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2041 | |
| 2042 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2043 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2044 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 2045 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2046 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 2047 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2048 | mWorkspace = null; |
| 2049 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 2050 | |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 2051 | PackageInstallerCompat.getInstance(this).onStop(); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2052 | LauncherAnimUtils.onDestroyActivity(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2053 | } |
| 2054 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2055 | public DragController getDragController() { |
| 2056 | return mDragController; |
| 2057 | } |
| 2058 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2059 | @Override |
| 2060 | public void startActivityForResult(Intent intent, int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2061 | if (requestCode >= 0) { |
| 2062 | setWaitingForResult(true); |
| 2063 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2064 | super.startActivityForResult(intent, requestCode); |
| 2065 | } |
| 2066 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2067 | /** |
| 2068 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2069 | * argument for {@link #startSearch} to true. |
| 2070 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2071 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2072 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2073 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2074 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2075 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2076 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2077 | if (initialQuery == null) { |
| 2078 | // Use any text typed in the launcher as the initial query |
| 2079 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2080 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2081 | if (appSearchData == null) { |
| 2082 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2083 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2084 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2085 | Rect sourceBounds = new Rect(); |
| 2086 | if (mSearchDropTargetBar != null) { |
| 2087 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2088 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2089 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2090 | startSearch(initialQuery, selectInitialQuery, |
| 2091 | appSearchData, sourceBounds); |
| 2092 | } |
| 2093 | |
| 2094 | public void startSearch(String initialQuery, |
| 2095 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2096 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2097 | appSearchData, sourceBounds); |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | /** |
| 2101 | * Starts the global search activity. This code is a copied from SearchManager |
| 2102 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2103 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2104 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2105 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2106 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2107 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2108 | if (globalSearchActivity == null) { |
| 2109 | Log.w(TAG, "No global search activity found."); |
| 2110 | return; |
| 2111 | } |
| 2112 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2113 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2114 | intent.setComponent(globalSearchActivity); |
| 2115 | // Make sure that we have a Bundle to put source in |
| 2116 | if (appSearchData == null) { |
| 2117 | appSearchData = new Bundle(); |
| 2118 | } else { |
| 2119 | appSearchData = new Bundle(appSearchData); |
| 2120 | } |
| 2121 | // Set source to package name of app that starts global search, if not set already. |
| 2122 | if (!appSearchData.containsKey("source")) { |
| 2123 | appSearchData.putString("source", getPackageName()); |
| 2124 | } |
| 2125 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2126 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2127 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2128 | } |
| 2129 | if (selectInitialQuery) { |
| 2130 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2131 | } |
| 2132 | intent.setSourceBounds(sourceBounds); |
| 2133 | try { |
| 2134 | startActivity(intent); |
| 2135 | } catch (ActivityNotFoundException ex) { |
| 2136 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2137 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2138 | } |
| 2139 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2140 | public boolean isOnCustomContent() { |
| 2141 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2142 | } |
| 2143 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2144 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2145 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2146 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2147 | if (!isOnCustomContent()) { |
| 2148 | // Close any open folders |
| 2149 | closeFolder(); |
| 2150 | // Stop resizing any widgets |
| 2151 | mWorkspace.exitWidgetResizeMode(); |
| 2152 | if (!mWorkspace.isInOverviewMode()) { |
| 2153 | // Show the overview mode |
| 2154 | showOverviewMode(true); |
| 2155 | } else { |
| 2156 | showWorkspace(true); |
| 2157 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2158 | } |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2159 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2160 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2161 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2162 | @Override |
| 2163 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2164 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2165 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2166 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2169 | public boolean isWorkspaceLocked() { |
| 2170 | return mWorkspaceLoading || mWaitingForResult; |
| 2171 | } |
| 2172 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2173 | public boolean isWorkspaceLoading() { |
| 2174 | return mWorkspaceLoading; |
| 2175 | } |
| 2176 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2177 | private void setWorkspaceLoading(boolean value) { |
| 2178 | boolean isLocked = isWorkspaceLocked(); |
| 2179 | mWorkspaceLoading = value; |
| 2180 | if (isLocked != isWorkspaceLocked()) { |
| 2181 | onWorkspaceLockedChanged(); |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | private void setWaitingForResult(boolean value) { |
| 2186 | boolean isLocked = isWorkspaceLocked(); |
| 2187 | mWaitingForResult = value; |
| 2188 | if (isLocked != isWorkspaceLocked()) { |
| 2189 | onWorkspaceLockedChanged(); |
| 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | protected void onWorkspaceLockedChanged() { } |
| 2194 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2195 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2196 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2197 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2198 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2199 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2200 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2201 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2202 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2203 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2204 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2205 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) { |
| 2206 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2207 | } |
| 2208 | |
| 2209 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2210 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int |
| 2211 | delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2212 | if (appWidgetInfo.configure != null) { |
| 2213 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2214 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2215 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2216 | // Launch over to configure widget, if needed |
| 2217 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2218 | intent.setComponent(appWidgetInfo.configure); |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2219 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
Michael Jurka | a805e1a | 2013-08-22 15:00:33 +0200 | [diff] [blame] | 2220 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2221 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2222 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2223 | Runnable onComplete = new Runnable() { |
| 2224 | @Override |
| 2225 | public void run() { |
| 2226 | // Exit spring loaded mode if necessary after adding the widget |
| 2227 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2228 | null); |
| 2229 | } |
| 2230 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2231 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2232 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2233 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2234 | } |
| 2235 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2236 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2237 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2238 | // Close any folders that may be open. |
| 2239 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2240 | mWorkspace.moveToCustomContentScreen(animate); |
| 2241 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2242 | /** |
| 2243 | * Process a shortcut drop. |
| 2244 | * |
| 2245 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2246 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2247 | * @param cell The cell it should be added to, optional |
| 2248 | * @param position The location on the screen where it was dropped, optional |
| 2249 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2250 | void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2251 | int[] cell, int[] loc) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2252 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2253 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2254 | mPendingAddInfo.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2255 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2256 | |
| 2257 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2258 | mPendingAddInfo.cellX = cell[0]; |
| 2259 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2260 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2261 | |
| 2262 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2263 | createShortcutIntent.setComponent(componentName); |
| 2264 | processShortcut(createShortcutIntent); |
| 2265 | } |
| 2266 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2267 | /** |
| 2268 | * Process a widget drop. |
| 2269 | * |
| 2270 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2271 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2272 | * @param cell The cell it should be added to, optional |
| 2273 | * @param position The location on the screen where it was dropped, optional |
| 2274 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2275 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2276 | int[] cell, int[] span, int[] loc) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2277 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2278 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2279 | mPendingAddInfo.screenId = info.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2280 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2281 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2282 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2283 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2284 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2285 | mPendingAddInfo.cellX = cell[0]; |
| 2286 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2287 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2288 | if (span != null) { |
| 2289 | mPendingAddInfo.spanX = span[0]; |
| 2290 | mPendingAddInfo.spanY = span[1]; |
| 2291 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2292 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2293 | AppWidgetHostView hostView = info.boundWidget; |
| 2294 | int appWidgetId; |
| 2295 | if (hostView != null) { |
| 2296 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2297 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2298 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2299 | // In this case, we either need to start an activity to get permission to bind |
| 2300 | // 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] | 2301 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2302 | Bundle options = info.bindOptions; |
| 2303 | |
| 2304 | boolean success = false; |
| 2305 | if (options != null) { |
| 2306 | success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, |
| 2307 | info.componentName, options); |
| 2308 | } else { |
| 2309 | success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, |
| 2310 | info.componentName); |
| 2311 | } |
| 2312 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2313 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2314 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2315 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2316 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2317 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2318 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2319 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2320 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2321 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2322 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2323 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2326 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2327 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2328 | } |
| 2329 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2330 | void processWallpaper(Intent intent) { |
| 2331 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2332 | } |
| 2333 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2334 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2335 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2336 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2337 | folderInfo.title = getText(R.string.folder_name); |
| 2338 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2339 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2340 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2341 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2342 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2343 | |
| 2344 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2345 | FolderIcon newFolder = |
| 2346 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2347 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2348 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2349 | // Force measure the new folder icon |
| 2350 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2351 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2352 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2353 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2354 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2355 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2356 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2357 | } |
| 2358 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2359 | protected ComponentName getWallpaperPickerComponent() { |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2360 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2361 | } |
| 2362 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2363 | /** |
| 2364 | * Registers various content observers. The current implementation registers |
| 2365 | * only a favorites observer to keep track of the favorites applications. |
| 2366 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2367 | private void registerContentObservers() { |
| 2368 | ContentResolver resolver = getContentResolver(); |
| 2369 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2370 | true, mWidgetObserver); |
| 2371 | } |
| 2372 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2373 | @Override |
| 2374 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2375 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2376 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2377 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2378 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2379 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 2380 | if (isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2381 | dumpState(); |
| 2382 | return true; |
| 2383 | } |
| 2384 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2385 | } |
| 2386 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2387 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2388 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2389 | return true; |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | return super.dispatchKeyEvent(event); |
| 2394 | } |
| 2395 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2396 | @Override |
| 2397 | public void onBackPressed() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2398 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2399 | if (mAppsCustomizeContent.getContentType() == |
| 2400 | AppsCustomizePagedView.ContentType.Applications) { |
| 2401 | showWorkspace(true); |
| 2402 | } else { |
| 2403 | showOverviewMode(true); |
| 2404 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2405 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2406 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2407 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2408 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2409 | if (openFolder.isEditingName()) { |
| 2410 | openFolder.dismissEditingName(); |
| 2411 | } else { |
| 2412 | closeFolder(); |
| 2413 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2414 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2415 | mWorkspace.exitWidgetResizeMode(); |
| 2416 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2417 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2418 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2419 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2420 | } |
| 2421 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2422 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2423 | * Re-listen when widgets are reset. |
| 2424 | */ |
| 2425 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2426 | if (mAppWidgetHost != null) { |
| 2427 | mAppWidgetHost.startListening(); |
| 2428 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2432 | * Launches the intent referred by the clicked shortcut. |
| 2433 | * |
| 2434 | * @param v The view representing the clicked shortcut. |
| 2435 | */ |
| 2436 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2437 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2438 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2439 | if (v.getWindowToken() == null) { |
| 2440 | return; |
| 2441 | } |
| 2442 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2443 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2444 | return; |
| 2445 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2446 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2447 | if (v instanceof Workspace) { |
| 2448 | if (mWorkspace.isInOverviewMode()) { |
| 2449 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2450 | } |
| 2451 | return; |
| 2452 | } |
| 2453 | |
| 2454 | if (v instanceof CellLayout) { |
| 2455 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2456 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2457 | } |
| 2458 | } |
| 2459 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2460 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2461 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2462 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2463 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2464 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2465 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2466 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2467 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2468 | onClickAllAppsButton(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2469 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2470 | if (v instanceof PendingAppWidgetHostView) { |
| 2471 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2472 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2473 | } |
| 2474 | } |
| 2475 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2476 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2477 | return false; |
| 2478 | } |
| 2479 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2480 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2481 | * Event handler for the app widget view which has not fully restored. |
| 2482 | */ |
| 2483 | public void onClickPendingWidget(PendingAppWidgetHostView v) { |
| 2484 | if (v.isReadyForClickSetup()) { |
| 2485 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
| 2486 | int widgetId = info.appWidgetId; |
| 2487 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
| 2488 | if (appWidgetInfo != null) { |
| 2489 | mPendingAddWidgetInfo = appWidgetInfo; |
| 2490 | mPendingAddInfo.copyFrom(info); |
| 2491 | mPendingAddWidgetId = widgetId; |
| 2492 | |
| 2493 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
| 2494 | intent.setComponent(appWidgetInfo.configure); |
| 2495 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId); |
| 2496 | Utilities.startActivityForResultSafely(this, intent, REQUEST_RECONFIGURE_APPWIDGET); |
| 2497 | } |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2502 | * Event handler for the search button |
| 2503 | * |
| 2504 | * @param v The view that was clicked. |
| 2505 | */ |
| 2506 | public void onClickSearchButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2507 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2508 | |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2509 | onSearchRequested(); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2513 | * Event handler for the voice button |
| 2514 | * |
| 2515 | * @param v The view that was clicked. |
| 2516 | */ |
| 2517 | public void onClickVoiceButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2518 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2519 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2520 | startVoice(); |
| 2521 | } |
| 2522 | |
| 2523 | public void startVoice() { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2524 | try { |
| 2525 | final SearchManager searchManager = |
| 2526 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2527 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 2528 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2529 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2530 | if (activityName != null) { |
| 2531 | intent.setPackage(activityName.getPackageName()); |
| 2532 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2533 | startActivity(null, intent, "onClickVoiceButton"); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2534 | } catch (ActivityNotFoundException e) { |
| 2535 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2536 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2537 | startActivitySafely(null, intent, "onClickVoiceButton"); |
| 2538 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2542 | * Event handler for the "grid" button that appears on the home screen, which |
| 2543 | * enters all apps mode. |
| 2544 | * |
| 2545 | * @param v The view that was clicked. |
| 2546 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2547 | protected void onClickAllAppsButton(View v) { |
| 2548 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2549 | if (isAllAppsVisible()) { |
| 2550 | showWorkspace(true); |
| 2551 | } else { |
| 2552 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | /** |
Mohammadinamul Sheik | 3b1a54a | 2014-03-18 11:28:19 -0700 | [diff] [blame] | 2557 | * Event handler for a paged view icon click. |
| 2558 | * @param v The view that was clicked. |
| 2559 | * @param appInfo The {link AppInfo} of the view. |
| 2560 | */ |
| 2561 | public void onClickPagedViewIcon(View v, AppInfo appInfo) { |
| 2562 | if (LOGD) Log.d(TAG, "onClickPagedViewIcon"); |
| 2563 | startActivitySafely(v, appInfo.intent, appInfo); |
| 2564 | getStats().recordLaunch(appInfo.intent); |
| 2565 | } |
| 2566 | |
| 2567 | /** |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2568 | * Event handler for an app shortcut click. |
| 2569 | * |
| 2570 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2571 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2572 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2573 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2574 | Object tag = v.getTag(); |
| 2575 | if (!(tag instanceof ShortcutInfo)) { |
| 2576 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2577 | } |
| 2578 | |
| 2579 | // Open shortcut |
| 2580 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
| 2581 | final Intent intent = shortcut.intent; |
| 2582 | |
| 2583 | // Check for special shortcuts |
| 2584 | if (intent.getComponent() != null) { |
| 2585 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2586 | |
| 2587 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2588 | MemoryDumpActivity.startDump(this); |
| 2589 | return; |
| 2590 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2591 | toggleShowWeightWatcher(); |
| 2592 | return; |
| 2593 | } |
| 2594 | } |
| 2595 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2596 | // Check for abandoned promise |
| 2597 | if (shortcut.isAbandoned() && v instanceof BubbleTextView) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2598 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 2599 | builder.setTitle(R.string.abandoned_promises_title); |
Chris Wren | 803a4be | 2014-07-01 16:52:49 -0400 | [diff] [blame] | 2600 | builder.setMessage(R.string.abandoned_promise_explanation); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2601 | builder.setPositiveButton(R.string.abandoned_search, |
| 2602 | new DialogInterface.OnClickListener() { |
| 2603 | public void onClick(DialogInterface dialog, int id) { |
| 2604 | startAppShortcutActivity(v); |
| 2605 | } |
| 2606 | } |
| 2607 | ); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2608 | builder.setNeutralButton(R.string.abandoned_clean_this, |
| 2609 | new DialogInterface.OnClickListener() { |
| 2610 | public void onClick(DialogInterface dialog, int id) { |
| 2611 | final BubbleTextView bubble = (BubbleTextView) v; |
| 2612 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 2613 | mWorkspace.removeAbandonedPromise(bubble, user); |
| 2614 | } |
| 2615 | }); |
| 2616 | builder.create().show(); |
| 2617 | return; |
| 2618 | } |
| 2619 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2620 | // Start activities |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2621 | startAppShortcutActivity(v); |
| 2622 | } |
| 2623 | |
| 2624 | private void startAppShortcutActivity(View v) { |
| 2625 | Object tag = v.getTag(); |
| 2626 | if (!(tag instanceof ShortcutInfo)) { |
| 2627 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2628 | } |
| 2629 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
| 2630 | final Intent intent = shortcut.intent; |
| 2631 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2632 | int[] pos = new int[2]; |
| 2633 | v.getLocationOnScreen(pos); |
| 2634 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2635 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
| 2636 | |
| 2637 | boolean success = startActivitySafely(v, intent, tag); |
| 2638 | |
| 2639 | mStats.recordLaunch(intent, shortcut); |
| 2640 | |
| 2641 | if (success && v instanceof BubbleTextView) { |
| 2642 | mWaitingForResume = (BubbleTextView) v; |
| 2643 | mWaitingForResume.setStayPressed(true); |
| 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | /** |
| 2648 | * Event handler for a folder icon click. |
| 2649 | * |
| 2650 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2651 | */ |
| 2652 | protected void onClickFolderIcon(View v) { |
| 2653 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2654 | if (!(v instanceof FolderIcon)){ |
| 2655 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2656 | } |
| 2657 | |
| 2658 | FolderIcon folderIcon = (FolderIcon) v; |
| 2659 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2660 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2661 | |
| 2662 | // If the folder info reports that the associated folder is open, then verify that |
| 2663 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2664 | if (info.opened && openFolder == null) { |
| 2665 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2666 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2667 | info.opened = false; |
| 2668 | } |
| 2669 | |
| 2670 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2671 | // Close any open folder |
| 2672 | closeFolder(); |
| 2673 | // Open the requested folder |
| 2674 | openFolder(folderIcon); |
| 2675 | } else { |
| 2676 | // Find the open folder... |
| 2677 | int folderScreen; |
| 2678 | if (openFolder != null) { |
| 2679 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2680 | // .. and close it |
| 2681 | closeFolder(openFolder); |
| 2682 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2683 | // Close any folder open on the current screen |
| 2684 | closeFolder(); |
| 2685 | // Pull the folder onto this screen |
| 2686 | openFolder(folderIcon); |
| 2687 | } |
| 2688 | } |
| 2689 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2692 | /** |
| 2693 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2694 | * on the home screen. |
| 2695 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2696 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2697 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2698 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2699 | } |
| 2700 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2701 | /** |
| 2702 | * Event handler for the wallpaper picker button that appears after a long press |
| 2703 | * on the home screen. |
| 2704 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2705 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2706 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2707 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2708 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2709 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
| 2710 | } |
| 2711 | |
| 2712 | /** |
| 2713 | * Event handler for a click on the settings button that appears after a long press |
| 2714 | * on the home screen. |
| 2715 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2716 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2717 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
| 2718 | } |
| 2719 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2720 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2721 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2722 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2725 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2726 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2727 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2728 | } |
| 2729 | |
| 2730 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2731 | if (mHapticFeedbackTouchListener == null) { |
| 2732 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2733 | @Override |
| 2734 | public boolean onTouch(View v, MotionEvent event) { |
| 2735 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2736 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2737 | } |
| 2738 | return false; |
| 2739 | } |
| 2740 | }; |
| 2741 | } |
| 2742 | return mHapticFeedbackTouchListener; |
| 2743 | } |
| 2744 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2745 | public void onClickAppMarketButton(View v) { |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 2746 | if (!DISABLE_MARKET_BUTTON) { |
| 2747 | if (mAppMarketIntent != null) { |
| 2748 | startActivitySafely(v, mAppMarketIntent, "app market"); |
| 2749 | } else { |
| 2750 | Log.e(TAG, "Invalid app market intent."); |
| 2751 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2755 | public void onDragStarted(View view) {} |
| 2756 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2757 | /** |
| 2758 | * Called when the user stops interacting with the launcher. |
| 2759 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2760 | */ |
| 2761 | protected void onInteractionEnd() {} |
| 2762 | |
| 2763 | /** |
| 2764 | * Called when the user starts interacting with the launcher. |
| 2765 | * The possible interactions are: |
| 2766 | * - open all apps |
| 2767 | * - reorder an app shortcut, or a widget |
| 2768 | * - open the overview mode. |
| 2769 | * This is a good time to stop doing things that only make sense |
| 2770 | * when the user is on the homescreen and not doing housekeeping. |
| 2771 | */ |
| 2772 | protected void onInteractionBegin() {} |
| 2773 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2774 | void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2775 | String packageName = componentName.getPackageName(); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2776 | try { |
| 2777 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2778 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
| 2779 | launcherApps.showAppDetailsForProfile(componentName, user); |
| 2780 | } catch (SecurityException e) { |
| 2781 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2782 | Log.e(TAG, "Launcher does not have permission to launch settings"); |
| 2783 | } catch (ActivityNotFoundException e) { |
| 2784 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2785 | Log.e(TAG, "Unable to launch settings"); |
| 2786 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2789 | // returns true if the activity was started |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2790 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags, |
| 2791 | UserHandleCompat user) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2792 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2793 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2794 | // We may give them the option of disabling apps this way. |
| 2795 | int messageId = R.string.uninstall_system_app_text; |
| 2796 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2797 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2798 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2799 | String packageName = componentName.getPackageName(); |
| 2800 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2801 | Intent intent = new Intent( |
| 2802 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2803 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2804 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2805 | if (user != null) { |
| 2806 | user.addToIntent(intent, Intent.EXTRA_USER); |
| 2807 | } |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2808 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2809 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2810 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2813 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 2814 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2815 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2816 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 2817 | // private contract between launcher and may be ignored in the future). |
| 2818 | boolean useLaunchAnimation = (v != null) && |
| 2819 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2820 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2821 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2822 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2823 | UserHandleCompat user = null; |
| 2824 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 2825 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 2826 | user = userManager.getUserForSerialNumber(serialNumber); |
| 2827 | } |
| 2828 | |
| 2829 | Bundle optsBundle = null; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2830 | if (useLaunchAnimation) { |
Adam Cohen | 4da294d | 2014-07-28 10:56:19 -0700 | [diff] [blame] | 2831 | ActivityOptions opts = Utilities.isLmp() ? |
| 2832 | ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) : |
| 2833 | ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 2834 | optsBundle = opts.toBundle(); |
| 2835 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2836 | |
| 2837 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 2838 | // Could be launching some bookkeeping activity |
| 2839 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2840 | } else { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2841 | // TODO Component can be null when shortcuts are supported for secondary user |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 2842 | launcherApps.startActivityForProfile(intent.getComponent(), user, |
| 2843 | intent.getSourceBounds(), optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2844 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2845 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2846 | } catch (SecurityException e) { |
| 2847 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2848 | 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] | 2849 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2850 | "or use the exported attribute for this activity. " |
| 2851 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2852 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2853 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2854 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2855 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2856 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 2857 | boolean success = false; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2858 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 2859 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 2860 | return false; |
| 2861 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2862 | try { |
| 2863 | success = startActivity(v, intent, tag); |
| 2864 | } catch (ActivityNotFoundException e) { |
| 2865 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2866 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 2867 | } |
| 2868 | return success; |
| 2869 | } |
| 2870 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2871 | /** |
| 2872 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 2873 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 2874 | */ |
| 2875 | private void copyFolderIconToImage(FolderIcon fi) { |
| 2876 | final int width = fi.getMeasuredWidth(); |
| 2877 | final int height = fi.getMeasuredHeight(); |
| 2878 | |
| 2879 | // Lazy load ImageView, Bitmap and Canvas |
| 2880 | if (mFolderIconImageView == null) { |
| 2881 | mFolderIconImageView = new ImageView(this); |
| 2882 | } |
| 2883 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 2884 | mFolderIconBitmap.getHeight() != height) { |
| 2885 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 2886 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 2887 | } |
| 2888 | |
| 2889 | DragLayer.LayoutParams lp; |
| 2890 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 2891 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 2892 | } else { |
| 2893 | lp = new DragLayer.LayoutParams(width, height); |
| 2894 | } |
| 2895 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2896 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 2897 | // view size by this scale factor. |
| 2898 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2899 | lp.customPosition = true; |
| 2900 | lp.x = mRectForFolderAnimation.left; |
| 2901 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2902 | lp.width = (int) (scale * width); |
| 2903 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2904 | |
| 2905 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2906 | fi.draw(mFolderIconCanvas); |
| 2907 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2908 | if (fi.getFolder() != null) { |
| 2909 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 2910 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2911 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2912 | // Just in case this image view is still in the drag layer from a previous animation, |
| 2913 | // we remove it and re-add it. |
| 2914 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 2915 | mDragLayer.removeView(mFolderIconImageView); |
| 2916 | } |
| 2917 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2918 | if (fi.getFolder() != null) { |
| 2919 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2920 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2921 | } |
| 2922 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2923 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2924 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2925 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 2926 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 2927 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 2928 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2929 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 2930 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2931 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 2932 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 2933 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2936 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 2937 | copyFolderIconToImage(fi); |
| 2938 | fi.setVisibility(View.INVISIBLE); |
| 2939 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2940 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2941 | scaleX, scaleY); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2942 | oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); |
| 2943 | oa.start(); |
| 2944 | } |
| 2945 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2946 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2947 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2948 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 2949 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 2950 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 2951 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2952 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2953 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2954 | // We remove and re-draw the FolderIcon in-case it has changed |
| 2955 | mDragLayer.removeView(mFolderIconImageView); |
| 2956 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2957 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2958 | scaleX, scaleY); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2959 | oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2960 | oa.addListener(new AnimatorListenerAdapter() { |
| 2961 | @Override |
| 2962 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2963 | if (cl != null) { |
| 2964 | cl.clearFolderLeaveBehind(); |
| 2965 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 2966 | mDragLayer.removeView(mFolderIconImageView); |
| 2967 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2968 | } |
| 2969 | } |
| 2970 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2971 | oa.start(); |
| 2972 | } |
| 2973 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2974 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 2975 | * 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] | 2976 | * is animated relative to the specified View. If the View is null, no animation |
| 2977 | * is played. |
| 2978 | * |
| 2979 | * @param folderInfo The FolderInfo describing the folder to open. |
| 2980 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2981 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2982 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2983 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2984 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2985 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2986 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2987 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 2988 | // There was a one-off crash where the folder had a parent already. |
| 2989 | if (folder.getParent() == null) { |
| 2990 | mDragLayer.addView(folder); |
| 2991 | mDragController.addDropTarget((DropTarget) folder); |
| 2992 | } else { |
| 2993 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 2994 | folder.getParent() + ")."); |
| 2995 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2996 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2997 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 2998 | |
| 2999 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 3000 | // the workspace items |
| 3001 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 3002 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 3006 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3007 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 3008 | if (folder.isEditingName()) { |
| 3009 | folder.dismissEditingName(); |
| 3010 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3011 | closeFolder(folder); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3012 | |
| 3013 | // Dismiss the folder cling |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 3014 | mLauncherClings.dismissFolderCling(null); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | void closeFolder(Folder folder) { |
| 3019 | folder.getInfo().opened = false; |
| 3020 | |
| 3021 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 3022 | if (parent != null) { |
| 3023 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 3024 | shrinkAndFadeInFolderIcon(fi); |
| 3025 | } |
| 3026 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3027 | |
| 3028 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 3029 | // longer occludeds the workspace items |
| 3030 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3031 | } |
| 3032 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3033 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 3034 | if (!isDraggingEnabled()) return false; |
| 3035 | if (isWorkspaceLocked()) return false; |
| 3036 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3037 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3038 | if (v instanceof Workspace) { |
| 3039 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 3040 | if (mWorkspace.enterOverviewMode()) { |
| 3041 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3042 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 3043 | return true; |
| 3044 | } else { |
| 3045 | return false; |
| 3046 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 3047 | } else { |
| 3048 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3049 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3050 | } |
| 3051 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 3052 | CellLayout.CellInfo longClickCellInfo = null; |
| 3053 | View itemUnderLongClick = null; |
| 3054 | if (v.getTag() instanceof ItemInfo) { |
| 3055 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3056 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 3057 | itemUnderLongClick = longClickCellInfo.cell; |
| 3058 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3059 | } |
| 3060 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3061 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 3062 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3063 | final boolean inHotseat = isHotseatLayout(v); |
| 3064 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3065 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3066 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3067 | // User long pressed on empty space |
| 3068 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3069 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3070 | if (mWorkspace.isInOverviewMode()) { |
| 3071 | mWorkspace.startReordering(v); |
| 3072 | } else { |
| 3073 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 3074 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3075 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3076 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 3077 | mHotseat.getOrderInHotseat( |
| 3078 | longClickCellInfo.cellX, |
| 3079 | longClickCellInfo.cellY)); |
| 3080 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3081 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3082 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | } |
| 3086 | return true; |
| 3087 | } |
| 3088 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3089 | boolean isHotseatLayout(View layout) { |
| 3090 | return mHotseat != null && layout != null && |
| 3091 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 3092 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 3093 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3094 | /** |
| 3095 | * Returns the CellLayout of the specified container at the specified screen. |
| 3096 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3097 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3098 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3099 | if (mHotseat != null) { |
| 3100 | return mHotseat.getLayout(); |
| 3101 | } else { |
| 3102 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 3103 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3104 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3105 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 3106 | } |
| 3107 | } |
| 3108 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3109 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3110 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 3111 | } |
| 3112 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3113 | private void setWorkspaceBackground(boolean workspace) { |
| 3114 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 3115 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3116 | } |
| 3117 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 3118 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3119 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 3120 | int curflags = getWindow().getAttributes().flags |
| 3121 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 3122 | if (wpflags != curflags) { |
| 3123 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 3124 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3125 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3128 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3129 | if (v instanceof LauncherTransitionable) { |
| 3130 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3131 | } |
| 3132 | } |
| 3133 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3134 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3135 | if (v instanceof LauncherTransitionable) { |
| 3136 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3137 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3138 | |
| 3139 | // Update the workspace transition step as well |
| 3140 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3141 | } |
| 3142 | |
| 3143 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3144 | if (v instanceof LauncherTransitionable) { |
| 3145 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3146 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3150 | if (v instanceof LauncherTransitionable) { |
| 3151 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3152 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3153 | |
| 3154 | // Update the workspace transition step as well |
| 3155 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3156 | } |
| 3157 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3158 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3159 | * Things to test when changing the following seven functions. |
| 3160 | * - Home from workspace |
| 3161 | * - from center screen |
| 3162 | * - from other screens |
| 3163 | * - Home from all apps |
| 3164 | * - from center screen |
| 3165 | * - from other screens |
| 3166 | * - Back from all apps |
| 3167 | * - from center screen |
| 3168 | * - from other screens |
| 3169 | * - Launch app from workspace and quit |
| 3170 | * - with back |
| 3171 | * - with home |
| 3172 | * - Launch app from all apps and quit |
| 3173 | * - with back |
| 3174 | * - with home |
| 3175 | * - Go to a screen that's not the default, then all |
| 3176 | * apps, and launch and app, and go back |
| 3177 | * - with back |
| 3178 | * -with home |
| 3179 | * - On workspace, long press power and go back |
| 3180 | * - with back |
| 3181 | * - with home |
| 3182 | * - On all apps, long press power and go back |
| 3183 | * - with back |
| 3184 | * - with home |
| 3185 | * - On workspace, power off |
| 3186 | * - On all apps, power off |
| 3187 | * - Launch an app and turn off the screen while in that app |
| 3188 | * - Go back with home key |
| 3189 | * - Go back with back key TODO: make this not go to workspace |
| 3190 | * - From all apps |
| 3191 | * - From workspace |
| 3192 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3193 | * - From all apps |
| 3194 | * - From the center workspace |
| 3195 | * - From another workspace |
| 3196 | */ |
| 3197 | |
| 3198 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3199 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3200 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3201 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3202 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3203 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3204 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3205 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3206 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3207 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3208 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3209 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3210 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3211 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3212 | mStateAnimation.cancel(); |
| 3213 | mStateAnimation = null; |
| 3214 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3215 | |
| 3216 | boolean material = Utilities.isLmp(); |
| 3217 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3218 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3219 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3220 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); |
| 3221 | final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3222 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3223 | final int itemsAlphaStagger = |
| 3224 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3225 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3226 | final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3227 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3228 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 3229 | final int startDelay = |
| 3230 | res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3231 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3232 | Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? |
| 3233 | Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3234 | Animator workspaceAnim = |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3235 | mWorkspace.getChangeStateAnimation(workspaceState, animated); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3236 | if (!LauncherAppState.isDisableAllApps() |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3237 | || contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3238 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3239 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3240 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3241 | |
| 3242 | if (animated) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3243 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 3244 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3245 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3246 | toView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3247 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3248 | final View page = content.getPageAt(content.getCurrentPage()); |
| 3249 | final View revealView = toView.findViewById(R.id.fake_page); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3250 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3251 | if (contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3252 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3253 | } else { |
| 3254 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3255 | } |
| 3256 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3257 | // Hide the real page background, and swap in the fake one |
| 3258 | revealView.setVisibility(View.VISIBLE); |
| 3259 | content.setPageBackgroundsVisible(false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3260 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3261 | int width = revealView.getMeasuredWidth(); |
| 3262 | int height = revealView.getMeasuredHeight(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3263 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3264 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
| 3265 | float yDrift = height / 2f; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3266 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3267 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3268 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", 0.4f, 1f); |
| 3269 | PropertyValuesHolder panelDrift = |
| 3270 | PropertyValuesHolder.ofFloat("translationY", yDrift, 0f); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3271 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3272 | ObjectAnimator panelAlphaAndDrift = |
| 3273 | ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift); |
| 3274 | panelAlphaAndDrift.setDuration(revealDuration); |
| 3275 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3276 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3277 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3278 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3279 | if (page != null) { |
| 3280 | page.setVisibility(View.VISIBLE); |
| 3281 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3282 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3283 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0); |
| 3284 | pageDrift.setDuration(revealDuration); |
| 3285 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3286 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3287 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3288 | // TODO (adamcohen): remove this 0.01f hack once fw is fixed |
| 3289 | // it's there to work around a framework bug (16918357) |
| 3290 | page.setAlpha(0.01f); |
| 3291 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0.01f, 1f); |
| 3292 | itemsAlpha.setDuration(revealDuration); |
| 3293 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 3294 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
| 3295 | mStateAnimation.play(itemsAlpha); |
| 3296 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3297 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3298 | View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); |
| 3299 | pageIndicators.setAlpha(0.01f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3300 | ObjectAnimator indicatorsAlpha = |
| 3301 | ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f); |
| 3302 | indicatorsAlpha.setDuration(revealDuration); |
| 3303 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3304 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3305 | if (material) { |
| 3306 | ValueAnimator reveal = (ValueAnimator) |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3307 | ViewAnimationUtils.createCircularReveal(revealView, width / 2, |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3308 | height / 2, 0f, revealRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3309 | reveal.setDuration(revealDuration); |
| 3310 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3311 | mStateAnimation.play(reveal); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3312 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3313 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3314 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
| 3315 | @Override |
| 3316 | public void onAnimationEnd(Animator animation) { |
| 3317 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3318 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 3319 | |
| 3320 | revealView.setVisibility(View.INVISIBLE); |
| 3321 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3322 | if (page != null) { |
| 3323 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3324 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3325 | content.setPageBackgroundsVisible(true); |
| 3326 | |
| 3327 | // Hide the search bar |
| 3328 | if (mSearchDropTargetBar != null) { |
| 3329 | mSearchDropTargetBar.hideSearchBar(false); |
| 3330 | } |
| 3331 | } |
| 3332 | |
| 3333 | @Override |
| 3334 | public void onAnimationStart(Animator animation) { |
| 3335 | // Prepare the position |
| 3336 | toView.bringToFront(); |
| 3337 | toView.setVisibility(View.VISIBLE); |
| 3338 | } |
| 3339 | }); |
| 3340 | |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3341 | boolean delayAnim = false; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3342 | if (workspaceAnim != null) { |
| 3343 | mStateAnimation.play(workspaceAnim); |
| 3344 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3345 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3346 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3347 | |
| 3348 | // If any of the objects being animated haven't been measured/laid out |
| 3349 | // yet, delay the animation until we get a layout pass |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3350 | if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3351 | (mWorkspace.getMeasuredWidth() == 0) || |
| 3352 | (toView.getMeasuredWidth() == 0)) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3353 | delayAnim = true; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3354 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3355 | |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3356 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3357 | final Runnable startAnimRunnable = new Runnable() { |
| 3358 | public void run() { |
| 3359 | // Check that mStateAnimation hasn't changed while |
| 3360 | // we waited for a layout/draw pass |
| 3361 | if (mStateAnimation != stateAnimation) |
| 3362 | return; |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3363 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3364 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3365 | LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3366 | } |
| 3367 | }; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3368 | if (delayAnim) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3369 | toView.bringToFront(); |
| 3370 | toView.setVisibility(View.VISIBLE); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3371 | final ViewTreeObserver observer = toView.getViewTreeObserver(); |
| 3372 | observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { |
| 3373 | public void onGlobalLayout() { |
| 3374 | startAnimRunnable.run(); |
| 3375 | toView.getViewTreeObserver().removeOnGlobalLayoutListener(this); |
| 3376 | } |
| 3377 | }); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3378 | } else { |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3379 | startAnimRunnable.run(); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3380 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3381 | } else { |
| 3382 | toView.setTranslationX(0.0f); |
| 3383 | toView.setTranslationY(0.0f); |
| 3384 | toView.setScaleX(1.0f); |
| 3385 | toView.setScaleY(1.0f); |
| 3386 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3387 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3388 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3389 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3390 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3391 | if (mSearchDropTargetBar != null) { |
| 3392 | mSearchDropTargetBar.hideSearchBar(false); |
| 3393 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3394 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3395 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3396 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3397 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3398 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3399 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3400 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3401 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | /** |
| 3405 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3406 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3407 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3408 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3409 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3410 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3411 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3412 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3413 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3414 | mStateAnimation.cancel(); |
| 3415 | mStateAnimation = null; |
| 3416 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3417 | |
| 3418 | boolean material = Utilities.isLmp(); |
| 3419 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3420 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3421 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3422 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3423 | final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime); |
| 3424 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3425 | final int itemsAlphaStagger = |
| 3426 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3427 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3428 | final float scaleFactor = (float) |
| 3429 | res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
| 3430 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3431 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3432 | Animator workspaceAnim = null; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3433 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3434 | int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger); |
| 3435 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3436 | toState, animated, stagger, -1); |
| 3437 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3438 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3439 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3440 | toState, animated); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3441 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3442 | |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3443 | showHotseat(animated); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3444 | if (animated) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3445 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3446 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3447 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3448 | fromView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3449 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3450 | final View page = content.getPageAt(content.getNextPage()); |
| 3451 | final View revealView = fromView.findViewById(R.id.fake_page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3452 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3453 | AppsCustomizePagedView.ContentType contentType = content.getContentType(); |
| 3454 | if (contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3455 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3456 | } else { |
| 3457 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3458 | } |
| 3459 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3460 | int width = revealView.getMeasuredWidth(); |
| 3461 | int height = revealView.getMeasuredHeight(); |
| 3462 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3463 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3464 | // Hide the real page background, and swap in the fake one |
| 3465 | revealView.setVisibility(View.VISIBLE); |
| 3466 | content.setPageBackgroundsVisible(false); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3467 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3468 | float yDrift = height / 2f; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3469 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3470 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3471 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3472 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f); |
| 3473 | PropertyValuesHolder panelDrift = |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3474 | PropertyValuesHolder.ofFloat("translationY", 0, yDrift); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3475 | ObjectAnimator panelAlphaAndDrift = |
| 3476 | ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift); |
| 3477 | panelAlphaAndDrift.setDuration(revealDuration); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3478 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3479 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3480 | panelAlphaAndDrift.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3481 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3482 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3483 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3484 | if (page != null) { |
| 3485 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3486 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3487 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", 0, yDrift); |
| 3488 | pageDrift.setDuration(revealDuration); |
| 3489 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3490 | pageDrift.setStartDelay(itemsAlphaStagger); |
| 3491 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3492 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3493 | page.setAlpha(1f); |
| 3494 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, View.ALPHA, 1f, 0f); |
| 3495 | itemsAlpha.setDuration(revealDuration); |
| 3496 | itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3497 | mStateAnimation.play(itemsAlpha); |
| 3498 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3499 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3500 | View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3501 | pageIndicators.setAlpha(1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3502 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3503 | ObjectAnimator.ofFloat(pageIndicators, "alpha", 0f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3504 | indicatorsAlpha.setDuration(revealDuration); |
| 3505 | indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 3506 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3507 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3508 | width = revealView.getMeasuredWidth(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3509 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3510 | if (material) { |
Nilesh Agrawal | 300c150 | 2014-07-22 13:20:54 -0700 | [diff] [blame] | 3511 | Animator reveal = |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3512 | ViewAnimationUtils.createCircularReveal(revealView, width / 2, |
| 3513 | height / 2 + 100, revealRadius, 0f); |
| 3514 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3515 | reveal.setDuration(revealDuration); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3516 | reveal.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3517 | |
| 3518 | reveal.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3519 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3520 | revealView.setVisibility(View.INVISIBLE); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3521 | } |
| 3522 | }); |
| 3523 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3524 | mStateAnimation.play(reveal); |
| 3525 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3526 | |
| 3527 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3528 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 3529 | mAppsCustomizeContent.stopScrolling(); |
| 3530 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3531 | if (workspaceAnim != null) { |
| 3532 | mStateAnimation.play(workspaceAnim); |
| 3533 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3534 | |
| 3535 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3536 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3537 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3538 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3539 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3540 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3541 | if (onCompleteRunnable != null) { |
| 3542 | onCompleteRunnable.run(); |
| 3543 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3544 | |
| 3545 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3546 | if (page != null) { |
| 3547 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3548 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3549 | content.setPageBackgroundsVisible(true); |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3550 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3551 | } |
| 3552 | }); |
| 3553 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3554 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3555 | dispatchOnLauncherTransitionStart(toView, animated, true); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3556 | LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3557 | } else { |
| 3558 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3559 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3560 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3561 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3562 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3563 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3564 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3565 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3566 | } |
| 3567 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3568 | @Override |
| 3569 | public void onTrimMemory(int level) { |
| 3570 | super.onTrimMemory(level); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 3571 | if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) { |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3572 | mAppsCustomizeTabHost.onTrimMemory(); |
| 3573 | } |
| 3574 | } |
| 3575 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3576 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3577 | showWorkspace(animated, null); |
| 3578 | } |
| 3579 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3580 | protected void showWorkspace() { |
| 3581 | showWorkspace(true); |
| 3582 | } |
| 3583 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3584 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 3585 | if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3586 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3587 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3588 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3589 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3590 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3591 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3592 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3593 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3594 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3595 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3596 | // Set focus to the AppsCustomize button |
| 3597 | if (mAllAppsButton != null) { |
| 3598 | mAllAppsButton.requestFocus(); |
| 3599 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3600 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3601 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3602 | // Change the state *after* we've called all the transition code |
| 3603 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3604 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3605 | // Resume the auto-advance of widgets |
| 3606 | mUserPresent = true; |
| 3607 | updateRunning(); |
| 3608 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3609 | // Send an accessibility event to announce the context change |
| 3610 | getWindow().getDecorView() |
| 3611 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3612 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3613 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3614 | } |
| 3615 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3616 | void showOverviewMode(boolean animated) { |
| 3617 | mWorkspace.setVisibility(View.VISIBLE); |
| 3618 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3619 | mState = State.WORKSPACE; |
| 3620 | onWorkspaceShown(animated); |
| 3621 | } |
| 3622 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3623 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3624 | } |
| 3625 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3626 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3627 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3628 | if (mState != State.WORKSPACE) return; |
| 3629 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3630 | if (resetPageToZero) { |
| 3631 | mAppsCustomizeTabHost.reset(); |
| 3632 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3633 | showAppsCustomizeHelper(animated, false, contentType); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 3634 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3635 | @Override |
| 3636 | public void run() { |
| 3637 | // We post this in-case the all apps view isn't yet constructed. |
| 3638 | mAppsCustomizeTabHost.requestFocus(); |
| 3639 | } |
| 3640 | }); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3641 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3642 | // Change the state *after* we've called all the transition code |
| 3643 | mState = State.APPS_CUSTOMIZE; |
| 3644 | |
| 3645 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3646 | mUserPresent = false; |
| 3647 | updateRunning(); |
| 3648 | closeFolder(); |
| 3649 | |
| 3650 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3651 | getWindow().getDecorView() |
| 3652 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3655 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3656 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3657 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3658 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3659 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3660 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3661 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3662 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3663 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3664 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 3665 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 3666 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3667 | @Override |
| 3668 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3669 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3670 | // Before we show workspace, hide all apps again because |
| 3671 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 3672 | // clean up our state transition functions |
| 3673 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3674 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3675 | } else { |
| 3676 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3677 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3678 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3679 | }, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3680 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3681 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3682 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3683 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3684 | final boolean animated = true; |
| 3685 | final boolean springLoaded = true; |
| 3686 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3687 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3688 | } |
| 3689 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 3690 | } |
| 3691 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3692 | void lockAllApps() { |
| 3693 | // TODO |
| 3694 | } |
| 3695 | |
| 3696 | void unlockAllApps() { |
| 3697 | // TODO |
| 3698 | } |
| 3699 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3700 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3701 | * Shows the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3702 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3703 | void showHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3704 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3705 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3706 | if (mHotseat.getAlpha() != 1f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3707 | int duration = 0; |
| 3708 | if (mSearchDropTargetBar != null) { |
| 3709 | duration = mSearchDropTargetBar.getTransitionInDuration(); |
| 3710 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3711 | mHotseat.animate().alpha(1f).setDuration(duration); |
| 3712 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3713 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3714 | mHotseat.setAlpha(1f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | } |
| 3718 | |
| 3719 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3720 | * Hides the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3721 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3722 | void hideHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3723 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3724 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3725 | if (mHotseat.getAlpha() != 0f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3726 | int duration = 0; |
| 3727 | if (mSearchDropTargetBar != null) { |
| 3728 | duration = mSearchDropTargetBar.getTransitionOutDuration(); |
| 3729 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3730 | mHotseat.animate().alpha(0f).setDuration(duration); |
| 3731 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3732 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3733 | mHotseat.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3734 | } |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3735 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3736 | } |
| 3737 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3738 | /** |
| 3739 | * Add an item from all apps or customize onto the given workspace screen. |
| 3740 | * If layout is null, add to the current screen. |
| 3741 | */ |
| 3742 | void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3743 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 3744 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 3745 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3746 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3747 | |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3748 | /** Maps the current orientation to an index for referencing orientation correct global icons */ |
| 3749 | private int getCurrentOrientationIndexForGlobalIcons() { |
| 3750 | // default - 0, landscape - 1 |
| 3751 | switch (getResources().getConfiguration().orientation) { |
| 3752 | case Configuration.ORIENTATION_LANDSCAPE: |
| 3753 | return 1; |
| 3754 | default: |
| 3755 | return 0; |
| 3756 | } |
| 3757 | } |
| 3758 | |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3759 | private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3760 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3761 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3762 | // Look for the toolbar icon specified in the activity meta-data |
| 3763 | Bundle metaData = packageManager.getActivityInfo( |
| 3764 | activityName, PackageManager.GET_META_DATA).metaData; |
| 3765 | if (metaData != null) { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3766 | int iconResId = metaData.getInt(resourceName); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3767 | if (iconResId != 0) { |
| 3768 | Resources res = packageManager.getResourcesForActivity(activityName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3769 | return res.getDrawable(iconResId); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3770 | } |
| 3771 | } |
| 3772 | } catch (NameNotFoundException e) { |
Michael Jurka | b6052a9 | 2011-07-12 17:02:45 -0700 | [diff] [blame] | 3773 | // This can happen if the activity defines an invalid drawable |
| 3774 | Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + |
| 3775 | " not found", e); |
Mathew Inwood | 70d5102 | 2011-07-12 13:41:41 +0100 | [diff] [blame] | 3776 | } catch (Resources.NotFoundException nfe) { |
| 3777 | // This can happen if the activity defines an invalid drawable |
| 3778 | Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), |
| 3779 | nfe); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3780 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3781 | return null; |
| 3782 | } |
| 3783 | |
| 3784 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3785 | private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3786 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 3787 | String toolbarResourceName) { |
| 3788 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3789 | Resources r = getResources(); |
| 3790 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 3791 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3792 | |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3793 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3794 | // If we were unable to find the icon via the meta-data, use a generic one |
| 3795 | if (toolbarIcon == null) { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3796 | toolbarIcon = r.getDrawable(fallbackDrawableId); |
| 3797 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3798 | if (button != null) { |
| 3799 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 3800 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3801 | return null; |
| 3802 | } else { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3803 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3804 | if (button != null) { |
| 3805 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 3806 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3807 | return toolbarIcon.getConstantState(); |
| 3808 | } |
| 3809 | } |
| 3810 | |
| 3811 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3812 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3813 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 3814 | String toolbarResourceName) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3815 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3816 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3817 | |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 3818 | if (button != null) { |
| 3819 | // If we were unable to find the icon via the meta-data, use a |
| 3820 | // generic one |
| 3821 | if (toolbarIcon == null) { |
| 3822 | button.setImageResource(fallbackDrawableId); |
| 3823 | } else { |
| 3824 | button.setImageDrawable(toolbarIcon); |
| 3825 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3826 | } |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 3827 | |
| 3828 | return toolbarIcon != null ? toolbarIcon.getConstantState() : null; |
| 3829 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3830 | } |
| 3831 | |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3832 | private void updateTextButtonWithDrawable(int buttonId, Drawable d) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3833 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3834 | button.setCompoundDrawables(d, null, null, null); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3835 | } |
| 3836 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3837 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3838 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3839 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3840 | } |
| 3841 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3842 | private void invalidatePressedFocusedStates(View container, View button) { |
| 3843 | if (container instanceof HolographicLinearLayout) { |
| 3844 | HolographicLinearLayout layout = (HolographicLinearLayout) container; |
| 3845 | layout.invalidatePressedFocusedStates(); |
| 3846 | } else if (button instanceof HolographicImageView) { |
| 3847 | HolographicImageView view = (HolographicImageView) button; |
| 3848 | view.invalidatePressedFocusedStates(); |
| 3849 | } |
| 3850 | } |
| 3851 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3852 | public View getQsbBar() { |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3853 | if (mQsb == null) { |
| 3854 | mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false); |
| 3855 | mSearchDropTargetBar.addView(mQsb); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3856 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3857 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | protected boolean updateGlobalSearchIcon() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3861 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3862 | final ImageView searchButton = (ImageView) findViewById(R.id.search_button); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3863 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 3864 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3865 | |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3866 | final SearchManager searchManager = |
| 3867 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3868 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 3869 | if (activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3870 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3871 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3872 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 3873 | TOOLBAR_SEARCH_ICON_METADATA_NAME); |
| 3874 | if (sGlobalSearchIcon[coi] == null) { |
| 3875 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 3876 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 3877 | TOOLBAR_ICON_METADATA_NAME); |
| 3878 | } |
| 3879 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3880 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); |
| 3881 | searchButton.setVisibility(View.VISIBLE); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3882 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3883 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3884 | } else { |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 3885 | // We disable both search and voice search when there is no global search provider |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3886 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); |
| 3887 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 3888 | if (searchButton != null) searchButton.setVisibility(View.GONE); |
| 3889 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3890 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3891 | return false; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3895 | protected void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3896 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
| 3897 | final View searchButton = (ImageView) findViewById(R.id.search_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3898 | updateButtonWithDrawable(R.id.search_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3899 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3900 | } |
| 3901 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3902 | protected boolean updateVoiceSearchIcon(boolean searchVisible) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3903 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3904 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3905 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3906 | // We only show/update the voice search icon if the search icon is enabled as well |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3907 | final SearchManager searchManager = |
| 3908 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3909 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 3910 | |
| 3911 | ComponentName activityName = null; |
| 3912 | if (globalSearchActivity != null) { |
| 3913 | // Check if the global search activity handles voice search |
| 3914 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3915 | intent.setPackage(globalSearchActivity.getPackageName()); |
| 3916 | activityName = intent.resolveActivity(getPackageManager()); |
| 3917 | } |
| 3918 | |
| 3919 | if (activityName == null) { |
| 3920 | // Fallback: check if an activity other than the global search activity |
| 3921 | // resolves this |
| 3922 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3923 | activityName = intent.resolveActivity(getPackageManager()); |
| 3924 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3925 | if (searchVisible && activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3926 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3927 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3928 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 3929 | TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); |
| 3930 | if (sVoiceSearchIcon[coi] == null) { |
| 3931 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 3932 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 3933 | TOOLBAR_ICON_METADATA_NAME); |
| 3934 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3935 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3936 | voiceButton.setVisibility(View.VISIBLE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3937 | updateVoiceButtonProxyVisible(false); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3938 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3939 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3940 | } else { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3941 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 3942 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3943 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3944 | return false; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3945 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3946 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3947 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3948 | protected void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3949 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
| 3950 | final View voiceButton = findViewById(R.id.voice_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3951 | updateButtonWithDrawable(R.id.voice_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3952 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3955 | public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) { |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3956 | final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); |
| 3957 | if (voiceButtonProxy != null) { |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3958 | boolean visible = !forceDisableVoiceButtonProxy && |
| 3959 | mWorkspace.shouldVoiceButtonProxyBeVisible(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3960 | voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3961 | voiceButtonProxy.bringToFront(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3962 | } |
| 3963 | } |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3964 | |
| 3965 | /** |
| 3966 | * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy |
| 3967 | * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns. |
| 3968 | */ |
| 3969 | public void disableVoiceButtonProxy(boolean disabled) { |
| 3970 | updateVoiceButtonProxyVisible(disabled); |
| 3971 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3972 | /** |
Winson Chung | eb66b14 | 2011-06-16 13:14:22 -0700 | [diff] [blame] | 3973 | * Sets the app market icon |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3974 | */ |
| 3975 | private void updateAppMarketIcon() { |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 3976 | if (!DISABLE_MARKET_BUTTON) { |
| 3977 | final View marketButton = findViewById(R.id.market_button); |
| 3978 | Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); |
| 3979 | // Find the app market activity by resolving an intent. |
| 3980 | // (If multiple app markets are installed, it will return the ResolverActivity.) |
| 3981 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
| 3982 | if (activityName != null) { |
| 3983 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3984 | mAppMarketIntent = intent; |
| 3985 | sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity( |
| 3986 | R.id.market_button, activityName, R.drawable.ic_launcher_market_holo, |
| 3987 | TOOLBAR_ICON_METADATA_NAME); |
| 3988 | marketButton.setVisibility(View.VISIBLE); |
| 3989 | } else { |
| 3990 | // We should hide and disable the view so that we don't try and restore the visibility |
| 3991 | // of it when we swap between drag & normal states from IconDropTarget subclasses. |
| 3992 | marketButton.setVisibility(View.GONE); |
| 3993 | marketButton.setEnabled(false); |
| 3994 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3995 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3998 | private void updateAppMarketIcon(Drawable.ConstantState d) { |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 3999 | if (!DISABLE_MARKET_BUTTON) { |
| 4000 | // Ensure that the new drawable we are creating has the approprate toolbar icon bounds |
| 4001 | Resources r = getResources(); |
| 4002 | Drawable marketIconDrawable = d.newDrawable(r); |
| 4003 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 4004 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
| 4005 | marketIconDrawable.setBounds(0, 0, w, h); |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 4006 | |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 4007 | updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable); |
| 4008 | } |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4009 | } |
| 4010 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4011 | @Override |
| 4012 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4013 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4014 | final List<CharSequence> text = event.getText(); |
| 4015 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4016 | // Populate event with a fake title based on the current state. |
| 4017 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4018 | text.add(mAppsCustomizeTabHost.getContentTag()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4019 | } else { |
| 4020 | text.add(getString(R.string.all_apps_home_button_label)); |
| 4021 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4022 | return result; |
| 4023 | } |
| 4024 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4025 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 4026 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4027 | */ |
| 4028 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 4029 | @Override |
| 4030 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4031 | closeSystemDialogs(); |
| 4032 | } |
| 4033 | } |
| 4034 | |
| 4035 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 4036 | * Receives notifications whenever the appwidgets are reset. |
| 4037 | */ |
| 4038 | private class AppWidgetResetObserver extends ContentObserver { |
| 4039 | public AppWidgetResetObserver() { |
| 4040 | super(new Handler()); |
| 4041 | } |
| 4042 | |
| 4043 | @Override |
| 4044 | public void onChange(boolean selfChange) { |
| 4045 | onAppWidgetReset(); |
| 4046 | } |
| 4047 | } |
| 4048 | |
| 4049 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4050 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 4051 | * in onResume. |
| 4052 | * |
| 4053 | * This needs to be called from incoming places where resources might have been loaded |
| 4054 | * while we are paused. That is becaues the Configuration might be wrong |
| 4055 | * when we're not running, and if it comes back to what it was when we |
| 4056 | * were paused, we are not restarted. |
| 4057 | * |
| 4058 | * Implementation of the method from LauncherModel.Callbacks. |
| 4059 | * |
| 4060 | * @return true if we are currently paused. The caller might be able to |
| 4061 | * skip some work in that case since we will come back again. |
| 4062 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4063 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4064 | if (mPaused) { |
| 4065 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4066 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4067 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4068 | } |
| 4069 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4070 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4071 | return true; |
| 4072 | } else { |
| 4073 | return false; |
| 4074 | } |
| 4075 | } |
| 4076 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4077 | private boolean waitUntilResume(Runnable run) { |
| 4078 | return waitUntilResume(run, false); |
| 4079 | } |
| 4080 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4081 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 4082 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4085 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4086 | * If the activity is currently paused, signal that we need to re-run the loader |
| 4087 | * in onResume. |
| 4088 | * |
| 4089 | * This needs to be called from incoming places where resources might have been loaded |
| 4090 | * while we are paused. That is becaues the Configuration might be wrong |
| 4091 | * when we're not running, and if it comes back to what it was when we |
| 4092 | * were paused, we are not restarted. |
| 4093 | * |
| 4094 | * Implementation of the method from LauncherModel.Callbacks. |
| 4095 | * |
| 4096 | * @return true if we are currently paused. The caller might be able to |
| 4097 | * skip some work in that case since we will come back again. |
| 4098 | */ |
| 4099 | public boolean setLoadOnResume() { |
| 4100 | if (mPaused) { |
| 4101 | Log.i(TAG, "setLoadOnResume"); |
| 4102 | mOnResumeNeedsLoad = true; |
| 4103 | return true; |
| 4104 | } else { |
| 4105 | return false; |
| 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4110 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4111 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4112 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4113 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4114 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4115 | } else { |
| 4116 | return SCREEN_COUNT / 2; |
| 4117 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4118 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4119 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4120 | /** |
| 4121 | * Refreshes the shortcuts shown on the workspace. |
| 4122 | * |
| 4123 | * Implementation of the method from LauncherModel.Callbacks. |
| 4124 | */ |
| 4125 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4126 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 4127 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4128 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 4129 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 4130 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4131 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4132 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4133 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4134 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 4135 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4136 | |
Michael Jurka | 05bf644 | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 4137 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4138 | if (mHotseat != null) { |
| 4139 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4140 | } |
| 4141 | } |
| 4142 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4143 | @Override |
| 4144 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4145 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4146 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 4147 | // If there are no screens, we need to have an empty screen |
| 4148 | if (orderedScreenIds.size() == 0) { |
| 4149 | mWorkspace.addExtraEmptyScreen(); |
| 4150 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4151 | |
| 4152 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4153 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 4154 | if (hasCustomContentToLeft()) { |
| 4155 | mWorkspace.createCustomContentContainer(); |
| 4156 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4157 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | @Override |
| 4161 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 4162 | // Log to disk |
| 4163 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 4164 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 4165 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4166 | int count = orderedScreenIds.size(); |
| 4167 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 4168 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4169 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4172 | private boolean shouldShowWeightWatcher() { |
| 4173 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4174 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 4175 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4176 | |
| 4177 | return show; |
| 4178 | } |
| 4179 | |
| 4180 | private void toggleShowWeightWatcher() { |
| 4181 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4182 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 4183 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 4184 | |
| 4185 | show = !show; |
| 4186 | |
| 4187 | SharedPreferences.Editor editor = sp.edit(); |
| 4188 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 4189 | editor.commit(); |
| 4190 | |
| 4191 | if (mWeightWatcher != null) { |
| 4192 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 4193 | } |
| 4194 | } |
| 4195 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4196 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 4197 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4198 | final ArrayList<ItemInfo> addAnimated, |
| 4199 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4200 | Runnable r = new Runnable() { |
| 4201 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4202 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4203 | } |
| 4204 | }; |
| 4205 | if (waitUntilResume(r)) { |
| 4206 | return; |
| 4207 | } |
| 4208 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4209 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4210 | if (newScreens != null) { |
| 4211 | bindAddScreens(newScreens); |
| 4212 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4213 | |
| 4214 | // We add the items without animation on non-visible pages, and with |
| 4215 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4216 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4217 | bindItems(addNotAnimated, 0, |
| 4218 | addNotAnimated.size(), false); |
| 4219 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4220 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4221 | bindItems(addAnimated, 0, |
| 4222 | addAnimated.size(), true); |
| 4223 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4224 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4225 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 4226 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4227 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4228 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4229 | addedApps != null && mAppsCustomizeContent != null) { |
| 4230 | mAppsCustomizeContent.addApps(addedApps); |
| 4231 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4234 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4235 | * Bind the items start-end from the list. |
| 4236 | * |
| 4237 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4238 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4239 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 4240 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4241 | Runnable r = new Runnable() { |
| 4242 | public void run() { |
| 4243 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 4244 | } |
| 4245 | }; |
| 4246 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4247 | return; |
| 4248 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4249 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4250 | // 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] | 4251 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 4252 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4253 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4254 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4255 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4256 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4257 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4258 | |
| 4259 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4260 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4261 | mHotseat == null) { |
| 4262 | continue; |
| 4263 | } |
| 4264 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4265 | switch (item.itemType) { |
| 4266 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4267 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4268 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4269 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4270 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4271 | /* |
| 4272 | * TODO: FIX collision case |
| 4273 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4274 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4275 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4276 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4277 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4278 | Object tag = v.getTag(); |
| 4279 | String desc = "Collision while binding workspace item: " + item |
| 4280 | + ". Collides with " + tag; |
| 4281 | if (LauncherAppState.isDogfoodBuild()) { |
| 4282 | throw (new RuntimeException(desc)); |
| 4283 | } else { |
| 4284 | Log.d(TAG, desc); |
| 4285 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4286 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4287 | } |
| 4288 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4289 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4290 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4291 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4292 | // Animate all the applications up now |
| 4293 | shortcut.setAlpha(0f); |
| 4294 | shortcut.setScaleX(0f); |
| 4295 | shortcut.setScaleY(0f); |
| 4296 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4297 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4298 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4299 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4300 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4301 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4302 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4303 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4304 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4305 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4306 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4307 | default: |
| 4308 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4309 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4310 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4311 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4312 | if (animateIcons) { |
| 4313 | // Animate to the correct page |
| 4314 | if (newShortcutsScreenId > -1) { |
| 4315 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4316 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4317 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4318 | public void run() { |
| 4319 | anim.playTogether(bounceAnims); |
| 4320 | anim.start(); |
| 4321 | } |
| 4322 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4323 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4324 | // We post the animation slightly delayed to prevent slowdowns |
| 4325 | // when we are loading right after we return to launcher. |
| 4326 | mWorkspace.postDelayed(new Runnable() { |
| 4327 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4328 | if (mWorkspace != null) { |
| 4329 | mWorkspace.snapToPage(newScreenIndex); |
| 4330 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4331 | NEW_APPS_ANIMATION_DELAY); |
| 4332 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4333 | } |
| 4334 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4335 | } else { |
| 4336 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4337 | } |
| 4338 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4339 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4340 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4343 | /** |
| 4344 | * Implementation of the method from LauncherModel.Callbacks. |
| 4345 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4346 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4347 | Runnable r = new Runnable() { |
| 4348 | public void run() { |
| 4349 | bindFolders(folders); |
| 4350 | } |
| 4351 | }; |
| 4352 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4353 | return; |
| 4354 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4355 | sFolders.clear(); |
| 4356 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4357 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4358 | |
| 4359 | /** |
| 4360 | * Add the views for a widget to the workspace. |
| 4361 | * |
| 4362 | * Implementation of the method from LauncherModel.Callbacks. |
| 4363 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4364 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4365 | Runnable r = new Runnable() { |
| 4366 | public void run() { |
| 4367 | bindAppWidget(item); |
| 4368 | } |
| 4369 | }; |
| 4370 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4371 | return; |
| 4372 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4373 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4374 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4375 | if (DEBUG_WIDGETS) { |
| 4376 | Log.d(TAG, "bindAppWidget: " + item); |
| 4377 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4378 | final Workspace workspace = mWorkspace; |
| 4379 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4380 | AppWidgetProviderInfo appWidgetInfo; |
| 4381 | if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) && |
| 4382 | ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { |
| 4383 | |
| 4384 | appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName); |
| 4385 | if (appWidgetInfo == null) { |
| 4386 | if (DEBUG_WIDGETS) { |
| 4387 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4388 | + " belongs to component " + item.providerName |
| 4389 | + ", as the povider is null"); |
| 4390 | } |
| 4391 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4392 | return; |
| 4393 | } |
| 4394 | // Note: This assumes that the id remap broadcast is received before this step. |
| 4395 | // If that is not the case, the id remap will be ignored and user may see the |
| 4396 | // click to setup view. |
| 4397 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null); |
| 4398 | pendingInfo.spanX = item.spanX; |
| 4399 | pendingInfo.spanY = item.spanY; |
| 4400 | pendingInfo.minSpanX = item.minSpanX; |
| 4401 | pendingInfo.minSpanY = item.minSpanY; |
| 4402 | Bundle options = |
| 4403 | AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo); |
| 4404 | |
| 4405 | boolean success = false; |
| 4406 | int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 4407 | if (options != null) { |
| 4408 | success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId, |
| 4409 | appWidgetInfo.provider, options); |
| 4410 | } else { |
| 4411 | success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId, |
| 4412 | appWidgetInfo.provider); |
| 4413 | } |
| 4414 | |
| 4415 | // TODO consider showing a permission dialog when the widget is clicked. |
| 4416 | if (!success) { |
| 4417 | mAppWidgetHost.deleteAppWidgetId(newWidgetId); |
| 4418 | if (DEBUG_WIDGETS) { |
| 4419 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4420 | + " belongs to component " + item.providerName |
| 4421 | + ", as the launcher is unable to bing a new widget id"); |
| 4422 | } |
| 4423 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4424 | return; |
| 4425 | } |
| 4426 | |
| 4427 | item.appWidgetId = newWidgetId; |
| 4428 | |
| 4429 | // If the widget has a configure activity, it is still needs to set it up, otherwise |
| 4430 | // the widget is ready to go. |
| 4431 | item.restoreStatus = (appWidgetInfo.configure == null) |
| 4432 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 4433 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 4434 | |
| 4435 | LauncherModel.updateItemInDatabase(this, item); |
| 4436 | } |
| 4437 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4438 | if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 4439 | final int appWidgetId = item.appWidgetId; |
| 4440 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 4441 | if (DEBUG_WIDGETS) { |
| 4442 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 4443 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4444 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4445 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4446 | } else { |
| 4447 | appWidgetInfo = null; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4448 | item.hostView = new PendingAppWidgetHostView(this, item.restoreStatus); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4449 | item.hostView.updateAppWidget(null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4450 | item.hostView.setOnClickListener(this); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4451 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4452 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4453 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4454 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4455 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4456 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4457 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4458 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4459 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4460 | workspace.requestLayout(); |
| 4461 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4462 | if (DEBUG_WIDGETS) { |
| 4463 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4464 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4465 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4466 | } |
| 4467 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4468 | /** |
| 4469 | * Restores a pending widget. |
| 4470 | * |
| 4471 | * @param appWidgetId The app widget id |
| 4472 | * @param cellInfo The position on screen where to create the widget. |
| 4473 | */ |
| 4474 | private void completeRestoreAppWidget(final int appWidgetId) { |
| 4475 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 4476 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 4477 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
| 4478 | return; |
| 4479 | } |
| 4480 | |
| 4481 | PendingAppWidgetHostView pendingView = (PendingAppWidgetHostView) view; |
| 4482 | pendingView.setStatus(LauncherAppWidgetInfo.RESTORE_COMPLETED); |
| 4483 | |
| 4484 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) pendingView.getTag(); |
| 4485 | info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 4486 | |
| 4487 | mWorkspace.reinflateWidgetsIfNecessary(); |
| 4488 | LauncherModel.updateItemInDatabase(this, info); |
| 4489 | } |
| 4490 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4491 | public void onPageBoundSynchronously(int page) { |
| 4492 | mSynchronouslyBoundPages.add(page); |
| 4493 | } |
| 4494 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4495 | /** |
| 4496 | * Callback saying that there aren't any more items to bind. |
| 4497 | * |
| 4498 | * Implementation of the method from LauncherModel.Callbacks. |
| 4499 | */ |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4500 | public void finishBindingItems(final boolean upgradePath) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4501 | Runnable r = new Runnable() { |
| 4502 | public void run() { |
| 4503 | finishBindingItems(upgradePath); |
| 4504 | } |
| 4505 | }; |
| 4506 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4507 | return; |
| 4508 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4509 | if (mSavedState != null) { |
| 4510 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4511 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4512 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4513 | mSavedState = null; |
| 4514 | } |
| 4515 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4516 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4517 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4518 | // Update the market app icon as necessary (the other icons will be managed in response to |
| 4519 | // package changes in bindSearchablesChanged() |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 4520 | if (!DISABLE_MARKET_BUTTON) { |
| 4521 | updateAppMarketIcon(); |
| 4522 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 4523 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4524 | setWorkspaceLoading(false); |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4525 | sendLoadingCompleteBroadcastIfNecessary(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 4526 | |
| 4527 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4528 | // widget configuration forced an orientation change), process them now. |
| 4529 | if (sPendingAddItem != null) { |
| 4530 | final long screenId = completeAdd(sPendingAddItem); |
| 4531 | |
| 4532 | // TODO: this moves the user to the page where the pending item was added. Ideally, |
| 4533 | // the screen would be guaranteed to exist after bind, and the page would be set through |
| 4534 | // the workspace restore process. |
| 4535 | mWorkspace.post(new Runnable() { |
| 4536 | @Override |
| 4537 | public void run() { |
| 4538 | mWorkspace.snapToScreenId(screenId); |
| 4539 | } |
| 4540 | }); |
| 4541 | sPendingAddItem = null; |
| 4542 | } |
| 4543 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4544 | if (upgradePath) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4545 | mWorkspace.getUniqueComponents(true, null); |
| 4546 | mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4547 | } |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4548 | PackageInstallerCompat.getInstance(this).onFinishBind(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4549 | } |
| 4550 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4551 | private void sendLoadingCompleteBroadcastIfNecessary() { |
| 4552 | if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) { |
| 4553 | String permission = |
| 4554 | getResources().getString(R.string.receive_first_load_broadcast_permission); |
| 4555 | Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE); |
| 4556 | sendBroadcast(intent, permission); |
| 4557 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4558 | editor.putBoolean(FIRST_LOAD_COMPLETE, true); |
| 4559 | editor.apply(); |
| 4560 | } |
| 4561 | } |
| 4562 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4563 | public boolean isAllAppsButtonRank(int rank) { |
| 4564 | if (mHotseat != null) { |
| 4565 | return mHotseat.isAllAppsButtonRank(rank); |
| 4566 | } |
| 4567 | return false; |
| 4568 | } |
| 4569 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4570 | private boolean canRunNewAppsAnimation() { |
| 4571 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4572 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4573 | } |
| 4574 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4575 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4576 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4577 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4578 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4579 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4580 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4581 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4582 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4583 | return bounceAnim; |
| 4584 | } |
| 4585 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4586 | public boolean useVerticalBarLayout() { |
| 4587 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4588 | getDeviceProfile().isVerticalBarLayout(); |
| 4589 | } |
| 4590 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4591 | protected Rect getSearchBarBounds() { |
| 4592 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4593 | getDeviceProfile().getSearchBarBounds(); |
| 4594 | } |
| 4595 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4596 | @Override |
| 4597 | public void bindSearchablesChanged() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4598 | boolean searchVisible = updateGlobalSearchIcon(); |
| 4599 | boolean voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4600 | if (mSearchDropTargetBar != null) { |
| 4601 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 4602 | } |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4603 | } |
| 4604 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4605 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4606 | * Add the icons for all apps. |
| 4607 | * |
| 4608 | * Implementation of the method from LauncherModel.Callbacks. |
| 4609 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4610 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4611 | if (LauncherAppState.isDisableAllApps()) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4612 | if (mIntentsOnWorkspaceFromUpgradePath != null) { |
| 4613 | if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) { |
| 4614 | getHotseat().addAllAppsFolder(mIconCache, apps, |
| 4615 | mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace); |
| 4616 | } |
| 4617 | mIntentsOnWorkspaceFromUpgradePath = null; |
Daniel Sandler | 8707e0f | 2013-08-15 15:54:18 -0700 | [diff] [blame] | 4618 | } |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4619 | if (mAppsCustomizeContent != null) { |
| 4620 | mAppsCustomizeContent.onPackagesUpdated( |
| 4621 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
| 4622 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4623 | } else { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 4624 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4625 | mAppsCustomizeContent.setApps(apps); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 4626 | mAppsCustomizeContent.onPackagesUpdated( |
| 4627 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4628 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4629 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | /** |
| 4633 | * A package was updated. |
| 4634 | * |
| 4635 | * Implementation of the method from LauncherModel.Callbacks. |
| 4636 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4637 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4638 | Runnable r = new Runnable() { |
| 4639 | public void run() { |
| 4640 | bindAppsUpdated(apps); |
| 4641 | } |
| 4642 | }; |
| 4643 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4644 | return; |
| 4645 | } |
| 4646 | |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 4647 | if (mWorkspace != null) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4648 | mWorkspace.updateShortcutsAndWidgets(apps); |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 4649 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4650 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4651 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4652 | mAppsCustomizeContent != null) { |
| 4653 | mAppsCustomizeContent.updateApps(apps); |
| 4654 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4658 | * Update the state of a package, typically related to install state. |
| 4659 | * |
| 4660 | * Implementation of the method from LauncherModel.Callbacks. |
| 4661 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4662 | @Override |
| 4663 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4664 | if (mWorkspace != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4665 | mWorkspace.updatePackageState(installInfo); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4666 | } |
| 4667 | } |
| 4668 | |
| 4669 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4670 | * A package was uninstalled. We take both the super set of packageNames |
| 4671 | * in addition to specific applications to remove, the reason being that |
| 4672 | * this can be called when a package is updated as well. In that scenario, |
| 4673 | * we only remove specific components from the workspace, where as |
| 4674 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4675 | * |
| 4676 | * Implementation of the method from LauncherModel.Callbacks. |
| 4677 | */ |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4678 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4679 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4680 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4681 | public void run() { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4682 | bindComponentsRemoved(packageNames, appInfos, user); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4683 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4684 | }; |
| 4685 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4686 | return; |
| 4687 | } |
| 4688 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4689 | if (!packageNames.isEmpty()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4690 | mWorkspace.removeItemsByPackageName(packageNames, user); |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4691 | } |
| 4692 | if (!appInfos.isEmpty()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4693 | mWorkspace.removeItemsByApplicationInfo(appInfos, user); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 4694 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4695 | |
Winson Chung | a182096 | 2011-10-03 16:31:06 -0700 | [diff] [blame] | 4696 | // Notify the drag controller |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4697 | mDragController.onAppsRemoved(packageNames, appInfos); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4698 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4699 | // Update AllApps |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4700 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4701 | mAppsCustomizeContent != null) { |
| 4702 | mAppsCustomizeContent.removeApps(appInfos); |
| 4703 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4704 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4705 | |
| 4706 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4707 | * A number of packages were updated. |
| 4708 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4709 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 4710 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4711 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4712 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 4713 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4714 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4715 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4716 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 4717 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 4718 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4719 | return; |
| 4720 | } |
| 4721 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4722 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4723 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4724 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4725 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4726 | } |
| 4727 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4728 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 4729 | final Display d = getWindowManager().getDefaultDisplay(); |
| 4730 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 4731 | switch (d.getRotation()) { |
| 4732 | case Surface.ROTATION_0: |
| 4733 | case Surface.ROTATION_180: |
| 4734 | // We are currently in the same basic orientation as the natural orientation |
| 4735 | naturalOri = configOri; |
| 4736 | break; |
| 4737 | case Surface.ROTATION_90: |
| 4738 | case Surface.ROTATION_270: |
| 4739 | // We are currently in the other basic orientation to the natural orientation |
| 4740 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 4741 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 4742 | break; |
| 4743 | } |
| 4744 | |
| 4745 | int[] oriMap = { |
| 4746 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 4747 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 4748 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 4749 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 4750 | }; |
| 4751 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 4752 | // is landscape. |
| 4753 | int indexOffset = 0; |
| 4754 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 4755 | indexOffset = 1; |
| 4756 | } |
| 4757 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 4758 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 4759 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4760 | public boolean isRotationEnabled() { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 4761 | boolean enableRotation = sForceEnableRotation || |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4762 | getResources().getBoolean(R.bool.allow_rotation); |
| 4763 | return enableRotation; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4764 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4765 | public void lockScreenOrientation() { |
| 4766 | if (isRotationEnabled()) { |
| 4767 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 4768 | .getConfiguration().orientation)); |
| 4769 | } |
| 4770 | } |
| 4771 | public void unlockScreenOrientation(boolean immediate) { |
| 4772 | if (isRotationEnabled()) { |
| 4773 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4774 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4775 | } else { |
| 4776 | mHandler.postDelayed(new Runnable() { |
| 4777 | public void run() { |
| 4778 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 4779 | } |
| 4780 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4781 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4782 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4783 | } |
| 4784 | |
Sandeep Siddhartha | d4d3d08 | 2013-12-26 15:42:52 -0800 | [diff] [blame] | 4785 | /** |
| 4786 | * Called when the SearchBar hint should be changed. |
| 4787 | * |
| 4788 | * @param hint the hint to be displayed in the search bar. |
| 4789 | */ |
| 4790 | protected void onSearchBarHintChanged(String hint) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4791 | mLauncherClings.updateSearchBarHint(hint); |
Sandeep Siddhartha | d4d3d08 | 2013-12-26 15:42:52 -0800 | [diff] [blame] | 4792 | } |
| 4793 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4794 | protected boolean isLauncherPreinstalled() { |
| 4795 | PackageManager pm = getPackageManager(); |
| 4796 | try { |
| 4797 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 4798 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4799 | return true; |
| 4800 | } else { |
| 4801 | return false; |
| 4802 | } |
| 4803 | } catch (NameNotFoundException e) { |
| 4804 | e.printStackTrace(); |
| 4805 | return false; |
| 4806 | } |
| 4807 | } |
| 4808 | |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4809 | /** |
| 4810 | * This method indicates whether or not we should suggest default wallpaper dimensions |
| 4811 | * when our wallpaper cropper was not yet used to set a wallpaper. |
| 4812 | */ |
| 4813 | protected boolean overrideWallpaperDimensions() { |
| 4814 | return true; |
| 4815 | } |
| 4816 | |
Adam Cohen | 5eed5d8 | 2014-05-19 13:12:13 -0700 | [diff] [blame] | 4817 | protected boolean shouldClingFocusHotseatApp() { |
| 4818 | return false; |
| 4819 | } |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 4820 | protected String getFirstRunClingSearchBarHint() { |
| 4821 | return ""; |
| 4822 | } |
| 4823 | protected String getFirstRunCustomContentHint() { |
| 4824 | return ""; |
| 4825 | } |
Winson Chung | 3a6e7f3 | 2013-10-09 15:50:52 -0700 | [diff] [blame] | 4826 | protected int getFirstRunFocusedHotseatAppDrawableId() { |
| 4827 | return -1; |
| 4828 | } |
| 4829 | protected ComponentName getFirstRunFocusedHotseatAppComponentName() { |
| 4830 | return null; |
| 4831 | } |
| 4832 | protected int getFirstRunFocusedHotseatAppRank() { |
| 4833 | return -1; |
| 4834 | } |
| 4835 | protected String getFirstRunFocusedHotseatAppBubbleTitle() { |
| 4836 | return ""; |
| 4837 | } |
| 4838 | protected String getFirstRunFocusedHotseatAppBubbleDescription() { |
| 4839 | return ""; |
| 4840 | } |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 4841 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 4842 | public void dismissFirstRunCling(View v) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4843 | mLauncherClings.dismissFirstRunCling(v); |
| 4844 | } |
| 4845 | public void dismissMigrationClingCopyApps(View v) { |
| 4846 | mLauncherClings.dismissMigrationClingCopyApps(v); |
| 4847 | } |
| 4848 | public void dismissMigrationClingUseDefault(View v) { |
| 4849 | mLauncherClings.dismissMigrationClingUseDefault(v); |
| 4850 | } |
| 4851 | public void dismissMigrationWorkspaceCling(View v) { |
| 4852 | mLauncherClings.dismissMigrationWorkspaceCling(v); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 4853 | } |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 4854 | public void dismissWorkspaceCling(View v) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4855 | mLauncherClings.dismissWorkspaceCling(v); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 4856 | } |
| 4857 | public void dismissFolderCling(View v) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4858 | mLauncherClings.dismissFolderCling(v); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 4859 | } |
Adam Cohen | 6268f2d | 2014-05-16 16:42:35 -0700 | [diff] [blame] | 4860 | public void markFolderClingDismissedIfNecessary() { |
| 4861 | mLauncherClings.markFolderClingDismissedIfNecessary(); |
| 4862 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4863 | |
| 4864 | /** |
| 4865 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 4866 | * before showing the standard launcher experience. |
| 4867 | */ |
| 4868 | protected boolean hasFirstRunActivity() { |
| 4869 | return false; |
| 4870 | } |
| 4871 | |
| 4872 | /** |
| 4873 | * To be overridden by subclasses to launch any first run activity |
| 4874 | */ |
| 4875 | protected Intent getFirstRunActivity() { |
| 4876 | return null; |
| 4877 | } |
| 4878 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4879 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4880 | return !ActivityManager.isRunningInTestHarness() && |
| 4881 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4882 | } |
| 4883 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 4884 | protected boolean hasRunFirstRunActivity() { |
| 4885 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 4886 | } |
| 4887 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4888 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4889 | if (shouldRunFirstRunActivity() && |
| 4890 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4891 | Intent firstRunIntent = getFirstRunActivity(); |
| 4892 | if (firstRunIntent != null) { |
| 4893 | startActivity(firstRunIntent); |
| 4894 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4895 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4896 | } |
| 4897 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4898 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4899 | } |
| 4900 | |
| 4901 | private void markFirstRunActivityShown() { |
| 4902 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4903 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 4904 | editor.apply(); |
| 4905 | } |
| 4906 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4907 | /** |
| 4908 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 4909 | * screen that must be displayed and dismissed. |
| 4910 | */ |
| 4911 | protected boolean hasDismissableIntroScreen() { |
| 4912 | return false; |
| 4913 | } |
| 4914 | |
| 4915 | /** |
| 4916 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 4917 | */ |
| 4918 | protected View getIntroScreen() { |
| 4919 | return null; |
| 4920 | } |
| 4921 | |
| 4922 | /** |
| 4923 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 4924 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 4925 | */ |
| 4926 | private boolean shouldShowIntroScreen() { |
| 4927 | return hasDismissableIntroScreen() && |
| 4928 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 4929 | } |
| 4930 | |
| 4931 | protected void showIntroScreen() { |
| 4932 | View introScreen = getIntroScreen(); |
| 4933 | changeWallpaperVisiblity(false); |
| 4934 | if (introScreen != null) { |
| 4935 | mDragLayer.showOverlayView(introScreen); |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | public void dismissIntroScreen() { |
| 4940 | markIntroScreenDismissed(); |
| 4941 | if (showFirstRunActivity()) { |
| 4942 | // We delay hiding the intro view until the first run activity is showing. This |
| 4943 | // avoids a blip. |
| 4944 | mWorkspace.postDelayed(new Runnable() { |
| 4945 | @Override |
| 4946 | public void run() { |
| 4947 | mDragLayer.dismissOverlayView(); |
| 4948 | } |
| 4949 | }, ACTIVITY_START_DELAY); |
| 4950 | } else { |
| 4951 | mDragLayer.dismissOverlayView(); |
| 4952 | } |
| 4953 | changeWallpaperVisiblity(true); |
| 4954 | } |
| 4955 | |
| 4956 | private void markIntroScreenDismissed() { |
| 4957 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4958 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 4959 | editor.apply(); |
| 4960 | } |
| 4961 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4962 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4963 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 4964 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 4965 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 4966 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4970 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 4971 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 4972 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 4973 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4974 | } |
| 4975 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4976 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4977 | // Called from search suggestion, not supported in other profiles. |
| 4978 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 4979 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 4980 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 4981 | myUser); |
| 4982 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4983 | return null; |
| 4984 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4985 | return new AppInfo(this, activityInfo, myUser, mIconCache, null); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 4989 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4990 | // Called from search suggestion, not supported in other profiles. |
| 4991 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 4992 | UserHandleCompat.myUserHandle()); |
| 4993 | } |
| 4994 | |
| 4995 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 4996 | Bitmap icon, UserHandleCompat user) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 4997 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 4998 | CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 4999 | return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 5002 | protected void moveWorkspaceToDefaultScreen() { |
| 5003 | mWorkspace.moveToDefaultScreen(false); |
| 5004 | } |
| 5005 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5006 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 5007 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 5008 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 5009 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5012 | @Override |
| 5013 | public void onPageSwitch(View newPage, int newPageIndex) { |
| 5014 | } |
| 5015 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5016 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5017 | * Prints out out state for debugging. |
| 5018 | */ |
| 5019 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5020 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5021 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5022 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 5023 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 5024 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 5025 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 5026 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5027 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5028 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5029 | if (mAppsCustomizeContent != null) { |
| 5030 | mAppsCustomizeContent.dumpState(); |
| 5031 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5032 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5033 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5034 | |
| 5035 | @Override |
| 5036 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5037 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5038 | synchronized (sDumpLogs) { |
| 5039 | writer.println(" "); |
| 5040 | writer.println("Debug logs: "); |
| 5041 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5042 | writer.println(" " + sDumpLogs.get(i)); |
| 5043 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5044 | } |
| 5045 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5046 | |
| 5047 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5048 | if (DEBUG_DUMP_LOG) { |
| 5049 | synchronized (sDumpLogs) { |
| 5050 | Log.d(TAG, ""); |
| 5051 | Log.d(TAG, "*********************"); |
| 5052 | Log.d(TAG, "Launcher debug logs: "); |
| 5053 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5054 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 5055 | } |
| 5056 | Log.d(TAG, "*********************"); |
| 5057 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5058 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5059 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5063 | addDumpLog(tag, log, null, debugLog); |
| 5064 | } |
| 5065 | |
| 5066 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5067 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5068 | if (e != null) { |
| 5069 | Log.d(tag, log, e); |
| 5070 | } else { |
| 5071 | Log.d(tag, log); |
| 5072 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5073 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5074 | if (DEBUG_DUMP_LOG) { |
| 5075 | sDateStamp.setTime(System.currentTimeMillis()); |
| 5076 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5077 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 5078 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5079 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5080 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5083 | public void dumpLogsToLocalData() { |
| 5084 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5085 | new AsyncTask<Void, Void, Void>() { |
| 5086 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5087 | boolean success = false; |
| 5088 | sDateStamp.setTime(sRunStart); |
| 5089 | String FILENAME = sDateStamp.getMonth() + "-" |
| 5090 | + sDateStamp.getDay() + "_" |
| 5091 | + sDateStamp.getHours() + "-" |
| 5092 | + sDateStamp.getMinutes() + "_" |
| 5093 | + sDateStamp.getSeconds() + ".txt"; |
| 5094 | |
| 5095 | FileOutputStream fos = null; |
| 5096 | File outFile = null; |
| 5097 | try { |
| 5098 | outFile = new File(getFilesDir(), FILENAME); |
| 5099 | outFile.createNewFile(); |
| 5100 | fos = new FileOutputStream(outFile); |
| 5101 | } catch (Exception e) { |
| 5102 | e.printStackTrace(); |
| 5103 | } |
| 5104 | if (fos != null) { |
| 5105 | PrintWriter writer = new PrintWriter(fos); |
| 5106 | |
| 5107 | writer.println(" "); |
| 5108 | writer.println("Debug logs: "); |
| 5109 | synchronized (sDumpLogs) { |
| 5110 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5111 | writer.println(" " + sDumpLogs.get(i)); |
| 5112 | } |
| 5113 | } |
| 5114 | writer.close(); |
| 5115 | } |
| 5116 | try { |
| 5117 | if (fos != null) { |
| 5118 | fos.close(); |
| 5119 | success = true; |
| 5120 | } |
| 5121 | } catch (IOException e) { |
| 5122 | e.printStackTrace(); |
| 5123 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5124 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5125 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5126 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5127 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5128 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5129 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5130 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 5131 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 5132 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 5133 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5134 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 5135 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5136 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5137 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 5138 | |
| 5139 | interface DebugIntents { |
| 5140 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 5141 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 5142 | } |