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] |
| 171 | static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate"; |
| 172 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 173 | static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 174 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 175 | // The Intent extra that defines whether to ignore the launch animation |
| 176 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 177 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 178 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 179 | // Type: int |
| 180 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 181 | // Type: int |
| 182 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 183 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 184 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 185 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 186 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 187 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 188 | 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] | 189 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 190 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 191 | // Type: boolean |
| 192 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 193 | // Type: long |
| 194 | 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] | 195 | // Type: int |
| 196 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 197 | // Type: int |
| 198 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 199 | // Type: parcelable |
| 200 | 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] | 201 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 202 | 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] | 203 | // Type: int[] |
| 204 | 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] | 205 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 206 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 207 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 208 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 209 | static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete"; |
| 210 | static final String ACTION_FIRST_LOAD_COMPLETE = |
| 211 | "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; |
| 212 | |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 213 | 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] | 214 | private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 215 | "com.android.launcher.toolbar_search_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 216 | private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 217 | "com.android.launcher.toolbar_voice_search_icon"; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 218 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 219 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b800 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 220 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 221 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 222 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 223 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 224 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 225 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 226 | private State mState = State.WORKSPACE; |
| 227 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 228 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 229 | private boolean mIsSafeModeEnabled; |
| 230 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 231 | LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl(); |
| 232 | LauncherOverlay mLauncherOverlay; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 233 | InsettableFrameLayout mLauncherOverlayContainer; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 234 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 235 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 236 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 237 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 238 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 239 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 240 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 241 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 242 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 243 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 244 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 245 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 246 | // 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] | 247 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 248 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 249 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 250 | private static final int SINGLE_FRAME_DELAY = 16; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 251 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 252 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 253 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 254 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 255 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 256 | private LayoutInflater mInflater; |
| 257 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 258 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 259 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 260 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 261 | private DragLayer mDragLayer; |
| 262 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 263 | private View mWeightWatcher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 264 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 265 | private AppWidgetManagerCompat mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 266 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 267 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 268 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 269 | private AppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 270 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 271 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 272 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 273 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 274 | private FolderInfo mFolderInfo; |
| 275 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 276 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 277 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 278 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 279 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 280 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 281 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 282 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 283 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 284 | private boolean mAutoAdvanceRunning = false; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 285 | private View mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 286 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 287 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 288 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 289 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 290 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 291 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 292 | |
| 293 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 294 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 295 | private boolean mWorkspaceLoading = true; |
| 296 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 297 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 298 | private boolean mRestoring; |
| 299 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 300 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 301 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 302 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 303 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 304 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 305 | private Bundle mSavedInstanceState; |
| 306 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 307 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 308 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 309 | private boolean mUserPresent = true; |
| 310 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 311 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 312 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 313 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 314 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 315 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 316 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 317 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 318 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 319 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 320 | // Related to the auto-advancing of widgets |
| 321 | private final int ADVANCE_MSG = 1; |
| 322 | private final int mAdvanceInterval = 20000; |
| 323 | private final int mAdvanceStagger = 250; |
| 324 | private long mAutoAdvanceSentTime; |
| 325 | private long mAutoAdvanceTimeLeft = -1; |
| 326 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 327 | new HashMap<View, AppWidgetProviderInfo>(); |
| 328 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 329 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 330 | // match the sensor state. |
| 331 | private final int mRestoreScreenOrientationDelay = 500; |
| 332 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 333 | // External icons saved in case of resource changes, orientation, etc. |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 334 | private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; |
| 335 | private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 336 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 337 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 338 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 339 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 340 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 341 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 342 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 343 | static Date sDateStamp = new Date(); |
| 344 | static DateFormat sDateFormat = |
| 345 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 346 | static long sRunStart = System.currentTimeMillis(); |
| 347 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 348 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 349 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 350 | // it from the context. |
| 351 | private SharedPreferences mSharedPrefs; |
| 352 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 353 | private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null; |
| 354 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 355 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 356 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 357 | private ImageView mFolderIconImageView; |
| 358 | private Bitmap mFolderIconBitmap; |
| 359 | private Canvas mFolderIconCanvas; |
| 360 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 361 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 362 | private BubbleTextView mWaitingForResume; |
| 363 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 364 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 365 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 366 | if (mWorkspace != null) { |
| 367 | mWorkspace.buildPageHardwareLayers(); |
| 368 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 369 | } |
| 370 | }; |
| 371 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 372 | private static PendingAddArguments sPendingAddItem; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 373 | |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 374 | public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 375 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 376 | private static class PendingAddArguments { |
| 377 | int requestCode; |
| 378 | Intent intent; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 379 | long container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 380 | long screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 381 | int cellX; |
| 382 | int cellY; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 383 | int appWidgetId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 386 | private Stats mStats; |
| 387 | |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 388 | FocusIndicatorView mFocusHandler; |
| 389 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 390 | static boolean isPropertyEnabled(String propertyName) { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 391 | return Log.isLoggable(propertyName, Log.VERBOSE); |
Michael Jurka | 9bc8eba | 2012-05-21 20:36:44 -0700 | [diff] [blame] | 392 | } |
| 393 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 394 | @Override |
| 395 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 396 | if (DEBUG_STRICT_MODE) { |
| 397 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 398 | .detectDiskReads() |
| 399 | .detectDiskWrites() |
| 400 | .detectNetwork() // or .detectAll() for all detectable problems |
| 401 | .penaltyLog() |
| 402 | .build()); |
| 403 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 404 | .detectLeakedSqlLiteObjects() |
| 405 | .detectLeakedClosableObjects() |
| 406 | .penaltyLog() |
| 407 | .penaltyDeath() |
| 408 | .build()); |
| 409 | } |
| 410 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 411 | if (mLauncherCallbacks != null) { |
| 412 | mLauncherCallbacks.preOnCreate(); |
| 413 | } |
| 414 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 415 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 416 | |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 417 | LauncherAppState.setApplicationContext(getApplicationContext()); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 418 | LauncherAppState app = LauncherAppState.getInstance(); |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 419 | LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 420 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 421 | // Lazy-initialize the dynamic grid |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 422 | DeviceProfile grid = app.initDynamicGrid(this); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 423 | |
| 424 | // 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] | 425 | mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 426 | Context.MODE_PRIVATE); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 427 | mIsSafeModeEnabled = getPackageManager().isSafeMode(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 428 | mModel = app.setLauncher(this); |
| 429 | mIconCache = app.getIconCache(); |
Winson Chung | e5467dc | 2013-10-14 17:03:04 -0700 | [diff] [blame] | 430 | mIconCache.flushInvalidIcons(grid); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 431 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 432 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 433 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 434 | mStats = new Stats(this); |
| 435 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 436 | mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 437 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 438 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 439 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 440 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 441 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 442 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 443 | // LauncherModel load. |
| 444 | mPaused = false; |
| 445 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 446 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 447 | android.os.Debug.startMethodTracing( |
| 448 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 452 | setContentView(R.layout.launcher); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 453 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 454 | setupViews(); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 455 | grid.layout(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 456 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 457 | registerContentObservers(); |
| 458 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 459 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 460 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 461 | mSavedState = savedInstanceState; |
| 462 | restoreState(mSavedState); |
| 463 | |
| 464 | if (PROFILE_STARTUP) { |
| 465 | android.os.Debug.stopMethodTracing(); |
| 466 | } |
| 467 | |
| 468 | if (!mRestoring) { |
Adam Cohen | db78dc8 | 2014-06-19 14:50:51 -0700 | [diff] [blame] | 469 | if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 470 | // If the user leaves launcher, then we should just load items asynchronously when |
| 471 | // they return. |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 472 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 473 | } else { |
| 474 | // We only load the page synchronously if the user rotates (or triggers a |
| 475 | // configuration change) while launcher is in the foreground |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 476 | mModel.startLoader(true, mWorkspace.getRestorePage()); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 477 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | // For handling default keys |
| 481 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 482 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 483 | |
| 484 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 485 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 486 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 487 | updateGlobalIcons(); |
| 488 | |
| 489 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 490 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 491 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 492 | if (shouldShowIntroScreen()) { |
| 493 | showIntroScreen(); |
| 494 | } else { |
| 495 | showFirstRunActivity(); |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 496 | showFirstRunClings(); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 497 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 498 | |
| 499 | if (mLauncherCallbacks != null) { |
| 500 | mLauncherCallbacks.onCreate(savedInstanceState); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 501 | if (mLauncherCallbacks.hasLauncherOverlay()) { |
| 502 | ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub); |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 503 | mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate(); |
| 504 | mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView( |
| 505 | mLauncherOverlayContainer, mLauncherOverlayCallbacks); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 506 | mWorkspace.setLauncherOverlay(mLauncherOverlay); |
| 507 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
| 511 | private LauncherCallbacks mLauncherCallbacks; |
| 512 | |
| 513 | public void onPostCreate(Bundle savedInstanceState) { |
| 514 | super.onPostCreate(savedInstanceState); |
| 515 | if (mLauncherCallbacks != null) { |
| 516 | mLauncherCallbacks.onPostCreate(savedInstanceState); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { |
| 521 | mLauncherCallbacks = callbacks; |
| 522 | return true; |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 525 | @Override |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 526 | public void onLauncherProviderChange() { |
| 527 | if (mLauncherCallbacks != null) { |
| 528 | mLauncherCallbacks.onLauncherProviderChange(); |
| 529 | } |
| 530 | } |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 531 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 532 | /** 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] | 533 | protected boolean hasCustomContentToLeft() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 534 | if (mLauncherCallbacks != null) { |
| 535 | return mLauncherCallbacks.hasCustomContentToLeft(); |
| 536 | } |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 537 | return false; |
| 538 | } |
| 539 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 540 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 541 | * 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] | 542 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 543 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 544 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 545 | protected void populateCustomContentContainer() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 546 | if (mLauncherCallbacks != null) { |
| 547 | mLauncherCallbacks.populateCustomContentContainer(); |
| 548 | } |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 553 | * ensure the custom content page is added or removed if necessary. |
| 554 | */ |
| 555 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 556 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 557 | // Not bound yet, wait for bindScreens to be called. |
| 558 | return; |
| 559 | } |
| 560 | |
| 561 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 562 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 563 | mWorkspace.createCustomContentContainer(); |
| 564 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 565 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 566 | mWorkspace.removeCustomContentPage(); |
| 567 | } |
| 568 | } |
| 569 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 570 | private void updateGlobalIcons() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 571 | boolean searchVisible = false; |
| 572 | boolean voiceVisible = false; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 573 | // 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] | 574 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
Adam Cohen | a00673c | 2014-08-14 12:57:28 -0700 | [diff] [blame] | 575 | if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 576 | searchVisible = updateGlobalSearchIcon(); |
| 577 | voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 578 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 579 | if (sGlobalSearchIcon[coi] != null) { |
| 580 | updateGlobalSearchIcon(sGlobalSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 581 | searchVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 582 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 583 | if (sVoiceSearchIcon[coi] != null) { |
| 584 | updateVoiceSearchIcon(sVoiceSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 585 | voiceVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 586 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 587 | if (mSearchDropTargetBar != null) { |
| 588 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 589 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 590 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 591 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 592 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 593 | if (sLocaleConfiguration == null) { |
| 594 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 595 | @Override |
| 596 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 597 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 598 | readConfiguration(Launcher.this, localeConfiguration); |
| 599 | return localeConfiguration; |
| 600 | } |
| 601 | |
| 602 | @Override |
| 603 | protected void onPostExecute(LocaleConfiguration result) { |
| 604 | sLocaleConfiguration = result; |
| 605 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 606 | } |
| 607 | }.execute(); |
| 608 | return; |
| 609 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 610 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 611 | final Configuration configuration = getResources().getConfiguration(); |
| 612 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 613 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 614 | final String locale = configuration.locale.toString(); |
| 615 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 616 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 617 | final int mcc = configuration.mcc; |
| 618 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 619 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 620 | final int mnc = configuration.mnc; |
| 621 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 622 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 623 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 624 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 625 | sLocaleConfiguration.locale = locale; |
| 626 | sLocaleConfiguration.mcc = mcc; |
| 627 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 628 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 629 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 630 | |
| 631 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 632 | new AsyncTask<Void, Void, Void>() { |
| 633 | public Void doInBackground(Void ... args) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 634 | writeConfiguration(Launcher.this, localeConfiguration); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 635 | return null; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 636 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 637 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
| 641 | private static class LocaleConfiguration { |
| 642 | public String locale; |
| 643 | public int mcc = -1; |
| 644 | public int mnc = -1; |
| 645 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 646 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 647 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 648 | DataInputStream in = null; |
| 649 | try { |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 650 | in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 651 | configuration.locale = in.readUTF(); |
| 652 | configuration.mcc = in.readInt(); |
| 653 | configuration.mnc = in.readInt(); |
| 654 | } catch (FileNotFoundException e) { |
| 655 | // Ignore |
| 656 | } catch (IOException e) { |
| 657 | // Ignore |
| 658 | } finally { |
| 659 | if (in != null) { |
| 660 | try { |
| 661 | in.close(); |
| 662 | } catch (IOException e) { |
| 663 | // Ignore |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 670 | DataOutputStream out = null; |
| 671 | try { |
Helena Josol | 4fbbb3e | 2014-10-06 16:06:46 +0100 | [diff] [blame] | 672 | out = new DataOutputStream(context.openFileOutput( |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 673 | LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 674 | out.writeUTF(configuration.locale); |
| 675 | out.writeInt(configuration.mcc); |
| 676 | out.writeInt(configuration.mnc); |
| 677 | out.flush(); |
| 678 | } catch (FileNotFoundException e) { |
| 679 | // Ignore |
| 680 | } catch (IOException e) { |
| 681 | //noinspection ResultOfMethodCallIgnored |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 682 | context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 683 | } finally { |
| 684 | if (out != null) { |
| 685 | try { |
| 686 | out.close(); |
| 687 | } catch (IOException e) { |
| 688 | // Ignore |
| 689 | } |
| 690 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 694 | public Stats getStats() { |
| 695 | return mStats; |
| 696 | } |
| 697 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 698 | public LayoutInflater getInflater() { |
| 699 | return mInflater; |
| 700 | } |
| 701 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 702 | boolean isDraggingEnabled() { |
| 703 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 704 | // that is subsequently removed from the workspace in startBinding(). |
| 705 | return !mModel.isLoadingWorkspace(); |
| 706 | } |
| 707 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 708 | static int getScreen() { |
| 709 | synchronized (sLock) { |
| 710 | return sScreen; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | static void setScreen(int screen) { |
| 715 | synchronized (sLock) { |
| 716 | sScreen = screen; |
| 717 | } |
| 718 | } |
| 719 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 720 | public static int generateViewId() { |
Ian Parkinson | 0c2918f | 2014-10-06 14:24:31 +0100 | [diff] [blame] | 721 | if (Build.VERSION.SDK_INT >= 17) { |
| 722 | return View.generateViewId(); |
| 723 | } else { |
| 724 | // View.generateViewId() is not available. The following fallback logic is a copy |
| 725 | // of its implementation. |
| 726 | for (;;) { |
| 727 | final int result = sNextGeneratedId.get(); |
| 728 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 729 | int newValue = result + 1; |
| 730 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 731 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 732 | return result; |
| 733 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | public int getViewIdForItem(ItemInfo info) { |
| 739 | // This cast is safe given the > 2B range for int. |
| 740 | int itemId = (int) info.id; |
| 741 | if (mItemIdToViewId.containsKey(itemId)) { |
| 742 | return mItemIdToViewId.get(itemId); |
| 743 | } |
| 744 | int viewId = generateViewId(); |
| 745 | mItemIdToViewId.put(itemId, viewId); |
| 746 | return viewId; |
| 747 | } |
| 748 | |
| 749 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 750 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 751 | * a configuration step, this allows the proper animations to run after other transitions. |
| 752 | */ |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 753 | private long completeAdd(PendingAddArguments args) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 754 | long screenId = args.screenId; |
| 755 | if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 756 | // When the screen id represents an actual screen (as opposed to a rank) we make sure |
| 757 | // that the drop page actually exists. |
| 758 | screenId = ensurePendingDropLayoutExists(args.screenId); |
| 759 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 760 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 761 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 762 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 763 | completeAddShortcut(args.intent, args.container, screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 764 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 765 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 766 | case REQUEST_CREATE_APPWIDGET: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 767 | completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 768 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 769 | case REQUEST_RECONFIGURE_APPWIDGET: |
| 770 | completeRestoreAppWidget(args.appWidgetId); |
| 771 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 772 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 773 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 774 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 775 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 776 | resetAddInfo(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 777 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 778 | } |
| 779 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 780 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 781 | protected void onActivityResult( |
| 782 | final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 783 | // Reset the startActivity waiting flag |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 784 | setWaitingForResult(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 785 | final int pendingAddWidgetId = mPendingAddWidgetId; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 786 | mPendingAddWidgetId = -1; |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 787 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 788 | Runnable exitSpringLoaded = new Runnable() { |
| 789 | @Override |
| 790 | public void run() { |
| 791 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 792 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 793 | } |
| 794 | }; |
| 795 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 796 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 797 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 798 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 799 | if (resultCode == RESULT_CANCELED) { |
| 800 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 801 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 802 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 803 | } else if (resultCode == RESULT_OK) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 804 | addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, |
| 805 | mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 806 | } |
| 807 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 808 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 809 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
| 810 | mWorkspace.exitOverviewMode(false); |
| 811 | } |
| 812 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 813 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 814 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 815 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 816 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 817 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 818 | final boolean workspaceLocked = isWorkspaceLocked(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 819 | // We have special handling for widgets |
| 820 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 821 | final int appWidgetId; |
| 822 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 823 | : -1; |
| 824 | if (widgetId < 0) { |
| 825 | appWidgetId = pendingAddWidgetId; |
| 826 | } else { |
| 827 | appWidgetId = widgetId; |
| 828 | } |
| 829 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 830 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 831 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 832 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 833 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 834 | result = RESULT_CANCELED; |
| 835 | completeTwoStageWidgetDrop(result, appWidgetId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 836 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 837 | @Override |
| 838 | public void run() { |
| 839 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 840 | } |
| 841 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 842 | if (workspaceLocked) { |
| 843 | // No need to remove the empty screen if we're mid-binding, as the |
| 844 | // the bind will not add the empty screen. |
| 845 | mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
| 846 | } else { |
| 847 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 848 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 849 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 850 | } else { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 851 | if (!workspaceLocked) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 852 | if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 853 | // When the screen id represents an actual screen (as opposed to a rank) |
| 854 | // we make sure that the drop page actually exists. |
| 855 | mPendingAddInfo.screenId = |
| 856 | ensurePendingDropLayoutExists(mPendingAddInfo.screenId); |
| 857 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 858 | final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
| 859 | |
| 860 | dropLayout.setDropPending(true); |
| 861 | final Runnable onComplete = new Runnable() { |
| 862 | @Override |
| 863 | public void run() { |
| 864 | completeTwoStageWidgetDrop(resultCode, appWidgetId); |
| 865 | dropLayout.setDropPending(false); |
| 866 | } |
| 867 | }; |
| 868 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 869 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 870 | } else { |
| 871 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId, |
| 872 | mPendingAddInfo); |
| 873 | sPendingAddItem = args; |
| 874 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 875 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 876 | return; |
| 877 | } |
| 878 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 879 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) { |
| 880 | if (resultCode == RESULT_OK) { |
| 881 | // Update the widget view. |
| 882 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, |
| 883 | pendingAddWidgetId, mPendingAddInfo); |
| 884 | if (workspaceLocked) { |
| 885 | sPendingAddItem = args; |
| 886 | } else { |
| 887 | completeAdd(args); |
| 888 | } |
| 889 | } |
| 890 | // Leave the widget in the pending state if the user canceled the configure. |
| 891 | return; |
| 892 | } |
| 893 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 894 | // The pattern used here is that a user PICKs a specific application, |
| 895 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 896 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 897 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 898 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Winson Chung | c7da555 | 2011-08-10 15:28:45 -0700 | [diff] [blame] | 899 | if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 900 | final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1, |
| 901 | mPendingAddInfo); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 902 | if (isWorkspaceLocked()) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 903 | sPendingAddItem = args; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 904 | } else { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 905 | completeAdd(args); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 906 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 907 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 908 | } |
Adam Cohen | 0007472 | 2013-10-11 17:46:09 -0700 | [diff] [blame] | 909 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 910 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 911 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 912 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 913 | mDragLayer.clearAnimatedView(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 916 | private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int |
| 917 | appWidgetId, ItemInfo info) { |
| 918 | PendingAddArguments args = new PendingAddArguments(); |
| 919 | args.requestCode = requestCode; |
| 920 | args.intent = data; |
| 921 | args.container = info.container; |
| 922 | args.screenId = info.screenId; |
| 923 | args.cellX = info.cellX; |
| 924 | args.cellY = info.cellY; |
| 925 | args.appWidgetId = appWidgetId; |
| 926 | return args; |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 931 | * |
| 932 | * @param screenId the screen id to check |
| 933 | * @return the new screen, or screenId if it exists |
| 934 | */ |
| 935 | private long ensurePendingDropLayoutExists(long screenId) { |
| 936 | CellLayout dropLayout = |
| 937 | (CellLayout) mWorkspace.getScreenWithId(screenId); |
| 938 | if (dropLayout == null) { |
| 939 | // it's possible that the add screen was removed because it was |
| 940 | // empty and a re-bind occurred |
| 941 | mWorkspace.addExtraEmptyScreen(); |
| 942 | return mWorkspace.commitExtraEmptyScreen(); |
| 943 | } else { |
| 944 | return screenId; |
| 945 | } |
| 946 | } |
| 947 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 948 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 949 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 950 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 951 | Runnable onCompleteRunnable = null; |
| 952 | int animationType = 0; |
| 953 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 954 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 955 | if (resultCode == RESULT_OK) { |
| 956 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 957 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 958 | mPendingAddWidgetInfo); |
| 959 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 960 | onCompleteRunnable = new Runnable() { |
| 961 | @Override |
| 962 | public void run() { |
| 963 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 964 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 965 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 966 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 967 | } |
| 968 | }; |
| 969 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 970 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 971 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 972 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 973 | if (mDragLayer.getAnimatedView() != null) { |
| 974 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 975 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 976 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 977 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 978 | // The animated view may be null in the case of a rotation during widget configuration |
| 979 | onCompleteRunnable.run(); |
| 980 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 984 | protected void onStop() { |
| 985 | super.onStop(); |
| 986 | FirstFrameAnimatorHelper.setIsVisible(false); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 987 | |
| 988 | if (mLauncherCallbacks != null) { |
| 989 | mLauncherCallbacks.onStop(); |
| 990 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | @Override |
| 994 | protected void onStart() { |
| 995 | super.onStart(); |
| 996 | FirstFrameAnimatorHelper.setIsVisible(true); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 997 | |
| 998 | if (mLauncherCallbacks != null) { |
| 999 | mLauncherCallbacks.onStart(); |
| 1000 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1004 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1005 | long startTime = 0; |
| 1006 | if (DEBUG_RESUME_TIME) { |
| 1007 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1008 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1009 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1010 | |
| 1011 | if (mLauncherCallbacks != null) { |
| 1012 | mLauncherCallbacks.preOnResume(); |
| 1013 | } |
| 1014 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1015 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1016 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1017 | // Restore the previous launcher state |
| 1018 | if (mOnResumeState == State.WORKSPACE) { |
| 1019 | showWorkspace(false); |
| 1020 | } else if (mOnResumeState == State.APPS_CUSTOMIZE) { |
Winson Chung | 07e045c6 | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 1021 | showAllApps(false, mAppsCustomizeContent.getContentType(), false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1022 | } |
| 1023 | mOnResumeState = State.NONE; |
| 1024 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1025 | // Background was set to gradient in onPause(), restore to black if in all apps. |
| 1026 | setWorkspaceBackground(mState == State.WORKSPACE); |
| 1027 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1028 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1029 | if (mRestoring || mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1030 | setWorkspaceLoading(true); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 1031 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1032 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1033 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1034 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1035 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1036 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 1037 | // execute them here |
| 1038 | long startTimeCallbacks = 0; |
| 1039 | if (DEBUG_RESUME_TIME) { |
| 1040 | startTimeCallbacks = System.currentTimeMillis(); |
| 1041 | } |
| 1042 | |
| 1043 | if (mAppsCustomizeContent != null) { |
| 1044 | mAppsCustomizeContent.setBulkBind(true); |
| 1045 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1046 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 1047 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1048 | } |
| 1049 | if (mAppsCustomizeContent != null) { |
| 1050 | mAppsCustomizeContent.setBulkBind(false); |
| 1051 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1052 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1053 | if (DEBUG_RESUME_TIME) { |
| 1054 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 1055 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 1056 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1057 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 1058 | if (mOnResumeCallbacks.size() > 0) { |
| 1059 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 1060 | mOnResumeCallbacks.get(i).run(); |
| 1061 | } |
| 1062 | mOnResumeCallbacks.clear(); |
| 1063 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1064 | |
| 1065 | // Reset the pressed state of icons that were locked in the press state while activities |
| 1066 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1067 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1068 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1069 | mWaitingForResume.setStayPressed(false); |
| 1070 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 1071 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1072 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 1073 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 1074 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 1075 | // orientation. |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1076 | getWorkspace().reinflateWidgetsIfNecessary(); |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1077 | |
Winson Chung | 780fe59 | 2013-09-26 14:48:44 -0700 | [diff] [blame] | 1078 | // Process any items that were added while Launcher was away. |
| 1079 | InstallShortcutReceiver.disableAndFlushInstallQueue(this); |
| 1080 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 1081 | // Update the voice search button proxy |
| 1082 | updateVoiceButtonProxyVisible(false); |
| 1083 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1084 | // Again, as with the above scenario, it's possible that one or more of the global icons |
| 1085 | // were updated in the wrong orientation. |
| 1086 | updateGlobalIcons(); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1087 | if (DEBUG_RESUME_TIME) { |
| 1088 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1089 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1090 | |
| 1091 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1092 | // If we are resuming and the custom content is the current page, we call onShow(). |
| 1093 | // It is also poassible that onShow will instead be called slightly after first layout |
| 1094 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1095 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1096 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1097 | } |
| 1098 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 1099 | mWorkspace.updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1100 | mWorkspace.onResume(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1101 | |
| 1102 | PackageInstallerCompat.getInstance(this).onResume(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1103 | |
| 1104 | if (mLauncherCallbacks != null) { |
| 1105 | mLauncherCallbacks.onResume(); |
| 1106 | } |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1109 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1110 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1111 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1112 | InstallShortcutReceiver.enableInstallQueue(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1113 | PackageInstallerCompat.getInstance(this).onPause(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1114 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1115 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1116 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1117 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1118 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1119 | |
| 1120 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1121 | // debounce excess onHide calls. |
| 1122 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1123 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1124 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1125 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1126 | if (mLauncherCallbacks != null) { |
| 1127 | mLauncherCallbacks.onPause(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1128 | } |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1132 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1133 | // by a onResume or by scrolling otherwise. |
| 1134 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1135 | |
| 1136 | // Custom content is completely hidden |
| 1137 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1138 | |
| 1139 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1140 | public void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1141 | |
| 1142 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1143 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1146 | public interface LauncherOverlay { |
| 1147 | |
| 1148 | /** |
| 1149 | * Touch interaction leading to overscroll has begun |
| 1150 | */ |
| 1151 | public void onScrollInteractionBegin(); |
| 1152 | |
| 1153 | /** |
| 1154 | * Touch interaction related to overscroll has ended |
| 1155 | */ |
| 1156 | public void onScrollInteractionEnd(); |
| 1157 | |
| 1158 | /** |
| 1159 | * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost |
| 1160 | * screen (or in the case of RTL, the rightmost screen). |
| 1161 | */ |
| 1162 | public void onScrollChange(int progress, boolean rtl); |
| 1163 | |
| 1164 | /** |
| 1165 | * Screen has stopped scrolling |
| 1166 | */ |
| 1167 | public void onScrollSettled(); |
| 1168 | |
| 1169 | /** |
| 1170 | * This method can be called by the Launcher in order to force the LauncherOverlay |
| 1171 | * to exit fully immersive mode. |
| 1172 | */ |
| 1173 | public void forceExitFullImmersion(); |
| 1174 | } |
| 1175 | |
| 1176 | public interface LauncherOverlayCallbacks { |
| 1177 | /** |
| 1178 | * This method indicates whether a call to {@link #enterFullImmersion()} will succeed, |
| 1179 | * however it doesn't modify any state within the launcher. |
| 1180 | */ |
| 1181 | public boolean canEnterFullImmersion(); |
| 1182 | |
| 1183 | /** |
| 1184 | * Should be called to tell Launcher that the LauncherOverlay will take over interaction, |
| 1185 | * eg. by occupying the full screen and handling all touch events. |
| 1186 | * |
| 1187 | * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this |
| 1188 | * case, Launcher will modify any necessary state and assumes the overlay is |
| 1189 | * handling all interaction. If false, the LauncherOverlay should cancel any |
| 1190 | * |
| 1191 | */ |
| 1192 | public boolean enterFullImmersion(); |
| 1193 | |
| 1194 | /** |
| 1195 | * Must be called when exiting fully immersive mode. Indicates to Launcher that it has |
| 1196 | * full control over UI and state. |
| 1197 | */ |
| 1198 | public void exitFullImmersion(); |
| 1199 | } |
| 1200 | |
| 1201 | class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks { |
| 1202 | |
| 1203 | @Override |
| 1204 | public boolean canEnterFullImmersion() { |
| 1205 | return mState == State.WORKSPACE; |
| 1206 | } |
| 1207 | |
| 1208 | @Override |
| 1209 | public boolean enterFullImmersion() { |
| 1210 | if (mState == State.WORKSPACE) { |
| 1211 | // When fully immersed, disregard any touches which fall through. |
| 1212 | mDragLayer.setBlockTouch(true); |
| 1213 | return true; |
| 1214 | } |
| 1215 | return false; |
| 1216 | } |
| 1217 | |
| 1218 | @Override |
| 1219 | public void exitFullImmersion() { |
| 1220 | mDragLayer.setBlockTouch(false); |
| 1221 | } |
| 1222 | } |
| 1223 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1224 | protected boolean hasSettings() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1225 | if (mLauncherCallbacks != null) { |
| 1226 | return mLauncherCallbacks.hasSettings(); |
| 1227 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1228 | return false; |
| 1229 | } |
| 1230 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1231 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1232 | public void addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1233 | CustomContentCallbacks callbacks, String description) { |
| 1234 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1237 | // The custom content needs to offset its content to account for the QSB |
| 1238 | public int getTopOffsetForCustomContent() { |
| 1239 | return mWorkspace.getPaddingTop(); |
| 1240 | } |
| 1241 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1242 | @Override |
| 1243 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1244 | // Flag the loader to stop early before switching |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1245 | if (mModel.isCurrentCallbacks(this)) { |
| 1246 | mModel.stopLoader(); |
| 1247 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1248 | if (mAppsCustomizeContent != null) { |
| 1249 | mAppsCustomizeContent.surrender(); |
| 1250 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1251 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1252 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1253 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1254 | // 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] | 1255 | @Override |
| 1256 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1257 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1258 | mHasFocus = hasFocus; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1259 | |
| 1260 | if (mLauncherCallbacks != null) { |
| 1261 | mLauncherCallbacks.onWindowFocusChanged(hasFocus); |
| 1262 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1263 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1264 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1265 | private boolean acceptFilter() { |
| 1266 | final InputMethodManager inputManager = (InputMethodManager) |
| 1267 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1268 | return !inputManager.isFullscreenMode(); |
| 1269 | } |
| 1270 | |
| 1271 | @Override |
| 1272 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1273 | final int uniChar = event.getUnicodeChar(); |
| 1274 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1275 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1276 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1277 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1278 | keyCode, event); |
| 1279 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1280 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1281 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1282 | // showSearchDialog() |
| 1283 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1284 | // onSearchRequested() will be called for every keystroke, |
| 1285 | // but it is idempotent, so it's fine. |
| 1286 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1290 | // Eat the long press event so the keyboard doesn't come up. |
| 1291 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1292 | return true; |
| 1293 | } |
| 1294 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1295 | return handled; |
| 1296 | } |
| 1297 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1298 | private String getTypedText() { |
| 1299 | return mDefaultKeySsb.toString(); |
| 1300 | } |
| 1301 | |
| 1302 | private void clearTypedText() { |
| 1303 | mDefaultKeySsb.clear(); |
| 1304 | mDefaultKeySsb.clearSpans(); |
| 1305 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1306 | } |
| 1307 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1308 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1309 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1310 | * State |
| 1311 | */ |
| 1312 | private static State intToState(int stateOrdinal) { |
| 1313 | State state = State.WORKSPACE; |
| 1314 | final State[] stateValues = State.values(); |
| 1315 | for (int i = 0; i < stateValues.length; i++) { |
| 1316 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1317 | state = stateValues[i]; |
| 1318 | break; |
| 1319 | } |
| 1320 | } |
| 1321 | return state; |
| 1322 | } |
| 1323 | |
| 1324 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1325 | * Restores the previous state, if it exists. |
| 1326 | * |
| 1327 | * @param savedState The previous state. |
| 1328 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1329 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1330 | private void restoreState(Bundle savedState) { |
| 1331 | if (savedState == null) { |
| 1332 | return; |
| 1333 | } |
| 1334 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1335 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1336 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1337 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1338 | } |
| 1339 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1340 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1341 | PagedView.INVALID_RESTORE_PAGE); |
| 1342 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1343 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1344 | } |
| 1345 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1346 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1347 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1348 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1349 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1350 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1351 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1352 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1353 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1354 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1355 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 1356 | mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1357 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1358 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1359 | mRestoring = true; |
| 1360 | } |
| 1361 | |
| 1362 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1363 | if (renameFolder) { |
| 1364 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1365 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1366 | mRestoring = true; |
| 1367 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1368 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1369 | // Restore the AppsCustomize tab |
| 1370 | if (mAppsCustomizeTabHost != null) { |
| 1371 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1372 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1373 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1374 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1375 | mAppsCustomizeContent.loadAssociatedPages( |
| 1376 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1379 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1380 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1381 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1382 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1383 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | /** |
| 1387 | * Finds all the views we need and configure them properly. |
| 1388 | */ |
| 1389 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1390 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1391 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1392 | mLauncherView = findViewById(R.id.launcher); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1393 | mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1394 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1395 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1396 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1397 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1398 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1399 | mLauncherView.setSystemUiVisibility( |
| 1400 | 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] | 1401 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1402 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1403 | // Setup the drag layer |
| 1404 | mDragLayer.setup(this, dragController); |
| 1405 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1406 | // Setup the hotseat |
| 1407 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1408 | if (mHotseat != null) { |
| 1409 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1410 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1413 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1414 | View widgetButton = findViewById(R.id.widget_button); |
| 1415 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1416 | @Override |
| 1417 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1418 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1419 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1420 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1421 | } |
| 1422 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1423 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1424 | |
| 1425 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1426 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1427 | @Override |
| 1428 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1429 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1430 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1431 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1432 | } |
| 1433 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1434 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1435 | |
| 1436 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1437 | if (hasSettings()) { |
| 1438 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1439 | @Override |
| 1440 | public void onClick(View arg0) { |
| 1441 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1442 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1443 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1444 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1445 | }); |
| 1446 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1447 | } else { |
| 1448 | settingsButton.setVisibility(View.GONE); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1449 | } |
| 1450 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1451 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1452 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1453 | // Setup the workspace |
| 1454 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1455 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1456 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1457 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1458 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1459 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1460 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1461 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1462 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1463 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1464 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1465 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1466 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1467 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1468 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1469 | // 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] | 1470 | dragController.setDragScoller(mWorkspace); |
| 1471 | dragController.setScrollView(mDragLayer); |
| 1472 | dragController.setMoveTarget(mWorkspace); |
| 1473 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1474 | if (mSearchDropTargetBar != null) { |
| 1475 | mSearchDropTargetBar.setup(this, dragController); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1476 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1477 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1478 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1479 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1480 | mWeightWatcher = new WeightWatcher(this); |
| 1481 | mWeightWatcher.setAlpha(0.5f); |
| 1482 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1483 | new FrameLayout.LayoutParams( |
| 1484 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1485 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1486 | Gravity.BOTTOM) |
| 1487 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1488 | |
| 1489 | boolean show = shouldShowWeightWatcher(); |
| 1490 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1491 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1495 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1496 | */ |
| 1497 | public void setAllAppsButton(View allAppsButton) { |
| 1498 | mAllAppsButton = allAppsButton; |
| 1499 | } |
| 1500 | |
| 1501 | public View getAllAppsButton() { |
| 1502 | return mAllAppsButton; |
| 1503 | } |
| 1504 | |
| 1505 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1506 | * Creates a view representing a shortcut. |
| 1507 | * |
| 1508 | * @param info The data structure describing the shortcut. |
| 1509 | * |
| 1510 | * @return A View inflated from R.layout.application. |
| 1511 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1512 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1513 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1514 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | /** |
| 1518 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1519 | * |
| 1520 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1521 | * @param parent The group the shortcut belongs to. |
| 1522 | * @param info The data structure describing the shortcut. |
| 1523 | * |
| 1524 | * @return A View inflated from layoutResId. |
| 1525 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1526 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1527 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 1528 | favorite.applyFromShortcutInfo(info, mIconCache, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1529 | favorite.setOnClickListener(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1530 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1531 | return favorite; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1535 | * Add a shortcut to the workspace. |
| 1536 | * |
| 1537 | * @param data The intent describing the shortcut. |
| 1538 | * @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] | 1539 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1540 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1541 | int cellY) { |
| 1542 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1543 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1544 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1545 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1546 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1547 | |
Sunny Goyal | 2350bc9 | 2014-10-14 16:42:54 -0700 | [diff] [blame] | 1548 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1549 | if (info == null) { |
| 1550 | return; |
| 1551 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1552 | final View view = createShortcut(info); |
| 1553 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1554 | // First we check if we already know the exact location where we want to add this item. |
| 1555 | if (cellX >= 0 && cellY >= 0) { |
| 1556 | cellXY[0] = cellX; |
| 1557 | cellXY[1] = cellY; |
| 1558 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1559 | |
| 1560 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1561 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1562 | true, null,null)) { |
| 1563 | return; |
| 1564 | } |
| 1565 | DragObject dragObject = new DragObject(); |
| 1566 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1567 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1568 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1569 | return; |
| 1570 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1571 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1572 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1573 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1574 | foundCellSpan = (result != null); |
| 1575 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1576 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1580 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1581 | return; |
| 1582 | } |
| 1583 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1584 | 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] | 1585 | |
| 1586 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1587 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1588 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1592 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1593 | int minHeight) { |
| 1594 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1595 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1596 | // to ensure that it gets the full amount of space that it has requested |
| 1597 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1598 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1599 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1602 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1603 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1606 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1607 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1610 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1611 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1614 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1615 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1616 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1617 | } |
| 1618 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1619 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1620 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1621 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1622 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1623 | * @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] | 1624 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1625 | private void completeAddAppWidget(final int appWidgetId, long container, long screenId, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1626 | AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1627 | if (appWidgetInfo == null) { |
| 1628 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1629 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1630 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1631 | // Calculate the grid spans needed to fit this widget |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1632 | CellLayout layout = getCellLayout(container, screenId); |
Adam Cohen | 0935386 | 2011-07-14 16:10:03 -0700 | [diff] [blame] | 1633 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1634 | int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo); |
| 1635 | int[] spanXY = getSpanForWidget(this, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1636 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1637 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1638 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1639 | // if we are placing widgets on a "spring-loaded" screen |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1640 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1641 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1642 | int[] finalSpan = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1643 | boolean foundCellSpan = false; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1644 | if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { |
| 1645 | cellXY[0] = mPendingAddInfo.cellX; |
| 1646 | cellXY[1] = mPendingAddInfo.cellY; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1647 | spanXY[0] = mPendingAddInfo.spanX; |
| 1648 | spanXY[1] = mPendingAddInfo.spanY; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1649 | foundCellSpan = true; |
| 1650 | } else if (touchXY != null) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1651 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1652 | int[] result = layout.findNearestVacantArea( |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1653 | touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], |
| 1654 | spanXY[1], cellXY, finalSpan); |
| 1655 | spanXY[0] = finalSpan[0]; |
| 1656 | spanXY[1] = finalSpan[1]; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1657 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1658 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1659 | foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1662 | if (!foundCellSpan) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1663 | if (appWidgetId != -1) { |
| 1664 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 1665 | // to the caller... |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1666 | new AsyncTask<Void, Void, Void>() { |
| 1667 | public Void doInBackground(Void ... args) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1668 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1669 | return null; |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1670 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1671 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1672 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1673 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1674 | return; |
| 1675 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1676 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1677 | // Build Launcher-specific widget info and save to database |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 1678 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, |
| 1679 | appWidgetInfo.provider); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1680 | launcherInfo.spanX = spanXY[0]; |
| 1681 | launcherInfo.spanY = spanXY[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1682 | launcherInfo.minSpanX = mPendingAddInfo.minSpanX; |
| 1683 | launcherInfo.minSpanY = mPendingAddInfo.minSpanY; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1684 | launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1685 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1686 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1687 | container, screenId, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1688 | |
| 1689 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1690 | if (hostView == null) { |
| 1691 | // Perform actual inflation because we're live |
| 1692 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1693 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1694 | } else { |
| 1695 | // The AppWidgetHostView has already been inflated and instantiated |
| 1696 | launcherInfo.hostView = hostView; |
| 1697 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1698 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1699 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1700 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1701 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1702 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1703 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1704 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1705 | |
| 1706 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1707 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1708 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1709 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1710 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1711 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1712 | @Override |
| 1713 | public void onReceive(Context context, Intent intent) { |
| 1714 | final String action = intent.getAction(); |
| 1715 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1716 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1717 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1718 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1719 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1720 | // 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] | 1721 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1722 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1723 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1724 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1725 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1726 | mUserPresent = true; |
| 1727 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1728 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1729 | mModel.resetLoadedState(false, true); |
| 1730 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1731 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1732 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1733 | mModel.resetLoadedState(false, true); |
| 1734 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1735 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1736 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1737 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1738 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1739 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1740 | } |
| 1741 | } |
| 1742 | }; |
| 1743 | |
| 1744 | @Override |
| 1745 | public void onAttachedToWindow() { |
| 1746 | super.onAttachedToWindow(); |
| 1747 | |
| 1748 | // Listen for broadcasts related to user-presence |
| 1749 | final IntentFilter filter = new IntentFilter(); |
| 1750 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1751 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1752 | // For handling managed profiles |
| 1753 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1754 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1755 | if (ENABLE_DEBUG_INTENTS) { |
| 1756 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1757 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1758 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1759 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1760 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1761 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1762 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1763 | mVisible = true; |
| 1764 | } |
| 1765 | |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1766 | /** |
| 1767 | * Sets up transparent navigation and status bars in LMP. |
| 1768 | * This method is a no-op for other platform versions. |
| 1769 | */ |
| 1770 | @TargetApi(19) |
| 1771 | private void setupTransparentSystemBarsForLmp() { |
| 1772 | // TODO(sansid): use the APIs directly when compiling against L sdk. |
| 1773 | // Currently we use reflection to access the flags and the API to set the transparency |
| 1774 | // on the System bars. |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 1775 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1776 | try { |
| 1777 | getWindow().getAttributes().systemUiVisibility |= |
| 1778 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1779 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1780 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1781 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
| 1782 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
| 1783 | Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( |
| 1784 | "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); |
| 1785 | getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); |
| 1786 | |
| 1787 | Method setStatusBarColorMethod = |
| 1788 | Window.class.getDeclaredMethod("setStatusBarColor", int.class); |
| 1789 | Method setNavigationBarColorMethod = |
| 1790 | Window.class.getDeclaredMethod("setNavigationBarColor", int.class); |
| 1791 | setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1792 | setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1793 | } catch (NoSuchFieldException e) { |
| 1794 | Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); |
| 1795 | } catch (NoSuchMethodException ex) { |
| 1796 | Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); |
| 1797 | } catch (IllegalAccessException e) { |
| 1798 | Log.w(TAG, "IllegalAccessException while setting up transparent bars"); |
| 1799 | } catch (IllegalArgumentException e) { |
| 1800 | Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); |
| 1801 | } catch (InvocationTargetException e) { |
| 1802 | Log.w(TAG, "InvocationTargetException while setting up transparent bars"); |
| 1803 | } finally {} |
| 1804 | } |
| 1805 | } |
| 1806 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1807 | @Override |
| 1808 | public void onDetachedFromWindow() { |
| 1809 | super.onDetachedFromWindow(); |
| 1810 | mVisible = false; |
| 1811 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1812 | if (mAttached) { |
| 1813 | unregisterReceiver(mReceiver); |
| 1814 | mAttached = false; |
| 1815 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1816 | updateRunning(); |
| 1817 | } |
| 1818 | |
| 1819 | public void onWindowVisibilityChanged(int visibility) { |
| 1820 | mVisible = visibility == View.VISIBLE; |
| 1821 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1822 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1823 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1824 | // is a more appropriate event to handle |
| 1825 | if (mVisible) { |
| 1826 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1827 | if (!mWorkspaceLoading) { |
| 1828 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1829 | // We want to let Launcher draw itself at least once before we force it to build |
| 1830 | // 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] | 1831 | // apps is nice and speedy. |
| 1832 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1833 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1834 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1835 | if (mStarted) return; |
| 1836 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1837 | // We delay the layer building a bit in order to give |
| 1838 | // other message processing a time to run. In particular |
| 1839 | // this avoids a delay in hiding the IME if it was |
| 1840 | // currently shown, because doing that may involve |
| 1841 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1842 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1843 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1844 | mWorkspace.post(new Runnable() { |
| 1845 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1846 | if (mWorkspace != null && |
| 1847 | mWorkspace.getViewTreeObserver() != null) { |
| 1848 | mWorkspace.getViewTreeObserver(). |
| 1849 | removeOnDrawListener(listener); |
| 1850 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1851 | } |
| 1852 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1853 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1854 | } |
| 1855 | }); |
| 1856 | } |
| 1857 | clearTypedText(); |
| 1858 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | private void sendAdvanceMessage(long delay) { |
| 1862 | mHandler.removeMessages(ADVANCE_MSG); |
| 1863 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1864 | mHandler.sendMessageDelayed(msg, delay); |
| 1865 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1866 | } |
| 1867 | |
| 1868 | private void updateRunning() { |
| 1869 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1870 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1871 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1872 | if (autoAdvanceRunning) { |
| 1873 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1874 | sendAdvanceMessage(delay); |
| 1875 | } else { |
| 1876 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1877 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1878 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1879 | } |
| 1880 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1881 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | private final Handler mHandler = new Handler() { |
| 1887 | @Override |
| 1888 | public void handleMessage(Message msg) { |
| 1889 | if (msg.what == ADVANCE_MSG) { |
| 1890 | int i = 0; |
| 1891 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1892 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1893 | final int delay = mAdvanceStagger * i; |
| 1894 | if (v instanceof Advanceable) { |
| 1895 | postDelayed(new Runnable() { |
| 1896 | public void run() { |
| 1897 | ((Advanceable) v).advance(); |
| 1898 | } |
| 1899 | }, delay); |
| 1900 | } |
| 1901 | i++; |
| 1902 | } |
| 1903 | sendAdvanceMessage(mAdvanceInterval); |
| 1904 | } |
| 1905 | } |
| 1906 | }; |
| 1907 | |
| 1908 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1909 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1910 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1911 | if (v instanceof Advanceable) { |
| 1912 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1913 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1914 | updateRunning(); |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | void removeWidgetToAutoAdvance(View hostView) { |
| 1919 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1920 | mWidgetsToAdvance.remove(hostView); |
| 1921 | updateRunning(); |
| 1922 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1925 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1926 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1927 | launcherInfo.hostView = null; |
| 1928 | } |
| 1929 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1930 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1931 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1932 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1935 | public DragLayer getDragLayer() { |
| 1936 | return mDragLayer; |
| 1937 | } |
| 1938 | |
| 1939 | public Workspace getWorkspace() { |
| 1940 | return mWorkspace; |
| 1941 | } |
| 1942 | |
| 1943 | public Hotseat getHotseat() { |
| 1944 | return mHotseat; |
| 1945 | } |
| 1946 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1947 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1948 | return mOverviewPanel; |
| 1949 | } |
| 1950 | |
| 1951 | public SearchDropTargetBar getSearchBar() { |
| 1952 | return mSearchDropTargetBar; |
| 1953 | } |
| 1954 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1955 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1956 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1957 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1958 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1959 | public LauncherModel getModel() { |
| 1960 | return mModel; |
| 1961 | } |
| 1962 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1963 | protected SharedPreferences getSharedPrefs() { |
| 1964 | return mSharedPrefs; |
| 1965 | } |
| 1966 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1967 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1968 | getWindow().closeAllPanels(); |
| 1969 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1970 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1971 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1972 | } |
| 1973 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1974 | @Override |
| 1975 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1976 | long startTime = 0; |
| 1977 | if (DEBUG_RESUME_TIME) { |
| 1978 | startTime = System.currentTimeMillis(); |
| 1979 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1980 | super.onNewIntent(intent); |
| 1981 | |
| 1982 | // Close the menu |
| 1983 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1984 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1985 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1986 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1987 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1988 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1989 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1990 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1991 | if (mWorkspace == null) { |
| 1992 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1993 | return; |
| 1994 | } |
| 1995 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1996 | // In all these cases, only animate if we're already on home |
| 1997 | mWorkspace.exitWidgetResizeMode(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1998 | |
| 1999 | boolean moveToDefaultScreen = mLauncherCallbacks != null ? |
| 2000 | mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true; |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 2001 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2002 | openFolder == null && moveToDefaultScreen) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 2003 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 2004 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 2005 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 2006 | closeFolder(); |
| 2007 | exitSpringLoadedDragMode(); |
| 2008 | |
| 2009 | // If we are already on home, then just animate back to the workspace, |
| 2010 | // otherwise, just wait until onResume to set the state back to Workspace |
| 2011 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2012 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 2013 | } else { |
| 2014 | mOnResumeState = State.WORKSPACE; |
| 2015 | } |
| 2016 | |
| 2017 | final View v = getWindow().peekDecorView(); |
| 2018 | if (v != null && v.getWindowToken() != null) { |
| 2019 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 2020 | INPUT_METHOD_SERVICE); |
| 2021 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 2022 | } |
| 2023 | |
| 2024 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 2025 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 2026 | mAppsCustomizeTabHost.reset(); |
| 2027 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 2028 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2029 | if (mLauncherCallbacks != null) { |
| 2030 | mLauncherCallbacks.onHomeIntent(); |
| 2031 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2032 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2033 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 2034 | if (DEBUG_RESUME_TIME) { |
| 2035 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 2036 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2037 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2038 | if (mLauncherCallbacks != null) { |
| 2039 | mLauncherCallbacks.onNewIntent(intent); |
| 2040 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2043 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 2044 | public void onRestoreInstanceState(Bundle state) { |
| 2045 | super.onRestoreInstanceState(state); |
| 2046 | for (int page: mSynchronouslyBoundPages) { |
| 2047 | mWorkspace.restoreInstanceStateForChild(page); |
| 2048 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | @Override |
| 2052 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 2053 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 2054 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 2055 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 2056 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 2057 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2058 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 2059 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 2060 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 2061 | // this state is reflected. |
| 2062 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2063 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2064 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2065 | mWaitingForResult) { |
| 2066 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2067 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2068 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 2069 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2070 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 2071 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 2072 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2073 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | if (mFolderInfo != null && mWaitingForResult) { |
| 2077 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 2078 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 2079 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 2080 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2081 | // Save the current AppsCustomize tab |
| 2082 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c6 | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 2083 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 2084 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2085 | if (currentTabTag != null) { |
| 2086 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 2087 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 2088 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 2089 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2090 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 2091 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2092 | |
| 2093 | if (mLauncherCallbacks != null) { |
| 2094 | mLauncherCallbacks.onSaveInstanceState(outState); |
| 2095 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | @Override |
| 2099 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2100 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2101 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2102 | // Remove all pending runnables |
| 2103 | mHandler.removeMessages(ADVANCE_MSG); |
| 2104 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 2105 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2106 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2107 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 2108 | LauncherAppState app = (LauncherAppState.getInstance()); |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 2109 | |
| 2110 | // It's possible to receive onDestroy after a new Launcher activity has |
| 2111 | // been created. In this case, don't interfere with the new Launcher. |
| 2112 | if (mModel.isCurrentCallbacks(this)) { |
| 2113 | mModel.stopLoader(); |
| 2114 | app.setLauncher(null); |
| 2115 | } |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2116 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2117 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2118 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2119 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2120 | 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] | 2121 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2122 | mAppWidgetHost = null; |
| 2123 | |
| 2124 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2125 | |
| 2126 | TextKeyListener.getInstance().release(); |
| 2127 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 2128 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 2129 | // to prevent leaking Launcher activities on orientation change. |
| 2130 | if (mModel != null) { |
| 2131 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 2132 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2133 | |
| 2134 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2135 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2136 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 2137 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2138 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 2139 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2140 | mWorkspace = null; |
| 2141 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 2142 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2143 | LauncherAnimUtils.onDestroyActivity(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2144 | |
| 2145 | if (mLauncherCallbacks != null) { |
| 2146 | mLauncherCallbacks.onDestroy(); |
| 2147 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2150 | public DragController getDragController() { |
| 2151 | return mDragController; |
| 2152 | } |
| 2153 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2154 | @Override |
| 2155 | public void startActivityForResult(Intent intent, int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2156 | if (requestCode >= 0) { |
| 2157 | setWaitingForResult(true); |
| 2158 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2159 | super.startActivityForResult(intent, requestCode); |
| 2160 | } |
| 2161 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2162 | /** |
| 2163 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2164 | * argument for {@link #startSearch} to true. |
| 2165 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2166 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2167 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2168 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2169 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2170 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2171 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2172 | if (initialQuery == null) { |
| 2173 | // Use any text typed in the launcher as the initial query |
| 2174 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2175 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2176 | if (appSearchData == null) { |
| 2177 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2178 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2179 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2180 | Rect sourceBounds = new Rect(); |
| 2181 | if (mSearchDropTargetBar != null) { |
| 2182 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2183 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2184 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2185 | boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2186 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2187 | if (clearTextImmediately) { |
| 2188 | clearTypedText(); |
| 2189 | } |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2190 | } |
| 2191 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2192 | /** |
| 2193 | * Start a text search. |
| 2194 | * |
| 2195 | * @return {@code true} if the search will start immediately, so any further keypresses |
| 2196 | * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue |
| 2197 | * to buffer keypresses. |
| 2198 | */ |
| 2199 | public boolean startSearch(String initialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2200 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2201 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 2202 | return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData, |
| 2203 | sourceBounds); |
| 2204 | } |
| 2205 | |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2206 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2207 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2208 | return false; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | /** |
| 2212 | * Starts the global search activity. This code is a copied from SearchManager |
| 2213 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2214 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2215 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2216 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2217 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2218 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2219 | if (globalSearchActivity == null) { |
| 2220 | Log.w(TAG, "No global search activity found."); |
| 2221 | return; |
| 2222 | } |
| 2223 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2224 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2225 | intent.setComponent(globalSearchActivity); |
| 2226 | // Make sure that we have a Bundle to put source in |
| 2227 | if (appSearchData == null) { |
| 2228 | appSearchData = new Bundle(); |
| 2229 | } else { |
| 2230 | appSearchData = new Bundle(appSearchData); |
| 2231 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2232 | // 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] | 2233 | if (!appSearchData.containsKey("source")) { |
| 2234 | appSearchData.putString("source", getPackageName()); |
| 2235 | } |
| 2236 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2237 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2238 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2239 | } |
| 2240 | if (selectInitialQuery) { |
| 2241 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2242 | } |
| 2243 | intent.setSourceBounds(sourceBounds); |
| 2244 | try { |
| 2245 | startActivity(intent); |
| 2246 | } catch (ActivityNotFoundException ex) { |
| 2247 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2248 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2249 | } |
| 2250 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2251 | public boolean isOnCustomContent() { |
| 2252 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2253 | } |
| 2254 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2255 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2256 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2257 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2258 | if (!isOnCustomContent()) { |
| 2259 | // Close any open folders |
| 2260 | closeFolder(); |
| 2261 | // Stop resizing any widgets |
| 2262 | mWorkspace.exitWidgetResizeMode(); |
| 2263 | if (!mWorkspace.isInOverviewMode()) { |
| 2264 | // Show the overview mode |
| 2265 | showOverviewMode(true); |
| 2266 | } else { |
| 2267 | showWorkspace(true); |
| 2268 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2269 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2270 | if (mLauncherCallbacks != null) { |
| 2271 | return mLauncherCallbacks.onPrepareOptionsMenu(menu); |
| 2272 | } |
| 2273 | |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2274 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2275 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2276 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2277 | @Override |
| 2278 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2279 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2280 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2281 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2284 | public boolean isWorkspaceLocked() { |
| 2285 | return mWorkspaceLoading || mWaitingForResult; |
| 2286 | } |
| 2287 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2288 | public boolean isWorkspaceLoading() { |
| 2289 | return mWorkspaceLoading; |
| 2290 | } |
| 2291 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2292 | private void setWorkspaceLoading(boolean value) { |
| 2293 | boolean isLocked = isWorkspaceLocked(); |
| 2294 | mWorkspaceLoading = value; |
| 2295 | if (isLocked != isWorkspaceLocked()) { |
| 2296 | onWorkspaceLockedChanged(); |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | private void setWaitingForResult(boolean value) { |
| 2301 | boolean isLocked = isWorkspaceLocked(); |
| 2302 | mWaitingForResult = value; |
| 2303 | if (isLocked != isWorkspaceLocked()) { |
| 2304 | onWorkspaceLockedChanged(); |
| 2305 | } |
| 2306 | } |
| 2307 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2308 | protected void onWorkspaceLockedChanged() { |
| 2309 | if (mLauncherCallbacks != null) { |
| 2310 | mLauncherCallbacks.onWorkspaceLockedChanged(); |
| 2311 | } |
| 2312 | } |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2313 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2314 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2315 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2316 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2317 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2318 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2319 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2320 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2321 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2322 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2323 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2324 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) { |
| 2325 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2326 | } |
| 2327 | |
| 2328 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2329 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int |
| 2330 | delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2331 | if (appWidgetInfo.configure != null) { |
| 2332 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2333 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2334 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2335 | // Launch over to configure widget, if needed |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2336 | mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this, |
| 2337 | mAppWidgetHost, REQUEST_CREATE_APPWIDGET); |
| 2338 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2339 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2340 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2341 | Runnable onComplete = new Runnable() { |
| 2342 | @Override |
| 2343 | public void run() { |
| 2344 | // Exit spring loaded mode if necessary after adding the widget |
| 2345 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2346 | null); |
| 2347 | } |
| 2348 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2349 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2350 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2351 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2352 | } |
| 2353 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2354 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2355 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2356 | // Close any folders that may be open. |
| 2357 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2358 | mWorkspace.moveToCustomContentScreen(animate); |
| 2359 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2360 | /** |
| 2361 | * Process a shortcut drop. |
| 2362 | * |
| 2363 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2364 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2365 | * @param cell The cell it should be added to, optional |
| 2366 | * @param position The location on the screen where it was dropped, optional |
| 2367 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2368 | void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2369 | int[] cell, int[] loc) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2370 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2371 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2372 | mPendingAddInfo.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2373 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2374 | |
| 2375 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2376 | mPendingAddInfo.cellX = cell[0]; |
| 2377 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2378 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2379 | |
| 2380 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2381 | createShortcutIntent.setComponent(componentName); |
| 2382 | processShortcut(createShortcutIntent); |
| 2383 | } |
| 2384 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2385 | /** |
| 2386 | * Process a widget drop. |
| 2387 | * |
| 2388 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2389 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2390 | * @param cell The cell it should be added to, optional |
| 2391 | * @param position The location on the screen where it was dropped, optional |
| 2392 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2393 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2394 | int[] cell, int[] span, int[] loc) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2395 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2396 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2397 | mPendingAddInfo.screenId = info.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2398 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2399 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2400 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2401 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2402 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2403 | mPendingAddInfo.cellX = cell[0]; |
| 2404 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2405 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2406 | if (span != null) { |
| 2407 | mPendingAddInfo.spanX = span[0]; |
| 2408 | mPendingAddInfo.spanY = span[1]; |
| 2409 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2410 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2411 | AppWidgetHostView hostView = info.boundWidget; |
| 2412 | int appWidgetId; |
| 2413 | if (hostView != null) { |
| 2414 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2415 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2416 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2417 | // In this case, we either need to start an activity to get permission to bind |
| 2418 | // 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] | 2419 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2420 | Bundle options = info.bindOptions; |
| 2421 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2422 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2423 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2424 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2425 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2426 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2427 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2428 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2429 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2430 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2431 | mAppWidgetManager.getUser(mPendingAddWidgetInfo) |
| 2432 | .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2433 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2434 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2435 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2436 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2437 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2440 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2441 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2442 | } |
| 2443 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2444 | void processWallpaper(Intent intent) { |
| 2445 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2446 | } |
| 2447 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2448 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2449 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2450 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2451 | folderInfo.title = getText(R.string.folder_name); |
| 2452 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2453 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2454 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2455 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2456 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2457 | |
| 2458 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2459 | FolderIcon newFolder = |
| 2460 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2461 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2462 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2463 | // Force measure the new folder icon |
| 2464 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2465 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2466 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2467 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2468 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2469 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2470 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2471 | } |
| 2472 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2473 | protected ComponentName getWallpaperPickerComponent() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2474 | if (mLauncherCallbacks != null) { |
| 2475 | return mLauncherCallbacks.getWallpaperPickerComponent(); |
| 2476 | } |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2477 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2478 | } |
| 2479 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2480 | /** |
| 2481 | * Registers various content observers. The current implementation registers |
| 2482 | * only a favorites observer to keep track of the favorites applications. |
| 2483 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2484 | private void registerContentObservers() { |
| 2485 | ContentResolver resolver = getContentResolver(); |
| 2486 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2487 | true, mWidgetObserver); |
| 2488 | } |
| 2489 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2490 | @Override |
| 2491 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2492 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2493 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2494 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2495 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2496 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 2497 | if (isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2498 | dumpState(); |
| 2499 | return true; |
| 2500 | } |
| 2501 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2502 | } |
| 2503 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2504 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2505 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2506 | return true; |
| 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | return super.dispatchKeyEvent(event); |
| 2511 | } |
| 2512 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2513 | @Override |
| 2514 | public void onBackPressed() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2515 | if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) { |
| 2516 | return; |
| 2517 | } |
| 2518 | |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2519 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2520 | if (mAppsCustomizeContent.getContentType() == |
| 2521 | AppsCustomizePagedView.ContentType.Applications) { |
| 2522 | showWorkspace(true); |
| 2523 | } else { |
| 2524 | showOverviewMode(true); |
| 2525 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2526 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2527 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2528 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2529 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2530 | if (openFolder.isEditingName()) { |
| 2531 | openFolder.dismissEditingName(); |
| 2532 | } else { |
| 2533 | closeFolder(); |
| 2534 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2535 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2536 | mWorkspace.exitWidgetResizeMode(); |
| 2537 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2538 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2539 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2540 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2541 | } |
| 2542 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2543 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2544 | * Re-listen when widgets are reset. |
| 2545 | */ |
| 2546 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2547 | if (mAppWidgetHost != null) { |
| 2548 | mAppWidgetHost.startListening(); |
| 2549 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2553 | * Launches the intent referred by the clicked shortcut. |
| 2554 | * |
| 2555 | * @param v The view representing the clicked shortcut. |
| 2556 | */ |
| 2557 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2558 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2559 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2560 | if (v.getWindowToken() == null) { |
| 2561 | return; |
| 2562 | } |
| 2563 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2564 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2565 | return; |
| 2566 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2567 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2568 | if (v instanceof Workspace) { |
| 2569 | if (mWorkspace.isInOverviewMode()) { |
| 2570 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2571 | } |
| 2572 | return; |
| 2573 | } |
| 2574 | |
| 2575 | if (v instanceof CellLayout) { |
| 2576 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2577 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2581 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2582 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2583 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2584 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2585 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2586 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2587 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2588 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2589 | onClickAllAppsButton(v); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2590 | } else if (tag instanceof AppInfo) { |
| 2591 | startAppShortcutOrInfoActivity(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2592 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2593 | if (v instanceof PendingAppWidgetHostView) { |
| 2594 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2595 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2599 | public void onClickPagedViewIcon(View v) { |
| 2600 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2601 | if (mLauncherCallbacks != null) { |
| 2602 | mLauncherCallbacks.onClickPagedViewIcon(v); |
| 2603 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2606 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2607 | return false; |
| 2608 | } |
| 2609 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2610 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2611 | * Event handler for the app widget view which has not fully restored. |
| 2612 | */ |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2613 | public void onClickPendingWidget(final PendingAppWidgetHostView v) { |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2614 | if (mIsSafeModeEnabled) { |
| 2615 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2616 | return; |
| 2617 | } |
| 2618 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2619 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2620 | if (v.isReadyForClickSetup()) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2621 | int widgetId = info.appWidgetId; |
| 2622 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
| 2623 | if (appWidgetInfo != null) { |
| 2624 | mPendingAddWidgetInfo = appWidgetInfo; |
| 2625 | mPendingAddInfo.copyFrom(info); |
| 2626 | mPendingAddWidgetId = widgetId; |
| 2627 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2628 | AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo, |
| 2629 | info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2630 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2631 | } else if (info.installProgress < 0) { |
| 2632 | // The install has not been queued |
| 2633 | final String packageName = info.providerName.getPackageName(); |
| 2634 | showBrokenAppInstallDialog(packageName, |
| 2635 | new DialogInterface.OnClickListener() { |
| 2636 | public void onClick(DialogInterface dialog, int id) { |
| 2637 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
| 2638 | } |
| 2639 | }); |
| 2640 | } else { |
| 2641 | // Download has started. |
| 2642 | final String packageName = info.providerName.getPackageName(); |
| 2643 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2648 | * Event handler for the search button |
| 2649 | * |
| 2650 | * @param v The view that was clicked. |
| 2651 | */ |
| 2652 | public void onClickSearchButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2653 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2654 | |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2655 | onSearchRequested(); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2659 | * Event handler for the voice button |
| 2660 | * |
| 2661 | * @param v The view that was clicked. |
| 2662 | */ |
| 2663 | public void onClickVoiceButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2664 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2665 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2666 | startVoice(); |
| 2667 | } |
| 2668 | |
| 2669 | public void startVoice() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2670 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 2671 | mLauncherCallbacks.startVoice(); |
| 2672 | return; |
| 2673 | } |
| 2674 | |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2675 | try { |
| 2676 | final SearchManager searchManager = |
| 2677 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2678 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 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 | if (activityName != null) { |
| 2682 | intent.setPackage(activityName.getPackageName()); |
| 2683 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2684 | startActivity(null, intent, "onClickVoiceButton"); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2685 | } catch (ActivityNotFoundException e) { |
| 2686 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2687 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2688 | startActivitySafely(null, intent, "onClickVoiceButton"); |
| 2689 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2693 | * Event handler for the "grid" button that appears on the home screen, which |
| 2694 | * enters all apps mode. |
| 2695 | * |
| 2696 | * @param v The view that was clicked. |
| 2697 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2698 | protected void onClickAllAppsButton(View v) { |
| 2699 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2700 | if (isAllAppsVisible()) { |
| 2701 | showWorkspace(true); |
| 2702 | } else { |
| 2703 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2704 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2705 | if (mLauncherCallbacks != null) { |
| 2706 | mLauncherCallbacks.onClickAllAppsButton(v); |
| 2707 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2708 | } |
| 2709 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2710 | private void showBrokenAppInstallDialog(final String packageName, |
| 2711 | DialogInterface.OnClickListener onSearchClickListener) { |
Sunny Goyal | e03b812 | 2014-10-08 09:55:24 -0700 | [diff] [blame] | 2712 | new AlertDialog.Builder(this) |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2713 | .setTitle(R.string.abandoned_promises_title) |
| 2714 | .setMessage(R.string.abandoned_promise_explanation) |
| 2715 | .setPositiveButton(R.string.abandoned_search, onSearchClickListener) |
| 2716 | .setNeutralButton(R.string.abandoned_clean_this, |
| 2717 | new DialogInterface.OnClickListener() { |
| 2718 | public void onClick(DialogInterface dialog, int id) { |
| 2719 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 2720 | mWorkspace.removeAbandonedPromise(packageName, user); |
| 2721 | } |
| 2722 | }) |
| 2723 | .create().show(); |
| 2724 | return; |
| 2725 | } |
| 2726 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2727 | /** |
| 2728 | * Event handler for an app shortcut click. |
| 2729 | * |
| 2730 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2731 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2732 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2733 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2734 | Object tag = v.getTag(); |
| 2735 | if (!(tag instanceof ShortcutInfo)) { |
| 2736 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2737 | } |
| 2738 | |
| 2739 | // Open shortcut |
| 2740 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2741 | |
| 2742 | if (shortcut.isDisabled != 0) { |
| 2743 | int error = R.string.activity_not_available; |
| 2744 | if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) { |
| 2745 | error = R.string.safemode_shortcut_error; |
| 2746 | } |
| 2747 | Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); |
| 2748 | return; |
| 2749 | } |
| 2750 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2751 | final Intent intent = shortcut.intent; |
| 2752 | |
| 2753 | // Check for special shortcuts |
| 2754 | if (intent.getComponent() != null) { |
| 2755 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2756 | |
| 2757 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2758 | MemoryDumpActivity.startDump(this); |
| 2759 | return; |
| 2760 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2761 | toggleShowWeightWatcher(); |
| 2762 | return; |
| 2763 | } |
| 2764 | } |
| 2765 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2766 | // Check for abandoned promise |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2767 | if ((v instanceof BubbleTextView) |
| 2768 | && shortcut.isPromise() |
| 2769 | && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2770 | showBrokenAppInstallDialog( |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2771 | shortcut.getTargetComponent().getPackageName(), |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2772 | new DialogInterface.OnClickListener() { |
| 2773 | public void onClick(DialogInterface dialog, int id) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2774 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2775 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2776 | }); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2777 | return; |
| 2778 | } |
| 2779 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2780 | // Start activities |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2781 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2782 | |
| 2783 | if (mLauncherCallbacks != null) { |
| 2784 | mLauncherCallbacks.onClickAppShortcut(v); |
| 2785 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2786 | } |
| 2787 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2788 | private void startAppShortcutOrInfoActivity(View v) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2789 | Object tag = v.getTag(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2790 | final ShortcutInfo shortcut; |
| 2791 | final Intent intent; |
| 2792 | if (tag instanceof ShortcutInfo) { |
| 2793 | shortcut = (ShortcutInfo) tag; |
| 2794 | intent = shortcut.intent; |
| 2795 | int[] pos = new int[2]; |
| 2796 | v.getLocationOnScreen(pos); |
| 2797 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2798 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2799 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2800 | } else if (tag instanceof AppInfo) { |
| 2801 | shortcut = null; |
| 2802 | intent = ((AppInfo) tag).intent; |
| 2803 | } else { |
| 2804 | throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); |
| 2805 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2806 | |
| 2807 | boolean success = startActivitySafely(v, intent, tag); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2808 | mStats.recordLaunch(intent, shortcut); |
| 2809 | |
| 2810 | if (success && v instanceof BubbleTextView) { |
| 2811 | mWaitingForResume = (BubbleTextView) v; |
| 2812 | mWaitingForResume.setStayPressed(true); |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | /** |
| 2817 | * Event handler for a folder icon click. |
| 2818 | * |
| 2819 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2820 | */ |
| 2821 | protected void onClickFolderIcon(View v) { |
| 2822 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2823 | if (!(v instanceof FolderIcon)){ |
| 2824 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2825 | } |
| 2826 | |
| 2827 | FolderIcon folderIcon = (FolderIcon) v; |
| 2828 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2829 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2830 | |
| 2831 | // If the folder info reports that the associated folder is open, then verify that |
| 2832 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2833 | if (info.opened && openFolder == null) { |
| 2834 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2835 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2836 | info.opened = false; |
| 2837 | } |
| 2838 | |
| 2839 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2840 | // Close any open folder |
| 2841 | closeFolder(); |
| 2842 | // Open the requested folder |
| 2843 | openFolder(folderIcon); |
| 2844 | } else { |
| 2845 | // Find the open folder... |
| 2846 | int folderScreen; |
| 2847 | if (openFolder != null) { |
| 2848 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2849 | // .. and close it |
| 2850 | closeFolder(openFolder); |
| 2851 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2852 | // Close any folder open on the current screen |
| 2853 | closeFolder(); |
| 2854 | // Pull the folder onto this screen |
| 2855 | openFolder(folderIcon); |
| 2856 | } |
| 2857 | } |
| 2858 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2859 | |
| 2860 | if (mLauncherCallbacks != null) { |
| 2861 | mLauncherCallbacks.onClickFolderIcon(v); |
| 2862 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2865 | /** |
| 2866 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2867 | * on the home screen. |
| 2868 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2869 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2870 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2871 | if (mIsSafeModeEnabled) { |
| 2872 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2873 | } else { |
| 2874 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2875 | if (mLauncherCallbacks != null) { |
| 2876 | mLauncherCallbacks.onClickAddWidgetButton(view); |
| 2877 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2878 | } |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2879 | } |
| 2880 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2881 | /** |
| 2882 | * Event handler for the wallpaper picker button that appears after a long press |
| 2883 | * on the home screen. |
| 2884 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2885 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2886 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2887 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2888 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2889 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2890 | |
| 2891 | if (mLauncherCallbacks != null) { |
| 2892 | mLauncherCallbacks.onClickWallpaperPicker(v); |
| 2893 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | /** |
| 2897 | * Event handler for a click on the settings button that appears after a long press |
| 2898 | * on the home screen. |
| 2899 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2900 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2901 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2902 | if (mLauncherCallbacks != null) { |
| 2903 | mLauncherCallbacks.onClickSettingsButton(v); |
| 2904 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2905 | } |
| 2906 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2907 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2908 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2909 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2912 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2913 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2914 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2915 | } |
| 2916 | |
| 2917 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2918 | if (mHapticFeedbackTouchListener == null) { |
| 2919 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2920 | @Override |
| 2921 | public boolean onTouch(View v, MotionEvent event) { |
| 2922 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2923 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2924 | } |
| 2925 | return false; |
| 2926 | } |
| 2927 | }; |
| 2928 | } |
| 2929 | return mHapticFeedbackTouchListener; |
| 2930 | } |
| 2931 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2932 | public void onDragStarted(View view) { |
| 2933 | if (isOnCustomContent()) { |
| 2934 | // Custom content screen doesn't participate in drag and drop. If on custom |
| 2935 | // content screen, move to default. |
| 2936 | moveWorkspaceToDefaultScreen(); |
| 2937 | } |
| 2938 | |
| 2939 | if (mLauncherCallbacks != null) { |
| 2940 | mLauncherCallbacks.onDragStarted(view); |
| 2941 | } |
| 2942 | } |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2943 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2944 | /** |
| 2945 | * Called when the user stops interacting with the launcher. |
| 2946 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2947 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2948 | protected void onInteractionEnd() { |
| 2949 | if (mLauncherCallbacks != null) { |
| 2950 | mLauncherCallbacks.onInteractionEnd(); |
| 2951 | } |
| 2952 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2953 | |
| 2954 | /** |
| 2955 | * Called when the user starts interacting with the launcher. |
| 2956 | * The possible interactions are: |
| 2957 | * - open all apps |
| 2958 | * - reorder an app shortcut, or a widget |
| 2959 | * - open the overview mode. |
| 2960 | * This is a good time to stop doing things that only make sense |
| 2961 | * when the user is on the homescreen and not doing housekeeping. |
| 2962 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2963 | protected void onInteractionBegin() { |
| 2964 | if (mLauncherCallbacks != null) { |
| 2965 | mLauncherCallbacks.onInteractionBegin(); |
| 2966 | } |
| 2967 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2968 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2969 | void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2970 | String packageName = componentName.getPackageName(); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2971 | try { |
| 2972 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2973 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
| 2974 | launcherApps.showAppDetailsForProfile(componentName, user); |
| 2975 | } catch (SecurityException e) { |
| 2976 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2977 | Log.e(TAG, "Launcher does not have permission to launch settings"); |
| 2978 | } catch (ActivityNotFoundException e) { |
| 2979 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2980 | Log.e(TAG, "Unable to launch settings"); |
| 2981 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2984 | // returns true if the activity was started |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2985 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags, |
| 2986 | UserHandleCompat user) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2987 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2988 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2989 | // We may give them the option of disabling apps this way. |
| 2990 | int messageId = R.string.uninstall_system_app_text; |
| 2991 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2992 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2993 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2994 | String packageName = componentName.getPackageName(); |
| 2995 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2996 | Intent intent = new Intent( |
| 2997 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2998 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2999 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 3000 | if (user != null) { |
| 3001 | user.addToIntent(intent, Intent.EXTRA_USER); |
| 3002 | } |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 3003 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3004 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 3005 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 3008 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 3009 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3010 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 3011 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 3012 | // private contract between launcher and may be ignored in the future). |
| 3013 | boolean useLaunchAnimation = (v != null) && |
| 3014 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3015 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 3016 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 3017 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 3018 | UserHandleCompat user = null; |
| 3019 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 3020 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 3021 | user = userManager.getUserForSerialNumber(serialNumber); |
| 3022 | } |
| 3023 | |
| 3024 | Bundle optsBundle = null; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 3025 | if (useLaunchAnimation) { |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3026 | ActivityOptions opts = Utilities.isLmpOrAbove() ? |
Adam Cohen | 4da294d | 2014-07-28 10:56:19 -0700 | [diff] [blame] | 3027 | ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) : |
| 3028 | ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 3029 | optsBundle = opts.toBundle(); |
| 3030 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 3031 | |
| 3032 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 3033 | // Could be launching some bookkeeping activity |
| 3034 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 3035 | } else { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 3036 | // TODO Component can be null when shortcuts are supported for secondary user |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 3037 | launcherApps.startActivityForProfile(intent.getComponent(), user, |
| 3038 | intent.getSourceBounds(), optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 3039 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 3040 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3041 | } catch (SecurityException e) { |
| 3042 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 3043 | 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] | 3044 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 3045 | "or use the exported attribute for this activity. " |
| 3046 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3047 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 3048 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3049 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3050 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 3051 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 3052 | boolean success = false; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 3053 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 3054 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 3055 | return false; |
| 3056 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 3057 | try { |
| 3058 | success = startActivity(v, intent, tag); |
| 3059 | } catch (ActivityNotFoundException e) { |
| 3060 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 3061 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 3062 | } |
| 3063 | return success; |
| 3064 | } |
| 3065 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3066 | /** |
| 3067 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 3068 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 3069 | */ |
| 3070 | private void copyFolderIconToImage(FolderIcon fi) { |
| 3071 | final int width = fi.getMeasuredWidth(); |
| 3072 | final int height = fi.getMeasuredHeight(); |
| 3073 | |
| 3074 | // Lazy load ImageView, Bitmap and Canvas |
| 3075 | if (mFolderIconImageView == null) { |
| 3076 | mFolderIconImageView = new ImageView(this); |
| 3077 | } |
| 3078 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 3079 | mFolderIconBitmap.getHeight() != height) { |
| 3080 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 3081 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 3082 | } |
| 3083 | |
| 3084 | DragLayer.LayoutParams lp; |
| 3085 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 3086 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 3087 | } else { |
| 3088 | lp = new DragLayer.LayoutParams(width, height); |
| 3089 | } |
| 3090 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 3091 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 3092 | // view size by this scale factor. |
| 3093 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3094 | lp.customPosition = true; |
| 3095 | lp.x = mRectForFolderAnimation.left; |
| 3096 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 3097 | lp.width = (int) (scale * width); |
| 3098 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3099 | |
| 3100 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 3101 | fi.draw(mFolderIconCanvas); |
| 3102 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3103 | if (fi.getFolder() != null) { |
| 3104 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 3105 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3106 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3107 | // Just in case this image view is still in the drag layer from a previous animation, |
| 3108 | // we remove it and re-add it. |
| 3109 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 3110 | mDragLayer.removeView(mFolderIconImageView); |
| 3111 | } |
| 3112 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3113 | if (fi.getFolder() != null) { |
| 3114 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3115 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3116 | } |
| 3117 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3118 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3119 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3120 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 3121 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 3122 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 3123 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3124 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 3125 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3126 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 3127 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 3128 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3131 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 3132 | copyFolderIconToImage(fi); |
| 3133 | fi.setVisibility(View.INVISIBLE); |
| 3134 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3135 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3136 | scaleX, scaleY); |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3137 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3138 | oa.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3139 | } |
| 3140 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3141 | oa.start(); |
| 3142 | } |
| 3143 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3144 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3145 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3146 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 3147 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 3148 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 3149 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3150 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3151 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3152 | // We remove and re-draw the FolderIcon in-case it has changed |
| 3153 | mDragLayer.removeView(mFolderIconImageView); |
| 3154 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3155 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3156 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3157 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3158 | oa.addListener(new AnimatorListenerAdapter() { |
| 3159 | @Override |
| 3160 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3161 | if (cl != null) { |
| 3162 | cl.clearFolderLeaveBehind(); |
| 3163 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 3164 | mDragLayer.removeView(mFolderIconImageView); |
| 3165 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3166 | } |
| 3167 | } |
| 3168 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3169 | oa.start(); |
| 3170 | } |
| 3171 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3172 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 3173 | * 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] | 3174 | * is animated relative to the specified View. If the View is null, no animation |
| 3175 | * is played. |
| 3176 | * |
| 3177 | * @param folderInfo The FolderInfo describing the folder to open. |
| 3178 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3179 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3180 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3181 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3182 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3183 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3184 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3185 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 3186 | // There was a one-off crash where the folder had a parent already. |
| 3187 | if (folder.getParent() == null) { |
| 3188 | mDragLayer.addView(folder); |
| 3189 | mDragController.addDropTarget((DropTarget) folder); |
| 3190 | } else { |
| 3191 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 3192 | folder.getParent() + ")."); |
| 3193 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3194 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3195 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3196 | |
| 3197 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 3198 | // the workspace items |
| 3199 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 3200 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 3204 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3205 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 3206 | if (folder.isEditingName()) { |
| 3207 | folder.dismissEditingName(); |
| 3208 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3209 | closeFolder(folder); |
| 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | void closeFolder(Folder folder) { |
| 3214 | folder.getInfo().opened = false; |
| 3215 | |
| 3216 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 3217 | if (parent != null) { |
| 3218 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 3219 | shrinkAndFadeInFolderIcon(fi); |
| 3220 | } |
| 3221 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3222 | |
| 3223 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 3224 | // longer occludeds the workspace items |
| 3225 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3226 | } |
| 3227 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3228 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 3229 | if (!isDraggingEnabled()) return false; |
| 3230 | if (isWorkspaceLocked()) return false; |
| 3231 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3232 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3233 | if (v instanceof Workspace) { |
| 3234 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 3235 | if (mWorkspace.enterOverviewMode()) { |
| 3236 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3237 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 3238 | return true; |
| 3239 | } else { |
| 3240 | return false; |
| 3241 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 3242 | } else { |
| 3243 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3244 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 3247 | CellLayout.CellInfo longClickCellInfo = null; |
| 3248 | View itemUnderLongClick = null; |
| 3249 | if (v.getTag() instanceof ItemInfo) { |
| 3250 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3251 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 3252 | itemUnderLongClick = longClickCellInfo.cell; |
| 3253 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3254 | } |
| 3255 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3256 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 3257 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3258 | final boolean inHotseat = isHotseatLayout(v); |
| 3259 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3260 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3261 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3262 | // User long pressed on empty space |
| 3263 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3264 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3265 | if (mWorkspace.isInOverviewMode()) { |
| 3266 | mWorkspace.startReordering(v); |
| 3267 | } else { |
| 3268 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 3269 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3270 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3271 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 3272 | mHotseat.getOrderInHotseat( |
| 3273 | longClickCellInfo.cellX, |
| 3274 | longClickCellInfo.cellY)); |
| 3275 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3276 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3277 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3278 | } |
| 3279 | } |
| 3280 | } |
| 3281 | return true; |
| 3282 | } |
| 3283 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3284 | boolean isHotseatLayout(View layout) { |
| 3285 | return mHotseat != null && layout != null && |
| 3286 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 3287 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 3288 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3289 | /** |
| 3290 | * Returns the CellLayout of the specified container at the specified screen. |
| 3291 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3292 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3293 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3294 | if (mHotseat != null) { |
| 3295 | return mHotseat.getLayout(); |
| 3296 | } else { |
| 3297 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 3298 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3299 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3300 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 3301 | } |
| 3302 | } |
| 3303 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3304 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3305 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 3306 | } |
| 3307 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3308 | private void setWorkspaceBackground(boolean workspace) { |
| 3309 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 3310 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 3313 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3314 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 3315 | int curflags = getWindow().getAttributes().flags |
| 3316 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 3317 | if (wpflags != curflags) { |
| 3318 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 3319 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3320 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3323 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3324 | if (v instanceof LauncherTransitionable) { |
| 3325 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3326 | } |
| 3327 | } |
| 3328 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3329 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3330 | if (v instanceof LauncherTransitionable) { |
| 3331 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3332 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3333 | |
| 3334 | // Update the workspace transition step as well |
| 3335 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3336 | } |
| 3337 | |
| 3338 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3339 | if (v instanceof LauncherTransitionable) { |
| 3340 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3341 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3345 | if (v instanceof LauncherTransitionable) { |
| 3346 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3347 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3348 | |
| 3349 | // Update the workspace transition step as well |
| 3350 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3351 | } |
| 3352 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3353 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3354 | * Things to test when changing the following seven functions. |
| 3355 | * - Home from workspace |
| 3356 | * - from center screen |
| 3357 | * - from other screens |
| 3358 | * - Home from all apps |
| 3359 | * - from center screen |
| 3360 | * - from other screens |
| 3361 | * - Back from all apps |
| 3362 | * - from center screen |
| 3363 | * - from other screens |
| 3364 | * - Launch app from workspace and quit |
| 3365 | * - with back |
| 3366 | * - with home |
| 3367 | * - Launch app from all apps and quit |
| 3368 | * - with back |
| 3369 | * - with home |
| 3370 | * - Go to a screen that's not the default, then all |
| 3371 | * apps, and launch and app, and go back |
| 3372 | * - with back |
| 3373 | * -with home |
| 3374 | * - On workspace, long press power and go back |
| 3375 | * - with back |
| 3376 | * - with home |
| 3377 | * - On all apps, long press power and go back |
| 3378 | * - with back |
| 3379 | * - with home |
| 3380 | * - On workspace, power off |
| 3381 | * - On all apps, power off |
| 3382 | * - Launch an app and turn off the screen while in that app |
| 3383 | * - Go back with home key |
| 3384 | * - Go back with back key TODO: make this not go to workspace |
| 3385 | * - From all apps |
| 3386 | * - From workspace |
| 3387 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3388 | * - From all apps |
| 3389 | * - From the center workspace |
| 3390 | * - From another workspace |
| 3391 | */ |
| 3392 | |
| 3393 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3394 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3395 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3396 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3397 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3398 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3399 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3400 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3401 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3402 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3403 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3404 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3405 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3406 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3407 | mStateAnimation.cancel(); |
| 3408 | mStateAnimation = null; |
| 3409 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3410 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3411 | boolean material = Utilities.isLmpOrAbove(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3412 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3413 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3414 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3415 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); |
| 3416 | final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3417 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3418 | final int itemsAlphaStagger = |
| 3419 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3420 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3421 | final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3422 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3423 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3424 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3425 | final ArrayList<View> layerViews = new ArrayList<View>(); |
| 3426 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3427 | Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? |
| 3428 | Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3429 | Animator workspaceAnim = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3430 | mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3431 | if (!LauncherAppState.isDisableAllApps() |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3432 | || contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3433 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3434 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3435 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3436 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3437 | // If for some reason our views aren't initialized, don't animate |
| 3438 | boolean initialized = getAllAppsButton() != null; |
| 3439 | |
| 3440 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3441 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3442 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3443 | toView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3444 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3445 | final View page = content.getPageAt(content.getCurrentPage()); |
| 3446 | final View revealView = toView.findViewById(R.id.fake_page); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3447 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3448 | final float initialPanelAlpha = 1f; |
| 3449 | |
| 3450 | final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; |
| 3451 | if (isWidgetTray) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3452 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3453 | } else { |
| 3454 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3455 | } |
| 3456 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3457 | // Hide the real page background, and swap in the fake one |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3458 | content.setPageBackgroundsVisible(false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3459 | revealView.setVisibility(View.VISIBLE); |
| 3460 | // We need to hide this view as the animation start will be posted. |
| 3461 | revealView.setAlpha(0); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3462 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3463 | int width = revealView.getMeasuredWidth(); |
| 3464 | int height = revealView.getMeasuredHeight(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3465 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3466 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3467 | revealView.setTranslationY(0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3468 | revealView.setTranslationX(0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3469 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3470 | // Get the y delta between the center of the page and the center of the all apps button |
| 3471 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3472 | getAllAppsButton(), null); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3473 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3474 | float alpha = 0; |
| 3475 | float xDrift = 0; |
| 3476 | float yDrift = 0; |
| 3477 | if (material) { |
| 3478 | alpha = isWidgetTray ? 0.3f : 1f; |
| 3479 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3480 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3481 | } else { |
| 3482 | yDrift = 2 * height / 3; |
| 3483 | xDrift = 0; |
| 3484 | } |
| 3485 | final float initAlpha = alpha; |
| 3486 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3487 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3488 | layerViews.add(revealView); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3489 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3490 | PropertyValuesHolder panelDriftY = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3491 | PropertyValuesHolder.ofFloat("translationY", yDrift, 0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3492 | PropertyValuesHolder panelDriftX = |
| 3493 | PropertyValuesHolder.ofFloat("translationX", xDrift, 0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3494 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3495 | ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, |
| 3496 | panelAlpha, panelDriftY, panelDriftX); |
| 3497 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3498 | panelAlphaAndDrift.setDuration(revealDuration); |
| 3499 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3500 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3501 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3502 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3503 | if (page != null) { |
| 3504 | page.setVisibility(View.VISIBLE); |
| 3505 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3506 | layerViews.add(page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3507 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3508 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0); |
| 3509 | page.setTranslationY(yDrift); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3510 | pageDrift.setDuration(revealDuration); |
| 3511 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3512 | pageDrift.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3513 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3514 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3515 | page.setAlpha(0f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3516 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3517 | itemsAlpha.setDuration(revealDuration); |
| 3518 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 3519 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
| 3520 | mStateAnimation.play(itemsAlpha); |
| 3521 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3522 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3523 | View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); |
| 3524 | pageIndicators.setAlpha(0.01f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3525 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3526 | ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3527 | indicatorsAlpha.setDuration(revealDuration); |
| 3528 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3529 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3530 | if (material) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3531 | final View allApps = getAllAppsButton(); |
| 3532 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3533 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3534 | float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3535 | Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3536 | height / 2, startRadius, revealRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3537 | reveal.setDuration(revealDuration); |
| 3538 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3539 | |
| 3540 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3541 | public void onAnimationStart(Animator animation) { |
| 3542 | if (!isWidgetTray) { |
| 3543 | allApps.setVisibility(View.INVISIBLE); |
| 3544 | } |
| 3545 | } |
| 3546 | public void onAnimationEnd(Animator animation) { |
| 3547 | if (!isWidgetTray) { |
| 3548 | allApps.setVisibility(View.VISIBLE); |
| 3549 | } |
| 3550 | } |
| 3551 | }); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3552 | mStateAnimation.play(reveal); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3553 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3554 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3555 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
| 3556 | @Override |
| 3557 | public void onAnimationEnd(Animator animation) { |
| 3558 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3559 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 3560 | |
| 3561 | revealView.setVisibility(View.INVISIBLE); |
| 3562 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3563 | if (page != null) { |
| 3564 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3565 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3566 | content.setPageBackgroundsVisible(true); |
| 3567 | |
| 3568 | // Hide the search bar |
| 3569 | if (mSearchDropTargetBar != null) { |
| 3570 | mSearchDropTargetBar.hideSearchBar(false); |
| 3571 | } |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame^] | 3572 | |
| 3573 | // This can hold unnecessary references to views. |
| 3574 | mStateAnimation = null; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3577 | }); |
| 3578 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3579 | if (workspaceAnim != null) { |
| 3580 | mStateAnimation.play(workspaceAnim); |
| 3581 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3582 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3583 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3584 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3585 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3586 | final Runnable startAnimRunnable = new Runnable() { |
| 3587 | public void run() { |
| 3588 | // Check that mStateAnimation hasn't changed while |
| 3589 | // we waited for a layout/draw pass |
| 3590 | if (mStateAnimation != stateAnimation) |
| 3591 | return; |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3592 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3593 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3594 | |
| 3595 | revealView.setAlpha(initAlpha); |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3596 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3597 | for (int i = 0; i < layerViews.size(); i++) { |
| 3598 | View v = layerViews.get(i); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3599 | if (v != null) { |
| 3600 | boolean attached = true; |
| 3601 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| 3602 | attached = v.isAttachedToWindow(); |
| 3603 | } |
| 3604 | if (attached) v.buildLayer(); |
| 3605 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3606 | } |
| 3607 | } |
| 3608 | mStateAnimation.start(); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3609 | } |
| 3610 | }; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3611 | toView.bringToFront(); |
| 3612 | toView.setVisibility(View.VISIBLE); |
| 3613 | toView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3614 | } else { |
| 3615 | toView.setTranslationX(0.0f); |
| 3616 | toView.setTranslationY(0.0f); |
| 3617 | toView.setScaleX(1.0f); |
| 3618 | toView.setScaleY(1.0f); |
| 3619 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3620 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3621 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3622 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3623 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3624 | if (mSearchDropTargetBar != null) { |
| 3625 | mSearchDropTargetBar.hideSearchBar(false); |
| 3626 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3627 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3628 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3629 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3630 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3631 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3632 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3633 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3634 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | /** |
| 3638 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3639 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3640 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3641 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3642 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3643 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3644 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3645 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3646 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3647 | mStateAnimation.cancel(); |
| 3648 | mStateAnimation = null; |
| 3649 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3650 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3651 | boolean material = Utilities.isLmpOrAbove(); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3652 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3653 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3654 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3655 | final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3656 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3657 | final int itemsAlphaStagger = |
| 3658 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3659 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3660 | final float scaleFactor = (float) |
| 3661 | res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
| 3662 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3663 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3664 | Animator workspaceAnim = null; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3665 | final ArrayList<View> layerViews = new ArrayList<View>(); |
| 3666 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3667 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3668 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3669 | toState, animated, layerViews); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3670 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3671 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3672 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3673 | toState, animated, layerViews); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3674 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3675 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3676 | // If for some reason our views aren't initialized, don't animate |
| 3677 | boolean initialized = getAllAppsButton() != null; |
| 3678 | |
| 3679 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3680 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3681 | if (workspaceAnim != null) { |
| 3682 | mStateAnimation.play(workspaceAnim); |
| 3683 | } |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3684 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3685 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3686 | fromView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3687 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3688 | final View page = content.getPageAt(content.getNextPage()); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3689 | |
| 3690 | // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases |
| 3691 | int count = content.getChildCount(); |
| 3692 | for (int i = 0; i < count; i++) { |
| 3693 | View child = content.getChildAt(i); |
| 3694 | if (child != page) { |
| 3695 | child.setVisibility(View.INVISIBLE); |
| 3696 | } |
| 3697 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3698 | final View revealView = fromView.findViewById(R.id.fake_page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3699 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3700 | // hideAppsCustomizeHelper is called in some cases when it is already hidden |
| 3701 | // don't perform all these no-op animations. In particularly, this was causing |
| 3702 | // the all-apps button to pop in and out. |
| 3703 | if (fromView.getVisibility() == View.VISIBLE) { |
| 3704 | AppsCustomizePagedView.ContentType contentType = content.getContentType(); |
| 3705 | final boolean isWidgetTray = |
| 3706 | contentType == AppsCustomizePagedView.ContentType.Widgets; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3707 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3708 | if (isWidgetTray) { |
| 3709 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3710 | } else { |
| 3711 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3712 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3713 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3714 | int width = revealView.getMeasuredWidth(); |
| 3715 | int height = revealView.getMeasuredHeight(); |
| 3716 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
| 3717 | |
| 3718 | // Hide the real page background, and swap in the fake one |
| 3719 | revealView.setVisibility(View.VISIBLE); |
| 3720 | content.setPageBackgroundsVisible(false); |
| 3721 | |
| 3722 | final View allAppsButton = getAllAppsButton(); |
| 3723 | revealView.setTranslationY(0); |
| 3724 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3725 | allAppsButton, null); |
| 3726 | |
| 3727 | float xDrift = 0; |
| 3728 | float yDrift = 0; |
| 3729 | if (material) { |
| 3730 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3731 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3732 | } else { |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3733 | yDrift = 2 * height / 3; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3734 | xDrift = 0; |
| 3735 | } |
| 3736 | |
| 3737 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3738 | TimeInterpolator decelerateInterpolator = material ? |
| 3739 | new LogDecelerateInterpolator(100, 0) : |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3740 | new DecelerateInterpolator(1f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3741 | |
| 3742 | // The vertical motion of the apps panel should be delayed by one frame |
| 3743 | // from the conceal animation in order to give the right feel. We correpsondingly |
| 3744 | // shorten the duration so that the slide and conceal end at the same time. |
| 3745 | ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", |
| 3746 | 0, yDrift); |
| 3747 | panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3748 | panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3749 | panelDriftY.setInterpolator(decelerateInterpolator); |
| 3750 | mStateAnimation.play(panelDriftY); |
| 3751 | |
| 3752 | ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", |
| 3753 | 0, xDrift); |
| 3754 | panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3755 | panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3756 | panelDriftX.setInterpolator(decelerateInterpolator); |
| 3757 | mStateAnimation.play(panelDriftX); |
| 3758 | |
| 3759 | if (isWidgetTray || !material) { |
| 3760 | float finalAlpha = material ? 0.4f : 0f; |
| 3761 | revealView.setAlpha(1f); |
| 3762 | ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", |
| 3763 | 1f, finalAlpha); |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3764 | panelAlpha.setDuration(material ? revealDuration : 150); |
| 3765 | panelAlpha.setInterpolator(decelerateInterpolator); |
| 3766 | panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3767 | mStateAnimation.play(panelAlpha); |
| 3768 | } |
| 3769 | |
| 3770 | if (page != null) { |
| 3771 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3772 | |
| 3773 | ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", |
| 3774 | 0, yDrift); |
| 3775 | page.setTranslationY(0); |
| 3776 | pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3777 | pageDrift.setInterpolator(decelerateInterpolator); |
| 3778 | pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3779 | mStateAnimation.play(pageDrift); |
| 3780 | |
| 3781 | page.setAlpha(1f); |
| 3782 | ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f); |
| 3783 | itemsAlpha.setDuration(100); |
| 3784 | itemsAlpha.setInterpolator(decelerateInterpolator); |
| 3785 | mStateAnimation.play(itemsAlpha); |
| 3786 | } |
| 3787 | |
| 3788 | View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); |
| 3789 | pageIndicators.setAlpha(1f); |
| 3790 | ObjectAnimator indicatorsAlpha = |
| 3791 | LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f); |
| 3792 | indicatorsAlpha.setDuration(revealDuration); |
| 3793 | indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 3794 | mStateAnimation.play(indicatorsAlpha); |
| 3795 | |
| 3796 | width = revealView.getMeasuredWidth(); |
| 3797 | |
| 3798 | if (material) { |
| 3799 | if (!isWidgetTray) { |
| 3800 | allAppsButton.setVisibility(View.INVISIBLE); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3801 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3802 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3803 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3804 | float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
| 3805 | Animator reveal = |
| 3806 | LauncherAnimUtils.createCircularReveal(revealView, width / 2, |
| 3807 | height / 2, revealRadius, finalRadius); |
| 3808 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3809 | reveal.setDuration(revealDuration); |
| 3810 | reveal.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3811 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3812 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3813 | public void onAnimationEnd(Animator animation) { |
| 3814 | revealView.setVisibility(View.INVISIBLE); |
| 3815 | if (!isWidgetTray) { |
| 3816 | allAppsButton.setVisibility(View.VISIBLE); |
| 3817 | } |
| 3818 | } |
| 3819 | }); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3820 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3821 | mStateAnimation.play(reveal); |
| 3822 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3823 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3824 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3825 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 3826 | mAppsCustomizeContent.stopScrolling(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3827 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3828 | |
| 3829 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3830 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3831 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3832 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3833 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3834 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3835 | if (onCompleteRunnable != null) { |
| 3836 | onCompleteRunnable.run(); |
| 3837 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3838 | |
| 3839 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3840 | if (page != null) { |
| 3841 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3842 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3843 | content.setPageBackgroundsVisible(true); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3844 | // Unhide side pages |
| 3845 | int count = content.getChildCount(); |
| 3846 | for (int i = 0; i < count; i++) { |
| 3847 | View child = content.getChildAt(i); |
| 3848 | child.setVisibility(View.VISIBLE); |
| 3849 | } |
| 3850 | |
| 3851 | // Reset page transforms |
Adam Cohen | 493f6bc | 2014-09-18 08:11:05 -0700 | [diff] [blame] | 3852 | if (page != null) { |
| 3853 | page.setTranslationX(0); |
| 3854 | page.setTranslationY(0); |
| 3855 | page.setAlpha(1); |
| 3856 | } |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3857 | content.setCurrentPage(content.getNextPage()); |
| 3858 | |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3859 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame^] | 3860 | |
| 3861 | // This can hold unnecessary references to views. |
| 3862 | mStateAnimation = null; |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3863 | } |
| 3864 | }); |
| 3865 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3866 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3867 | final Runnable startAnimRunnable = new Runnable() { |
| 3868 | public void run() { |
| 3869 | // Check that mStateAnimation hasn't changed while |
| 3870 | // we waited for a layout/draw pass |
| 3871 | if (mStateAnimation != stateAnimation) |
| 3872 | return; |
| 3873 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3874 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3875 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3876 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3877 | for (int i = 0; i < layerViews.size(); i++) { |
| 3878 | View v = layerViews.get(i); |
Adam Cohen | 0f668f3 | 2014-09-08 19:54:17 +0200 | [diff] [blame] | 3879 | if (v != null) { |
| 3880 | boolean attached = true; |
| 3881 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| 3882 | attached = v.isAttachedToWindow(); |
| 3883 | } |
| 3884 | if (attached) v.buildLayer(); |
| 3885 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3886 | } |
| 3887 | } |
| 3888 | mStateAnimation.start(); |
| 3889 | } |
| 3890 | }; |
| 3891 | fromView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3892 | } else { |
| 3893 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3894 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3895 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3896 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3897 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3898 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3899 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3900 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3901 | } |
| 3902 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3903 | @Override |
| 3904 | public void onTrimMemory(int level) { |
| 3905 | super.onTrimMemory(level); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame^] | 3906 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
| 3907 | // The widget preview db can result in holding onto over |
| 3908 | // 3MB of memory for caching which isn't necessary. |
| 3909 | SQLiteDatabase.releaseMemory(); |
| 3910 | |
| 3911 | // We reset the apps customize tray in order to |
| 3912 | // to free all the memory associated with widget previews |
| 3913 | if (mAppsCustomizeTabHost != null) { |
| 3914 | mAppsCustomizeTabHost.reset(); |
| 3915 | } |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3916 | } |
| 3917 | } |
| 3918 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3919 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3920 | showWorkspace(animated, null); |
| 3921 | } |
| 3922 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3923 | protected void showWorkspace() { |
| 3924 | showWorkspace(true); |
| 3925 | } |
| 3926 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3927 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 3928 | if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3929 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3930 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3931 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3932 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3933 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3934 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3935 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3936 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3937 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3938 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3939 | // Set focus to the AppsCustomize button |
| 3940 | if (mAllAppsButton != null) { |
| 3941 | mAllAppsButton.requestFocus(); |
| 3942 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3943 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3944 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3945 | // Change the state *after* we've called all the transition code |
| 3946 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3947 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3948 | // Resume the auto-advance of widgets |
| 3949 | mUserPresent = true; |
| 3950 | updateRunning(); |
| 3951 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3952 | // Send an accessibility event to announce the context change |
| 3953 | getWindow().getDecorView() |
| 3954 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3955 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3956 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3957 | } |
| 3958 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3959 | void showOverviewMode(boolean animated) { |
| 3960 | mWorkspace.setVisibility(View.VISIBLE); |
| 3961 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3962 | mState = State.WORKSPACE; |
| 3963 | onWorkspaceShown(animated); |
| 3964 | } |
| 3965 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3966 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3967 | } |
| 3968 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3969 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3970 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3971 | if (mState != State.WORKSPACE) return; |
| 3972 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3973 | if (resetPageToZero) { |
| 3974 | mAppsCustomizeTabHost.reset(); |
| 3975 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3976 | showAppsCustomizeHelper(animated, false, contentType); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 3977 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3978 | @Override |
| 3979 | public void run() { |
| 3980 | // We post this in-case the all apps view isn't yet constructed. |
| 3981 | mAppsCustomizeTabHost.requestFocus(); |
| 3982 | } |
| 3983 | }); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3984 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3985 | // Change the state *after* we've called all the transition code |
| 3986 | mState = State.APPS_CUSTOMIZE; |
| 3987 | |
| 3988 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3989 | mUserPresent = false; |
| 3990 | updateRunning(); |
| 3991 | closeFolder(); |
| 3992 | |
| 3993 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3994 | getWindow().getDecorView() |
| 3995 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3998 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3999 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 4000 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 4001 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 4002 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 4003 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 4004 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 4005 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4006 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 4007 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 4008 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 4009 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 4010 | @Override |
| 4011 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 4012 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 4013 | // Before we show workspace, hide all apps again because |
| 4014 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 4015 | // clean up our state transition functions |
| 4016 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4017 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 4018 | } else { |
| 4019 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 4020 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 4021 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 4022 | }, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 4023 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 4024 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 4025 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 4026 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 4027 | final boolean animated = true; |
| 4028 | final boolean springLoaded = true; |
| 4029 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 4030 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4031 | } |
| 4032 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 4033 | } |
| 4034 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 4035 | void lockAllApps() { |
| 4036 | // TODO |
| 4037 | } |
| 4038 | |
| 4039 | void unlockAllApps() { |
| 4040 | // TODO |
| 4041 | } |
| 4042 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4043 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4044 | * Hides the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4045 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4046 | void hideHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 4047 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4048 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 4049 | if (mHotseat.getAlpha() != 0f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4050 | int duration = 0; |
| 4051 | if (mSearchDropTargetBar != null) { |
| 4052 | duration = mSearchDropTargetBar.getTransitionOutDuration(); |
| 4053 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 4054 | mHotseat.animate().alpha(0f).setDuration(duration); |
| 4055 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4056 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4057 | mHotseat.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4058 | } |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 4059 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 4060 | } |
| 4061 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 4062 | /** |
| 4063 | * Add an item from all apps or customize onto the given workspace screen. |
| 4064 | * If layout is null, add to the current screen. |
| 4065 | */ |
| 4066 | void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 4067 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 4068 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 4069 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 4070 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 4071 | |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 4072 | /** Maps the current orientation to an index for referencing orientation correct global icons */ |
| 4073 | private int getCurrentOrientationIndexForGlobalIcons() { |
| 4074 | // default - 0, landscape - 1 |
| 4075 | switch (getResources().getConfiguration().orientation) { |
| 4076 | case Configuration.ORIENTATION_LANDSCAPE: |
| 4077 | return 1; |
| 4078 | default: |
| 4079 | return 0; |
| 4080 | } |
| 4081 | } |
| 4082 | |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4083 | private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4084 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4085 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4086 | // Look for the toolbar icon specified in the activity meta-data |
| 4087 | Bundle metaData = packageManager.getActivityInfo( |
| 4088 | activityName, PackageManager.GET_META_DATA).metaData; |
| 4089 | if (metaData != null) { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4090 | int iconResId = metaData.getInt(resourceName); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4091 | if (iconResId != 0) { |
| 4092 | Resources res = packageManager.getResourcesForActivity(activityName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4093 | return res.getDrawable(iconResId); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4094 | } |
| 4095 | } |
| 4096 | } catch (NameNotFoundException e) { |
Michael Jurka | b6052a9 | 2011-07-12 17:02:45 -0700 | [diff] [blame] | 4097 | // This can happen if the activity defines an invalid drawable |
| 4098 | Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + |
| 4099 | " not found", e); |
Mathew Inwood | 70d5102 | 2011-07-12 13:41:41 +0100 | [diff] [blame] | 4100 | } catch (Resources.NotFoundException nfe) { |
| 4101 | // This can happen if the activity defines an invalid drawable |
| 4102 | Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), |
| 4103 | nfe); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4104 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4105 | return null; |
| 4106 | } |
| 4107 | |
| 4108 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 4109 | private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4110 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 4111 | String toolbarResourceName) { |
| 4112 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 4113 | Resources r = getResources(); |
| 4114 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 4115 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4116 | |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 4117 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4118 | // If we were unable to find the icon via the meta-data, use a generic one |
| 4119 | if (toolbarIcon == null) { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 4120 | toolbarIcon = r.getDrawable(fallbackDrawableId); |
| 4121 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 4122 | if (button != null) { |
| 4123 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 4124 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4125 | return null; |
| 4126 | } else { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 4127 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 4128 | if (button != null) { |
| 4129 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 4130 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4131 | return toolbarIcon.getConstantState(); |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 4136 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4137 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 4138 | String toolbarResourceName) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4139 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4140 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4141 | |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 4142 | if (button != null) { |
| 4143 | // If we were unable to find the icon via the meta-data, use a |
| 4144 | // generic one |
| 4145 | if (toolbarIcon == null) { |
| 4146 | button.setImageResource(fallbackDrawableId); |
| 4147 | } else { |
| 4148 | button.setImageDrawable(toolbarIcon); |
| 4149 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4150 | } |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 4151 | |
| 4152 | return toolbarIcon != null ? toolbarIcon.getConstantState() : null; |
| 4153 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4154 | } |
| 4155 | |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 4156 | private void updateTextButtonWithDrawable(int buttonId, Drawable d) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4157 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 4158 | button.setCompoundDrawables(d, null, null, null); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 4159 | } |
| 4160 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 4161 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4162 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 4163 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4164 | } |
| 4165 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4166 | private void invalidatePressedFocusedStates(View container, View button) { |
| 4167 | if (container instanceof HolographicLinearLayout) { |
| 4168 | HolographicLinearLayout layout = (HolographicLinearLayout) container; |
| 4169 | layout.invalidatePressedFocusedStates(); |
| 4170 | } else if (button instanceof HolographicImageView) { |
| 4171 | HolographicImageView view = (HolographicImageView) button; |
| 4172 | view.invalidatePressedFocusedStates(); |
| 4173 | } |
| 4174 | } |
| 4175 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4176 | public View getQsbBar() { |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 4177 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 4178 | return mLauncherCallbacks.getQsbBar(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 4181 | if (mQsb == null) { |
| 4182 | mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false); |
| 4183 | mSearchDropTargetBar.addView(mQsb); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4184 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 4185 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | protected boolean updateGlobalSearchIcon() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4189 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 4190 | return true; |
| 4191 | } |
| 4192 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4193 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4194 | final ImageView searchButton = (ImageView) findViewById(R.id.search_button); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4195 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 4196 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 4197 | |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4198 | final SearchManager searchManager = |
| 4199 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 4200 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 4201 | if (activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 4202 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 4203 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4204 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 4205 | TOOLBAR_SEARCH_ICON_METADATA_NAME); |
| 4206 | if (sGlobalSearchIcon[coi] == null) { |
| 4207 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 4208 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 4209 | TOOLBAR_ICON_METADATA_NAME); |
| 4210 | } |
| 4211 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4212 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); |
| 4213 | searchButton.setVisibility(View.VISIBLE); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4214 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4215 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4216 | } else { |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 4217 | // 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] | 4218 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); |
| 4219 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 4220 | if (searchButton != null) searchButton.setVisibility(View.GONE); |
| 4221 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4222 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4223 | return false; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4224 | } |
| 4225 | } |
| 4226 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4227 | protected void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4228 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) return; |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4229 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
| 4230 | final View searchButton = (ImageView) findViewById(R.id.search_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4231 | updateButtonWithDrawable(R.id.search_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4232 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4233 | } |
| 4234 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4235 | protected boolean updateVoiceSearchIcon(boolean searchVisible) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4236 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 4237 | return true; |
| 4238 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4239 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4240 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 4241 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4242 | // 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] | 4243 | final SearchManager searchManager = |
| 4244 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 4245 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 4246 | |
| 4247 | ComponentName activityName = null; |
| 4248 | if (globalSearchActivity != null) { |
| 4249 | // Check if the global search activity handles voice search |
| 4250 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 4251 | intent.setPackage(globalSearchActivity.getPackageName()); |
| 4252 | activityName = intent.resolveActivity(getPackageManager()); |
| 4253 | } |
| 4254 | |
| 4255 | if (activityName == null) { |
| 4256 | // Fallback: check if an activity other than the global search activity |
| 4257 | // resolves this |
| 4258 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 4259 | activityName = intent.resolveActivity(getPackageManager()); |
| 4260 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4261 | if (searchVisible && activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 4262 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 4263 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 4264 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 4265 | TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); |
| 4266 | if (sVoiceSearchIcon[coi] == null) { |
| 4267 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 4268 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 4269 | TOOLBAR_ICON_METADATA_NAME); |
| 4270 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4271 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4272 | voiceButton.setVisibility(View.VISIBLE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4273 | updateVoiceButtonProxyVisible(false); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4274 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4275 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 4276 | } else { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4277 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 4278 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4279 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4280 | return false; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4281 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 4282 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 4283 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4284 | protected void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4285 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 4286 | return; |
| 4287 | } |
| 4288 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4289 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
| 4290 | final View voiceButton = findViewById(R.id.voice_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4291 | updateButtonWithDrawable(R.id.voice_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 4292 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4293 | } |
| 4294 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4295 | public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4296 | if (mLauncherCallbacks != null) { |
| 4297 | forceDisableVoiceButtonProxy |= mLauncherCallbacks.forceDisableVoiceButtonProxy(); |
| 4298 | } |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4299 | final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); |
| 4300 | if (voiceButtonProxy != null) { |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4301 | boolean visible = !forceDisableVoiceButtonProxy && |
| 4302 | mWorkspace.shouldVoiceButtonProxyBeVisible(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4303 | voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4304 | voiceButtonProxy.bringToFront(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 4305 | } |
| 4306 | } |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 4307 | |
| 4308 | /** |
| 4309 | * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy |
| 4310 | * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns. |
| 4311 | */ |
| 4312 | public void disableVoiceButtonProxy(boolean disabled) { |
| 4313 | updateVoiceButtonProxyVisible(disabled); |
| 4314 | } |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 4315 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4316 | @Override |
| 4317 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4318 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4319 | final List<CharSequence> text = event.getText(); |
| 4320 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4321 | // Populate event with a fake title based on the current state. |
| 4322 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4323 | text.add(mAppsCustomizeTabHost.getContentTag()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4324 | } else { |
| 4325 | text.add(getString(R.string.all_apps_home_button_label)); |
| 4326 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4327 | return result; |
| 4328 | } |
| 4329 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4330 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 4331 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4332 | */ |
| 4333 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 4334 | @Override |
| 4335 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4336 | closeSystemDialogs(); |
| 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 4341 | * Receives notifications whenever the appwidgets are reset. |
| 4342 | */ |
| 4343 | private class AppWidgetResetObserver extends ContentObserver { |
| 4344 | public AppWidgetResetObserver() { |
| 4345 | super(new Handler()); |
| 4346 | } |
| 4347 | |
| 4348 | @Override |
| 4349 | public void onChange(boolean selfChange) { |
| 4350 | onAppWidgetReset(); |
| 4351 | } |
| 4352 | } |
| 4353 | |
| 4354 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4355 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 4356 | * in onResume. |
| 4357 | * |
| 4358 | * This needs to be called from incoming places where resources might have been loaded |
| 4359 | * while we are paused. That is becaues the Configuration might be wrong |
| 4360 | * when we're not running, and if it comes back to what it was when we |
| 4361 | * were paused, we are not restarted. |
| 4362 | * |
| 4363 | * Implementation of the method from LauncherModel.Callbacks. |
| 4364 | * |
| 4365 | * @return true if we are currently paused. The caller might be able to |
| 4366 | * skip some work in that case since we will come back again. |
| 4367 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4368 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4369 | if (mPaused) { |
| 4370 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4371 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4372 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4373 | } |
| 4374 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4375 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4376 | return true; |
| 4377 | } else { |
| 4378 | return false; |
| 4379 | } |
| 4380 | } |
| 4381 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4382 | private boolean waitUntilResume(Runnable run) { |
| 4383 | return waitUntilResume(run, false); |
| 4384 | } |
| 4385 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4386 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 4387 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4388 | } |
| 4389 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4390 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4391 | * If the activity is currently paused, signal that we need to re-run the loader |
| 4392 | * in onResume. |
| 4393 | * |
| 4394 | * This needs to be called from incoming places where resources might have been loaded |
| 4395 | * while we are paused. That is becaues the Configuration might be wrong |
| 4396 | * when we're not running, and if it comes back to what it was when we |
| 4397 | * were paused, we are not restarted. |
| 4398 | * |
| 4399 | * Implementation of the method from LauncherModel.Callbacks. |
| 4400 | * |
| 4401 | * @return true if we are currently paused. The caller might be able to |
| 4402 | * skip some work in that case since we will come back again. |
| 4403 | */ |
| 4404 | public boolean setLoadOnResume() { |
| 4405 | if (mPaused) { |
| 4406 | Log.i(TAG, "setLoadOnResume"); |
| 4407 | mOnResumeNeedsLoad = true; |
| 4408 | return true; |
| 4409 | } else { |
| 4410 | return false; |
| 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4415 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4416 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4417 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4418 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4419 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4420 | } else { |
| 4421 | return SCREEN_COUNT / 2; |
| 4422 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4423 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4424 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4425 | /** |
| 4426 | * Refreshes the shortcuts shown on the workspace. |
| 4427 | * |
| 4428 | * Implementation of the method from LauncherModel.Callbacks. |
| 4429 | */ |
| 4430 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4431 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 4432 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4433 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 4434 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 4435 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4436 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4437 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4438 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4439 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 4440 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4441 | |
Michael Jurka | 05bf644e | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 4442 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4443 | if (mHotseat != null) { |
| 4444 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4445 | } |
| 4446 | } |
| 4447 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4448 | @Override |
| 4449 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4450 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4451 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 4452 | // If there are no screens, we need to have an empty screen |
| 4453 | if (orderedScreenIds.size() == 0) { |
| 4454 | mWorkspace.addExtraEmptyScreen(); |
| 4455 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4456 | |
| 4457 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4458 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 4459 | if (hasCustomContentToLeft()) { |
| 4460 | mWorkspace.createCustomContentContainer(); |
| 4461 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4462 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4463 | } |
| 4464 | |
| 4465 | @Override |
| 4466 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 4467 | // Log to disk |
| 4468 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 4469 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 4470 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4471 | int count = orderedScreenIds.size(); |
| 4472 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 4473 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4474 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4475 | } |
| 4476 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4477 | private boolean shouldShowWeightWatcher() { |
| 4478 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4479 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b800 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 4480 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4481 | |
| 4482 | return show; |
| 4483 | } |
| 4484 | |
| 4485 | private void toggleShowWeightWatcher() { |
| 4486 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4487 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 4488 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 4489 | |
| 4490 | show = !show; |
| 4491 | |
| 4492 | SharedPreferences.Editor editor = sp.edit(); |
| 4493 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 4494 | editor.commit(); |
| 4495 | |
| 4496 | if (mWeightWatcher != null) { |
| 4497 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 4498 | } |
| 4499 | } |
| 4500 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4501 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 4502 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4503 | final ArrayList<ItemInfo> addAnimated, |
| 4504 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4505 | Runnable r = new Runnable() { |
| 4506 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4507 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4508 | } |
| 4509 | }; |
| 4510 | if (waitUntilResume(r)) { |
| 4511 | return; |
| 4512 | } |
| 4513 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4514 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4515 | if (newScreens != null) { |
| 4516 | bindAddScreens(newScreens); |
| 4517 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4518 | |
| 4519 | // We add the items without animation on non-visible pages, and with |
| 4520 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4521 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4522 | bindItems(addNotAnimated, 0, |
| 4523 | addNotAnimated.size(), false); |
| 4524 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4525 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4526 | bindItems(addAnimated, 0, |
| 4527 | addAnimated.size(), true); |
| 4528 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4529 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4530 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 4531 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4532 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4533 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4534 | addedApps != null && mAppsCustomizeContent != null) { |
| 4535 | mAppsCustomizeContent.addApps(addedApps); |
| 4536 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4537 | } |
| 4538 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4539 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4540 | * Bind the items start-end from the list. |
| 4541 | * |
| 4542 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4543 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4544 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 4545 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4546 | Runnable r = new Runnable() { |
| 4547 | public void run() { |
| 4548 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 4549 | } |
| 4550 | }; |
| 4551 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4552 | return; |
| 4553 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4554 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4555 | // 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] | 4556 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 4557 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4558 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4559 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4560 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4561 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4562 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4563 | |
| 4564 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4565 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4566 | mHotseat == null) { |
| 4567 | continue; |
| 4568 | } |
| 4569 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4570 | switch (item.itemType) { |
| 4571 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4572 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4573 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4574 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4575 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4576 | /* |
| 4577 | * TODO: FIX collision case |
| 4578 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4579 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4580 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4581 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4582 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4583 | Object tag = v.getTag(); |
| 4584 | String desc = "Collision while binding workspace item: " + item |
| 4585 | + ". Collides with " + tag; |
| 4586 | if (LauncherAppState.isDogfoodBuild()) { |
| 4587 | throw (new RuntimeException(desc)); |
| 4588 | } else { |
| 4589 | Log.d(TAG, desc); |
| 4590 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4591 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4592 | } |
| 4593 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4594 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4595 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4596 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4597 | // Animate all the applications up now |
| 4598 | shortcut.setAlpha(0f); |
| 4599 | shortcut.setScaleX(0f); |
| 4600 | shortcut.setScaleY(0f); |
| 4601 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4602 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4603 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4604 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4605 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4606 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4607 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4608 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4609 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4610 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4611 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4612 | default: |
| 4613 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4614 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4615 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4616 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4617 | if (animateIcons) { |
| 4618 | // Animate to the correct page |
| 4619 | if (newShortcutsScreenId > -1) { |
| 4620 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4621 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4622 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4623 | public void run() { |
| 4624 | anim.playTogether(bounceAnims); |
| 4625 | anim.start(); |
| 4626 | } |
| 4627 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4628 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4629 | // We post the animation slightly delayed to prevent slowdowns |
| 4630 | // when we are loading right after we return to launcher. |
| 4631 | mWorkspace.postDelayed(new Runnable() { |
| 4632 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4633 | if (mWorkspace != null) { |
| 4634 | mWorkspace.snapToPage(newScreenIndex); |
| 4635 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4636 | NEW_APPS_ANIMATION_DELAY); |
| 4637 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4638 | } |
| 4639 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4640 | } else { |
| 4641 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4642 | } |
| 4643 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4644 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4645 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4646 | } |
| 4647 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4648 | /** |
| 4649 | * Implementation of the method from LauncherModel.Callbacks. |
| 4650 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4651 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4652 | Runnable r = new Runnable() { |
| 4653 | public void run() { |
| 4654 | bindFolders(folders); |
| 4655 | } |
| 4656 | }; |
| 4657 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4658 | return; |
| 4659 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4660 | sFolders.clear(); |
| 4661 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4662 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4663 | |
| 4664 | /** |
| 4665 | * Add the views for a widget to the workspace. |
| 4666 | * |
| 4667 | * Implementation of the method from LauncherModel.Callbacks. |
| 4668 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4669 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4670 | Runnable r = new Runnable() { |
| 4671 | public void run() { |
| 4672 | bindAppWidget(item); |
| 4673 | } |
| 4674 | }; |
| 4675 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4676 | return; |
| 4677 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4678 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4679 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4680 | if (DEBUG_WIDGETS) { |
| 4681 | Log.d(TAG, "bindAppWidget: " + item); |
| 4682 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4683 | final Workspace workspace = mWorkspace; |
| 4684 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4685 | AppWidgetProviderInfo appWidgetInfo; |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4686 | if (!mIsSafeModeEnabled |
| 4687 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) |
| 4688 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4689 | |
| 4690 | appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName); |
| 4691 | if (appWidgetInfo == null) { |
| 4692 | if (DEBUG_WIDGETS) { |
| 4693 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4694 | + " belongs to component " + item.providerName |
| 4695 | + ", as the povider is null"); |
| 4696 | } |
| 4697 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4698 | return; |
| 4699 | } |
| 4700 | // Note: This assumes that the id remap broadcast is received before this step. |
| 4701 | // If that is not the case, the id remap will be ignored and user may see the |
| 4702 | // click to setup view. |
| 4703 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null); |
| 4704 | pendingInfo.spanX = item.spanX; |
| 4705 | pendingInfo.spanY = item.spanY; |
| 4706 | pendingInfo.minSpanX = item.minSpanX; |
| 4707 | pendingInfo.minSpanY = item.minSpanY; |
| 4708 | Bundle options = |
| 4709 | AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo); |
| 4710 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4711 | int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 4712 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 4713 | newWidgetId, appWidgetInfo, options); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4714 | |
| 4715 | // TODO consider showing a permission dialog when the widget is clicked. |
| 4716 | if (!success) { |
| 4717 | mAppWidgetHost.deleteAppWidgetId(newWidgetId); |
| 4718 | if (DEBUG_WIDGETS) { |
| 4719 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4720 | + " belongs to component " + item.providerName |
| 4721 | + ", as the launcher is unable to bing a new widget id"); |
| 4722 | } |
| 4723 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4724 | return; |
| 4725 | } |
| 4726 | |
| 4727 | item.appWidgetId = newWidgetId; |
| 4728 | |
| 4729 | // If the widget has a configure activity, it is still needs to set it up, otherwise |
| 4730 | // the widget is ready to go. |
| 4731 | item.restoreStatus = (appWidgetInfo.configure == null) |
| 4732 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 4733 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 4734 | |
| 4735 | LauncherModel.updateItemInDatabase(this, item); |
| 4736 | } |
| 4737 | |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4738 | if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4739 | final int appWidgetId = item.appWidgetId; |
| 4740 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 4741 | if (DEBUG_WIDGETS) { |
| 4742 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 4743 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4744 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4745 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4746 | } else { |
| 4747 | appWidgetInfo = null; |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4748 | PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, |
| 4749 | mIsSafeModeEnabled); |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4750 | view.updateIcon(mIconCache); |
| 4751 | item.hostView = view; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4752 | item.hostView.updateAppWidget(null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4753 | item.hostView.setOnClickListener(this); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4754 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4755 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4756 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4757 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4758 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4759 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4760 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4761 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4762 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4763 | workspace.requestLayout(); |
| 4764 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4765 | if (DEBUG_WIDGETS) { |
| 4766 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4767 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4768 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4769 | } |
| 4770 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4771 | /** |
| 4772 | * Restores a pending widget. |
| 4773 | * |
| 4774 | * @param appWidgetId The app widget id |
| 4775 | * @param cellInfo The position on screen where to create the widget. |
| 4776 | */ |
| 4777 | private void completeRestoreAppWidget(final int appWidgetId) { |
| 4778 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 4779 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 4780 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
| 4781 | return; |
| 4782 | } |
| 4783 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4784 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4785 | info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 4786 | |
| 4787 | mWorkspace.reinflateWidgetsIfNecessary(); |
| 4788 | LauncherModel.updateItemInDatabase(this, info); |
| 4789 | } |
| 4790 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4791 | public void onPageBoundSynchronously(int page) { |
| 4792 | mSynchronouslyBoundPages.add(page); |
| 4793 | } |
| 4794 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4795 | /** |
| 4796 | * Callback saying that there aren't any more items to bind. |
| 4797 | * |
| 4798 | * Implementation of the method from LauncherModel.Callbacks. |
| 4799 | */ |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4800 | public void finishBindingItems(final boolean upgradePath) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4801 | Runnable r = new Runnable() { |
| 4802 | public void run() { |
| 4803 | finishBindingItems(upgradePath); |
| 4804 | } |
| 4805 | }; |
| 4806 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4807 | return; |
| 4808 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4809 | if (mSavedState != null) { |
| 4810 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4811 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4812 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4813 | mSavedState = null; |
| 4814 | } |
| 4815 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4816 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4817 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4818 | setWorkspaceLoading(false); |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4819 | sendLoadingCompleteBroadcastIfNecessary(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 4820 | |
| 4821 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4822 | // widget configuration forced an orientation change), process them now. |
| 4823 | if (sPendingAddItem != null) { |
| 4824 | final long screenId = completeAdd(sPendingAddItem); |
| 4825 | |
| 4826 | // TODO: this moves the user to the page where the pending item was added. Ideally, |
| 4827 | // the screen would be guaranteed to exist after bind, and the page would be set through |
| 4828 | // the workspace restore process. |
| 4829 | mWorkspace.post(new Runnable() { |
| 4830 | @Override |
| 4831 | public void run() { |
| 4832 | mWorkspace.snapToScreenId(screenId); |
| 4833 | } |
| 4834 | }); |
| 4835 | sPendingAddItem = null; |
| 4836 | } |
| 4837 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4838 | if (upgradePath) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4839 | mWorkspace.getUniqueComponents(true, null); |
| 4840 | mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4841 | } |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4842 | PackageInstallerCompat.getInstance(this).onFinishBind(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4843 | |
| 4844 | if (mLauncherCallbacks != null) { |
| 4845 | mLauncherCallbacks.finishBindingItems(upgradePath); |
| 4846 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4849 | private void sendLoadingCompleteBroadcastIfNecessary() { |
| 4850 | if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) { |
| 4851 | String permission = |
| 4852 | getResources().getString(R.string.receive_first_load_broadcast_permission); |
| 4853 | Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE); |
| 4854 | sendBroadcast(intent, permission); |
| 4855 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4856 | editor.putBoolean(FIRST_LOAD_COMPLETE, true); |
| 4857 | editor.apply(); |
| 4858 | } |
| 4859 | } |
| 4860 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4861 | public boolean isAllAppsButtonRank(int rank) { |
| 4862 | if (mHotseat != null) { |
| 4863 | return mHotseat.isAllAppsButtonRank(rank); |
| 4864 | } |
| 4865 | return false; |
| 4866 | } |
| 4867 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4868 | private boolean canRunNewAppsAnimation() { |
| 4869 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4870 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4871 | } |
| 4872 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4873 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4874 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4875 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4876 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4877 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4878 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4879 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4880 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4881 | return bounceAnim; |
| 4882 | } |
| 4883 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4884 | public boolean useVerticalBarLayout() { |
| 4885 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4886 | getDeviceProfile().isVerticalBarLayout(); |
| 4887 | } |
| 4888 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4889 | protected Rect getSearchBarBounds() { |
| 4890 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4891 | getDeviceProfile().getSearchBarBounds(); |
| 4892 | } |
| 4893 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4894 | @Override |
| 4895 | public void bindSearchablesChanged() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4896 | boolean searchVisible = updateGlobalSearchIcon(); |
| 4897 | boolean voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4898 | if (mSearchDropTargetBar != null) { |
| 4899 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 4900 | } |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4901 | } |
| 4902 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4903 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4904 | * Add the icons for all apps. |
| 4905 | * |
| 4906 | * Implementation of the method from LauncherModel.Callbacks. |
| 4907 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4908 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4909 | if (LauncherAppState.isDisableAllApps()) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4910 | if (mIntentsOnWorkspaceFromUpgradePath != null) { |
| 4911 | if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) { |
| 4912 | getHotseat().addAllAppsFolder(mIconCache, apps, |
| 4913 | mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace); |
| 4914 | } |
| 4915 | mIntentsOnWorkspaceFromUpgradePath = null; |
Daniel Sandler | 8707e0f | 2013-08-15 15:54:18 -0700 | [diff] [blame] | 4916 | } |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4917 | if (mAppsCustomizeContent != null) { |
| 4918 | mAppsCustomizeContent.onPackagesUpdated( |
| 4919 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
| 4920 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4921 | } else { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 4922 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4923 | mAppsCustomizeContent.setApps(apps); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 4924 | mAppsCustomizeContent.onPackagesUpdated( |
| 4925 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4926 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4927 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4928 | if (mLauncherCallbacks != null) { |
| 4929 | mLauncherCallbacks.bindAllApplications(apps); |
| 4930 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4931 | } |
| 4932 | |
| 4933 | /** |
| 4934 | * A package was updated. |
| 4935 | * |
| 4936 | * Implementation of the method from LauncherModel.Callbacks. |
| 4937 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4938 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4939 | Runnable r = new Runnable() { |
| 4940 | public void run() { |
| 4941 | bindAppsUpdated(apps); |
| 4942 | } |
| 4943 | }; |
| 4944 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4945 | return; |
| 4946 | } |
| 4947 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4948 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4949 | mAppsCustomizeContent != null) { |
| 4950 | mAppsCustomizeContent.updateApps(apps); |
| 4951 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4952 | } |
| 4953 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4954 | @Override |
| 4955 | public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) { |
| 4956 | Runnable r = new Runnable() { |
| 4957 | public void run() { |
| 4958 | bindWidgetsRestored(widgets); |
| 4959 | } |
| 4960 | }; |
| 4961 | if (waitUntilResume(r)) { |
| 4962 | return; |
| 4963 | } |
| 4964 | mWorkspace.widgetsRestored(widgets); |
| 4965 | } |
| 4966 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4967 | /** |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4968 | * Some shortcuts were updated in the background. |
| 4969 | * |
| 4970 | * Implementation of the method from LauncherModel.Callbacks. |
| 4971 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4972 | @Override |
| 4973 | public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated, |
| 4974 | final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4975 | Runnable r = new Runnable() { |
| 4976 | public void run() { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4977 | bindShortcutsChanged(updated, removed, user); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4978 | } |
| 4979 | }; |
| 4980 | if (waitUntilResume(r)) { |
| 4981 | return; |
| 4982 | } |
| 4983 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4984 | if (!updated.isEmpty()) { |
| 4985 | mWorkspace.updateShortcuts(updated); |
| 4986 | } |
| 4987 | |
| 4988 | if (!removed.isEmpty()) { |
| 4989 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 4990 | for (ShortcutInfo si : removed) { |
| 4991 | removedComponents.add(si.getTargetComponent()); |
| 4992 | } |
| 4993 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
| 4994 | // Notify the drag controller |
| 4995 | mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4996 | } |
| 4997 | } |
| 4998 | |
| 4999 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 5000 | * Update the state of a package, typically related to install state. |
| 5001 | * |
| 5002 | * Implementation of the method from LauncherModel.Callbacks. |
| 5003 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 5004 | @Override |
| 5005 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 5006 | if (mWorkspace != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 5007 | mWorkspace.updatePackageState(installInfo); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 5008 | } |
| 5009 | } |
| 5010 | |
| 5011 | /** |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 5012 | * Update the label and icon of all the icons in a package |
| 5013 | * |
| 5014 | * Implementation of the method from LauncherModel.Callbacks. |
| 5015 | */ |
| 5016 | @Override |
| 5017 | public void updatePackageBadge(String packageName) { |
| 5018 | if (mWorkspace != null) { |
| 5019 | mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle()); |
| 5020 | } |
| 5021 | } |
| 5022 | |
| 5023 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5024 | * A package was uninstalled. We take both the super set of packageNames |
| 5025 | * in addition to specific applications to remove, the reason being that |
| 5026 | * this can be called when a package is updated as well. In that scenario, |
| 5027 | * we only remove specific components from the workspace, where as |
| 5028 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 5029 | * |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5030 | * @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] | 5031 | * Implementation of the method from LauncherModel.Callbacks. |
| 5032 | */ |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5033 | @Override |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5034 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5035 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 5036 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5037 | public void run() { |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5038 | bindComponentsRemoved(packageNames, appInfos, user, reason); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5039 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 5040 | }; |
| 5041 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5042 | return; |
| 5043 | } |
| 5044 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5045 | if (reason == 0) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 5046 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 5047 | for (AppInfo info : appInfos) { |
| 5048 | removedComponents.add(info.componentName); |
| 5049 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5050 | if (!packageNames.isEmpty()) { |
| 5051 | mWorkspace.removeItemsByPackageName(packageNames, user); |
| 5052 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 5053 | if (!removedComponents.isEmpty()) { |
| 5054 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5055 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 5056 | // Notify the drag controller |
| 5057 | mDragController.onAppsRemoved(packageNames, removedComponents); |
| 5058 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 5059 | } else { |
| 5060 | mWorkspace.disableShortcutsByPackageName(packageNames, user, reason); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 5061 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5062 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 5063 | // Update AllApps |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 5064 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 5065 | mAppsCustomizeContent != null) { |
| 5066 | mAppsCustomizeContent.removeApps(appInfos); |
| 5067 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 5068 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5069 | |
| 5070 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5071 | * A number of packages were updated. |
| 5072 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5073 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 5074 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5075 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5076 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 5077 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5078 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5079 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5080 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 5081 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 5082 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 5083 | return; |
| 5084 | } |
| 5085 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 5086 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 5087 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 5088 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5089 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5090 | } |
| 5091 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 5092 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 5093 | final Display d = getWindowManager().getDefaultDisplay(); |
| 5094 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 5095 | switch (d.getRotation()) { |
| 5096 | case Surface.ROTATION_0: |
| 5097 | case Surface.ROTATION_180: |
| 5098 | // We are currently in the same basic orientation as the natural orientation |
| 5099 | naturalOri = configOri; |
| 5100 | break; |
| 5101 | case Surface.ROTATION_90: |
| 5102 | case Surface.ROTATION_270: |
| 5103 | // We are currently in the other basic orientation to the natural orientation |
| 5104 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 5105 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 5106 | break; |
| 5107 | } |
| 5108 | |
| 5109 | int[] oriMap = { |
| 5110 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 5111 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 5112 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 5113 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 5114 | }; |
| 5115 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 5116 | // is landscape. |
| 5117 | int indexOffset = 0; |
| 5118 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 5119 | indexOffset = 1; |
| 5120 | } |
| 5121 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 5122 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 5123 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5124 | public boolean isRotationEnabled() { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 5125 | boolean enableRotation = sForceEnableRotation || |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5126 | getResources().getBoolean(R.bool.allow_rotation); |
| 5127 | return enableRotation; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 5128 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5129 | public void lockScreenOrientation() { |
| 5130 | if (isRotationEnabled()) { |
| 5131 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 5132 | .getConfiguration().orientation)); |
| 5133 | } |
| 5134 | } |
| 5135 | public void unlockScreenOrientation(boolean immediate) { |
| 5136 | if (isRotationEnabled()) { |
| 5137 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 5138 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5139 | } else { |
| 5140 | mHandler.postDelayed(new Runnable() { |
| 5141 | public void run() { |
| 5142 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 5143 | } |
| 5144 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 5145 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 5146 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 5147 | } |
| 5148 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 5149 | protected boolean isLauncherPreinstalled() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5150 | if (mLauncherCallbacks != null) { |
| 5151 | return mLauncherCallbacks.isLauncherPreinstalled(); |
| 5152 | } |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 5153 | PackageManager pm = getPackageManager(); |
| 5154 | try { |
| 5155 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 5156 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 5157 | return true; |
| 5158 | } else { |
| 5159 | return false; |
| 5160 | } |
| 5161 | } catch (NameNotFoundException e) { |
| 5162 | e.printStackTrace(); |
| 5163 | return false; |
| 5164 | } |
| 5165 | } |
| 5166 | |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 5167 | /** |
| 5168 | * This method indicates whether or not we should suggest default wallpaper dimensions |
| 5169 | * when our wallpaper cropper was not yet used to set a wallpaper. |
| 5170 | */ |
| 5171 | protected boolean overrideWallpaperDimensions() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5172 | if (mLauncherCallbacks != null) { |
| 5173 | return mLauncherCallbacks.overrideWallpaperDimensions(); |
| 5174 | } |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 5175 | return true; |
| 5176 | } |
| 5177 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5178 | /** |
| 5179 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 5180 | * before showing the standard launcher experience. |
| 5181 | */ |
| 5182 | protected boolean hasFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5183 | if (mLauncherCallbacks != null) { |
| 5184 | return mLauncherCallbacks.hasFirstRunActivity(); |
| 5185 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5186 | return false; |
| 5187 | } |
| 5188 | |
| 5189 | /** |
| 5190 | * To be overridden by subclasses to launch any first run activity |
| 5191 | */ |
| 5192 | protected Intent getFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5193 | if (mLauncherCallbacks != null) { |
| 5194 | return mLauncherCallbacks.getFirstRunActivity(); |
| 5195 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5196 | return null; |
| 5197 | } |
| 5198 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5199 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 5200 | return !ActivityManager.isRunningInTestHarness() && |
| 5201 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5202 | } |
| 5203 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 5204 | protected boolean hasRunFirstRunActivity() { |
| 5205 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 5206 | } |
| 5207 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5208 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 5209 | if (shouldRunFirstRunActivity() && |
| 5210 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5211 | Intent firstRunIntent = getFirstRunActivity(); |
| 5212 | if (firstRunIntent != null) { |
| 5213 | startActivity(firstRunIntent); |
| 5214 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5215 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5216 | } |
| 5217 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5218 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | private void markFirstRunActivityShown() { |
| 5222 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 5223 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 5224 | editor.apply(); |
| 5225 | } |
| 5226 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5227 | /** |
| 5228 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 5229 | * screen that must be displayed and dismissed. |
| 5230 | */ |
| 5231 | protected boolean hasDismissableIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5232 | if (mLauncherCallbacks != null) { |
| 5233 | return mLauncherCallbacks.hasDismissableIntroScreen(); |
| 5234 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5235 | return false; |
| 5236 | } |
| 5237 | |
| 5238 | /** |
| 5239 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 5240 | */ |
| 5241 | protected View getIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5242 | if (mLauncherCallbacks != null) { |
| 5243 | return mLauncherCallbacks.getIntroScreen(); |
| 5244 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5245 | return null; |
| 5246 | } |
| 5247 | |
| 5248 | /** |
| 5249 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 5250 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 5251 | */ |
| 5252 | private boolean shouldShowIntroScreen() { |
| 5253 | return hasDismissableIntroScreen() && |
| 5254 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 5255 | } |
| 5256 | |
| 5257 | protected void showIntroScreen() { |
| 5258 | View introScreen = getIntroScreen(); |
| 5259 | changeWallpaperVisiblity(false); |
| 5260 | if (introScreen != null) { |
| 5261 | mDragLayer.showOverlayView(introScreen); |
| 5262 | } |
| 5263 | } |
| 5264 | |
| 5265 | public void dismissIntroScreen() { |
| 5266 | markIntroScreenDismissed(); |
| 5267 | if (showFirstRunActivity()) { |
| 5268 | // We delay hiding the intro view until the first run activity is showing. This |
| 5269 | // avoids a blip. |
| 5270 | mWorkspace.postDelayed(new Runnable() { |
| 5271 | @Override |
| 5272 | public void run() { |
| 5273 | mDragLayer.dismissOverlayView(); |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5274 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5275 | } |
| 5276 | }, ACTIVITY_START_DELAY); |
| 5277 | } else { |
| 5278 | mDragLayer.dismissOverlayView(); |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5279 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 5280 | } |
| 5281 | changeWallpaperVisiblity(true); |
| 5282 | } |
| 5283 | |
| 5284 | private void markIntroScreenDismissed() { |
| 5285 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 5286 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 5287 | editor.apply(); |
| 5288 | } |
| 5289 | |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5290 | private void showFirstRunClings() { |
| 5291 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 5292 | // on the device, then we always show the first run cling experience (or if there is no |
| 5293 | // launcher2). Otherwise, we prompt the user upon started for migration |
| 5294 | LauncherClings launcherClings = new LauncherClings(this); |
| 5295 | if (launcherClings.shouldShowFirstRunOrMigrationClings()) { |
| 5296 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
| 5297 | launcherClings.showMigrationCling(); |
| 5298 | } else { |
Sunny Goyal | af0628f | 2014-09-19 10:14:48 -0700 | [diff] [blame] | 5299 | launcherClings.showLongPressCling(true); |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 5300 | } |
| 5301 | } |
| 5302 | } |
| 5303 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5304 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 5305 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 5306 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 5307 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 5308 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 5312 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 5313 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 5314 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 5315 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5316 | } |
| 5317 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5318 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5319 | // Called from search suggestion, not supported in other profiles. |
| 5320 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 5321 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 5322 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 5323 | myUser); |
| 5324 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5325 | return null; |
| 5326 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5327 | return new AppInfo(this, activityInfo, myUser, mIconCache, null); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5331 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5332 | // Called from search suggestion, not supported in other profiles. |
| 5333 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 5334 | UserHandleCompat.myUserHandle()); |
| 5335 | } |
| 5336 | |
| 5337 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5338 | Bitmap icon, UserHandleCompat user) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5339 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 5340 | CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5341 | return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5342 | } |
| 5343 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 5344 | protected void moveWorkspaceToDefaultScreen() { |
| 5345 | mWorkspace.moveToDefaultScreen(false); |
| 5346 | } |
| 5347 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5348 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 5349 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 5350 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 5351 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5352 | } |
| 5353 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5354 | @Override |
| 5355 | public void onPageSwitch(View newPage, int newPageIndex) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5356 | if (mLauncherCallbacks != null) { |
| 5357 | mLauncherCallbacks.onPageSwitch(newPage, newPageIndex); |
| 5358 | } |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5359 | } |
| 5360 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5361 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5362 | * Prints out out state for debugging. |
| 5363 | */ |
| 5364 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5365 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5366 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5367 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 5368 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 5369 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 5370 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 5371 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5372 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5373 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5374 | if (mAppsCustomizeContent != null) { |
| 5375 | mAppsCustomizeContent.dumpState(); |
| 5376 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5377 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5378 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5379 | |
| 5380 | @Override |
| 5381 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5382 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5383 | synchronized (sDumpLogs) { |
| 5384 | writer.println(" "); |
| 5385 | writer.println("Debug logs: "); |
| 5386 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5387 | writer.println(" " + sDumpLogs.get(i)); |
| 5388 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5389 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5390 | if (mLauncherCallbacks != null) { |
| 5391 | mLauncherCallbacks.dump(prefix, fd, writer, args); |
| 5392 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5393 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5394 | |
| 5395 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5396 | if (DEBUG_DUMP_LOG) { |
| 5397 | synchronized (sDumpLogs) { |
| 5398 | Log.d(TAG, ""); |
| 5399 | Log.d(TAG, "*********************"); |
| 5400 | Log.d(TAG, "Launcher debug logs: "); |
| 5401 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5402 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 5403 | } |
| 5404 | Log.d(TAG, "*********************"); |
| 5405 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5406 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5407 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5411 | addDumpLog(tag, log, null, debugLog); |
| 5412 | } |
| 5413 | |
| 5414 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5415 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5416 | if (e != null) { |
| 5417 | Log.d(tag, log, e); |
| 5418 | } else { |
| 5419 | Log.d(tag, log); |
| 5420 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5421 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5422 | if (DEBUG_DUMP_LOG) { |
| 5423 | sDateStamp.setTime(System.currentTimeMillis()); |
| 5424 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5425 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 5426 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5427 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5428 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5431 | public void dumpLogsToLocalData() { |
| 5432 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5433 | new AsyncTask<Void, Void, Void>() { |
| 5434 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5435 | boolean success = false; |
| 5436 | sDateStamp.setTime(sRunStart); |
| 5437 | String FILENAME = sDateStamp.getMonth() + "-" |
| 5438 | + sDateStamp.getDay() + "_" |
| 5439 | + sDateStamp.getHours() + "-" |
| 5440 | + sDateStamp.getMinutes() + "_" |
| 5441 | + sDateStamp.getSeconds() + ".txt"; |
| 5442 | |
| 5443 | FileOutputStream fos = null; |
| 5444 | File outFile = null; |
| 5445 | try { |
| 5446 | outFile = new File(getFilesDir(), FILENAME); |
| 5447 | outFile.createNewFile(); |
| 5448 | fos = new FileOutputStream(outFile); |
| 5449 | } catch (Exception e) { |
| 5450 | e.printStackTrace(); |
| 5451 | } |
| 5452 | if (fos != null) { |
| 5453 | PrintWriter writer = new PrintWriter(fos); |
| 5454 | |
| 5455 | writer.println(" "); |
| 5456 | writer.println("Debug logs: "); |
| 5457 | synchronized (sDumpLogs) { |
| 5458 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5459 | writer.println(" " + sDumpLogs.get(i)); |
| 5460 | } |
| 5461 | } |
| 5462 | writer.close(); |
| 5463 | } |
| 5464 | try { |
| 5465 | if (fos != null) { |
| 5466 | fos.close(); |
| 5467 | success = true; |
| 5468 | } |
| 5469 | } catch (IOException e) { |
| 5470 | e.printStackTrace(); |
| 5471 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5472 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5473 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5474 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5475 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5476 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5477 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5478 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 5479 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 5480 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 5481 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5482 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 5483 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5484 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5485 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 5486 | |
| 5487 | interface DebugIntents { |
| 5488 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 5489 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 5490 | } |