Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 18 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 20 | import android.animation.Animator; |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 21 | import android.animation.AnimatorListenerAdapter; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 22 | import android.animation.AnimatorSet; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
| 24 | import android.animation.PropertyValuesHolder; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 25 | import android.animation.TimeInterpolator; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 26 | import android.animation.ValueAnimator; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 27 | import android.annotation.TargetApi; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 28 | import android.app.Activity; |
Brett Chabot | 2a9e228 | 2011-08-23 15:03:13 -0700 | [diff] [blame] | 29 | import android.app.ActivityManager; |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 30 | import android.app.ActivityOptions; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 31 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | import android.app.SearchManager; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 33 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 34 | import android.appwidget.AppWidgetManager; |
| 35 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 37 | import android.content.BroadcastReceiver; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 38 | import android.content.ComponentCallbacks2; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 39 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 40 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.content.Context; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 42 | import android.content.DialogInterface; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 44 | import android.content.IntentFilter; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 45 | import android.content.SharedPreferences; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 46 | import android.content.pm.ActivityInfo; |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 47 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 49 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 51 | import android.content.res.Resources; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 52 | import android.database.ContentObserver; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 53 | import android.graphics.Bitmap; |
| 54 | import android.graphics.Canvas; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame] | 55 | import android.graphics.Color; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 56 | import android.graphics.Point; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 57 | import android.graphics.PorterDuff; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 58 | import android.graphics.Rect; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 59 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 60 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 61 | import android.os.AsyncTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 62 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 63 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 64 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 65 | import android.os.Message; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 66 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 67 | import android.os.SystemClock; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 68 | import android.speech.RecognizerIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | import android.text.Selection; |
| 70 | import android.text.SpannableStringBuilder; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 71 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | import android.text.method.TextKeyListener; |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 73 | import android.util.DisplayMetrics; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 74 | import android.util.Log; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 75 | import android.view.Display; |
| 76 | import android.view.Gravity; |
| 77 | import android.view.HapticFeedbackConstants; |
| 78 | import android.view.KeyEvent; |
| 79 | import android.view.LayoutInflater; |
| 80 | import android.view.Menu; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 81 | import android.view.MotionEvent; |
| 82 | import android.view.Surface; |
| 83 | import android.view.View; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 84 | import android.view.View.OnClickListener; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 85 | import android.view.View.OnLongClickListener; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 86 | import android.view.ViewAnimationUtils; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 87 | import android.view.ViewGroup; |
| 88 | import android.view.ViewTreeObserver; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 89 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 90 | import android.view.Window; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 91 | import android.view.WindowManager; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 92 | import android.view.accessibility.AccessibilityEvent; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 93 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 94 | import android.view.animation.DecelerateInterpolator; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 95 | import android.view.animation.Interpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 96 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 97 | import android.widget.Advanceable; |
| 98 | import android.widget.FrameLayout; |
| 99 | import android.widget.ImageView; |
| 100 | import android.widget.TextView; |
| 101 | import android.widget.Toast; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 102 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 103 | import com.android.launcher3.DropTarget.DragObject; |
| 104 | import com.android.launcher3.PagedView.PageSwitchListener; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 105 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 106 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 107 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 108 | import com.android.launcher3.compat.PackageInstallerCompat; |
| 109 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 110 | import com.android.launcher3.compat.UserHandleCompat; |
| 111 | import com.android.launcher3.compat.UserManagerCompat; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 112 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 113 | import java.io.DataInputStream; |
| 114 | import java.io.DataOutputStream; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 115 | import java.io.File; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 116 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 117 | import java.io.FileNotFoundException; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 118 | import java.io.FileOutputStream; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 119 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 120 | import java.io.PrintWriter; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 121 | import java.lang.reflect.Field; |
| 122 | import java.lang.reflect.InvocationTargetException; |
| 123 | import java.lang.reflect.Method; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 124 | import java.text.DateFormat; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 125 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 126 | import java.util.Collection; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 127 | import java.util.Date; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 128 | import java.util.HashMap; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 129 | import java.util.List; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 130 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 131 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 132 | /** |
| 133 | * Default launcher application. |
| 134 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 135 | public class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 136 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 137 | View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 138 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 139 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 140 | |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 141 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 142 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 143 | static final boolean DEBUG_STRICT_MODE = false; |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 144 | static final boolean DEBUG_RESUME_TIME = false; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 145 | static final boolean DEBUG_DUMP_LOG = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 146 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 147 | static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run |
| 148 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 149 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 150 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 151 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 152 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 153 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 154 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 155 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 156 | private static final int REQUEST_RECONFIGURE_APPWIDGET = 12; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 157 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 158 | /** |
| 159 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 160 | * request codes used internally. |
| 161 | */ |
| 162 | protected static final int REQUEST_LAST = 100; |
| 163 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 164 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 165 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 166 | static final int SCREEN_COUNT = 5; |
| 167 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 168 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 169 | private static final String PREFERENCES = "launcher.preferences"; |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 170 | // To turn on these properties, type |
| 171 | // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS] |
| 172 | static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate"; |
| 173 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 174 | static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 175 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 176 | // The Intent extra that defines whether to ignore the launch animation |
| 177 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 178 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 179 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 180 | // Type: int |
| 181 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 182 | // Type: int |
| 183 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 184 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 185 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 186 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 187 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 188 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 189 | 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] | 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_Y = "launcher.add_cell_y"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 192 | // Type: boolean |
| 193 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 194 | // Type: long |
| 195 | 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] | 196 | // Type: int |
| 197 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 198 | // Type: int |
| 199 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 200 | // Type: parcelable |
| 201 | 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] | 202 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 203 | 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] | 204 | // Type: int[] |
| 205 | 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] | 206 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 207 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 208 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 209 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 210 | static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete"; |
| 211 | static final String ACTION_FIRST_LOAD_COMPLETE = |
| 212 | "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; |
| 213 | |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 214 | 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] | 215 | private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 216 | "com.android.launcher.toolbar_search_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 217 | private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 218 | "com.android.launcher.toolbar_voice_search_icon"; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 219 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 220 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 221 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 222 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 223 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 224 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 225 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 226 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 227 | private State mState = State.WORKSPACE; |
| 228 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 229 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 230 | private boolean mIsSafeModeEnabled; |
| 231 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 232 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 233 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 234 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 235 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 236 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 237 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 238 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 239 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 240 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 241 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 242 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 243 | // 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] | 244 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 245 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 246 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 247 | private static final int SINGLE_FRAME_DELAY = 16; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 248 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 249 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 250 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 251 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 252 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 253 | private LayoutInflater mInflater; |
| 254 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 255 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 256 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 257 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 258 | private DragLayer mDragLayer; |
| 259 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 260 | private View mWeightWatcher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 261 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 262 | private AppWidgetManagerCompat mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 263 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 264 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 265 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 266 | private AppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 267 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 268 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 269 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 270 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 271 | private FolderInfo mFolderInfo; |
| 272 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 273 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 274 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 275 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 276 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 277 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 278 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 279 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 280 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 281 | private boolean mAutoAdvanceRunning = false; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 282 | private View mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 283 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 284 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 285 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 286 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 287 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 288 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 289 | |
| 290 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 291 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 292 | private boolean mWorkspaceLoading = true; |
| 293 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 294 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 295 | private boolean mRestoring; |
| 296 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 297 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 298 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 299 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 300 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 301 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 302 | private Bundle mSavedInstanceState; |
| 303 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 304 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 305 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 306 | private boolean mUserPresent = true; |
| 307 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 308 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 309 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 310 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 311 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 312 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 313 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 314 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 315 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 316 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 317 | // Related to the auto-advancing of widgets |
| 318 | private final int ADVANCE_MSG = 1; |
| 319 | private final int mAdvanceInterval = 20000; |
| 320 | private final int mAdvanceStagger = 250; |
| 321 | private long mAutoAdvanceSentTime; |
| 322 | private long mAutoAdvanceTimeLeft = -1; |
| 323 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 324 | new HashMap<View, AppWidgetProviderInfo>(); |
| 325 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 326 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 327 | // match the sensor state. |
| 328 | private final int mRestoreScreenOrientationDelay = 500; |
| 329 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 330 | // External icons saved in case of resource changes, orientation, etc. |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 331 | private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; |
| 332 | private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 333 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 334 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 335 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 336 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 337 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 338 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 339 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 340 | static Date sDateStamp = new Date(); |
| 341 | static DateFormat sDateFormat = |
| 342 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 343 | static long sRunStart = System.currentTimeMillis(); |
| 344 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 345 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 346 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 347 | // it from the context. |
| 348 | private SharedPreferences mSharedPrefs; |
| 349 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 350 | private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null; |
| 351 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 352 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 353 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 354 | private ImageView mFolderIconImageView; |
| 355 | private Bitmap mFolderIconBitmap; |
| 356 | private Canvas mFolderIconCanvas; |
| 357 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 358 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 359 | private BubbleTextView mWaitingForResume; |
| 360 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 361 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 362 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 363 | if (mWorkspace != null) { |
| 364 | mWorkspace.buildPageHardwareLayers(); |
| 365 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 366 | } |
| 367 | }; |
| 368 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 369 | private static PendingAddArguments sPendingAddItem; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 370 | |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 371 | public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 372 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 373 | private static class PendingAddArguments { |
| 374 | int requestCode; |
| 375 | Intent intent; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 376 | long container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 377 | long screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 378 | int cellX; |
| 379 | int cellY; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 380 | int appWidgetId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 383 | private Stats mStats; |
| 384 | |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 385 | FocusIndicatorView mFocusHandler; |
| 386 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 387 | static boolean isPropertyEnabled(String propertyName) { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 388 | return Log.isLoggable(propertyName, Log.VERBOSE); |
Michael Jurka | 9bc8eba | 2012-05-21 20:36:44 -0700 | [diff] [blame] | 389 | } |
| 390 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 391 | @Override |
| 392 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 393 | if (DEBUG_STRICT_MODE) { |
| 394 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 395 | .detectDiskReads() |
| 396 | .detectDiskWrites() |
| 397 | .detectNetwork() // or .detectAll() for all detectable problems |
| 398 | .penaltyLog() |
| 399 | .build()); |
| 400 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 401 | .detectLeakedSqlLiteObjects() |
| 402 | .detectLeakedClosableObjects() |
| 403 | .penaltyLog() |
| 404 | .penaltyDeath() |
| 405 | .build()); |
| 406 | } |
| 407 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 408 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 409 | |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 410 | LauncherAppState.setApplicationContext(getApplicationContext()); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 411 | LauncherAppState app = LauncherAppState.getInstance(); |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 412 | LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 413 | // Determine the dynamic grid properties |
| 414 | Point smallestSize = new Point(); |
| 415 | Point largestSize = new Point(); |
| 416 | Point realSize = new Point(); |
| 417 | Display display = getWindowManager().getDefaultDisplay(); |
| 418 | display.getCurrentSizeRange(smallestSize, largestSize); |
| 419 | display.getRealSize(realSize); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 420 | DisplayMetrics dm = new DisplayMetrics(); |
| 421 | display.getMetrics(dm); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 422 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 423 | // Lazy-initialize the dynamic grid |
| 424 | DeviceProfile grid = app.initDynamicGrid(this, |
| 425 | Math.min(smallestSize.x, smallestSize.y), |
| 426 | Math.min(largestSize.x, largestSize.y), |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 427 | realSize.x, realSize.y, |
| 428 | dm.widthPixels, dm.heightPixels); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 429 | |
| 430 | // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 431 | mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 432 | Context.MODE_PRIVATE); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 433 | mIsSafeModeEnabled = getPackageManager().isSafeMode(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 434 | mModel = app.setLauncher(this); |
| 435 | mIconCache = app.getIconCache(); |
Winson Chung | e5467dc | 2013-10-14 17:03:04 -0700 | [diff] [blame] | 436 | mIconCache.flushInvalidIcons(grid); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 437 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 438 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 439 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 440 | mStats = new Stats(this); |
| 441 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 442 | mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 443 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 444 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 445 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 446 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 447 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 448 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 449 | // LauncherModel load. |
| 450 | mPaused = false; |
| 451 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 452 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 453 | android.os.Debug.startMethodTracing( |
| 454 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 458 | setContentView(R.layout.launcher); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 459 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 460 | setupViews(); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 461 | grid.layout(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 462 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 463 | registerContentObservers(); |
| 464 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 465 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 466 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 467 | mSavedState = savedInstanceState; |
| 468 | restoreState(mSavedState); |
| 469 | |
| 470 | if (PROFILE_STARTUP) { |
| 471 | android.os.Debug.stopMethodTracing(); |
| 472 | } |
| 473 | |
| 474 | if (!mRestoring) { |
Adam Cohen | db78dc8 | 2014-06-19 14:50:51 -0700 | [diff] [blame] | 475 | if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 476 | // If the user leaves launcher, then we should just load items asynchronously when |
| 477 | // they return. |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 478 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 479 | } else { |
| 480 | // We only load the page synchronously if the user rotates (or triggers a |
| 481 | // configuration change) while launcher is in the foreground |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 482 | mModel.startLoader(true, mWorkspace.getRestorePage()); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 483 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | // For handling default keys |
| 487 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 488 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 489 | |
| 490 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 491 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 492 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 493 | updateGlobalIcons(); |
| 494 | |
| 495 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 496 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 497 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 498 | if (shouldShowIntroScreen()) { |
| 499 | showIntroScreen(); |
| 500 | } else { |
| 501 | showFirstRunActivity(); |
| 502 | } |
| 503 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 504 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 505 | // on the device, then we always show the first run cling experience (or if there is no |
| 506 | // launcher2). Otherwise, we prompt the user upon started for migration |
Sunny Goyal | 424418b | 2014-08-22 16:09:37 -0700 | [diff] [blame] | 507 | LauncherClings launcherClings = new LauncherClings(this); |
| 508 | if (launcherClings.shouldShowFirstRunOrMigrationClings()) { |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 509 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
Sunny Goyal | 424418b | 2014-08-22 16:09:37 -0700 | [diff] [blame] | 510 | launcherClings.showMigrationCling(); |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 511 | } else { |
Sunny Goyal | 7661614 | 2014-08-26 10:54:08 -0700 | [diff] [blame] | 512 | launcherClings.showLongPressCling(false); |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 513 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 514 | } |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 517 | @Override |
| 518 | public void onLauncherProviderChange() { } |
| 519 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 520 | /** To be overriden by subclasses to hint to Launcher that we have custom content */ |
| 521 | protected boolean hasCustomContentToLeft() { |
| 522 | return false; |
| 523 | } |
| 524 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 525 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 526 | * 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] | 527 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 528 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 529 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 530 | protected void populateCustomContentContainer() { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 535 | * ensure the custom content page is added or removed if necessary. |
| 536 | */ |
| 537 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 538 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 539 | // Not bound yet, wait for bindScreens to be called. |
| 540 | return; |
| 541 | } |
| 542 | |
| 543 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 544 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 545 | mWorkspace.createCustomContentContainer(); |
| 546 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 547 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 548 | mWorkspace.removeCustomContentPage(); |
| 549 | } |
| 550 | } |
| 551 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 552 | private void updateGlobalIcons() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 553 | boolean searchVisible = false; |
| 554 | boolean voiceVisible = false; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 555 | // 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] | 556 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
Adam Cohen | a00673c | 2014-08-14 12:57:28 -0700 | [diff] [blame] | 557 | if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 558 | searchVisible = updateGlobalSearchIcon(); |
| 559 | voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 560 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 561 | if (sGlobalSearchIcon[coi] != null) { |
| 562 | updateGlobalSearchIcon(sGlobalSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 563 | searchVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 564 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 565 | if (sVoiceSearchIcon[coi] != null) { |
| 566 | updateVoiceSearchIcon(sVoiceSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 567 | voiceVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 568 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 569 | if (mSearchDropTargetBar != null) { |
| 570 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 571 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 572 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 573 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 574 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 575 | if (sLocaleConfiguration == null) { |
| 576 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 577 | @Override |
| 578 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 579 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 580 | readConfiguration(Launcher.this, localeConfiguration); |
| 581 | return localeConfiguration; |
| 582 | } |
| 583 | |
| 584 | @Override |
| 585 | protected void onPostExecute(LocaleConfiguration result) { |
| 586 | sLocaleConfiguration = result; |
| 587 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 588 | } |
| 589 | }.execute(); |
| 590 | return; |
| 591 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 592 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 593 | final Configuration configuration = getResources().getConfiguration(); |
| 594 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 595 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 596 | final String locale = configuration.locale.toString(); |
| 597 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 598 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 599 | final int mcc = configuration.mcc; |
| 600 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 601 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 602 | final int mnc = configuration.mnc; |
| 603 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 604 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 605 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 606 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 607 | sLocaleConfiguration.locale = locale; |
| 608 | sLocaleConfiguration.mcc = mcc; |
| 609 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 610 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 611 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 612 | |
| 613 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 614 | new AsyncTask<Void, Void, Void>() { |
| 615 | public Void doInBackground(Void ... args) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 616 | writeConfiguration(Launcher.this, localeConfiguration); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 617 | return null; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 618 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 619 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
| 623 | private static class LocaleConfiguration { |
| 624 | public String locale; |
| 625 | public int mcc = -1; |
| 626 | public int mnc = -1; |
| 627 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 628 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 629 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 630 | DataInputStream in = null; |
| 631 | try { |
| 632 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 633 | configuration.locale = in.readUTF(); |
| 634 | configuration.mcc = in.readInt(); |
| 635 | configuration.mnc = in.readInt(); |
| 636 | } catch (FileNotFoundException e) { |
| 637 | // Ignore |
| 638 | } catch (IOException e) { |
| 639 | // Ignore |
| 640 | } finally { |
| 641 | if (in != null) { |
| 642 | try { |
| 643 | in.close(); |
| 644 | } catch (IOException e) { |
| 645 | // Ignore |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 652 | DataOutputStream out = null; |
| 653 | try { |
| 654 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 655 | out.writeUTF(configuration.locale); |
| 656 | out.writeInt(configuration.mcc); |
| 657 | out.writeInt(configuration.mnc); |
| 658 | out.flush(); |
| 659 | } catch (FileNotFoundException e) { |
| 660 | // Ignore |
| 661 | } catch (IOException e) { |
| 662 | //noinspection ResultOfMethodCallIgnored |
| 663 | context.getFileStreamPath(PREFERENCES).delete(); |
| 664 | } finally { |
| 665 | if (out != null) { |
| 666 | try { |
| 667 | out.close(); |
| 668 | } catch (IOException e) { |
| 669 | // Ignore |
| 670 | } |
| 671 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 675 | public Stats getStats() { |
| 676 | return mStats; |
| 677 | } |
| 678 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 679 | public LayoutInflater getInflater() { |
| 680 | return mInflater; |
| 681 | } |
| 682 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 683 | boolean isDraggingEnabled() { |
| 684 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 685 | // that is subsequently removed from the workspace in startBinding(). |
| 686 | return !mModel.isLoadingWorkspace(); |
| 687 | } |
| 688 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 689 | static int getScreen() { |
| 690 | synchronized (sLock) { |
| 691 | return sScreen; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | static void setScreen(int screen) { |
| 696 | synchronized (sLock) { |
| 697 | sScreen = screen; |
| 698 | } |
| 699 | } |
| 700 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 701 | /** |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 702 | * Copied from View -- the View version of the method isn't called |
| 703 | * anywhere else in our process and only exists for API level 17+, |
| 704 | * so it's ok to keep our own version with no API requirement. |
| 705 | */ |
| 706 | public static int generateViewId() { |
| 707 | for (;;) { |
| 708 | final int result = sNextGeneratedId.get(); |
| 709 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 710 | int newValue = result + 1; |
| 711 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 712 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 713 | return result; |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | public int getViewIdForItem(ItemInfo info) { |
| 719 | // This cast is safe given the > 2B range for int. |
| 720 | int itemId = (int) info.id; |
| 721 | if (mItemIdToViewId.containsKey(itemId)) { |
| 722 | return mItemIdToViewId.get(itemId); |
| 723 | } |
| 724 | int viewId = generateViewId(); |
| 725 | mItemIdToViewId.put(itemId, viewId); |
| 726 | return viewId; |
| 727 | } |
| 728 | |
| 729 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 730 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 731 | * a configuration step, this allows the proper animations to run after other transitions. |
| 732 | */ |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 733 | private long completeAdd(PendingAddArguments args) { |
| 734 | |
| 735 | long screenId = ensurePendingDropLayoutExists(args.screenId); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 736 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 737 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 738 | completeAddShortcut(args.intent, args.container, screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 739 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 740 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 741 | case REQUEST_CREATE_APPWIDGET: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 742 | completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 743 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 744 | case REQUEST_RECONFIGURE_APPWIDGET: |
| 745 | completeRestoreAppWidget(args.appWidgetId); |
| 746 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 747 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 748 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 749 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 750 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 751 | resetAddInfo(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 752 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 753 | } |
| 754 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 755 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 756 | protected void onActivityResult( |
| 757 | final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 758 | // Reset the startActivity waiting flag |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 759 | setWaitingForResult(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 760 | final int pendingAddWidgetId = mPendingAddWidgetId; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 761 | mPendingAddWidgetId = -1; |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 762 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 763 | Runnable exitSpringLoaded = new Runnable() { |
| 764 | @Override |
| 765 | public void run() { |
| 766 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 767 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 768 | } |
| 769 | }; |
| 770 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 771 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 772 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 773 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 774 | if (resultCode == RESULT_CANCELED) { |
| 775 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 776 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 777 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 778 | } else if (resultCode == RESULT_OK) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 779 | addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, |
| 780 | mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 781 | } |
| 782 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 783 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 784 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
| 785 | mWorkspace.exitOverviewMode(false); |
| 786 | } |
| 787 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 788 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 789 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 790 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 791 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 792 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 793 | final boolean workspaceLocked = isWorkspaceLocked(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 794 | // We have special handling for widgets |
| 795 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 796 | final int appWidgetId; |
| 797 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 798 | : -1; |
| 799 | if (widgetId < 0) { |
| 800 | appWidgetId = pendingAddWidgetId; |
| 801 | } else { |
| 802 | appWidgetId = widgetId; |
| 803 | } |
| 804 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 805 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 806 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 807 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 808 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 809 | result = RESULT_CANCELED; |
| 810 | completeTwoStageWidgetDrop(result, appWidgetId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 811 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 812 | @Override |
| 813 | public void run() { |
| 814 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 815 | } |
| 816 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 817 | if (workspaceLocked) { |
| 818 | // No need to remove the empty screen if we're mid-binding, as the |
| 819 | // the bind will not add the empty screen. |
| 820 | mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
| 821 | } else { |
| 822 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 823 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 824 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 825 | } else { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 826 | if (!workspaceLocked) { |
| 827 | mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId); |
| 828 | final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
| 829 | |
| 830 | dropLayout.setDropPending(true); |
| 831 | final Runnable onComplete = new Runnable() { |
| 832 | @Override |
| 833 | public void run() { |
| 834 | completeTwoStageWidgetDrop(resultCode, appWidgetId); |
| 835 | dropLayout.setDropPending(false); |
| 836 | } |
| 837 | }; |
| 838 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 839 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 840 | } else { |
| 841 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId, |
| 842 | mPendingAddInfo); |
| 843 | sPendingAddItem = args; |
| 844 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 845 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 846 | return; |
| 847 | } |
| 848 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 849 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) { |
| 850 | if (resultCode == RESULT_OK) { |
| 851 | // Update the widget view. |
| 852 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, |
| 853 | pendingAddWidgetId, mPendingAddInfo); |
| 854 | if (workspaceLocked) { |
| 855 | sPendingAddItem = args; |
| 856 | } else { |
| 857 | completeAdd(args); |
| 858 | } |
| 859 | } |
| 860 | // Leave the widget in the pending state if the user canceled the configure. |
| 861 | return; |
| 862 | } |
| 863 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 864 | // The pattern used here is that a user PICKs a specific application, |
| 865 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 866 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 867 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 868 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Winson Chung | c7da555 | 2011-08-10 15:28:45 -0700 | [diff] [blame] | 869 | if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 870 | final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1, |
| 871 | mPendingAddInfo); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 872 | if (isWorkspaceLocked()) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 873 | sPendingAddItem = args; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 874 | } else { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 875 | completeAdd(args); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 876 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 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 | 0007472 | 2013-10-11 17:46:09 -0700 | [diff] [blame] | 879 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 880 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 881 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 882 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 883 | mDragLayer.clearAnimatedView(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 884 | } |
| 885 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 886 | private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int |
| 887 | appWidgetId, ItemInfo info) { |
| 888 | PendingAddArguments args = new PendingAddArguments(); |
| 889 | args.requestCode = requestCode; |
| 890 | args.intent = data; |
| 891 | args.container = info.container; |
| 892 | args.screenId = info.screenId; |
| 893 | args.cellX = info.cellX; |
| 894 | args.cellY = info.cellY; |
| 895 | args.appWidgetId = appWidgetId; |
| 896 | return args; |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 901 | * |
| 902 | * @param screenId the screen id to check |
| 903 | * @return the new screen, or screenId if it exists |
| 904 | */ |
| 905 | private long ensurePendingDropLayoutExists(long screenId) { |
| 906 | CellLayout dropLayout = |
| 907 | (CellLayout) mWorkspace.getScreenWithId(screenId); |
| 908 | if (dropLayout == null) { |
| 909 | // it's possible that the add screen was removed because it was |
| 910 | // empty and a re-bind occurred |
| 911 | mWorkspace.addExtraEmptyScreen(); |
| 912 | return mWorkspace.commitExtraEmptyScreen(); |
| 913 | } else { |
| 914 | return screenId; |
| 915 | } |
| 916 | } |
| 917 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 918 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 919 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 920 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 921 | Runnable onCompleteRunnable = null; |
| 922 | int animationType = 0; |
| 923 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 924 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 925 | if (resultCode == RESULT_OK) { |
| 926 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 927 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 928 | mPendingAddWidgetInfo); |
| 929 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 930 | onCompleteRunnable = new Runnable() { |
| 931 | @Override |
| 932 | public void run() { |
| 933 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 934 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 935 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 936 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 937 | } |
| 938 | }; |
| 939 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 940 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 941 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 942 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 943 | if (mDragLayer.getAnimatedView() != null) { |
| 944 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 945 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 946 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 947 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 948 | // The animated view may be null in the case of a rotation during widget configuration |
| 949 | onCompleteRunnable.run(); |
| 950 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 954 | protected void onStop() { |
| 955 | super.onStop(); |
| 956 | FirstFrameAnimatorHelper.setIsVisible(false); |
| 957 | } |
| 958 | |
| 959 | @Override |
| 960 | protected void onStart() { |
| 961 | super.onStart(); |
| 962 | FirstFrameAnimatorHelper.setIsVisible(true); |
| 963 | } |
| 964 | |
| 965 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 966 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 967 | long startTime = 0; |
| 968 | if (DEBUG_RESUME_TIME) { |
| 969 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 970 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 971 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 972 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 973 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 974 | // Restore the previous launcher state |
| 975 | if (mOnResumeState == State.WORKSPACE) { |
| 976 | showWorkspace(false); |
| 977 | } else if (mOnResumeState == State.APPS_CUSTOMIZE) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 978 | showAllApps(false, mAppsCustomizeContent.getContentType(), false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 979 | } |
| 980 | mOnResumeState = State.NONE; |
| 981 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 982 | // Background was set to gradient in onPause(), restore to black if in all apps. |
| 983 | setWorkspaceBackground(mState == State.WORKSPACE); |
| 984 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 985 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 986 | if (mRestoring || mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 987 | setWorkspaceLoading(true); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 988 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 989 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 990 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 991 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 992 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 993 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 994 | // execute them here |
| 995 | long startTimeCallbacks = 0; |
| 996 | if (DEBUG_RESUME_TIME) { |
| 997 | startTimeCallbacks = System.currentTimeMillis(); |
| 998 | } |
| 999 | |
| 1000 | if (mAppsCustomizeContent != null) { |
| 1001 | mAppsCustomizeContent.setBulkBind(true); |
| 1002 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1003 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 1004 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1005 | } |
| 1006 | if (mAppsCustomizeContent != null) { |
| 1007 | mAppsCustomizeContent.setBulkBind(false); |
| 1008 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1009 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1010 | if (DEBUG_RESUME_TIME) { |
| 1011 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 1012 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 1013 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1014 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 1015 | if (mOnResumeCallbacks.size() > 0) { |
| 1016 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 1017 | mOnResumeCallbacks.get(i).run(); |
| 1018 | } |
| 1019 | mOnResumeCallbacks.clear(); |
| 1020 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1021 | |
| 1022 | // Reset the pressed state of icons that were locked in the press state while activities |
| 1023 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1024 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1025 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1026 | mWaitingForResume.setStayPressed(false); |
| 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(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1058 | |
| 1059 | PackageInstallerCompat.getInstance(this).onResume(); |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1062 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1063 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1064 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1065 | InstallShortcutReceiver.enableInstallQueue(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1066 | PackageInstallerCompat.getInstance(this).onPause(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1067 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1068 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1069 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1070 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1071 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1072 | |
| 1073 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1074 | // debounce excess onHide calls. |
| 1075 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1076 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1077 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1078 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1079 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1080 | QSBScroller mQsbScroller = new QSBScroller() { |
| 1081 | int scrollY = 0; |
| 1082 | |
| 1083 | @Override |
| 1084 | public void setScrollY(int scroll) { |
| 1085 | scrollY = scroll; |
| 1086 | |
| 1087 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
| 1088 | mSearchDropTargetBar.setTranslationY(- scrollY); |
Mark Brophy | d7dc681 | 2013-09-20 17:27:32 +0100 | [diff] [blame] | 1089 | getQsbBar().setTranslationY(-scrollY); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1090 | } |
| 1091 | } |
| 1092 | }; |
| 1093 | |
| 1094 | public void resetQSBScroll() { |
| 1095 | mSearchDropTargetBar.animate().translationY(0).start(); |
Mark Brophy | d7dc681 | 2013-09-20 17:27:32 +0100 | [diff] [blame] | 1096 | getQsbBar().animate().translationY(0).start(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1100 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1101 | // by a onResume or by scrolling otherwise. |
| 1102 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1103 | |
| 1104 | // Custom content is completely hidden |
| 1105 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1106 | |
| 1107 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1108 | public void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1109 | |
| 1110 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1111 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1114 | protected boolean hasSettings() { |
| 1115 | return false; |
| 1116 | } |
| 1117 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1118 | public interface QSBScroller { |
| 1119 | public void setScrollY(int scrollY); |
| 1120 | } |
| 1121 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 1122 | public QSBScroller addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1123 | CustomContentCallbacks callbacks, String description) { |
| 1124 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1125 | return mQsbScroller; |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1128 | // The custom content needs to offset its content to account for the QSB |
| 1129 | public int getTopOffsetForCustomContent() { |
| 1130 | return mWorkspace.getPaddingTop(); |
| 1131 | } |
| 1132 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1133 | @Override |
| 1134 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1135 | // Flag the loader to stop early before switching |
| 1136 | mModel.stopLoader(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1137 | if (mAppsCustomizeContent != null) { |
| 1138 | mAppsCustomizeContent.surrender(); |
| 1139 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1140 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1141 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1142 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1143 | // 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] | 1144 | @Override |
| 1145 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1146 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1147 | mHasFocus = hasFocus; |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1148 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1149 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1150 | private boolean acceptFilter() { |
| 1151 | final InputMethodManager inputManager = (InputMethodManager) |
| 1152 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1153 | return !inputManager.isFullscreenMode(); |
| 1154 | } |
| 1155 | |
| 1156 | @Override |
| 1157 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1158 | final int uniChar = event.getUnicodeChar(); |
| 1159 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1160 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1161 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1162 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1163 | keyCode, event); |
| 1164 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1165 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1166 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1167 | // showSearchDialog() |
| 1168 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1169 | // onSearchRequested() will be called for every keystroke, |
| 1170 | // but it is idempotent, so it's fine. |
| 1171 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1175 | // Eat the long press event so the keyboard doesn't come up. |
| 1176 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1177 | return true; |
| 1178 | } |
| 1179 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1180 | return handled; |
| 1181 | } |
| 1182 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1183 | private String getTypedText() { |
| 1184 | return mDefaultKeySsb.toString(); |
| 1185 | } |
| 1186 | |
| 1187 | private void clearTypedText() { |
| 1188 | mDefaultKeySsb.clear(); |
| 1189 | mDefaultKeySsb.clearSpans(); |
| 1190 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1191 | } |
| 1192 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1193 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1194 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1195 | * State |
| 1196 | */ |
| 1197 | private static State intToState(int stateOrdinal) { |
| 1198 | State state = State.WORKSPACE; |
| 1199 | final State[] stateValues = State.values(); |
| 1200 | for (int i = 0; i < stateValues.length; i++) { |
| 1201 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1202 | state = stateValues[i]; |
| 1203 | break; |
| 1204 | } |
| 1205 | } |
| 1206 | return state; |
| 1207 | } |
| 1208 | |
| 1209 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1210 | * Restores the previous state, if it exists. |
| 1211 | * |
| 1212 | * @param savedState The previous state. |
| 1213 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1214 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1215 | private void restoreState(Bundle savedState) { |
| 1216 | if (savedState == null) { |
| 1217 | return; |
| 1218 | } |
| 1219 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1220 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1221 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1222 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1225 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1226 | PagedView.INVALID_RESTORE_PAGE); |
| 1227 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1228 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1231 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1232 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1233 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1234 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1235 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1236 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1237 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1238 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1239 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1240 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 1241 | mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1242 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1243 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1244 | mRestoring = true; |
| 1245 | } |
| 1246 | |
| 1247 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1248 | if (renameFolder) { |
| 1249 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1250 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1251 | mRestoring = true; |
| 1252 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1253 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1254 | // Restore the AppsCustomize tab |
| 1255 | if (mAppsCustomizeTabHost != null) { |
| 1256 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1257 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1258 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1259 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1260 | mAppsCustomizeContent.loadAssociatedPages( |
| 1261 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1264 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1265 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1266 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1267 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1268 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | /** |
| 1272 | * Finds all the views we need and configure them properly. |
| 1273 | */ |
| 1274 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1275 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1276 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1277 | mLauncherView = findViewById(R.id.launcher); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1278 | mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1279 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1280 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1281 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1282 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1283 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1284 | mLauncherView.setSystemUiVisibility( |
| 1285 | 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] | 1286 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1287 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1288 | // Setup the drag layer |
| 1289 | mDragLayer.setup(this, dragController); |
| 1290 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1291 | // Setup the hotseat |
| 1292 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1293 | if (mHotseat != null) { |
| 1294 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1295 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1298 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1299 | View widgetButton = findViewById(R.id.widget_button); |
| 1300 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1301 | @Override |
| 1302 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1303 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1304 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1305 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1306 | } |
| 1307 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1308 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1309 | |
| 1310 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1311 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1312 | @Override |
| 1313 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1314 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1315 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1316 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1317 | } |
| 1318 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1319 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1320 | |
| 1321 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1322 | if (hasSettings()) { |
| 1323 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1324 | @Override |
| 1325 | public void onClick(View arg0) { |
| 1326 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1327 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1328 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1329 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1330 | }); |
| 1331 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1332 | } else { |
| 1333 | settingsButton.setVisibility(View.GONE); |
| 1334 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams(); |
| 1335 | lp.gravity = Gravity.END | Gravity.TOP; |
| 1336 | widgetButton.requestLayout(); |
| 1337 | } |
| 1338 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1339 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1340 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1341 | // Setup the workspace |
| 1342 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1343 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1344 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1345 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1346 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1347 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1348 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1349 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1350 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1351 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1352 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1353 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1354 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1355 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1356 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1357 | // 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] | 1358 | dragController.setDragScoller(mWorkspace); |
| 1359 | dragController.setScrollView(mDragLayer); |
| 1360 | dragController.setMoveTarget(mWorkspace); |
| 1361 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1362 | if (mSearchDropTargetBar != null) { |
| 1363 | mSearchDropTargetBar.setup(this, dragController); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1364 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1365 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1366 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1367 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1368 | mWeightWatcher = new WeightWatcher(this); |
| 1369 | mWeightWatcher.setAlpha(0.5f); |
| 1370 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1371 | new FrameLayout.LayoutParams( |
| 1372 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1373 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1374 | Gravity.BOTTOM) |
| 1375 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1376 | |
| 1377 | boolean show = shouldShowWeightWatcher(); |
| 1378 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1379 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1383 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1384 | */ |
| 1385 | public void setAllAppsButton(View allAppsButton) { |
| 1386 | mAllAppsButton = allAppsButton; |
| 1387 | } |
| 1388 | |
| 1389 | public View getAllAppsButton() { |
| 1390 | return mAllAppsButton; |
| 1391 | } |
| 1392 | |
| 1393 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1394 | * Creates a view representing a shortcut. |
| 1395 | * |
| 1396 | * @param info The data structure describing the shortcut. |
| 1397 | * |
| 1398 | * @return A View inflated from R.layout.application. |
| 1399 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1400 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1401 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1402 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1407 | * |
| 1408 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1409 | * @param parent The group the shortcut belongs to. |
| 1410 | * @param info The data structure describing the shortcut. |
| 1411 | * |
| 1412 | * @return A View inflated from layoutResId. |
| 1413 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1414 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1415 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 1416 | favorite.applyFromShortcutInfo(info, mIconCache, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1417 | favorite.setOnClickListener(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1418 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1419 | return favorite; |
| 1420 | } |
| 1421 | |
| 1422 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1423 | * Add a shortcut to the workspace. |
| 1424 | * |
| 1425 | * @param data The intent describing the shortcut. |
| 1426 | * @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] | 1427 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1428 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1429 | int cellY) { |
| 1430 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1431 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1432 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1433 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1434 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1435 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1436 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1437 | if (info == null) { |
| 1438 | return; |
| 1439 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1440 | final View view = createShortcut(info); |
| 1441 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1442 | // First we check if we already know the exact location where we want to add this item. |
| 1443 | if (cellX >= 0 && cellY >= 0) { |
| 1444 | cellXY[0] = cellX; |
| 1445 | cellXY[1] = cellY; |
| 1446 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1447 | |
| 1448 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1449 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1450 | true, null,null)) { |
| 1451 | return; |
| 1452 | } |
| 1453 | DragObject dragObject = new DragObject(); |
| 1454 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1455 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1456 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1457 | return; |
| 1458 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1459 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1460 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1461 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1462 | foundCellSpan = (result != null); |
| 1463 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1464 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1468 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1469 | return; |
| 1470 | } |
| 1471 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1472 | 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] | 1473 | |
| 1474 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1475 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1476 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1477 | } |
| 1478 | } |
| 1479 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1480 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1481 | int minHeight) { |
| 1482 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1483 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1484 | // to ensure that it gets the full amount of space that it has requested |
| 1485 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1486 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1487 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1490 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1491 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1494 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1495 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1498 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1499 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1502 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1503 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1504 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1505 | } |
| 1506 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1507 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1508 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1509 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1510 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1511 | * @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] | 1512 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1513 | private void completeAddAppWidget(final int appWidgetId, long container, long screenId, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1514 | AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1515 | if (appWidgetInfo == null) { |
| 1516 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1517 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1518 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1519 | // Calculate the grid spans needed to fit this widget |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1520 | CellLayout layout = getCellLayout(container, screenId); |
Adam Cohen | 0935386 | 2011-07-14 16:10:03 -0700 | [diff] [blame] | 1521 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1522 | int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo); |
| 1523 | int[] spanXY = getSpanForWidget(this, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1524 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1525 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1526 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1527 | // if we are placing widgets on a "spring-loaded" screen |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1528 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1529 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1530 | int[] finalSpan = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1531 | boolean foundCellSpan = false; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1532 | if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { |
| 1533 | cellXY[0] = mPendingAddInfo.cellX; |
| 1534 | cellXY[1] = mPendingAddInfo.cellY; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1535 | spanXY[0] = mPendingAddInfo.spanX; |
| 1536 | spanXY[1] = mPendingAddInfo.spanY; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1537 | foundCellSpan = true; |
| 1538 | } else if (touchXY != null) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1539 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1540 | int[] result = layout.findNearestVacantArea( |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1541 | touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], |
| 1542 | spanXY[1], cellXY, finalSpan); |
| 1543 | spanXY[0] = finalSpan[0]; |
| 1544 | spanXY[1] = finalSpan[1]; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1545 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1546 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1547 | foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1550 | if (!foundCellSpan) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1551 | if (appWidgetId != -1) { |
| 1552 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 1553 | // to the caller... |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1554 | new AsyncTask<Void, Void, Void>() { |
| 1555 | public Void doInBackground(Void ... args) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1556 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1557 | return null; |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1558 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1559 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1560 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1561 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1562 | return; |
| 1563 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1564 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1565 | // Build Launcher-specific widget info and save to database |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 1566 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, |
| 1567 | appWidgetInfo.provider); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1568 | launcherInfo.spanX = spanXY[0]; |
| 1569 | launcherInfo.spanY = spanXY[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1570 | launcherInfo.minSpanX = mPendingAddInfo.minSpanX; |
| 1571 | launcherInfo.minSpanY = mPendingAddInfo.minSpanY; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1572 | launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1573 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1574 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1575 | container, screenId, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1576 | |
| 1577 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1578 | if (hostView == null) { |
| 1579 | // Perform actual inflation because we're live |
| 1580 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1581 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1582 | } else { |
| 1583 | // The AppWidgetHostView has already been inflated and instantiated |
| 1584 | launcherInfo.hostView = hostView; |
| 1585 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1586 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1587 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1588 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1589 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1590 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1591 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1592 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1593 | |
| 1594 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1595 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1596 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1597 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1598 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1599 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1600 | @Override |
| 1601 | public void onReceive(Context context, Intent intent) { |
| 1602 | final String action = intent.getAction(); |
| 1603 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1604 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1605 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1606 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1607 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1608 | // 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] | 1609 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1610 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1611 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1612 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1613 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1614 | mUserPresent = true; |
| 1615 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1616 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1617 | mModel.resetLoadedState(false, true); |
| 1618 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1619 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1620 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1621 | mModel.resetLoadedState(false, true); |
| 1622 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1623 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1624 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1625 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1626 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1627 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | }; |
| 1631 | |
| 1632 | @Override |
| 1633 | public void onAttachedToWindow() { |
| 1634 | super.onAttachedToWindow(); |
| 1635 | |
| 1636 | // Listen for broadcasts related to user-presence |
| 1637 | final IntentFilter filter = new IntentFilter(); |
| 1638 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1639 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1640 | // For handling managed profiles |
| 1641 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1642 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1643 | if (ENABLE_DEBUG_INTENTS) { |
| 1644 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1645 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1646 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1647 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1648 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1649 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1650 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1651 | mVisible = true; |
| 1652 | } |
| 1653 | |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1654 | /** |
| 1655 | * Sets up transparent navigation and status bars in LMP. |
| 1656 | * This method is a no-op for other platform versions. |
| 1657 | */ |
| 1658 | @TargetApi(19) |
| 1659 | private void setupTransparentSystemBarsForLmp() { |
| 1660 | // TODO(sansid): use the APIs directly when compiling against L sdk. |
| 1661 | // Currently we use reflection to access the flags and the API to set the transparency |
| 1662 | // on the System bars. |
| 1663 | if (Utilities.isLmp()) { |
| 1664 | try { |
| 1665 | getWindow().getAttributes().systemUiVisibility |= |
| 1666 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1667 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1668 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1669 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
| 1670 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
| 1671 | Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( |
| 1672 | "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); |
| 1673 | getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); |
| 1674 | |
| 1675 | Method setStatusBarColorMethod = |
| 1676 | Window.class.getDeclaredMethod("setStatusBarColor", int.class); |
| 1677 | Method setNavigationBarColorMethod = |
| 1678 | Window.class.getDeclaredMethod("setNavigationBarColor", int.class); |
| 1679 | setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1680 | setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1681 | } catch (NoSuchFieldException e) { |
| 1682 | Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); |
| 1683 | } catch (NoSuchMethodException ex) { |
| 1684 | Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); |
| 1685 | } catch (IllegalAccessException e) { |
| 1686 | Log.w(TAG, "IllegalAccessException while setting up transparent bars"); |
| 1687 | } catch (IllegalArgumentException e) { |
| 1688 | Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); |
| 1689 | } catch (InvocationTargetException e) { |
| 1690 | Log.w(TAG, "InvocationTargetException while setting up transparent bars"); |
| 1691 | } finally {} |
| 1692 | } |
| 1693 | } |
| 1694 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1695 | @Override |
| 1696 | public void onDetachedFromWindow() { |
| 1697 | super.onDetachedFromWindow(); |
| 1698 | mVisible = false; |
| 1699 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1700 | if (mAttached) { |
| 1701 | unregisterReceiver(mReceiver); |
| 1702 | mAttached = false; |
| 1703 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1704 | updateRunning(); |
| 1705 | } |
| 1706 | |
| 1707 | public void onWindowVisibilityChanged(int visibility) { |
| 1708 | mVisible = visibility == View.VISIBLE; |
| 1709 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1710 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1711 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1712 | // is a more appropriate event to handle |
| 1713 | if (mVisible) { |
| 1714 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1715 | if (!mWorkspaceLoading) { |
| 1716 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1717 | // We want to let Launcher draw itself at least once before we force it to build |
| 1718 | // 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] | 1719 | // apps is nice and speedy. |
| 1720 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1721 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1722 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1723 | if (mStarted) return; |
| 1724 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1725 | // We delay the layer building a bit in order to give |
| 1726 | // other message processing a time to run. In particular |
| 1727 | // this avoids a delay in hiding the IME if it was |
| 1728 | // currently shown, because doing that may involve |
| 1729 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1730 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1731 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1732 | mWorkspace.post(new Runnable() { |
| 1733 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1734 | if (mWorkspace != null && |
| 1735 | mWorkspace.getViewTreeObserver() != null) { |
| 1736 | mWorkspace.getViewTreeObserver(). |
| 1737 | removeOnDrawListener(listener); |
| 1738 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1739 | } |
| 1740 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1741 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1742 | } |
| 1743 | }); |
| 1744 | } |
| 1745 | clearTypedText(); |
| 1746 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | private void sendAdvanceMessage(long delay) { |
| 1750 | mHandler.removeMessages(ADVANCE_MSG); |
| 1751 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1752 | mHandler.sendMessageDelayed(msg, delay); |
| 1753 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1754 | } |
| 1755 | |
| 1756 | private void updateRunning() { |
| 1757 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1758 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1759 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1760 | if (autoAdvanceRunning) { |
| 1761 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1762 | sendAdvanceMessage(delay); |
| 1763 | } else { |
| 1764 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1765 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1766 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1767 | } |
| 1768 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1769 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | private final Handler mHandler = new Handler() { |
| 1775 | @Override |
| 1776 | public void handleMessage(Message msg) { |
| 1777 | if (msg.what == ADVANCE_MSG) { |
| 1778 | int i = 0; |
| 1779 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1780 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1781 | final int delay = mAdvanceStagger * i; |
| 1782 | if (v instanceof Advanceable) { |
| 1783 | postDelayed(new Runnable() { |
| 1784 | public void run() { |
| 1785 | ((Advanceable) v).advance(); |
| 1786 | } |
| 1787 | }, delay); |
| 1788 | } |
| 1789 | i++; |
| 1790 | } |
| 1791 | sendAdvanceMessage(mAdvanceInterval); |
| 1792 | } |
| 1793 | } |
| 1794 | }; |
| 1795 | |
| 1796 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1797 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1798 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1799 | if (v instanceof Advanceable) { |
| 1800 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1801 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1802 | updateRunning(); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | void removeWidgetToAutoAdvance(View hostView) { |
| 1807 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1808 | mWidgetsToAdvance.remove(hostView); |
| 1809 | updateRunning(); |
| 1810 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1813 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1814 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1815 | launcherInfo.hostView = null; |
| 1816 | } |
| 1817 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1818 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1819 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1820 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1823 | public DragLayer getDragLayer() { |
| 1824 | return mDragLayer; |
| 1825 | } |
| 1826 | |
| 1827 | public Workspace getWorkspace() { |
| 1828 | return mWorkspace; |
| 1829 | } |
| 1830 | |
| 1831 | public Hotseat getHotseat() { |
| 1832 | return mHotseat; |
| 1833 | } |
| 1834 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1835 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1836 | return mOverviewPanel; |
| 1837 | } |
| 1838 | |
| 1839 | public SearchDropTargetBar getSearchBar() { |
| 1840 | return mSearchDropTargetBar; |
| 1841 | } |
| 1842 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1843 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1844 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1845 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1846 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1847 | public LauncherModel getModel() { |
| 1848 | return mModel; |
| 1849 | } |
| 1850 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1851 | protected SharedPreferences getSharedPrefs() { |
| 1852 | return mSharedPrefs; |
| 1853 | } |
| 1854 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1855 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1856 | getWindow().closeAllPanels(); |
| 1857 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1858 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1859 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1860 | } |
| 1861 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1862 | @Override |
| 1863 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1864 | long startTime = 0; |
| 1865 | if (DEBUG_RESUME_TIME) { |
| 1866 | startTime = System.currentTimeMillis(); |
| 1867 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1868 | super.onNewIntent(intent); |
| 1869 | |
| 1870 | // Close the menu |
| 1871 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1872 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1873 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1874 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1875 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1876 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1877 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1878 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1879 | if (mWorkspace == null) { |
| 1880 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1881 | return; |
| 1882 | } |
| 1883 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1884 | // In all these cases, only animate if we're already on home |
| 1885 | mWorkspace.exitWidgetResizeMode(); |
| 1886 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1887 | openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1888 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1889 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1890 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1891 | closeFolder(); |
| 1892 | exitSpringLoadedDragMode(); |
| 1893 | |
| 1894 | // If we are already on home, then just animate back to the workspace, |
| 1895 | // otherwise, just wait until onResume to set the state back to Workspace |
| 1896 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1897 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1898 | } else { |
| 1899 | mOnResumeState = State.WORKSPACE; |
| 1900 | } |
| 1901 | |
| 1902 | final View v = getWindow().peekDecorView(); |
| 1903 | if (v != null && v.getWindowToken() != null) { |
| 1904 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1905 | INPUT_METHOD_SERVICE); |
| 1906 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 1907 | } |
| 1908 | |
| 1909 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 1910 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1911 | mAppsCustomizeTabHost.reset(); |
| 1912 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1913 | |
| 1914 | onHomeIntent(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1915 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1916 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1917 | if (DEBUG_RESUME_TIME) { |
| 1918 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 1919 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1920 | } |
| 1921 | |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1922 | /** |
| 1923 | * Override point for subclasses to prevent movement to the default screen when the home |
| 1924 | * button is pressed. Used (for example) in GEL, to prevent movement during a search. |
| 1925 | */ |
| 1926 | protected boolean shouldMoveToDefaultScreenOnHomeIntent() { |
| 1927 | return true; |
| 1928 | } |
| 1929 | |
| 1930 | /** |
| 1931 | * Override point for subclasses to provide custom behaviour for when a home intent is fired. |
| 1932 | */ |
| 1933 | protected void onHomeIntent() { |
| 1934 | // Do nothing |
| 1935 | } |
| 1936 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1937 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1938 | public void onRestoreInstanceState(Bundle state) { |
| 1939 | super.onRestoreInstanceState(state); |
| 1940 | for (int page: mSynchronouslyBoundPages) { |
| 1941 | mWorkspace.restoreInstanceStateForChild(page); |
| 1942 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | @Override |
| 1946 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1947 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 1948 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1949 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1950 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1951 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1952 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1953 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 1954 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 1955 | // this state is reflected. |
| 1956 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1957 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1958 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1959 | mWaitingForResult) { |
| 1960 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1961 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1962 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 1963 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1964 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 1965 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 1966 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1967 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | if (mFolderInfo != null && mWaitingForResult) { |
| 1971 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1972 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1973 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1974 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1975 | // Save the current AppsCustomize tab |
| 1976 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 1977 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 1978 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1979 | if (currentTabTag != null) { |
| 1980 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 1981 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1982 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 1983 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1984 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1985 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | @Override |
| 1989 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1990 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1991 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1992 | // Remove all pending runnables |
| 1993 | mHandler.removeMessages(ADVANCE_MSG); |
| 1994 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 1995 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1996 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1997 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 1998 | LauncherAppState app = (LauncherAppState.getInstance()); |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1999 | mModel.stopLoader(); |
| 2000 | app.setLauncher(null); |
| 2001 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2002 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2003 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2004 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2005 | 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] | 2006 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2007 | mAppWidgetHost = null; |
| 2008 | |
| 2009 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2010 | |
| 2011 | TextKeyListener.getInstance().release(); |
| 2012 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 2013 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 2014 | // to prevent leaking Launcher activities on orientation change. |
| 2015 | if (mModel != null) { |
| 2016 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 2017 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2018 | |
| 2019 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2020 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2021 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 2022 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2023 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 2024 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2025 | mWorkspace = null; |
| 2026 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 2027 | |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 2028 | PackageInstallerCompat.getInstance(this).onStop(); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2029 | LauncherAnimUtils.onDestroyActivity(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2030 | } |
| 2031 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2032 | public DragController getDragController() { |
| 2033 | return mDragController; |
| 2034 | } |
| 2035 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2036 | @Override |
| 2037 | public void startActivityForResult(Intent intent, int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2038 | if (requestCode >= 0) { |
| 2039 | setWaitingForResult(true); |
| 2040 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2041 | super.startActivityForResult(intent, requestCode); |
| 2042 | } |
| 2043 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2044 | /** |
| 2045 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2046 | * argument for {@link #startSearch} to true. |
| 2047 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2048 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2049 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2050 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2051 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2052 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2053 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2054 | if (initialQuery == null) { |
| 2055 | // Use any text typed in the launcher as the initial query |
| 2056 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2057 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2058 | if (appSearchData == null) { |
| 2059 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2060 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2061 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2062 | Rect sourceBounds = new Rect(); |
| 2063 | if (mSearchDropTargetBar != null) { |
| 2064 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2065 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2066 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2067 | boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2068 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2069 | if (clearTextImmediately) { |
| 2070 | clearTypedText(); |
| 2071 | } |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2072 | } |
| 2073 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2074 | /** |
| 2075 | * Start a text search. |
| 2076 | * |
| 2077 | * @return {@code true} if the search will start immediately, so any further keypresses |
| 2078 | * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue |
| 2079 | * to buffer keypresses. |
| 2080 | */ |
| 2081 | public boolean startSearch(String initialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2082 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2083 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2084 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2085 | return false; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | /** |
| 2089 | * Starts the global search activity. This code is a copied from SearchManager |
| 2090 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2091 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2092 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2093 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2094 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2095 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2096 | if (globalSearchActivity == null) { |
| 2097 | Log.w(TAG, "No global search activity found."); |
| 2098 | return; |
| 2099 | } |
| 2100 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2101 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2102 | intent.setComponent(globalSearchActivity); |
| 2103 | // Make sure that we have a Bundle to put source in |
| 2104 | if (appSearchData == null) { |
| 2105 | appSearchData = new Bundle(); |
| 2106 | } else { |
| 2107 | appSearchData = new Bundle(appSearchData); |
| 2108 | } |
| 2109 | // Set source to package name of app that starts global search, if not set already. |
| 2110 | if (!appSearchData.containsKey("source")) { |
| 2111 | appSearchData.putString("source", getPackageName()); |
| 2112 | } |
| 2113 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2114 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2115 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2116 | } |
| 2117 | if (selectInitialQuery) { |
| 2118 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2119 | } |
| 2120 | intent.setSourceBounds(sourceBounds); |
| 2121 | try { |
| 2122 | startActivity(intent); |
| 2123 | } catch (ActivityNotFoundException ex) { |
| 2124 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2125 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2126 | } |
| 2127 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2128 | public boolean isOnCustomContent() { |
| 2129 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2130 | } |
| 2131 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2132 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2133 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2134 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2135 | if (!isOnCustomContent()) { |
| 2136 | // Close any open folders |
| 2137 | closeFolder(); |
| 2138 | // Stop resizing any widgets |
| 2139 | mWorkspace.exitWidgetResizeMode(); |
| 2140 | if (!mWorkspace.isInOverviewMode()) { |
| 2141 | // Show the overview mode |
| 2142 | showOverviewMode(true); |
| 2143 | } else { |
| 2144 | showWorkspace(true); |
| 2145 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2146 | } |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2147 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2148 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2149 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2150 | @Override |
| 2151 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2152 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2153 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2154 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2157 | public boolean isWorkspaceLocked() { |
| 2158 | return mWorkspaceLoading || mWaitingForResult; |
| 2159 | } |
| 2160 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2161 | public boolean isWorkspaceLoading() { |
| 2162 | return mWorkspaceLoading; |
| 2163 | } |
| 2164 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2165 | private void setWorkspaceLoading(boolean value) { |
| 2166 | boolean isLocked = isWorkspaceLocked(); |
| 2167 | mWorkspaceLoading = value; |
| 2168 | if (isLocked != isWorkspaceLocked()) { |
| 2169 | onWorkspaceLockedChanged(); |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | private void setWaitingForResult(boolean value) { |
| 2174 | boolean isLocked = isWorkspaceLocked(); |
| 2175 | mWaitingForResult = value; |
| 2176 | if (isLocked != isWorkspaceLocked()) { |
| 2177 | onWorkspaceLockedChanged(); |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | protected void onWorkspaceLockedChanged() { } |
| 2182 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2183 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2184 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2185 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2186 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2187 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2188 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2189 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2190 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2191 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2192 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2193 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) { |
| 2194 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2195 | } |
| 2196 | |
| 2197 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2198 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int |
| 2199 | delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2200 | if (appWidgetInfo.configure != null) { |
| 2201 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2202 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2203 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2204 | // Launch over to configure widget, if needed |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2205 | mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this, |
| 2206 | mAppWidgetHost, REQUEST_CREATE_APPWIDGET); |
| 2207 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2208 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2209 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2210 | Runnable onComplete = new Runnable() { |
| 2211 | @Override |
| 2212 | public void run() { |
| 2213 | // Exit spring loaded mode if necessary after adding the widget |
| 2214 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2215 | null); |
| 2216 | } |
| 2217 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2218 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2219 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2220 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2221 | } |
| 2222 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2223 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2224 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2225 | // Close any folders that may be open. |
| 2226 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2227 | mWorkspace.moveToCustomContentScreen(animate); |
| 2228 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2229 | /** |
| 2230 | * Process a shortcut drop. |
| 2231 | * |
| 2232 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2233 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2234 | * @param cell The cell it should be added to, optional |
| 2235 | * @param position The location on the screen where it was dropped, optional |
| 2236 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2237 | void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2238 | int[] cell, int[] loc) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2239 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2240 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2241 | mPendingAddInfo.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2242 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2243 | |
| 2244 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2245 | mPendingAddInfo.cellX = cell[0]; |
| 2246 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2247 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2248 | |
| 2249 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2250 | createShortcutIntent.setComponent(componentName); |
| 2251 | processShortcut(createShortcutIntent); |
| 2252 | } |
| 2253 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2254 | /** |
| 2255 | * Process a widget drop. |
| 2256 | * |
| 2257 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2258 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2259 | * @param cell The cell it should be added to, optional |
| 2260 | * @param position The location on the screen where it was dropped, optional |
| 2261 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2262 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2263 | int[] cell, int[] span, int[] loc) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2264 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2265 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2266 | mPendingAddInfo.screenId = info.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2267 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2268 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2269 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2270 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2271 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2272 | mPendingAddInfo.cellX = cell[0]; |
| 2273 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2274 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2275 | if (span != null) { |
| 2276 | mPendingAddInfo.spanX = span[0]; |
| 2277 | mPendingAddInfo.spanY = span[1]; |
| 2278 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2279 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2280 | AppWidgetHostView hostView = info.boundWidget; |
| 2281 | int appWidgetId; |
| 2282 | if (hostView != null) { |
| 2283 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2284 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2285 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2286 | // In this case, we either need to start an activity to get permission to bind |
| 2287 | // 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] | 2288 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2289 | Bundle options = info.bindOptions; |
| 2290 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2291 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2292 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2293 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2294 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2295 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2296 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2297 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2298 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2299 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2300 | mAppWidgetManager.getUser(mPendingAddWidgetInfo) |
| 2301 | .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2302 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2303 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2304 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2305 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2306 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2309 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2310 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2311 | } |
| 2312 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2313 | void processWallpaper(Intent intent) { |
| 2314 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2315 | } |
| 2316 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2317 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2318 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2319 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2320 | folderInfo.title = getText(R.string.folder_name); |
| 2321 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2322 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2323 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2324 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2325 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2326 | |
| 2327 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2328 | FolderIcon newFolder = |
| 2329 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2330 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2331 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2332 | // Force measure the new folder icon |
| 2333 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2334 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2335 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2336 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2337 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2338 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2339 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2340 | } |
| 2341 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2342 | protected ComponentName getWallpaperPickerComponent() { |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2343 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2344 | } |
| 2345 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2346 | /** |
| 2347 | * Registers various content observers. The current implementation registers |
| 2348 | * only a favorites observer to keep track of the favorites applications. |
| 2349 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2350 | private void registerContentObservers() { |
| 2351 | ContentResolver resolver = getContentResolver(); |
| 2352 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2353 | true, mWidgetObserver); |
| 2354 | } |
| 2355 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2356 | @Override |
| 2357 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2358 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2359 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2360 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2361 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2362 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 2363 | if (isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2364 | dumpState(); |
| 2365 | return true; |
| 2366 | } |
| 2367 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2368 | } |
| 2369 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2370 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2371 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2372 | return true; |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | return super.dispatchKeyEvent(event); |
| 2377 | } |
| 2378 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2379 | @Override |
| 2380 | public void onBackPressed() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2381 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2382 | if (mAppsCustomizeContent.getContentType() == |
| 2383 | AppsCustomizePagedView.ContentType.Applications) { |
| 2384 | showWorkspace(true); |
| 2385 | } else { |
| 2386 | showOverviewMode(true); |
| 2387 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2388 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2389 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2390 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2391 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2392 | if (openFolder.isEditingName()) { |
| 2393 | openFolder.dismissEditingName(); |
| 2394 | } else { |
| 2395 | closeFolder(); |
| 2396 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2397 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2398 | mWorkspace.exitWidgetResizeMode(); |
| 2399 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2400 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2401 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2402 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2405 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2406 | * Re-listen when widgets are reset. |
| 2407 | */ |
| 2408 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2409 | if (mAppWidgetHost != null) { |
| 2410 | mAppWidgetHost.startListening(); |
| 2411 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2415 | * Launches the intent referred by the clicked shortcut. |
| 2416 | * |
| 2417 | * @param v The view representing the clicked shortcut. |
| 2418 | */ |
| 2419 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2420 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2421 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2422 | if (v.getWindowToken() == null) { |
| 2423 | return; |
| 2424 | } |
| 2425 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2426 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2427 | return; |
| 2428 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2429 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2430 | if (v instanceof Workspace) { |
| 2431 | if (mWorkspace.isInOverviewMode()) { |
| 2432 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2433 | } |
| 2434 | return; |
| 2435 | } |
| 2436 | |
| 2437 | if (v instanceof CellLayout) { |
| 2438 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2439 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2440 | } |
| 2441 | } |
| 2442 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2443 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2444 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2445 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2446 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2447 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2448 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2449 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2450 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2451 | onClickAllAppsButton(v); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2452 | } else if (tag instanceof AppInfo) { |
| 2453 | startAppShortcutOrInfoActivity(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2454 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2455 | if (v instanceof PendingAppWidgetHostView) { |
| 2456 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2457 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2458 | } |
| 2459 | } |
| 2460 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2461 | public void onClickPagedViewIcon(View v) { |
| 2462 | startAppShortcutOrInfoActivity(v); |
| 2463 | } |
| 2464 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2465 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2466 | return false; |
| 2467 | } |
| 2468 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2469 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2470 | * Event handler for the app widget view which has not fully restored. |
| 2471 | */ |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2472 | public void onClickPendingWidget(final PendingAppWidgetHostView v) { |
| 2473 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2474 | if (v.isReadyForClickSetup()) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2475 | int widgetId = info.appWidgetId; |
| 2476 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
| 2477 | if (appWidgetInfo != null) { |
| 2478 | mPendingAddWidgetInfo = appWidgetInfo; |
| 2479 | mPendingAddInfo.copyFrom(info); |
| 2480 | mPendingAddWidgetId = widgetId; |
| 2481 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2482 | AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo, |
| 2483 | info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2484 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2485 | } else if (info.installProgress < 0) { |
| 2486 | // The install has not been queued |
| 2487 | final String packageName = info.providerName.getPackageName(); |
| 2488 | showBrokenAppInstallDialog(packageName, |
| 2489 | new DialogInterface.OnClickListener() { |
| 2490 | public void onClick(DialogInterface dialog, int id) { |
| 2491 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
| 2492 | } |
| 2493 | }); |
| 2494 | } else { |
| 2495 | // Download has started. |
| 2496 | final String packageName = info.providerName.getPackageName(); |
| 2497 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2502 | * Event handler for the search button |
| 2503 | * |
| 2504 | * @param v The view that was clicked. |
| 2505 | */ |
| 2506 | public void onClickSearchButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2507 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2508 | |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2509 | onSearchRequested(); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2513 | * Event handler for the voice button |
| 2514 | * |
| 2515 | * @param v The view that was clicked. |
| 2516 | */ |
| 2517 | public void onClickVoiceButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2518 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2519 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2520 | startVoice(); |
| 2521 | } |
| 2522 | |
| 2523 | public void startVoice() { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2524 | try { |
| 2525 | final SearchManager searchManager = |
| 2526 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2527 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 2528 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2529 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2530 | if (activityName != null) { |
| 2531 | intent.setPackage(activityName.getPackageName()); |
| 2532 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2533 | startActivity(null, intent, "onClickVoiceButton"); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2534 | } catch (ActivityNotFoundException e) { |
| 2535 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2536 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2537 | startActivitySafely(null, intent, "onClickVoiceButton"); |
| 2538 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2542 | * Event handler for the "grid" button that appears on the home screen, which |
| 2543 | * enters all apps mode. |
| 2544 | * |
| 2545 | * @param v The view that was clicked. |
| 2546 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2547 | protected void onClickAllAppsButton(View v) { |
| 2548 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2549 | if (isAllAppsVisible()) { |
| 2550 | showWorkspace(true); |
| 2551 | } else { |
| 2552 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2553 | } |
| 2554 | } |
| 2555 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2556 | private void showBrokenAppInstallDialog(final String packageName, |
| 2557 | DialogInterface.OnClickListener onSearchClickListener) { |
| 2558 | new AlertDialog.Builder(this) |
| 2559 | .setTitle(R.string.abandoned_promises_title) |
| 2560 | .setMessage(R.string.abandoned_promise_explanation) |
| 2561 | .setPositiveButton(R.string.abandoned_search, onSearchClickListener) |
| 2562 | .setNeutralButton(R.string.abandoned_clean_this, |
| 2563 | new DialogInterface.OnClickListener() { |
| 2564 | public void onClick(DialogInterface dialog, int id) { |
| 2565 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 2566 | mWorkspace.removeAbandonedPromise(packageName, user); |
| 2567 | } |
| 2568 | }) |
| 2569 | .create().show(); |
| 2570 | return; |
| 2571 | } |
| 2572 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2573 | /** |
| 2574 | * Event handler for an app shortcut click. |
| 2575 | * |
| 2576 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2577 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2578 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2579 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2580 | Object tag = v.getTag(); |
| 2581 | if (!(tag instanceof ShortcutInfo)) { |
| 2582 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2583 | } |
| 2584 | |
| 2585 | // Open shortcut |
| 2586 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
| 2587 | final Intent intent = shortcut.intent; |
| 2588 | |
| 2589 | // Check for special shortcuts |
| 2590 | if (intent.getComponent() != null) { |
| 2591 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2592 | |
| 2593 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2594 | MemoryDumpActivity.startDump(this); |
| 2595 | return; |
| 2596 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2597 | toggleShowWeightWatcher(); |
| 2598 | return; |
| 2599 | } |
| 2600 | } |
| 2601 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2602 | // Check for abandoned promise |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2603 | if ((v instanceof BubbleTextView) |
| 2604 | && shortcut.isPromise() |
| 2605 | && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2606 | showBrokenAppInstallDialog( |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2607 | shortcut.getTargetComponent().getPackageName(), |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2608 | new DialogInterface.OnClickListener() { |
| 2609 | public void onClick(DialogInterface dialog, int id) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2610 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2611 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2612 | }); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2613 | return; |
| 2614 | } |
| 2615 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2616 | // Start activities |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2617 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2618 | } |
| 2619 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2620 | private void startAppShortcutOrInfoActivity(View v) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2621 | Object tag = v.getTag(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2622 | final ShortcutInfo shortcut; |
| 2623 | final Intent intent; |
| 2624 | if (tag instanceof ShortcutInfo) { |
| 2625 | shortcut = (ShortcutInfo) tag; |
| 2626 | intent = shortcut.intent; |
| 2627 | int[] pos = new int[2]; |
| 2628 | v.getLocationOnScreen(pos); |
| 2629 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2630 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2631 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2632 | } else if (tag instanceof AppInfo) { |
| 2633 | shortcut = null; |
| 2634 | intent = ((AppInfo) tag).intent; |
| 2635 | } else { |
| 2636 | throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); |
| 2637 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2638 | |
| 2639 | boolean success = startActivitySafely(v, intent, tag); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2640 | mStats.recordLaunch(intent, shortcut); |
| 2641 | |
| 2642 | if (success && v instanceof BubbleTextView) { |
| 2643 | mWaitingForResume = (BubbleTextView) v; |
| 2644 | mWaitingForResume.setStayPressed(true); |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | /** |
| 2649 | * Event handler for a folder icon click. |
| 2650 | * |
| 2651 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2652 | */ |
| 2653 | protected void onClickFolderIcon(View v) { |
| 2654 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2655 | if (!(v instanceof FolderIcon)){ |
| 2656 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2657 | } |
| 2658 | |
| 2659 | FolderIcon folderIcon = (FolderIcon) v; |
| 2660 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2661 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2662 | |
| 2663 | // If the folder info reports that the associated folder is open, then verify that |
| 2664 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2665 | if (info.opened && openFolder == null) { |
| 2666 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2667 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2668 | info.opened = false; |
| 2669 | } |
| 2670 | |
| 2671 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2672 | // Close any open folder |
| 2673 | closeFolder(); |
| 2674 | // Open the requested folder |
| 2675 | openFolder(folderIcon); |
| 2676 | } else { |
| 2677 | // Find the open folder... |
| 2678 | int folderScreen; |
| 2679 | if (openFolder != null) { |
| 2680 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2681 | // .. and close it |
| 2682 | closeFolder(openFolder); |
| 2683 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2684 | // Close any folder open on the current screen |
| 2685 | closeFolder(); |
| 2686 | // Pull the folder onto this screen |
| 2687 | openFolder(folderIcon); |
| 2688 | } |
| 2689 | } |
| 2690 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2693 | /** |
| 2694 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2695 | * on the home screen. |
| 2696 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2697 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2698 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2699 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2700 | } |
| 2701 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2702 | /** |
| 2703 | * Event handler for the wallpaper picker button that appears after a long press |
| 2704 | * on the home screen. |
| 2705 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2706 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2707 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2708 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2709 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2710 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
| 2711 | } |
| 2712 | |
| 2713 | /** |
| 2714 | * Event handler for a click on the settings button that appears after a long press |
| 2715 | * on the home screen. |
| 2716 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2717 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2718 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
| 2719 | } |
| 2720 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2721 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2722 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2723 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2726 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2727 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2728 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2729 | } |
| 2730 | |
| 2731 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2732 | if (mHapticFeedbackTouchListener == null) { |
| 2733 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2734 | @Override |
| 2735 | public boolean onTouch(View v, MotionEvent event) { |
| 2736 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2737 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2738 | } |
| 2739 | return false; |
| 2740 | } |
| 2741 | }; |
| 2742 | } |
| 2743 | return mHapticFeedbackTouchListener; |
| 2744 | } |
| 2745 | |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2746 | public void onDragStarted(View view) {} |
| 2747 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2748 | /** |
| 2749 | * Called when the user stops interacting with the launcher. |
| 2750 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2751 | */ |
| 2752 | protected void onInteractionEnd() {} |
| 2753 | |
| 2754 | /** |
| 2755 | * Called when the user starts interacting with the launcher. |
| 2756 | * The possible interactions are: |
| 2757 | * - open all apps |
| 2758 | * - reorder an app shortcut, or a widget |
| 2759 | * - open the overview mode. |
| 2760 | * This is a good time to stop doing things that only make sense |
| 2761 | * when the user is on the homescreen and not doing housekeeping. |
| 2762 | */ |
| 2763 | protected void onInteractionBegin() {} |
| 2764 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2765 | void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2766 | String packageName = componentName.getPackageName(); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2767 | try { |
| 2768 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2769 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
| 2770 | launcherApps.showAppDetailsForProfile(componentName, user); |
| 2771 | } catch (SecurityException e) { |
| 2772 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2773 | Log.e(TAG, "Launcher does not have permission to launch settings"); |
| 2774 | } catch (ActivityNotFoundException e) { |
| 2775 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2776 | Log.e(TAG, "Unable to launch settings"); |
| 2777 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2780 | // returns true if the activity was started |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2781 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags, |
| 2782 | UserHandleCompat user) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2783 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2784 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2785 | // We may give them the option of disabling apps this way. |
| 2786 | int messageId = R.string.uninstall_system_app_text; |
| 2787 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2788 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2789 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2790 | String packageName = componentName.getPackageName(); |
| 2791 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2792 | Intent intent = new Intent( |
| 2793 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2794 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2795 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2796 | if (user != null) { |
| 2797 | user.addToIntent(intent, Intent.EXTRA_USER); |
| 2798 | } |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2799 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2800 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2801 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2804 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 2805 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2806 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2807 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 2808 | // private contract between launcher and may be ignored in the future). |
| 2809 | boolean useLaunchAnimation = (v != null) && |
| 2810 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2811 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2812 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2813 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2814 | UserHandleCompat user = null; |
| 2815 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 2816 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 2817 | user = userManager.getUserForSerialNumber(serialNumber); |
| 2818 | } |
| 2819 | |
| 2820 | Bundle optsBundle = null; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2821 | if (useLaunchAnimation) { |
Adam Cohen | 4da294d | 2014-07-28 10:56:19 -0700 | [diff] [blame] | 2822 | ActivityOptions opts = Utilities.isLmp() ? |
| 2823 | ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) : |
| 2824 | ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 2825 | optsBundle = opts.toBundle(); |
| 2826 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2827 | |
| 2828 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 2829 | // Could be launching some bookkeeping activity |
| 2830 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2831 | } else { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2832 | // TODO Component can be null when shortcuts are supported for secondary user |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 2833 | launcherApps.startActivityForProfile(intent.getComponent(), user, |
| 2834 | intent.getSourceBounds(), optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2835 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2836 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2837 | } catch (SecurityException e) { |
| 2838 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2839 | 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] | 2840 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2841 | "or use the exported attribute for this activity. " |
| 2842 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2843 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2844 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2845 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2846 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2847 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 2848 | boolean success = false; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2849 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 2850 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 2851 | return false; |
| 2852 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2853 | try { |
| 2854 | success = startActivity(v, intent, tag); |
| 2855 | } catch (ActivityNotFoundException e) { |
| 2856 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2857 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 2858 | } |
| 2859 | return success; |
| 2860 | } |
| 2861 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2862 | /** |
| 2863 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 2864 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 2865 | */ |
| 2866 | private void copyFolderIconToImage(FolderIcon fi) { |
| 2867 | final int width = fi.getMeasuredWidth(); |
| 2868 | final int height = fi.getMeasuredHeight(); |
| 2869 | |
| 2870 | // Lazy load ImageView, Bitmap and Canvas |
| 2871 | if (mFolderIconImageView == null) { |
| 2872 | mFolderIconImageView = new ImageView(this); |
| 2873 | } |
| 2874 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 2875 | mFolderIconBitmap.getHeight() != height) { |
| 2876 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 2877 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 2878 | } |
| 2879 | |
| 2880 | DragLayer.LayoutParams lp; |
| 2881 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 2882 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 2883 | } else { |
| 2884 | lp = new DragLayer.LayoutParams(width, height); |
| 2885 | } |
| 2886 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2887 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 2888 | // view size by this scale factor. |
| 2889 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2890 | lp.customPosition = true; |
| 2891 | lp.x = mRectForFolderAnimation.left; |
| 2892 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2893 | lp.width = (int) (scale * width); |
| 2894 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2895 | |
| 2896 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2897 | fi.draw(mFolderIconCanvas); |
| 2898 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2899 | if (fi.getFolder() != null) { |
| 2900 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 2901 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2902 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2903 | // Just in case this image view is still in the drag layer from a previous animation, |
| 2904 | // we remove it and re-add it. |
| 2905 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 2906 | mDragLayer.removeView(mFolderIconImageView); |
| 2907 | } |
| 2908 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2909 | if (fi.getFolder() != null) { |
| 2910 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2911 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2914 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2915 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2916 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 2917 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 2918 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 2919 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2920 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 2921 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2922 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 2923 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 2924 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2927 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 2928 | copyFolderIconToImage(fi); |
| 2929 | fi.setVisibility(View.INVISIBLE); |
| 2930 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2931 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2932 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 2933 | if (Utilities.isLmp()) { |
| 2934 | oa.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 2935 | } |
| 2936 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2937 | oa.start(); |
| 2938 | } |
| 2939 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2940 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2941 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2942 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 2943 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 2944 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 2945 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2946 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2947 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2948 | // We remove and re-draw the FolderIcon in-case it has changed |
| 2949 | mDragLayer.removeView(mFolderIconImageView); |
| 2950 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2951 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2952 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 2953 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2954 | oa.addListener(new AnimatorListenerAdapter() { |
| 2955 | @Override |
| 2956 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2957 | if (cl != null) { |
| 2958 | cl.clearFolderLeaveBehind(); |
| 2959 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 2960 | mDragLayer.removeView(mFolderIconImageView); |
| 2961 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2962 | } |
| 2963 | } |
| 2964 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2965 | oa.start(); |
| 2966 | } |
| 2967 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2968 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 2969 | * 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] | 2970 | * is animated relative to the specified View. If the View is null, no animation |
| 2971 | * is played. |
| 2972 | * |
| 2973 | * @param folderInfo The FolderInfo describing the folder to open. |
| 2974 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2975 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2976 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2977 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2978 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2979 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2980 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2981 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 2982 | // There was a one-off crash where the folder had a parent already. |
| 2983 | if (folder.getParent() == null) { |
| 2984 | mDragLayer.addView(folder); |
| 2985 | mDragController.addDropTarget((DropTarget) folder); |
| 2986 | } else { |
| 2987 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 2988 | folder.getParent() + ")."); |
| 2989 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2990 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2991 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 2992 | |
| 2993 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 2994 | // the workspace items |
| 2995 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2996 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 3000 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3001 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 3002 | if (folder.isEditingName()) { |
| 3003 | folder.dismissEditingName(); |
| 3004 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3005 | closeFolder(folder); |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | void closeFolder(Folder folder) { |
| 3010 | folder.getInfo().opened = false; |
| 3011 | |
| 3012 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 3013 | if (parent != null) { |
| 3014 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 3015 | shrinkAndFadeInFolderIcon(fi); |
| 3016 | } |
| 3017 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3018 | |
| 3019 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 3020 | // longer occludeds the workspace items |
| 3021 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3022 | } |
| 3023 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3024 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 3025 | if (!isDraggingEnabled()) return false; |
| 3026 | if (isWorkspaceLocked()) return false; |
| 3027 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3028 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3029 | if (v instanceof Workspace) { |
| 3030 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 3031 | if (mWorkspace.enterOverviewMode()) { |
| 3032 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3033 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 3034 | return true; |
| 3035 | } else { |
| 3036 | return false; |
| 3037 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 3038 | } else { |
| 3039 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3040 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 3043 | CellLayout.CellInfo longClickCellInfo = null; |
| 3044 | View itemUnderLongClick = null; |
| 3045 | if (v.getTag() instanceof ItemInfo) { |
| 3046 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3047 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 3048 | itemUnderLongClick = longClickCellInfo.cell; |
| 3049 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3050 | } |
| 3051 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3052 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 3053 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3054 | final boolean inHotseat = isHotseatLayout(v); |
| 3055 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3056 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3057 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3058 | // User long pressed on empty space |
| 3059 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3060 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3061 | if (mWorkspace.isInOverviewMode()) { |
| 3062 | mWorkspace.startReordering(v); |
| 3063 | } else { |
| 3064 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 3065 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3066 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3067 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 3068 | mHotseat.getOrderInHotseat( |
| 3069 | longClickCellInfo.cellX, |
| 3070 | longClickCellInfo.cellY)); |
| 3071 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3072 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3073 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | } |
| 3077 | return true; |
| 3078 | } |
| 3079 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3080 | boolean isHotseatLayout(View layout) { |
| 3081 | return mHotseat != null && layout != null && |
| 3082 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 3083 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 3084 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3085 | /** |
| 3086 | * Returns the CellLayout of the specified container at the specified screen. |
| 3087 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3088 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3089 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3090 | if (mHotseat != null) { |
| 3091 | return mHotseat.getLayout(); |
| 3092 | } else { |
| 3093 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 3094 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3095 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3096 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3100 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3101 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 3102 | } |
| 3103 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3104 | private void setWorkspaceBackground(boolean workspace) { |
| 3105 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 3106 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3107 | } |
| 3108 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 3109 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3110 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 3111 | int curflags = getWindow().getAttributes().flags |
| 3112 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 3113 | if (wpflags != curflags) { |
| 3114 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 3115 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3116 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3117 | } |
| 3118 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3119 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3120 | if (v instanceof LauncherTransitionable) { |
| 3121 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3122 | } |
| 3123 | } |
| 3124 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3125 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3126 | if (v instanceof LauncherTransitionable) { |
| 3127 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3128 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3129 | |
| 3130 | // Update the workspace transition step as well |
| 3131 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3132 | } |
| 3133 | |
| 3134 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3135 | if (v instanceof LauncherTransitionable) { |
| 3136 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3137 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3141 | if (v instanceof LauncherTransitionable) { |
| 3142 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3143 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3144 | |
| 3145 | // Update the workspace transition step as well |
| 3146 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3147 | } |
| 3148 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3149 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3150 | * Things to test when changing the following seven functions. |
| 3151 | * - Home from workspace |
| 3152 | * - from center screen |
| 3153 | * - from other screens |
| 3154 | * - Home from all apps |
| 3155 | * - from center screen |
| 3156 | * - from other screens |
| 3157 | * - Back from all apps |
| 3158 | * - from center screen |
| 3159 | * - from other screens |
| 3160 | * - Launch app from workspace and quit |
| 3161 | * - with back |
| 3162 | * - with home |
| 3163 | * - Launch app from all apps and quit |
| 3164 | * - with back |
| 3165 | * - with home |
| 3166 | * - Go to a screen that's not the default, then all |
| 3167 | * apps, and launch and app, and go back |
| 3168 | * - with back |
| 3169 | * -with home |
| 3170 | * - On workspace, long press power and go back |
| 3171 | * - with back |
| 3172 | * - with home |
| 3173 | * - On all apps, long press power and go back |
| 3174 | * - with back |
| 3175 | * - with home |
| 3176 | * - On workspace, power off |
| 3177 | * - On all apps, power off |
| 3178 | * - Launch an app and turn off the screen while in that app |
| 3179 | * - Go back with home key |
| 3180 | * - Go back with back key TODO: make this not go to workspace |
| 3181 | * - From all apps |
| 3182 | * - From workspace |
| 3183 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3184 | * - From all apps |
| 3185 | * - From the center workspace |
| 3186 | * - From another workspace |
| 3187 | */ |
| 3188 | |
| 3189 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3190 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3191 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3192 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3193 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3194 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3195 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3196 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3197 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3198 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3199 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3200 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3201 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3202 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3203 | mStateAnimation.cancel(); |
| 3204 | mStateAnimation = null; |
| 3205 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3206 | |
| 3207 | boolean material = Utilities.isLmp(); |
| 3208 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3209 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3210 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3211 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); |
| 3212 | final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3213 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3214 | final int itemsAlphaStagger = |
| 3215 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3216 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3217 | final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3218 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3219 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3220 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3221 | final ArrayList<View> layerViews = new ArrayList<View>(); |
| 3222 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3223 | Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? |
| 3224 | Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3225 | Animator workspaceAnim = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3226 | mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3227 | if (!LauncherAppState.isDisableAllApps() |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3228 | || contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3229 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3230 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3231 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3232 | |
| 3233 | if (animated) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3234 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3235 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3236 | toView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3237 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3238 | final View page = content.getPageAt(content.getCurrentPage()); |
| 3239 | final View revealView = toView.findViewById(R.id.fake_page); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3240 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3241 | final float initialPanelAlpha = 1f; |
| 3242 | |
| 3243 | final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; |
| 3244 | if (isWidgetTray) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3245 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3246 | } else { |
| 3247 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3248 | } |
| 3249 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3250 | // Hide the real page background, and swap in the fake one |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3251 | content.setPageBackgroundsVisible(false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3252 | revealView.setVisibility(View.VISIBLE); |
| 3253 | // We need to hide this view as the animation start will be posted. |
| 3254 | revealView.setAlpha(0); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3255 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3256 | int width = revealView.getMeasuredWidth(); |
| 3257 | int height = revealView.getMeasuredHeight(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3258 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3259 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3260 | revealView.setTranslationY(0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3261 | revealView.setTranslationX(0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3262 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3263 | // Get the y delta between the center of the page and the center of the all apps button |
| 3264 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3265 | getAllAppsButton(), null); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3266 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3267 | float alpha = 0; |
| 3268 | float xDrift = 0; |
| 3269 | float yDrift = 0; |
| 3270 | if (material) { |
| 3271 | alpha = isWidgetTray ? 0.3f : 1f; |
| 3272 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3273 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3274 | } else { |
| 3275 | yDrift = 2 * height / 3; |
| 3276 | xDrift = 0; |
| 3277 | } |
| 3278 | final float initAlpha = alpha; |
| 3279 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3280 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3281 | layerViews.add(revealView); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3282 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3283 | PropertyValuesHolder panelDriftY = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3284 | PropertyValuesHolder.ofFloat("translationY", yDrift, 0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3285 | PropertyValuesHolder panelDriftX = |
| 3286 | PropertyValuesHolder.ofFloat("translationX", xDrift, 0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3287 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3288 | ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, |
| 3289 | panelAlpha, panelDriftY, panelDriftX); |
| 3290 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3291 | panelAlphaAndDrift.setDuration(revealDuration); |
| 3292 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3293 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3294 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3295 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3296 | if (page != null) { |
| 3297 | page.setVisibility(View.VISIBLE); |
| 3298 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3299 | layerViews.add(page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3300 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3301 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0); |
| 3302 | page.setTranslationY(yDrift); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3303 | pageDrift.setDuration(revealDuration); |
| 3304 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3305 | pageDrift.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3306 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3307 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3308 | page.setAlpha(0f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3309 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3310 | itemsAlpha.setDuration(revealDuration); |
| 3311 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 3312 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
| 3313 | mStateAnimation.play(itemsAlpha); |
| 3314 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3315 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3316 | View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); |
| 3317 | pageIndicators.setAlpha(0.01f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3318 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3319 | ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3320 | indicatorsAlpha.setDuration(revealDuration); |
| 3321 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3322 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3323 | if (material) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3324 | final View allApps = getAllAppsButton(); |
| 3325 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3326 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3327 | float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3328 | Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3329 | height / 2, startRadius, revealRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3330 | reveal.setDuration(revealDuration); |
| 3331 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3332 | |
| 3333 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3334 | public void onAnimationStart(Animator animation) { |
| 3335 | if (!isWidgetTray) { |
| 3336 | allApps.setVisibility(View.INVISIBLE); |
| 3337 | } |
| 3338 | } |
| 3339 | public void onAnimationEnd(Animator animation) { |
| 3340 | if (!isWidgetTray) { |
| 3341 | allApps.setVisibility(View.VISIBLE); |
| 3342 | } |
| 3343 | } |
| 3344 | }); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3345 | mStateAnimation.play(reveal); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3346 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3347 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3348 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
| 3349 | @Override |
| 3350 | public void onAnimationEnd(Animator animation) { |
| 3351 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3352 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 3353 | |
| 3354 | revealView.setVisibility(View.INVISIBLE); |
| 3355 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3356 | if (page != null) { |
| 3357 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3358 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3359 | content.setPageBackgroundsVisible(true); |
| 3360 | |
| 3361 | // Hide the search bar |
| 3362 | if (mSearchDropTargetBar != null) { |
| 3363 | mSearchDropTargetBar.hideSearchBar(false); |
| 3364 | } |
| 3365 | } |
| 3366 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3367 | }); |
| 3368 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3369 | if (workspaceAnim != null) { |
| 3370 | mStateAnimation.play(workspaceAnim); |
| 3371 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3372 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3373 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3374 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3375 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3376 | final Runnable startAnimRunnable = new Runnable() { |
| 3377 | public void run() { |
| 3378 | // Check that mStateAnimation hasn't changed while |
| 3379 | // we waited for a layout/draw pass |
| 3380 | if (mStateAnimation != stateAnimation) |
| 3381 | return; |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3382 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3383 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3384 | |
| 3385 | revealView.setAlpha(initAlpha); |
| 3386 | if (Utilities.isLmp()) { |
| 3387 | for (int i = 0; i < layerViews.size(); i++) { |
| 3388 | View v = layerViews.get(i); |
Adam Cohen | c761d3c | 2014-09-06 18:16:32 +0200 | [diff] [blame] | 3389 | if (v != null && v.isAttachedToWindow()) v.buildLayer(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3390 | } |
| 3391 | } |
| 3392 | mStateAnimation.start(); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3393 | } |
| 3394 | }; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3395 | toView.bringToFront(); |
| 3396 | toView.setVisibility(View.VISIBLE); |
| 3397 | toView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3398 | } else { |
| 3399 | toView.setTranslationX(0.0f); |
| 3400 | toView.setTranslationY(0.0f); |
| 3401 | toView.setScaleX(1.0f); |
| 3402 | toView.setScaleY(1.0f); |
| 3403 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3404 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3405 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3406 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3407 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3408 | if (mSearchDropTargetBar != null) { |
| 3409 | mSearchDropTargetBar.hideSearchBar(false); |
| 3410 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3411 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3412 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3413 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3414 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3415 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3416 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3417 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3418 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | /** |
| 3422 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3423 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3424 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3425 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3426 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3427 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3428 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3429 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3430 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3431 | mStateAnimation.cancel(); |
| 3432 | mStateAnimation = null; |
| 3433 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3434 | |
| 3435 | boolean material = Utilities.isLmp(); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3436 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3437 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3438 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3439 | final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3440 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3441 | final int itemsAlphaStagger = |
| 3442 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3443 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3444 | final float scaleFactor = (float) |
| 3445 | res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
| 3446 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3447 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3448 | Animator workspaceAnim = null; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3449 | final ArrayList<View> layerViews = new ArrayList<View>(); |
| 3450 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3451 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3452 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3453 | toState, animated, layerViews); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3454 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3455 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3456 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3457 | toState, animated, layerViews); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3458 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3459 | |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3460 | if (animated) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3461 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3462 | if (workspaceAnim != null) { |
| 3463 | mStateAnimation.play(workspaceAnim); |
| 3464 | } |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3465 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3466 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3467 | fromView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3468 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3469 | final View page = content.getPageAt(content.getNextPage()); |
| 3470 | final View revealView = fromView.findViewById(R.id.fake_page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3471 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3472 | // hideAppsCustomizeHelper is called in some cases when it is already hidden |
| 3473 | // don't perform all these no-op animations. In particularly, this was causing |
| 3474 | // the all-apps button to pop in and out. |
| 3475 | if (fromView.getVisibility() == View.VISIBLE) { |
| 3476 | AppsCustomizePagedView.ContentType contentType = content.getContentType(); |
| 3477 | final boolean isWidgetTray = |
| 3478 | contentType == AppsCustomizePagedView.ContentType.Widgets; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3479 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3480 | if (isWidgetTray) { |
| 3481 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3482 | } else { |
| 3483 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3484 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3485 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3486 | int width = revealView.getMeasuredWidth(); |
| 3487 | int height = revealView.getMeasuredHeight(); |
| 3488 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
| 3489 | |
| 3490 | // Hide the real page background, and swap in the fake one |
| 3491 | revealView.setVisibility(View.VISIBLE); |
| 3492 | content.setPageBackgroundsVisible(false); |
| 3493 | |
| 3494 | final View allAppsButton = getAllAppsButton(); |
| 3495 | revealView.setTranslationY(0); |
| 3496 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3497 | allAppsButton, null); |
| 3498 | |
| 3499 | float xDrift = 0; |
| 3500 | float yDrift = 0; |
| 3501 | if (material) { |
| 3502 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3503 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3504 | } else { |
| 3505 | yDrift = 5 * height / 4; |
| 3506 | xDrift = 0; |
| 3507 | } |
| 3508 | |
| 3509 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3510 | TimeInterpolator decelerateInterpolator = material ? |
| 3511 | new LogDecelerateInterpolator(100, 0) : |
| 3512 | new LogDecelerateInterpolator(30, 0); |
| 3513 | |
| 3514 | // The vertical motion of the apps panel should be delayed by one frame |
| 3515 | // from the conceal animation in order to give the right feel. We correpsondingly |
| 3516 | // shorten the duration so that the slide and conceal end at the same time. |
| 3517 | ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", |
| 3518 | 0, yDrift); |
| 3519 | panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3520 | panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3521 | panelDriftY.setInterpolator(decelerateInterpolator); |
| 3522 | mStateAnimation.play(panelDriftY); |
| 3523 | |
| 3524 | ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", |
| 3525 | 0, xDrift); |
| 3526 | panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3527 | panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3528 | panelDriftX.setInterpolator(decelerateInterpolator); |
| 3529 | mStateAnimation.play(panelDriftX); |
| 3530 | |
| 3531 | if (isWidgetTray || !material) { |
| 3532 | float finalAlpha = material ? 0.4f : 0f; |
| 3533 | revealView.setAlpha(1f); |
| 3534 | ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", |
| 3535 | 1f, finalAlpha); |
| 3536 | panelAlpha.setDuration(revealDuration); |
| 3537 | panelAlpha.setInterpolator(material ? decelerateInterpolator : |
| 3538 | new AccelerateInterpolator(1.5f)); |
| 3539 | mStateAnimation.play(panelAlpha); |
| 3540 | } |
| 3541 | |
| 3542 | if (page != null) { |
| 3543 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3544 | |
| 3545 | ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", |
| 3546 | 0, yDrift); |
| 3547 | page.setTranslationY(0); |
| 3548 | pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3549 | pageDrift.setInterpolator(decelerateInterpolator); |
| 3550 | pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3551 | mStateAnimation.play(pageDrift); |
| 3552 | |
| 3553 | page.setAlpha(1f); |
| 3554 | ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f); |
| 3555 | itemsAlpha.setDuration(100); |
| 3556 | itemsAlpha.setInterpolator(decelerateInterpolator); |
| 3557 | mStateAnimation.play(itemsAlpha); |
| 3558 | } |
| 3559 | |
| 3560 | View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); |
| 3561 | pageIndicators.setAlpha(1f); |
| 3562 | ObjectAnimator indicatorsAlpha = |
| 3563 | LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f); |
| 3564 | indicatorsAlpha.setDuration(revealDuration); |
| 3565 | indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 3566 | mStateAnimation.play(indicatorsAlpha); |
| 3567 | |
| 3568 | width = revealView.getMeasuredWidth(); |
| 3569 | |
| 3570 | if (material) { |
| 3571 | if (!isWidgetTray) { |
| 3572 | allAppsButton.setVisibility(View.INVISIBLE); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3573 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3574 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3575 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3576 | float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
| 3577 | Animator reveal = |
| 3578 | LauncherAnimUtils.createCircularReveal(revealView, width / 2, |
| 3579 | height / 2, revealRadius, finalRadius); |
| 3580 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3581 | reveal.setDuration(revealDuration); |
| 3582 | reveal.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3583 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3584 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3585 | public void onAnimationEnd(Animator animation) { |
| 3586 | revealView.setVisibility(View.INVISIBLE); |
| 3587 | if (!isWidgetTray) { |
| 3588 | allAppsButton.setVisibility(View.VISIBLE); |
| 3589 | } |
| 3590 | } |
| 3591 | }); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3592 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3593 | mStateAnimation.play(reveal); |
| 3594 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3595 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3596 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3597 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 3598 | mAppsCustomizeContent.stopScrolling(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3599 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3600 | |
| 3601 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3602 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3603 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3604 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3605 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3606 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3607 | if (onCompleteRunnable != null) { |
| 3608 | onCompleteRunnable.run(); |
| 3609 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3610 | |
| 3611 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3612 | if (page != null) { |
| 3613 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3614 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3615 | content.setPageBackgroundsVisible(true); |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3616 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3617 | } |
| 3618 | }); |
| 3619 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3620 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3621 | final Runnable startAnimRunnable = new Runnable() { |
| 3622 | public void run() { |
| 3623 | // Check that mStateAnimation hasn't changed while |
| 3624 | // we waited for a layout/draw pass |
| 3625 | if (mStateAnimation != stateAnimation) |
| 3626 | return; |
| 3627 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3628 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3629 | |
| 3630 | if (Utilities.isLmp()) { |
| 3631 | for (int i = 0; i < layerViews.size(); i++) { |
| 3632 | View v = layerViews.get(i); |
Adam Cohen | cd14528 | 2014-09-06 18:32:56 +0200 | [diff] [blame^] | 3633 | if (v != null && v.isAttachedToWindow()) v.buildLayer(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3634 | } |
| 3635 | } |
| 3636 | mStateAnimation.start(); |
| 3637 | } |
| 3638 | }; |
| 3639 | fromView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3640 | } else { |
| 3641 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3642 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3643 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3644 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3645 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3646 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3647 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3648 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3651 | @Override |
| 3652 | public void onTrimMemory(int level) { |
| 3653 | super.onTrimMemory(level); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 3654 | if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) { |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3655 | mAppsCustomizeTabHost.onTrimMemory(); |
| 3656 | } |
| 3657 | } |
| 3658 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3659 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3660 | showWorkspace(animated, null); |
| 3661 | } |
| 3662 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3663 | protected void showWorkspace() { |
| 3664 | showWorkspace(true); |
| 3665 | } |
| 3666 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3667 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 3668 | if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3669 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3670 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3671 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3672 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3673 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3674 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3675 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3676 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3677 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3678 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3679 | // Set focus to the AppsCustomize button |
| 3680 | if (mAllAppsButton != null) { |
| 3681 | mAllAppsButton.requestFocus(); |
| 3682 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3683 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3684 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3685 | // Change the state *after* we've called all the transition code |
| 3686 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3687 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3688 | // Resume the auto-advance of widgets |
| 3689 | mUserPresent = true; |
| 3690 | updateRunning(); |
| 3691 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3692 | // Send an accessibility event to announce the context change |
| 3693 | getWindow().getDecorView() |
| 3694 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3695 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3696 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3697 | } |
| 3698 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3699 | void showOverviewMode(boolean animated) { |
| 3700 | mWorkspace.setVisibility(View.VISIBLE); |
| 3701 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3702 | mState = State.WORKSPACE; |
| 3703 | onWorkspaceShown(animated); |
| 3704 | } |
| 3705 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3706 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3707 | } |
| 3708 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3709 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3710 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3711 | if (mState != State.WORKSPACE) return; |
| 3712 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3713 | if (resetPageToZero) { |
| 3714 | mAppsCustomizeTabHost.reset(); |
| 3715 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3716 | showAppsCustomizeHelper(animated, false, contentType); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 3717 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3718 | @Override |
| 3719 | public void run() { |
| 3720 | // We post this in-case the all apps view isn't yet constructed. |
| 3721 | mAppsCustomizeTabHost.requestFocus(); |
| 3722 | } |
| 3723 | }); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3724 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3725 | // Change the state *after* we've called all the transition code |
| 3726 | mState = State.APPS_CUSTOMIZE; |
| 3727 | |
| 3728 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3729 | mUserPresent = false; |
| 3730 | updateRunning(); |
| 3731 | closeFolder(); |
| 3732 | |
| 3733 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3734 | getWindow().getDecorView() |
| 3735 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3736 | } |
| 3737 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3738 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3739 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3740 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3741 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3742 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3743 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3744 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3745 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3746 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3747 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 3748 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 3749 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3750 | @Override |
| 3751 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3752 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3753 | // Before we show workspace, hide all apps again because |
| 3754 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 3755 | // clean up our state transition functions |
| 3756 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3757 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3758 | } else { |
| 3759 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3760 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3761 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3762 | }, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3763 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3764 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3765 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3766 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3767 | final boolean animated = true; |
| 3768 | final boolean springLoaded = true; |
| 3769 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3770 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3771 | } |
| 3772 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 3773 | } |
| 3774 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3775 | void lockAllApps() { |
| 3776 | // TODO |
| 3777 | } |
| 3778 | |
| 3779 | void unlockAllApps() { |
| 3780 | // TODO |
| 3781 | } |
| 3782 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3783 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3784 | * Hides the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3785 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3786 | void hideHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3787 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3788 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3789 | if (mHotseat.getAlpha() != 0f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3790 | int duration = 0; |
| 3791 | if (mSearchDropTargetBar != null) { |
| 3792 | duration = mSearchDropTargetBar.getTransitionOutDuration(); |
| 3793 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3794 | mHotseat.animate().alpha(0f).setDuration(duration); |
| 3795 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3796 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3797 | mHotseat.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3798 | } |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3799 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3800 | } |
| 3801 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3802 | /** |
| 3803 | * Add an item from all apps or customize onto the given workspace screen. |
| 3804 | * If layout is null, add to the current screen. |
| 3805 | */ |
| 3806 | void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3807 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 3808 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 3809 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3810 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3811 | |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3812 | /** Maps the current orientation to an index for referencing orientation correct global icons */ |
| 3813 | private int getCurrentOrientationIndexForGlobalIcons() { |
| 3814 | // default - 0, landscape - 1 |
| 3815 | switch (getResources().getConfiguration().orientation) { |
| 3816 | case Configuration.ORIENTATION_LANDSCAPE: |
| 3817 | return 1; |
| 3818 | default: |
| 3819 | return 0; |
| 3820 | } |
| 3821 | } |
| 3822 | |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3823 | private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3824 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3825 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3826 | // Look for the toolbar icon specified in the activity meta-data |
| 3827 | Bundle metaData = packageManager.getActivityInfo( |
| 3828 | activityName, PackageManager.GET_META_DATA).metaData; |
| 3829 | if (metaData != null) { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3830 | int iconResId = metaData.getInt(resourceName); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3831 | if (iconResId != 0) { |
| 3832 | Resources res = packageManager.getResourcesForActivity(activityName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3833 | return res.getDrawable(iconResId); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3834 | } |
| 3835 | } |
| 3836 | } catch (NameNotFoundException e) { |
Michael Jurka | b6052a9 | 2011-07-12 17:02:45 -0700 | [diff] [blame] | 3837 | // This can happen if the activity defines an invalid drawable |
| 3838 | Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + |
| 3839 | " not found", e); |
Mathew Inwood | 70d5102 | 2011-07-12 13:41:41 +0100 | [diff] [blame] | 3840 | } catch (Resources.NotFoundException nfe) { |
| 3841 | // This can happen if the activity defines an invalid drawable |
| 3842 | Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), |
| 3843 | nfe); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3844 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3845 | return null; |
| 3846 | } |
| 3847 | |
| 3848 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3849 | private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3850 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 3851 | String toolbarResourceName) { |
| 3852 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3853 | Resources r = getResources(); |
| 3854 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 3855 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3856 | |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3857 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3858 | // If we were unable to find the icon via the meta-data, use a generic one |
| 3859 | if (toolbarIcon == null) { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3860 | toolbarIcon = r.getDrawable(fallbackDrawableId); |
| 3861 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3862 | if (button != null) { |
| 3863 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 3864 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3865 | return null; |
| 3866 | } else { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3867 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3868 | if (button != null) { |
| 3869 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 3870 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3871 | return toolbarIcon.getConstantState(); |
| 3872 | } |
| 3873 | } |
| 3874 | |
| 3875 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3876 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3877 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 3878 | String toolbarResourceName) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3879 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3880 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3881 | |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 3882 | if (button != null) { |
| 3883 | // If we were unable to find the icon via the meta-data, use a |
| 3884 | // generic one |
| 3885 | if (toolbarIcon == null) { |
| 3886 | button.setImageResource(fallbackDrawableId); |
| 3887 | } else { |
| 3888 | button.setImageDrawable(toolbarIcon); |
| 3889 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3890 | } |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 3891 | |
| 3892 | return toolbarIcon != null ? toolbarIcon.getConstantState() : null; |
| 3893 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3894 | } |
| 3895 | |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3896 | private void updateTextButtonWithDrawable(int buttonId, Drawable d) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3897 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3898 | button.setCompoundDrawables(d, null, null, null); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3899 | } |
| 3900 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3901 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3902 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3903 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3904 | } |
| 3905 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3906 | private void invalidatePressedFocusedStates(View container, View button) { |
| 3907 | if (container instanceof HolographicLinearLayout) { |
| 3908 | HolographicLinearLayout layout = (HolographicLinearLayout) container; |
| 3909 | layout.invalidatePressedFocusedStates(); |
| 3910 | } else if (button instanceof HolographicImageView) { |
| 3911 | HolographicImageView view = (HolographicImageView) button; |
| 3912 | view.invalidatePressedFocusedStates(); |
| 3913 | } |
| 3914 | } |
| 3915 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3916 | public View getQsbBar() { |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3917 | if (mQsb == null) { |
| 3918 | mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false); |
| 3919 | mSearchDropTargetBar.addView(mQsb); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3920 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3921 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | protected boolean updateGlobalSearchIcon() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3925 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3926 | final ImageView searchButton = (ImageView) findViewById(R.id.search_button); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3927 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 3928 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3929 | |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3930 | final SearchManager searchManager = |
| 3931 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3932 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 3933 | if (activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3934 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3935 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3936 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 3937 | TOOLBAR_SEARCH_ICON_METADATA_NAME); |
| 3938 | if (sGlobalSearchIcon[coi] == null) { |
| 3939 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 3940 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 3941 | TOOLBAR_ICON_METADATA_NAME); |
| 3942 | } |
| 3943 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3944 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); |
| 3945 | searchButton.setVisibility(View.VISIBLE); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3946 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3947 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3948 | } else { |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 3949 | // 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] | 3950 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); |
| 3951 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 3952 | if (searchButton != null) searchButton.setVisibility(View.GONE); |
| 3953 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3954 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3955 | return false; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3956 | } |
| 3957 | } |
| 3958 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3959 | protected void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3960 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
| 3961 | final View searchButton = (ImageView) findViewById(R.id.search_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3962 | updateButtonWithDrawable(R.id.search_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3963 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3964 | } |
| 3965 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3966 | protected boolean updateVoiceSearchIcon(boolean searchVisible) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3967 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3968 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3969 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3970 | // 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] | 3971 | final SearchManager searchManager = |
| 3972 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3973 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 3974 | |
| 3975 | ComponentName activityName = null; |
| 3976 | if (globalSearchActivity != null) { |
| 3977 | // Check if the global search activity handles voice search |
| 3978 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3979 | intent.setPackage(globalSearchActivity.getPackageName()); |
| 3980 | activityName = intent.resolveActivity(getPackageManager()); |
| 3981 | } |
| 3982 | |
| 3983 | if (activityName == null) { |
| 3984 | // Fallback: check if an activity other than the global search activity |
| 3985 | // resolves this |
| 3986 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3987 | activityName = intent.resolveActivity(getPackageManager()); |
| 3988 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3989 | if (searchVisible && activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3990 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3991 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3992 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 3993 | TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); |
| 3994 | if (sVoiceSearchIcon[coi] == null) { |
| 3995 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 3996 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 3997 | TOOLBAR_ICON_METADATA_NAME); |
| 3998 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3999 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4000 | voiceButton.setVisibility(View.VISIBLE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4001 | updateVoiceButtonProxyVisible(false); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4002 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4003 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4004 | } else { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4005 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 4006 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4007 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4008 | return false; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4009 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 4010 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4011 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4012 | protected void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4013 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
| 4014 | final View voiceButton = findViewById(R.id.voice_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4015 | updateButtonWithDrawable(R.id.voice_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4016 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4017 | } |
| 4018 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4019 | public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) { |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4020 | final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); |
| 4021 | if (voiceButtonProxy != null) { |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4022 | boolean visible = !forceDisableVoiceButtonProxy && |
| 4023 | mWorkspace.shouldVoiceButtonProxyBeVisible(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4024 | voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4025 | voiceButtonProxy.bringToFront(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4026 | } |
| 4027 | } |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4028 | |
| 4029 | /** |
| 4030 | * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy |
| 4031 | * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns. |
| 4032 | */ |
| 4033 | public void disableVoiceButtonProxy(boolean disabled) { |
| 4034 | updateVoiceButtonProxyVisible(disabled); |
| 4035 | } |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4036 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4037 | @Override |
| 4038 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4039 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4040 | final List<CharSequence> text = event.getText(); |
| 4041 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4042 | // Populate event with a fake title based on the current state. |
| 4043 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4044 | text.add(mAppsCustomizeTabHost.getContentTag()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4045 | } else { |
| 4046 | text.add(getString(R.string.all_apps_home_button_label)); |
| 4047 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4048 | return result; |
| 4049 | } |
| 4050 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4051 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 4052 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4053 | */ |
| 4054 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 4055 | @Override |
| 4056 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4057 | closeSystemDialogs(); |
| 4058 | } |
| 4059 | } |
| 4060 | |
| 4061 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 4062 | * Receives notifications whenever the appwidgets are reset. |
| 4063 | */ |
| 4064 | private class AppWidgetResetObserver extends ContentObserver { |
| 4065 | public AppWidgetResetObserver() { |
| 4066 | super(new Handler()); |
| 4067 | } |
| 4068 | |
| 4069 | @Override |
| 4070 | public void onChange(boolean selfChange) { |
| 4071 | onAppWidgetReset(); |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4076 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 4077 | * in onResume. |
| 4078 | * |
| 4079 | * This needs to be called from incoming places where resources might have been loaded |
| 4080 | * while we are paused. That is becaues the Configuration might be wrong |
| 4081 | * when we're not running, and if it comes back to what it was when we |
| 4082 | * were paused, we are not restarted. |
| 4083 | * |
| 4084 | * Implementation of the method from LauncherModel.Callbacks. |
| 4085 | * |
| 4086 | * @return true if we are currently paused. The caller might be able to |
| 4087 | * skip some work in that case since we will come back again. |
| 4088 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4089 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4090 | if (mPaused) { |
| 4091 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4092 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4093 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4094 | } |
| 4095 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4096 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4097 | return true; |
| 4098 | } else { |
| 4099 | return false; |
| 4100 | } |
| 4101 | } |
| 4102 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4103 | private boolean waitUntilResume(Runnable run) { |
| 4104 | return waitUntilResume(run, false); |
| 4105 | } |
| 4106 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4107 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 4108 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4109 | } |
| 4110 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4111 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4112 | * If the activity is currently paused, signal that we need to re-run the loader |
| 4113 | * in onResume. |
| 4114 | * |
| 4115 | * This needs to be called from incoming places where resources might have been loaded |
| 4116 | * while we are paused. That is becaues the Configuration might be wrong |
| 4117 | * when we're not running, and if it comes back to what it was when we |
| 4118 | * were paused, we are not restarted. |
| 4119 | * |
| 4120 | * Implementation of the method from LauncherModel.Callbacks. |
| 4121 | * |
| 4122 | * @return true if we are currently paused. The caller might be able to |
| 4123 | * skip some work in that case since we will come back again. |
| 4124 | */ |
| 4125 | public boolean setLoadOnResume() { |
| 4126 | if (mPaused) { |
| 4127 | Log.i(TAG, "setLoadOnResume"); |
| 4128 | mOnResumeNeedsLoad = true; |
| 4129 | return true; |
| 4130 | } else { |
| 4131 | return false; |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4136 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4137 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4138 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4139 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4140 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4141 | } else { |
| 4142 | return SCREEN_COUNT / 2; |
| 4143 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4144 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4145 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4146 | /** |
| 4147 | * Refreshes the shortcuts shown on the workspace. |
| 4148 | * |
| 4149 | * Implementation of the method from LauncherModel.Callbacks. |
| 4150 | */ |
| 4151 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4152 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 4153 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4154 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 4155 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 4156 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4157 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4158 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4159 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4160 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 4161 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4162 | |
Michael Jurka | 05bf644 | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 4163 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4164 | if (mHotseat != null) { |
| 4165 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4166 | } |
| 4167 | } |
| 4168 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4169 | @Override |
| 4170 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4171 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4172 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 4173 | // If there are no screens, we need to have an empty screen |
| 4174 | if (orderedScreenIds.size() == 0) { |
| 4175 | mWorkspace.addExtraEmptyScreen(); |
| 4176 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4177 | |
| 4178 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4179 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 4180 | if (hasCustomContentToLeft()) { |
| 4181 | mWorkspace.createCustomContentContainer(); |
| 4182 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4183 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | @Override |
| 4187 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 4188 | // Log to disk |
| 4189 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 4190 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 4191 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4192 | int count = orderedScreenIds.size(); |
| 4193 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 4194 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4195 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4196 | } |
| 4197 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4198 | private boolean shouldShowWeightWatcher() { |
| 4199 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4200 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 4201 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4202 | |
| 4203 | return show; |
| 4204 | } |
| 4205 | |
| 4206 | private void toggleShowWeightWatcher() { |
| 4207 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4208 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 4209 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 4210 | |
| 4211 | show = !show; |
| 4212 | |
| 4213 | SharedPreferences.Editor editor = sp.edit(); |
| 4214 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 4215 | editor.commit(); |
| 4216 | |
| 4217 | if (mWeightWatcher != null) { |
| 4218 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 4219 | } |
| 4220 | } |
| 4221 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4222 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 4223 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4224 | final ArrayList<ItemInfo> addAnimated, |
| 4225 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4226 | Runnable r = new Runnable() { |
| 4227 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4228 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4229 | } |
| 4230 | }; |
| 4231 | if (waitUntilResume(r)) { |
| 4232 | return; |
| 4233 | } |
| 4234 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4235 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4236 | if (newScreens != null) { |
| 4237 | bindAddScreens(newScreens); |
| 4238 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4239 | |
| 4240 | // We add the items without animation on non-visible pages, and with |
| 4241 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4242 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4243 | bindItems(addNotAnimated, 0, |
| 4244 | addNotAnimated.size(), false); |
| 4245 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4246 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4247 | bindItems(addAnimated, 0, |
| 4248 | addAnimated.size(), true); |
| 4249 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4250 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4251 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 4252 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4253 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4254 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4255 | addedApps != null && mAppsCustomizeContent != null) { |
| 4256 | mAppsCustomizeContent.addApps(addedApps); |
| 4257 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4258 | } |
| 4259 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4260 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4261 | * Bind the items start-end from the list. |
| 4262 | * |
| 4263 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4264 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4265 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 4266 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4267 | Runnable r = new Runnable() { |
| 4268 | public void run() { |
| 4269 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 4270 | } |
| 4271 | }; |
| 4272 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4273 | return; |
| 4274 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4275 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4276 | // 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] | 4277 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 4278 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4279 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4280 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4281 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4282 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4283 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4284 | |
| 4285 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4286 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4287 | mHotseat == null) { |
| 4288 | continue; |
| 4289 | } |
| 4290 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4291 | switch (item.itemType) { |
| 4292 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4293 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4294 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4295 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4296 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4297 | /* |
| 4298 | * TODO: FIX collision case |
| 4299 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4300 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4301 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4302 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4303 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4304 | Object tag = v.getTag(); |
| 4305 | String desc = "Collision while binding workspace item: " + item |
| 4306 | + ". Collides with " + tag; |
| 4307 | if (LauncherAppState.isDogfoodBuild()) { |
| 4308 | throw (new RuntimeException(desc)); |
| 4309 | } else { |
| 4310 | Log.d(TAG, desc); |
| 4311 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4312 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4315 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4316 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4317 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4318 | // Animate all the applications up now |
| 4319 | shortcut.setAlpha(0f); |
| 4320 | shortcut.setScaleX(0f); |
| 4321 | shortcut.setScaleY(0f); |
| 4322 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4323 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4324 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4325 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4326 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4327 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4328 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4329 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4330 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4331 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4332 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4333 | default: |
| 4334 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4335 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4336 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4337 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4338 | if (animateIcons) { |
| 4339 | // Animate to the correct page |
| 4340 | if (newShortcutsScreenId > -1) { |
| 4341 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4342 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4343 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4344 | public void run() { |
| 4345 | anim.playTogether(bounceAnims); |
| 4346 | anim.start(); |
| 4347 | } |
| 4348 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4349 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4350 | // We post the animation slightly delayed to prevent slowdowns |
| 4351 | // when we are loading right after we return to launcher. |
| 4352 | mWorkspace.postDelayed(new Runnable() { |
| 4353 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4354 | if (mWorkspace != null) { |
| 4355 | mWorkspace.snapToPage(newScreenIndex); |
| 4356 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4357 | NEW_APPS_ANIMATION_DELAY); |
| 4358 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4359 | } |
| 4360 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4361 | } else { |
| 4362 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4363 | } |
| 4364 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4365 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4366 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4367 | } |
| 4368 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4369 | /** |
| 4370 | * Implementation of the method from LauncherModel.Callbacks. |
| 4371 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4372 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4373 | Runnable r = new Runnable() { |
| 4374 | public void run() { |
| 4375 | bindFolders(folders); |
| 4376 | } |
| 4377 | }; |
| 4378 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4379 | return; |
| 4380 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4381 | sFolders.clear(); |
| 4382 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4383 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4384 | |
| 4385 | /** |
| 4386 | * Add the views for a widget to the workspace. |
| 4387 | * |
| 4388 | * Implementation of the method from LauncherModel.Callbacks. |
| 4389 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4390 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4391 | Runnable r = new Runnable() { |
| 4392 | public void run() { |
| 4393 | bindAppWidget(item); |
| 4394 | } |
| 4395 | }; |
| 4396 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4397 | return; |
| 4398 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4399 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4400 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4401 | if (DEBUG_WIDGETS) { |
| 4402 | Log.d(TAG, "bindAppWidget: " + item); |
| 4403 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4404 | final Workspace workspace = mWorkspace; |
| 4405 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4406 | AppWidgetProviderInfo appWidgetInfo; |
| 4407 | if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) && |
| 4408 | ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { |
| 4409 | |
| 4410 | appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName); |
| 4411 | if (appWidgetInfo == null) { |
| 4412 | if (DEBUG_WIDGETS) { |
| 4413 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4414 | + " belongs to component " + item.providerName |
| 4415 | + ", as the povider is null"); |
| 4416 | } |
| 4417 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4418 | return; |
| 4419 | } |
| 4420 | // Note: This assumes that the id remap broadcast is received before this step. |
| 4421 | // If that is not the case, the id remap will be ignored and user may see the |
| 4422 | // click to setup view. |
| 4423 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null); |
| 4424 | pendingInfo.spanX = item.spanX; |
| 4425 | pendingInfo.spanY = item.spanY; |
| 4426 | pendingInfo.minSpanX = item.minSpanX; |
| 4427 | pendingInfo.minSpanY = item.minSpanY; |
| 4428 | Bundle options = |
| 4429 | AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo); |
| 4430 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4431 | int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 4432 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 4433 | newWidgetId, appWidgetInfo, options); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4434 | |
| 4435 | // TODO consider showing a permission dialog when the widget is clicked. |
| 4436 | if (!success) { |
| 4437 | mAppWidgetHost.deleteAppWidgetId(newWidgetId); |
| 4438 | if (DEBUG_WIDGETS) { |
| 4439 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4440 | + " belongs to component " + item.providerName |
| 4441 | + ", as the launcher is unable to bing a new widget id"); |
| 4442 | } |
| 4443 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4444 | return; |
| 4445 | } |
| 4446 | |
| 4447 | item.appWidgetId = newWidgetId; |
| 4448 | |
| 4449 | // If the widget has a configure activity, it is still needs to set it up, otherwise |
| 4450 | // the widget is ready to go. |
| 4451 | item.restoreStatus = (appWidgetInfo.configure == null) |
| 4452 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 4453 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 4454 | |
| 4455 | LauncherModel.updateItemInDatabase(this, item); |
| 4456 | } |
| 4457 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4458 | if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 4459 | final int appWidgetId = item.appWidgetId; |
| 4460 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 4461 | if (DEBUG_WIDGETS) { |
| 4462 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 4463 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4464 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4465 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4466 | } else { |
| 4467 | appWidgetInfo = null; |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4468 | PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item); |
| 4469 | view.updateIcon(mIconCache); |
| 4470 | item.hostView = view; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4471 | item.hostView.updateAppWidget(null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4472 | item.hostView.setOnClickListener(this); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4473 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4474 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4475 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4476 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4477 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4478 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4479 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4480 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4481 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4482 | workspace.requestLayout(); |
| 4483 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4484 | if (DEBUG_WIDGETS) { |
| 4485 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4486 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4487 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4488 | } |
| 4489 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4490 | /** |
| 4491 | * Restores a pending widget. |
| 4492 | * |
| 4493 | * @param appWidgetId The app widget id |
| 4494 | * @param cellInfo The position on screen where to create the widget. |
| 4495 | */ |
| 4496 | private void completeRestoreAppWidget(final int appWidgetId) { |
| 4497 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 4498 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 4499 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
| 4500 | return; |
| 4501 | } |
| 4502 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4503 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4504 | info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 4505 | |
| 4506 | mWorkspace.reinflateWidgetsIfNecessary(); |
| 4507 | LauncherModel.updateItemInDatabase(this, info); |
| 4508 | } |
| 4509 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4510 | public void onPageBoundSynchronously(int page) { |
| 4511 | mSynchronouslyBoundPages.add(page); |
| 4512 | } |
| 4513 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4514 | /** |
| 4515 | * Callback saying that there aren't any more items to bind. |
| 4516 | * |
| 4517 | * Implementation of the method from LauncherModel.Callbacks. |
| 4518 | */ |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4519 | public void finishBindingItems(final boolean upgradePath) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4520 | Runnable r = new Runnable() { |
| 4521 | public void run() { |
| 4522 | finishBindingItems(upgradePath); |
| 4523 | } |
| 4524 | }; |
| 4525 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4526 | return; |
| 4527 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4528 | if (mSavedState != null) { |
| 4529 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4530 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4531 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4532 | mSavedState = null; |
| 4533 | } |
| 4534 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4535 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4536 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4537 | setWorkspaceLoading(false); |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4538 | sendLoadingCompleteBroadcastIfNecessary(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 4539 | |
| 4540 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4541 | // widget configuration forced an orientation change), process them now. |
| 4542 | if (sPendingAddItem != null) { |
| 4543 | final long screenId = completeAdd(sPendingAddItem); |
| 4544 | |
| 4545 | // TODO: this moves the user to the page where the pending item was added. Ideally, |
| 4546 | // the screen would be guaranteed to exist after bind, and the page would be set through |
| 4547 | // the workspace restore process. |
| 4548 | mWorkspace.post(new Runnable() { |
| 4549 | @Override |
| 4550 | public void run() { |
| 4551 | mWorkspace.snapToScreenId(screenId); |
| 4552 | } |
| 4553 | }); |
| 4554 | sPendingAddItem = null; |
| 4555 | } |
| 4556 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4557 | if (upgradePath) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4558 | mWorkspace.getUniqueComponents(true, null); |
| 4559 | mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4560 | } |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4561 | PackageInstallerCompat.getInstance(this).onFinishBind(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4564 | private void sendLoadingCompleteBroadcastIfNecessary() { |
| 4565 | if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) { |
| 4566 | String permission = |
| 4567 | getResources().getString(R.string.receive_first_load_broadcast_permission); |
| 4568 | Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE); |
| 4569 | sendBroadcast(intent, permission); |
| 4570 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4571 | editor.putBoolean(FIRST_LOAD_COMPLETE, true); |
| 4572 | editor.apply(); |
| 4573 | } |
| 4574 | } |
| 4575 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4576 | public boolean isAllAppsButtonRank(int rank) { |
| 4577 | if (mHotseat != null) { |
| 4578 | return mHotseat.isAllAppsButtonRank(rank); |
| 4579 | } |
| 4580 | return false; |
| 4581 | } |
| 4582 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4583 | private boolean canRunNewAppsAnimation() { |
| 4584 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4585 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4586 | } |
| 4587 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4588 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4589 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4590 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4591 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4592 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4593 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4594 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4595 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4596 | return bounceAnim; |
| 4597 | } |
| 4598 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4599 | public boolean useVerticalBarLayout() { |
| 4600 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4601 | getDeviceProfile().isVerticalBarLayout(); |
| 4602 | } |
| 4603 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4604 | protected Rect getSearchBarBounds() { |
| 4605 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4606 | getDeviceProfile().getSearchBarBounds(); |
| 4607 | } |
| 4608 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4609 | @Override |
| 4610 | public void bindSearchablesChanged() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4611 | boolean searchVisible = updateGlobalSearchIcon(); |
| 4612 | boolean voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4613 | if (mSearchDropTargetBar != null) { |
| 4614 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 4615 | } |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4616 | } |
| 4617 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4618 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4619 | * Add the icons for all apps. |
| 4620 | * |
| 4621 | * Implementation of the method from LauncherModel.Callbacks. |
| 4622 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4623 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4624 | if (LauncherAppState.isDisableAllApps()) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4625 | if (mIntentsOnWorkspaceFromUpgradePath != null) { |
| 4626 | if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) { |
| 4627 | getHotseat().addAllAppsFolder(mIconCache, apps, |
| 4628 | mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace); |
| 4629 | } |
| 4630 | mIntentsOnWorkspaceFromUpgradePath = null; |
Daniel Sandler | 8707e0f | 2013-08-15 15:54:18 -0700 | [diff] [blame] | 4631 | } |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4632 | if (mAppsCustomizeContent != null) { |
| 4633 | mAppsCustomizeContent.onPackagesUpdated( |
| 4634 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
| 4635 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4636 | } else { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 4637 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4638 | mAppsCustomizeContent.setApps(apps); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 4639 | mAppsCustomizeContent.onPackagesUpdated( |
| 4640 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4641 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4642 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | /** |
| 4646 | * A package was updated. |
| 4647 | * |
| 4648 | * Implementation of the method from LauncherModel.Callbacks. |
| 4649 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4650 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4651 | Runnable r = new Runnable() { |
| 4652 | public void run() { |
| 4653 | bindAppsUpdated(apps); |
| 4654 | } |
| 4655 | }; |
| 4656 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4657 | return; |
| 4658 | } |
| 4659 | |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 4660 | if (mWorkspace != null) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4661 | mWorkspace.updateShortcutsAndWidgets(apps); |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 4662 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4663 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4664 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4665 | mAppsCustomizeContent != null) { |
| 4666 | mAppsCustomizeContent.updateApps(apps); |
| 4667 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4671 | * Update the state of a package, typically related to install state. |
| 4672 | * |
| 4673 | * Implementation of the method from LauncherModel.Callbacks. |
| 4674 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4675 | @Override |
| 4676 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4677 | if (mWorkspace != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4678 | mWorkspace.updatePackageState(installInfo); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4679 | } |
| 4680 | } |
| 4681 | |
| 4682 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4683 | * A package was uninstalled. We take both the super set of packageNames |
| 4684 | * in addition to specific applications to remove, the reason being that |
| 4685 | * this can be called when a package is updated as well. In that scenario, |
| 4686 | * we only remove specific components from the workspace, where as |
| 4687 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4688 | * |
| 4689 | * Implementation of the method from LauncherModel.Callbacks. |
| 4690 | */ |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4691 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4692 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4693 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4694 | public void run() { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4695 | bindComponentsRemoved(packageNames, appInfos, user); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4696 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4697 | }; |
| 4698 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4699 | return; |
| 4700 | } |
| 4701 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4702 | if (!packageNames.isEmpty()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4703 | mWorkspace.removeItemsByPackageName(packageNames, user); |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4704 | } |
| 4705 | if (!appInfos.isEmpty()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4706 | mWorkspace.removeItemsByApplicationInfo(appInfos, user); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 4707 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4708 | |
Winson Chung | a182096 | 2011-10-03 16:31:06 -0700 | [diff] [blame] | 4709 | // Notify the drag controller |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4710 | mDragController.onAppsRemoved(packageNames, appInfos); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4711 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4712 | // Update AllApps |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4713 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4714 | mAppsCustomizeContent != null) { |
| 4715 | mAppsCustomizeContent.removeApps(appInfos); |
| 4716 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4717 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4718 | |
| 4719 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4720 | * A number of packages were updated. |
| 4721 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4722 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 4723 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4724 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4725 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 4726 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4727 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4728 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4729 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 4730 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 4731 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4732 | return; |
| 4733 | } |
| 4734 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4735 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4736 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4737 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4738 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4741 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 4742 | final Display d = getWindowManager().getDefaultDisplay(); |
| 4743 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 4744 | switch (d.getRotation()) { |
| 4745 | case Surface.ROTATION_0: |
| 4746 | case Surface.ROTATION_180: |
| 4747 | // We are currently in the same basic orientation as the natural orientation |
| 4748 | naturalOri = configOri; |
| 4749 | break; |
| 4750 | case Surface.ROTATION_90: |
| 4751 | case Surface.ROTATION_270: |
| 4752 | // We are currently in the other basic orientation to the natural orientation |
| 4753 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 4754 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 4755 | break; |
| 4756 | } |
| 4757 | |
| 4758 | int[] oriMap = { |
| 4759 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 4760 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 4761 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 4762 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 4763 | }; |
| 4764 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 4765 | // is landscape. |
| 4766 | int indexOffset = 0; |
| 4767 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 4768 | indexOffset = 1; |
| 4769 | } |
| 4770 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 4771 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 4772 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4773 | public boolean isRotationEnabled() { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 4774 | boolean enableRotation = sForceEnableRotation || |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4775 | getResources().getBoolean(R.bool.allow_rotation); |
| 4776 | return enableRotation; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4777 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4778 | public void lockScreenOrientation() { |
| 4779 | if (isRotationEnabled()) { |
| 4780 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 4781 | .getConfiguration().orientation)); |
| 4782 | } |
| 4783 | } |
| 4784 | public void unlockScreenOrientation(boolean immediate) { |
| 4785 | if (isRotationEnabled()) { |
| 4786 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4787 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4788 | } else { |
| 4789 | mHandler.postDelayed(new Runnable() { |
| 4790 | public void run() { |
| 4791 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 4792 | } |
| 4793 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4794 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4795 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4796 | } |
| 4797 | |
Sandeep Siddhartha | d4d3d08 | 2013-12-26 15:42:52 -0800 | [diff] [blame] | 4798 | /** |
| 4799 | * Called when the SearchBar hint should be changed. |
| 4800 | * |
| 4801 | * @param hint the hint to be displayed in the search bar. |
| 4802 | */ |
| 4803 | protected void onSearchBarHintChanged(String hint) { |
Sunny Goyal | 424418b | 2014-08-22 16:09:37 -0700 | [diff] [blame] | 4804 | |
Sandeep Siddhartha | d4d3d08 | 2013-12-26 15:42:52 -0800 | [diff] [blame] | 4805 | } |
| 4806 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4807 | protected boolean isLauncherPreinstalled() { |
| 4808 | PackageManager pm = getPackageManager(); |
| 4809 | try { |
| 4810 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 4811 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4812 | return true; |
| 4813 | } else { |
| 4814 | return false; |
| 4815 | } |
| 4816 | } catch (NameNotFoundException e) { |
| 4817 | e.printStackTrace(); |
| 4818 | return false; |
| 4819 | } |
| 4820 | } |
| 4821 | |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4822 | /** |
| 4823 | * This method indicates whether or not we should suggest default wallpaper dimensions |
| 4824 | * when our wallpaper cropper was not yet used to set a wallpaper. |
| 4825 | */ |
| 4826 | protected boolean overrideWallpaperDimensions() { |
| 4827 | return true; |
| 4828 | } |
| 4829 | |
Adam Cohen | 5eed5d8 | 2014-05-19 13:12:13 -0700 | [diff] [blame] | 4830 | protected boolean shouldClingFocusHotseatApp() { |
| 4831 | return false; |
| 4832 | } |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 4833 | protected String getFirstRunClingSearchBarHint() { |
| 4834 | return ""; |
| 4835 | } |
| 4836 | protected String getFirstRunCustomContentHint() { |
| 4837 | return ""; |
| 4838 | } |
Winson Chung | 3a6e7f3 | 2013-10-09 15:50:52 -0700 | [diff] [blame] | 4839 | protected int getFirstRunFocusedHotseatAppDrawableId() { |
| 4840 | return -1; |
| 4841 | } |
| 4842 | protected ComponentName getFirstRunFocusedHotseatAppComponentName() { |
| 4843 | return null; |
| 4844 | } |
| 4845 | protected int getFirstRunFocusedHotseatAppRank() { |
| 4846 | return -1; |
| 4847 | } |
| 4848 | protected String getFirstRunFocusedHotseatAppBubbleTitle() { |
| 4849 | return ""; |
| 4850 | } |
| 4851 | protected String getFirstRunFocusedHotseatAppBubbleDescription() { |
| 4852 | return ""; |
| 4853 | } |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 4854 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4855 | /** |
| 4856 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 4857 | * before showing the standard launcher experience. |
| 4858 | */ |
| 4859 | protected boolean hasFirstRunActivity() { |
| 4860 | return false; |
| 4861 | } |
| 4862 | |
| 4863 | /** |
| 4864 | * To be overridden by subclasses to launch any first run activity |
| 4865 | */ |
| 4866 | protected Intent getFirstRunActivity() { |
| 4867 | return null; |
| 4868 | } |
| 4869 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4870 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4871 | return !ActivityManager.isRunningInTestHarness() && |
| 4872 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4873 | } |
| 4874 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 4875 | protected boolean hasRunFirstRunActivity() { |
| 4876 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 4877 | } |
| 4878 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4879 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4880 | if (shouldRunFirstRunActivity() && |
| 4881 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4882 | Intent firstRunIntent = getFirstRunActivity(); |
| 4883 | if (firstRunIntent != null) { |
| 4884 | startActivity(firstRunIntent); |
| 4885 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4886 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4887 | } |
| 4888 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4889 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4890 | } |
| 4891 | |
| 4892 | private void markFirstRunActivityShown() { |
| 4893 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4894 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 4895 | editor.apply(); |
| 4896 | } |
| 4897 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4898 | /** |
| 4899 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 4900 | * screen that must be displayed and dismissed. |
| 4901 | */ |
| 4902 | protected boolean hasDismissableIntroScreen() { |
| 4903 | return false; |
| 4904 | } |
| 4905 | |
| 4906 | /** |
| 4907 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 4908 | */ |
| 4909 | protected View getIntroScreen() { |
| 4910 | return null; |
| 4911 | } |
| 4912 | |
| 4913 | /** |
| 4914 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 4915 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 4916 | */ |
| 4917 | private boolean shouldShowIntroScreen() { |
| 4918 | return hasDismissableIntroScreen() && |
| 4919 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 4920 | } |
| 4921 | |
| 4922 | protected void showIntroScreen() { |
| 4923 | View introScreen = getIntroScreen(); |
| 4924 | changeWallpaperVisiblity(false); |
| 4925 | if (introScreen != null) { |
| 4926 | mDragLayer.showOverlayView(introScreen); |
| 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | public void dismissIntroScreen() { |
| 4931 | markIntroScreenDismissed(); |
| 4932 | if (showFirstRunActivity()) { |
| 4933 | // We delay hiding the intro view until the first run activity is showing. This |
| 4934 | // avoids a blip. |
| 4935 | mWorkspace.postDelayed(new Runnable() { |
| 4936 | @Override |
| 4937 | public void run() { |
| 4938 | mDragLayer.dismissOverlayView(); |
| 4939 | } |
| 4940 | }, ACTIVITY_START_DELAY); |
| 4941 | } else { |
| 4942 | mDragLayer.dismissOverlayView(); |
| 4943 | } |
| 4944 | changeWallpaperVisiblity(true); |
| 4945 | } |
| 4946 | |
| 4947 | private void markIntroScreenDismissed() { |
| 4948 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4949 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 4950 | editor.apply(); |
| 4951 | } |
| 4952 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4953 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4954 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 4955 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 4956 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 4957 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4961 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 4962 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 4963 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 4964 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4965 | } |
| 4966 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4967 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4968 | // Called from search suggestion, not supported in other profiles. |
| 4969 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 4970 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 4971 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 4972 | myUser); |
| 4973 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4974 | return null; |
| 4975 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4976 | return new AppInfo(this, activityInfo, myUser, mIconCache, null); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 4980 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4981 | // Called from search suggestion, not supported in other profiles. |
| 4982 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 4983 | UserHandleCompat.myUserHandle()); |
| 4984 | } |
| 4985 | |
| 4986 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 4987 | Bitmap icon, UserHandleCompat user) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 4988 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 4989 | CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 4990 | return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4991 | } |
| 4992 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 4993 | protected void moveWorkspaceToDefaultScreen() { |
| 4994 | mWorkspace.moveToDefaultScreen(false); |
| 4995 | } |
| 4996 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4997 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 4998 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 4999 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 5000 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5001 | } |
| 5002 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5003 | @Override |
| 5004 | public void onPageSwitch(View newPage, int newPageIndex) { |
| 5005 | } |
| 5006 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5007 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5008 | * Prints out out state for debugging. |
| 5009 | */ |
| 5010 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5011 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5012 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5013 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 5014 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 5015 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 5016 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 5017 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5018 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5019 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5020 | if (mAppsCustomizeContent != null) { |
| 5021 | mAppsCustomizeContent.dumpState(); |
| 5022 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5023 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5024 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5025 | |
| 5026 | @Override |
| 5027 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5028 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5029 | synchronized (sDumpLogs) { |
| 5030 | writer.println(" "); |
| 5031 | writer.println("Debug logs: "); |
| 5032 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5033 | writer.println(" " + sDumpLogs.get(i)); |
| 5034 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5035 | } |
| 5036 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5037 | |
| 5038 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5039 | if (DEBUG_DUMP_LOG) { |
| 5040 | synchronized (sDumpLogs) { |
| 5041 | Log.d(TAG, ""); |
| 5042 | Log.d(TAG, "*********************"); |
| 5043 | Log.d(TAG, "Launcher debug logs: "); |
| 5044 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5045 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 5046 | } |
| 5047 | Log.d(TAG, "*********************"); |
| 5048 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5049 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5050 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5054 | addDumpLog(tag, log, null, debugLog); |
| 5055 | } |
| 5056 | |
| 5057 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5058 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5059 | if (e != null) { |
| 5060 | Log.d(tag, log, e); |
| 5061 | } else { |
| 5062 | Log.d(tag, log); |
| 5063 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5064 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5065 | if (DEBUG_DUMP_LOG) { |
| 5066 | sDateStamp.setTime(System.currentTimeMillis()); |
| 5067 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5068 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 5069 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5070 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5071 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5072 | } |
| 5073 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5074 | public void dumpLogsToLocalData() { |
| 5075 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5076 | new AsyncTask<Void, Void, Void>() { |
| 5077 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5078 | boolean success = false; |
| 5079 | sDateStamp.setTime(sRunStart); |
| 5080 | String FILENAME = sDateStamp.getMonth() + "-" |
| 5081 | + sDateStamp.getDay() + "_" |
| 5082 | + sDateStamp.getHours() + "-" |
| 5083 | + sDateStamp.getMinutes() + "_" |
| 5084 | + sDateStamp.getSeconds() + ".txt"; |
| 5085 | |
| 5086 | FileOutputStream fos = null; |
| 5087 | File outFile = null; |
| 5088 | try { |
| 5089 | outFile = new File(getFilesDir(), FILENAME); |
| 5090 | outFile.createNewFile(); |
| 5091 | fos = new FileOutputStream(outFile); |
| 5092 | } catch (Exception e) { |
| 5093 | e.printStackTrace(); |
| 5094 | } |
| 5095 | if (fos != null) { |
| 5096 | PrintWriter writer = new PrintWriter(fos); |
| 5097 | |
| 5098 | writer.println(" "); |
| 5099 | writer.println("Debug logs: "); |
| 5100 | synchronized (sDumpLogs) { |
| 5101 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5102 | writer.println(" " + sDumpLogs.get(i)); |
| 5103 | } |
| 5104 | } |
| 5105 | writer.close(); |
| 5106 | } |
| 5107 | try { |
| 5108 | if (fos != null) { |
| 5109 | fos.close(); |
| 5110 | success = true; |
| 5111 | } |
| 5112 | } catch (IOException e) { |
| 5113 | e.printStackTrace(); |
| 5114 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5115 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5116 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5117 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5118 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5119 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5120 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5121 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 5122 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 5123 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 5124 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5125 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 5126 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5127 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5128 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 5129 | |
| 5130 | interface DebugIntents { |
| 5131 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 5132 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 5133 | } |