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