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 | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 53 | import android.database.sqlite.SQLiteDatabase; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 54 | import android.graphics.Bitmap; |
| 55 | import android.graphics.Canvas; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame] | 56 | import android.graphics.Color; |
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; |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 62 | import android.os.Build; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 63 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 64 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 65 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 66 | import android.os.Message; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 67 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 68 | import android.os.SystemClock; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 69 | import android.speech.RecognizerIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | import android.text.Selection; |
| 71 | import android.text.SpannableStringBuilder; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 72 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 73 | import android.text.method.TextKeyListener; |
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; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 88 | import android.view.ViewStub; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 89 | import android.view.ViewTreeObserver; |
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; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 95 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 96 | import android.widget.Advanceable; |
| 97 | import android.widget.FrameLayout; |
| 98 | import android.widget.ImageView; |
| 99 | import android.widget.TextView; |
| 100 | import android.widget.Toast; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 101 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 102 | import com.android.launcher3.DropTarget.DragObject; |
| 103 | import com.android.launcher3.PagedView.PageSwitchListener; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 104 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 105 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 106 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 107 | import com.android.launcher3.compat.PackageInstallerCompat; |
| 108 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 109 | import com.android.launcher3.compat.UserHandleCompat; |
| 110 | import com.android.launcher3.compat.UserManagerCompat; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 111 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 112 | import java.io.DataInputStream; |
| 113 | import java.io.DataOutputStream; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 114 | import java.io.File; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 115 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 116 | import java.io.FileNotFoundException; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 117 | import java.io.FileOutputStream; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 118 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 119 | import java.io.PrintWriter; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 120 | import java.lang.reflect.Field; |
| 121 | import java.lang.reflect.InvocationTargetException; |
| 122 | import java.lang.reflect.Method; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 123 | import java.text.DateFormat; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 124 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 125 | import java.util.Collection; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 126 | import java.util.Date; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 127 | import java.util.HashMap; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 128 | import java.util.HashSet; |
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 | |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 169 | // To turn on these properties, type |
| 170 | // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS] |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 171 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 172 | static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 173 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 174 | // The Intent extra that defines whether to ignore the launch animation |
| 175 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 176 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 177 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 178 | // Type: int |
| 179 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 180 | // Type: int |
| 181 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 182 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 183 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 184 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 185 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 186 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 187 | 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] | 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_Y = "launcher.add_cell_y"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 190 | // Type: boolean |
| 191 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 192 | // Type: long |
| 193 | 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] | 194 | // Type: int |
| 195 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 196 | // Type: int |
| 197 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 198 | // Type: parcelable |
| 199 | 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] | 200 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 201 | 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] | 202 | // Type: int[] |
| 203 | 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] | 204 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 205 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 206 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 207 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 208 | static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete"; |
| 209 | static final String ACTION_FIRST_LOAD_COMPLETE = |
| 210 | "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; |
| 211 | |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 212 | private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 213 | private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 214 | "com.android.launcher.toolbar_search_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 215 | private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 216 | "com.android.launcher.toolbar_voice_search_icon"; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 217 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 218 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 219 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 220 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 221 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 222 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 223 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 224 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 225 | private State mState = State.WORKSPACE; |
| 226 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 227 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 228 | private boolean mIsSafeModeEnabled; |
| 229 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 230 | LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl(); |
| 231 | LauncherOverlay mLauncherOverlay; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 232 | InsettableFrameLayout mLauncherOverlayContainer; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 233 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 234 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 235 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 236 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 237 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 238 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 239 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 240 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 241 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 242 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 243 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 244 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 245 | // How long to wait before the new-shortcut animation automatically pans the workspace |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 246 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 247 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 248 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 249 | private static final int SINGLE_FRAME_DELAY = 16; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 250 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 251 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 252 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 253 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 254 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 255 | private LayoutInflater mInflater; |
| 256 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 257 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 258 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 259 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 260 | private DragLayer mDragLayer; |
| 261 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 262 | private View mWeightWatcher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 263 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 264 | private AppWidgetManagerCompat mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 265 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 266 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 267 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 268 | private AppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 269 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 270 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 271 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 272 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 273 | private FolderInfo mFolderInfo; |
| 274 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 275 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 276 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 277 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 278 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 279 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 280 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 281 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 282 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 283 | private boolean mAutoAdvanceRunning = false; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 284 | private View mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 285 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 286 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 287 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 288 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 289 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 290 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 291 | |
| 292 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 293 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 294 | private boolean mWorkspaceLoading = true; |
| 295 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 296 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 297 | private boolean mRestoring; |
| 298 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 299 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 300 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 301 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 302 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 303 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 304 | private Bundle mSavedInstanceState; |
| 305 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 306 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 307 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 308 | private boolean mUserPresent = true; |
| 309 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 310 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 311 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 312 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 313 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 314 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 315 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 316 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 317 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 318 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 319 | // Related to the auto-advancing of widgets |
| 320 | private final int ADVANCE_MSG = 1; |
| 321 | private final int mAdvanceInterval = 20000; |
| 322 | private final int mAdvanceStagger = 250; |
| 323 | private long mAutoAdvanceSentTime; |
| 324 | private long mAutoAdvanceTimeLeft = -1; |
| 325 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 326 | new HashMap<View, AppWidgetProviderInfo>(); |
| 327 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 328 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 329 | // match the sensor state. |
| 330 | private final int mRestoreScreenOrientationDelay = 500; |
| 331 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 332 | // External icons saved in case of resource changes, orientation, etc. |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 333 | private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; |
| 334 | private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 335 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 336 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 337 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 338 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 339 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 340 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 341 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 342 | static Date sDateStamp = new Date(); |
| 343 | static DateFormat sDateFormat = |
| 344 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 345 | static long sRunStart = System.currentTimeMillis(); |
| 346 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 347 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 348 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 349 | // it from the context. |
| 350 | private SharedPreferences mSharedPrefs; |
| 351 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 352 | private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null; |
| 353 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 354 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 355 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 356 | private ImageView mFolderIconImageView; |
| 357 | private Bitmap mFolderIconBitmap; |
| 358 | private Canvas mFolderIconCanvas; |
| 359 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 360 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 361 | private BubbleTextView mWaitingForResume; |
| 362 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 363 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 364 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 365 | if (mWorkspace != null) { |
| 366 | mWorkspace.buildPageHardwareLayers(); |
| 367 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 368 | } |
| 369 | }; |
| 370 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 371 | private static PendingAddArguments sPendingAddItem; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 372 | |
| 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 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 387 | @Override |
| 388 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 389 | if (DEBUG_STRICT_MODE) { |
| 390 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 391 | .detectDiskReads() |
| 392 | .detectDiskWrites() |
| 393 | .detectNetwork() // or .detectAll() for all detectable problems |
| 394 | .penaltyLog() |
| 395 | .build()); |
| 396 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 397 | .detectLeakedSqlLiteObjects() |
| 398 | .detectLeakedClosableObjects() |
| 399 | .penaltyLog() |
| 400 | .penaltyDeath() |
| 401 | .build()); |
| 402 | } |
| 403 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 404 | if (mLauncherCallbacks != null) { |
| 405 | mLauncherCallbacks.preOnCreate(); |
| 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 | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 413 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 414 | // Lazy-initialize the dynamic grid |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 415 | DeviceProfile grid = app.initDynamicGrid(this); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 416 | |
| 417 | // 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] | 418 | mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 419 | Context.MODE_PRIVATE); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 420 | mIsSafeModeEnabled = getPackageManager().isSafeMode(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 421 | mModel = app.setLauncher(this); |
| 422 | mIconCache = app.getIconCache(); |
Winson Chung | e5467dc | 2013-10-14 17:03:04 -0700 | [diff] [blame] | 423 | mIconCache.flushInvalidIcons(grid); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 424 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 425 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 426 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 427 | mStats = new Stats(this); |
| 428 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 429 | mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 430 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 431 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 432 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 433 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 434 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 435 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 436 | // LauncherModel load. |
| 437 | mPaused = false; |
| 438 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 439 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 440 | android.os.Debug.startMethodTracing( |
| 441 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 445 | setContentView(R.layout.launcher); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 446 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 447 | setupViews(); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 448 | grid.layout(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 449 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 450 | registerContentObservers(); |
| 451 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 452 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 453 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 454 | mSavedState = savedInstanceState; |
| 455 | restoreState(mSavedState); |
| 456 | |
| 457 | if (PROFILE_STARTUP) { |
| 458 | android.os.Debug.stopMethodTracing(); |
| 459 | } |
| 460 | |
| 461 | if (!mRestoring) { |
Adam Cohen | db78dc8 | 2014-06-19 14:50:51 -0700 | [diff] [blame] | 462 | if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 463 | // If the user leaves launcher, then we should just load items asynchronously when |
| 464 | // they return. |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 465 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 466 | } else { |
| 467 | // We only load the page synchronously if the user rotates (or triggers a |
| 468 | // configuration change) while launcher is in the foreground |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 469 | mModel.startLoader(true, mWorkspace.getRestorePage()); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 470 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | // For handling default keys |
| 474 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 475 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 476 | |
| 477 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 478 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 479 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 480 | updateGlobalIcons(); |
| 481 | |
| 482 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 483 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 484 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 485 | if (mLauncherCallbacks != null) { |
| 486 | mLauncherCallbacks.onCreate(savedInstanceState); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 487 | if (mLauncherCallbacks.hasLauncherOverlay()) { |
| 488 | ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub); |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 489 | mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate(); |
| 490 | mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView( |
| 491 | mLauncherOverlayContainer, mLauncherOverlayCallbacks); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 492 | mWorkspace.setLauncherOverlay(mLauncherOverlay); |
| 493 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 494 | } |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 495 | |
| 496 | if (shouldShowIntroScreen()) { |
| 497 | showIntroScreen(); |
| 498 | } else { |
| 499 | showFirstRunActivity(); |
| 500 | showFirstRunClings(); |
| 501 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | private LauncherCallbacks mLauncherCallbacks; |
| 505 | |
| 506 | public void onPostCreate(Bundle savedInstanceState) { |
| 507 | super.onPostCreate(savedInstanceState); |
| 508 | if (mLauncherCallbacks != null) { |
| 509 | mLauncherCallbacks.onPostCreate(savedInstanceState); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { |
| 514 | mLauncherCallbacks = callbacks; |
| 515 | return true; |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 518 | @Override |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 519 | public void onLauncherProviderChange() { |
| 520 | if (mLauncherCallbacks != null) { |
| 521 | mLauncherCallbacks.onLauncherProviderChange(); |
| 522 | } |
| 523 | } |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 524 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 525 | /** To be overridden by subclasses to hint to Launcher that we have custom content */ |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 526 | protected boolean hasCustomContentToLeft() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 527 | if (mLauncherCallbacks != null) { |
| 528 | return mLauncherCallbacks.hasCustomContentToLeft(); |
| 529 | } |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 530 | return false; |
| 531 | } |
| 532 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 533 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 534 | * 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] | 535 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 536 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 537 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 538 | protected void populateCustomContentContainer() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 539 | if (mLauncherCallbacks != null) { |
| 540 | mLauncherCallbacks.populateCustomContentContainer(); |
| 541 | } |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 546 | * ensure the custom content page is added or removed if necessary. |
| 547 | */ |
| 548 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 549 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 550 | // Not bound yet, wait for bindScreens to be called. |
| 551 | return; |
| 552 | } |
| 553 | |
| 554 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 555 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 556 | mWorkspace.createCustomContentContainer(); |
| 557 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 558 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 559 | mWorkspace.removeCustomContentPage(); |
| 560 | } |
| 561 | } |
| 562 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 563 | private void updateGlobalIcons() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 564 | boolean searchVisible = false; |
| 565 | boolean voiceVisible = false; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 566 | // 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] | 567 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
Adam Cohen | a00673c | 2014-08-14 12:57:28 -0700 | [diff] [blame] | 568 | if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 569 | searchVisible = updateGlobalSearchIcon(); |
| 570 | voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 571 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 572 | if (sGlobalSearchIcon[coi] != null) { |
| 573 | updateGlobalSearchIcon(sGlobalSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 574 | searchVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 575 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 576 | if (sVoiceSearchIcon[coi] != null) { |
| 577 | updateVoiceSearchIcon(sVoiceSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 578 | voiceVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 579 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 580 | if (mSearchDropTargetBar != null) { |
| 581 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 582 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 583 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 584 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 585 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 586 | if (sLocaleConfiguration == null) { |
| 587 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 588 | @Override |
| 589 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 590 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 591 | readConfiguration(Launcher.this, localeConfiguration); |
| 592 | return localeConfiguration; |
| 593 | } |
| 594 | |
| 595 | @Override |
| 596 | protected void onPostExecute(LocaleConfiguration result) { |
| 597 | sLocaleConfiguration = result; |
| 598 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 599 | } |
| 600 | }.execute(); |
| 601 | return; |
| 602 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 603 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 604 | final Configuration configuration = getResources().getConfiguration(); |
| 605 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 606 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 607 | final String locale = configuration.locale.toString(); |
| 608 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 609 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 610 | final int mcc = configuration.mcc; |
| 611 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 612 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 613 | final int mnc = configuration.mnc; |
| 614 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 615 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 616 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 617 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 618 | sLocaleConfiguration.locale = locale; |
| 619 | sLocaleConfiguration.mcc = mcc; |
| 620 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 621 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 622 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 623 | |
| 624 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 625 | new AsyncTask<Void, Void, Void>() { |
| 626 | public Void doInBackground(Void ... args) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 627 | writeConfiguration(Launcher.this, localeConfiguration); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 628 | return null; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 629 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 630 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
| 634 | private static class LocaleConfiguration { |
| 635 | public String locale; |
| 636 | public int mcc = -1; |
| 637 | public int mnc = -1; |
| 638 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 639 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 640 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 641 | DataInputStream in = null; |
| 642 | try { |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 643 | in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 644 | configuration.locale = in.readUTF(); |
| 645 | configuration.mcc = in.readInt(); |
| 646 | configuration.mnc = in.readInt(); |
| 647 | } catch (FileNotFoundException e) { |
| 648 | // Ignore |
| 649 | } catch (IOException e) { |
| 650 | // Ignore |
| 651 | } finally { |
| 652 | if (in != null) { |
| 653 | try { |
| 654 | in.close(); |
| 655 | } catch (IOException e) { |
| 656 | // Ignore |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 663 | DataOutputStream out = null; |
| 664 | try { |
Helena Josol | 4fbbb3e | 2014-10-06 16:06:46 +0100 | [diff] [blame] | 665 | out = new DataOutputStream(context.openFileOutput( |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 666 | LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 667 | out.writeUTF(configuration.locale); |
| 668 | out.writeInt(configuration.mcc); |
| 669 | out.writeInt(configuration.mnc); |
| 670 | out.flush(); |
| 671 | } catch (FileNotFoundException e) { |
| 672 | // Ignore |
| 673 | } catch (IOException e) { |
| 674 | //noinspection ResultOfMethodCallIgnored |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 675 | context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 676 | } finally { |
| 677 | if (out != null) { |
| 678 | try { |
| 679 | out.close(); |
| 680 | } catch (IOException e) { |
| 681 | // Ignore |
| 682 | } |
| 683 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 687 | public Stats getStats() { |
| 688 | return mStats; |
| 689 | } |
| 690 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 691 | public LayoutInflater getInflater() { |
| 692 | return mInflater; |
| 693 | } |
| 694 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 695 | boolean isDraggingEnabled() { |
| 696 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 697 | // that is subsequently removed from the workspace in startBinding(). |
| 698 | return !mModel.isLoadingWorkspace(); |
| 699 | } |
| 700 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 701 | static int getScreen() { |
| 702 | synchronized (sLock) { |
| 703 | return sScreen; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | static void setScreen(int screen) { |
| 708 | synchronized (sLock) { |
| 709 | sScreen = screen; |
| 710 | } |
| 711 | } |
| 712 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 713 | public static int generateViewId() { |
Ian Parkinson | 0c2918f | 2014-10-06 14:24:31 +0100 | [diff] [blame] | 714 | if (Build.VERSION.SDK_INT >= 17) { |
| 715 | return View.generateViewId(); |
| 716 | } else { |
| 717 | // View.generateViewId() is not available. The following fallback logic is a copy |
| 718 | // of its implementation. |
| 719 | for (;;) { |
| 720 | final int result = sNextGeneratedId.get(); |
| 721 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 722 | int newValue = result + 1; |
| 723 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 724 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 725 | return result; |
| 726 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | public int getViewIdForItem(ItemInfo info) { |
| 732 | // This cast is safe given the > 2B range for int. |
| 733 | int itemId = (int) info.id; |
| 734 | if (mItemIdToViewId.containsKey(itemId)) { |
| 735 | return mItemIdToViewId.get(itemId); |
| 736 | } |
| 737 | int viewId = generateViewId(); |
| 738 | mItemIdToViewId.put(itemId, viewId); |
| 739 | return viewId; |
| 740 | } |
| 741 | |
| 742 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 743 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 744 | * a configuration step, this allows the proper animations to run after other transitions. |
| 745 | */ |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 746 | private long completeAdd(PendingAddArguments args) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 747 | long screenId = args.screenId; |
| 748 | if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 749 | // When the screen id represents an actual screen (as opposed to a rank) we make sure |
| 750 | // that the drop page actually exists. |
| 751 | screenId = ensurePendingDropLayoutExists(args.screenId); |
| 752 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 753 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 754 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 755 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 756 | completeAddShortcut(args.intent, args.container, screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 757 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 758 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 759 | case REQUEST_CREATE_APPWIDGET: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 760 | completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 761 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 762 | case REQUEST_RECONFIGURE_APPWIDGET: |
| 763 | completeRestoreAppWidget(args.appWidgetId); |
| 764 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 765 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 766 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 767 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 768 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 769 | resetAddInfo(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 770 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 771 | } |
| 772 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 773 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 774 | protected void onActivityResult( |
| 775 | final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 776 | // Reset the startActivity waiting flag |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 777 | setWaitingForResult(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 778 | final int pendingAddWidgetId = mPendingAddWidgetId; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 779 | mPendingAddWidgetId = -1; |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 780 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 781 | Runnable exitSpringLoaded = new Runnable() { |
| 782 | @Override |
| 783 | public void run() { |
| 784 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 785 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 786 | } |
| 787 | }; |
| 788 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 789 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 790 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 791 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 792 | if (resultCode == RESULT_CANCELED) { |
| 793 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 794 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 795 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 796 | } else if (resultCode == RESULT_OK) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 797 | addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, |
| 798 | mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 799 | } |
| 800 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 801 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 802 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
| 803 | mWorkspace.exitOverviewMode(false); |
| 804 | } |
| 805 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 806 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 807 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 808 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 809 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 810 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 811 | final boolean workspaceLocked = isWorkspaceLocked(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 812 | // We have special handling for widgets |
| 813 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 814 | final int appWidgetId; |
| 815 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 816 | : -1; |
| 817 | if (widgetId < 0) { |
| 818 | appWidgetId = pendingAddWidgetId; |
| 819 | } else { |
| 820 | appWidgetId = widgetId; |
| 821 | } |
| 822 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 823 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 824 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 825 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 826 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 827 | result = RESULT_CANCELED; |
| 828 | completeTwoStageWidgetDrop(result, appWidgetId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 829 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 830 | @Override |
| 831 | public void run() { |
| 832 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 833 | } |
| 834 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 835 | if (workspaceLocked) { |
| 836 | // No need to remove the empty screen if we're mid-binding, as the |
| 837 | // the bind will not add the empty screen. |
| 838 | mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
| 839 | } else { |
| 840 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 841 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 842 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 843 | } else { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 844 | if (!workspaceLocked) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 845 | if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 846 | // When the screen id represents an actual screen (as opposed to a rank) |
| 847 | // we make sure that the drop page actually exists. |
| 848 | mPendingAddInfo.screenId = |
| 849 | ensurePendingDropLayoutExists(mPendingAddInfo.screenId); |
| 850 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 851 | final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
| 852 | |
| 853 | dropLayout.setDropPending(true); |
| 854 | final Runnable onComplete = new Runnable() { |
| 855 | @Override |
| 856 | public void run() { |
| 857 | completeTwoStageWidgetDrop(resultCode, appWidgetId); |
| 858 | dropLayout.setDropPending(false); |
| 859 | } |
| 860 | }; |
| 861 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 862 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 863 | } else { |
| 864 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId, |
| 865 | mPendingAddInfo); |
| 866 | sPendingAddItem = args; |
| 867 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 868 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 869 | return; |
| 870 | } |
| 871 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 872 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) { |
| 873 | if (resultCode == RESULT_OK) { |
| 874 | // Update the widget view. |
| 875 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, |
| 876 | pendingAddWidgetId, mPendingAddInfo); |
| 877 | if (workspaceLocked) { |
| 878 | sPendingAddItem = args; |
| 879 | } else { |
| 880 | completeAdd(args); |
| 881 | } |
| 882 | } |
| 883 | // Leave the widget in the pending state if the user canceled the configure. |
| 884 | return; |
| 885 | } |
| 886 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 887 | // The pattern used here is that a user PICKs a specific application, |
| 888 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 889 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 890 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 891 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Winson Chung | c7da555 | 2011-08-10 15:28:45 -0700 | [diff] [blame] | 892 | if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 893 | final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1, |
| 894 | mPendingAddInfo); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 895 | if (isWorkspaceLocked()) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 896 | sPendingAddItem = args; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 897 | } else { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 898 | completeAdd(args); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 899 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 900 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 901 | } |
Adam Cohen | 0007472 | 2013-10-11 17:46:09 -0700 | [diff] [blame] | 902 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 903 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 904 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 905 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 906 | mDragLayer.clearAnimatedView(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 907 | } |
| 908 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 909 | private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int |
| 910 | appWidgetId, ItemInfo info) { |
| 911 | PendingAddArguments args = new PendingAddArguments(); |
| 912 | args.requestCode = requestCode; |
| 913 | args.intent = data; |
| 914 | args.container = info.container; |
| 915 | args.screenId = info.screenId; |
| 916 | args.cellX = info.cellX; |
| 917 | args.cellY = info.cellY; |
| 918 | args.appWidgetId = appWidgetId; |
| 919 | return args; |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 924 | * |
| 925 | * @param screenId the screen id to check |
| 926 | * @return the new screen, or screenId if it exists |
| 927 | */ |
| 928 | private long ensurePendingDropLayoutExists(long screenId) { |
| 929 | CellLayout dropLayout = |
| 930 | (CellLayout) mWorkspace.getScreenWithId(screenId); |
| 931 | if (dropLayout == null) { |
| 932 | // it's possible that the add screen was removed because it was |
| 933 | // empty and a re-bind occurred |
| 934 | mWorkspace.addExtraEmptyScreen(); |
| 935 | return mWorkspace.commitExtraEmptyScreen(); |
| 936 | } else { |
| 937 | return screenId; |
| 938 | } |
| 939 | } |
| 940 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 941 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 942 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 943 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 944 | Runnable onCompleteRunnable = null; |
| 945 | int animationType = 0; |
| 946 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 947 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 948 | if (resultCode == RESULT_OK) { |
| 949 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 950 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 951 | mPendingAddWidgetInfo); |
| 952 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 953 | onCompleteRunnable = new Runnable() { |
| 954 | @Override |
| 955 | public void run() { |
| 956 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 957 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 958 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 959 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 960 | } |
| 961 | }; |
| 962 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 963 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 964 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 965 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 966 | if (mDragLayer.getAnimatedView() != null) { |
| 967 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 968 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 969 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 970 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 971 | // The animated view may be null in the case of a rotation during widget configuration |
| 972 | onCompleteRunnable.run(); |
| 973 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 977 | protected void onStop() { |
| 978 | super.onStop(); |
| 979 | FirstFrameAnimatorHelper.setIsVisible(false); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 980 | |
| 981 | if (mLauncherCallbacks != null) { |
| 982 | mLauncherCallbacks.onStop(); |
| 983 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | @Override |
| 987 | protected void onStart() { |
| 988 | super.onStart(); |
| 989 | FirstFrameAnimatorHelper.setIsVisible(true); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 990 | |
| 991 | if (mLauncherCallbacks != null) { |
| 992 | mLauncherCallbacks.onStart(); |
| 993 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 997 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 998 | long startTime = 0; |
| 999 | if (DEBUG_RESUME_TIME) { |
| 1000 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1001 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1002 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1003 | |
| 1004 | if (mLauncherCallbacks != null) { |
| 1005 | mLauncherCallbacks.preOnResume(); |
| 1006 | } |
| 1007 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1008 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1009 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1010 | // Restore the previous launcher state |
| 1011 | if (mOnResumeState == State.WORKSPACE) { |
| 1012 | showWorkspace(false); |
| 1013 | } else if (mOnResumeState == State.APPS_CUSTOMIZE) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 1014 | showAllApps(false, mAppsCustomizeContent.getContentType(), false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1015 | } |
| 1016 | mOnResumeState = State.NONE; |
| 1017 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1018 | // Background was set to gradient in onPause(), restore to black if in all apps. |
| 1019 | setWorkspaceBackground(mState == State.WORKSPACE); |
| 1020 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1021 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1022 | if (mRestoring || mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1023 | setWorkspaceLoading(true); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 1024 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1025 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1026 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1027 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1028 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1029 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 1030 | // execute them here |
| 1031 | long startTimeCallbacks = 0; |
| 1032 | if (DEBUG_RESUME_TIME) { |
| 1033 | startTimeCallbacks = System.currentTimeMillis(); |
| 1034 | } |
| 1035 | |
| 1036 | if (mAppsCustomizeContent != null) { |
| 1037 | mAppsCustomizeContent.setBulkBind(true); |
| 1038 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1039 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 1040 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1041 | } |
| 1042 | if (mAppsCustomizeContent != null) { |
| 1043 | mAppsCustomizeContent.setBulkBind(false); |
| 1044 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1045 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1046 | if (DEBUG_RESUME_TIME) { |
| 1047 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 1048 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 1049 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1050 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 1051 | if (mOnResumeCallbacks.size() > 0) { |
| 1052 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 1053 | mOnResumeCallbacks.get(i).run(); |
| 1054 | } |
| 1055 | mOnResumeCallbacks.clear(); |
| 1056 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1057 | |
| 1058 | // Reset the pressed state of icons that were locked in the press state while activities |
| 1059 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1060 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1061 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1062 | mWaitingForResume.setStayPressed(false); |
| 1063 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 1064 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1065 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 1066 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 1067 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 1068 | // orientation. |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1069 | getWorkspace().reinflateWidgetsIfNecessary(); |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1070 | |
Winson Chung | 780fe59 | 2013-09-26 14:48:44 -0700 | [diff] [blame] | 1071 | // Process any items that were added while Launcher was away. |
| 1072 | InstallShortcutReceiver.disableAndFlushInstallQueue(this); |
| 1073 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 1074 | // Update the voice search button proxy |
| 1075 | updateVoiceButtonProxyVisible(false); |
| 1076 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1077 | // Again, as with the above scenario, it's possible that one or more of the global icons |
| 1078 | // were updated in the wrong orientation. |
| 1079 | updateGlobalIcons(); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1080 | if (DEBUG_RESUME_TIME) { |
| 1081 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1082 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1083 | |
| 1084 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1085 | // If we are resuming and the custom content is the current page, we call onShow(). |
| 1086 | // It is also poassible that onShow will instead be called slightly after first layout |
| 1087 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1088 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1089 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1090 | } |
| 1091 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 1092 | mWorkspace.updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1093 | mWorkspace.onResume(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1094 | |
| 1095 | PackageInstallerCompat.getInstance(this).onResume(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1096 | |
| 1097 | if (mLauncherCallbacks != null) { |
| 1098 | mLauncherCallbacks.onResume(); |
| 1099 | } |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1102 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1103 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1104 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1105 | InstallShortcutReceiver.enableInstallQueue(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1106 | PackageInstallerCompat.getInstance(this).onPause(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1107 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1108 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1109 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1110 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1111 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1112 | |
| 1113 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1114 | // debounce excess onHide calls. |
| 1115 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1116 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1117 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1118 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1119 | if (mLauncherCallbacks != null) { |
| 1120 | mLauncherCallbacks.onPause(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1121 | } |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1125 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1126 | // by a onResume or by scrolling otherwise. |
| 1127 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1128 | |
| 1129 | // Custom content is completely hidden |
| 1130 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1131 | |
| 1132 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1133 | public void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1134 | |
| 1135 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1136 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1139 | public interface LauncherOverlay { |
| 1140 | |
| 1141 | /** |
| 1142 | * Touch interaction leading to overscroll has begun |
| 1143 | */ |
| 1144 | public void onScrollInteractionBegin(); |
| 1145 | |
| 1146 | /** |
| 1147 | * Touch interaction related to overscroll has ended |
| 1148 | */ |
| 1149 | public void onScrollInteractionEnd(); |
| 1150 | |
| 1151 | /** |
| 1152 | * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost |
| 1153 | * screen (or in the case of RTL, the rightmost screen). |
| 1154 | */ |
| 1155 | public void onScrollChange(int progress, boolean rtl); |
| 1156 | |
| 1157 | /** |
| 1158 | * Screen has stopped scrolling |
| 1159 | */ |
| 1160 | public void onScrollSettled(); |
| 1161 | |
| 1162 | /** |
| 1163 | * This method can be called by the Launcher in order to force the LauncherOverlay |
| 1164 | * to exit fully immersive mode. |
| 1165 | */ |
| 1166 | public void forceExitFullImmersion(); |
| 1167 | } |
| 1168 | |
| 1169 | public interface LauncherOverlayCallbacks { |
| 1170 | /** |
| 1171 | * This method indicates whether a call to {@link #enterFullImmersion()} will succeed, |
| 1172 | * however it doesn't modify any state within the launcher. |
| 1173 | */ |
| 1174 | public boolean canEnterFullImmersion(); |
| 1175 | |
| 1176 | /** |
| 1177 | * Should be called to tell Launcher that the LauncherOverlay will take over interaction, |
| 1178 | * eg. by occupying the full screen and handling all touch events. |
| 1179 | * |
| 1180 | * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this |
| 1181 | * case, Launcher will modify any necessary state and assumes the overlay is |
| 1182 | * handling all interaction. If false, the LauncherOverlay should cancel any |
| 1183 | * |
| 1184 | */ |
| 1185 | public boolean enterFullImmersion(); |
| 1186 | |
| 1187 | /** |
| 1188 | * Must be called when exiting fully immersive mode. Indicates to Launcher that it has |
| 1189 | * full control over UI and state. |
| 1190 | */ |
| 1191 | public void exitFullImmersion(); |
| 1192 | } |
| 1193 | |
| 1194 | class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks { |
| 1195 | |
| 1196 | @Override |
| 1197 | public boolean canEnterFullImmersion() { |
| 1198 | return mState == State.WORKSPACE; |
| 1199 | } |
| 1200 | |
| 1201 | @Override |
| 1202 | public boolean enterFullImmersion() { |
| 1203 | if (mState == State.WORKSPACE) { |
| 1204 | // When fully immersed, disregard any touches which fall through. |
| 1205 | mDragLayer.setBlockTouch(true); |
| 1206 | return true; |
| 1207 | } |
| 1208 | return false; |
| 1209 | } |
| 1210 | |
| 1211 | @Override |
| 1212 | public void exitFullImmersion() { |
| 1213 | mDragLayer.setBlockTouch(false); |
| 1214 | } |
| 1215 | } |
| 1216 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1217 | protected boolean hasSettings() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1218 | if (mLauncherCallbacks != null) { |
| 1219 | return mLauncherCallbacks.hasSettings(); |
| 1220 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1221 | return false; |
| 1222 | } |
| 1223 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1224 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1225 | public void addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1226 | CustomContentCallbacks callbacks, String description) { |
| 1227 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1230 | // The custom content needs to offset its content to account for the QSB |
| 1231 | public int getTopOffsetForCustomContent() { |
| 1232 | return mWorkspace.getPaddingTop(); |
| 1233 | } |
| 1234 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1235 | @Override |
| 1236 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1237 | // Flag the loader to stop early before switching |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1238 | if (mModel.isCurrentCallbacks(this)) { |
| 1239 | mModel.stopLoader(); |
| 1240 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1241 | if (mAppsCustomizeContent != null) { |
| 1242 | mAppsCustomizeContent.surrender(); |
| 1243 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1244 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1245 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1246 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1247 | // 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] | 1248 | @Override |
| 1249 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1250 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1251 | mHasFocus = hasFocus; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1252 | |
| 1253 | if (mLauncherCallbacks != null) { |
| 1254 | mLauncherCallbacks.onWindowFocusChanged(hasFocus); |
| 1255 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1256 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1257 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1258 | private boolean acceptFilter() { |
| 1259 | final InputMethodManager inputManager = (InputMethodManager) |
| 1260 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1261 | return !inputManager.isFullscreenMode(); |
| 1262 | } |
| 1263 | |
| 1264 | @Override |
| 1265 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1266 | final int uniChar = event.getUnicodeChar(); |
| 1267 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1268 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1269 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1270 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1271 | keyCode, event); |
| 1272 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1273 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1274 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1275 | // showSearchDialog() |
| 1276 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1277 | // onSearchRequested() will be called for every keystroke, |
| 1278 | // but it is idempotent, so it's fine. |
| 1279 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1280 | } |
| 1281 | } |
| 1282 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1283 | // Eat the long press event so the keyboard doesn't come up. |
| 1284 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1285 | return true; |
| 1286 | } |
| 1287 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1288 | return handled; |
| 1289 | } |
| 1290 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1291 | private String getTypedText() { |
| 1292 | return mDefaultKeySsb.toString(); |
| 1293 | } |
| 1294 | |
| 1295 | private void clearTypedText() { |
| 1296 | mDefaultKeySsb.clear(); |
| 1297 | mDefaultKeySsb.clearSpans(); |
| 1298 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1299 | } |
| 1300 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1301 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1302 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1303 | * State |
| 1304 | */ |
| 1305 | private static State intToState(int stateOrdinal) { |
| 1306 | State state = State.WORKSPACE; |
| 1307 | final State[] stateValues = State.values(); |
| 1308 | for (int i = 0; i < stateValues.length; i++) { |
| 1309 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1310 | state = stateValues[i]; |
| 1311 | break; |
| 1312 | } |
| 1313 | } |
| 1314 | return state; |
| 1315 | } |
| 1316 | |
| 1317 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1318 | * Restores the previous state, if it exists. |
| 1319 | * |
| 1320 | * @param savedState The previous state. |
| 1321 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1322 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1323 | private void restoreState(Bundle savedState) { |
| 1324 | if (savedState == null) { |
| 1325 | return; |
| 1326 | } |
| 1327 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1328 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1329 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1330 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1333 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1334 | PagedView.INVALID_RESTORE_PAGE); |
| 1335 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1336 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1337 | } |
| 1338 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1339 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1340 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1341 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1342 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1343 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1344 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1345 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1346 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1347 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1348 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 1349 | mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1350 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1351 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1352 | mRestoring = true; |
| 1353 | } |
| 1354 | |
| 1355 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1356 | if (renameFolder) { |
| 1357 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1358 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1359 | mRestoring = true; |
| 1360 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1361 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1362 | // Restore the AppsCustomize tab |
| 1363 | if (mAppsCustomizeTabHost != null) { |
| 1364 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1365 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1366 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1367 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1368 | mAppsCustomizeContent.loadAssociatedPages( |
| 1369 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1372 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1373 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1374 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1375 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1376 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | /** |
| 1380 | * Finds all the views we need and configure them properly. |
| 1381 | */ |
| 1382 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1383 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1384 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1385 | mLauncherView = findViewById(R.id.launcher); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1386 | mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1387 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1388 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1389 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1390 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1391 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1392 | mLauncherView.setSystemUiVisibility( |
| 1393 | 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] | 1394 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1395 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1396 | // Setup the drag layer |
| 1397 | mDragLayer.setup(this, dragController); |
| 1398 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1399 | // Setup the hotseat |
| 1400 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1401 | if (mHotseat != null) { |
| 1402 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1403 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1406 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1407 | View widgetButton = findViewById(R.id.widget_button); |
| 1408 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1409 | @Override |
| 1410 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1411 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1412 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1413 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1414 | } |
| 1415 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1416 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1417 | |
| 1418 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1419 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1420 | @Override |
| 1421 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1422 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1423 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1424 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1425 | } |
| 1426 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1427 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1428 | |
| 1429 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1430 | if (hasSettings()) { |
| 1431 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1432 | @Override |
| 1433 | public void onClick(View arg0) { |
| 1434 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1435 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1436 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1437 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1438 | }); |
| 1439 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1440 | } else { |
| 1441 | settingsButton.setVisibility(View.GONE); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1442 | } |
| 1443 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1444 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1445 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1446 | // Setup the workspace |
| 1447 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1448 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1449 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1450 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1451 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1452 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1453 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1454 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1455 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1456 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1457 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1458 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1459 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1460 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1461 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1462 | // 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] | 1463 | dragController.setDragScoller(mWorkspace); |
| 1464 | dragController.setScrollView(mDragLayer); |
| 1465 | dragController.setMoveTarget(mWorkspace); |
| 1466 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1467 | if (mSearchDropTargetBar != null) { |
| 1468 | mSearchDropTargetBar.setup(this, dragController); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1469 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1470 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1471 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1472 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1473 | mWeightWatcher = new WeightWatcher(this); |
| 1474 | mWeightWatcher.setAlpha(0.5f); |
| 1475 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1476 | new FrameLayout.LayoutParams( |
| 1477 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1478 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1479 | Gravity.BOTTOM) |
| 1480 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1481 | |
| 1482 | boolean show = shouldShowWeightWatcher(); |
| 1483 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1484 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1488 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1489 | */ |
| 1490 | public void setAllAppsButton(View allAppsButton) { |
| 1491 | mAllAppsButton = allAppsButton; |
| 1492 | } |
| 1493 | |
| 1494 | public View getAllAppsButton() { |
| 1495 | return mAllAppsButton; |
| 1496 | } |
| 1497 | |
| 1498 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1499 | * Creates a view representing a shortcut. |
| 1500 | * |
| 1501 | * @param info The data structure describing the shortcut. |
| 1502 | * |
| 1503 | * @return A View inflated from R.layout.application. |
| 1504 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1505 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1506 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1507 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1512 | * |
| 1513 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1514 | * @param parent The group the shortcut belongs to. |
| 1515 | * @param info The data structure describing the shortcut. |
| 1516 | * |
| 1517 | * @return A View inflated from layoutResId. |
| 1518 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1519 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1520 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 1521 | favorite.applyFromShortcutInfo(info, mIconCache, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1522 | favorite.setOnClickListener(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1523 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1524 | return favorite; |
| 1525 | } |
| 1526 | |
| 1527 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1528 | * Add a shortcut to the workspace. |
| 1529 | * |
| 1530 | * @param data The intent describing the shortcut. |
| 1531 | * @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] | 1532 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1533 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1534 | int cellY) { |
| 1535 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1536 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1537 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1538 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1539 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1540 | |
Sunny Goyal | 2350bc9 | 2014-10-14 16:42:54 -0700 | [diff] [blame] | 1541 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1542 | if (info == null) { |
| 1543 | return; |
| 1544 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1545 | final View view = createShortcut(info); |
| 1546 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1547 | // First we check if we already know the exact location where we want to add this item. |
| 1548 | if (cellX >= 0 && cellY >= 0) { |
| 1549 | cellXY[0] = cellX; |
| 1550 | cellXY[1] = cellY; |
| 1551 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1552 | |
| 1553 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1554 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1555 | true, null,null)) { |
| 1556 | return; |
| 1557 | } |
| 1558 | DragObject dragObject = new DragObject(); |
| 1559 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1560 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1561 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1562 | return; |
| 1563 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1564 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1565 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1566 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1567 | foundCellSpan = (result != null); |
| 1568 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1569 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1573 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1574 | return; |
| 1575 | } |
| 1576 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1577 | 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] | 1578 | |
| 1579 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1580 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1581 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1585 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1586 | int minHeight) { |
| 1587 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1588 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1589 | // to ensure that it gets the full amount of space that it has requested |
| 1590 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1591 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1592 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1595 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1596 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1599 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1600 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1603 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1604 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1607 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1608 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1609 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1610 | } |
| 1611 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1612 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1613 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1614 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1615 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1616 | * @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] | 1617 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1618 | private void completeAddAppWidget(final int appWidgetId, long container, long screenId, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1619 | AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1620 | if (appWidgetInfo == null) { |
| 1621 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1622 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1623 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1624 | // Calculate the grid spans needed to fit this widget |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1625 | CellLayout layout = getCellLayout(container, screenId); |
Adam Cohen | 0935386 | 2011-07-14 16:10:03 -0700 | [diff] [blame] | 1626 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1627 | int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo); |
| 1628 | int[] spanXY = getSpanForWidget(this, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1629 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1630 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1631 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1632 | // if we are placing widgets on a "spring-loaded" screen |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1633 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1634 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1635 | int[] finalSpan = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1636 | boolean foundCellSpan = false; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1637 | if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { |
| 1638 | cellXY[0] = mPendingAddInfo.cellX; |
| 1639 | cellXY[1] = mPendingAddInfo.cellY; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1640 | spanXY[0] = mPendingAddInfo.spanX; |
| 1641 | spanXY[1] = mPendingAddInfo.spanY; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1642 | foundCellSpan = true; |
| 1643 | } else if (touchXY != null) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1644 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1645 | int[] result = layout.findNearestVacantArea( |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1646 | touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], |
| 1647 | spanXY[1], cellXY, finalSpan); |
| 1648 | spanXY[0] = finalSpan[0]; |
| 1649 | spanXY[1] = finalSpan[1]; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1650 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1651 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1652 | foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1655 | if (!foundCellSpan) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1656 | if (appWidgetId != -1) { |
| 1657 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 1658 | // to the caller... |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1659 | new AsyncTask<Void, Void, Void>() { |
| 1660 | public Void doInBackground(Void ... args) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1661 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1662 | return null; |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1663 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1664 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1665 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1666 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1667 | return; |
| 1668 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1669 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1670 | // Build Launcher-specific widget info and save to database |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 1671 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, |
| 1672 | appWidgetInfo.provider); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1673 | launcherInfo.spanX = spanXY[0]; |
| 1674 | launcherInfo.spanY = spanXY[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1675 | launcherInfo.minSpanX = mPendingAddInfo.minSpanX; |
| 1676 | launcherInfo.minSpanY = mPendingAddInfo.minSpanY; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1677 | launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1678 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1679 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1680 | container, screenId, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1681 | |
| 1682 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1683 | if (hostView == null) { |
| 1684 | // Perform actual inflation because we're live |
| 1685 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1686 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1687 | } else { |
| 1688 | // The AppWidgetHostView has already been inflated and instantiated |
| 1689 | launcherInfo.hostView = hostView; |
| 1690 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1691 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1692 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1693 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1694 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1695 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1696 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1697 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1698 | |
| 1699 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1700 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1701 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1702 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1703 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1704 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1705 | @Override |
| 1706 | public void onReceive(Context context, Intent intent) { |
| 1707 | final String action = intent.getAction(); |
| 1708 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1709 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1710 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1711 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1712 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1713 | // 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] | 1714 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1715 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1716 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1717 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1718 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1719 | mUserPresent = true; |
| 1720 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1721 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1722 | mModel.resetLoadedState(false, true); |
| 1723 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1724 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1725 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1726 | mModel.resetLoadedState(false, true); |
| 1727 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1728 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1729 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1730 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1731 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1732 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1733 | } |
| 1734 | } |
| 1735 | }; |
| 1736 | |
| 1737 | @Override |
| 1738 | public void onAttachedToWindow() { |
| 1739 | super.onAttachedToWindow(); |
| 1740 | |
| 1741 | // Listen for broadcasts related to user-presence |
| 1742 | final IntentFilter filter = new IntentFilter(); |
| 1743 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1744 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1745 | // For handling managed profiles |
| 1746 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1747 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1748 | if (ENABLE_DEBUG_INTENTS) { |
| 1749 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1750 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1751 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1752 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1753 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1754 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1755 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1756 | mVisible = true; |
| 1757 | } |
| 1758 | |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1759 | /** |
| 1760 | * Sets up transparent navigation and status bars in LMP. |
| 1761 | * This method is a no-op for other platform versions. |
| 1762 | */ |
| 1763 | @TargetApi(19) |
| 1764 | private void setupTransparentSystemBarsForLmp() { |
| 1765 | // TODO(sansid): use the APIs directly when compiling against L sdk. |
| 1766 | // Currently we use reflection to access the flags and the API to set the transparency |
| 1767 | // on the System bars. |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 1768 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1769 | try { |
| 1770 | getWindow().getAttributes().systemUiVisibility |= |
| 1771 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1772 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1773 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1774 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
| 1775 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
| 1776 | Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( |
| 1777 | "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); |
| 1778 | getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); |
| 1779 | |
| 1780 | Method setStatusBarColorMethod = |
| 1781 | Window.class.getDeclaredMethod("setStatusBarColor", int.class); |
| 1782 | Method setNavigationBarColorMethod = |
| 1783 | Window.class.getDeclaredMethod("setNavigationBarColor", int.class); |
| 1784 | setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1785 | setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1786 | } catch (NoSuchFieldException e) { |
| 1787 | Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); |
| 1788 | } catch (NoSuchMethodException ex) { |
| 1789 | Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); |
| 1790 | } catch (IllegalAccessException e) { |
| 1791 | Log.w(TAG, "IllegalAccessException while setting up transparent bars"); |
| 1792 | } catch (IllegalArgumentException e) { |
| 1793 | Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); |
| 1794 | } catch (InvocationTargetException e) { |
| 1795 | Log.w(TAG, "InvocationTargetException while setting up transparent bars"); |
| 1796 | } finally {} |
| 1797 | } |
| 1798 | } |
| 1799 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1800 | @Override |
| 1801 | public void onDetachedFromWindow() { |
| 1802 | super.onDetachedFromWindow(); |
| 1803 | mVisible = false; |
| 1804 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1805 | if (mAttached) { |
| 1806 | unregisterReceiver(mReceiver); |
| 1807 | mAttached = false; |
| 1808 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1809 | updateRunning(); |
| 1810 | } |
| 1811 | |
| 1812 | public void onWindowVisibilityChanged(int visibility) { |
| 1813 | mVisible = visibility == View.VISIBLE; |
| 1814 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1815 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1816 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1817 | // is a more appropriate event to handle |
| 1818 | if (mVisible) { |
| 1819 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1820 | if (!mWorkspaceLoading) { |
| 1821 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1822 | // We want to let Launcher draw itself at least once before we force it to build |
| 1823 | // 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] | 1824 | // apps is nice and speedy. |
| 1825 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1826 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1827 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1828 | if (mStarted) return; |
| 1829 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1830 | // We delay the layer building a bit in order to give |
| 1831 | // other message processing a time to run. In particular |
| 1832 | // this avoids a delay in hiding the IME if it was |
| 1833 | // currently shown, because doing that may involve |
| 1834 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1835 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1836 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1837 | mWorkspace.post(new Runnable() { |
| 1838 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1839 | if (mWorkspace != null && |
| 1840 | mWorkspace.getViewTreeObserver() != null) { |
| 1841 | mWorkspace.getViewTreeObserver(). |
| 1842 | removeOnDrawListener(listener); |
| 1843 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1844 | } |
| 1845 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1846 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1847 | } |
| 1848 | }); |
| 1849 | } |
| 1850 | clearTypedText(); |
| 1851 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | private void sendAdvanceMessage(long delay) { |
| 1855 | mHandler.removeMessages(ADVANCE_MSG); |
| 1856 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1857 | mHandler.sendMessageDelayed(msg, delay); |
| 1858 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1859 | } |
| 1860 | |
| 1861 | private void updateRunning() { |
| 1862 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1863 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1864 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1865 | if (autoAdvanceRunning) { |
| 1866 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1867 | sendAdvanceMessage(delay); |
| 1868 | } else { |
| 1869 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1870 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1871 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1872 | } |
| 1873 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1874 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1875 | } |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | private final Handler mHandler = new Handler() { |
| 1880 | @Override |
| 1881 | public void handleMessage(Message msg) { |
| 1882 | if (msg.what == ADVANCE_MSG) { |
| 1883 | int i = 0; |
| 1884 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1885 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1886 | final int delay = mAdvanceStagger * i; |
| 1887 | if (v instanceof Advanceable) { |
| 1888 | postDelayed(new Runnable() { |
| 1889 | public void run() { |
| 1890 | ((Advanceable) v).advance(); |
| 1891 | } |
| 1892 | }, delay); |
| 1893 | } |
| 1894 | i++; |
| 1895 | } |
| 1896 | sendAdvanceMessage(mAdvanceInterval); |
| 1897 | } |
| 1898 | } |
| 1899 | }; |
| 1900 | |
| 1901 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1902 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1903 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1904 | if (v instanceof Advanceable) { |
| 1905 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1906 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1907 | updateRunning(); |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | void removeWidgetToAutoAdvance(View hostView) { |
| 1912 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1913 | mWidgetsToAdvance.remove(hostView); |
| 1914 | updateRunning(); |
| 1915 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1918 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1919 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1920 | launcherInfo.hostView = null; |
| 1921 | } |
| 1922 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1923 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1924 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1925 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1928 | public DragLayer getDragLayer() { |
| 1929 | return mDragLayer; |
| 1930 | } |
| 1931 | |
| 1932 | public Workspace getWorkspace() { |
| 1933 | return mWorkspace; |
| 1934 | } |
| 1935 | |
| 1936 | public Hotseat getHotseat() { |
| 1937 | return mHotseat; |
| 1938 | } |
| 1939 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1940 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1941 | return mOverviewPanel; |
| 1942 | } |
| 1943 | |
| 1944 | public SearchDropTargetBar getSearchBar() { |
| 1945 | return mSearchDropTargetBar; |
| 1946 | } |
| 1947 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1948 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1949 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1950 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1951 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1952 | public LauncherModel getModel() { |
| 1953 | return mModel; |
| 1954 | } |
| 1955 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1956 | protected SharedPreferences getSharedPrefs() { |
| 1957 | return mSharedPrefs; |
| 1958 | } |
| 1959 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1960 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1961 | getWindow().closeAllPanels(); |
| 1962 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1963 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1964 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1965 | } |
| 1966 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1967 | @Override |
| 1968 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1969 | long startTime = 0; |
| 1970 | if (DEBUG_RESUME_TIME) { |
| 1971 | startTime = System.currentTimeMillis(); |
| 1972 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1973 | super.onNewIntent(intent); |
| 1974 | |
| 1975 | // Close the menu |
| 1976 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1977 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1978 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1979 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1980 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1981 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1982 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1983 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1984 | if (mWorkspace == null) { |
| 1985 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1986 | return; |
| 1987 | } |
| 1988 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1989 | // In all these cases, only animate if we're already on home |
| 1990 | mWorkspace.exitWidgetResizeMode(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1991 | |
| 1992 | boolean moveToDefaultScreen = mLauncherCallbacks != null ? |
| 1993 | mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true; |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1994 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1995 | openFolder == null && moveToDefaultScreen) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1996 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1997 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1998 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1999 | closeFolder(); |
| 2000 | exitSpringLoadedDragMode(); |
| 2001 | |
| 2002 | // If we are already on home, then just animate back to the workspace, |
| 2003 | // otherwise, just wait until onResume to set the state back to Workspace |
| 2004 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2005 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 2006 | } else { |
| 2007 | mOnResumeState = State.WORKSPACE; |
| 2008 | } |
| 2009 | |
| 2010 | final View v = getWindow().peekDecorView(); |
| 2011 | if (v != null && v.getWindowToken() != null) { |
| 2012 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 2013 | INPUT_METHOD_SERVICE); |
| 2014 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 2015 | } |
| 2016 | |
| 2017 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 2018 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 2019 | mAppsCustomizeTabHost.reset(); |
| 2020 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 2021 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2022 | if (mLauncherCallbacks != null) { |
| 2023 | mLauncherCallbacks.onHomeIntent(); |
| 2024 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2025 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2026 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 2027 | if (DEBUG_RESUME_TIME) { |
| 2028 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 2029 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2030 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2031 | if (mLauncherCallbacks != null) { |
| 2032 | mLauncherCallbacks.onNewIntent(intent); |
| 2033 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2036 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2037 | public void onRestoreInstanceState(Bundle state) { |
| 2038 | super.onRestoreInstanceState(state); |
| 2039 | for (int page: mSynchronouslyBoundPages) { |
| 2040 | mWorkspace.restoreInstanceStateForChild(page); |
| 2041 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | @Override |
| 2045 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 2046 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2047 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 2048 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 2049 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 2050 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2051 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 2052 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 2053 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 2054 | // this state is reflected. |
| 2055 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2056 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2057 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2058 | mWaitingForResult) { |
| 2059 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2060 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2061 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 2062 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2063 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 2064 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 2065 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2066 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | if (mFolderInfo != null && mWaitingForResult) { |
| 2070 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 2071 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 2072 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 2073 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2074 | // Save the current AppsCustomize tab |
| 2075 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 2076 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 2077 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2078 | if (currentTabTag != null) { |
| 2079 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 2080 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 2081 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 2082 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2083 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 2084 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2085 | |
| 2086 | if (mLauncherCallbacks != null) { |
| 2087 | mLauncherCallbacks.onSaveInstanceState(outState); |
| 2088 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | @Override |
| 2092 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2093 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2094 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2095 | // Remove all pending runnables |
| 2096 | mHandler.removeMessages(ADVANCE_MSG); |
| 2097 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 2098 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2099 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2100 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 2101 | LauncherAppState app = (LauncherAppState.getInstance()); |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 2102 | |
| 2103 | // It's possible to receive onDestroy after a new Launcher activity has |
| 2104 | // been created. In this case, don't interfere with the new Launcher. |
| 2105 | if (mModel.isCurrentCallbacks(this)) { |
| 2106 | mModel.stopLoader(); |
| 2107 | app.setLauncher(null); |
| 2108 | } |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2109 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2110 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2111 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2112 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2113 | 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] | 2114 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2115 | mAppWidgetHost = null; |
| 2116 | |
| 2117 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2118 | |
| 2119 | TextKeyListener.getInstance().release(); |
| 2120 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 2121 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 2122 | // to prevent leaking Launcher activities on orientation change. |
| 2123 | if (mModel != null) { |
| 2124 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 2125 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2126 | |
| 2127 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2128 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2129 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 2130 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2131 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 2132 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2133 | mWorkspace = null; |
| 2134 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 2135 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2136 | LauncherAnimUtils.onDestroyActivity(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2137 | |
| 2138 | if (mLauncherCallbacks != null) { |
| 2139 | mLauncherCallbacks.onDestroy(); |
| 2140 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2141 | } |
| 2142 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2143 | public DragController getDragController() { |
| 2144 | return mDragController; |
| 2145 | } |
| 2146 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2147 | @Override |
| 2148 | public void startActivityForResult(Intent intent, int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2149 | if (requestCode >= 0) { |
| 2150 | setWaitingForResult(true); |
| 2151 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2152 | super.startActivityForResult(intent, requestCode); |
| 2153 | } |
| 2154 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2155 | /** |
| 2156 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2157 | * argument for {@link #startSearch} to true. |
| 2158 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2159 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2160 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2161 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2162 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2163 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2164 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2165 | if (initialQuery == null) { |
| 2166 | // Use any text typed in the launcher as the initial query |
| 2167 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2168 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2169 | if (appSearchData == null) { |
| 2170 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2171 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2172 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2173 | Rect sourceBounds = new Rect(); |
| 2174 | if (mSearchDropTargetBar != null) { |
| 2175 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2176 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2177 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2178 | boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2179 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2180 | if (clearTextImmediately) { |
| 2181 | clearTypedText(); |
| 2182 | } |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2183 | } |
| 2184 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2185 | /** |
| 2186 | * Start a text search. |
| 2187 | * |
| 2188 | * @return {@code true} if the search will start immediately, so any further keypresses |
| 2189 | * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue |
| 2190 | * to buffer keypresses. |
| 2191 | */ |
| 2192 | public boolean startSearch(String initialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2193 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2194 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 2195 | return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData, |
| 2196 | sourceBounds); |
| 2197 | } |
| 2198 | |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2199 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2200 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2201 | return false; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | /** |
| 2205 | * Starts the global search activity. This code is a copied from SearchManager |
| 2206 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2207 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2208 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2209 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2210 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2211 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2212 | if (globalSearchActivity == null) { |
| 2213 | Log.w(TAG, "No global search activity found."); |
| 2214 | return; |
| 2215 | } |
| 2216 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2217 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2218 | intent.setComponent(globalSearchActivity); |
| 2219 | // Make sure that we have a Bundle to put source in |
| 2220 | if (appSearchData == null) { |
| 2221 | appSearchData = new Bundle(); |
| 2222 | } else { |
| 2223 | appSearchData = new Bundle(appSearchData); |
| 2224 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2225 | // Set source to package name of app that starts global search if not set already. |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2226 | if (!appSearchData.containsKey("source")) { |
| 2227 | appSearchData.putString("source", getPackageName()); |
| 2228 | } |
| 2229 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2230 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2231 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2232 | } |
| 2233 | if (selectInitialQuery) { |
| 2234 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2235 | } |
| 2236 | intent.setSourceBounds(sourceBounds); |
| 2237 | try { |
| 2238 | startActivity(intent); |
| 2239 | } catch (ActivityNotFoundException ex) { |
| 2240 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2241 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2242 | } |
| 2243 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2244 | public boolean isOnCustomContent() { |
| 2245 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2246 | } |
| 2247 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2248 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2249 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2250 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2251 | if (!isOnCustomContent()) { |
| 2252 | // Close any open folders |
| 2253 | closeFolder(); |
| 2254 | // Stop resizing any widgets |
| 2255 | mWorkspace.exitWidgetResizeMode(); |
| 2256 | if (!mWorkspace.isInOverviewMode()) { |
| 2257 | // Show the overview mode |
| 2258 | showOverviewMode(true); |
| 2259 | } else { |
| 2260 | showWorkspace(true); |
| 2261 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2262 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2263 | if (mLauncherCallbacks != null) { |
| 2264 | return mLauncherCallbacks.onPrepareOptionsMenu(menu); |
| 2265 | } |
| 2266 | |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2267 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2268 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2269 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2270 | @Override |
| 2271 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2272 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2273 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2274 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2277 | public boolean isWorkspaceLocked() { |
| 2278 | return mWorkspaceLoading || mWaitingForResult; |
| 2279 | } |
| 2280 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2281 | public boolean isWorkspaceLoading() { |
| 2282 | return mWorkspaceLoading; |
| 2283 | } |
| 2284 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2285 | private void setWorkspaceLoading(boolean value) { |
| 2286 | boolean isLocked = isWorkspaceLocked(); |
| 2287 | mWorkspaceLoading = value; |
| 2288 | if (isLocked != isWorkspaceLocked()) { |
| 2289 | onWorkspaceLockedChanged(); |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | private void setWaitingForResult(boolean value) { |
| 2294 | boolean isLocked = isWorkspaceLocked(); |
| 2295 | mWaitingForResult = value; |
| 2296 | if (isLocked != isWorkspaceLocked()) { |
| 2297 | onWorkspaceLockedChanged(); |
| 2298 | } |
| 2299 | } |
| 2300 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2301 | protected void onWorkspaceLockedChanged() { |
| 2302 | if (mLauncherCallbacks != null) { |
| 2303 | mLauncherCallbacks.onWorkspaceLockedChanged(); |
| 2304 | } |
| 2305 | } |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2306 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2307 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2308 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2309 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2310 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2311 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2312 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2313 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2314 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2315 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2316 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2317 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) { |
| 2318 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2319 | } |
| 2320 | |
| 2321 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2322 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int |
| 2323 | delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2324 | if (appWidgetInfo.configure != null) { |
| 2325 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2326 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2327 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2328 | // Launch over to configure widget, if needed |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2329 | mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this, |
| 2330 | mAppWidgetHost, REQUEST_CREATE_APPWIDGET); |
| 2331 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2332 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2333 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2334 | Runnable onComplete = new Runnable() { |
| 2335 | @Override |
| 2336 | public void run() { |
| 2337 | // Exit spring loaded mode if necessary after adding the widget |
| 2338 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2339 | null); |
| 2340 | } |
| 2341 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2342 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2343 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2344 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2345 | } |
| 2346 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2347 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2348 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2349 | // Close any folders that may be open. |
| 2350 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2351 | mWorkspace.moveToCustomContentScreen(animate); |
| 2352 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2353 | /** |
| 2354 | * Process a shortcut drop. |
| 2355 | * |
| 2356 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2357 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2358 | * @param cell The cell it should be added to, optional |
| 2359 | * @param position The location on the screen where it was dropped, optional |
| 2360 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2361 | void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2362 | int[] cell, int[] loc) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2363 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2364 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2365 | mPendingAddInfo.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2366 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2367 | |
| 2368 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2369 | mPendingAddInfo.cellX = cell[0]; |
| 2370 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2371 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2372 | |
| 2373 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2374 | createShortcutIntent.setComponent(componentName); |
| 2375 | processShortcut(createShortcutIntent); |
| 2376 | } |
| 2377 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2378 | /** |
| 2379 | * Process a widget drop. |
| 2380 | * |
| 2381 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2382 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2383 | * @param cell The cell it should be added to, optional |
| 2384 | * @param position The location on the screen where it was dropped, optional |
| 2385 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2386 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2387 | int[] cell, int[] span, int[] loc) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2388 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2389 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2390 | mPendingAddInfo.screenId = info.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2391 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2392 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2393 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2394 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2395 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2396 | mPendingAddInfo.cellX = cell[0]; |
| 2397 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2398 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2399 | if (span != null) { |
| 2400 | mPendingAddInfo.spanX = span[0]; |
| 2401 | mPendingAddInfo.spanY = span[1]; |
| 2402 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2403 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2404 | AppWidgetHostView hostView = info.boundWidget; |
| 2405 | int appWidgetId; |
| 2406 | if (hostView != null) { |
| 2407 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2408 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2409 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2410 | // In this case, we either need to start an activity to get permission to bind |
| 2411 | // 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] | 2412 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2413 | Bundle options = info.bindOptions; |
| 2414 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2415 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2416 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2417 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2418 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2419 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2420 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2421 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2422 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2423 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2424 | mAppWidgetManager.getUser(mPendingAddWidgetInfo) |
| 2425 | .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2426 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2427 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2428 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2429 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2430 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2433 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2434 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2435 | } |
| 2436 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2437 | void processWallpaper(Intent intent) { |
| 2438 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2439 | } |
| 2440 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2441 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2442 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2443 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2444 | folderInfo.title = getText(R.string.folder_name); |
| 2445 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2446 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2447 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2448 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2449 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2450 | |
| 2451 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2452 | FolderIcon newFolder = |
| 2453 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2454 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2455 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2456 | // Force measure the new folder icon |
| 2457 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2458 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2459 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2460 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2461 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2462 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2463 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2464 | } |
| 2465 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2466 | protected ComponentName getWallpaperPickerComponent() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2467 | if (mLauncherCallbacks != null) { |
| 2468 | return mLauncherCallbacks.getWallpaperPickerComponent(); |
| 2469 | } |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2470 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2471 | } |
| 2472 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2473 | /** |
| 2474 | * Registers various content observers. The current implementation registers |
| 2475 | * only a favorites observer to keep track of the favorites applications. |
| 2476 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2477 | private void registerContentObservers() { |
| 2478 | ContentResolver resolver = getContentResolver(); |
| 2479 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2480 | true, mWidgetObserver); |
| 2481 | } |
| 2482 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2483 | @Override |
| 2484 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2485 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2486 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2487 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2488 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2489 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame^] | 2490 | if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2491 | dumpState(); |
| 2492 | return true; |
| 2493 | } |
| 2494 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2495 | } |
| 2496 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2497 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2498 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2499 | return true; |
| 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | return super.dispatchKeyEvent(event); |
| 2504 | } |
| 2505 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2506 | @Override |
| 2507 | public void onBackPressed() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2508 | if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) { |
| 2509 | return; |
| 2510 | } |
| 2511 | |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2512 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2513 | if (mAppsCustomizeContent.getContentType() == |
| 2514 | AppsCustomizePagedView.ContentType.Applications) { |
| 2515 | showWorkspace(true); |
| 2516 | } else { |
| 2517 | showOverviewMode(true); |
| 2518 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2519 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2520 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2521 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2522 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2523 | if (openFolder.isEditingName()) { |
| 2524 | openFolder.dismissEditingName(); |
| 2525 | } else { |
| 2526 | closeFolder(); |
| 2527 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2528 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2529 | mWorkspace.exitWidgetResizeMode(); |
| 2530 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2531 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2532 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2533 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2534 | } |
| 2535 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2536 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2537 | * Re-listen when widgets are reset. |
| 2538 | */ |
| 2539 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2540 | if (mAppWidgetHost != null) { |
| 2541 | mAppWidgetHost.startListening(); |
| 2542 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2546 | * Launches the intent referred by the clicked shortcut. |
| 2547 | * |
| 2548 | * @param v The view representing the clicked shortcut. |
| 2549 | */ |
| 2550 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2551 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2552 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2553 | if (v.getWindowToken() == null) { |
| 2554 | return; |
| 2555 | } |
| 2556 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2557 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2558 | return; |
| 2559 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2560 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2561 | if (v instanceof Workspace) { |
| 2562 | if (mWorkspace.isInOverviewMode()) { |
| 2563 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2564 | } |
| 2565 | return; |
| 2566 | } |
| 2567 | |
| 2568 | if (v instanceof CellLayout) { |
| 2569 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2570 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2571 | } |
| 2572 | } |
| 2573 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2574 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2575 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2576 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2577 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2578 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2579 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2580 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2581 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2582 | onClickAllAppsButton(v); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2583 | } else if (tag instanceof AppInfo) { |
| 2584 | startAppShortcutOrInfoActivity(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2585 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2586 | if (v instanceof PendingAppWidgetHostView) { |
| 2587 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2588 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2592 | public void onClickPagedViewIcon(View v) { |
| 2593 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2594 | if (mLauncherCallbacks != null) { |
| 2595 | mLauncherCallbacks.onClickPagedViewIcon(v); |
| 2596 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2599 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2600 | return false; |
| 2601 | } |
| 2602 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2603 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2604 | * Event handler for the app widget view which has not fully restored. |
| 2605 | */ |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2606 | public void onClickPendingWidget(final PendingAppWidgetHostView v) { |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2607 | if (mIsSafeModeEnabled) { |
| 2608 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2609 | return; |
| 2610 | } |
| 2611 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2612 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2613 | if (v.isReadyForClickSetup()) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2614 | int widgetId = info.appWidgetId; |
| 2615 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
| 2616 | if (appWidgetInfo != null) { |
| 2617 | mPendingAddWidgetInfo = appWidgetInfo; |
| 2618 | mPendingAddInfo.copyFrom(info); |
| 2619 | mPendingAddWidgetId = widgetId; |
| 2620 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2621 | AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo, |
| 2622 | info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2623 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2624 | } else if (info.installProgress < 0) { |
| 2625 | // The install has not been queued |
| 2626 | final String packageName = info.providerName.getPackageName(); |
| 2627 | showBrokenAppInstallDialog(packageName, |
| 2628 | new DialogInterface.OnClickListener() { |
| 2629 | public void onClick(DialogInterface dialog, int id) { |
| 2630 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
| 2631 | } |
| 2632 | }); |
| 2633 | } else { |
| 2634 | // Download has started. |
| 2635 | final String packageName = info.providerName.getPackageName(); |
| 2636 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2641 | * Event handler for the search button |
| 2642 | * |
| 2643 | * @param v The view that was clicked. |
| 2644 | */ |
| 2645 | public void onClickSearchButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2646 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2647 | |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2648 | onSearchRequested(); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2652 | * Event handler for the voice button |
| 2653 | * |
| 2654 | * @param v The view that was clicked. |
| 2655 | */ |
| 2656 | public void onClickVoiceButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2657 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2658 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2659 | startVoice(); |
| 2660 | } |
| 2661 | |
| 2662 | public void startVoice() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2663 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 2664 | mLauncherCallbacks.startVoice(); |
| 2665 | return; |
| 2666 | } |
| 2667 | |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2668 | try { |
| 2669 | final SearchManager searchManager = |
| 2670 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2671 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 2672 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2673 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2674 | if (activityName != null) { |
| 2675 | intent.setPackage(activityName.getPackageName()); |
| 2676 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2677 | startActivity(null, intent, "onClickVoiceButton"); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2678 | } catch (ActivityNotFoundException e) { |
| 2679 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2680 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2681 | startActivitySafely(null, intent, "onClickVoiceButton"); |
| 2682 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2686 | * Event handler for the "grid" button that appears on the home screen, which |
| 2687 | * enters all apps mode. |
| 2688 | * |
| 2689 | * @param v The view that was clicked. |
| 2690 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2691 | protected void onClickAllAppsButton(View v) { |
| 2692 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2693 | if (isAllAppsVisible()) { |
| 2694 | showWorkspace(true); |
| 2695 | } else { |
| 2696 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2697 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2698 | if (mLauncherCallbacks != null) { |
| 2699 | mLauncherCallbacks.onClickAllAppsButton(v); |
| 2700 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2701 | } |
| 2702 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2703 | private void showBrokenAppInstallDialog(final String packageName, |
| 2704 | DialogInterface.OnClickListener onSearchClickListener) { |
Sunny Goyal | e03b812 | 2014-10-08 09:55:24 -0700 | [diff] [blame] | 2705 | new AlertDialog.Builder(this) |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2706 | .setTitle(R.string.abandoned_promises_title) |
| 2707 | .setMessage(R.string.abandoned_promise_explanation) |
| 2708 | .setPositiveButton(R.string.abandoned_search, onSearchClickListener) |
| 2709 | .setNeutralButton(R.string.abandoned_clean_this, |
| 2710 | new DialogInterface.OnClickListener() { |
| 2711 | public void onClick(DialogInterface dialog, int id) { |
| 2712 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 2713 | mWorkspace.removeAbandonedPromise(packageName, user); |
| 2714 | } |
| 2715 | }) |
| 2716 | .create().show(); |
| 2717 | return; |
| 2718 | } |
| 2719 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2720 | /** |
| 2721 | * Event handler for an app shortcut click. |
| 2722 | * |
| 2723 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2724 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2725 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2726 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2727 | Object tag = v.getTag(); |
| 2728 | if (!(tag instanceof ShortcutInfo)) { |
| 2729 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2730 | } |
| 2731 | |
| 2732 | // Open shortcut |
| 2733 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2734 | |
| 2735 | if (shortcut.isDisabled != 0) { |
| 2736 | int error = R.string.activity_not_available; |
| 2737 | if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) { |
| 2738 | error = R.string.safemode_shortcut_error; |
| 2739 | } |
| 2740 | Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); |
| 2741 | return; |
| 2742 | } |
| 2743 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2744 | final Intent intent = shortcut.intent; |
| 2745 | |
| 2746 | // Check for special shortcuts |
| 2747 | if (intent.getComponent() != null) { |
| 2748 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2749 | |
| 2750 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2751 | MemoryDumpActivity.startDump(this); |
| 2752 | return; |
| 2753 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2754 | toggleShowWeightWatcher(); |
| 2755 | return; |
| 2756 | } |
| 2757 | } |
| 2758 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2759 | // Check for abandoned promise |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2760 | if ((v instanceof BubbleTextView) |
| 2761 | && shortcut.isPromise() |
| 2762 | && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2763 | showBrokenAppInstallDialog( |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2764 | shortcut.getTargetComponent().getPackageName(), |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2765 | new DialogInterface.OnClickListener() { |
| 2766 | public void onClick(DialogInterface dialog, int id) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2767 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2768 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2769 | }); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2770 | return; |
| 2771 | } |
| 2772 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2773 | // Start activities |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2774 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2775 | |
| 2776 | if (mLauncherCallbacks != null) { |
| 2777 | mLauncherCallbacks.onClickAppShortcut(v); |
| 2778 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2779 | } |
| 2780 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2781 | private void startAppShortcutOrInfoActivity(View v) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2782 | Object tag = v.getTag(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2783 | final ShortcutInfo shortcut; |
| 2784 | final Intent intent; |
| 2785 | if (tag instanceof ShortcutInfo) { |
| 2786 | shortcut = (ShortcutInfo) tag; |
| 2787 | intent = shortcut.intent; |
| 2788 | int[] pos = new int[2]; |
| 2789 | v.getLocationOnScreen(pos); |
| 2790 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2791 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2792 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2793 | } else if (tag instanceof AppInfo) { |
| 2794 | shortcut = null; |
| 2795 | intent = ((AppInfo) tag).intent; |
| 2796 | } else { |
| 2797 | throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); |
| 2798 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2799 | |
| 2800 | boolean success = startActivitySafely(v, intent, tag); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2801 | mStats.recordLaunch(intent, shortcut); |
| 2802 | |
| 2803 | if (success && v instanceof BubbleTextView) { |
| 2804 | mWaitingForResume = (BubbleTextView) v; |
| 2805 | mWaitingForResume.setStayPressed(true); |
| 2806 | } |
| 2807 | } |
| 2808 | |
| 2809 | /** |
| 2810 | * Event handler for a folder icon click. |
| 2811 | * |
| 2812 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2813 | */ |
| 2814 | protected void onClickFolderIcon(View v) { |
| 2815 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2816 | if (!(v instanceof FolderIcon)){ |
| 2817 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2818 | } |
| 2819 | |
| 2820 | FolderIcon folderIcon = (FolderIcon) v; |
| 2821 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2822 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2823 | |
| 2824 | // If the folder info reports that the associated folder is open, then verify that |
| 2825 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2826 | if (info.opened && openFolder == null) { |
| 2827 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2828 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2829 | info.opened = false; |
| 2830 | } |
| 2831 | |
| 2832 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2833 | // Close any open folder |
| 2834 | closeFolder(); |
| 2835 | // Open the requested folder |
| 2836 | openFolder(folderIcon); |
| 2837 | } else { |
| 2838 | // Find the open folder... |
| 2839 | int folderScreen; |
| 2840 | if (openFolder != null) { |
| 2841 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2842 | // .. and close it |
| 2843 | closeFolder(openFolder); |
| 2844 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2845 | // Close any folder open on the current screen |
| 2846 | closeFolder(); |
| 2847 | // Pull the folder onto this screen |
| 2848 | openFolder(folderIcon); |
| 2849 | } |
| 2850 | } |
| 2851 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2852 | |
| 2853 | if (mLauncherCallbacks != null) { |
| 2854 | mLauncherCallbacks.onClickFolderIcon(v); |
| 2855 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2858 | /** |
| 2859 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2860 | * on the home screen. |
| 2861 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2862 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2863 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2864 | if (mIsSafeModeEnabled) { |
| 2865 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2866 | } else { |
| 2867 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2868 | if (mLauncherCallbacks != null) { |
| 2869 | mLauncherCallbacks.onClickAddWidgetButton(view); |
| 2870 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2871 | } |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2872 | } |
| 2873 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2874 | /** |
| 2875 | * Event handler for the wallpaper picker button that appears after a long press |
| 2876 | * on the home screen. |
| 2877 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2878 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2879 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2880 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2881 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2882 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2883 | |
| 2884 | if (mLauncherCallbacks != null) { |
| 2885 | mLauncherCallbacks.onClickWallpaperPicker(v); |
| 2886 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | /** |
| 2890 | * Event handler for a click on the settings button that appears after a long press |
| 2891 | * on the home screen. |
| 2892 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2893 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2894 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2895 | if (mLauncherCallbacks != null) { |
| 2896 | mLauncherCallbacks.onClickSettingsButton(v); |
| 2897 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2898 | } |
| 2899 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2900 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2901 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2902 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2905 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2906 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2907 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2908 | } |
| 2909 | |
| 2910 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2911 | if (mHapticFeedbackTouchListener == null) { |
| 2912 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2913 | @Override |
| 2914 | public boolean onTouch(View v, MotionEvent event) { |
| 2915 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2916 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2917 | } |
| 2918 | return false; |
| 2919 | } |
| 2920 | }; |
| 2921 | } |
| 2922 | return mHapticFeedbackTouchListener; |
| 2923 | } |
| 2924 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2925 | public void onDragStarted(View view) { |
| 2926 | if (isOnCustomContent()) { |
| 2927 | // Custom content screen doesn't participate in drag and drop. If on custom |
| 2928 | // content screen, move to default. |
| 2929 | moveWorkspaceToDefaultScreen(); |
| 2930 | } |
| 2931 | |
| 2932 | if (mLauncherCallbacks != null) { |
| 2933 | mLauncherCallbacks.onDragStarted(view); |
| 2934 | } |
| 2935 | } |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2936 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2937 | /** |
| 2938 | * Called when the user stops interacting with the launcher. |
| 2939 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2940 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2941 | protected void onInteractionEnd() { |
| 2942 | if (mLauncherCallbacks != null) { |
| 2943 | mLauncherCallbacks.onInteractionEnd(); |
| 2944 | } |
| 2945 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2946 | |
| 2947 | /** |
| 2948 | * Called when the user starts interacting with the launcher. |
| 2949 | * The possible interactions are: |
| 2950 | * - open all apps |
| 2951 | * - reorder an app shortcut, or a widget |
| 2952 | * - open the overview mode. |
| 2953 | * This is a good time to stop doing things that only make sense |
| 2954 | * when the user is on the homescreen and not doing housekeeping. |
| 2955 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2956 | protected void onInteractionBegin() { |
| 2957 | if (mLauncherCallbacks != null) { |
| 2958 | mLauncherCallbacks.onInteractionBegin(); |
| 2959 | } |
| 2960 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2961 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2962 | void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2963 | String packageName = componentName.getPackageName(); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2964 | try { |
| 2965 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2966 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
| 2967 | launcherApps.showAppDetailsForProfile(componentName, user); |
| 2968 | } catch (SecurityException e) { |
| 2969 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2970 | Log.e(TAG, "Launcher does not have permission to launch settings"); |
| 2971 | } catch (ActivityNotFoundException e) { |
| 2972 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2973 | Log.e(TAG, "Unable to launch settings"); |
| 2974 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2975 | } |
| 2976 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2977 | // returns true if the activity was started |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2978 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags, |
| 2979 | UserHandleCompat user) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2980 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2981 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2982 | // We may give them the option of disabling apps this way. |
| 2983 | int messageId = R.string.uninstall_system_app_text; |
| 2984 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2985 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2986 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2987 | String packageName = componentName.getPackageName(); |
| 2988 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2989 | Intent intent = new Intent( |
| 2990 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2991 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2992 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2993 | if (user != null) { |
| 2994 | user.addToIntent(intent, Intent.EXTRA_USER); |
| 2995 | } |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2996 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2997 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2998 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 3001 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 3002 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3003 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 3004 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 3005 | // private contract between launcher and may be ignored in the future). |
| 3006 | boolean useLaunchAnimation = (v != null) && |
| 3007 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3008 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 3009 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3010 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 3011 | UserHandleCompat user = null; |
| 3012 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 3013 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 3014 | user = userManager.getUserForSerialNumber(serialNumber); |
| 3015 | } |
| 3016 | |
| 3017 | Bundle optsBundle = null; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 3018 | if (useLaunchAnimation) { |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3019 | ActivityOptions opts = Utilities.isLmpOrAbove() ? |
Adam Cohen | 4da294d | 2014-07-28 10:56:19 -0700 | [diff] [blame] | 3020 | ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) : |
| 3021 | ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 3022 | optsBundle = opts.toBundle(); |
| 3023 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 3024 | |
| 3025 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 3026 | // Could be launching some bookkeeping activity |
| 3027 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 3028 | } else { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 3029 | // TODO Component can be null when shortcuts are supported for secondary user |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 3030 | launcherApps.startActivityForProfile(intent.getComponent(), user, |
| 3031 | intent.getSourceBounds(), optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 3032 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 3033 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3034 | } catch (SecurityException e) { |
| 3035 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 3036 | 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] | 3037 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 3038 | "or use the exported attribute for this activity. " |
| 3039 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3040 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 3041 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3042 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3043 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 3044 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 3045 | boolean success = false; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 3046 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 3047 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 3048 | return false; |
| 3049 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 3050 | try { |
| 3051 | success = startActivity(v, intent, tag); |
| 3052 | } catch (ActivityNotFoundException e) { |
| 3053 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 3054 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 3055 | } |
| 3056 | return success; |
| 3057 | } |
| 3058 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3059 | /** |
| 3060 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 3061 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 3062 | */ |
| 3063 | private void copyFolderIconToImage(FolderIcon fi) { |
| 3064 | final int width = fi.getMeasuredWidth(); |
| 3065 | final int height = fi.getMeasuredHeight(); |
| 3066 | |
| 3067 | // Lazy load ImageView, Bitmap and Canvas |
| 3068 | if (mFolderIconImageView == null) { |
| 3069 | mFolderIconImageView = new ImageView(this); |
| 3070 | } |
| 3071 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 3072 | mFolderIconBitmap.getHeight() != height) { |
| 3073 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 3074 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 3075 | } |
| 3076 | |
| 3077 | DragLayer.LayoutParams lp; |
| 3078 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 3079 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 3080 | } else { |
| 3081 | lp = new DragLayer.LayoutParams(width, height); |
| 3082 | } |
| 3083 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 3084 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 3085 | // view size by this scale factor. |
| 3086 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3087 | lp.customPosition = true; |
| 3088 | lp.x = mRectForFolderAnimation.left; |
| 3089 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 3090 | lp.width = (int) (scale * width); |
| 3091 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3092 | |
| 3093 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 3094 | fi.draw(mFolderIconCanvas); |
| 3095 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3096 | if (fi.getFolder() != null) { |
| 3097 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 3098 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3099 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3100 | // Just in case this image view is still in the drag layer from a previous animation, |
| 3101 | // we remove it and re-add it. |
| 3102 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 3103 | mDragLayer.removeView(mFolderIconImageView); |
| 3104 | } |
| 3105 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3106 | if (fi.getFolder() != null) { |
| 3107 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3108 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3111 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3112 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3113 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 3114 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 3115 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 3116 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3117 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 3118 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3119 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 3120 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 3121 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3124 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 3125 | copyFolderIconToImage(fi); |
| 3126 | fi.setVisibility(View.INVISIBLE); |
| 3127 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3128 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3129 | scaleX, scaleY); |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3130 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3131 | oa.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3132 | } |
| 3133 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3134 | oa.start(); |
| 3135 | } |
| 3136 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3137 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3138 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3139 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 3140 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 3141 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 3142 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3143 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3144 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3145 | // We remove and re-draw the FolderIcon in-case it has changed |
| 3146 | mDragLayer.removeView(mFolderIconImageView); |
| 3147 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3148 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3149 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3150 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3151 | oa.addListener(new AnimatorListenerAdapter() { |
| 3152 | @Override |
| 3153 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3154 | if (cl != null) { |
| 3155 | cl.clearFolderLeaveBehind(); |
| 3156 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 3157 | mDragLayer.removeView(mFolderIconImageView); |
| 3158 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3162 | oa.start(); |
| 3163 | } |
| 3164 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3165 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 3166 | * 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] | 3167 | * is animated relative to the specified View. If the View is null, no animation |
| 3168 | * is played. |
| 3169 | * |
| 3170 | * @param folderInfo The FolderInfo describing the folder to open. |
| 3171 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3172 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3173 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3174 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3175 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3176 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3177 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3178 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 3179 | // There was a one-off crash where the folder had a parent already. |
| 3180 | if (folder.getParent() == null) { |
| 3181 | mDragLayer.addView(folder); |
| 3182 | mDragController.addDropTarget((DropTarget) folder); |
| 3183 | } else { |
| 3184 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 3185 | folder.getParent() + ")."); |
| 3186 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3187 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3188 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3189 | |
| 3190 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 3191 | // the workspace items |
| 3192 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 3193 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 3197 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3198 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 3199 | if (folder.isEditingName()) { |
| 3200 | folder.dismissEditingName(); |
| 3201 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3202 | closeFolder(folder); |
| 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | void closeFolder(Folder folder) { |
| 3207 | folder.getInfo().opened = false; |
| 3208 | |
| 3209 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 3210 | if (parent != null) { |
| 3211 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 3212 | shrinkAndFadeInFolderIcon(fi); |
| 3213 | } |
| 3214 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3215 | |
| 3216 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 3217 | // longer occludeds the workspace items |
| 3218 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3219 | } |
| 3220 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3221 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 3222 | if (!isDraggingEnabled()) return false; |
| 3223 | if (isWorkspaceLocked()) return false; |
| 3224 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3225 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3226 | if (v instanceof Workspace) { |
| 3227 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 3228 | if (mWorkspace.enterOverviewMode()) { |
| 3229 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3230 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 3231 | return true; |
| 3232 | } else { |
| 3233 | return false; |
| 3234 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 3235 | } else { |
| 3236 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3237 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 3240 | CellLayout.CellInfo longClickCellInfo = null; |
| 3241 | View itemUnderLongClick = null; |
| 3242 | if (v.getTag() instanceof ItemInfo) { |
| 3243 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3244 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 3245 | itemUnderLongClick = longClickCellInfo.cell; |
| 3246 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3247 | } |
| 3248 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3249 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 3250 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3251 | final boolean inHotseat = isHotseatLayout(v); |
| 3252 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3253 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3254 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3255 | // User long pressed on empty space |
| 3256 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3257 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3258 | if (mWorkspace.isInOverviewMode()) { |
| 3259 | mWorkspace.startReordering(v); |
| 3260 | } else { |
| 3261 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 3262 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3263 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3264 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 3265 | mHotseat.getOrderInHotseat( |
| 3266 | longClickCellInfo.cellX, |
| 3267 | longClickCellInfo.cellY)); |
| 3268 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3269 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3270 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3271 | } |
| 3272 | } |
| 3273 | } |
| 3274 | return true; |
| 3275 | } |
| 3276 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3277 | boolean isHotseatLayout(View layout) { |
| 3278 | return mHotseat != null && layout != null && |
| 3279 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 3280 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 3281 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3282 | /** |
| 3283 | * Returns the CellLayout of the specified container at the specified screen. |
| 3284 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3285 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3286 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3287 | if (mHotseat != null) { |
| 3288 | return mHotseat.getLayout(); |
| 3289 | } else { |
| 3290 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 3291 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3292 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3293 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 3294 | } |
| 3295 | } |
| 3296 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3297 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3298 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 3299 | } |
| 3300 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3301 | private void setWorkspaceBackground(boolean workspace) { |
| 3302 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 3303 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 3306 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3307 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 3308 | int curflags = getWindow().getAttributes().flags |
| 3309 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 3310 | if (wpflags != curflags) { |
| 3311 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 3312 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3313 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3316 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3317 | if (v instanceof LauncherTransitionable) { |
| 3318 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3319 | } |
| 3320 | } |
| 3321 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3322 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3323 | if (v instanceof LauncherTransitionable) { |
| 3324 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3325 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3326 | |
| 3327 | // Update the workspace transition step as well |
| 3328 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3329 | } |
| 3330 | |
| 3331 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3332 | if (v instanceof LauncherTransitionable) { |
| 3333 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3334 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3335 | } |
| 3336 | |
| 3337 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3338 | if (v instanceof LauncherTransitionable) { |
| 3339 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3340 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3341 | |
| 3342 | // Update the workspace transition step as well |
| 3343 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3344 | } |
| 3345 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3346 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3347 | * Things to test when changing the following seven functions. |
| 3348 | * - Home from workspace |
| 3349 | * - from center screen |
| 3350 | * - from other screens |
| 3351 | * - Home from all apps |
| 3352 | * - from center screen |
| 3353 | * - from other screens |
| 3354 | * - Back from all apps |
| 3355 | * - from center screen |
| 3356 | * - from other screens |
| 3357 | * - Launch app from workspace and quit |
| 3358 | * - with back |
| 3359 | * - with home |
| 3360 | * - Launch app from all apps and quit |
| 3361 | * - with back |
| 3362 | * - with home |
| 3363 | * - Go to a screen that's not the default, then all |
| 3364 | * apps, and launch and app, and go back |
| 3365 | * - with back |
| 3366 | * -with home |
| 3367 | * - On workspace, long press power and go back |
| 3368 | * - with back |
| 3369 | * - with home |
| 3370 | * - On all apps, long press power and go back |
| 3371 | * - with back |
| 3372 | * - with home |
| 3373 | * - On workspace, power off |
| 3374 | * - On all apps, power off |
| 3375 | * - Launch an app and turn off the screen while in that app |
| 3376 | * - Go back with home key |
| 3377 | * - Go back with back key TODO: make this not go to workspace |
| 3378 | * - From all apps |
| 3379 | * - From workspace |
| 3380 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3381 | * - From all apps |
| 3382 | * - From the center workspace |
| 3383 | * - From another workspace |
| 3384 | */ |
| 3385 | |
| 3386 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3387 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3388 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3389 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3390 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3391 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3392 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3393 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3394 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3395 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3396 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3397 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3398 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3399 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3400 | mStateAnimation.cancel(); |
| 3401 | mStateAnimation = null; |
| 3402 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3403 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3404 | boolean material = Utilities.isLmpOrAbove(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3405 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3406 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3407 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3408 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); |
| 3409 | final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3410 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3411 | final int itemsAlphaStagger = |
| 3412 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3413 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3414 | final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3415 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3416 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3417 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3418 | final ArrayList<View> layerViews = new ArrayList<View>(); |
| 3419 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3420 | Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? |
| 3421 | Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3422 | Animator workspaceAnim = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3423 | mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3424 | if (!LauncherAppState.isDisableAllApps() |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3425 | || contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3426 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3427 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3428 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3429 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3430 | // If for some reason our views aren't initialized, don't animate |
| 3431 | boolean initialized = getAllAppsButton() != null; |
| 3432 | |
| 3433 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3434 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3435 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3436 | toView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3437 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3438 | final View page = content.getPageAt(content.getCurrentPage()); |
| 3439 | final View revealView = toView.findViewById(R.id.fake_page); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3440 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3441 | final float initialPanelAlpha = 1f; |
| 3442 | |
| 3443 | final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; |
| 3444 | if (isWidgetTray) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3445 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3446 | } else { |
| 3447 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3448 | } |
| 3449 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3450 | // Hide the real page background, and swap in the fake one |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3451 | content.setPageBackgroundsVisible(false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3452 | revealView.setVisibility(View.VISIBLE); |
| 3453 | // We need to hide this view as the animation start will be posted. |
| 3454 | revealView.setAlpha(0); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3455 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3456 | int width = revealView.getMeasuredWidth(); |
| 3457 | int height = revealView.getMeasuredHeight(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3458 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3459 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3460 | revealView.setTranslationY(0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3461 | revealView.setTranslationX(0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3462 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3463 | // Get the y delta between the center of the page and the center of the all apps button |
| 3464 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3465 | getAllAppsButton(), null); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3466 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3467 | float alpha = 0; |
| 3468 | float xDrift = 0; |
| 3469 | float yDrift = 0; |
| 3470 | if (material) { |
| 3471 | alpha = isWidgetTray ? 0.3f : 1f; |
| 3472 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3473 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3474 | } else { |
| 3475 | yDrift = 2 * height / 3; |
| 3476 | xDrift = 0; |
| 3477 | } |
| 3478 | final float initAlpha = alpha; |
| 3479 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3480 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3481 | layerViews.add(revealView); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3482 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3483 | PropertyValuesHolder panelDriftY = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3484 | PropertyValuesHolder.ofFloat("translationY", yDrift, 0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3485 | PropertyValuesHolder panelDriftX = |
| 3486 | PropertyValuesHolder.ofFloat("translationX", xDrift, 0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3487 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3488 | ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, |
| 3489 | panelAlpha, panelDriftY, panelDriftX); |
| 3490 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3491 | panelAlphaAndDrift.setDuration(revealDuration); |
| 3492 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3493 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3494 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3495 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3496 | if (page != null) { |
| 3497 | page.setVisibility(View.VISIBLE); |
| 3498 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3499 | layerViews.add(page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3500 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3501 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0); |
| 3502 | page.setTranslationY(yDrift); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3503 | pageDrift.setDuration(revealDuration); |
| 3504 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3505 | pageDrift.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3506 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3507 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3508 | page.setAlpha(0f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3509 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3510 | itemsAlpha.setDuration(revealDuration); |
| 3511 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 3512 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
| 3513 | mStateAnimation.play(itemsAlpha); |
| 3514 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3515 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3516 | View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); |
| 3517 | pageIndicators.setAlpha(0.01f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3518 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3519 | ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3520 | indicatorsAlpha.setDuration(revealDuration); |
| 3521 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3522 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3523 | if (material) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3524 | final View allApps = getAllAppsButton(); |
| 3525 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3526 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3527 | float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3528 | Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3529 | height / 2, startRadius, revealRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3530 | reveal.setDuration(revealDuration); |
| 3531 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3532 | |
| 3533 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3534 | public void onAnimationStart(Animator animation) { |
| 3535 | if (!isWidgetTray) { |
| 3536 | allApps.setVisibility(View.INVISIBLE); |
| 3537 | } |
| 3538 | } |
| 3539 | public void onAnimationEnd(Animator animation) { |
| 3540 | if (!isWidgetTray) { |
| 3541 | allApps.setVisibility(View.VISIBLE); |
| 3542 | } |
| 3543 | } |
| 3544 | }); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3545 | mStateAnimation.play(reveal); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3546 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3547 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3548 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
| 3549 | @Override |
| 3550 | public void onAnimationEnd(Animator animation) { |
| 3551 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3552 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 3553 | |
| 3554 | revealView.setVisibility(View.INVISIBLE); |
| 3555 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3556 | if (page != null) { |
| 3557 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3558 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3559 | content.setPageBackgroundsVisible(true); |
| 3560 | |
| 3561 | // Hide the search bar |
| 3562 | if (mSearchDropTargetBar != null) { |
| 3563 | mSearchDropTargetBar.hideSearchBar(false); |
| 3564 | } |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3565 | |
| 3566 | // This can hold unnecessary references to views. |
| 3567 | mStateAnimation = null; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3568 | } |
| 3569 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3570 | }); |
| 3571 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3572 | if (workspaceAnim != null) { |
| 3573 | mStateAnimation.play(workspaceAnim); |
| 3574 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3575 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3576 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3577 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3578 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3579 | final Runnable startAnimRunnable = new Runnable() { |
| 3580 | public void run() { |
| 3581 | // Check that mStateAnimation hasn't changed while |
| 3582 | // we waited for a layout/draw pass |
| 3583 | if (mStateAnimation != stateAnimation) |
| 3584 | return; |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3585 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3586 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3587 | |
| 3588 | revealView.setAlpha(initAlpha); |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3589 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3590 | for (int i = 0; i < layerViews.size(); i++) { |
| 3591 | View v = layerViews.get(i); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3592 | if (v != null) { |
Sunny Goyal | fafca52 | 2014-11-03 11:30:01 -0800 | [diff] [blame] | 3593 | if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3594 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3595 | } |
| 3596 | } |
| 3597 | mStateAnimation.start(); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3598 | } |
| 3599 | }; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3600 | toView.bringToFront(); |
| 3601 | toView.setVisibility(View.VISIBLE); |
| 3602 | toView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3603 | } else { |
| 3604 | toView.setTranslationX(0.0f); |
| 3605 | toView.setTranslationY(0.0f); |
| 3606 | toView.setScaleX(1.0f); |
| 3607 | toView.setScaleY(1.0f); |
| 3608 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3609 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3610 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3611 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3612 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3613 | if (mSearchDropTargetBar != null) { |
| 3614 | mSearchDropTargetBar.hideSearchBar(false); |
| 3615 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3616 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3617 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3618 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3619 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3620 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3621 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3622 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3623 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | /** |
| 3627 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3628 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3629 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3630 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3631 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3632 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3633 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3634 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3635 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3636 | mStateAnimation.cancel(); |
| 3637 | mStateAnimation = null; |
| 3638 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3639 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3640 | boolean material = Utilities.isLmpOrAbove(); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3641 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3642 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3643 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3644 | final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3645 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3646 | final int itemsAlphaStagger = |
| 3647 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3648 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3649 | final float scaleFactor = (float) |
| 3650 | res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
| 3651 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3652 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3653 | Animator workspaceAnim = null; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3654 | final ArrayList<View> layerViews = new ArrayList<View>(); |
| 3655 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3656 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3657 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3658 | toState, animated, layerViews); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3659 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3660 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3661 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3662 | toState, animated, layerViews); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3663 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3664 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3665 | // If for some reason our views aren't initialized, don't animate |
| 3666 | boolean initialized = getAllAppsButton() != null; |
| 3667 | |
| 3668 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3669 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3670 | if (workspaceAnim != null) { |
| 3671 | mStateAnimation.play(workspaceAnim); |
| 3672 | } |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3673 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3674 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3675 | fromView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3676 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3677 | final View page = content.getPageAt(content.getNextPage()); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3678 | |
| 3679 | // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases |
| 3680 | int count = content.getChildCount(); |
| 3681 | for (int i = 0; i < count; i++) { |
| 3682 | View child = content.getChildAt(i); |
| 3683 | if (child != page) { |
| 3684 | child.setVisibility(View.INVISIBLE); |
| 3685 | } |
| 3686 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3687 | final View revealView = fromView.findViewById(R.id.fake_page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3688 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3689 | // hideAppsCustomizeHelper is called in some cases when it is already hidden |
| 3690 | // don't perform all these no-op animations. In particularly, this was causing |
| 3691 | // the all-apps button to pop in and out. |
| 3692 | if (fromView.getVisibility() == View.VISIBLE) { |
| 3693 | AppsCustomizePagedView.ContentType contentType = content.getContentType(); |
| 3694 | final boolean isWidgetTray = |
| 3695 | contentType == AppsCustomizePagedView.ContentType.Widgets; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3696 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3697 | if (isWidgetTray) { |
| 3698 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3699 | } else { |
| 3700 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3701 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3702 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3703 | int width = revealView.getMeasuredWidth(); |
| 3704 | int height = revealView.getMeasuredHeight(); |
| 3705 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
| 3706 | |
| 3707 | // Hide the real page background, and swap in the fake one |
| 3708 | revealView.setVisibility(View.VISIBLE); |
| 3709 | content.setPageBackgroundsVisible(false); |
| 3710 | |
| 3711 | final View allAppsButton = getAllAppsButton(); |
| 3712 | revealView.setTranslationY(0); |
| 3713 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3714 | allAppsButton, null); |
| 3715 | |
| 3716 | float xDrift = 0; |
| 3717 | float yDrift = 0; |
| 3718 | if (material) { |
| 3719 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3720 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3721 | } else { |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3722 | yDrift = 2 * height / 3; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3723 | xDrift = 0; |
| 3724 | } |
| 3725 | |
| 3726 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3727 | TimeInterpolator decelerateInterpolator = material ? |
| 3728 | new LogDecelerateInterpolator(100, 0) : |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3729 | new DecelerateInterpolator(1f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3730 | |
| 3731 | // The vertical motion of the apps panel should be delayed by one frame |
| 3732 | // from the conceal animation in order to give the right feel. We correpsondingly |
| 3733 | // shorten the duration so that the slide and conceal end at the same time. |
| 3734 | ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", |
| 3735 | 0, yDrift); |
| 3736 | panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3737 | panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3738 | panelDriftY.setInterpolator(decelerateInterpolator); |
| 3739 | mStateAnimation.play(panelDriftY); |
| 3740 | |
| 3741 | ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", |
| 3742 | 0, xDrift); |
| 3743 | panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3744 | panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3745 | panelDriftX.setInterpolator(decelerateInterpolator); |
| 3746 | mStateAnimation.play(panelDriftX); |
| 3747 | |
| 3748 | if (isWidgetTray || !material) { |
| 3749 | float finalAlpha = material ? 0.4f : 0f; |
| 3750 | revealView.setAlpha(1f); |
| 3751 | ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", |
| 3752 | 1f, finalAlpha); |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3753 | panelAlpha.setDuration(material ? revealDuration : 150); |
| 3754 | panelAlpha.setInterpolator(decelerateInterpolator); |
| 3755 | panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3756 | mStateAnimation.play(panelAlpha); |
| 3757 | } |
| 3758 | |
| 3759 | if (page != null) { |
| 3760 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3761 | |
| 3762 | ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", |
| 3763 | 0, yDrift); |
| 3764 | page.setTranslationY(0); |
| 3765 | pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3766 | pageDrift.setInterpolator(decelerateInterpolator); |
| 3767 | pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3768 | mStateAnimation.play(pageDrift); |
| 3769 | |
| 3770 | page.setAlpha(1f); |
| 3771 | ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f); |
| 3772 | itemsAlpha.setDuration(100); |
| 3773 | itemsAlpha.setInterpolator(decelerateInterpolator); |
| 3774 | mStateAnimation.play(itemsAlpha); |
| 3775 | } |
| 3776 | |
| 3777 | View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); |
| 3778 | pageIndicators.setAlpha(1f); |
| 3779 | ObjectAnimator indicatorsAlpha = |
| 3780 | LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f); |
| 3781 | indicatorsAlpha.setDuration(revealDuration); |
| 3782 | indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 3783 | mStateAnimation.play(indicatorsAlpha); |
| 3784 | |
| 3785 | width = revealView.getMeasuredWidth(); |
| 3786 | |
| 3787 | if (material) { |
| 3788 | if (!isWidgetTray) { |
| 3789 | allAppsButton.setVisibility(View.INVISIBLE); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3790 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3791 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3792 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3793 | float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
| 3794 | Animator reveal = |
| 3795 | LauncherAnimUtils.createCircularReveal(revealView, width / 2, |
| 3796 | height / 2, revealRadius, finalRadius); |
| 3797 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3798 | reveal.setDuration(revealDuration); |
| 3799 | reveal.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3800 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3801 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3802 | public void onAnimationEnd(Animator animation) { |
| 3803 | revealView.setVisibility(View.INVISIBLE); |
| 3804 | if (!isWidgetTray) { |
| 3805 | allAppsButton.setVisibility(View.VISIBLE); |
| 3806 | } |
| 3807 | } |
| 3808 | }); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3809 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3810 | mStateAnimation.play(reveal); |
| 3811 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3812 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3813 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3814 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 3815 | mAppsCustomizeContent.stopScrolling(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3816 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3817 | |
| 3818 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3819 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3820 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3821 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3822 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3823 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3824 | if (onCompleteRunnable != null) { |
| 3825 | onCompleteRunnable.run(); |
| 3826 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3827 | |
| 3828 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3829 | if (page != null) { |
| 3830 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3831 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3832 | content.setPageBackgroundsVisible(true); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3833 | // Unhide side pages |
| 3834 | int count = content.getChildCount(); |
| 3835 | for (int i = 0; i < count; i++) { |
| 3836 | View child = content.getChildAt(i); |
| 3837 | child.setVisibility(View.VISIBLE); |
| 3838 | } |
| 3839 | |
| 3840 | // Reset page transforms |
Adam Cohen | 493f6bc | 2014-09-18 08:11:05 -0700 | [diff] [blame] | 3841 | if (page != null) { |
| 3842 | page.setTranslationX(0); |
| 3843 | page.setTranslationY(0); |
| 3844 | page.setAlpha(1); |
| 3845 | } |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3846 | content.setCurrentPage(content.getNextPage()); |
| 3847 | |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3848 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3849 | |
| 3850 | // This can hold unnecessary references to views. |
| 3851 | mStateAnimation = null; |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3852 | } |
| 3853 | }); |
| 3854 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3855 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3856 | final Runnable startAnimRunnable = new Runnable() { |
| 3857 | public void run() { |
| 3858 | // Check that mStateAnimation hasn't changed while |
| 3859 | // we waited for a layout/draw pass |
| 3860 | if (mStateAnimation != stateAnimation) |
| 3861 | return; |
| 3862 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3863 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3864 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3865 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3866 | for (int i = 0; i < layerViews.size(); i++) { |
| 3867 | View v = layerViews.get(i); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3868 | if (v != null) { |
Sunny Goyal | fafca52 | 2014-11-03 11:30:01 -0800 | [diff] [blame] | 3869 | if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3870 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3871 | } |
| 3872 | } |
| 3873 | mStateAnimation.start(); |
| 3874 | } |
| 3875 | }; |
| 3876 | fromView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3877 | } else { |
| 3878 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3879 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3880 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3881 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3882 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3883 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3884 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3885 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3888 | @Override |
| 3889 | public void onTrimMemory(int level) { |
| 3890 | super.onTrimMemory(level); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3891 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
| 3892 | // The widget preview db can result in holding onto over |
| 3893 | // 3MB of memory for caching which isn't necessary. |
| 3894 | SQLiteDatabase.releaseMemory(); |
| 3895 | |
| 3896 | // We reset the apps customize tray in order to |
| 3897 | // to free all the memory associated with widget previews |
| 3898 | if (mAppsCustomizeTabHost != null) { |
| 3899 | mAppsCustomizeTabHost.reset(); |
| 3900 | } |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3904 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3905 | showWorkspace(animated, null); |
| 3906 | } |
| 3907 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3908 | protected void showWorkspace() { |
| 3909 | showWorkspace(true); |
| 3910 | } |
| 3911 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3912 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 3913 | if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3914 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3915 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3916 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3917 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3918 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3919 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3920 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3921 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3922 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3923 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3924 | // Set focus to the AppsCustomize button |
| 3925 | if (mAllAppsButton != null) { |
| 3926 | mAllAppsButton.requestFocus(); |
| 3927 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3928 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3929 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3930 | // Change the state *after* we've called all the transition code |
| 3931 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3932 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3933 | // Resume the auto-advance of widgets |
| 3934 | mUserPresent = true; |
| 3935 | updateRunning(); |
| 3936 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3937 | // Send an accessibility event to announce the context change |
| 3938 | getWindow().getDecorView() |
| 3939 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3940 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3941 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3942 | } |
| 3943 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3944 | void showOverviewMode(boolean animated) { |
| 3945 | mWorkspace.setVisibility(View.VISIBLE); |
| 3946 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3947 | mState = State.WORKSPACE; |
| 3948 | onWorkspaceShown(animated); |
| 3949 | } |
| 3950 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3951 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3952 | } |
| 3953 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3954 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3955 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3956 | if (mState != State.WORKSPACE) return; |
| 3957 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3958 | if (resetPageToZero) { |
| 3959 | mAppsCustomizeTabHost.reset(); |
| 3960 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3961 | showAppsCustomizeHelper(animated, false, contentType); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 3962 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3963 | @Override |
| 3964 | public void run() { |
| 3965 | // We post this in-case the all apps view isn't yet constructed. |
| 3966 | mAppsCustomizeTabHost.requestFocus(); |
| 3967 | } |
| 3968 | }); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3969 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3970 | // Change the state *after* we've called all the transition code |
| 3971 | mState = State.APPS_CUSTOMIZE; |
| 3972 | |
| 3973 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3974 | mUserPresent = false; |
| 3975 | updateRunning(); |
| 3976 | closeFolder(); |
| 3977 | |
| 3978 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3979 | getWindow().getDecorView() |
| 3980 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3983 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3984 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3985 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3986 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3987 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3988 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3989 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3990 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3991 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3992 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 3993 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 3994 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3995 | @Override |
| 3996 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3997 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3998 | // Before we show workspace, hide all apps again because |
| 3999 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 4000 | // clean up our state transition functions |
| 4001 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4002 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 4003 | } else { |
| 4004 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 4005 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 4006 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 4007 | }, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 4008 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 4009 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 4010 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 4011 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 4012 | final boolean animated = true; |
| 4013 | final boolean springLoaded = true; |
| 4014 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 4015 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4016 | } |
| 4017 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 4018 | } |
| 4019 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 4020 | void lockAllApps() { |
| 4021 | // TODO |
| 4022 | } |
| 4023 | |
| 4024 | void unlockAllApps() { |
| 4025 | // TODO |
| 4026 | } |
| 4027 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4028 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4029 | * Hides the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4030 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4031 | void hideHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 4032 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4033 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 4034 | if (mHotseat.getAlpha() != 0f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4035 | int duration = 0; |
| 4036 | if (mSearchDropTargetBar != null) { |
| 4037 | duration = mSearchDropTargetBar.getTransitionOutDuration(); |
| 4038 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 4039 | mHotseat.animate().alpha(0f).setDuration(duration); |
| 4040 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4041 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4042 | mHotseat.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4043 | } |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 4044 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 4045 | } |
| 4046 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 4047 | /** |
| 4048 | * Add an item from all apps or customize onto the given workspace screen. |
| 4049 | * If layout is null, add to the current screen. |
| 4050 | */ |
| 4051 | void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 4052 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 4053 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 4054 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 4055 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 4056 | |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 4057 | /** Maps the current orientation to an index for referencing orientation correct global icons */ |
| 4058 | private int getCurrentOrientationIndexForGlobalIcons() { |
| 4059 | // default - 0, landscape - 1 |
| 4060 | switch (getResources().getConfiguration().orientation) { |
| 4061 | case Configuration.ORIENTATION_LANDSCAPE: |
| 4062 | return 1; |
| 4063 | default: |
| 4064 | return 0; |
| 4065 | } |
| 4066 | } |
| 4067 | |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4068 | private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4069 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4070 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4071 | // Look for the toolbar icon specified in the activity meta-data |
| 4072 | Bundle metaData = packageManager.getActivityInfo( |
| 4073 | activityName, PackageManager.GET_META_DATA).metaData; |
| 4074 | if (metaData != null) { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4075 | int iconResId = metaData.getInt(resourceName); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4076 | if (iconResId != 0) { |
| 4077 | Resources res = packageManager.getResourcesForActivity(activityName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4078 | return res.getDrawable(iconResId); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4079 | } |
| 4080 | } |
| 4081 | } catch (NameNotFoundException e) { |
Michael Jurka | b6052a9 | 2011-07-12 17:02:45 -0700 | [diff] [blame] | 4082 | // This can happen if the activity defines an invalid drawable |
| 4083 | Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + |
| 4084 | " not found", e); |
Mathew Inwood | 70d5102 | 2011-07-12 13:41:41 +0100 | [diff] [blame] | 4085 | } catch (Resources.NotFoundException nfe) { |
| 4086 | // This can happen if the activity defines an invalid drawable |
| 4087 | Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), |
| 4088 | nfe); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4089 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4090 | return null; |
| 4091 | } |
| 4092 | |
| 4093 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 4094 | private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4095 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 4096 | String toolbarResourceName) { |
| 4097 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 4098 | Resources r = getResources(); |
| 4099 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 4100 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4101 | |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 4102 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4103 | // If we were unable to find the icon via the meta-data, use a generic one |
| 4104 | if (toolbarIcon == null) { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 4105 | toolbarIcon = r.getDrawable(fallbackDrawableId); |
| 4106 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 4107 | if (button != null) { |
| 4108 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 4109 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4110 | return null; |
| 4111 | } else { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 4112 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 4113 | if (button != null) { |
| 4114 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 4115 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4116 | return toolbarIcon.getConstantState(); |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 4121 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4122 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 4123 | String toolbarResourceName) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4124 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4125 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4126 | |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 4127 | if (button != null) { |
| 4128 | // If we were unable to find the icon via the meta-data, use a |
| 4129 | // generic one |
| 4130 | if (toolbarIcon == null) { |
| 4131 | button.setImageResource(fallbackDrawableId); |
| 4132 | } else { |
| 4133 | button.setImageDrawable(toolbarIcon); |
| 4134 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4135 | } |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 4136 | |
| 4137 | return toolbarIcon != null ? toolbarIcon.getConstantState() : null; |
| 4138 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 4141 | private void updateTextButtonWithDrawable(int buttonId, Drawable d) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4142 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 4143 | button.setCompoundDrawables(d, null, null, null); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4144 | } |
| 4145 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 4146 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4147 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 4148 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4149 | } |
| 4150 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4151 | private void invalidatePressedFocusedStates(View container, View button) { |
| 4152 | if (container instanceof HolographicLinearLayout) { |
| 4153 | HolographicLinearLayout layout = (HolographicLinearLayout) container; |
| 4154 | layout.invalidatePressedFocusedStates(); |
| 4155 | } else if (button instanceof HolographicImageView) { |
| 4156 | HolographicImageView view = (HolographicImageView) button; |
| 4157 | view.invalidatePressedFocusedStates(); |
| 4158 | } |
| 4159 | } |
| 4160 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4161 | public View getQsbBar() { |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 4162 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 4163 | return mLauncherCallbacks.getQsbBar(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 4166 | if (mQsb == null) { |
| 4167 | mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false); |
| 4168 | mSearchDropTargetBar.addView(mQsb); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4169 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 4170 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | protected boolean updateGlobalSearchIcon() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4174 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 4175 | return true; |
| 4176 | } |
| 4177 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4178 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4179 | final ImageView searchButton = (ImageView) findViewById(R.id.search_button); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4180 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 4181 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 4182 | |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4183 | final SearchManager searchManager = |
| 4184 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 4185 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 4186 | if (activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 4187 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 4188 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4189 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 4190 | TOOLBAR_SEARCH_ICON_METADATA_NAME); |
| 4191 | if (sGlobalSearchIcon[coi] == null) { |
| 4192 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 4193 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 4194 | TOOLBAR_ICON_METADATA_NAME); |
| 4195 | } |
| 4196 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4197 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); |
| 4198 | searchButton.setVisibility(View.VISIBLE); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4199 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4200 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4201 | } else { |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 4202 | // 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] | 4203 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); |
| 4204 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 4205 | if (searchButton != null) searchButton.setVisibility(View.GONE); |
| 4206 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4207 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4208 | return false; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4209 | } |
| 4210 | } |
| 4211 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4212 | protected void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4213 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) return; |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4214 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
| 4215 | final View searchButton = (ImageView) findViewById(R.id.search_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4216 | updateButtonWithDrawable(R.id.search_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4217 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4218 | } |
| 4219 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4220 | protected boolean updateVoiceSearchIcon(boolean searchVisible) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4221 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 4222 | return true; |
| 4223 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4224 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4225 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 4226 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4227 | // 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] | 4228 | final SearchManager searchManager = |
| 4229 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 4230 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 4231 | |
| 4232 | ComponentName activityName = null; |
| 4233 | if (globalSearchActivity != null) { |
| 4234 | // Check if the global search activity handles voice search |
| 4235 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 4236 | intent.setPackage(globalSearchActivity.getPackageName()); |
| 4237 | activityName = intent.resolveActivity(getPackageManager()); |
| 4238 | } |
| 4239 | |
| 4240 | if (activityName == null) { |
| 4241 | // Fallback: check if an activity other than the global search activity |
| 4242 | // resolves this |
| 4243 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 4244 | activityName = intent.resolveActivity(getPackageManager()); |
| 4245 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4246 | if (searchVisible && activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 4247 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 4248 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4249 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 4250 | TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); |
| 4251 | if (sVoiceSearchIcon[coi] == null) { |
| 4252 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 4253 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 4254 | TOOLBAR_ICON_METADATA_NAME); |
| 4255 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4256 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4257 | voiceButton.setVisibility(View.VISIBLE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4258 | updateVoiceButtonProxyVisible(false); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4259 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4260 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4261 | } else { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4262 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 4263 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4264 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4265 | return false; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4266 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 4267 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4268 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4269 | protected void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4270 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 4271 | return; |
| 4272 | } |
| 4273 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4274 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
| 4275 | final View voiceButton = findViewById(R.id.voice_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4276 | updateButtonWithDrawable(R.id.voice_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4277 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4278 | } |
| 4279 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4280 | public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4281 | if (mLauncherCallbacks != null) { |
| 4282 | forceDisableVoiceButtonProxy |= mLauncherCallbacks.forceDisableVoiceButtonProxy(); |
| 4283 | } |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4284 | final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); |
| 4285 | if (voiceButtonProxy != null) { |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4286 | boolean visible = !forceDisableVoiceButtonProxy && |
| 4287 | mWorkspace.shouldVoiceButtonProxyBeVisible(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4288 | voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4289 | voiceButtonProxy.bringToFront(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4290 | } |
| 4291 | } |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4292 | |
| 4293 | /** |
| 4294 | * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy |
| 4295 | * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns. |
| 4296 | */ |
| 4297 | public void disableVoiceButtonProxy(boolean disabled) { |
| 4298 | updateVoiceButtonProxyVisible(disabled); |
| 4299 | } |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4300 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4301 | @Override |
| 4302 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4303 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4304 | final List<CharSequence> text = event.getText(); |
| 4305 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4306 | // Populate event with a fake title based on the current state. |
| 4307 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4308 | text.add(mAppsCustomizeTabHost.getContentTag()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4309 | } else { |
| 4310 | text.add(getString(R.string.all_apps_home_button_label)); |
| 4311 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4312 | return result; |
| 4313 | } |
| 4314 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4315 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 4316 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4317 | */ |
| 4318 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 4319 | @Override |
| 4320 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4321 | closeSystemDialogs(); |
| 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 4326 | * Receives notifications whenever the appwidgets are reset. |
| 4327 | */ |
| 4328 | private class AppWidgetResetObserver extends ContentObserver { |
| 4329 | public AppWidgetResetObserver() { |
| 4330 | super(new Handler()); |
| 4331 | } |
| 4332 | |
| 4333 | @Override |
| 4334 | public void onChange(boolean selfChange) { |
| 4335 | onAppWidgetReset(); |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4340 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 4341 | * in onResume. |
| 4342 | * |
| 4343 | * This needs to be called from incoming places where resources might have been loaded |
| 4344 | * while we are paused. That is becaues the Configuration might be wrong |
| 4345 | * when we're not running, and if it comes back to what it was when we |
| 4346 | * were paused, we are not restarted. |
| 4347 | * |
| 4348 | * Implementation of the method from LauncherModel.Callbacks. |
| 4349 | * |
| 4350 | * @return true if we are currently paused. The caller might be able to |
| 4351 | * skip some work in that case since we will come back again. |
| 4352 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4353 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4354 | if (mPaused) { |
| 4355 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4356 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4357 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4358 | } |
| 4359 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4360 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4361 | return true; |
| 4362 | } else { |
| 4363 | return false; |
| 4364 | } |
| 4365 | } |
| 4366 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4367 | private boolean waitUntilResume(Runnable run) { |
| 4368 | return waitUntilResume(run, false); |
| 4369 | } |
| 4370 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4371 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 4372 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4373 | } |
| 4374 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4375 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4376 | * If the activity is currently paused, signal that we need to re-run the loader |
| 4377 | * in onResume. |
| 4378 | * |
| 4379 | * This needs to be called from incoming places where resources might have been loaded |
| 4380 | * while we are paused. That is becaues the Configuration might be wrong |
| 4381 | * when we're not running, and if it comes back to what it was when we |
| 4382 | * were paused, we are not restarted. |
| 4383 | * |
| 4384 | * Implementation of the method from LauncherModel.Callbacks. |
| 4385 | * |
| 4386 | * @return true if we are currently paused. The caller might be able to |
| 4387 | * skip some work in that case since we will come back again. |
| 4388 | */ |
| 4389 | public boolean setLoadOnResume() { |
| 4390 | if (mPaused) { |
| 4391 | Log.i(TAG, "setLoadOnResume"); |
| 4392 | mOnResumeNeedsLoad = true; |
| 4393 | return true; |
| 4394 | } else { |
| 4395 | return false; |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4400 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4401 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4402 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4403 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4404 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4405 | } else { |
| 4406 | return SCREEN_COUNT / 2; |
| 4407 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4408 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4409 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4410 | /** |
| 4411 | * Refreshes the shortcuts shown on the workspace. |
| 4412 | * |
| 4413 | * Implementation of the method from LauncherModel.Callbacks. |
| 4414 | */ |
| 4415 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4416 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 4417 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4418 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 4419 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 4420 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4421 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4422 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4423 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4424 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 4425 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4426 | |
Michael Jurka | 05bf644 | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 4427 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4428 | if (mHotseat != null) { |
| 4429 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4430 | } |
| 4431 | } |
| 4432 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4433 | @Override |
| 4434 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4435 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4436 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 4437 | // If there are no screens, we need to have an empty screen |
| 4438 | if (orderedScreenIds.size() == 0) { |
| 4439 | mWorkspace.addExtraEmptyScreen(); |
| 4440 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4441 | |
| 4442 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4443 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 4444 | if (hasCustomContentToLeft()) { |
| 4445 | mWorkspace.createCustomContentContainer(); |
| 4446 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4447 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | @Override |
| 4451 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 4452 | // Log to disk |
| 4453 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 4454 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 4455 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4456 | int count = orderedScreenIds.size(); |
| 4457 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 4458 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4459 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4460 | } |
| 4461 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4462 | private boolean shouldShowWeightWatcher() { |
| 4463 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4464 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 4465 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4466 | |
| 4467 | return show; |
| 4468 | } |
| 4469 | |
| 4470 | private void toggleShowWeightWatcher() { |
| 4471 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4472 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 4473 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 4474 | |
| 4475 | show = !show; |
| 4476 | |
| 4477 | SharedPreferences.Editor editor = sp.edit(); |
| 4478 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 4479 | editor.commit(); |
| 4480 | |
| 4481 | if (mWeightWatcher != null) { |
| 4482 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 4483 | } |
| 4484 | } |
| 4485 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4486 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 4487 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4488 | final ArrayList<ItemInfo> addAnimated, |
| 4489 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4490 | Runnable r = new Runnable() { |
| 4491 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4492 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4493 | } |
| 4494 | }; |
| 4495 | if (waitUntilResume(r)) { |
| 4496 | return; |
| 4497 | } |
| 4498 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4499 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4500 | if (newScreens != null) { |
| 4501 | bindAddScreens(newScreens); |
| 4502 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4503 | |
| 4504 | // We add the items without animation on non-visible pages, and with |
| 4505 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4506 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4507 | bindItems(addNotAnimated, 0, |
| 4508 | addNotAnimated.size(), false); |
| 4509 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4510 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4511 | bindItems(addAnimated, 0, |
| 4512 | addAnimated.size(), true); |
| 4513 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4514 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4515 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 4516 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4517 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4518 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4519 | addedApps != null && mAppsCustomizeContent != null) { |
| 4520 | mAppsCustomizeContent.addApps(addedApps); |
| 4521 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4522 | } |
| 4523 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4524 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4525 | * Bind the items start-end from the list. |
| 4526 | * |
| 4527 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4528 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4529 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 4530 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4531 | Runnable r = new Runnable() { |
| 4532 | public void run() { |
| 4533 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 4534 | } |
| 4535 | }; |
| 4536 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4537 | return; |
| 4538 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4539 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4540 | // 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] | 4541 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 4542 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4543 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4544 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4545 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4546 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4547 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4548 | |
| 4549 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4550 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4551 | mHotseat == null) { |
| 4552 | continue; |
| 4553 | } |
| 4554 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4555 | switch (item.itemType) { |
| 4556 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4557 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4558 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4559 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4560 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4561 | /* |
| 4562 | * TODO: FIX collision case |
| 4563 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4564 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4565 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4566 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4567 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4568 | Object tag = v.getTag(); |
| 4569 | String desc = "Collision while binding workspace item: " + item |
| 4570 | + ". Collides with " + tag; |
| 4571 | if (LauncherAppState.isDogfoodBuild()) { |
| 4572 | throw (new RuntimeException(desc)); |
| 4573 | } else { |
| 4574 | Log.d(TAG, desc); |
| 4575 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4576 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4579 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4580 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4581 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4582 | // Animate all the applications up now |
| 4583 | shortcut.setAlpha(0f); |
| 4584 | shortcut.setScaleX(0f); |
| 4585 | shortcut.setScaleY(0f); |
| 4586 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4587 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4588 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4589 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4590 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4591 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4592 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4593 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4594 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4595 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4596 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4597 | default: |
| 4598 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4599 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4600 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4601 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4602 | if (animateIcons) { |
| 4603 | // Animate to the correct page |
| 4604 | if (newShortcutsScreenId > -1) { |
| 4605 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4606 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4607 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4608 | public void run() { |
| 4609 | anim.playTogether(bounceAnims); |
| 4610 | anim.start(); |
| 4611 | } |
| 4612 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4613 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4614 | // We post the animation slightly delayed to prevent slowdowns |
| 4615 | // when we are loading right after we return to launcher. |
| 4616 | mWorkspace.postDelayed(new Runnable() { |
| 4617 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4618 | if (mWorkspace != null) { |
| 4619 | mWorkspace.snapToPage(newScreenIndex); |
| 4620 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4621 | NEW_APPS_ANIMATION_DELAY); |
| 4622 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4623 | } |
| 4624 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4625 | } else { |
| 4626 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4627 | } |
| 4628 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4629 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4630 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4631 | } |
| 4632 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4633 | /** |
| 4634 | * Implementation of the method from LauncherModel.Callbacks. |
| 4635 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4636 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4637 | Runnable r = new Runnable() { |
| 4638 | public void run() { |
| 4639 | bindFolders(folders); |
| 4640 | } |
| 4641 | }; |
| 4642 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4643 | return; |
| 4644 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4645 | sFolders.clear(); |
| 4646 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4647 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4648 | |
| 4649 | /** |
| 4650 | * Add the views for a widget to the workspace. |
| 4651 | * |
| 4652 | * Implementation of the method from LauncherModel.Callbacks. |
| 4653 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4654 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4655 | Runnable r = new Runnable() { |
| 4656 | public void run() { |
| 4657 | bindAppWidget(item); |
| 4658 | } |
| 4659 | }; |
| 4660 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4661 | return; |
| 4662 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4663 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4664 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4665 | if (DEBUG_WIDGETS) { |
| 4666 | Log.d(TAG, "bindAppWidget: " + item); |
| 4667 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4668 | final Workspace workspace = mWorkspace; |
| 4669 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4670 | AppWidgetProviderInfo appWidgetInfo; |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4671 | if (!mIsSafeModeEnabled |
| 4672 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) |
| 4673 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4674 | |
| 4675 | appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName); |
| 4676 | if (appWidgetInfo == null) { |
| 4677 | if (DEBUG_WIDGETS) { |
| 4678 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4679 | + " belongs to component " + item.providerName |
| 4680 | + ", as the povider is null"); |
| 4681 | } |
| 4682 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4683 | return; |
| 4684 | } |
| 4685 | // Note: This assumes that the id remap broadcast is received before this step. |
| 4686 | // If that is not the case, the id remap will be ignored and user may see the |
| 4687 | // click to setup view. |
| 4688 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null); |
| 4689 | pendingInfo.spanX = item.spanX; |
| 4690 | pendingInfo.spanY = item.spanY; |
| 4691 | pendingInfo.minSpanX = item.minSpanX; |
| 4692 | pendingInfo.minSpanY = item.minSpanY; |
| 4693 | Bundle options = |
| 4694 | AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo); |
| 4695 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4696 | int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 4697 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 4698 | newWidgetId, appWidgetInfo, options); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4699 | |
| 4700 | // TODO consider showing a permission dialog when the widget is clicked. |
| 4701 | if (!success) { |
| 4702 | mAppWidgetHost.deleteAppWidgetId(newWidgetId); |
| 4703 | if (DEBUG_WIDGETS) { |
| 4704 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4705 | + " belongs to component " + item.providerName |
| 4706 | + ", as the launcher is unable to bing a new widget id"); |
| 4707 | } |
| 4708 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4709 | return; |
| 4710 | } |
| 4711 | |
| 4712 | item.appWidgetId = newWidgetId; |
| 4713 | |
| 4714 | // If the widget has a configure activity, it is still needs to set it up, otherwise |
| 4715 | // the widget is ready to go. |
| 4716 | item.restoreStatus = (appWidgetInfo.configure == null) |
| 4717 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 4718 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 4719 | |
| 4720 | LauncherModel.updateItemInDatabase(this, item); |
| 4721 | } |
| 4722 | |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4723 | if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4724 | final int appWidgetId = item.appWidgetId; |
| 4725 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 4726 | if (DEBUG_WIDGETS) { |
| 4727 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 4728 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4729 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4730 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4731 | } else { |
| 4732 | appWidgetInfo = null; |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4733 | PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, |
| 4734 | mIsSafeModeEnabled); |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4735 | view.updateIcon(mIconCache); |
| 4736 | item.hostView = view; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4737 | item.hostView.updateAppWidget(null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4738 | item.hostView.setOnClickListener(this); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4739 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4740 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4741 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4742 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4743 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4744 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4745 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4746 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4747 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4748 | workspace.requestLayout(); |
| 4749 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4750 | if (DEBUG_WIDGETS) { |
| 4751 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4752 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4753 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4754 | } |
| 4755 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4756 | /** |
| 4757 | * Restores a pending widget. |
| 4758 | * |
| 4759 | * @param appWidgetId The app widget id |
| 4760 | * @param cellInfo The position on screen where to create the widget. |
| 4761 | */ |
| 4762 | private void completeRestoreAppWidget(final int appWidgetId) { |
| 4763 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 4764 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 4765 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
| 4766 | return; |
| 4767 | } |
| 4768 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4769 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4770 | info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 4771 | |
| 4772 | mWorkspace.reinflateWidgetsIfNecessary(); |
| 4773 | LauncherModel.updateItemInDatabase(this, info); |
| 4774 | } |
| 4775 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4776 | public void onPageBoundSynchronously(int page) { |
| 4777 | mSynchronouslyBoundPages.add(page); |
| 4778 | } |
| 4779 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4780 | /** |
| 4781 | * Callback saying that there aren't any more items to bind. |
| 4782 | * |
| 4783 | * Implementation of the method from LauncherModel.Callbacks. |
| 4784 | */ |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4785 | public void finishBindingItems(final boolean upgradePath) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4786 | Runnable r = new Runnable() { |
| 4787 | public void run() { |
| 4788 | finishBindingItems(upgradePath); |
| 4789 | } |
| 4790 | }; |
| 4791 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4792 | return; |
| 4793 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4794 | if (mSavedState != null) { |
| 4795 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4796 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4797 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4798 | mSavedState = null; |
| 4799 | } |
| 4800 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4801 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4802 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4803 | setWorkspaceLoading(false); |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4804 | sendLoadingCompleteBroadcastIfNecessary(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 4805 | |
| 4806 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4807 | // widget configuration forced an orientation change), process them now. |
| 4808 | if (sPendingAddItem != null) { |
| 4809 | final long screenId = completeAdd(sPendingAddItem); |
| 4810 | |
| 4811 | // TODO: this moves the user to the page where the pending item was added. Ideally, |
| 4812 | // the screen would be guaranteed to exist after bind, and the page would be set through |
| 4813 | // the workspace restore process. |
| 4814 | mWorkspace.post(new Runnable() { |
| 4815 | @Override |
| 4816 | public void run() { |
| 4817 | mWorkspace.snapToScreenId(screenId); |
| 4818 | } |
| 4819 | }); |
| 4820 | sPendingAddItem = null; |
| 4821 | } |
| 4822 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4823 | if (upgradePath) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4824 | mWorkspace.getUniqueComponents(true, null); |
| 4825 | mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4826 | } |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4827 | PackageInstallerCompat.getInstance(this).onFinishBind(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4828 | |
| 4829 | if (mLauncherCallbacks != null) { |
| 4830 | mLauncherCallbacks.finishBindingItems(upgradePath); |
| 4831 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4832 | } |
| 4833 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4834 | private void sendLoadingCompleteBroadcastIfNecessary() { |
| 4835 | if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) { |
| 4836 | String permission = |
| 4837 | getResources().getString(R.string.receive_first_load_broadcast_permission); |
| 4838 | Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE); |
| 4839 | sendBroadcast(intent, permission); |
| 4840 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4841 | editor.putBoolean(FIRST_LOAD_COMPLETE, true); |
| 4842 | editor.apply(); |
| 4843 | } |
| 4844 | } |
| 4845 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4846 | public boolean isAllAppsButtonRank(int rank) { |
| 4847 | if (mHotseat != null) { |
| 4848 | return mHotseat.isAllAppsButtonRank(rank); |
| 4849 | } |
| 4850 | return false; |
| 4851 | } |
| 4852 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4853 | private boolean canRunNewAppsAnimation() { |
| 4854 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4855 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4856 | } |
| 4857 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4858 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4859 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4860 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4861 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4862 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4863 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4864 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4865 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4866 | return bounceAnim; |
| 4867 | } |
| 4868 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4869 | public boolean useVerticalBarLayout() { |
| 4870 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4871 | getDeviceProfile().isVerticalBarLayout(); |
| 4872 | } |
| 4873 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4874 | protected Rect getSearchBarBounds() { |
| 4875 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4876 | getDeviceProfile().getSearchBarBounds(); |
| 4877 | } |
| 4878 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4879 | @Override |
| 4880 | public void bindSearchablesChanged() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4881 | boolean searchVisible = updateGlobalSearchIcon(); |
| 4882 | boolean voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4883 | if (mSearchDropTargetBar != null) { |
| 4884 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 4885 | } |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4886 | } |
| 4887 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4888 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4889 | * Add the icons for all apps. |
| 4890 | * |
| 4891 | * Implementation of the method from LauncherModel.Callbacks. |
| 4892 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4893 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4894 | if (LauncherAppState.isDisableAllApps()) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4895 | if (mIntentsOnWorkspaceFromUpgradePath != null) { |
| 4896 | if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) { |
| 4897 | getHotseat().addAllAppsFolder(mIconCache, apps, |
| 4898 | mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace); |
| 4899 | } |
| 4900 | mIntentsOnWorkspaceFromUpgradePath = null; |
Daniel Sandler | 8707e0f | 2013-08-15 15:54:18 -0700 | [diff] [blame] | 4901 | } |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4902 | if (mAppsCustomizeContent != null) { |
| 4903 | mAppsCustomizeContent.onPackagesUpdated( |
| 4904 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
| 4905 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4906 | } else { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 4907 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4908 | mAppsCustomizeContent.setApps(apps); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 4909 | mAppsCustomizeContent.onPackagesUpdated( |
| 4910 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4911 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4912 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4913 | if (mLauncherCallbacks != null) { |
| 4914 | mLauncherCallbacks.bindAllApplications(apps); |
| 4915 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4916 | } |
| 4917 | |
| 4918 | /** |
| 4919 | * A package was updated. |
| 4920 | * |
| 4921 | * Implementation of the method from LauncherModel.Callbacks. |
| 4922 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4923 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4924 | Runnable r = new Runnable() { |
| 4925 | public void run() { |
| 4926 | bindAppsUpdated(apps); |
| 4927 | } |
| 4928 | }; |
| 4929 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4930 | return; |
| 4931 | } |
| 4932 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4933 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4934 | mAppsCustomizeContent != null) { |
| 4935 | mAppsCustomizeContent.updateApps(apps); |
| 4936 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4937 | } |
| 4938 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4939 | @Override |
| 4940 | public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) { |
| 4941 | Runnable r = new Runnable() { |
| 4942 | public void run() { |
| 4943 | bindWidgetsRestored(widgets); |
| 4944 | } |
| 4945 | }; |
| 4946 | if (waitUntilResume(r)) { |
| 4947 | return; |
| 4948 | } |
| 4949 | mWorkspace.widgetsRestored(widgets); |
| 4950 | } |
| 4951 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4952 | /** |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4953 | * Some shortcuts were updated in the background. |
| 4954 | * |
| 4955 | * Implementation of the method from LauncherModel.Callbacks. |
| 4956 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4957 | @Override |
| 4958 | public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated, |
| 4959 | final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4960 | Runnable r = new Runnable() { |
| 4961 | public void run() { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4962 | bindShortcutsChanged(updated, removed, user); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4963 | } |
| 4964 | }; |
| 4965 | if (waitUntilResume(r)) { |
| 4966 | return; |
| 4967 | } |
| 4968 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4969 | if (!updated.isEmpty()) { |
| 4970 | mWorkspace.updateShortcuts(updated); |
| 4971 | } |
| 4972 | |
| 4973 | if (!removed.isEmpty()) { |
| 4974 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 4975 | for (ShortcutInfo si : removed) { |
| 4976 | removedComponents.add(si.getTargetComponent()); |
| 4977 | } |
| 4978 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
| 4979 | // Notify the drag controller |
| 4980 | mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4985 | * Update the state of a package, typically related to install state. |
| 4986 | * |
| 4987 | * Implementation of the method from LauncherModel.Callbacks. |
| 4988 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4989 | @Override |
| 4990 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4991 | if (mWorkspace != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4992 | mWorkspace.updatePackageState(installInfo); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | /** |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 4997 | * Update the label and icon of all the icons in a package |
| 4998 | * |
| 4999 | * Implementation of the method from LauncherModel.Callbacks. |
| 5000 | */ |
| 5001 | @Override |
| 5002 | public void updatePackageBadge(String packageName) { |
| 5003 | if (mWorkspace != null) { |
| 5004 | mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle()); |
| 5005 | } |
| 5006 | } |
| 5007 | |
| 5008 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5009 | * A package was uninstalled. We take both the super set of packageNames |
| 5010 | * in addition to specific applications to remove, the reason being that |
| 5011 | * this can be called when a package is updated as well. In that scenario, |
| 5012 | * we only remove specific components from the workspace, where as |
| 5013 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 5014 | * |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5015 | * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 5016 | * Implementation of the method from LauncherModel.Callbacks. |
| 5017 | */ |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5018 | @Override |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5019 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5020 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 5021 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5022 | public void run() { |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5023 | bindComponentsRemoved(packageNames, appInfos, user, reason); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5024 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 5025 | }; |
| 5026 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5027 | return; |
| 5028 | } |
| 5029 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5030 | if (reason == 0) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 5031 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 5032 | for (AppInfo info : appInfos) { |
| 5033 | removedComponents.add(info.componentName); |
| 5034 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5035 | if (!packageNames.isEmpty()) { |
| 5036 | mWorkspace.removeItemsByPackageName(packageNames, user); |
| 5037 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 5038 | if (!removedComponents.isEmpty()) { |
| 5039 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5040 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 5041 | // Notify the drag controller |
| 5042 | mDragController.onAppsRemoved(packageNames, removedComponents); |
| 5043 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5044 | } else { |
| 5045 | mWorkspace.disableShortcutsByPackageName(packageNames, user, reason); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 5046 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5047 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 5048 | // Update AllApps |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 5049 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 5050 | mAppsCustomizeContent != null) { |
| 5051 | mAppsCustomizeContent.removeApps(appInfos); |
| 5052 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 5053 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5054 | |
| 5055 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5056 | * A number of packages were updated. |
| 5057 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5058 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 5059 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5060 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5061 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 5062 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5063 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5064 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5065 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 5066 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 5067 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5068 | return; |
| 5069 | } |
| 5070 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 5071 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 5072 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5073 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5074 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5075 | } |
| 5076 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 5077 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 5078 | final Display d = getWindowManager().getDefaultDisplay(); |
| 5079 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 5080 | switch (d.getRotation()) { |
| 5081 | case Surface.ROTATION_0: |
| 5082 | case Surface.ROTATION_180: |
| 5083 | // We are currently in the same basic orientation as the natural orientation |
| 5084 | naturalOri = configOri; |
| 5085 | break; |
| 5086 | case Surface.ROTATION_90: |
| 5087 | case Surface.ROTATION_270: |
| 5088 | // We are currently in the other basic orientation to the natural orientation |
| 5089 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 5090 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 5091 | break; |
| 5092 | } |
| 5093 | |
| 5094 | int[] oriMap = { |
| 5095 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 5096 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 5097 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 5098 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 5099 | }; |
| 5100 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 5101 | // is landscape. |
| 5102 | int indexOffset = 0; |
| 5103 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 5104 | indexOffset = 1; |
| 5105 | } |
| 5106 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 5107 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 5108 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5109 | public void lockScreenOrientation() { |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame^] | 5110 | if (Utilities.isRotationEnabled(this)) { |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5111 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 5112 | .getConfiguration().orientation)); |
| 5113 | } |
| 5114 | } |
| 5115 | public void unlockScreenOrientation(boolean immediate) { |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame^] | 5116 | if (Utilities.isRotationEnabled(this)) { |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5117 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 5118 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5119 | } else { |
| 5120 | mHandler.postDelayed(new Runnable() { |
| 5121 | public void run() { |
| 5122 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 5123 | } |
| 5124 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 5125 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5126 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 5127 | } |
| 5128 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 5129 | protected boolean isLauncherPreinstalled() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5130 | if (mLauncherCallbacks != null) { |
| 5131 | return mLauncherCallbacks.isLauncherPreinstalled(); |
| 5132 | } |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 5133 | PackageManager pm = getPackageManager(); |
| 5134 | try { |
| 5135 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 5136 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 5137 | return true; |
| 5138 | } else { |
| 5139 | return false; |
| 5140 | } |
| 5141 | } catch (NameNotFoundException e) { |
| 5142 | e.printStackTrace(); |
| 5143 | return false; |
| 5144 | } |
| 5145 | } |
| 5146 | |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 5147 | /** |
| 5148 | * This method indicates whether or not we should suggest default wallpaper dimensions |
| 5149 | * when our wallpaper cropper was not yet used to set a wallpaper. |
| 5150 | */ |
| 5151 | protected boolean overrideWallpaperDimensions() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5152 | if (mLauncherCallbacks != null) { |
| 5153 | return mLauncherCallbacks.overrideWallpaperDimensions(); |
| 5154 | } |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 5155 | return true; |
| 5156 | } |
| 5157 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5158 | /** |
| 5159 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 5160 | * before showing the standard launcher experience. |
| 5161 | */ |
| 5162 | protected boolean hasFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5163 | if (mLauncherCallbacks != null) { |
| 5164 | return mLauncherCallbacks.hasFirstRunActivity(); |
| 5165 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5166 | return false; |
| 5167 | } |
| 5168 | |
| 5169 | /** |
| 5170 | * To be overridden by subclasses to launch any first run activity |
| 5171 | */ |
| 5172 | protected Intent getFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5173 | if (mLauncherCallbacks != null) { |
| 5174 | return mLauncherCallbacks.getFirstRunActivity(); |
| 5175 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5176 | return null; |
| 5177 | } |
| 5178 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5179 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 5180 | return !ActivityManager.isRunningInTestHarness() && |
| 5181 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5182 | } |
| 5183 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 5184 | protected boolean hasRunFirstRunActivity() { |
| 5185 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 5186 | } |
| 5187 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5188 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 5189 | if (shouldRunFirstRunActivity() && |
| 5190 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5191 | Intent firstRunIntent = getFirstRunActivity(); |
| 5192 | if (firstRunIntent != null) { |
| 5193 | startActivity(firstRunIntent); |
| 5194 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5195 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5196 | } |
| 5197 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5198 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | private void markFirstRunActivityShown() { |
| 5202 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 5203 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 5204 | editor.apply(); |
| 5205 | } |
| 5206 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5207 | /** |
| 5208 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 5209 | * screen that must be displayed and dismissed. |
| 5210 | */ |
| 5211 | protected boolean hasDismissableIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5212 | if (mLauncherCallbacks != null) { |
| 5213 | return mLauncherCallbacks.hasDismissableIntroScreen(); |
| 5214 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5215 | return false; |
| 5216 | } |
| 5217 | |
| 5218 | /** |
| 5219 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 5220 | */ |
| 5221 | protected View getIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5222 | if (mLauncherCallbacks != null) { |
| 5223 | return mLauncherCallbacks.getIntroScreen(); |
| 5224 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5225 | return null; |
| 5226 | } |
| 5227 | |
| 5228 | /** |
| 5229 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 5230 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 5231 | */ |
| 5232 | private boolean shouldShowIntroScreen() { |
| 5233 | return hasDismissableIntroScreen() && |
| 5234 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 5235 | } |
| 5236 | |
| 5237 | protected void showIntroScreen() { |
| 5238 | View introScreen = getIntroScreen(); |
| 5239 | changeWallpaperVisiblity(false); |
| 5240 | if (introScreen != null) { |
| 5241 | mDragLayer.showOverlayView(introScreen); |
| 5242 | } |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 5243 | if (mLauncherOverlayContainer != null) { |
| 5244 | mLauncherOverlayContainer.setVisibility(View.INVISIBLE); |
| 5245 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | public void dismissIntroScreen() { |
| 5249 | markIntroScreenDismissed(); |
| 5250 | if (showFirstRunActivity()) { |
| 5251 | // We delay hiding the intro view until the first run activity is showing. This |
| 5252 | // avoids a blip. |
| 5253 | mWorkspace.postDelayed(new Runnable() { |
| 5254 | @Override |
| 5255 | public void run() { |
| 5256 | mDragLayer.dismissOverlayView(); |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 5257 | if (mLauncherOverlayContainer != null) { |
| 5258 | mLauncherOverlayContainer.setVisibility(View.VISIBLE); |
| 5259 | } |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5260 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5261 | } |
| 5262 | }, ACTIVITY_START_DELAY); |
| 5263 | } else { |
| 5264 | mDragLayer.dismissOverlayView(); |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 5265 | if (mLauncherOverlayContainer != null) { |
| 5266 | mLauncherOverlayContainer.setVisibility(View.VISIBLE); |
| 5267 | } |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5268 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5269 | } |
| 5270 | changeWallpaperVisiblity(true); |
| 5271 | } |
| 5272 | |
| 5273 | private void markIntroScreenDismissed() { |
| 5274 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 5275 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 5276 | editor.apply(); |
| 5277 | } |
| 5278 | |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5279 | private void showFirstRunClings() { |
| 5280 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 5281 | // on the device, then we always show the first run cling experience (or if there is no |
| 5282 | // launcher2). Otherwise, we prompt the user upon started for migration |
| 5283 | LauncherClings launcherClings = new LauncherClings(this); |
| 5284 | if (launcherClings.shouldShowFirstRunOrMigrationClings()) { |
| 5285 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
| 5286 | launcherClings.showMigrationCling(); |
| 5287 | } else { |
Sunny Goyal | af0628f | 2014-09-19 10:14:48 -0700 | [diff] [blame] | 5288 | launcherClings.showLongPressCling(true); |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5289 | } |
| 5290 | } |
| 5291 | } |
| 5292 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5293 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 5294 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 5295 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 5296 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 5297 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 5301 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 5302 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 5303 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 5304 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5305 | } |
| 5306 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5307 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5308 | // Called from search suggestion, not supported in other profiles. |
| 5309 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 5310 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 5311 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 5312 | myUser); |
| 5313 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5314 | return null; |
| 5315 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5316 | return new AppInfo(this, activityInfo, myUser, mIconCache, null); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5320 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5321 | // Called from search suggestion, not supported in other profiles. |
| 5322 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 5323 | UserHandleCompat.myUserHandle()); |
| 5324 | } |
| 5325 | |
| 5326 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5327 | Bitmap icon, UserHandleCompat user) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5328 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 5329 | CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5330 | return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5331 | } |
| 5332 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 5333 | protected void moveWorkspaceToDefaultScreen() { |
| 5334 | mWorkspace.moveToDefaultScreen(false); |
| 5335 | } |
| 5336 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5337 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 5338 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 5339 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 5340 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5343 | @Override |
| 5344 | public void onPageSwitch(View newPage, int newPageIndex) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5345 | if (mLauncherCallbacks != null) { |
| 5346 | mLauncherCallbacks.onPageSwitch(newPage, newPageIndex); |
| 5347 | } |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5348 | } |
| 5349 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5350 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5351 | * Prints out out state for debugging. |
| 5352 | */ |
| 5353 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5354 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5355 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5356 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 5357 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 5358 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 5359 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 5360 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5361 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5362 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5363 | if (mAppsCustomizeContent != null) { |
| 5364 | mAppsCustomizeContent.dumpState(); |
| 5365 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5366 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5367 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5368 | |
| 5369 | @Override |
| 5370 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5371 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5372 | synchronized (sDumpLogs) { |
| 5373 | writer.println(" "); |
| 5374 | writer.println("Debug logs: "); |
| 5375 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5376 | writer.println(" " + sDumpLogs.get(i)); |
| 5377 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5378 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5379 | if (mLauncherCallbacks != null) { |
| 5380 | mLauncherCallbacks.dump(prefix, fd, writer, args); |
| 5381 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5382 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5383 | |
| 5384 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5385 | if (DEBUG_DUMP_LOG) { |
| 5386 | synchronized (sDumpLogs) { |
| 5387 | Log.d(TAG, ""); |
| 5388 | Log.d(TAG, "*********************"); |
| 5389 | Log.d(TAG, "Launcher debug logs: "); |
| 5390 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5391 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 5392 | } |
| 5393 | Log.d(TAG, "*********************"); |
| 5394 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5395 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5396 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5400 | addDumpLog(tag, log, null, debugLog); |
| 5401 | } |
| 5402 | |
| 5403 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5404 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5405 | if (e != null) { |
| 5406 | Log.d(tag, log, e); |
| 5407 | } else { |
| 5408 | Log.d(tag, log); |
| 5409 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5410 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5411 | if (DEBUG_DUMP_LOG) { |
| 5412 | sDateStamp.setTime(System.currentTimeMillis()); |
| 5413 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5414 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 5415 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5416 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5417 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5418 | } |
| 5419 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5420 | public void dumpLogsToLocalData() { |
| 5421 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5422 | new AsyncTask<Void, Void, Void>() { |
| 5423 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5424 | boolean success = false; |
| 5425 | sDateStamp.setTime(sRunStart); |
| 5426 | String FILENAME = sDateStamp.getMonth() + "-" |
| 5427 | + sDateStamp.getDay() + "_" |
| 5428 | + sDateStamp.getHours() + "-" |
| 5429 | + sDateStamp.getMinutes() + "_" |
| 5430 | + sDateStamp.getSeconds() + ".txt"; |
| 5431 | |
| 5432 | FileOutputStream fos = null; |
| 5433 | File outFile = null; |
| 5434 | try { |
| 5435 | outFile = new File(getFilesDir(), FILENAME); |
| 5436 | outFile.createNewFile(); |
| 5437 | fos = new FileOutputStream(outFile); |
| 5438 | } catch (Exception e) { |
| 5439 | e.printStackTrace(); |
| 5440 | } |
| 5441 | if (fos != null) { |
| 5442 | PrintWriter writer = new PrintWriter(fos); |
| 5443 | |
| 5444 | writer.println(" "); |
| 5445 | writer.println("Debug logs: "); |
| 5446 | synchronized (sDumpLogs) { |
| 5447 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5448 | writer.println(" " + sDumpLogs.get(i)); |
| 5449 | } |
| 5450 | } |
| 5451 | writer.close(); |
| 5452 | } |
| 5453 | try { |
| 5454 | if (fos != null) { |
| 5455 | fos.close(); |
| 5456 | success = true; |
| 5457 | } |
| 5458 | } catch (IOException e) { |
| 5459 | e.printStackTrace(); |
| 5460 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5461 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5462 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5463 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5464 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5465 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5466 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5467 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 5468 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 5469 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 5470 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5471 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 5472 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5473 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5474 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 5475 | |
| 5476 | interface DebugIntents { |
| 5477 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 5478 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 5479 | } |