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