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; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | import android.text.Selection; |
| 70 | import android.text.SpannableStringBuilder; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 71 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 73 | import android.util.Log; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 74 | import android.view.Display; |
| 75 | import android.view.Gravity; |
| 76 | import android.view.HapticFeedbackConstants; |
| 77 | import android.view.KeyEvent; |
| 78 | import android.view.LayoutInflater; |
| 79 | import android.view.Menu; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 80 | import android.view.MotionEvent; |
| 81 | import android.view.Surface; |
| 82 | import android.view.View; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 83 | import android.view.View.OnClickListener; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 84 | import android.view.View.OnLongClickListener; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 85 | import android.view.ViewAnimationUtils; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 86 | import android.view.ViewGroup; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 87 | import android.view.ViewStub; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 88 | import android.view.ViewTreeObserver; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 89 | import android.view.Window; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 90 | import android.view.WindowManager; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 91 | import android.view.accessibility.AccessibilityEvent; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 92 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 93 | import android.view.animation.DecelerateInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 95 | import android.widget.Advanceable; |
| 96 | import android.widget.FrameLayout; |
| 97 | import android.widget.ImageView; |
Chet Haase | a8f996d | 2015-02-17 12:56:04 -0800 | [diff] [blame] | 98 | import android.widget.TextView; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 99 | import android.widget.Toast; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 100 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 101 | import com.android.launcher3.DropTarget.DragObject; |
| 102 | import com.android.launcher3.PagedView.PageSwitchListener; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 103 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 104 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 105 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 106 | import com.android.launcher3.compat.PackageInstallerCompat; |
| 107 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 108 | import com.android.launcher3.compat.UserHandleCompat; |
| 109 | import com.android.launcher3.compat.UserManagerCompat; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 110 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 111 | import java.io.DataInputStream; |
| 112 | import java.io.DataOutputStream; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 113 | import java.io.File; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 114 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 115 | import java.io.FileNotFoundException; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 116 | import java.io.FileOutputStream; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 117 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 118 | import java.io.PrintWriter; |
Chet Haase | a8f996d | 2015-02-17 12:56:04 -0800 | [diff] [blame] | 119 | import java.lang.reflect.Field; |
| 120 | import java.lang.reflect.InvocationTargetException; |
| 121 | import java.lang.reflect.Method; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 122 | import java.text.DateFormat; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 123 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 124 | import java.util.Collection; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 125 | import java.util.Date; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 126 | import java.util.HashMap; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 127 | import java.util.HashSet; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 128 | import java.util.List; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 129 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 130 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 131 | /** |
| 132 | * Default launcher application. |
| 133 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 134 | public class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 135 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 136 | View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 137 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 138 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 139 | |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 140 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 141 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 142 | static final boolean DEBUG_STRICT_MODE = false; |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 143 | static final boolean DEBUG_RESUME_TIME = false; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_DUMP_LOG = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 145 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 146 | static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run |
| 147 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 148 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 149 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 150 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 151 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 152 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 154 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 155 | private static final int REQUEST_RECONFIGURE_APPWIDGET = 12; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 156 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 157 | /** |
| 158 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 159 | * request codes used internally. |
| 160 | */ |
| 161 | protected static final int REQUEST_LAST = 100; |
| 162 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 163 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 164 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 165 | static final int SCREEN_COUNT = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 166 | |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 167 | // To turn on these properties, type |
| 168 | // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS] |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 169 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 170 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 171 | // The Intent extra that defines whether to ignore the launch animation |
| 172 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 173 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 174 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 175 | // Type: int |
| 176 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 177 | // Type: int |
| 178 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 179 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 180 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 181 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 182 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 183 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 184 | 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] | 185 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 186 | 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] | 187 | // Type: boolean |
| 188 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 189 | // Type: long |
| 190 | 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] | 191 | // Type: int |
| 192 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 193 | // Type: int |
| 194 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 195 | // Type: parcelable |
| 196 | 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] | 197 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 198 | 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] | 199 | // Type: int[] |
| 200 | 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] | 201 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 202 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 203 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 204 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 205 | static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete"; |
| 206 | static final String ACTION_FIRST_LOAD_COMPLETE = |
| 207 | "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; |
| 208 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 209 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b800 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 210 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 211 | |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 212 | private static final String QSB_WIDGET_ID = "qsb_widget_id"; |
| 213 | private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider"; |
| 214 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 215 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 216 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 217 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 218 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 219 | private State mState = State.WORKSPACE; |
| 220 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 221 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 222 | private boolean mIsSafeModeEnabled; |
| 223 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 224 | LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl(); |
| 225 | LauncherOverlay mLauncherOverlay; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 226 | InsettableFrameLayout mLauncherOverlayContainer; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 227 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 228 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 229 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 230 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 231 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 232 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 233 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 234 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 235 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 236 | // 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] | 237 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 238 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 239 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 240 | private static final int SINGLE_FRAME_DELAY = 16; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 241 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 242 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 243 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 244 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 245 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 246 | private LayoutInflater mInflater; |
| 247 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 248 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 249 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 250 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 251 | private DragLayer mDragLayer; |
| 252 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 253 | private View mWeightWatcher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 254 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 255 | private AppWidgetManagerCompat mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 256 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 257 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 258 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 259 | private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 260 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 261 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 262 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 263 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 264 | private FolderInfo mFolderInfo; |
| 265 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 266 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 267 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 268 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 269 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 270 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 271 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 272 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 273 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 274 | private boolean mAutoAdvanceRunning = false; |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 275 | private AppWidgetHostView mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 276 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 277 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 278 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 279 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 280 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 281 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 282 | |
| 283 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 284 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 285 | private boolean mWorkspaceLoading = true; |
| 286 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 287 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 288 | private boolean mRestoring; |
| 289 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 290 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 291 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 292 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 293 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 294 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 295 | private Bundle mSavedInstanceState; |
| 296 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 297 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 298 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 299 | private boolean mUserPresent = true; |
| 300 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 301 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 302 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 303 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 304 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 305 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 306 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 307 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 308 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 309 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 310 | public static final int BUILD_LAYER = 0; |
| 311 | public static final int BUILD_AND_SET_LAYER = 1; |
| 312 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 313 | // Related to the auto-advancing of widgets |
| 314 | private final int ADVANCE_MSG = 1; |
| 315 | private final int mAdvanceInterval = 20000; |
| 316 | private final int mAdvanceStagger = 250; |
| 317 | private long mAutoAdvanceSentTime; |
| 318 | private long mAutoAdvanceTimeLeft = -1; |
| 319 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 320 | new HashMap<View, AppWidgetProviderInfo>(); |
| 321 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 322 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 323 | // match the sensor state. |
| 324 | private final int mRestoreScreenOrientationDelay = 500; |
| 325 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 326 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 327 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 328 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 329 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 330 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 331 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 332 | static Date sDateStamp = new Date(); |
| 333 | static DateFormat sDateFormat = |
| 334 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 335 | static long sRunStart = System.currentTimeMillis(); |
| 336 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 337 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 338 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 339 | // it from the context. |
| 340 | private SharedPreferences mSharedPrefs; |
| 341 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 342 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 343 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 344 | private ImageView mFolderIconImageView; |
| 345 | private Bitmap mFolderIconBitmap; |
| 346 | private Canvas mFolderIconCanvas; |
| 347 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 348 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 349 | private BubbleTextView mWaitingForResume; |
| 350 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 351 | protected static HashMap<String, CustomAppWidget> sCustomAppWidgets = |
| 352 | new HashMap<String, CustomAppWidget>(); |
| 353 | |
| 354 | private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false; |
| 355 | static { |
| 356 | if (ENABLE_CUSTOM_WIDGET_TEST) { |
| 357 | sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget()); |
| 358 | } |
| 359 | } |
| 360 | |
Chet Haase | a8f996d | 2015-02-17 12:56:04 -0800 | [diff] [blame] | 361 | // TODO: remove this field and call method directly when Launcher3 can depend on M APIs |
| 362 | private static Method sClipRevealMethod = null; |
| 363 | static { |
| 364 | Class<?> activityOptionsClass = ActivityOptions.class; |
| 365 | try { |
| 366 | sClipRevealMethod = activityOptionsClass.getDeclaredMethod("makeClipRevealAnimation", |
| 367 | View.class, int.class, int.class, int.class, int.class); |
| 368 | } catch (Exception e) { |
| 369 | // Earlier version |
| 370 | } |
| 371 | } |
| 372 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 373 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 374 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 375 | if (mWorkspace != null) { |
| 376 | mWorkspace.buildPageHardwareLayers(); |
| 377 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 378 | } |
| 379 | }; |
| 380 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 381 | private static PendingAddArguments sPendingAddItem; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 382 | |
| 383 | private static class PendingAddArguments { |
| 384 | int requestCode; |
| 385 | Intent intent; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 386 | long container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 387 | long screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 388 | int cellX; |
| 389 | int cellY; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 390 | int appWidgetId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 391 | } |
| 392 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 393 | private Stats mStats; |
| 394 | |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 395 | FocusIndicatorView mFocusHandler; |
| 396 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 397 | @Override |
| 398 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 399 | if (DEBUG_STRICT_MODE) { |
| 400 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 401 | .detectDiskReads() |
| 402 | .detectDiskWrites() |
| 403 | .detectNetwork() // or .detectAll() for all detectable problems |
| 404 | .penaltyLog() |
| 405 | .build()); |
| 406 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 407 | .detectLeakedSqlLiteObjects() |
| 408 | .detectLeakedClosableObjects() |
| 409 | .penaltyLog() |
| 410 | .penaltyDeath() |
| 411 | .build()); |
| 412 | } |
| 413 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 414 | if (mLauncherCallbacks != null) { |
| 415 | mLauncherCallbacks.preOnCreate(); |
| 416 | } |
| 417 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 418 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 419 | |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 420 | LauncherAppState.setApplicationContext(getApplicationContext()); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 421 | LauncherAppState app = LauncherAppState.getInstance(); |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 422 | LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 423 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 424 | // Lazy-initialize the dynamic grid |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 425 | DeviceProfile grid = app.initDynamicGrid(this); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 426 | |
| 427 | // 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] | 428 | mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 429 | Context.MODE_PRIVATE); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 430 | mIsSafeModeEnabled = getPackageManager().isSafeMode(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 431 | mModel = app.setLauncher(this); |
| 432 | mIconCache = app.getIconCache(); |
Winson Chung | e5467dc | 2013-10-14 17:03:04 -0700 | [diff] [blame] | 433 | mIconCache.flushInvalidIcons(grid); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 434 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 435 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 436 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 437 | mStats = new Stats(this); |
| 438 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 439 | mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 440 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 441 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 442 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 443 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 444 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 445 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 446 | // LauncherModel load. |
| 447 | mPaused = false; |
| 448 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 449 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 450 | android.os.Debug.startMethodTracing( |
| 451 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 455 | setContentView(R.layout.launcher); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 456 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 457 | setupViews(); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 458 | grid.layout(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 459 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 460 | registerContentObservers(); |
| 461 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 462 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 463 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 464 | mSavedState = savedInstanceState; |
| 465 | restoreState(mSavedState); |
| 466 | |
| 467 | if (PROFILE_STARTUP) { |
| 468 | android.os.Debug.stopMethodTracing(); |
| 469 | } |
| 470 | |
| 471 | if (!mRestoring) { |
Adam Cohen | db78dc8 | 2014-06-19 14:50:51 -0700 | [diff] [blame] | 472 | if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 473 | // If the user leaves launcher, then we should just load items asynchronously when |
| 474 | // they return. |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 475 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 476 | } else { |
| 477 | // We only load the page synchronously if the user rotates (or triggers a |
| 478 | // configuration change) while launcher is in the foreground |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 479 | mModel.startLoader(true, mWorkspace.getRestorePage()); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 480 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | // For handling default keys |
| 484 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 485 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 486 | |
| 487 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 488 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 489 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 490 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 491 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 492 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 493 | if (mLauncherCallbacks != null) { |
| 494 | mLauncherCallbacks.onCreate(savedInstanceState); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 495 | if (mLauncherCallbacks.hasLauncherOverlay()) { |
| 496 | ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub); |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 497 | mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate(); |
| 498 | mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView( |
| 499 | mLauncherOverlayContainer, mLauncherOverlayCallbacks); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 500 | mWorkspace.setLauncherOverlay(mLauncherOverlay); |
| 501 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 502 | } |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 503 | |
| 504 | if (shouldShowIntroScreen()) { |
| 505 | showIntroScreen(); |
| 506 | } else { |
| 507 | showFirstRunActivity(); |
| 508 | showFirstRunClings(); |
| 509 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | private LauncherCallbacks mLauncherCallbacks; |
| 513 | |
| 514 | public void onPostCreate(Bundle savedInstanceState) { |
| 515 | super.onPostCreate(savedInstanceState); |
| 516 | if (mLauncherCallbacks != null) { |
| 517 | mLauncherCallbacks.onPostCreate(savedInstanceState); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { |
| 522 | mLauncherCallbacks = callbacks; |
| 523 | return true; |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 526 | @Override |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 527 | public void onLauncherProviderChange() { |
| 528 | if (mLauncherCallbacks != null) { |
| 529 | mLauncherCallbacks.onLauncherProviderChange(); |
| 530 | } |
| 531 | } |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 532 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 533 | /** 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] | 534 | protected boolean hasCustomContentToLeft() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 535 | if (mLauncherCallbacks != null) { |
| 536 | return mLauncherCallbacks.hasCustomContentToLeft(); |
| 537 | } |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 538 | return false; |
| 539 | } |
| 540 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 541 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 542 | * 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] | 543 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 544 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 545 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 546 | protected void populateCustomContentContainer() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 547 | if (mLauncherCallbacks != null) { |
| 548 | mLauncherCallbacks.populateCustomContentContainer(); |
| 549 | } |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 554 | * ensure the custom content page is added or removed if necessary. |
| 555 | */ |
| 556 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 557 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 558 | // Not bound yet, wait for bindScreens to be called. |
| 559 | return; |
| 560 | } |
| 561 | |
| 562 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 563 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 564 | mWorkspace.createCustomContentContainer(); |
| 565 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 566 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 567 | mWorkspace.removeCustomContentPage(); |
| 568 | } |
| 569 | } |
| 570 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 571 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 572 | if (sLocaleConfiguration == null) { |
| 573 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 574 | @Override |
| 575 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 576 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 577 | readConfiguration(Launcher.this, localeConfiguration); |
| 578 | return localeConfiguration; |
| 579 | } |
| 580 | |
| 581 | @Override |
| 582 | protected void onPostExecute(LocaleConfiguration result) { |
| 583 | sLocaleConfiguration = result; |
| 584 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 585 | } |
| 586 | }.execute(); |
| 587 | return; |
| 588 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 589 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 590 | final Configuration configuration = getResources().getConfiguration(); |
| 591 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 592 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 593 | final String locale = configuration.locale.toString(); |
| 594 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 595 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 596 | final int mcc = configuration.mcc; |
| 597 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 598 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 599 | final int mnc = configuration.mnc; |
| 600 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 601 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 602 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 603 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 604 | sLocaleConfiguration.locale = locale; |
| 605 | sLocaleConfiguration.mcc = mcc; |
| 606 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 607 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 608 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 609 | |
| 610 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 611 | new AsyncTask<Void, Void, Void>() { |
| 612 | public Void doInBackground(Void ... args) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 613 | writeConfiguration(Launcher.this, localeConfiguration); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 614 | return null; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 615 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 616 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
| 620 | private static class LocaleConfiguration { |
| 621 | public String locale; |
| 622 | public int mcc = -1; |
| 623 | public int mnc = -1; |
| 624 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 625 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 626 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 627 | DataInputStream in = null; |
| 628 | try { |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 629 | in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 630 | configuration.locale = in.readUTF(); |
| 631 | configuration.mcc = in.readInt(); |
| 632 | configuration.mnc = in.readInt(); |
| 633 | } catch (FileNotFoundException e) { |
| 634 | // Ignore |
| 635 | } catch (IOException e) { |
| 636 | // Ignore |
| 637 | } finally { |
| 638 | if (in != null) { |
| 639 | try { |
| 640 | in.close(); |
| 641 | } catch (IOException e) { |
| 642 | // Ignore |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 649 | DataOutputStream out = null; |
| 650 | try { |
Helena Josol | 4fbbb3e | 2014-10-06 16:06:46 +0100 | [diff] [blame] | 651 | out = new DataOutputStream(context.openFileOutput( |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 652 | LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE)); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 653 | out.writeUTF(configuration.locale); |
| 654 | out.writeInt(configuration.mcc); |
| 655 | out.writeInt(configuration.mnc); |
| 656 | out.flush(); |
| 657 | } catch (FileNotFoundException e) { |
| 658 | // Ignore |
| 659 | } catch (IOException e) { |
| 660 | //noinspection ResultOfMethodCallIgnored |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 661 | context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 662 | } finally { |
| 663 | if (out != null) { |
| 664 | try { |
| 665 | out.close(); |
| 666 | } catch (IOException e) { |
| 667 | // Ignore |
| 668 | } |
| 669 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 673 | public Stats getStats() { |
| 674 | return mStats; |
| 675 | } |
| 676 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 677 | public LayoutInflater getInflater() { |
| 678 | return mInflater; |
| 679 | } |
| 680 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 681 | boolean isDraggingEnabled() { |
| 682 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 683 | // that is subsequently removed from the workspace in startBinding(). |
| 684 | return !mModel.isLoadingWorkspace(); |
| 685 | } |
| 686 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 687 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 688 | public static int generateViewId() { |
Ian Parkinson | 0c2918f | 2014-10-06 14:24:31 +0100 | [diff] [blame] | 689 | if (Build.VERSION.SDK_INT >= 17) { |
| 690 | return View.generateViewId(); |
| 691 | } else { |
| 692 | // View.generateViewId() is not available. The following fallback logic is a copy |
| 693 | // of its implementation. |
| 694 | for (;;) { |
| 695 | final int result = sNextGeneratedId.get(); |
| 696 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 697 | int newValue = result + 1; |
| 698 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 699 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 700 | return result; |
| 701 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | public int getViewIdForItem(ItemInfo info) { |
| 707 | // This cast is safe given the > 2B range for int. |
| 708 | int itemId = (int) info.id; |
| 709 | if (mItemIdToViewId.containsKey(itemId)) { |
| 710 | return mItemIdToViewId.get(itemId); |
| 711 | } |
| 712 | int viewId = generateViewId(); |
| 713 | mItemIdToViewId.put(itemId, viewId); |
| 714 | return viewId; |
| 715 | } |
| 716 | |
| 717 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 718 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 719 | * a configuration step, this allows the proper animations to run after other transitions. |
| 720 | */ |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 721 | private long completeAdd(PendingAddArguments args) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 722 | long screenId = args.screenId; |
| 723 | if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 724 | // When the screen id represents an actual screen (as opposed to a rank) we make sure |
| 725 | // that the drop page actually exists. |
| 726 | screenId = ensurePendingDropLayoutExists(args.screenId); |
| 727 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 728 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 729 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 730 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 731 | completeAddShortcut(args.intent, args.container, screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 732 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 733 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 734 | case REQUEST_CREATE_APPWIDGET: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 735 | completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 736 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 737 | case REQUEST_RECONFIGURE_APPWIDGET: |
| 738 | completeRestoreAppWidget(args.appWidgetId); |
| 739 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 740 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 741 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 742 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 743 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 744 | resetAddInfo(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 745 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 748 | private void handleActivityResult( |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 749 | final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 750 | // Reset the startActivity waiting flag |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 751 | setWaitingForResult(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 752 | final int pendingAddWidgetId = mPendingAddWidgetId; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 753 | mPendingAddWidgetId = -1; |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 754 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 755 | Runnable exitSpringLoaded = new Runnable() { |
| 756 | @Override |
| 757 | public void run() { |
| 758 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 759 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 760 | } |
| 761 | }; |
| 762 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 763 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 764 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 765 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 766 | if (resultCode == RESULT_CANCELED) { |
| 767 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 768 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 769 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 770 | } else if (resultCode == RESULT_OK) { |
Sunny Goyal | e6b63a3 | 2015-01-16 16:14:29 -0800 | [diff] [blame] | 771 | addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 772 | mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 773 | } |
| 774 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 775 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 776 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
| 777 | mWorkspace.exitOverviewMode(false); |
| 778 | } |
| 779 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 780 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 781 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 782 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 783 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 784 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 785 | final boolean workspaceLocked = isWorkspaceLocked(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 786 | // We have special handling for widgets |
| 787 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 788 | final int appWidgetId; |
| 789 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 790 | : -1; |
| 791 | if (widgetId < 0) { |
| 792 | appWidgetId = pendingAddWidgetId; |
| 793 | } else { |
| 794 | appWidgetId = widgetId; |
| 795 | } |
| 796 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 797 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 798 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 799 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 800 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 801 | result = RESULT_CANCELED; |
| 802 | completeTwoStageWidgetDrop(result, appWidgetId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 803 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 804 | @Override |
| 805 | public void run() { |
| 806 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 807 | } |
| 808 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 809 | if (workspaceLocked) { |
| 810 | // No need to remove the empty screen if we're mid-binding, as the |
| 811 | // the bind will not add the empty screen. |
| 812 | mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
| 813 | } else { |
| 814 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 815 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 816 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 817 | } else { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 818 | if (!workspaceLocked) { |
Adam Cohen | 83079e4 | 2014-09-19 17:43:08 -0700 | [diff] [blame] | 819 | if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 820 | // When the screen id represents an actual screen (as opposed to a rank) |
| 821 | // we make sure that the drop page actually exists. |
| 822 | mPendingAddInfo.screenId = |
| 823 | ensurePendingDropLayoutExists(mPendingAddInfo.screenId); |
| 824 | } |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 825 | final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
| 826 | |
| 827 | dropLayout.setDropPending(true); |
| 828 | final Runnable onComplete = new Runnable() { |
| 829 | @Override |
| 830 | public void run() { |
| 831 | completeTwoStageWidgetDrop(resultCode, appWidgetId); |
| 832 | dropLayout.setDropPending(false); |
| 833 | } |
| 834 | }; |
| 835 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 836 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 837 | } else { |
| 838 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId, |
| 839 | mPendingAddInfo); |
| 840 | sPendingAddItem = args; |
| 841 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 842 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 843 | return; |
| 844 | } |
| 845 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 846 | if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) { |
| 847 | if (resultCode == RESULT_OK) { |
| 848 | // Update the widget view. |
| 849 | PendingAddArguments args = preparePendingAddArgs(requestCode, data, |
| 850 | pendingAddWidgetId, mPendingAddInfo); |
| 851 | if (workspaceLocked) { |
| 852 | sPendingAddItem = args; |
| 853 | } else { |
| 854 | completeAdd(args); |
| 855 | } |
| 856 | } |
| 857 | // Leave the widget in the pending state if the user canceled the configure. |
| 858 | return; |
| 859 | } |
| 860 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 861 | // The pattern used here is that a user PICKs a specific application, |
| 862 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 863 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 864 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 865 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Winson Chung | c7da555 | 2011-08-10 15:28:45 -0700 | [diff] [blame] | 866 | if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 867 | final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1, |
| 868 | mPendingAddInfo); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 869 | if (isWorkspaceLocked()) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 870 | sPendingAddItem = args; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 871 | } else { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 872 | completeAdd(args); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 873 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
| 874 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 875 | } |
Adam Cohen | 0007472 | 2013-10-11 17:46:09 -0700 | [diff] [blame] | 876 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 877 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 878 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 879 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 880 | mDragLayer.clearAnimatedView(); |
Adam Cohen | c7cd2cb | 2014-11-17 17:45:34 -0800 | [diff] [blame] | 881 | |
| 882 | } |
| 883 | |
| 884 | @Override |
| 885 | protected void onActivityResult( |
| 886 | final int requestCode, final int resultCode, final Intent data) { |
| 887 | handleActivityResult(requestCode, resultCode, data); |
| 888 | if (mLauncherCallbacks != null) { |
| 889 | mLauncherCallbacks.onActivityResult(requestCode, resultCode, data); |
| 890 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 891 | } |
| 892 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 893 | private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int |
| 894 | appWidgetId, ItemInfo info) { |
| 895 | PendingAddArguments args = new PendingAddArguments(); |
| 896 | args.requestCode = requestCode; |
| 897 | args.intent = data; |
| 898 | args.container = info.container; |
| 899 | args.screenId = info.screenId; |
| 900 | args.cellX = info.cellX; |
| 901 | args.cellY = info.cellY; |
| 902 | args.appWidgetId = appWidgetId; |
| 903 | return args; |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 908 | * |
| 909 | * @param screenId the screen id to check |
| 910 | * @return the new screen, or screenId if it exists |
| 911 | */ |
| 912 | private long ensurePendingDropLayoutExists(long screenId) { |
| 913 | CellLayout dropLayout = |
| 914 | (CellLayout) mWorkspace.getScreenWithId(screenId); |
| 915 | if (dropLayout == null) { |
| 916 | // it's possible that the add screen was removed because it was |
| 917 | // empty and a re-bind occurred |
| 918 | mWorkspace.addExtraEmptyScreen(); |
| 919 | return mWorkspace.commitExtraEmptyScreen(); |
| 920 | } else { |
| 921 | return screenId; |
| 922 | } |
| 923 | } |
| 924 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 925 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 926 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 927 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 928 | Runnable onCompleteRunnable = null; |
| 929 | int animationType = 0; |
| 930 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 931 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 932 | if (resultCode == RESULT_OK) { |
| 933 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 934 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 935 | mPendingAddWidgetInfo); |
| 936 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 937 | onCompleteRunnable = new Runnable() { |
| 938 | @Override |
| 939 | public void run() { |
| 940 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 941 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 942 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 943 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 944 | } |
| 945 | }; |
| 946 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 947 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 948 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 949 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 950 | if (mDragLayer.getAnimatedView() != null) { |
| 951 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 952 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 953 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 954 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 955 | // The animated view may be null in the case of a rotation during widget configuration |
| 956 | onCompleteRunnable.run(); |
| 957 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 961 | protected void onStop() { |
| 962 | super.onStop(); |
| 963 | FirstFrameAnimatorHelper.setIsVisible(false); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 964 | |
| 965 | if (mLauncherCallbacks != null) { |
| 966 | mLauncherCallbacks.onStop(); |
| 967 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | @Override |
| 971 | protected void onStart() { |
| 972 | super.onStart(); |
| 973 | FirstFrameAnimatorHelper.setIsVisible(true); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 974 | |
| 975 | if (mLauncherCallbacks != null) { |
| 976 | mLauncherCallbacks.onStart(); |
| 977 | } |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 981 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 982 | long startTime = 0; |
| 983 | if (DEBUG_RESUME_TIME) { |
| 984 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 985 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 986 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 987 | |
| 988 | if (mLauncherCallbacks != null) { |
| 989 | mLauncherCallbacks.preOnResume(); |
| 990 | } |
| 991 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 992 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 993 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 994 | // Restore the previous launcher state |
| 995 | if (mOnResumeState == State.WORKSPACE) { |
| 996 | showWorkspace(false); |
| 997 | } else if (mOnResumeState == State.APPS_CUSTOMIZE) { |
Winson Chung | 07e045c6 | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 998 | showAllApps(false, mAppsCustomizeContent.getContentType(), false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 999 | } |
| 1000 | mOnResumeState = State.NONE; |
| 1001 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1002 | // Background was set to gradient in onPause(), restore to black if in all apps. |
| 1003 | setWorkspaceBackground(mState == State.WORKSPACE); |
| 1004 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1005 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1006 | if (mRestoring || mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1007 | setWorkspaceLoading(true); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 1008 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1009 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1010 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1011 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1012 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1013 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 1014 | // execute them here |
| 1015 | long startTimeCallbacks = 0; |
| 1016 | if (DEBUG_RESUME_TIME) { |
| 1017 | startTimeCallbacks = System.currentTimeMillis(); |
| 1018 | } |
| 1019 | |
| 1020 | if (mAppsCustomizeContent != null) { |
| 1021 | mAppsCustomizeContent.setBulkBind(true); |
| 1022 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1023 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 1024 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1025 | } |
| 1026 | if (mAppsCustomizeContent != null) { |
| 1027 | mAppsCustomizeContent.setBulkBind(false); |
| 1028 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1029 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1030 | if (DEBUG_RESUME_TIME) { |
| 1031 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 1032 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 1033 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1034 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 1035 | if (mOnResumeCallbacks.size() > 0) { |
| 1036 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 1037 | mOnResumeCallbacks.get(i).run(); |
| 1038 | } |
| 1039 | mOnResumeCallbacks.clear(); |
| 1040 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1041 | |
| 1042 | // Reset the pressed state of icons that were locked in the press state while activities |
| 1043 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1044 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1045 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1046 | mWaitingForResume.setStayPressed(false); |
| 1047 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 1048 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1049 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 1050 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 1051 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 1052 | // orientation. |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1053 | getWorkspace().reinflateWidgetsIfNecessary(); |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1054 | |
Winson Chung | 780fe59 | 2013-09-26 14:48:44 -0700 | [diff] [blame] | 1055 | // Process any items that were added while Launcher was away. |
| 1056 | InstallShortcutReceiver.disableAndFlushInstallQueue(this); |
| 1057 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1058 | if (DEBUG_RESUME_TIME) { |
| 1059 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1060 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1061 | |
| 1062 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1063 | // If we are resuming and the custom content is the current page, we call onShow(). |
| 1064 | // It is also poassible that onShow will instead be called slightly after first layout |
| 1065 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1066 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1067 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1068 | } |
| 1069 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 1070 | mWorkspace.updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1071 | mWorkspace.onResume(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1072 | |
| 1073 | PackageInstallerCompat.getInstance(this).onResume(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1074 | |
| 1075 | if (mLauncherCallbacks != null) { |
| 1076 | mLauncherCallbacks.onResume(); |
| 1077 | } |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1080 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1081 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1082 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1083 | InstallShortcutReceiver.enableInstallQueue(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1084 | PackageInstallerCompat.getInstance(this).onPause(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1085 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1086 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1087 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1088 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1089 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1090 | |
| 1091 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1092 | // debounce excess onHide calls. |
| 1093 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1094 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1095 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1096 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1097 | if (mLauncherCallbacks != null) { |
| 1098 | mLauncherCallbacks.onPause(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1099 | } |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1103 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1104 | // by a onResume or by scrolling otherwise. |
| 1105 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1106 | |
| 1107 | // Custom content is completely hidden |
| 1108 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1109 | |
| 1110 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1111 | public void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1112 | |
| 1113 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1114 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1117 | public interface LauncherOverlay { |
| 1118 | |
| 1119 | /** |
| 1120 | * Touch interaction leading to overscroll has begun |
| 1121 | */ |
| 1122 | public void onScrollInteractionBegin(); |
| 1123 | |
| 1124 | /** |
| 1125 | * Touch interaction related to overscroll has ended |
| 1126 | */ |
| 1127 | public void onScrollInteractionEnd(); |
| 1128 | |
| 1129 | /** |
| 1130 | * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost |
| 1131 | * screen (or in the case of RTL, the rightmost screen). |
| 1132 | */ |
| 1133 | public void onScrollChange(int progress, boolean rtl); |
| 1134 | |
| 1135 | /** |
| 1136 | * Screen has stopped scrolling |
| 1137 | */ |
| 1138 | public void onScrollSettled(); |
| 1139 | |
| 1140 | /** |
| 1141 | * This method can be called by the Launcher in order to force the LauncherOverlay |
| 1142 | * to exit fully immersive mode. |
| 1143 | */ |
| 1144 | public void forceExitFullImmersion(); |
| 1145 | } |
| 1146 | |
| 1147 | public interface LauncherOverlayCallbacks { |
| 1148 | /** |
| 1149 | * This method indicates whether a call to {@link #enterFullImmersion()} will succeed, |
| 1150 | * however it doesn't modify any state within the launcher. |
| 1151 | */ |
| 1152 | public boolean canEnterFullImmersion(); |
| 1153 | |
| 1154 | /** |
| 1155 | * Should be called to tell Launcher that the LauncherOverlay will take over interaction, |
| 1156 | * eg. by occupying the full screen and handling all touch events. |
| 1157 | * |
| 1158 | * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this |
| 1159 | * case, Launcher will modify any necessary state and assumes the overlay is |
| 1160 | * handling all interaction. If false, the LauncherOverlay should cancel any |
| 1161 | * |
| 1162 | */ |
| 1163 | public boolean enterFullImmersion(); |
| 1164 | |
| 1165 | /** |
| 1166 | * Must be called when exiting fully immersive mode. Indicates to Launcher that it has |
| 1167 | * full control over UI and state. |
| 1168 | */ |
| 1169 | public void exitFullImmersion(); |
| 1170 | } |
| 1171 | |
| 1172 | class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks { |
| 1173 | |
| 1174 | @Override |
| 1175 | public boolean canEnterFullImmersion() { |
| 1176 | return mState == State.WORKSPACE; |
| 1177 | } |
| 1178 | |
| 1179 | @Override |
| 1180 | public boolean enterFullImmersion() { |
| 1181 | if (mState == State.WORKSPACE) { |
| 1182 | // When fully immersed, disregard any touches which fall through. |
| 1183 | mDragLayer.setBlockTouch(true); |
| 1184 | return true; |
| 1185 | } |
| 1186 | return false; |
| 1187 | } |
| 1188 | |
| 1189 | @Override |
| 1190 | public void exitFullImmersion() { |
| 1191 | mDragLayer.setBlockTouch(false); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1195 | protected boolean hasSettings() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1196 | if (mLauncherCallbacks != null) { |
| 1197 | return mLauncherCallbacks.hasSettings(); |
| 1198 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1199 | return false; |
| 1200 | } |
| 1201 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1202 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1203 | public void addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1204 | CustomContentCallbacks callbacks, String description) { |
| 1205 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1208 | // The custom content needs to offset its content to account for the QSB |
| 1209 | public int getTopOffsetForCustomContent() { |
| 1210 | return mWorkspace.getPaddingTop(); |
| 1211 | } |
| 1212 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1213 | @Override |
| 1214 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1215 | // Flag the loader to stop early before switching |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 1216 | if (mModel.isCurrentCallbacks(this)) { |
| 1217 | mModel.stopLoader(); |
| 1218 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1219 | if (mAppsCustomizeContent != null) { |
| 1220 | mAppsCustomizeContent.surrender(); |
| 1221 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1222 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1223 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1224 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1225 | // 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] | 1226 | @Override |
| 1227 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1228 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1229 | mHasFocus = hasFocus; |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1230 | |
| 1231 | if (mLauncherCallbacks != null) { |
| 1232 | mLauncherCallbacks.onWindowFocusChanged(hasFocus); |
| 1233 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1234 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1235 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1236 | private boolean acceptFilter() { |
| 1237 | final InputMethodManager inputManager = (InputMethodManager) |
| 1238 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1239 | return !inputManager.isFullscreenMode(); |
| 1240 | } |
| 1241 | |
| 1242 | @Override |
| 1243 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1244 | final int uniChar = event.getUnicodeChar(); |
| 1245 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1246 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1247 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1248 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1249 | keyCode, event); |
| 1250 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1251 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1252 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1253 | // showSearchDialog() |
| 1254 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1255 | // onSearchRequested() will be called for every keystroke, |
| 1256 | // but it is idempotent, so it's fine. |
| 1257 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1258 | } |
| 1259 | } |
| 1260 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1261 | // Eat the long press event so the keyboard doesn't come up. |
| 1262 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1263 | return true; |
| 1264 | } |
| 1265 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1266 | return handled; |
| 1267 | } |
| 1268 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1269 | private String getTypedText() { |
| 1270 | return mDefaultKeySsb.toString(); |
| 1271 | } |
| 1272 | |
| 1273 | private void clearTypedText() { |
| 1274 | mDefaultKeySsb.clear(); |
| 1275 | mDefaultKeySsb.clearSpans(); |
| 1276 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1277 | } |
| 1278 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1279 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1280 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1281 | * State |
| 1282 | */ |
| 1283 | private static State intToState(int stateOrdinal) { |
| 1284 | State state = State.WORKSPACE; |
| 1285 | final State[] stateValues = State.values(); |
| 1286 | for (int i = 0; i < stateValues.length; i++) { |
| 1287 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1288 | state = stateValues[i]; |
| 1289 | break; |
| 1290 | } |
| 1291 | } |
| 1292 | return state; |
| 1293 | } |
| 1294 | |
| 1295 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1296 | * Restores the previous state, if it exists. |
| 1297 | * |
| 1298 | * @param savedState The previous state. |
| 1299 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1300 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1301 | private void restoreState(Bundle savedState) { |
| 1302 | if (savedState == null) { |
| 1303 | return; |
| 1304 | } |
| 1305 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1306 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1307 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1308 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1311 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1312 | PagedView.INVALID_RESTORE_PAGE); |
| 1313 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1314 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1315 | } |
| 1316 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1317 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1318 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1319 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1320 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1321 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1322 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1323 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1324 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1325 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1326 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 1327 | mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1328 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1329 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1330 | mRestoring = true; |
| 1331 | } |
| 1332 | |
| 1333 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1334 | if (renameFolder) { |
| 1335 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1336 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1337 | mRestoring = true; |
| 1338 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1339 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1340 | // Restore the AppsCustomize tab |
| 1341 | if (mAppsCustomizeTabHost != null) { |
| 1342 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1343 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1344 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1345 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1346 | mAppsCustomizeContent.loadAssociatedPages( |
| 1347 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1350 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1351 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1352 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1353 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1354 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * Finds all the views we need and configure them properly. |
| 1359 | */ |
| 1360 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1361 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1362 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1363 | mLauncherView = findViewById(R.id.launcher); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1364 | mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1365 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1366 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1367 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1368 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1369 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1370 | mLauncherView.setSystemUiVisibility( |
| 1371 | 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] | 1372 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1373 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1374 | // Setup the drag layer |
| 1375 | mDragLayer.setup(this, dragController); |
| 1376 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1377 | // Setup the hotseat |
| 1378 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1379 | if (mHotseat != null) { |
| 1380 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1381 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1384 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1385 | View widgetButton = findViewById(R.id.widget_button); |
| 1386 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1387 | @Override |
| 1388 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1389 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1390 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1391 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1392 | } |
| 1393 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1394 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1395 | |
| 1396 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1397 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1398 | @Override |
| 1399 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1400 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1401 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1402 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1403 | } |
| 1404 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1405 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1406 | |
| 1407 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1408 | if (hasSettings()) { |
| 1409 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1410 | @Override |
| 1411 | public void onClick(View arg0) { |
| 1412 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1413 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1414 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1415 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1416 | }); |
| 1417 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1418 | } else { |
| 1419 | settingsButton.setVisibility(View.GONE); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1420 | } |
| 1421 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1422 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1423 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1424 | // Setup the workspace |
| 1425 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1426 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1427 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1428 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1429 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1430 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1431 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1432 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1433 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1434 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1435 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1436 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1437 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1438 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1439 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1440 | // 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] | 1441 | dragController.setDragScoller(mWorkspace); |
| 1442 | dragController.setScrollView(mDragLayer); |
| 1443 | dragController.setMoveTarget(mWorkspace); |
| 1444 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1445 | if (mSearchDropTargetBar != null) { |
| 1446 | mSearchDropTargetBar.setup(this, dragController); |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 1447 | mSearchDropTargetBar.setQsbSearchBar(getQsbBar()); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1448 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1449 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1450 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1451 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1452 | mWeightWatcher = new WeightWatcher(this); |
| 1453 | mWeightWatcher.setAlpha(0.5f); |
| 1454 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1455 | new FrameLayout.LayoutParams( |
| 1456 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1457 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1458 | Gravity.BOTTOM) |
| 1459 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1460 | |
| 1461 | boolean show = shouldShowWeightWatcher(); |
| 1462 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1463 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1467 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1468 | */ |
| 1469 | public void setAllAppsButton(View allAppsButton) { |
| 1470 | mAllAppsButton = allAppsButton; |
| 1471 | } |
| 1472 | |
| 1473 | public View getAllAppsButton() { |
| 1474 | return mAllAppsButton; |
| 1475 | } |
| 1476 | |
| 1477 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1478 | * Creates a view representing a shortcut. |
| 1479 | * |
| 1480 | * @param info The data structure describing the shortcut. |
| 1481 | * |
| 1482 | * @return A View inflated from R.layout.application. |
| 1483 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1484 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1485 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1486 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /** |
| 1490 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1491 | * |
| 1492 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1493 | * @param parent The group the shortcut belongs to. |
| 1494 | * @param info The data structure describing the shortcut. |
| 1495 | * |
| 1496 | * @return A View inflated from layoutResId. |
| 1497 | */ |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1498 | public View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1499 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 1500 | favorite.applyFromShortcutInfo(info, mIconCache, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1501 | favorite.setOnClickListener(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1502 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1503 | return favorite; |
| 1504 | } |
| 1505 | |
| 1506 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1507 | * Add a shortcut to the workspace. |
| 1508 | * |
| 1509 | * @param data The intent describing the shortcut. |
| 1510 | * @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] | 1511 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1512 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1513 | int cellY) { |
| 1514 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1515 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1516 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1517 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1518 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1519 | |
Sunny Goyal | 2350bc9 | 2014-10-14 16:42:54 -0700 | [diff] [blame] | 1520 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1521 | if (info == null) { |
| 1522 | return; |
| 1523 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1524 | final View view = createShortcut(info); |
| 1525 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1526 | // First we check if we already know the exact location where we want to add this item. |
| 1527 | if (cellX >= 0 && cellY >= 0) { |
| 1528 | cellXY[0] = cellX; |
| 1529 | cellXY[1] = cellY; |
| 1530 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1531 | |
| 1532 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1533 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1534 | true, null,null)) { |
| 1535 | return; |
| 1536 | } |
| 1537 | DragObject dragObject = new DragObject(); |
| 1538 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1539 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1540 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1541 | return; |
| 1542 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1543 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1544 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1545 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1546 | foundCellSpan = (result != null); |
| 1547 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1548 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1552 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1553 | return; |
| 1554 | } |
| 1555 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1556 | 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] | 1557 | |
| 1558 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1559 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1560 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1564 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1565 | int minHeight) { |
| 1566 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1567 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1568 | // to ensure that it gets the full amount of space that it has requested |
| 1569 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1570 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1571 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1574 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1575 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1578 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1579 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1582 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1583 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1586 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1587 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1588 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1589 | } |
| 1590 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1591 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1592 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1593 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1594 | * @param appWidgetId The app widget id |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1595 | */ |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1596 | private void completeAddAppWidget(int appWidgetId, long container, long screenId, |
| 1597 | AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) { |
| 1598 | |
| 1599 | ItemInfo info = mPendingAddInfo; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1600 | if (appWidgetInfo == null) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1601 | appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this, |
| 1602 | mAppWidgetManager.getAppWidgetInfo(appWidgetId)); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1603 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1604 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1605 | if (appWidgetInfo.isCustomWidget) { |
| 1606 | appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1609 | LauncherAppWidgetInfo launcherInfo; |
| 1610 | launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider); |
| 1611 | launcherInfo.spanX = info.spanX; |
| 1612 | launcherInfo.spanY = info.spanY; |
| 1613 | launcherInfo.minSpanX = info.minSpanX; |
| 1614 | launcherInfo.minSpanY = info.minSpanY; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1615 | launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1616 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1617 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1618 | container, screenId, info.cellX, info.cellY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1619 | |
| 1620 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1621 | if (hostView == null) { |
| 1622 | // Perform actual inflation because we're live |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1623 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, |
| 1624 | appWidgetInfo); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1625 | } else { |
| 1626 | // The AppWidgetHostView has already been inflated and instantiated |
| 1627 | launcherInfo.hostView = hostView; |
| 1628 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1629 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1630 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1631 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1632 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1633 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX, |
| 1634 | info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1635 | |
| 1636 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1637 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1638 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1639 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1640 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1641 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1642 | @Override |
| 1643 | public void onReceive(Context context, Intent intent) { |
| 1644 | final String action = intent.getAction(); |
| 1645 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1646 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1647 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1648 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1649 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1650 | // 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] | 1651 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1652 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1653 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1654 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1655 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1656 | mUserPresent = true; |
| 1657 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1658 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1659 | mModel.resetLoadedState(false, true); |
| 1660 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1661 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1662 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1663 | mModel.resetLoadedState(false, true); |
| 1664 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1665 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1666 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1667 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1668 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1669 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | }; |
| 1673 | |
| 1674 | @Override |
| 1675 | public void onAttachedToWindow() { |
| 1676 | super.onAttachedToWindow(); |
| 1677 | |
| 1678 | // Listen for broadcasts related to user-presence |
| 1679 | final IntentFilter filter = new IntentFilter(); |
| 1680 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1681 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1682 | // For handling managed profiles |
| 1683 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1684 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1685 | if (ENABLE_DEBUG_INTENTS) { |
| 1686 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1687 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1688 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1689 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1690 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1691 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1692 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1693 | mVisible = true; |
| 1694 | } |
| 1695 | |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1696 | /** |
| 1697 | * Sets up transparent navigation and status bars in LMP. |
| 1698 | * This method is a no-op for other platform versions. |
| 1699 | */ |
Sunny Goyal | d009101 | 2015-01-20 15:55:34 -0800 | [diff] [blame] | 1700 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1701 | private void setupTransparentSystemBarsForLmp() { |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 1702 | if (Utilities.isLmpOrAbove()) { |
Sunny Goyal | d009101 | 2015-01-20 15:55:34 -0800 | [diff] [blame] | 1703 | Window window = getWindow(); |
| 1704 | window.getAttributes().systemUiVisibility |= |
| 1705 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1706 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1707 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1708 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
| 1709 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
| 1710 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
| 1711 | window.setStatusBarColor(Color.TRANSPARENT); |
| 1712 | window.setNavigationBarColor(Color.TRANSPARENT); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1713 | } |
| 1714 | } |
| 1715 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1716 | @Override |
| 1717 | public void onDetachedFromWindow() { |
| 1718 | super.onDetachedFromWindow(); |
| 1719 | mVisible = false; |
| 1720 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1721 | if (mAttached) { |
| 1722 | unregisterReceiver(mReceiver); |
| 1723 | mAttached = false; |
| 1724 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1725 | updateRunning(); |
| 1726 | } |
| 1727 | |
| 1728 | public void onWindowVisibilityChanged(int visibility) { |
| 1729 | mVisible = visibility == View.VISIBLE; |
| 1730 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1731 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1732 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1733 | // is a more appropriate event to handle |
| 1734 | if (mVisible) { |
| 1735 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1736 | if (!mWorkspaceLoading) { |
| 1737 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1738 | // We want to let Launcher draw itself at least once before we force it to build |
| 1739 | // 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] | 1740 | // apps is nice and speedy. |
| 1741 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1742 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1743 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1744 | if (mStarted) return; |
| 1745 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1746 | // We delay the layer building a bit in order to give |
| 1747 | // other message processing a time to run. In particular |
| 1748 | // this avoids a delay in hiding the IME if it was |
| 1749 | // currently shown, because doing that may involve |
| 1750 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1751 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1752 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1753 | mWorkspace.post(new Runnable() { |
| 1754 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1755 | if (mWorkspace != null && |
| 1756 | mWorkspace.getViewTreeObserver() != null) { |
| 1757 | mWorkspace.getViewTreeObserver(). |
| 1758 | removeOnDrawListener(listener); |
| 1759 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1760 | } |
| 1761 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1762 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1763 | } |
| 1764 | }); |
| 1765 | } |
| 1766 | clearTypedText(); |
| 1767 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | private void sendAdvanceMessage(long delay) { |
| 1771 | mHandler.removeMessages(ADVANCE_MSG); |
| 1772 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1773 | mHandler.sendMessageDelayed(msg, delay); |
| 1774 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1775 | } |
| 1776 | |
| 1777 | private void updateRunning() { |
| 1778 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1779 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1780 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1781 | if (autoAdvanceRunning) { |
| 1782 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1783 | sendAdvanceMessage(delay); |
| 1784 | } else { |
| 1785 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1786 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1787 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1788 | } |
| 1789 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1790 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | private final Handler mHandler = new Handler() { |
| 1796 | @Override |
| 1797 | public void handleMessage(Message msg) { |
| 1798 | if (msg.what == ADVANCE_MSG) { |
| 1799 | int i = 0; |
| 1800 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1801 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1802 | final int delay = mAdvanceStagger * i; |
| 1803 | if (v instanceof Advanceable) { |
| 1804 | postDelayed(new Runnable() { |
| 1805 | public void run() { |
| 1806 | ((Advanceable) v).advance(); |
| 1807 | } |
| 1808 | }, delay); |
| 1809 | } |
| 1810 | i++; |
| 1811 | } |
| 1812 | sendAdvanceMessage(mAdvanceInterval); |
| 1813 | } |
| 1814 | } |
| 1815 | }; |
| 1816 | |
| 1817 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1818 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1819 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1820 | if (v instanceof Advanceable) { |
| 1821 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1822 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1823 | updateRunning(); |
| 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | void removeWidgetToAutoAdvance(View hostView) { |
| 1828 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1829 | mWidgetsToAdvance.remove(hostView); |
| 1830 | updateRunning(); |
| 1831 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1834 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1835 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1836 | launcherInfo.hostView = null; |
| 1837 | } |
| 1838 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1839 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1840 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1841 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 1844 | public ArrayList<AppInfo> getAllAppsList() { |
| 1845 | return mAppsCustomizeContent.getApps(); |
| 1846 | } |
| 1847 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1848 | public DragLayer getDragLayer() { |
| 1849 | return mDragLayer; |
| 1850 | } |
| 1851 | |
| 1852 | public Workspace getWorkspace() { |
| 1853 | return mWorkspace; |
| 1854 | } |
| 1855 | |
| 1856 | public Hotseat getHotseat() { |
| 1857 | return mHotseat; |
| 1858 | } |
| 1859 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1860 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1861 | return mOverviewPanel; |
| 1862 | } |
| 1863 | |
| 1864 | public SearchDropTargetBar getSearchBar() { |
| 1865 | return mSearchDropTargetBar; |
| 1866 | } |
| 1867 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1868 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1869 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1870 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1871 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1872 | public LauncherModel getModel() { |
| 1873 | return mModel; |
| 1874 | } |
| 1875 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1876 | protected SharedPreferences getSharedPrefs() { |
| 1877 | return mSharedPrefs; |
| 1878 | } |
| 1879 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1880 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1881 | getWindow().closeAllPanels(); |
| 1882 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1883 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1884 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1885 | } |
| 1886 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1887 | @Override |
| 1888 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1889 | long startTime = 0; |
| 1890 | if (DEBUG_RESUME_TIME) { |
| 1891 | startTime = System.currentTimeMillis(); |
| 1892 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1893 | super.onNewIntent(intent); |
| 1894 | |
| 1895 | // Close the menu |
| 1896 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1897 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1898 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1899 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1900 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1901 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1902 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1903 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1904 | if (mWorkspace == null) { |
| 1905 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1906 | return; |
| 1907 | } |
| 1908 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1909 | // In all these cases, only animate if we're already on home |
| 1910 | mWorkspace.exitWidgetResizeMode(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1911 | |
| 1912 | boolean moveToDefaultScreen = mLauncherCallbacks != null ? |
| 1913 | mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true; |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1914 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1915 | openFolder == null && moveToDefaultScreen) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1916 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1917 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1918 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1919 | closeFolder(); |
| 1920 | exitSpringLoadedDragMode(); |
| 1921 | |
| 1922 | // If we are already on home, then just animate back to the workspace, |
| 1923 | // otherwise, just wait until onResume to set the state back to Workspace |
| 1924 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1925 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1926 | } else { |
| 1927 | mOnResumeState = State.WORKSPACE; |
| 1928 | } |
| 1929 | |
| 1930 | final View v = getWindow().peekDecorView(); |
| 1931 | if (v != null && v.getWindowToken() != null) { |
| 1932 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1933 | INPUT_METHOD_SERVICE); |
| 1934 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 1935 | } |
| 1936 | |
| 1937 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 1938 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1939 | mAppsCustomizeTabHost.reset(); |
| 1940 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1941 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1942 | if (mLauncherCallbacks != null) { |
| 1943 | mLauncherCallbacks.onHomeIntent(); |
| 1944 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1945 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1946 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1947 | if (DEBUG_RESUME_TIME) { |
| 1948 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 1949 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1950 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 1951 | if (mLauncherCallbacks != null) { |
| 1952 | mLauncherCallbacks.onNewIntent(intent); |
| 1953 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1956 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1957 | public void onRestoreInstanceState(Bundle state) { |
| 1958 | super.onRestoreInstanceState(state); |
| 1959 | for (int page: mSynchronouslyBoundPages) { |
| 1960 | mWorkspace.restoreInstanceStateForChild(page); |
| 1961 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | @Override |
| 1965 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1966 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 1967 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1968 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1969 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1970 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1971 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1972 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 1973 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 1974 | // this state is reflected. |
| 1975 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1976 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1977 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1978 | mWaitingForResult) { |
| 1979 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1980 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1981 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 1982 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1983 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 1984 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 1985 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1986 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | if (mFolderInfo != null && mWaitingForResult) { |
| 1990 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1991 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1992 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1993 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1994 | // Save the current AppsCustomize tab |
| 1995 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c6 | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 1996 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 1997 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1998 | if (currentTabTag != null) { |
| 1999 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 2000 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 2001 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 2002 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2003 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 2004 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2005 | |
| 2006 | if (mLauncherCallbacks != null) { |
| 2007 | mLauncherCallbacks.onSaveInstanceState(outState); |
| 2008 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | @Override |
| 2012 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2013 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2014 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2015 | // Remove all pending runnables |
| 2016 | mHandler.removeMessages(ADVANCE_MSG); |
| 2017 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 2018 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2019 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2020 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 2021 | LauncherAppState app = (LauncherAppState.getInstance()); |
Adam Cohen | 1a85c58 | 2014-09-30 09:48:49 -0700 | [diff] [blame] | 2022 | |
| 2023 | // It's possible to receive onDestroy after a new Launcher activity has |
| 2024 | // been created. In this case, don't interfere with the new Launcher. |
| 2025 | if (mModel.isCurrentCallbacks(this)) { |
| 2026 | mModel.stopLoader(); |
| 2027 | app.setLauncher(null); |
| 2028 | } |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 2029 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2030 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2031 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2032 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2033 | 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] | 2034 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2035 | mAppWidgetHost = null; |
| 2036 | |
| 2037 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2038 | |
| 2039 | TextKeyListener.getInstance().release(); |
| 2040 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 2041 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 2042 | // to prevent leaking Launcher activities on orientation change. |
| 2043 | if (mModel != null) { |
| 2044 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 2045 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2046 | |
| 2047 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2048 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2049 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 2050 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2051 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 2052 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2053 | mWorkspace = null; |
| 2054 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 2055 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2056 | LauncherAnimUtils.onDestroyActivity(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2057 | |
| 2058 | if (mLauncherCallbacks != null) { |
| 2059 | mLauncherCallbacks.onDestroy(); |
| 2060 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2061 | } |
| 2062 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2063 | public DragController getDragController() { |
| 2064 | return mDragController; |
| 2065 | } |
| 2066 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2067 | @Override |
| 2068 | public void startActivityForResult(Intent intent, int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2069 | if (requestCode >= 0) { |
| 2070 | setWaitingForResult(true); |
| 2071 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2072 | super.startActivityForResult(intent, requestCode); |
| 2073 | } |
| 2074 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2075 | /** |
| 2076 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2077 | * argument for {@link #startSearch} to true. |
| 2078 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2079 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2080 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2081 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2082 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2083 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2084 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2085 | if (initialQuery == null) { |
| 2086 | // Use any text typed in the launcher as the initial query |
| 2087 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2088 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2089 | if (appSearchData == null) { |
| 2090 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2091 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2092 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2093 | Rect sourceBounds = new Rect(); |
| 2094 | if (mSearchDropTargetBar != null) { |
| 2095 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2096 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2097 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2098 | boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2099 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2100 | if (clearTextImmediately) { |
| 2101 | clearTypedText(); |
| 2102 | } |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2103 | } |
| 2104 | |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2105 | /** |
| 2106 | * Start a text search. |
| 2107 | * |
| 2108 | * @return {@code true} if the search will start immediately, so any further keypresses |
| 2109 | * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue |
| 2110 | * to buffer keypresses. |
| 2111 | */ |
| 2112 | public boolean startSearch(String initialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2113 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2114 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 2115 | return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData, |
| 2116 | sourceBounds); |
| 2117 | } |
| 2118 | |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2119 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2120 | appSearchData, sourceBounds); |
Ian Parkinson | 047036e | 2014-09-01 15:40:53 +0100 | [diff] [blame] | 2121 | return false; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | /** |
| 2125 | * Starts the global search activity. This code is a copied from SearchManager |
| 2126 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2127 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2128 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2129 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2130 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2131 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2132 | if (globalSearchActivity == null) { |
| 2133 | Log.w(TAG, "No global search activity found."); |
| 2134 | return; |
| 2135 | } |
| 2136 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2137 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2138 | intent.setComponent(globalSearchActivity); |
| 2139 | // Make sure that we have a Bundle to put source in |
| 2140 | if (appSearchData == null) { |
| 2141 | appSearchData = new Bundle(); |
| 2142 | } else { |
| 2143 | appSearchData = new Bundle(appSearchData); |
| 2144 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2145 | // 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] | 2146 | if (!appSearchData.containsKey("source")) { |
| 2147 | appSearchData.putString("source", getPackageName()); |
| 2148 | } |
| 2149 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2150 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2151 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2152 | } |
| 2153 | if (selectInitialQuery) { |
| 2154 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2155 | } |
| 2156 | intent.setSourceBounds(sourceBounds); |
| 2157 | try { |
| 2158 | startActivity(intent); |
| 2159 | } catch (ActivityNotFoundException ex) { |
| 2160 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2161 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2162 | } |
| 2163 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2164 | public boolean isOnCustomContent() { |
| 2165 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2166 | } |
| 2167 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2168 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2169 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2170 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2171 | if (!isOnCustomContent()) { |
| 2172 | // Close any open folders |
| 2173 | closeFolder(); |
| 2174 | // Stop resizing any widgets |
| 2175 | mWorkspace.exitWidgetResizeMode(); |
| 2176 | if (!mWorkspace.isInOverviewMode()) { |
| 2177 | // Show the overview mode |
| 2178 | showOverviewMode(true); |
| 2179 | } else { |
| 2180 | showWorkspace(true); |
| 2181 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2182 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2183 | if (mLauncherCallbacks != null) { |
| 2184 | return mLauncherCallbacks.onPrepareOptionsMenu(menu); |
| 2185 | } |
| 2186 | |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2187 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2188 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2189 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2190 | @Override |
| 2191 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2192 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2193 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2194 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2197 | public boolean isWorkspaceLocked() { |
| 2198 | return mWorkspaceLoading || mWaitingForResult; |
| 2199 | } |
| 2200 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2201 | public boolean isWorkspaceLoading() { |
| 2202 | return mWorkspaceLoading; |
| 2203 | } |
| 2204 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2205 | private void setWorkspaceLoading(boolean value) { |
| 2206 | boolean isLocked = isWorkspaceLocked(); |
| 2207 | mWorkspaceLoading = value; |
| 2208 | if (isLocked != isWorkspaceLocked()) { |
| 2209 | onWorkspaceLockedChanged(); |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | private void setWaitingForResult(boolean value) { |
| 2214 | boolean isLocked = isWorkspaceLocked(); |
| 2215 | mWaitingForResult = value; |
| 2216 | if (isLocked != isWorkspaceLocked()) { |
| 2217 | onWorkspaceLockedChanged(); |
| 2218 | } |
| 2219 | } |
| 2220 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2221 | protected void onWorkspaceLockedChanged() { |
| 2222 | if (mLauncherCallbacks != null) { |
| 2223 | mLauncherCallbacks.onWorkspaceLockedChanged(); |
| 2224 | } |
| 2225 | } |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2226 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2227 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2228 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2229 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2230 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2231 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2232 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2233 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2234 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2235 | |
Sunny Goyal | e6b63a3 | 2015-01-16 16:14:29 -0800 | [diff] [blame] | 2236 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, final |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2237 | AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2238 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2239 | } |
| 2240 | |
Sunny Goyal | e6b63a3 | 2015-01-16 16:14:29 -0800 | [diff] [blame] | 2241 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2242 | final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo, |
| 2243 | int delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2244 | if (appWidgetInfo.configure != null) { |
| 2245 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2246 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2247 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2248 | // Launch over to configure widget, if needed |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2249 | mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this, |
| 2250 | mAppWidgetHost, REQUEST_CREATE_APPWIDGET); |
| 2251 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2252 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2253 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2254 | Runnable onComplete = new Runnable() { |
| 2255 | @Override |
| 2256 | public void run() { |
| 2257 | // Exit spring loaded mode if necessary after adding the widget |
| 2258 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2259 | null); |
| 2260 | } |
| 2261 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2262 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2263 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2264 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2265 | } |
| 2266 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2267 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2268 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2269 | // Close any folders that may be open. |
| 2270 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2271 | mWorkspace.moveToCustomContentScreen(animate); |
| 2272 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2273 | |
| 2274 | public void addPendingItem(PendingAddItemInfo info, long container, long screenId, |
| 2275 | int[] cell, int spanX, int spanY) { |
| 2276 | switch (info.itemType) { |
| 2277 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: |
| 2278 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
| 2279 | int span[] = new int[2]; |
| 2280 | span[0] = spanX; |
| 2281 | span[1] = spanY; |
| 2282 | addAppWidgetFromDrop((PendingAddWidgetInfo) info, |
| 2283 | container, screenId, cell, span); |
| 2284 | break; |
| 2285 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 2286 | processShortcutFromDrop(info.componentName, container, screenId, cell); |
| 2287 | break; |
| 2288 | default: |
| 2289 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
| 2290 | } |
| 2291 | } |
| 2292 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2293 | /** |
| 2294 | * Process a shortcut drop. |
| 2295 | * |
| 2296 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2297 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2298 | * @param cell The cell it should be added to, optional |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2299 | */ |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2300 | private void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
| 2301 | int[] cell) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2302 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2303 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2304 | mPendingAddInfo.screenId = screenId; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2305 | mPendingAddInfo.dropPos = null; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2306 | |
| 2307 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2308 | mPendingAddInfo.cellX = cell[0]; |
| 2309 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2310 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2311 | |
| 2312 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2313 | createShortcutIntent.setComponent(componentName); |
| 2314 | processShortcut(createShortcutIntent); |
| 2315 | } |
| 2316 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2317 | /** |
| 2318 | * Process a widget drop. |
| 2319 | * |
| 2320 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2321 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2322 | * @param cell The cell it should be added to, optional |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2323 | */ |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2324 | private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
| 2325 | int[] cell, int[] span) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2326 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2327 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2328 | mPendingAddInfo.screenId = info.screenId = screenId; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 2329 | mPendingAddInfo.dropPos = null; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2330 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2331 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2332 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2333 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2334 | mPendingAddInfo.cellX = cell[0]; |
| 2335 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2336 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2337 | if (span != null) { |
| 2338 | mPendingAddInfo.spanX = span[0]; |
| 2339 | mPendingAddInfo.spanY = span[1]; |
| 2340 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2341 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2342 | AppWidgetHostView hostView = info.boundWidget; |
| 2343 | int appWidgetId; |
| 2344 | if (hostView != null) { |
| 2345 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2346 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2347 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2348 | // In this case, we either need to start an activity to get permission to bind |
| 2349 | // 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] | 2350 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2351 | Bundle options = info.bindOptions; |
| 2352 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2353 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2354 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2355 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2356 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2357 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2358 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2359 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2360 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2361 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2362 | mAppWidgetManager.getUser(mPendingAddWidgetInfo) |
| 2363 | .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2364 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2365 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2366 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2367 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2368 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2371 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2372 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2373 | } |
| 2374 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2375 | void processWallpaper(Intent intent) { |
| 2376 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2377 | } |
| 2378 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2379 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2380 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2381 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2382 | folderInfo.title = getText(R.string.folder_name); |
| 2383 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2384 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2385 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2386 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2387 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2388 | |
| 2389 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2390 | FolderIcon newFolder = |
| 2391 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2392 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2393 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2394 | // Force measure the new folder icon |
| 2395 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2396 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2397 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2398 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2399 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2400 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2401 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2402 | } |
| 2403 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2404 | protected ComponentName getWallpaperPickerComponent() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2405 | if (mLauncherCallbacks != null) { |
| 2406 | return mLauncherCallbacks.getWallpaperPickerComponent(); |
| 2407 | } |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2408 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2409 | } |
| 2410 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2411 | /** |
| 2412 | * Registers various content observers. The current implementation registers |
| 2413 | * only a favorites observer to keep track of the favorites applications. |
| 2414 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2415 | private void registerContentObservers() { |
| 2416 | ContentResolver resolver = getContentResolver(); |
| 2417 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2418 | true, mWidgetObserver); |
| 2419 | } |
| 2420 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2421 | @Override |
| 2422 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2423 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2424 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2425 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2426 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2427 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 2428 | if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2429 | dumpState(); |
| 2430 | return true; |
| 2431 | } |
| 2432 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2433 | } |
| 2434 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2435 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2436 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2437 | return true; |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | return super.dispatchKeyEvent(event); |
| 2442 | } |
| 2443 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2444 | @Override |
| 2445 | public void onBackPressed() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2446 | if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) { |
| 2447 | return; |
| 2448 | } |
| 2449 | |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2450 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2451 | if (mAppsCustomizeContent.getContentType() == |
| 2452 | AppsCustomizePagedView.ContentType.Applications) { |
| 2453 | showWorkspace(true); |
| 2454 | } else { |
| 2455 | showOverviewMode(true); |
| 2456 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2457 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2458 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2459 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2460 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2461 | if (openFolder.isEditingName()) { |
| 2462 | openFolder.dismissEditingName(); |
| 2463 | } else { |
| 2464 | closeFolder(); |
| 2465 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2466 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2467 | mWorkspace.exitWidgetResizeMode(); |
| 2468 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2469 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2470 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2471 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2472 | } |
| 2473 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2474 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2475 | * Re-listen when widgets are reset. |
| 2476 | */ |
| 2477 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2478 | if (mAppWidgetHost != null) { |
| 2479 | mAppWidgetHost.startListening(); |
| 2480 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2484 | * Launches the intent referred by the clicked shortcut. |
| 2485 | * |
| 2486 | * @param v The view representing the clicked shortcut. |
| 2487 | */ |
| 2488 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2489 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2490 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2491 | if (v.getWindowToken() == null) { |
| 2492 | return; |
| 2493 | } |
| 2494 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2495 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2496 | return; |
| 2497 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2498 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2499 | if (v instanceof Workspace) { |
| 2500 | if (mWorkspace.isInOverviewMode()) { |
| 2501 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2502 | } |
| 2503 | return; |
| 2504 | } |
| 2505 | |
| 2506 | if (v instanceof CellLayout) { |
| 2507 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2508 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2509 | } |
| 2510 | } |
| 2511 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2512 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2513 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2514 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2515 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2516 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2517 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2518 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2519 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2520 | onClickAllAppsButton(v); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2521 | } else if (tag instanceof AppInfo) { |
| 2522 | startAppShortcutOrInfoActivity(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2523 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2524 | if (v instanceof PendingAppWidgetHostView) { |
| 2525 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2526 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2527 | } |
| 2528 | } |
| 2529 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2530 | public void onClickPagedViewIcon(View v) { |
| 2531 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2532 | if (mLauncherCallbacks != null) { |
| 2533 | mLauncherCallbacks.onClickPagedViewIcon(v); |
| 2534 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2537 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2538 | return false; |
| 2539 | } |
| 2540 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2541 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2542 | * Event handler for the app widget view which has not fully restored. |
| 2543 | */ |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2544 | public void onClickPendingWidget(final PendingAppWidgetHostView v) { |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2545 | if (mIsSafeModeEnabled) { |
| 2546 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2547 | return; |
| 2548 | } |
| 2549 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2550 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2551 | if (v.isReadyForClickSetup()) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2552 | int widgetId = info.appWidgetId; |
| 2553 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
| 2554 | if (appWidgetInfo != null) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2555 | mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo( |
| 2556 | this, appWidgetInfo); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2557 | mPendingAddInfo.copyFrom(info); |
| 2558 | mPendingAddWidgetId = widgetId; |
| 2559 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2560 | AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo, |
| 2561 | info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2562 | } |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2563 | } else if (info.installProgress < 0) { |
| 2564 | // The install has not been queued |
| 2565 | final String packageName = info.providerName.getPackageName(); |
| 2566 | showBrokenAppInstallDialog(packageName, |
| 2567 | new DialogInterface.OnClickListener() { |
| 2568 | public void onClick(DialogInterface dialog, int id) { |
| 2569 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
| 2570 | } |
| 2571 | }); |
| 2572 | } else { |
| 2573 | // Download has started. |
| 2574 | final String packageName = info.providerName.getPackageName(); |
| 2575 | startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2580 | * Event handler for the "grid" button that appears on the home screen, which |
| 2581 | * enters all apps mode. |
| 2582 | * |
| 2583 | * @param v The view that was clicked. |
| 2584 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2585 | protected void onClickAllAppsButton(View v) { |
| 2586 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2587 | if (isAllAppsVisible()) { |
| 2588 | showWorkspace(true); |
| 2589 | } else { |
| 2590 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2591 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2592 | if (mLauncherCallbacks != null) { |
| 2593 | mLauncherCallbacks.onClickAllAppsButton(v); |
| 2594 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2595 | } |
| 2596 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2597 | private void showBrokenAppInstallDialog(final String packageName, |
| 2598 | DialogInterface.OnClickListener onSearchClickListener) { |
Sunny Goyal | e03b812 | 2014-10-08 09:55:24 -0700 | [diff] [blame] | 2599 | new AlertDialog.Builder(this) |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2600 | .setTitle(R.string.abandoned_promises_title) |
| 2601 | .setMessage(R.string.abandoned_promise_explanation) |
| 2602 | .setPositiveButton(R.string.abandoned_search, onSearchClickListener) |
| 2603 | .setNeutralButton(R.string.abandoned_clean_this, |
| 2604 | new DialogInterface.OnClickListener() { |
| 2605 | public void onClick(DialogInterface dialog, int id) { |
| 2606 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 2607 | mWorkspace.removeAbandonedPromise(packageName, user); |
| 2608 | } |
| 2609 | }) |
| 2610 | .create().show(); |
| 2611 | return; |
| 2612 | } |
| 2613 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2614 | /** |
| 2615 | * Event handler for an app shortcut click. |
| 2616 | * |
| 2617 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2618 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2619 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2620 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2621 | Object tag = v.getTag(); |
| 2622 | if (!(tag instanceof ShortcutInfo)) { |
| 2623 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2624 | } |
| 2625 | |
| 2626 | // Open shortcut |
| 2627 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 2628 | |
| 2629 | if (shortcut.isDisabled != 0) { |
| 2630 | int error = R.string.activity_not_available; |
| 2631 | if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) { |
| 2632 | error = R.string.safemode_shortcut_error; |
| 2633 | } |
| 2634 | Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); |
| 2635 | return; |
| 2636 | } |
| 2637 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2638 | final Intent intent = shortcut.intent; |
| 2639 | |
| 2640 | // Check for special shortcuts |
| 2641 | if (intent.getComponent() != null) { |
| 2642 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2643 | |
| 2644 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2645 | MemoryDumpActivity.startDump(this); |
| 2646 | return; |
| 2647 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2648 | toggleShowWeightWatcher(); |
| 2649 | return; |
| 2650 | } |
| 2651 | } |
| 2652 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2653 | // Check for abandoned promise |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2654 | if ((v instanceof BubbleTextView) |
| 2655 | && shortcut.isPromise() |
| 2656 | && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) { |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 2657 | showBrokenAppInstallDialog( |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 2658 | shortcut.getTargetComponent().getPackageName(), |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2659 | new DialogInterface.OnClickListener() { |
| 2660 | public void onClick(DialogInterface dialog, int id) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2661 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2662 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2663 | }); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2664 | return; |
| 2665 | } |
| 2666 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2667 | // Start activities |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2668 | startAppShortcutOrInfoActivity(v); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2669 | |
| 2670 | if (mLauncherCallbacks != null) { |
| 2671 | mLauncherCallbacks.onClickAppShortcut(v); |
| 2672 | } |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2673 | } |
| 2674 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2675 | private void startAppShortcutOrInfoActivity(View v) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2676 | Object tag = v.getTag(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2677 | final ShortcutInfo shortcut; |
| 2678 | final Intent intent; |
| 2679 | if (tag instanceof ShortcutInfo) { |
| 2680 | shortcut = (ShortcutInfo) tag; |
| 2681 | intent = shortcut.intent; |
| 2682 | int[] pos = new int[2]; |
| 2683 | v.getLocationOnScreen(pos); |
| 2684 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2685 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2686 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2687 | } else if (tag instanceof AppInfo) { |
| 2688 | shortcut = null; |
| 2689 | intent = ((AppInfo) tag).intent; |
| 2690 | } else { |
| 2691 | throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); |
| 2692 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2693 | |
| 2694 | boolean success = startActivitySafely(v, intent, tag); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2695 | mStats.recordLaunch(intent, shortcut); |
| 2696 | |
| 2697 | if (success && v instanceof BubbleTextView) { |
| 2698 | mWaitingForResume = (BubbleTextView) v; |
| 2699 | mWaitingForResume.setStayPressed(true); |
| 2700 | } |
| 2701 | } |
| 2702 | |
| 2703 | /** |
| 2704 | * Event handler for a folder icon click. |
| 2705 | * |
| 2706 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2707 | */ |
| 2708 | protected void onClickFolderIcon(View v) { |
| 2709 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2710 | if (!(v instanceof FolderIcon)){ |
| 2711 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2712 | } |
| 2713 | |
| 2714 | FolderIcon folderIcon = (FolderIcon) v; |
| 2715 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2716 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2717 | |
| 2718 | // If the folder info reports that the associated folder is open, then verify that |
| 2719 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2720 | if (info.opened && openFolder == null) { |
| 2721 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2722 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2723 | info.opened = false; |
| 2724 | } |
| 2725 | |
| 2726 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2727 | // Close any open folder |
| 2728 | closeFolder(); |
| 2729 | // Open the requested folder |
| 2730 | openFolder(folderIcon); |
| 2731 | } else { |
| 2732 | // Find the open folder... |
| 2733 | int folderScreen; |
| 2734 | if (openFolder != null) { |
| 2735 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2736 | // .. and close it |
| 2737 | closeFolder(openFolder); |
| 2738 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2739 | // Close any folder open on the current screen |
| 2740 | closeFolder(); |
| 2741 | // Pull the folder onto this screen |
| 2742 | openFolder(folderIcon); |
| 2743 | } |
| 2744 | } |
| 2745 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2746 | |
| 2747 | if (mLauncherCallbacks != null) { |
| 2748 | mLauncherCallbacks.onClickFolderIcon(v); |
| 2749 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2752 | /** |
| 2753 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2754 | * on the home screen. |
| 2755 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2756 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2757 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 2758 | if (mIsSafeModeEnabled) { |
| 2759 | Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); |
| 2760 | } else { |
| 2761 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2762 | if (mLauncherCallbacks != null) { |
| 2763 | mLauncherCallbacks.onClickAddWidgetButton(view); |
| 2764 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2765 | } |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2766 | } |
| 2767 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2768 | /** |
| 2769 | * Event handler for the wallpaper picker button that appears after a long press |
| 2770 | * on the home screen. |
| 2771 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2772 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2773 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2774 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2775 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2776 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2777 | |
| 2778 | if (mLauncherCallbacks != null) { |
| 2779 | mLauncherCallbacks.onClickWallpaperPicker(v); |
| 2780 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | /** |
| 2784 | * Event handler for a click on the settings button that appears after a long press |
| 2785 | * on the home screen. |
| 2786 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2787 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2788 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2789 | if (mLauncherCallbacks != null) { |
| 2790 | mLauncherCallbacks.onClickSettingsButton(v); |
| 2791 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2792 | } |
| 2793 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2794 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2795 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2796 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2799 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2800 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2801 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2802 | } |
| 2803 | |
| 2804 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2805 | if (mHapticFeedbackTouchListener == null) { |
| 2806 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2807 | @Override |
| 2808 | public boolean onTouch(View v, MotionEvent event) { |
| 2809 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2810 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2811 | } |
| 2812 | return false; |
| 2813 | } |
| 2814 | }; |
| 2815 | } |
| 2816 | return mHapticFeedbackTouchListener; |
| 2817 | } |
| 2818 | |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2819 | public void onDragStarted(View view) { |
| 2820 | if (isOnCustomContent()) { |
| 2821 | // Custom content screen doesn't participate in drag and drop. If on custom |
| 2822 | // content screen, move to default. |
| 2823 | moveWorkspaceToDefaultScreen(); |
| 2824 | } |
| 2825 | |
| 2826 | if (mLauncherCallbacks != null) { |
| 2827 | mLauncherCallbacks.onDragStarted(view); |
| 2828 | } |
| 2829 | } |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2830 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2831 | /** |
| 2832 | * Called when the user stops interacting with the launcher. |
| 2833 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2834 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2835 | protected void onInteractionEnd() { |
| 2836 | if (mLauncherCallbacks != null) { |
| 2837 | mLauncherCallbacks.onInteractionEnd(); |
| 2838 | } |
| 2839 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2840 | |
| 2841 | /** |
| 2842 | * Called when the user starts interacting with the launcher. |
| 2843 | * The possible interactions are: |
| 2844 | * - open all apps |
| 2845 | * - reorder an app shortcut, or a widget |
| 2846 | * - open the overview mode. |
| 2847 | * This is a good time to stop doing things that only make sense |
| 2848 | * when the user is on the homescreen and not doing housekeeping. |
| 2849 | */ |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 2850 | protected void onInteractionBegin() { |
| 2851 | if (mLauncherCallbacks != null) { |
| 2852 | mLauncherCallbacks.onInteractionBegin(); |
| 2853 | } |
| 2854 | } |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2855 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2856 | void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2857 | try { |
| 2858 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2859 | launcherApps.showAppDetailsForProfile(componentName, user); |
| 2860 | } catch (SecurityException e) { |
| 2861 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2862 | Log.e(TAG, "Launcher does not have permission to launch settings"); |
| 2863 | } catch (ActivityNotFoundException e) { |
| 2864 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2865 | Log.e(TAG, "Unable to launch settings"); |
| 2866 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2867 | } |
| 2868 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2869 | // returns true if the activity was started |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2870 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags, |
| 2871 | UserHandleCompat user) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2872 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2873 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2874 | // We may give them the option of disabling apps this way. |
| 2875 | int messageId = R.string.uninstall_system_app_text; |
| 2876 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2877 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2878 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2879 | String packageName = componentName.getPackageName(); |
| 2880 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2881 | Intent intent = new Intent( |
| 2882 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2883 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2884 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2885 | if (user != null) { |
| 2886 | user.addToIntent(intent, Intent.EXTRA_USER); |
| 2887 | } |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2888 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2889 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2890 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2893 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 2894 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2895 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2896 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 2897 | // private contract between launcher and may be ignored in the future). |
| 2898 | boolean useLaunchAnimation = (v != null) && |
| 2899 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2900 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2901 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2902 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2903 | UserHandleCompat user = null; |
| 2904 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 2905 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 2906 | user = userManager.getUserForSerialNumber(serialNumber); |
| 2907 | } |
| 2908 | |
| 2909 | Bundle optsBundle = null; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2910 | if (useLaunchAnimation) { |
Chet Haase | a8f996d | 2015-02-17 12:56:04 -0800 | [diff] [blame] | 2911 | ActivityOptions opts = null; |
| 2912 | if (sClipRevealMethod != null) { |
| 2913 | // TODO: call method directly when Launcher3 can depend on M APIs |
| 2914 | int left = 0, top = 0; |
| 2915 | int width = v.getMeasuredWidth(), height = v.getMeasuredHeight(); |
| 2916 | if (v instanceof TextView) { |
| 2917 | // Launch from center of icon, not entire view |
| 2918 | TextView tv = (TextView) v; |
| 2919 | Drawable[] drawables = tv.getCompoundDrawables(); |
| 2920 | if (drawables != null && drawables[1] != null) { |
| 2921 | Rect bounds = drawables[1].getBounds(); |
| 2922 | left = (width - bounds.width()) / 2; |
| 2923 | top = tv.getPaddingTop(); |
| 2924 | width = bounds.width(); |
| 2925 | height = bounds.height(); |
| 2926 | } |
| 2927 | } |
| 2928 | try { |
| 2929 | opts = (ActivityOptions) sClipRevealMethod.invoke(null, v, |
| 2930 | left, top, width, height); |
| 2931 | } catch (IllegalAccessException e) { |
| 2932 | Log.d(TAG, "Could not call makeClipRevealAnimation: " + e); |
| 2933 | sClipRevealMethod = null; |
| 2934 | } catch (InvocationTargetException e) { |
| 2935 | Log.d(TAG, "Could not call makeClipRevealAnimation: " + e); |
| 2936 | sClipRevealMethod = null; |
| 2937 | } |
| 2938 | } |
| 2939 | if (opts == null) { |
| 2940 | opts = Utilities.isLmpOrAbove() ? |
| 2941 | ActivityOptions.makeCustomAnimation(this, |
| 2942 | R.anim.task_open_enter, R.anim.no_anim) : |
| 2943 | ActivityOptions.makeScaleUpAnimation(v, 0, 0, |
| 2944 | v.getMeasuredWidth(), v.getMeasuredHeight()); |
| 2945 | } |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 2946 | optsBundle = opts.toBundle(); |
| 2947 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2948 | |
| 2949 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 2950 | // Could be launching some bookkeeping activity |
| 2951 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2952 | } else { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2953 | // TODO Component can be null when shortcuts are supported for secondary user |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 2954 | launcherApps.startActivityForProfile(intent.getComponent(), user, |
| 2955 | intent.getSourceBounds(), optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2956 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2957 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2958 | } catch (SecurityException e) { |
| 2959 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2960 | 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] | 2961 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2962 | "or use the exported attribute for this activity. " |
| 2963 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2964 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2965 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2966 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2967 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2968 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 2969 | boolean success = false; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2970 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 2971 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 2972 | return false; |
| 2973 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2974 | try { |
| 2975 | success = startActivity(v, intent, tag); |
| 2976 | } catch (ActivityNotFoundException e) { |
| 2977 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2978 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 2979 | } |
| 2980 | return success; |
| 2981 | } |
| 2982 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2983 | /** |
| 2984 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 2985 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 2986 | */ |
| 2987 | private void copyFolderIconToImage(FolderIcon fi) { |
| 2988 | final int width = fi.getMeasuredWidth(); |
| 2989 | final int height = fi.getMeasuredHeight(); |
| 2990 | |
| 2991 | // Lazy load ImageView, Bitmap and Canvas |
| 2992 | if (mFolderIconImageView == null) { |
| 2993 | mFolderIconImageView = new ImageView(this); |
| 2994 | } |
| 2995 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 2996 | mFolderIconBitmap.getHeight() != height) { |
| 2997 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 2998 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 2999 | } |
| 3000 | |
| 3001 | DragLayer.LayoutParams lp; |
| 3002 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 3003 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 3004 | } else { |
| 3005 | lp = new DragLayer.LayoutParams(width, height); |
| 3006 | } |
| 3007 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 3008 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 3009 | // view size by this scale factor. |
| 3010 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3011 | lp.customPosition = true; |
| 3012 | lp.x = mRectForFolderAnimation.left; |
| 3013 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 3014 | lp.width = (int) (scale * width); |
| 3015 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3016 | |
| 3017 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 3018 | fi.draw(mFolderIconCanvas); |
| 3019 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3020 | if (fi.getFolder() != null) { |
| 3021 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 3022 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3023 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3024 | // Just in case this image view is still in the drag layer from a previous animation, |
| 3025 | // we remove it and re-add it. |
| 3026 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 3027 | mDragLayer.removeView(mFolderIconImageView); |
| 3028 | } |
| 3029 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3030 | if (fi.getFolder() != null) { |
| 3031 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 3032 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3035 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3036 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3037 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 3038 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 3039 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 3040 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3041 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 3042 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3043 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 3044 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 3045 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3048 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 3049 | copyFolderIconToImage(fi); |
| 3050 | fi.setVisibility(View.INVISIBLE); |
| 3051 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3052 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3053 | scaleX, scaleY); |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3054 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3055 | oa.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3056 | } |
| 3057 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3058 | oa.start(); |
| 3059 | } |
| 3060 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3061 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 3062 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3063 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 3064 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 3065 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 3066 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3067 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3068 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3069 | // We remove and re-draw the FolderIcon in-case it has changed |
| 3070 | mDragLayer.removeView(mFolderIconImageView); |
| 3071 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3072 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3073 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3074 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3075 | oa.addListener(new AnimatorListenerAdapter() { |
| 3076 | @Override |
| 3077 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3078 | if (cl != null) { |
| 3079 | cl.clearFolderLeaveBehind(); |
| 3080 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 3081 | mDragLayer.removeView(mFolderIconImageView); |
| 3082 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 3086 | oa.start(); |
| 3087 | } |
| 3088 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3089 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 3090 | * 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] | 3091 | * is animated relative to the specified View. If the View is null, no animation |
| 3092 | * is played. |
| 3093 | * |
| 3094 | * @param folderInfo The FolderInfo describing the folder to open. |
| 3095 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3096 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 3097 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3098 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3099 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3100 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3101 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3102 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 3103 | // There was a one-off crash where the folder had a parent already. |
| 3104 | if (folder.getParent() == null) { |
| 3105 | mDragLayer.addView(folder); |
| 3106 | mDragController.addDropTarget((DropTarget) folder); |
| 3107 | } else { |
| 3108 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 3109 | folder.getParent() + ")."); |
| 3110 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3111 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 3112 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3113 | |
| 3114 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 3115 | // the workspace items |
| 3116 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 3117 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 3121 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3122 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 3123 | if (folder.isEditingName()) { |
| 3124 | folder.dismissEditingName(); |
| 3125 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 3126 | closeFolder(folder); |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | void closeFolder(Folder folder) { |
| 3131 | folder.getInfo().opened = false; |
| 3132 | |
| 3133 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 3134 | if (parent != null) { |
| 3135 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 3136 | shrinkAndFadeInFolderIcon(fi); |
| 3137 | } |
| 3138 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 3139 | |
| 3140 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 3141 | // longer occludeds the workspace items |
| 3142 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3143 | } |
| 3144 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3145 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 3146 | if (!isDraggingEnabled()) return false; |
| 3147 | if (isWorkspaceLocked()) return false; |
| 3148 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3149 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3150 | if (v instanceof Workspace) { |
| 3151 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 3152 | if (mWorkspace.enterOverviewMode()) { |
| 3153 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3154 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 3155 | return true; |
| 3156 | } else { |
| 3157 | return false; |
| 3158 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 3159 | } else { |
| 3160 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3161 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 3164 | CellLayout.CellInfo longClickCellInfo = null; |
| 3165 | View itemUnderLongClick = null; |
| 3166 | if (v.getTag() instanceof ItemInfo) { |
| 3167 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3168 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 3169 | itemUnderLongClick = longClickCellInfo.cell; |
| 3170 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3171 | } |
| 3172 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3173 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 3174 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3175 | final boolean inHotseat = isHotseatLayout(v); |
| 3176 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3177 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3178 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3179 | // User long pressed on empty space |
| 3180 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3181 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3182 | if (mWorkspace.isInOverviewMode()) { |
| 3183 | mWorkspace.startReordering(v); |
| 3184 | } else { |
| 3185 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 3186 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3187 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3188 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 3189 | mHotseat.getOrderInHotseat( |
| 3190 | longClickCellInfo.cellX, |
| 3191 | longClickCellInfo.cellY)); |
| 3192 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3193 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3194 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3195 | } |
| 3196 | } |
| 3197 | } |
| 3198 | return true; |
| 3199 | } |
| 3200 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3201 | boolean isHotseatLayout(View layout) { |
| 3202 | return mHotseat != null && layout != null && |
| 3203 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 3204 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 3205 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3206 | /** |
| 3207 | * Returns the CellLayout of the specified container at the specified screen. |
| 3208 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3209 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3210 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3211 | if (mHotseat != null) { |
| 3212 | return mHotseat.getLayout(); |
| 3213 | } else { |
| 3214 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 3215 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3216 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3217 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 3218 | } |
| 3219 | } |
| 3220 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3221 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3222 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 3223 | } |
| 3224 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3225 | private void setWorkspaceBackground(boolean workspace) { |
| 3226 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 3227 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 3230 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3231 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 3232 | int curflags = getWindow().getAttributes().flags |
| 3233 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 3234 | if (wpflags != curflags) { |
| 3235 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 3236 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3237 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3240 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3241 | if (v instanceof LauncherTransitionable) { |
| 3242 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3243 | } |
| 3244 | } |
| 3245 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3246 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3247 | if (v instanceof LauncherTransitionable) { |
| 3248 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3249 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3250 | |
| 3251 | // Update the workspace transition step as well |
| 3252 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3253 | } |
| 3254 | |
| 3255 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3256 | if (v instanceof LauncherTransitionable) { |
| 3257 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3258 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3262 | if (v instanceof LauncherTransitionable) { |
| 3263 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3264 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3265 | |
| 3266 | // Update the workspace transition step as well |
| 3267 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3268 | } |
| 3269 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3270 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3271 | * Things to test when changing the following seven functions. |
| 3272 | * - Home from workspace |
| 3273 | * - from center screen |
| 3274 | * - from other screens |
| 3275 | * - Home from all apps |
| 3276 | * - from center screen |
| 3277 | * - from other screens |
| 3278 | * - Back from all apps |
| 3279 | * - from center screen |
| 3280 | * - from other screens |
| 3281 | * - Launch app from workspace and quit |
| 3282 | * - with back |
| 3283 | * - with home |
| 3284 | * - Launch app from all apps and quit |
| 3285 | * - with back |
| 3286 | * - with home |
| 3287 | * - Go to a screen that's not the default, then all |
| 3288 | * apps, and launch and app, and go back |
| 3289 | * - with back |
| 3290 | * -with home |
| 3291 | * - On workspace, long press power and go back |
| 3292 | * - with back |
| 3293 | * - with home |
| 3294 | * - On all apps, long press power and go back |
| 3295 | * - with back |
| 3296 | * - with home |
| 3297 | * - On workspace, power off |
| 3298 | * - On all apps, power off |
| 3299 | * - Launch an app and turn off the screen while in that app |
| 3300 | * - Go back with home key |
| 3301 | * - Go back with back key TODO: make this not go to workspace |
| 3302 | * - From all apps |
| 3303 | * - From workspace |
| 3304 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3305 | * - From all apps |
| 3306 | * - From the center workspace |
| 3307 | * - From another workspace |
| 3308 | */ |
| 3309 | |
| 3310 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3311 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3312 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3313 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3314 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3315 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3316 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3317 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3318 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3319 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 3320 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3321 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3322 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3323 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3324 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3325 | mStateAnimation.cancel(); |
| 3326 | mStateAnimation = null; |
| 3327 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3328 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3329 | boolean material = Utilities.isLmpOrAbove(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3330 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3331 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3332 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3333 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3334 | final int itemsAlphaStagger = |
| 3335 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3336 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3337 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3338 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3339 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3340 | final HashMap<View, Integer> layerViews = new HashMap<View, Integer>(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3341 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3342 | Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? |
| 3343 | Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3344 | Animator workspaceAnim = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3345 | mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews); |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 3346 | if (contentType == AppsCustomizePagedView.ContentType.Widgets) { |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3347 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3348 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3349 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3350 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3351 | // If for some reason our views aren't initialized, don't animate |
| 3352 | boolean initialized = getAllAppsButton() != null; |
| 3353 | |
| 3354 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3355 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3356 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3357 | toView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3358 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3359 | final View page = content.getPageAt(content.getCurrentPage()); |
| 3360 | final View revealView = toView.findViewById(R.id.fake_page); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3361 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3362 | final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; |
| 3363 | if (isWidgetTray) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3364 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3365 | } else { |
| 3366 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3367 | } |
| 3368 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3369 | // Hide the real page background, and swap in the fake one |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3370 | content.setPageBackgroundsVisible(false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3371 | revealView.setVisibility(View.VISIBLE); |
| 3372 | // We need to hide this view as the animation start will be posted. |
| 3373 | revealView.setAlpha(0); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3374 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3375 | int width = revealView.getMeasuredWidth(); |
| 3376 | int height = revealView.getMeasuredHeight(); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3377 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3378 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3379 | revealView.setTranslationY(0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3380 | revealView.setTranslationX(0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3381 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3382 | // Get the y delta between the center of the page and the center of the all apps button |
| 3383 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3384 | getAllAppsButton(), null); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3385 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3386 | float alpha = 0; |
| 3387 | float xDrift = 0; |
| 3388 | float yDrift = 0; |
| 3389 | if (material) { |
| 3390 | alpha = isWidgetTray ? 0.3f : 1f; |
| 3391 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3392 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3393 | } else { |
| 3394 | yDrift = 2 * height / 3; |
| 3395 | xDrift = 0; |
| 3396 | } |
| 3397 | final float initAlpha = alpha; |
| 3398 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3399 | layerViews.put(revealView, BUILD_AND_SET_LAYER); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3400 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3401 | PropertyValuesHolder panelDriftY = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3402 | PropertyValuesHolder.ofFloat("translationY", yDrift, 0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3403 | PropertyValuesHolder panelDriftX = |
| 3404 | PropertyValuesHolder.ofFloat("translationX", xDrift, 0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3405 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3406 | ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, |
| 3407 | panelAlpha, panelDriftY, panelDriftX); |
| 3408 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3409 | panelAlphaAndDrift.setDuration(revealDuration); |
| 3410 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3411 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3412 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3413 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3414 | if (page != null) { |
| 3415 | page.setVisibility(View.VISIBLE); |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3416 | layerViews.put(page, BUILD_AND_SET_LAYER); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3417 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3418 | ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0); |
| 3419 | page.setTranslationY(yDrift); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3420 | pageDrift.setDuration(revealDuration); |
| 3421 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3422 | pageDrift.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3423 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3424 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3425 | page.setAlpha(0f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3426 | ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3427 | itemsAlpha.setDuration(revealDuration); |
| 3428 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 3429 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
| 3430 | mStateAnimation.play(itemsAlpha); |
| 3431 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3432 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3433 | View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); |
| 3434 | pageIndicators.setAlpha(0.01f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3435 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3436 | ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3437 | indicatorsAlpha.setDuration(revealDuration); |
| 3438 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3439 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3440 | if (material) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3441 | final View allApps = getAllAppsButton(); |
| 3442 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3443 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3444 | float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3445 | Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3446 | height / 2, startRadius, revealRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3447 | reveal.setDuration(revealDuration); |
| 3448 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3449 | |
| 3450 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3451 | public void onAnimationStart(Animator animation) { |
| 3452 | if (!isWidgetTray) { |
| 3453 | allApps.setVisibility(View.INVISIBLE); |
| 3454 | } |
| 3455 | } |
| 3456 | public void onAnimationEnd(Animator animation) { |
| 3457 | if (!isWidgetTray) { |
| 3458 | allApps.setVisibility(View.VISIBLE); |
| 3459 | } |
| 3460 | } |
| 3461 | }); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3462 | mStateAnimation.play(reveal); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3463 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3464 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3465 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
| 3466 | @Override |
| 3467 | public void onAnimationEnd(Animator animation) { |
| 3468 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3469 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 3470 | |
| 3471 | revealView.setVisibility(View.INVISIBLE); |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3472 | |
| 3473 | for (View v : layerViews.keySet()) { |
| 3474 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 3475 | v.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3476 | } |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3477 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3478 | content.setPageBackgroundsVisible(true); |
| 3479 | |
| 3480 | // Hide the search bar |
| 3481 | if (mSearchDropTargetBar != null) { |
| 3482 | mSearchDropTargetBar.hideSearchBar(false); |
| 3483 | } |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3484 | |
| 3485 | // This can hold unnecessary references to views. |
| 3486 | mStateAnimation = null; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3487 | } |
| 3488 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3489 | }); |
| 3490 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3491 | if (workspaceAnim != null) { |
| 3492 | mStateAnimation.play(workspaceAnim); |
| 3493 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3494 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3495 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3496 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3497 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3498 | final Runnable startAnimRunnable = new Runnable() { |
| 3499 | public void run() { |
| 3500 | // Check that mStateAnimation hasn't changed while |
| 3501 | // we waited for a layout/draw pass |
| 3502 | if (mStateAnimation != stateAnimation) |
| 3503 | return; |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3504 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3505 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3506 | |
| 3507 | revealView.setAlpha(initAlpha); |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3508 | |
| 3509 | for (View v : layerViews.keySet()) { |
| 3510 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 3511 | v.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3512 | } |
| 3513 | } |
| 3514 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3515 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3516 | for (View v : layerViews.keySet()) { |
| 3517 | if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3518 | } |
| 3519 | } |
| 3520 | mStateAnimation.start(); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3521 | } |
| 3522 | }; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3523 | toView.bringToFront(); |
| 3524 | toView.setVisibility(View.VISIBLE); |
| 3525 | toView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3526 | } else { |
| 3527 | toView.setTranslationX(0.0f); |
| 3528 | toView.setTranslationY(0.0f); |
| 3529 | toView.setScaleX(1.0f); |
| 3530 | toView.setScaleY(1.0f); |
| 3531 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3532 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3533 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3534 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3535 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3536 | if (mSearchDropTargetBar != null) { |
| 3537 | mSearchDropTargetBar.hideSearchBar(false); |
| 3538 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3539 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3540 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3541 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3542 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3543 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3544 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3545 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3546 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | /** |
| 3550 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3551 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3552 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3553 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3554 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3555 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3556 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3557 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3558 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3559 | mStateAnimation.cancel(); |
| 3560 | mStateAnimation = null; |
| 3561 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3562 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3563 | boolean material = Utilities.isLmpOrAbove(); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3564 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3565 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3566 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3567 | final int itemsAlphaStagger = |
| 3568 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3569 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3570 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3571 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3572 | Animator workspaceAnim = null; |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3573 | final HashMap<View, Integer> layerViews = new HashMap<View, Integer>(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3574 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3575 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3576 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3577 | toState, animated, layerViews); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3578 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3579 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3580 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3581 | toState, animated, layerViews); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3582 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3583 | |
Adam Cohen | a38dc90 | 2014-09-07 17:48:55 +0200 | [diff] [blame] | 3584 | // If for some reason our views aren't initialized, don't animate |
| 3585 | boolean initialized = getAllAppsButton() != null; |
| 3586 | |
| 3587 | if (animated && initialized) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3588 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3589 | if (workspaceAnim != null) { |
| 3590 | mStateAnimation.play(workspaceAnim); |
| 3591 | } |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3592 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3593 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3594 | fromView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3595 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3596 | final View page = content.getPageAt(content.getNextPage()); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3597 | |
| 3598 | // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases |
| 3599 | int count = content.getChildCount(); |
| 3600 | for (int i = 0; i < count; i++) { |
| 3601 | View child = content.getChildAt(i); |
| 3602 | if (child != page) { |
| 3603 | child.setVisibility(View.INVISIBLE); |
| 3604 | } |
| 3605 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3606 | final View revealView = fromView.findViewById(R.id.fake_page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3607 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3608 | // hideAppsCustomizeHelper is called in some cases when it is already hidden |
| 3609 | // don't perform all these no-op animations. In particularly, this was causing |
| 3610 | // the all-apps button to pop in and out. |
| 3611 | if (fromView.getVisibility() == View.VISIBLE) { |
| 3612 | AppsCustomizePagedView.ContentType contentType = content.getContentType(); |
| 3613 | final boolean isWidgetTray = |
| 3614 | contentType == AppsCustomizePagedView.ContentType.Widgets; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3615 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3616 | if (isWidgetTray) { |
| 3617 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3618 | } else { |
| 3619 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3620 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3621 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3622 | int width = revealView.getMeasuredWidth(); |
| 3623 | int height = revealView.getMeasuredHeight(); |
| 3624 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
| 3625 | |
| 3626 | // Hide the real page background, and swap in the fake one |
| 3627 | revealView.setVisibility(View.VISIBLE); |
| 3628 | content.setPageBackgroundsVisible(false); |
| 3629 | |
| 3630 | final View allAppsButton = getAllAppsButton(); |
| 3631 | revealView.setTranslationY(0); |
| 3632 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3633 | allAppsButton, null); |
| 3634 | |
| 3635 | float xDrift = 0; |
| 3636 | float yDrift = 0; |
| 3637 | if (material) { |
| 3638 | yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
| 3639 | xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
| 3640 | } else { |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3641 | yDrift = 2 * height / 3; |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3642 | xDrift = 0; |
| 3643 | } |
| 3644 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3645 | layerViews.put(revealView, BUILD_AND_SET_LAYER); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3646 | TimeInterpolator decelerateInterpolator = material ? |
| 3647 | new LogDecelerateInterpolator(100, 0) : |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3648 | new DecelerateInterpolator(1f); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3649 | |
| 3650 | // The vertical motion of the apps panel should be delayed by one frame |
| 3651 | // from the conceal animation in order to give the right feel. We correpsondingly |
| 3652 | // shorten the duration so that the slide and conceal end at the same time. |
| 3653 | ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", |
| 3654 | 0, yDrift); |
| 3655 | panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3656 | panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3657 | panelDriftY.setInterpolator(decelerateInterpolator); |
| 3658 | mStateAnimation.play(panelDriftY); |
| 3659 | |
| 3660 | ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", |
| 3661 | 0, xDrift); |
| 3662 | panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3663 | panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3664 | panelDriftX.setInterpolator(decelerateInterpolator); |
| 3665 | mStateAnimation.play(panelDriftX); |
| 3666 | |
| 3667 | if (isWidgetTray || !material) { |
| 3668 | float finalAlpha = material ? 0.4f : 0f; |
| 3669 | revealView.setAlpha(1f); |
| 3670 | ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", |
| 3671 | 1f, finalAlpha); |
Adam Cohen | 0fb5ce2 | 2014-10-24 13:50:20 -0700 | [diff] [blame] | 3672 | panelAlpha.setDuration(material ? revealDuration : 150); |
| 3673 | panelAlpha.setInterpolator(decelerateInterpolator); |
| 3674 | panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3675 | mStateAnimation.play(panelAlpha); |
| 3676 | } |
| 3677 | |
| 3678 | if (page != null) { |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3679 | layerViews.put(page, BUILD_AND_SET_LAYER); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3680 | |
| 3681 | ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", |
| 3682 | 0, yDrift); |
| 3683 | page.setTranslationY(0); |
| 3684 | pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3685 | pageDrift.setInterpolator(decelerateInterpolator); |
| 3686 | pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3687 | mStateAnimation.play(pageDrift); |
| 3688 | |
| 3689 | page.setAlpha(1f); |
| 3690 | ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f); |
| 3691 | itemsAlpha.setDuration(100); |
| 3692 | itemsAlpha.setInterpolator(decelerateInterpolator); |
| 3693 | mStateAnimation.play(itemsAlpha); |
| 3694 | } |
| 3695 | |
| 3696 | View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); |
| 3697 | pageIndicators.setAlpha(1f); |
| 3698 | ObjectAnimator indicatorsAlpha = |
| 3699 | LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f); |
| 3700 | indicatorsAlpha.setDuration(revealDuration); |
| 3701 | indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 3702 | mStateAnimation.play(indicatorsAlpha); |
| 3703 | |
| 3704 | width = revealView.getMeasuredWidth(); |
| 3705 | |
| 3706 | if (material) { |
| 3707 | if (!isWidgetTray) { |
| 3708 | allAppsButton.setVisibility(View.INVISIBLE); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3709 | } |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3710 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3711 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3712 | float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
| 3713 | Animator reveal = |
| 3714 | LauncherAnimUtils.createCircularReveal(revealView, width / 2, |
| 3715 | height / 2, revealRadius, finalRadius); |
| 3716 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3717 | reveal.setDuration(revealDuration); |
| 3718 | reveal.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3719 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3720 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3721 | public void onAnimationEnd(Animator animation) { |
| 3722 | revealView.setVisibility(View.INVISIBLE); |
| 3723 | if (!isWidgetTray) { |
| 3724 | allAppsButton.setVisibility(View.VISIBLE); |
| 3725 | } |
| 3726 | } |
| 3727 | }); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3728 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3729 | mStateAnimation.play(reveal); |
| 3730 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3731 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3732 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3733 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 3734 | mAppsCustomizeContent.stopScrolling(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3735 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3736 | |
| 3737 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3738 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3739 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3740 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3741 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3742 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3743 | if (onCompleteRunnable != null) { |
| 3744 | onCompleteRunnable.run(); |
| 3745 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3746 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3747 | for (View v : layerViews.keySet()) { |
| 3748 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 3749 | v.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3750 | } |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3751 | } |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3752 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3753 | content.setPageBackgroundsVisible(true); |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3754 | // Unhide side pages |
| 3755 | int count = content.getChildCount(); |
| 3756 | for (int i = 0; i < count; i++) { |
| 3757 | View child = content.getChildAt(i); |
| 3758 | child.setVisibility(View.VISIBLE); |
| 3759 | } |
| 3760 | |
| 3761 | // Reset page transforms |
Adam Cohen | 493f6bc | 2014-09-18 08:11:05 -0700 | [diff] [blame] | 3762 | if (page != null) { |
| 3763 | page.setTranslationX(0); |
| 3764 | page.setTranslationY(0); |
| 3765 | page.setAlpha(1); |
| 3766 | } |
Adam Cohen | 8e894fa | 2014-09-08 19:45:43 +0200 | [diff] [blame] | 3767 | content.setCurrentPage(content.getNextPage()); |
| 3768 | |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3769 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3770 | |
| 3771 | // This can hold unnecessary references to views. |
| 3772 | mStateAnimation = null; |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3773 | } |
| 3774 | }); |
| 3775 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3776 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3777 | final Runnable startAnimRunnable = new Runnable() { |
| 3778 | public void run() { |
| 3779 | // Check that mStateAnimation hasn't changed while |
| 3780 | // we waited for a layout/draw pass |
| 3781 | if (mStateAnimation != stateAnimation) |
| 3782 | return; |
| 3783 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3784 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3785 | |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3786 | for (View v : layerViews.keySet()) { |
| 3787 | if (layerViews.get(v) == BUILD_AND_SET_LAYER) { |
| 3788 | v.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3789 | } |
| 3790 | } |
| 3791 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 3792 | if (Utilities.isLmpOrAbove()) { |
Adam Cohen | 80e6beb | 2015-02-13 16:14:33 -0800 | [diff] [blame] | 3793 | for (View v : layerViews.keySet()) { |
| 3794 | if (Utilities.isViewAttachedToWindow(v)) v.buildLayer(); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 3795 | } |
| 3796 | } |
| 3797 | mStateAnimation.start(); |
| 3798 | } |
| 3799 | }; |
| 3800 | fromView.post(startAnimRunnable); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3801 | } else { |
| 3802 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3803 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3804 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3805 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3806 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3807 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3808 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3809 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3812 | @Override |
| 3813 | public void onTrimMemory(int level) { |
| 3814 | super.onTrimMemory(level); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3815 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
| 3816 | // The widget preview db can result in holding onto over |
| 3817 | // 3MB of memory for caching which isn't necessary. |
| 3818 | SQLiteDatabase.releaseMemory(); |
| 3819 | |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 3820 | // This clears all widget bitmaps from the widget tray |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3821 | if (mAppsCustomizeTabHost != null) { |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 3822 | mAppsCustomizeTabHost.trimMemory(); |
Adam Cohen | 3f9c971 | 2014-10-31 11:48:25 -0700 | [diff] [blame] | 3823 | } |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3824 | } |
| 3825 | } |
| 3826 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3827 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3828 | showWorkspace(animated, null); |
| 3829 | } |
| 3830 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3831 | protected void showWorkspace() { |
| 3832 | showWorkspace(true); |
| 3833 | } |
| 3834 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3835 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 3836 | if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3837 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3838 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3839 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3840 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3841 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3842 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3843 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3844 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3845 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3846 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3847 | // Set focus to the AppsCustomize button |
| 3848 | if (mAllAppsButton != null) { |
| 3849 | mAllAppsButton.requestFocus(); |
| 3850 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3851 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3852 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3853 | // Change the state *after* we've called all the transition code |
| 3854 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3855 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3856 | // Resume the auto-advance of widgets |
| 3857 | mUserPresent = true; |
| 3858 | updateRunning(); |
| 3859 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3860 | // Send an accessibility event to announce the context change |
| 3861 | getWindow().getDecorView() |
| 3862 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3863 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3864 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3865 | } |
| 3866 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3867 | void showOverviewMode(boolean animated) { |
| 3868 | mWorkspace.setVisibility(View.VISIBLE); |
| 3869 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3870 | mState = State.WORKSPACE; |
| 3871 | onWorkspaceShown(animated); |
| 3872 | } |
| 3873 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3874 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3875 | } |
| 3876 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3877 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3878 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3879 | if (mState != State.WORKSPACE) return; |
| 3880 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3881 | if (resetPageToZero) { |
| 3882 | mAppsCustomizeTabHost.reset(); |
| 3883 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3884 | showAppsCustomizeHelper(animated, false, contentType); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 3885 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3886 | @Override |
| 3887 | public void run() { |
| 3888 | // We post this in-case the all apps view isn't yet constructed. |
| 3889 | mAppsCustomizeTabHost.requestFocus(); |
| 3890 | } |
| 3891 | }); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3892 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3893 | // Change the state *after* we've called all the transition code |
| 3894 | mState = State.APPS_CUSTOMIZE; |
| 3895 | |
| 3896 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3897 | mUserPresent = false; |
| 3898 | updateRunning(); |
| 3899 | closeFolder(); |
| 3900 | |
| 3901 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3902 | getWindow().getDecorView() |
| 3903 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3904 | } |
| 3905 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3906 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3907 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3908 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3909 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3910 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3911 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3912 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3913 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3914 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3915 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 3916 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 3917 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3918 | @Override |
| 3919 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3920 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3921 | // Before we show workspace, hide all apps again because |
| 3922 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 3923 | // clean up our state transition functions |
| 3924 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3925 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3926 | } else { |
| 3927 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3928 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3929 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3930 | }, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3931 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3932 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3933 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3934 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3935 | final boolean animated = true; |
| 3936 | final boolean springLoaded = true; |
| 3937 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3938 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3939 | } |
| 3940 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 3941 | } |
| 3942 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3943 | void lockAllApps() { |
| 3944 | // TODO |
| 3945 | } |
| 3946 | |
| 3947 | void unlockAllApps() { |
| 3948 | // TODO |
| 3949 | } |
| 3950 | |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3951 | protected void disableVoiceButtonProxy(boolean disable) { |
| 3952 | // NO-OP |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3955 | public View getQsbBar() { |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 3956 | if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { |
| 3957 | return mLauncherCallbacks.getQsbBar(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3960 | if (mQsb == null) { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3961 | AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this); |
| 3962 | if (searchProvider == null) { |
| 3963 | return null; |
| 3964 | } |
| 3965 | |
| 3966 | Bundle opts = new Bundle(); |
| 3967 | opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, |
Adam Cohen | eb8e282 | 2015-02-20 16:38:48 +0000 | [diff] [blame] | 3968 | AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3969 | |
| 3970 | SharedPreferences sp = getSharedPreferences( |
| 3971 | LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE); |
| 3972 | int widgetId = sp.getInt(QSB_WIDGET_ID, -1); |
Sunny Goyal | 416541c | 2014-11-14 11:59:57 -0800 | [diff] [blame] | 3973 | AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3974 | if (!searchProvider.provider.flattenToString().equals( |
| 3975 | sp.getString(QSB_WIDGET_PROVIDER, null)) |
Sunny Goyal | 416541c | 2014-11-14 11:59:57 -0800 | [diff] [blame] | 3976 | || (widgetInfo == null) |
| 3977 | || !widgetInfo.provider.equals(searchProvider.provider)) { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 3978 | // A valid widget is not already bound. |
| 3979 | if (widgetId > -1) { |
| 3980 | mAppWidgetHost.deleteAppWidgetId(widgetId); |
| 3981 | widgetId = -1; |
| 3982 | } |
| 3983 | |
| 3984 | // Try to bind a new widget |
| 3985 | widgetId = mAppWidgetHost.allocateAppWidgetId(); |
| 3986 | |
| 3987 | if (!AppWidgetManagerCompat.getInstance(this) |
| 3988 | .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) { |
| 3989 | mAppWidgetHost.deleteAppWidgetId(widgetId); |
| 3990 | widgetId = -1; |
| 3991 | } |
| 3992 | |
| 3993 | sp.edit() |
| 3994 | .putInt(QSB_WIDGET_ID, widgetId) |
| 3995 | .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString()) |
| 3996 | .commit(); |
| 3997 | } |
| 3998 | |
| 3999 | if (widgetId != -1) { |
| 4000 | mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider); |
| 4001 | mQsb.updateAppWidgetOptions(opts); |
| 4002 | mQsb.setPadding(0, 0, 0, 0); |
| 4003 | mSearchDropTargetBar.addView(mQsb); |
| 4004 | } |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4005 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 4006 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 4007 | } |
| 4008 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4009 | @Override |
| 4010 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4011 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4012 | final List<CharSequence> text = event.getText(); |
| 4013 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4014 | // Populate event with a fake title based on the current state. |
| 4015 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4016 | text.add(mAppsCustomizeTabHost.getContentTag()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 4017 | } else { |
| 4018 | text.add(getString(R.string.all_apps_home_button_label)); |
| 4019 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 4020 | return result; |
| 4021 | } |
| 4022 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 4023 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 4024 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4025 | */ |
| 4026 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 4027 | @Override |
| 4028 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4029 | closeSystemDialogs(); |
| 4030 | } |
| 4031 | } |
| 4032 | |
| 4033 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 4034 | * Receives notifications whenever the appwidgets are reset. |
| 4035 | */ |
| 4036 | private class AppWidgetResetObserver extends ContentObserver { |
| 4037 | public AppWidgetResetObserver() { |
| 4038 | super(new Handler()); |
| 4039 | } |
| 4040 | |
| 4041 | @Override |
| 4042 | public void onChange(boolean selfChange) { |
| 4043 | onAppWidgetReset(); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4048 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 4049 | * in onResume. |
| 4050 | * |
| 4051 | * This needs to be called from incoming places where resources might have been loaded |
| 4052 | * while we are paused. That is becaues the Configuration might be wrong |
| 4053 | * when we're not running, and if it comes back to what it was when we |
| 4054 | * were paused, we are not restarted. |
| 4055 | * |
| 4056 | * Implementation of the method from LauncherModel.Callbacks. |
| 4057 | * |
| 4058 | * @return true if we are currently paused. The caller might be able to |
| 4059 | * skip some work in that case since we will come back again. |
| 4060 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4061 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4062 | if (mPaused) { |
| 4063 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4064 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4065 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4066 | } |
| 4067 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4068 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4069 | return true; |
| 4070 | } else { |
| 4071 | return false; |
| 4072 | } |
| 4073 | } |
| 4074 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4075 | private boolean waitUntilResume(Runnable run) { |
| 4076 | return waitUntilResume(run, false); |
| 4077 | } |
| 4078 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4079 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 4080 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4083 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4084 | * If the activity is currently paused, signal that we need to re-run the loader |
| 4085 | * in onResume. |
| 4086 | * |
| 4087 | * This needs to be called from incoming places where resources might have been loaded |
| 4088 | * while we are paused. That is becaues the Configuration might be wrong |
| 4089 | * when we're not running, and if it comes back to what it was when we |
| 4090 | * were paused, we are not restarted. |
| 4091 | * |
| 4092 | * Implementation of the method from LauncherModel.Callbacks. |
| 4093 | * |
| 4094 | * @return true if we are currently paused. The caller might be able to |
| 4095 | * skip some work in that case since we will come back again. |
| 4096 | */ |
| 4097 | public boolean setLoadOnResume() { |
| 4098 | if (mPaused) { |
| 4099 | Log.i(TAG, "setLoadOnResume"); |
| 4100 | mOnResumeNeedsLoad = true; |
| 4101 | return true; |
| 4102 | } else { |
| 4103 | return false; |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4108 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4109 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4110 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4111 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4112 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4113 | } else { |
| 4114 | return SCREEN_COUNT / 2; |
| 4115 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4116 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4117 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4118 | /** |
| 4119 | * Refreshes the shortcuts shown on the workspace. |
| 4120 | * |
| 4121 | * Implementation of the method from LauncherModel.Callbacks. |
| 4122 | */ |
| 4123 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4124 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 4125 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4126 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 4127 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 4128 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4129 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4130 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4131 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4132 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 4133 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4134 | |
Michael Jurka | 05bf644e | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 4135 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4136 | if (mHotseat != null) { |
| 4137 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4141 | @Override |
| 4142 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4143 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4144 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 4145 | // If there are no screens, we need to have an empty screen |
| 4146 | if (orderedScreenIds.size() == 0) { |
| 4147 | mWorkspace.addExtraEmptyScreen(); |
| 4148 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4149 | |
| 4150 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4151 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 4152 | if (hasCustomContentToLeft()) { |
| 4153 | mWorkspace.createCustomContentContainer(); |
| 4154 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4155 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | @Override |
| 4159 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 4160 | // Log to disk |
| 4161 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 4162 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 4163 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4164 | int count = orderedScreenIds.size(); |
| 4165 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 4166 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4167 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4168 | } |
| 4169 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 4170 | @Override |
| 4171 | public void bindAddPendingItem(final PendingAddItemInfo info, final long container, |
| 4172 | final long screenId, final int[] cell, final int spanX, final int spanY) { |
| 4173 | showWorkspace(true, new Runnable() { |
| 4174 | |
| 4175 | @Override |
| 4176 | public void run() { |
| 4177 | mWorkspace.snapToPage(mWorkspace.getPageIndexForScreenId(screenId)); |
| 4178 | addPendingItem(info, container, screenId, cell, spanX, spanY); |
| 4179 | } |
| 4180 | }); |
| 4181 | } |
| 4182 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4183 | private boolean shouldShowWeightWatcher() { |
| 4184 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4185 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b800 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 4186 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4187 | |
| 4188 | return show; |
| 4189 | } |
| 4190 | |
| 4191 | private void toggleShowWeightWatcher() { |
| 4192 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4193 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 4194 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 4195 | |
| 4196 | show = !show; |
| 4197 | |
| 4198 | SharedPreferences.Editor editor = sp.edit(); |
| 4199 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 4200 | editor.commit(); |
| 4201 | |
| 4202 | if (mWeightWatcher != null) { |
| 4203 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 4204 | } |
| 4205 | } |
| 4206 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4207 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 4208 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4209 | final ArrayList<ItemInfo> addAnimated, |
| 4210 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4211 | Runnable r = new Runnable() { |
| 4212 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4213 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4214 | } |
| 4215 | }; |
| 4216 | if (waitUntilResume(r)) { |
| 4217 | return; |
| 4218 | } |
| 4219 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4220 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4221 | if (newScreens != null) { |
| 4222 | bindAddScreens(newScreens); |
| 4223 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4224 | |
| 4225 | // We add the items without animation on non-visible pages, and with |
| 4226 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4227 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4228 | bindItems(addNotAnimated, 0, |
| 4229 | addNotAnimated.size(), false); |
| 4230 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4231 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4232 | bindItems(addAnimated, 0, |
| 4233 | addAnimated.size(), true); |
| 4234 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4235 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4236 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 4237 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4238 | |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 4239 | if (addedApps != null && mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4240 | mAppsCustomizeContent.addApps(addedApps); |
| 4241 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4242 | } |
| 4243 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4244 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4245 | * Bind the items start-end from the list. |
| 4246 | * |
| 4247 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4248 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4249 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 4250 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4251 | Runnable r = new Runnable() { |
| 4252 | public void run() { |
| 4253 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 4254 | } |
| 4255 | }; |
| 4256 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4257 | return; |
| 4258 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4259 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4260 | // 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] | 4261 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 4262 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4263 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4264 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4265 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4266 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4267 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4268 | |
| 4269 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4270 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4271 | mHotseat == null) { |
| 4272 | continue; |
| 4273 | } |
| 4274 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4275 | switch (item.itemType) { |
| 4276 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4277 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4278 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4279 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4280 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4281 | /* |
| 4282 | * TODO: FIX collision case |
| 4283 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4284 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4285 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4286 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4287 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4288 | Object tag = v.getTag(); |
| 4289 | String desc = "Collision while binding workspace item: " + item |
| 4290 | + ". Collides with " + tag; |
| 4291 | if (LauncherAppState.isDogfoodBuild()) { |
| 4292 | throw (new RuntimeException(desc)); |
| 4293 | } else { |
| 4294 | Log.d(TAG, desc); |
| 4295 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4296 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4299 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4300 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4301 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4302 | // Animate all the applications up now |
| 4303 | shortcut.setAlpha(0f); |
| 4304 | shortcut.setScaleX(0f); |
| 4305 | shortcut.setScaleY(0f); |
| 4306 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4307 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4308 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4309 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4310 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4311 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4312 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4313 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4314 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4315 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4316 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4317 | default: |
| 4318 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4319 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4320 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4321 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4322 | if (animateIcons) { |
| 4323 | // Animate to the correct page |
| 4324 | if (newShortcutsScreenId > -1) { |
| 4325 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4326 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4327 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4328 | public void run() { |
| 4329 | anim.playTogether(bounceAnims); |
| 4330 | anim.start(); |
| 4331 | } |
| 4332 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4333 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4334 | // We post the animation slightly delayed to prevent slowdowns |
| 4335 | // when we are loading right after we return to launcher. |
| 4336 | mWorkspace.postDelayed(new Runnable() { |
| 4337 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4338 | if (mWorkspace != null) { |
| 4339 | mWorkspace.snapToPage(newScreenIndex); |
| 4340 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4341 | NEW_APPS_ANIMATION_DELAY); |
| 4342 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4343 | } |
| 4344 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4345 | } else { |
| 4346 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4347 | } |
| 4348 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4349 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4350 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4351 | } |
| 4352 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4353 | /** |
| 4354 | * Implementation of the method from LauncherModel.Callbacks. |
| 4355 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4356 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4357 | Runnable r = new Runnable() { |
| 4358 | public void run() { |
| 4359 | bindFolders(folders); |
| 4360 | } |
| 4361 | }; |
| 4362 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4363 | return; |
| 4364 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4365 | sFolders.clear(); |
| 4366 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4367 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4368 | |
| 4369 | /** |
| 4370 | * Add the views for a widget to the workspace. |
| 4371 | * |
| 4372 | * Implementation of the method from LauncherModel.Callbacks. |
| 4373 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4374 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4375 | Runnable r = new Runnable() { |
| 4376 | public void run() { |
| 4377 | bindAppWidget(item); |
| 4378 | } |
| 4379 | }; |
| 4380 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4381 | return; |
| 4382 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4383 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4384 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4385 | if (DEBUG_WIDGETS) { |
| 4386 | Log.d(TAG, "bindAppWidget: " + item); |
| 4387 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4388 | final Workspace workspace = mWorkspace; |
| 4389 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4390 | LauncherAppWidgetProviderInfo appWidgetInfo = |
| 4391 | LauncherModel.getProviderInfo(this, item.providerName); |
| 4392 | |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4393 | if (!mIsSafeModeEnabled |
| 4394 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) |
| 4395 | && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4396 | if (appWidgetInfo == null) { |
| 4397 | if (DEBUG_WIDGETS) { |
| 4398 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4399 | + " belongs to component " + item.providerName |
| 4400 | + ", as the povider is null"); |
| 4401 | } |
| 4402 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4403 | return; |
| 4404 | } |
| 4405 | // Note: This assumes that the id remap broadcast is received before this step. |
| 4406 | // If that is not the case, the id remap will be ignored and user may see the |
| 4407 | // click to setup view. |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4408 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4409 | pendingInfo.spanX = item.spanX; |
| 4410 | pendingInfo.spanY = item.spanY; |
| 4411 | pendingInfo.minSpanX = item.minSpanX; |
| 4412 | pendingInfo.minSpanY = item.minSpanY; |
| 4413 | Bundle options = |
| 4414 | AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo); |
| 4415 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4416 | int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 4417 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 4418 | newWidgetId, appWidgetInfo, options); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4419 | |
| 4420 | // TODO consider showing a permission dialog when the widget is clicked. |
| 4421 | if (!success) { |
| 4422 | mAppWidgetHost.deleteAppWidgetId(newWidgetId); |
| 4423 | if (DEBUG_WIDGETS) { |
| 4424 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4425 | + " belongs to component " + item.providerName |
| 4426 | + ", as the launcher is unable to bing a new widget id"); |
| 4427 | } |
| 4428 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4429 | return; |
| 4430 | } |
| 4431 | |
| 4432 | item.appWidgetId = newWidgetId; |
| 4433 | |
| 4434 | // If the widget has a configure activity, it is still needs to set it up, otherwise |
| 4435 | // the widget is ready to go. |
| 4436 | item.restoreStatus = (appWidgetInfo.configure == null) |
| 4437 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 4438 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 4439 | |
| 4440 | LauncherModel.updateItemInDatabase(this, item); |
| 4441 | } |
| 4442 | |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4443 | if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4444 | final int appWidgetId = item.appWidgetId; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4445 | if (DEBUG_WIDGETS) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4446 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " |
| 4447 | + appWidgetInfo.provider); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4448 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4449 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4450 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4451 | } else { |
| 4452 | appWidgetInfo = null; |
Sunny Goyal | 9b4b081 | 2014-10-08 10:47:28 -0700 | [diff] [blame] | 4453 | PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, |
| 4454 | mIsSafeModeEnabled); |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4455 | view.updateIcon(mIconCache); |
| 4456 | item.hostView = view; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4457 | item.hostView.updateAppWidget(null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4458 | item.hostView.setOnClickListener(this); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4459 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4460 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4461 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4462 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4463 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4464 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4465 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4466 | if (!item.isCustomWidget()) { |
| 4467 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4468 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4469 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4470 | workspace.requestLayout(); |
| 4471 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4472 | if (DEBUG_WIDGETS) { |
| 4473 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4474 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4475 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4476 | } |
| 4477 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4478 | /** |
| 4479 | * Restores a pending widget. |
| 4480 | * |
| 4481 | * @param appWidgetId The app widget id |
| 4482 | * @param cellInfo The position on screen where to create the widget. |
| 4483 | */ |
| 4484 | private void completeRestoreAppWidget(final int appWidgetId) { |
| 4485 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 4486 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 4487 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
| 4488 | return; |
| 4489 | } |
| 4490 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4491 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4492 | info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 4493 | |
| 4494 | mWorkspace.reinflateWidgetsIfNecessary(); |
| 4495 | LauncherModel.updateItemInDatabase(this, info); |
| 4496 | } |
| 4497 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4498 | public void onPageBoundSynchronously(int page) { |
| 4499 | mSynchronouslyBoundPages.add(page); |
| 4500 | } |
| 4501 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4502 | /** |
| 4503 | * Callback saying that there aren't any more items to bind. |
| 4504 | * |
| 4505 | * Implementation of the method from LauncherModel.Callbacks. |
| 4506 | */ |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 4507 | public void finishBindingItems() { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4508 | Runnable r = new Runnable() { |
| 4509 | public void run() { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 4510 | finishBindingItems(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4511 | } |
| 4512 | }; |
| 4513 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4514 | return; |
| 4515 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4516 | if (mSavedState != null) { |
| 4517 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4518 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4519 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4520 | mSavedState = null; |
| 4521 | } |
| 4522 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4523 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4524 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4525 | setWorkspaceLoading(false); |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4526 | sendLoadingCompleteBroadcastIfNecessary(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 4527 | |
| 4528 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4529 | // widget configuration forced an orientation change), process them now. |
| 4530 | if (sPendingAddItem != null) { |
| 4531 | final long screenId = completeAdd(sPendingAddItem); |
| 4532 | |
| 4533 | // TODO: this moves the user to the page where the pending item was added. Ideally, |
| 4534 | // the screen would be guaranteed to exist after bind, and the page would be set through |
| 4535 | // the workspace restore process. |
| 4536 | mWorkspace.post(new Runnable() { |
| 4537 | @Override |
| 4538 | public void run() { |
| 4539 | mWorkspace.snapToScreenId(screenId); |
| 4540 | } |
| 4541 | }); |
| 4542 | sPendingAddItem = null; |
| 4543 | } |
| 4544 | |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4545 | PackageInstallerCompat.getInstance(this).onFinishBind(); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4546 | |
| 4547 | if (mLauncherCallbacks != null) { |
Sunny Goyal | 66cfdc2 | 2015-02-02 13:01:51 -0800 | [diff] [blame] | 4548 | mLauncherCallbacks.finishBindingItems(false); |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4549 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4550 | } |
| 4551 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4552 | private void sendLoadingCompleteBroadcastIfNecessary() { |
| 4553 | if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) { |
| 4554 | String permission = |
| 4555 | getResources().getString(R.string.receive_first_load_broadcast_permission); |
| 4556 | Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE); |
| 4557 | sendBroadcast(intent, permission); |
| 4558 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4559 | editor.putBoolean(FIRST_LOAD_COMPLETE, true); |
| 4560 | editor.apply(); |
| 4561 | } |
| 4562 | } |
| 4563 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4564 | public boolean isAllAppsButtonRank(int rank) { |
| 4565 | if (mHotseat != null) { |
| 4566 | return mHotseat.isAllAppsButtonRank(rank); |
| 4567 | } |
| 4568 | return false; |
| 4569 | } |
| 4570 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4571 | private boolean canRunNewAppsAnimation() { |
| 4572 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4573 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4574 | } |
| 4575 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4576 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4577 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4578 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4579 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4580 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4581 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4582 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4583 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4584 | return bounceAnim; |
| 4585 | } |
| 4586 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4587 | public boolean useVerticalBarLayout() { |
| 4588 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4589 | getDeviceProfile().isVerticalBarLayout(); |
| 4590 | } |
| 4591 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4592 | protected Rect getSearchBarBounds() { |
| 4593 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4594 | getDeviceProfile().getSearchBarBounds(); |
| 4595 | } |
| 4596 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4597 | public void bindSearchablesChanged() { |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 4598 | if (mSearchDropTargetBar == null) { |
| 4599 | return; |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4600 | } |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 4601 | if (mQsb != null) { |
| 4602 | mSearchDropTargetBar.removeView(mQsb); |
| 4603 | mQsb = null; |
| 4604 | } |
| 4605 | mSearchDropTargetBar.setQsbSearchBar(getQsbBar()); |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4606 | } |
| 4607 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4608 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4609 | * Add the icons for all apps. |
| 4610 | * |
| 4611 | * Implementation of the method from LauncherModel.Callbacks. |
| 4612 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4613 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 4614 | if (mAppsCustomizeContent != null) { |
| 4615 | mAppsCustomizeContent.setApps(apps); |
| 4616 | mAppsCustomizeContent.onPackagesUpdated( |
| 4617 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4618 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4619 | if (mLauncherCallbacks != null) { |
| 4620 | mLauncherCallbacks.bindAllApplications(apps); |
| 4621 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | /** |
| 4625 | * A package was updated. |
| 4626 | * |
| 4627 | * Implementation of the method from LauncherModel.Callbacks. |
| 4628 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4629 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4630 | Runnable r = new Runnable() { |
| 4631 | public void run() { |
| 4632 | bindAppsUpdated(apps); |
| 4633 | } |
| 4634 | }; |
| 4635 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4636 | return; |
| 4637 | } |
| 4638 | |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 4639 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4640 | mAppsCustomizeContent.updateApps(apps); |
| 4641 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4642 | } |
| 4643 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4644 | @Override |
| 4645 | public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) { |
| 4646 | Runnable r = new Runnable() { |
| 4647 | public void run() { |
| 4648 | bindWidgetsRestored(widgets); |
| 4649 | } |
| 4650 | }; |
| 4651 | if (waitUntilResume(r)) { |
| 4652 | return; |
| 4653 | } |
| 4654 | mWorkspace.widgetsRestored(widgets); |
| 4655 | } |
| 4656 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4657 | /** |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4658 | * Some shortcuts were updated in the background. |
| 4659 | * |
| 4660 | * Implementation of the method from LauncherModel.Callbacks. |
| 4661 | */ |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4662 | @Override |
| 4663 | public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated, |
| 4664 | final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) { |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4665 | Runnable r = new Runnable() { |
| 4666 | public void run() { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4667 | bindShortcutsChanged(updated, removed, user); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4668 | } |
| 4669 | }; |
| 4670 | if (waitUntilResume(r)) { |
| 4671 | return; |
| 4672 | } |
| 4673 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4674 | if (!updated.isEmpty()) { |
| 4675 | mWorkspace.updateShortcuts(updated); |
| 4676 | } |
| 4677 | |
| 4678 | if (!removed.isEmpty()) { |
| 4679 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 4680 | for (ShortcutInfo si : removed) { |
| 4681 | removedComponents.add(si.getTargetComponent()); |
| 4682 | } |
| 4683 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
| 4684 | // Notify the drag controller |
| 4685 | mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4686 | } |
| 4687 | } |
| 4688 | |
| 4689 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4690 | * Update the state of a package, typically related to install state. |
| 4691 | * |
| 4692 | * Implementation of the method from LauncherModel.Callbacks. |
| 4693 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4694 | @Override |
| 4695 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4696 | if (mWorkspace != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4697 | mWorkspace.updatePackageState(installInfo); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4698 | } |
| 4699 | } |
| 4700 | |
| 4701 | /** |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 4702 | * Update the label and icon of all the icons in a package |
| 4703 | * |
| 4704 | * Implementation of the method from LauncherModel.Callbacks. |
| 4705 | */ |
| 4706 | @Override |
| 4707 | public void updatePackageBadge(String packageName) { |
| 4708 | if (mWorkspace != null) { |
| 4709 | mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle()); |
| 4710 | } |
| 4711 | } |
| 4712 | |
| 4713 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4714 | * A package was uninstalled. We take both the super set of packageNames |
| 4715 | * in addition to specific applications to remove, the reason being that |
| 4716 | * this can be called when a package is updated as well. In that scenario, |
| 4717 | * we only remove specific components from the workspace, where as |
| 4718 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4719 | * |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4720 | * @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] | 4721 | * Implementation of the method from LauncherModel.Callbacks. |
| 4722 | */ |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4723 | @Override |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4724 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4725 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4726 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4727 | public void run() { |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4728 | bindComponentsRemoved(packageNames, appInfos, user, reason); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4729 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4730 | }; |
| 4731 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4732 | return; |
| 4733 | } |
| 4734 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4735 | if (reason == 0) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4736 | HashSet<ComponentName> removedComponents = new HashSet<ComponentName>(); |
| 4737 | for (AppInfo info : appInfos) { |
| 4738 | removedComponents.add(info.componentName); |
| 4739 | } |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4740 | if (!packageNames.isEmpty()) { |
| 4741 | mWorkspace.removeItemsByPackageName(packageNames, user); |
| 4742 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4743 | if (!removedComponents.isEmpty()) { |
| 4744 | mWorkspace.removeItemsByComponentName(removedComponents, user); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4745 | } |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4746 | // Notify the drag controller |
| 4747 | mDragController.onAppsRemoved(packageNames, removedComponents); |
| 4748 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4749 | } else { |
| 4750 | mWorkspace.disableShortcutsByPackageName(packageNames, user, reason); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 4751 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4752 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4753 | // Update AllApps |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 4754 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4755 | mAppsCustomizeContent.removeApps(appInfos); |
| 4756 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4757 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4758 | |
| 4759 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4760 | * A number of packages were updated. |
| 4761 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4762 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 4763 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4764 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4765 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 4766 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4767 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4768 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4769 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 4770 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 4771 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4772 | return; |
| 4773 | } |
| 4774 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4775 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4776 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4777 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4778 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4779 | } |
| 4780 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4781 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 4782 | final Display d = getWindowManager().getDefaultDisplay(); |
| 4783 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 4784 | switch (d.getRotation()) { |
| 4785 | case Surface.ROTATION_0: |
| 4786 | case Surface.ROTATION_180: |
| 4787 | // We are currently in the same basic orientation as the natural orientation |
| 4788 | naturalOri = configOri; |
| 4789 | break; |
| 4790 | case Surface.ROTATION_90: |
| 4791 | case Surface.ROTATION_270: |
| 4792 | // We are currently in the other basic orientation to the natural orientation |
| 4793 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 4794 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 4795 | break; |
| 4796 | } |
| 4797 | |
| 4798 | int[] oriMap = { |
| 4799 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 4800 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 4801 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 4802 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 4803 | }; |
| 4804 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 4805 | // is landscape. |
| 4806 | int indexOffset = 0; |
| 4807 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 4808 | indexOffset = 1; |
| 4809 | } |
| 4810 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 4811 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 4812 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4813 | public void lockScreenOrientation() { |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 4814 | if (Utilities.isRotationEnabled(this)) { |
Sunny Goyal | 3c1865a | 2015-02-10 14:28:44 -0800 | [diff] [blame] | 4815 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { |
| 4816 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 4817 | .getConfiguration().orientation)); |
| 4818 | } else { |
| 4819 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
| 4820 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4821 | } |
| 4822 | } |
| 4823 | public void unlockScreenOrientation(boolean immediate) { |
Sunny Goyal | 4bbf419 | 2014-11-11 12:23:59 -0800 | [diff] [blame] | 4824 | if (Utilities.isRotationEnabled(this)) { |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4825 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4826 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4827 | } else { |
| 4828 | mHandler.postDelayed(new Runnable() { |
| 4829 | public void run() { |
| 4830 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 4831 | } |
| 4832 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4833 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4834 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4835 | } |
| 4836 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4837 | protected boolean isLauncherPreinstalled() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4838 | if (mLauncherCallbacks != null) { |
| 4839 | return mLauncherCallbacks.isLauncherPreinstalled(); |
| 4840 | } |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4841 | PackageManager pm = getPackageManager(); |
| 4842 | try { |
| 4843 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 4844 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4845 | return true; |
| 4846 | } else { |
| 4847 | return false; |
| 4848 | } |
| 4849 | } catch (NameNotFoundException e) { |
| 4850 | e.printStackTrace(); |
| 4851 | return false; |
| 4852 | } |
| 4853 | } |
| 4854 | |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4855 | /** |
| 4856 | * This method indicates whether or not we should suggest default wallpaper dimensions |
| 4857 | * when our wallpaper cropper was not yet used to set a wallpaper. |
| 4858 | */ |
| 4859 | protected boolean overrideWallpaperDimensions() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4860 | if (mLauncherCallbacks != null) { |
| 4861 | return mLauncherCallbacks.overrideWallpaperDimensions(); |
| 4862 | } |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4863 | return true; |
| 4864 | } |
| 4865 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4866 | /** |
| 4867 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 4868 | * before showing the standard launcher experience. |
| 4869 | */ |
| 4870 | protected boolean hasFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4871 | if (mLauncherCallbacks != null) { |
| 4872 | return mLauncherCallbacks.hasFirstRunActivity(); |
| 4873 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4874 | return false; |
| 4875 | } |
| 4876 | |
| 4877 | /** |
| 4878 | * To be overridden by subclasses to launch any first run activity |
| 4879 | */ |
| 4880 | protected Intent getFirstRunActivity() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4881 | if (mLauncherCallbacks != null) { |
| 4882 | return mLauncherCallbacks.getFirstRunActivity(); |
| 4883 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4884 | return null; |
| 4885 | } |
| 4886 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4887 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4888 | return !ActivityManager.isRunningInTestHarness() && |
| 4889 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4890 | } |
| 4891 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 4892 | protected boolean hasRunFirstRunActivity() { |
| 4893 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 4894 | } |
| 4895 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4896 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4897 | if (shouldRunFirstRunActivity() && |
| 4898 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4899 | Intent firstRunIntent = getFirstRunActivity(); |
| 4900 | if (firstRunIntent != null) { |
| 4901 | startActivity(firstRunIntent); |
| 4902 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4903 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4904 | } |
| 4905 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4906 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4907 | } |
| 4908 | |
| 4909 | private void markFirstRunActivityShown() { |
| 4910 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4911 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 4912 | editor.apply(); |
| 4913 | } |
| 4914 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4915 | /** |
| 4916 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 4917 | * screen that must be displayed and dismissed. |
| 4918 | */ |
| 4919 | protected boolean hasDismissableIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4920 | if (mLauncherCallbacks != null) { |
| 4921 | return mLauncherCallbacks.hasDismissableIntroScreen(); |
| 4922 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4923 | return false; |
| 4924 | } |
| 4925 | |
| 4926 | /** |
| 4927 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 4928 | */ |
| 4929 | protected View getIntroScreen() { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 4930 | if (mLauncherCallbacks != null) { |
| 4931 | return mLauncherCallbacks.getIntroScreen(); |
| 4932 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4933 | return null; |
| 4934 | } |
| 4935 | |
| 4936 | /** |
| 4937 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 4938 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 4939 | */ |
| 4940 | private boolean shouldShowIntroScreen() { |
| 4941 | return hasDismissableIntroScreen() && |
| 4942 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 4943 | } |
| 4944 | |
| 4945 | protected void showIntroScreen() { |
| 4946 | View introScreen = getIntroScreen(); |
| 4947 | changeWallpaperVisiblity(false); |
| 4948 | if (introScreen != null) { |
| 4949 | mDragLayer.showOverlayView(introScreen); |
| 4950 | } |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 4951 | if (mLauncherOverlayContainer != null) { |
| 4952 | mLauncherOverlayContainer.setVisibility(View.INVISIBLE); |
| 4953 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | public void dismissIntroScreen() { |
| 4957 | markIntroScreenDismissed(); |
| 4958 | if (showFirstRunActivity()) { |
| 4959 | // We delay hiding the intro view until the first run activity is showing. This |
| 4960 | // avoids a blip. |
| 4961 | mWorkspace.postDelayed(new Runnable() { |
| 4962 | @Override |
| 4963 | public void run() { |
| 4964 | mDragLayer.dismissOverlayView(); |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 4965 | if (mLauncherOverlayContainer != null) { |
| 4966 | mLauncherOverlayContainer.setVisibility(View.VISIBLE); |
| 4967 | } |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 4968 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4969 | } |
| 4970 | }, ACTIVITY_START_DELAY); |
| 4971 | } else { |
| 4972 | mDragLayer.dismissOverlayView(); |
Adam Cohen | c3e12c7 | 2014-10-31 16:15:36 -0700 | [diff] [blame] | 4973 | if (mLauncherOverlayContainer != null) { |
| 4974 | mLauncherOverlayContainer.setVisibility(View.VISIBLE); |
| 4975 | } |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 4976 | showFirstRunClings(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4977 | } |
| 4978 | changeWallpaperVisiblity(true); |
| 4979 | } |
| 4980 | |
| 4981 | private void markIntroScreenDismissed() { |
| 4982 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4983 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 4984 | editor.apply(); |
| 4985 | } |
| 4986 | |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 4987 | private void showFirstRunClings() { |
| 4988 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 4989 | // on the device, then we always show the first run cling experience (or if there is no |
| 4990 | // launcher2). Otherwise, we prompt the user upon started for migration |
| 4991 | LauncherClings launcherClings = new LauncherClings(this); |
| 4992 | if (launcherClings.shouldShowFirstRunOrMigrationClings()) { |
| 4993 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
| 4994 | launcherClings.showMigrationCling(); |
| 4995 | } else { |
Sunny Goyal | af0628f | 2014-09-19 10:14:48 -0700 | [diff] [blame] | 4996 | launcherClings.showLongPressCling(true); |
Sunny Goyal | 88d60f1 | 2014-09-08 03:47:29 -0700 | [diff] [blame] | 4997 | } |
| 4998 | } |
| 4999 | } |
| 5000 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5001 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 5002 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 5003 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 5004 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 5005 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 5009 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 5010 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 5011 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 5012 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 5013 | } |
| 5014 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5015 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5016 | // Called from search suggestion, not supported in other profiles. |
| 5017 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 5018 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 5019 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 5020 | myUser); |
| 5021 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5022 | return null; |
| 5023 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 5024 | return new AppInfo(this, activityInfo, myUser, mIconCache); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5028 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 5029 | // Called from search suggestion, not supported in other profiles. |
| 5030 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 5031 | UserHandleCompat.myUserHandle()); |
| 5032 | } |
| 5033 | |
| 5034 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 5035 | Bitmap icon, UserHandleCompat user) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5036 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 5037 | CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 5038 | return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5039 | } |
| 5040 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 5041 | protected void moveWorkspaceToDefaultScreen() { |
| 5042 | mWorkspace.moveToDefaultScreen(false); |
| 5043 | } |
| 5044 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5045 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 5046 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 5047 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 5048 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 5049 | } |
| 5050 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5051 | @Override |
| 5052 | public void onPageSwitch(View newPage, int newPageIndex) { |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5053 | if (mLauncherCallbacks != null) { |
| 5054 | mLauncherCallbacks.onPageSwitch(newPage, newPageIndex); |
| 5055 | } |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 5056 | } |
| 5057 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 5058 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5059 | * Prints out out state for debugging. |
| 5060 | */ |
| 5061 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5062 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5063 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 5064 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 5065 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 5066 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 5067 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 5068 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5069 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 5070 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 5071 | if (mAppsCustomizeContent != null) { |
| 5072 | mAppsCustomizeContent.dumpState(); |
| 5073 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 5074 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 5075 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5076 | |
| 5077 | @Override |
| 5078 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5079 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5080 | synchronized (sDumpLogs) { |
| 5081 | writer.println(" "); |
| 5082 | writer.println("Debug logs: "); |
| 5083 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5084 | writer.println(" " + sDumpLogs.get(i)); |
| 5085 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5086 | } |
Adam Cohen | 9211d42 | 2014-10-07 18:14:53 -0700 | [diff] [blame] | 5087 | if (mLauncherCallbacks != null) { |
| 5088 | mLauncherCallbacks.dump(prefix, fd, writer, args); |
| 5089 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 5090 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5091 | |
| 5092 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5093 | if (DEBUG_DUMP_LOG) { |
| 5094 | synchronized (sDumpLogs) { |
| 5095 | Log.d(TAG, ""); |
| 5096 | Log.d(TAG, "*********************"); |
| 5097 | Log.d(TAG, "Launcher debug logs: "); |
| 5098 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5099 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 5100 | } |
| 5101 | Log.d(TAG, "*********************"); |
| 5102 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5103 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5104 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5108 | addDumpLog(tag, log, null, debugLog); |
| 5109 | } |
| 5110 | |
| 5111 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5112 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5113 | if (e != null) { |
| 5114 | Log.d(tag, log, e); |
| 5115 | } else { |
| 5116 | Log.d(tag, log); |
| 5117 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5118 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5119 | if (DEBUG_DUMP_LOG) { |
| 5120 | sDateStamp.setTime(System.currentTimeMillis()); |
| 5121 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5122 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 5123 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5124 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5125 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5126 | } |
| 5127 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 5128 | public static CustomAppWidget getCustomAppWidget(String name) { |
| 5129 | return sCustomAppWidgets.get(name); |
| 5130 | } |
| 5131 | |
| 5132 | public static HashMap<String, CustomAppWidget> getCustomAppWidgets() { |
| 5133 | return sCustomAppWidgets; |
| 5134 | } |
| 5135 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5136 | public void dumpLogsToLocalData() { |
| 5137 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5138 | new AsyncTask<Void, Void, Void>() { |
| 5139 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5140 | boolean success = false; |
| 5141 | sDateStamp.setTime(sRunStart); |
| 5142 | String FILENAME = sDateStamp.getMonth() + "-" |
| 5143 | + sDateStamp.getDay() + "_" |
| 5144 | + sDateStamp.getHours() + "-" |
| 5145 | + sDateStamp.getMinutes() + "_" |
| 5146 | + sDateStamp.getSeconds() + ".txt"; |
| 5147 | |
| 5148 | FileOutputStream fos = null; |
| 5149 | File outFile = null; |
| 5150 | try { |
| 5151 | outFile = new File(getFilesDir(), FILENAME); |
| 5152 | outFile.createNewFile(); |
| 5153 | fos = new FileOutputStream(outFile); |
| 5154 | } catch (Exception e) { |
| 5155 | e.printStackTrace(); |
| 5156 | } |
| 5157 | if (fos != null) { |
| 5158 | PrintWriter writer = new PrintWriter(fos); |
| 5159 | |
| 5160 | writer.println(" "); |
| 5161 | writer.println("Debug logs: "); |
| 5162 | synchronized (sDumpLogs) { |
| 5163 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5164 | writer.println(" " + sDumpLogs.get(i)); |
| 5165 | } |
| 5166 | } |
| 5167 | writer.close(); |
| 5168 | } |
| 5169 | try { |
| 5170 | if (fos != null) { |
| 5171 | fos.close(); |
| 5172 | success = true; |
| 5173 | } |
| 5174 | } catch (IOException e) { |
| 5175 | e.printStackTrace(); |
| 5176 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5177 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5178 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5179 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5180 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5181 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5182 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5183 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 5184 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 5185 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 5186 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5187 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 5188 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5189 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5190 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 5191 | |
| 5192 | interface DebugIntents { |
| 5193 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 5194 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 5195 | } |