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