Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 18 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 20 | import android.animation.Animator; |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 21 | import android.animation.AnimatorListenerAdapter; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 22 | import android.animation.AnimatorSet; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
| 24 | import android.animation.PropertyValuesHolder; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 25 | import android.animation.ValueAnimator; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 26 | import android.annotation.TargetApi; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 27 | import android.app.Activity; |
Brett Chabot | 2a9e228 | 2011-08-23 15:03:13 -0700 | [diff] [blame] | 28 | import android.app.ActivityManager; |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 29 | import android.app.ActivityOptions; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 30 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | import android.app.SearchManager; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 32 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 33 | import android.appwidget.AppWidgetManager; |
| 34 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 35 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 36 | import android.content.BroadcastReceiver; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 37 | import android.content.ComponentCallbacks2; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 38 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 39 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 40 | import android.content.Context; |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 41 | import android.content.DialogInterface; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 43 | import android.content.IntentFilter; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 44 | import android.content.SharedPreferences; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 45 | import android.content.pm.ActivityInfo; |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 46 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 47 | import android.content.pm.PackageManager; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 49 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 50 | import android.content.res.Resources; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 51 | import android.database.ContentObserver; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 52 | import android.graphics.Bitmap; |
| 53 | import android.graphics.Canvas; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame] | 54 | import android.graphics.Color; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 55 | import android.graphics.Point; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 56 | import android.graphics.PorterDuff; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 57 | import android.graphics.Rect; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 58 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 59 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 60 | import android.os.AsyncTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 61 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 62 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 63 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 64 | import android.os.Message; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 65 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 66 | import android.os.SystemClock; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 67 | import android.speech.RecognizerIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 68 | import android.text.Selection; |
| 69 | import android.text.SpannableStringBuilder; |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 70 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 71 | import android.text.method.TextKeyListener; |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 72 | import android.util.DisplayMetrics; |
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 | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 85 | import android.view.ViewGroup; |
| 86 | import android.view.ViewTreeObserver; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 87 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 88 | import android.view.Window; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 89 | import android.view.WindowManager; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 90 | import android.view.accessibility.AccessibilityEvent; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 91 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 92 | import android.view.animation.DecelerateInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 93 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 94 | import android.widget.Advanceable; |
| 95 | import android.widget.FrameLayout; |
| 96 | import android.widget.ImageView; |
| 97 | import android.widget.TextView; |
| 98 | import android.widget.Toast; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 99 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 100 | import com.android.launcher3.DropTarget.DragObject; |
| 101 | import com.android.launcher3.PagedView.PageSwitchListener; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 102 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 103 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 104 | import com.android.launcher3.compat.LauncherAppsCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 105 | import com.android.launcher3.compat.PackageInstallerCompat; |
| 106 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 107 | import com.android.launcher3.compat.UserHandleCompat; |
| 108 | import com.android.launcher3.compat.UserManagerCompat; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 109 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 110 | import java.io.DataInputStream; |
| 111 | import java.io.DataOutputStream; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 112 | import java.io.File; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 113 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 114 | import java.io.FileNotFoundException; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 115 | import java.io.FileOutputStream; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 116 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 117 | import java.io.PrintWriter; |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 118 | import java.lang.reflect.Field; |
| 119 | import java.lang.reflect.InvocationTargetException; |
| 120 | import java.lang.reflect.Method; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 121 | import java.text.DateFormat; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 122 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 123 | import java.util.Collection; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 124 | import java.util.Date; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 125 | import java.util.HashMap; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 126 | import java.util.List; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 127 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 128 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 129 | /** |
| 130 | * Default launcher application. |
| 131 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 132 | public class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 133 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 134 | View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 135 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 136 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 137 | |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 138 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 139 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 140 | static final boolean DEBUG_STRICT_MODE = false; |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 141 | static final boolean DEBUG_RESUME_TIME = false; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 142 | static final boolean DEBUG_DUMP_LOG = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 143 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 144 | static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run |
| 145 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 146 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 147 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 148 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 149 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 150 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 151 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 152 | private static final int REQUEST_BIND_APPWIDGET = 11; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 153 | private static final int REQUEST_RECONFIGURE_APPWIDGET = 12; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 154 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 155 | /** |
| 156 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 157 | * request codes used internally. |
| 158 | */ |
| 159 | protected static final int REQUEST_LAST = 100; |
| 160 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 161 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 162 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 163 | static final int SCREEN_COUNT = 5; |
| 164 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 165 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 166 | private static final String PREFERENCES = "launcher.preferences"; |
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] |
| 169 | static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate"; |
| 170 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 171 | static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 172 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 173 | // The Intent extra that defines whether to ignore the launch animation |
| 174 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 175 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 176 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 177 | // Type: int |
| 178 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 179 | // Type: int |
| 180 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 181 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 182 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 183 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 184 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 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_X = "launcher.add_cell_x"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 187 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 188 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 189 | // Type: boolean |
| 190 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 191 | // Type: long |
| 192 | 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] | 193 | // Type: int |
| 194 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 195 | // Type: int |
| 196 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 197 | // Type: parcelable |
| 198 | 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] | 199 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 200 | 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] | 201 | // Type: int[] |
| 202 | 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] | 203 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 204 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 205 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 206 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 207 | static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete"; |
| 208 | static final String ACTION_FIRST_LOAD_COMPLETE = |
| 209 | "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; |
| 210 | |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 211 | private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 212 | private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 213 | "com.android.launcher.toolbar_search_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 214 | private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 215 | "com.android.launcher.toolbar_voice_search_icon"; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 216 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 217 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 218 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 219 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 220 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 221 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 222 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 223 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 224 | private State mState = State.WORKSPACE; |
| 225 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 226 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 227 | private boolean mIsSafeModeEnabled; |
| 228 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 229 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 230 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 231 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 232 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 233 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 234 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 235 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 236 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 237 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 238 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 239 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 240 | // 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] | 241 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 242 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 243 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 244 | private static final int SINGLE_FRAME_DELAY = 16; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 245 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 246 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 247 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 248 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 249 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 250 | private LayoutInflater mInflater; |
| 251 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 252 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 253 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 254 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 255 | private DragLayer mDragLayer; |
| 256 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 257 | private View mWeightWatcher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 258 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 259 | private AppWidgetManagerCompat mAppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 260 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 261 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 262 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 263 | private AppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 264 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 265 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 266 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 267 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 268 | private FolderInfo mFolderInfo; |
| 269 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 270 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 271 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 272 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 273 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 274 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 275 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 276 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 277 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 278 | private boolean mAutoAdvanceRunning = false; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 279 | private View mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 280 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 281 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 282 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 283 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 284 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 285 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 286 | |
| 287 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 288 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 289 | private boolean mWorkspaceLoading = true; |
| 290 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 291 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 292 | private boolean mRestoring; |
| 293 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 294 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 295 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 296 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 297 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 298 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 299 | private Bundle mSavedInstanceState; |
| 300 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 301 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 302 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 303 | private boolean mUserPresent = true; |
| 304 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 305 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 306 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 307 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 308 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 309 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 310 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 311 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 312 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 313 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 314 | // Related to the auto-advancing of widgets |
| 315 | private final int ADVANCE_MSG = 1; |
| 316 | private final int mAdvanceInterval = 20000; |
| 317 | private final int mAdvanceStagger = 250; |
| 318 | private long mAutoAdvanceSentTime; |
| 319 | private long mAutoAdvanceTimeLeft = -1; |
| 320 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 321 | new HashMap<View, AppWidgetProviderInfo>(); |
| 322 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 323 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 324 | // match the sensor state. |
| 325 | private final int mRestoreScreenOrientationDelay = 500; |
| 326 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 327 | // External icons saved in case of resource changes, orientation, etc. |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 328 | private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; |
| 329 | private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 330 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 331 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 332 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 333 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 334 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 335 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 336 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 337 | static Date sDateStamp = new Date(); |
| 338 | static DateFormat sDateFormat = |
| 339 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 340 | static long sRunStart = System.currentTimeMillis(); |
| 341 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 342 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 343 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 344 | // it from the context. |
| 345 | private SharedPreferences mSharedPrefs; |
| 346 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 347 | private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null; |
| 348 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 349 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 350 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 351 | private ImageView mFolderIconImageView; |
| 352 | private Bitmap mFolderIconBitmap; |
| 353 | private Canvas mFolderIconCanvas; |
| 354 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 355 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 356 | private BubbleTextView mWaitingForResume; |
| 357 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 358 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 359 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 360 | if (mWorkspace != null) { |
| 361 | mWorkspace.buildPageHardwareLayers(); |
| 362 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 363 | } |
| 364 | }; |
| 365 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 366 | private static PendingAddArguments sPendingAddItem; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 367 | |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 368 | public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 369 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 370 | private static class PendingAddArguments { |
| 371 | int requestCode; |
| 372 | Intent intent; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 373 | long container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 374 | long screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 375 | int cellX; |
| 376 | int cellY; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 377 | int appWidgetId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 380 | private Stats mStats; |
| 381 | |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 382 | FocusIndicatorView mFocusHandler; |
| 383 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 384 | static boolean isPropertyEnabled(String propertyName) { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 385 | return Log.isLoggable(propertyName, Log.VERBOSE); |
Michael Jurka | 9bc8eba | 2012-05-21 20:36:44 -0700 | [diff] [blame] | 386 | } |
| 387 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 388 | @Override |
| 389 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 390 | if (DEBUG_STRICT_MODE) { |
| 391 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 392 | .detectDiskReads() |
| 393 | .detectDiskWrites() |
| 394 | .detectNetwork() // or .detectAll() for all detectable problems |
| 395 | .penaltyLog() |
| 396 | .build()); |
| 397 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 398 | .detectLeakedSqlLiteObjects() |
| 399 | .detectLeakedClosableObjects() |
| 400 | .penaltyLog() |
| 401 | .penaltyDeath() |
| 402 | .build()); |
| 403 | } |
| 404 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 405 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 406 | |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 407 | LauncherAppState.setApplicationContext(getApplicationContext()); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 408 | LauncherAppState app = LauncherAppState.getInstance(); |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 409 | LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 410 | // Determine the dynamic grid properties |
| 411 | Point smallestSize = new Point(); |
| 412 | Point largestSize = new Point(); |
| 413 | Point realSize = new Point(); |
| 414 | Display display = getWindowManager().getDefaultDisplay(); |
| 415 | display.getCurrentSizeRange(smallestSize, largestSize); |
| 416 | display.getRealSize(realSize); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 417 | DisplayMetrics dm = new DisplayMetrics(); |
| 418 | display.getMetrics(dm); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 419 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 420 | // Lazy-initialize the dynamic grid |
| 421 | DeviceProfile grid = app.initDynamicGrid(this, |
| 422 | Math.min(smallestSize.x, smallestSize.y), |
| 423 | Math.min(largestSize.x, largestSize.y), |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 424 | realSize.x, realSize.y, |
| 425 | dm.widthPixels, dm.heightPixels); |
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 | updateGlobalIcons(); |
| 491 | |
| 492 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 493 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 494 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 495 | if (shouldShowIntroScreen()) { |
| 496 | showIntroScreen(); |
| 497 | } else { |
| 498 | showFirstRunActivity(); |
| 499 | } |
| 500 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 501 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 502 | // on the device, then we always show the first run cling experience (or if there is no |
| 503 | // launcher2). Otherwise, we prompt the user upon started for migration |
Sunny Goyal | 424418b | 2014-08-22 16:09:37 -0700 | [diff] [blame^] | 504 | LauncherClings launcherClings = new LauncherClings(this); |
| 505 | if (launcherClings.shouldShowFirstRunOrMigrationClings()) { |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 506 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
Sunny Goyal | 424418b | 2014-08-22 16:09:37 -0700 | [diff] [blame^] | 507 | launcherClings.showMigrationCling(); |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 508 | } else { |
Sunny Goyal | 424418b | 2014-08-22 16:09:37 -0700 | [diff] [blame^] | 509 | launcherClings.showLongPressCling(true); |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 510 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 511 | } |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 514 | @Override |
| 515 | public void onLauncherProviderChange() { } |
| 516 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 517 | /** To be overriden by subclasses to hint to Launcher that we have custom content */ |
| 518 | protected boolean hasCustomContentToLeft() { |
| 519 | return false; |
| 520 | } |
| 521 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 522 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 523 | * 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] | 524 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 525 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 526 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 527 | protected void populateCustomContentContainer() { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | /** |
| 531 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 532 | * ensure the custom content page is added or removed if necessary. |
| 533 | */ |
| 534 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 535 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 536 | // Not bound yet, wait for bindScreens to be called. |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 541 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 542 | mWorkspace.createCustomContentContainer(); |
| 543 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 544 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 545 | mWorkspace.removeCustomContentPage(); |
| 546 | } |
| 547 | } |
| 548 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 549 | private void updateGlobalIcons() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 550 | boolean searchVisible = false; |
| 551 | boolean voiceVisible = false; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 552 | // If we have a saved version of these external icons, we load them up immediately |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 553 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
Adam Cohen | a00673c | 2014-08-14 12:57:28 -0700 | [diff] [blame] | 554 | if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 555 | searchVisible = updateGlobalSearchIcon(); |
| 556 | voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 557 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 558 | if (sGlobalSearchIcon[coi] != null) { |
| 559 | updateGlobalSearchIcon(sGlobalSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 560 | searchVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 561 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 562 | if (sVoiceSearchIcon[coi] != null) { |
| 563 | updateVoiceSearchIcon(sVoiceSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 564 | voiceVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 565 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 566 | if (mSearchDropTargetBar != null) { |
| 567 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 568 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 569 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 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 { |
| 629 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 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 { |
| 651 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 652 | out.writeUTF(configuration.locale); |
| 653 | out.writeInt(configuration.mcc); |
| 654 | out.writeInt(configuration.mnc); |
| 655 | out.flush(); |
| 656 | } catch (FileNotFoundException e) { |
| 657 | // Ignore |
| 658 | } catch (IOException e) { |
| 659 | //noinspection ResultOfMethodCallIgnored |
| 660 | context.getFileStreamPath(PREFERENCES).delete(); |
| 661 | } finally { |
| 662 | if (out != null) { |
| 663 | try { |
| 664 | out.close(); |
| 665 | } catch (IOException e) { |
| 666 | // Ignore |
| 667 | } |
| 668 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 672 | public Stats getStats() { |
| 673 | return mStats; |
| 674 | } |
| 675 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 676 | public LayoutInflater getInflater() { |
| 677 | return mInflater; |
| 678 | } |
| 679 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 680 | boolean isDraggingEnabled() { |
| 681 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 682 | // that is subsequently removed from the workspace in startBinding(). |
| 683 | return !mModel.isLoadingWorkspace(); |
| 684 | } |
| 685 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 686 | static int getScreen() { |
| 687 | synchronized (sLock) { |
| 688 | return sScreen; |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | static void setScreen(int screen) { |
| 693 | synchronized (sLock) { |
| 694 | sScreen = screen; |
| 695 | } |
| 696 | } |
| 697 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 698 | /** |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 699 | * Copied from View -- the View version of the method isn't called |
| 700 | * anywhere else in our process and only exists for API level 17+, |
| 701 | * so it's ok to keep our own version with no API requirement. |
| 702 | */ |
| 703 | public static int generateViewId() { |
| 704 | for (;;) { |
| 705 | final int result = sNextGeneratedId.get(); |
| 706 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 707 | int newValue = result + 1; |
| 708 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 709 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 710 | return result; |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | public int getViewIdForItem(ItemInfo info) { |
| 716 | // This cast is safe given the > 2B range for int. |
| 717 | int itemId = (int) info.id; |
| 718 | if (mItemIdToViewId.containsKey(itemId)) { |
| 719 | return mItemIdToViewId.get(itemId); |
| 720 | } |
| 721 | int viewId = generateViewId(); |
| 722 | mItemIdToViewId.put(itemId, viewId); |
| 723 | return viewId; |
| 724 | } |
| 725 | |
| 726 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 727 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 728 | * a configuration step, this allows the proper animations to run after other transitions. |
| 729 | */ |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 730 | private long completeAdd(PendingAddArguments args) { |
| 731 | |
| 732 | long screenId = ensurePendingDropLayoutExists(args.screenId); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 733 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 734 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 735 | completeAddShortcut(args.intent, args.container, screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 736 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 737 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 738 | case REQUEST_CREATE_APPWIDGET: |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 739 | completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 740 | break; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 741 | case REQUEST_RECONFIGURE_APPWIDGET: |
| 742 | completeRestoreAppWidget(args.appWidgetId); |
| 743 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 744 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 745 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 746 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 747 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 748 | resetAddInfo(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 749 | return screenId; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 750 | } |
| 751 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 752 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 753 | protected void onActivityResult( |
| 754 | final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 755 | // Reset the startActivity waiting flag |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 756 | setWaitingForResult(false); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 757 | final int pendingAddWidgetId = mPendingAddWidgetId; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 758 | mPendingAddWidgetId = -1; |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 759 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 760 | Runnable exitSpringLoaded = new Runnable() { |
| 761 | @Override |
| 762 | public void run() { |
| 763 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 764 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 765 | } |
| 766 | }; |
| 767 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 768 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 769 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 770 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 771 | if (resultCode == RESULT_CANCELED) { |
| 772 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 773 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 774 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 775 | } else if (resultCode == RESULT_OK) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 776 | addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, |
| 777 | mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 778 | } |
| 779 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 780 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 781 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
| 782 | mWorkspace.exitOverviewMode(false); |
| 783 | } |
| 784 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 785 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 786 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 787 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 788 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 789 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 790 | final boolean workspaceLocked = isWorkspaceLocked(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 791 | // We have special handling for widgets |
| 792 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 793 | final int appWidgetId; |
| 794 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 795 | : -1; |
| 796 | if (widgetId < 0) { |
| 797 | appWidgetId = pendingAddWidgetId; |
| 798 | } else { |
| 799 | appWidgetId = widgetId; |
| 800 | } |
| 801 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 802 | final int result; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 803 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 804 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + |
| 805 | "returned from the widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 806 | result = RESULT_CANCELED; |
| 807 | completeTwoStageWidgetDrop(result, appWidgetId); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 808 | final Runnable onComplete = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 809 | @Override |
| 810 | public void run() { |
| 811 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 812 | } |
| 813 | }; |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 814 | if (workspaceLocked) { |
| 815 | // No need to remove the empty screen if we're mid-binding, as the |
| 816 | // the bind will not add the empty screen. |
| 817 | mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
| 818 | } else { |
| 819 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, |
| 820 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
| 821 | } |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 822 | } else { |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 823 | if (!workspaceLocked) { |
| 824 | mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId); |
| 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 | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 881 | } |
| 882 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 883 | private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int |
| 884 | appWidgetId, ItemInfo info) { |
| 885 | PendingAddArguments args = new PendingAddArguments(); |
| 886 | args.requestCode = requestCode; |
| 887 | args.intent = data; |
| 888 | args.container = info.container; |
| 889 | args.screenId = info.screenId; |
| 890 | args.cellX = info.cellX; |
| 891 | args.cellY = info.cellY; |
| 892 | args.appWidgetId = appWidgetId; |
| 893 | return args; |
| 894 | } |
| 895 | |
| 896 | /** |
| 897 | * Check to see if a given screen id exists. If not, create it at the end, return the new id. |
| 898 | * |
| 899 | * @param screenId the screen id to check |
| 900 | * @return the new screen, or screenId if it exists |
| 901 | */ |
| 902 | private long ensurePendingDropLayoutExists(long screenId) { |
| 903 | CellLayout dropLayout = |
| 904 | (CellLayout) mWorkspace.getScreenWithId(screenId); |
| 905 | if (dropLayout == null) { |
| 906 | // it's possible that the add screen was removed because it was |
| 907 | // empty and a re-bind occurred |
| 908 | mWorkspace.addExtraEmptyScreen(); |
| 909 | return mWorkspace.commitExtraEmptyScreen(); |
| 910 | } else { |
| 911 | return screenId; |
| 912 | } |
| 913 | } |
| 914 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 915 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 916 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 917 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 918 | Runnable onCompleteRunnable = null; |
| 919 | int animationType = 0; |
| 920 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 921 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 922 | if (resultCode == RESULT_OK) { |
| 923 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 924 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 925 | mPendingAddWidgetInfo); |
| 926 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 927 | onCompleteRunnable = new Runnable() { |
| 928 | @Override |
| 929 | public void run() { |
| 930 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 931 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 932 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 933 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 934 | } |
| 935 | }; |
| 936 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 937 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 938 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 939 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 940 | if (mDragLayer.getAnimatedView() != null) { |
| 941 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 942 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 943 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 944 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 945 | // The animated view may be null in the case of a rotation during widget configuration |
| 946 | onCompleteRunnable.run(); |
| 947 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 951 | protected void onStop() { |
| 952 | super.onStop(); |
| 953 | FirstFrameAnimatorHelper.setIsVisible(false); |
| 954 | } |
| 955 | |
| 956 | @Override |
| 957 | protected void onStart() { |
| 958 | super.onStart(); |
| 959 | FirstFrameAnimatorHelper.setIsVisible(true); |
| 960 | } |
| 961 | |
| 962 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 963 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 964 | long startTime = 0; |
| 965 | if (DEBUG_RESUME_TIME) { |
| 966 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 967 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 968 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 969 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 970 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 971 | // Restore the previous launcher state |
| 972 | if (mOnResumeState == State.WORKSPACE) { |
| 973 | showWorkspace(false); |
| 974 | } else if (mOnResumeState == State.APPS_CUSTOMIZE) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 975 | showAllApps(false, mAppsCustomizeContent.getContentType(), false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 976 | } |
| 977 | mOnResumeState = State.NONE; |
| 978 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 979 | // Background was set to gradient in onPause(), restore to black if in all apps. |
| 980 | setWorkspaceBackground(mState == State.WORKSPACE); |
| 981 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 982 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 983 | if (mRestoring || mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 984 | setWorkspaceLoading(true); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 985 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 986 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 987 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 988 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 989 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 990 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 991 | // execute them here |
| 992 | long startTimeCallbacks = 0; |
| 993 | if (DEBUG_RESUME_TIME) { |
| 994 | startTimeCallbacks = System.currentTimeMillis(); |
| 995 | } |
| 996 | |
| 997 | if (mAppsCustomizeContent != null) { |
| 998 | mAppsCustomizeContent.setBulkBind(true); |
| 999 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1000 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 1001 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1002 | } |
| 1003 | if (mAppsCustomizeContent != null) { |
| 1004 | mAppsCustomizeContent.setBulkBind(false); |
| 1005 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1006 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 1007 | if (DEBUG_RESUME_TIME) { |
| 1008 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 1009 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 1010 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1011 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 1012 | if (mOnResumeCallbacks.size() > 0) { |
| 1013 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 1014 | mOnResumeCallbacks.get(i).run(); |
| 1015 | } |
| 1016 | mOnResumeCallbacks.clear(); |
| 1017 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1018 | |
| 1019 | // Reset the pressed state of icons that were locked in the press state while activities |
| 1020 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1021 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 1022 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1023 | mWaitingForResume.setStayPressed(false); |
| 1024 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 1025 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1026 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 1027 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 1028 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 1029 | // orientation. |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1030 | getWorkspace().reinflateWidgetsIfNecessary(); |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1031 | |
Winson Chung | 780fe59 | 2013-09-26 14:48:44 -0700 | [diff] [blame] | 1032 | // Process any items that were added while Launcher was away. |
| 1033 | InstallShortcutReceiver.disableAndFlushInstallQueue(this); |
| 1034 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 1035 | // Update the voice search button proxy |
| 1036 | updateVoiceButtonProxyVisible(false); |
| 1037 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1038 | // Again, as with the above scenario, it's possible that one or more of the global icons |
| 1039 | // were updated in the wrong orientation. |
| 1040 | updateGlobalIcons(); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1041 | if (DEBUG_RESUME_TIME) { |
| 1042 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1043 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1044 | |
| 1045 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1046 | // If we are resuming and the custom content is the current page, we call onShow(). |
| 1047 | // It is also poassible that onShow will instead be called slightly after first layout |
| 1048 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1049 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1050 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1051 | } |
| 1052 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 1053 | mWorkspace.updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1054 | mWorkspace.onResume(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1055 | |
| 1056 | PackageInstallerCompat.getInstance(this).onResume(); |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1059 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1060 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1061 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1062 | InstallShortcutReceiver.enableInstallQueue(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 1063 | PackageInstallerCompat.getInstance(this).onPause(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1064 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1065 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1066 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1067 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1068 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1069 | |
| 1070 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1071 | // debounce excess onHide calls. |
| 1072 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1073 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1074 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1075 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1076 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1077 | QSBScroller mQsbScroller = new QSBScroller() { |
| 1078 | int scrollY = 0; |
| 1079 | |
| 1080 | @Override |
| 1081 | public void setScrollY(int scroll) { |
| 1082 | scrollY = scroll; |
| 1083 | |
| 1084 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
| 1085 | mSearchDropTargetBar.setTranslationY(- scrollY); |
Mark Brophy | d7dc681 | 2013-09-20 17:27:32 +0100 | [diff] [blame] | 1086 | getQsbBar().setTranslationY(-scrollY); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | }; |
| 1090 | |
| 1091 | public void resetQSBScroll() { |
| 1092 | mSearchDropTargetBar.animate().translationY(0).start(); |
Mark Brophy | d7dc681 | 2013-09-20 17:27:32 +0100 | [diff] [blame] | 1093 | getQsbBar().animate().translationY(0).start(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1097 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1098 | // by a onResume or by scrolling otherwise. |
| 1099 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1100 | |
| 1101 | // Custom content is completely hidden |
| 1102 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1103 | |
| 1104 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1105 | public void onScrollProgressChanged(float progress); |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1106 | |
| 1107 | // Indicates whether the user is allowed to scroll away from the custom content. |
| 1108 | boolean isScrollingAllowed(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1111 | protected boolean hasSettings() { |
| 1112 | return false; |
| 1113 | } |
| 1114 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1115 | public interface QSBScroller { |
| 1116 | public void setScrollY(int scrollY); |
| 1117 | } |
| 1118 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 1119 | public QSBScroller addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1120 | CustomContentCallbacks callbacks, String description) { |
| 1121 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1122 | return mQsbScroller; |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1125 | // The custom content needs to offset its content to account for the QSB |
| 1126 | public int getTopOffsetForCustomContent() { |
| 1127 | return mWorkspace.getPaddingTop(); |
| 1128 | } |
| 1129 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1130 | @Override |
| 1131 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1132 | // Flag the loader to stop early before switching |
| 1133 | mModel.stopLoader(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1134 | if (mAppsCustomizeContent != null) { |
| 1135 | mAppsCustomizeContent.surrender(); |
| 1136 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1137 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1138 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1139 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1140 | // We can't hide the IME if it was forced open. So don't bother |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1141 | @Override |
| 1142 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1143 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1144 | mHasFocus = hasFocus; |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1145 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1146 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1147 | private boolean acceptFilter() { |
| 1148 | final InputMethodManager inputManager = (InputMethodManager) |
| 1149 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1150 | return !inputManager.isFullscreenMode(); |
| 1151 | } |
| 1152 | |
| 1153 | @Override |
| 1154 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1155 | final int uniChar = event.getUnicodeChar(); |
| 1156 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1157 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1158 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1159 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1160 | keyCode, event); |
| 1161 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1162 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1163 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1164 | // showSearchDialog() |
| 1165 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1166 | // onSearchRequested() will be called for every keystroke, |
| 1167 | // but it is idempotent, so it's fine. |
| 1168 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1169 | } |
| 1170 | } |
| 1171 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1172 | // Eat the long press event so the keyboard doesn't come up. |
| 1173 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1174 | return true; |
| 1175 | } |
| 1176 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1177 | return handled; |
| 1178 | } |
| 1179 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1180 | private String getTypedText() { |
| 1181 | return mDefaultKeySsb.toString(); |
| 1182 | } |
| 1183 | |
| 1184 | private void clearTypedText() { |
| 1185 | mDefaultKeySsb.clear(); |
| 1186 | mDefaultKeySsb.clearSpans(); |
| 1187 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1188 | } |
| 1189 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1190 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1191 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1192 | * State |
| 1193 | */ |
| 1194 | private static State intToState(int stateOrdinal) { |
| 1195 | State state = State.WORKSPACE; |
| 1196 | final State[] stateValues = State.values(); |
| 1197 | for (int i = 0; i < stateValues.length; i++) { |
| 1198 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1199 | state = stateValues[i]; |
| 1200 | break; |
| 1201 | } |
| 1202 | } |
| 1203 | return state; |
| 1204 | } |
| 1205 | |
| 1206 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1207 | * Restores the previous state, if it exists. |
| 1208 | * |
| 1209 | * @param savedState The previous state. |
| 1210 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1211 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1212 | private void restoreState(Bundle savedState) { |
| 1213 | if (savedState == null) { |
| 1214 | return; |
| 1215 | } |
| 1216 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1217 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1218 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1219 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1222 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1223 | PagedView.INVALID_RESTORE_PAGE); |
| 1224 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1225 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1226 | } |
| 1227 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1228 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1229 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1230 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1231 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1232 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1233 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1234 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1235 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1236 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1237 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 1238 | mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1239 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1240 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1241 | mRestoring = true; |
| 1242 | } |
| 1243 | |
| 1244 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1245 | if (renameFolder) { |
| 1246 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1247 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1248 | mRestoring = true; |
| 1249 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1250 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1251 | // Restore the AppsCustomize tab |
| 1252 | if (mAppsCustomizeTabHost != null) { |
| 1253 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1254 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1255 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1256 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1257 | mAppsCustomizeContent.loadAssociatedPages( |
| 1258 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1261 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1262 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1263 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1264 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1265 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | /** |
| 1269 | * Finds all the views we need and configure them properly. |
| 1270 | */ |
| 1271 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1272 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1273 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1274 | mLauncherView = findViewById(R.id.launcher); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1275 | mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1276 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1277 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1278 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1279 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1280 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1281 | mLauncherView.setSystemUiVisibility( |
| 1282 | 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] | 1283 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1284 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1285 | // Setup the drag layer |
| 1286 | mDragLayer.setup(this, dragController); |
| 1287 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1288 | // Setup the hotseat |
| 1289 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1290 | if (mHotseat != null) { |
| 1291 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1292 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1295 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1296 | View widgetButton = findViewById(R.id.widget_button); |
| 1297 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1298 | @Override |
| 1299 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1300 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1301 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1302 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1303 | } |
| 1304 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1305 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1306 | |
| 1307 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1308 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1309 | @Override |
| 1310 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1311 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1312 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1313 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1314 | } |
| 1315 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1316 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1317 | |
| 1318 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1319 | if (hasSettings()) { |
| 1320 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1321 | @Override |
| 1322 | public void onClick(View arg0) { |
| 1323 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1324 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1325 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1326 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1327 | }); |
| 1328 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1329 | } else { |
| 1330 | settingsButton.setVisibility(View.GONE); |
| 1331 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams(); |
| 1332 | lp.gravity = Gravity.END | Gravity.TOP; |
| 1333 | widgetButton.requestLayout(); |
| 1334 | } |
| 1335 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1336 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1337 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1338 | // Setup the workspace |
| 1339 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1340 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1341 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1342 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1343 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1344 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1345 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1346 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1347 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1348 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1349 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1350 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1351 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1352 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1353 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1354 | // 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] | 1355 | dragController.setDragScoller(mWorkspace); |
| 1356 | dragController.setScrollView(mDragLayer); |
| 1357 | dragController.setMoveTarget(mWorkspace); |
| 1358 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1359 | if (mSearchDropTargetBar != null) { |
| 1360 | mSearchDropTargetBar.setup(this, dragController); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1361 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1362 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1363 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1364 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1365 | mWeightWatcher = new WeightWatcher(this); |
| 1366 | mWeightWatcher.setAlpha(0.5f); |
| 1367 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1368 | new FrameLayout.LayoutParams( |
| 1369 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1370 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1371 | Gravity.BOTTOM) |
| 1372 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1373 | |
| 1374 | boolean show = shouldShowWeightWatcher(); |
| 1375 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1376 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1380 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1381 | */ |
| 1382 | public void setAllAppsButton(View allAppsButton) { |
| 1383 | mAllAppsButton = allAppsButton; |
| 1384 | } |
| 1385 | |
| 1386 | public View getAllAppsButton() { |
| 1387 | return mAllAppsButton; |
| 1388 | } |
| 1389 | |
| 1390 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1391 | * Creates a view representing a shortcut. |
| 1392 | * |
| 1393 | * @param info The data structure describing the shortcut. |
| 1394 | * |
| 1395 | * @return A View inflated from R.layout.application. |
| 1396 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1397 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1398 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1399 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | /** |
| 1403 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1404 | * |
| 1405 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1406 | * @param parent The group the shortcut belongs to. |
| 1407 | * @param info The data structure describing the shortcut. |
| 1408 | * |
| 1409 | * @return A View inflated from layoutResId. |
| 1410 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1411 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1412 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 1413 | favorite.applyFromShortcutInfo(info, mIconCache, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1414 | favorite.setOnClickListener(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1415 | favorite.setOnFocusChangeListener(mFocusHandler); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1416 | return favorite; |
| 1417 | } |
| 1418 | |
| 1419 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1420 | * Add a shortcut to the workspace. |
| 1421 | * |
| 1422 | * @param data The intent describing the shortcut. |
| 1423 | * @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] | 1424 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1425 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1426 | int cellY) { |
| 1427 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1428 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1429 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1430 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1431 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1432 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1433 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1434 | if (info == null) { |
| 1435 | return; |
| 1436 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1437 | final View view = createShortcut(info); |
| 1438 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1439 | // First we check if we already know the exact location where we want to add this item. |
| 1440 | if (cellX >= 0 && cellY >= 0) { |
| 1441 | cellXY[0] = cellX; |
| 1442 | cellXY[1] = cellY; |
| 1443 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1444 | |
| 1445 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1446 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1447 | true, null,null)) { |
| 1448 | return; |
| 1449 | } |
| 1450 | DragObject dragObject = new DragObject(); |
| 1451 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1452 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1453 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1454 | return; |
| 1455 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1456 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1457 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1458 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1459 | foundCellSpan = (result != null); |
| 1460 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1461 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1465 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1466 | return; |
| 1467 | } |
| 1468 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1469 | 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] | 1470 | |
| 1471 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1472 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1473 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1477 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1478 | int minHeight) { |
| 1479 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1480 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1481 | // to ensure that it gets the full amount of space that it has requested |
| 1482 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1483 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1484 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1487 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1488 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1491 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1492 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1495 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1496 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1499 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1500 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1501 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1502 | } |
| 1503 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1504 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1505 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1506 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1507 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1508 | * @param cellInfo The position on screen where to create the widget. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1509 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1510 | private void completeAddAppWidget(final int appWidgetId, long container, long screenId, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1511 | AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1512 | if (appWidgetInfo == null) { |
| 1513 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1514 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1515 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1516 | // Calculate the grid spans needed to fit this widget |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1517 | CellLayout layout = getCellLayout(container, screenId); |
Adam Cohen | 0935386 | 2011-07-14 16:10:03 -0700 | [diff] [blame] | 1518 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1519 | int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo); |
| 1520 | int[] spanXY = getSpanForWidget(this, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1521 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1522 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1523 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1524 | // if we are placing widgets on a "spring-loaded" screen |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1525 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1526 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1527 | int[] finalSpan = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1528 | boolean foundCellSpan = false; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1529 | if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { |
| 1530 | cellXY[0] = mPendingAddInfo.cellX; |
| 1531 | cellXY[1] = mPendingAddInfo.cellY; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1532 | spanXY[0] = mPendingAddInfo.spanX; |
| 1533 | spanXY[1] = mPendingAddInfo.spanY; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1534 | foundCellSpan = true; |
| 1535 | } else if (touchXY != null) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1536 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1537 | int[] result = layout.findNearestVacantArea( |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1538 | touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], |
| 1539 | spanXY[1], cellXY, finalSpan); |
| 1540 | spanXY[0] = finalSpan[0]; |
| 1541 | spanXY[1] = finalSpan[1]; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1542 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1543 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1544 | foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1547 | if (!foundCellSpan) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1548 | if (appWidgetId != -1) { |
| 1549 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 1550 | // to the caller... |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1551 | new AsyncTask<Void, Void, Void>() { |
| 1552 | public Void doInBackground(Void ... args) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1553 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1554 | return null; |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1555 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1556 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1557 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1558 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1559 | return; |
| 1560 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1561 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1562 | // Build Launcher-specific widget info and save to database |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 1563 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, |
| 1564 | appWidgetInfo.provider); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1565 | launcherInfo.spanX = spanXY[0]; |
| 1566 | launcherInfo.spanY = spanXY[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1567 | launcherInfo.minSpanX = mPendingAddInfo.minSpanX; |
| 1568 | launcherInfo.minSpanY = mPendingAddInfo.minSpanY; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1569 | launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1570 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1571 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1572 | container, screenId, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1573 | |
| 1574 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1575 | if (hostView == null) { |
| 1576 | // Perform actual inflation because we're live |
| 1577 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1578 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1579 | } else { |
| 1580 | // The AppWidgetHostView has already been inflated and instantiated |
| 1581 | launcherInfo.hostView = hostView; |
| 1582 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1583 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1584 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1585 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1586 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1587 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1588 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1589 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1590 | |
| 1591 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1592 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1593 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1594 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1595 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1596 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1597 | @Override |
| 1598 | public void onReceive(Context context, Intent intent) { |
| 1599 | final String action = intent.getAction(); |
| 1600 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1601 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1602 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1603 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1604 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1605 | // 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] | 1606 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1607 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1608 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1609 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1610 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1611 | mUserPresent = true; |
| 1612 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1613 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1614 | mModel.resetLoadedState(false, true); |
| 1615 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1616 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1617 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1618 | mModel.resetLoadedState(false, true); |
| 1619 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1620 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1621 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1622 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1623 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1624 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1625 | } |
| 1626 | } |
| 1627 | }; |
| 1628 | |
| 1629 | @Override |
| 1630 | public void onAttachedToWindow() { |
| 1631 | super.onAttachedToWindow(); |
| 1632 | |
| 1633 | // Listen for broadcasts related to user-presence |
| 1634 | final IntentFilter filter = new IntentFilter(); |
| 1635 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1636 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1637 | // For handling managed profiles |
| 1638 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1639 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1640 | if (ENABLE_DEBUG_INTENTS) { |
| 1641 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1642 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1643 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1644 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1645 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1646 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1647 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1648 | mVisible = true; |
| 1649 | } |
| 1650 | |
Adam Cohen | 0b39535 | 2014-06-09 22:54:36 +0000 | [diff] [blame] | 1651 | /** |
| 1652 | * Sets up transparent navigation and status bars in LMP. |
| 1653 | * This method is a no-op for other platform versions. |
| 1654 | */ |
| 1655 | @TargetApi(19) |
| 1656 | private void setupTransparentSystemBarsForLmp() { |
| 1657 | // TODO(sansid): use the APIs directly when compiling against L sdk. |
| 1658 | // Currently we use reflection to access the flags and the API to set the transparency |
| 1659 | // on the System bars. |
| 1660 | if (Utilities.isLmp()) { |
| 1661 | try { |
| 1662 | getWindow().getAttributes().systemUiVisibility |= |
| 1663 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1664 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1665 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1666 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
| 1667 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
| 1668 | Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( |
| 1669 | "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); |
| 1670 | getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); |
| 1671 | |
| 1672 | Method setStatusBarColorMethod = |
| 1673 | Window.class.getDeclaredMethod("setStatusBarColor", int.class); |
| 1674 | Method setNavigationBarColorMethod = |
| 1675 | Window.class.getDeclaredMethod("setNavigationBarColor", int.class); |
| 1676 | setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1677 | setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1678 | } catch (NoSuchFieldException e) { |
| 1679 | Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); |
| 1680 | } catch (NoSuchMethodException ex) { |
| 1681 | Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); |
| 1682 | } catch (IllegalAccessException e) { |
| 1683 | Log.w(TAG, "IllegalAccessException while setting up transparent bars"); |
| 1684 | } catch (IllegalArgumentException e) { |
| 1685 | Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); |
| 1686 | } catch (InvocationTargetException e) { |
| 1687 | Log.w(TAG, "InvocationTargetException while setting up transparent bars"); |
| 1688 | } finally {} |
| 1689 | } |
| 1690 | } |
| 1691 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1692 | @Override |
| 1693 | public void onDetachedFromWindow() { |
| 1694 | super.onDetachedFromWindow(); |
| 1695 | mVisible = false; |
| 1696 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1697 | if (mAttached) { |
| 1698 | unregisterReceiver(mReceiver); |
| 1699 | mAttached = false; |
| 1700 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1701 | updateRunning(); |
| 1702 | } |
| 1703 | |
| 1704 | public void onWindowVisibilityChanged(int visibility) { |
| 1705 | mVisible = visibility == View.VISIBLE; |
| 1706 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1707 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1708 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1709 | // is a more appropriate event to handle |
| 1710 | if (mVisible) { |
| 1711 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1712 | if (!mWorkspaceLoading) { |
| 1713 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1714 | // We want to let Launcher draw itself at least once before we force it to build |
| 1715 | // 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] | 1716 | // apps is nice and speedy. |
| 1717 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1718 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1719 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1720 | if (mStarted) return; |
| 1721 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1722 | // We delay the layer building a bit in order to give |
| 1723 | // other message processing a time to run. In particular |
| 1724 | // this avoids a delay in hiding the IME if it was |
| 1725 | // currently shown, because doing that may involve |
| 1726 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1727 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1728 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1729 | mWorkspace.post(new Runnable() { |
| 1730 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1731 | if (mWorkspace != null && |
| 1732 | mWorkspace.getViewTreeObserver() != null) { |
| 1733 | mWorkspace.getViewTreeObserver(). |
| 1734 | removeOnDrawListener(listener); |
| 1735 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1736 | } |
| 1737 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1738 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1739 | } |
| 1740 | }); |
| 1741 | } |
| 1742 | clearTypedText(); |
| 1743 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | private void sendAdvanceMessage(long delay) { |
| 1747 | mHandler.removeMessages(ADVANCE_MSG); |
| 1748 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1749 | mHandler.sendMessageDelayed(msg, delay); |
| 1750 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1751 | } |
| 1752 | |
| 1753 | private void updateRunning() { |
| 1754 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1755 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1756 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1757 | if (autoAdvanceRunning) { |
| 1758 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1759 | sendAdvanceMessage(delay); |
| 1760 | } else { |
| 1761 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1762 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1763 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1764 | } |
| 1765 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1766 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | private final Handler mHandler = new Handler() { |
| 1772 | @Override |
| 1773 | public void handleMessage(Message msg) { |
| 1774 | if (msg.what == ADVANCE_MSG) { |
| 1775 | int i = 0; |
| 1776 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1777 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1778 | final int delay = mAdvanceStagger * i; |
| 1779 | if (v instanceof Advanceable) { |
| 1780 | postDelayed(new Runnable() { |
| 1781 | public void run() { |
| 1782 | ((Advanceable) v).advance(); |
| 1783 | } |
| 1784 | }, delay); |
| 1785 | } |
| 1786 | i++; |
| 1787 | } |
| 1788 | sendAdvanceMessage(mAdvanceInterval); |
| 1789 | } |
| 1790 | } |
| 1791 | }; |
| 1792 | |
| 1793 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1794 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1795 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1796 | if (v instanceof Advanceable) { |
| 1797 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1798 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1799 | updateRunning(); |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | void removeWidgetToAutoAdvance(View hostView) { |
| 1804 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1805 | mWidgetsToAdvance.remove(hostView); |
| 1806 | updateRunning(); |
| 1807 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1810 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1811 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1812 | launcherInfo.hostView = null; |
| 1813 | } |
| 1814 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1815 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1816 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1817 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1820 | public DragLayer getDragLayer() { |
| 1821 | return mDragLayer; |
| 1822 | } |
| 1823 | |
| 1824 | public Workspace getWorkspace() { |
| 1825 | return mWorkspace; |
| 1826 | } |
| 1827 | |
| 1828 | public Hotseat getHotseat() { |
| 1829 | return mHotseat; |
| 1830 | } |
| 1831 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1832 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1833 | return mOverviewPanel; |
| 1834 | } |
| 1835 | |
| 1836 | public SearchDropTargetBar getSearchBar() { |
| 1837 | return mSearchDropTargetBar; |
| 1838 | } |
| 1839 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1840 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1841 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1842 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1843 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1844 | public LauncherModel getModel() { |
| 1845 | return mModel; |
| 1846 | } |
| 1847 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1848 | protected SharedPreferences getSharedPrefs() { |
| 1849 | return mSharedPrefs; |
| 1850 | } |
| 1851 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1852 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1853 | getWindow().closeAllPanels(); |
| 1854 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1855 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1856 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1857 | } |
| 1858 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1859 | @Override |
| 1860 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1861 | long startTime = 0; |
| 1862 | if (DEBUG_RESUME_TIME) { |
| 1863 | startTime = System.currentTimeMillis(); |
| 1864 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1865 | super.onNewIntent(intent); |
| 1866 | |
| 1867 | // Close the menu |
| 1868 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1869 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1870 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1871 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1872 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1873 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1874 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1875 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1876 | if (mWorkspace == null) { |
| 1877 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1878 | return; |
| 1879 | } |
| 1880 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1881 | // In all these cases, only animate if we're already on home |
| 1882 | mWorkspace.exitWidgetResizeMode(); |
| 1883 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1884 | openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1885 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1886 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1887 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1888 | closeFolder(); |
| 1889 | exitSpringLoadedDragMode(); |
| 1890 | |
| 1891 | // If we are already on home, then just animate back to the workspace, |
| 1892 | // otherwise, just wait until onResume to set the state back to Workspace |
| 1893 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1894 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1895 | } else { |
| 1896 | mOnResumeState = State.WORKSPACE; |
| 1897 | } |
| 1898 | |
| 1899 | final View v = getWindow().peekDecorView(); |
| 1900 | if (v != null && v.getWindowToken() != null) { |
| 1901 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1902 | INPUT_METHOD_SERVICE); |
| 1903 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 1904 | } |
| 1905 | |
| 1906 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 1907 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1908 | mAppsCustomizeTabHost.reset(); |
| 1909 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1910 | |
| 1911 | onHomeIntent(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1912 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1913 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1914 | if (DEBUG_RESUME_TIME) { |
| 1915 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 1916 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1917 | } |
| 1918 | |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1919 | /** |
| 1920 | * Override point for subclasses to prevent movement to the default screen when the home |
| 1921 | * button is pressed. Used (for example) in GEL, to prevent movement during a search. |
| 1922 | */ |
| 1923 | protected boolean shouldMoveToDefaultScreenOnHomeIntent() { |
| 1924 | return true; |
| 1925 | } |
| 1926 | |
| 1927 | /** |
| 1928 | * Override point for subclasses to provide custom behaviour for when a home intent is fired. |
| 1929 | */ |
| 1930 | protected void onHomeIntent() { |
| 1931 | // Do nothing |
| 1932 | } |
| 1933 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1934 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1935 | public void onRestoreInstanceState(Bundle state) { |
| 1936 | super.onRestoreInstanceState(state); |
| 1937 | for (int page: mSynchronouslyBoundPages) { |
| 1938 | mWorkspace.restoreInstanceStateForChild(page); |
| 1939 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | @Override |
| 1943 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1944 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 1945 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1946 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1947 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1948 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1949 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1950 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 1951 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 1952 | // this state is reflected. |
| 1953 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1954 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1955 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1956 | mWaitingForResult) { |
| 1957 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1958 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1959 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 1960 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1961 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 1962 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 1963 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1964 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | if (mFolderInfo != null && mWaitingForResult) { |
| 1968 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1969 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1970 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1971 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1972 | // Save the current AppsCustomize tab |
| 1973 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 1974 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 1975 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1976 | if (currentTabTag != null) { |
| 1977 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 1978 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1979 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 1980 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1981 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1982 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | @Override |
| 1986 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1987 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1988 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1989 | // Remove all pending runnables |
| 1990 | mHandler.removeMessages(ADVANCE_MSG); |
| 1991 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 1992 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1993 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1994 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 1995 | LauncherAppState app = (LauncherAppState.getInstance()); |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1996 | mModel.stopLoader(); |
| 1997 | app.setLauncher(null); |
| 1998 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1999 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2000 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2001 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2002 | 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] | 2003 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2004 | mAppWidgetHost = null; |
| 2005 | |
| 2006 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2007 | |
| 2008 | TextKeyListener.getInstance().release(); |
| 2009 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 2010 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 2011 | // to prevent leaking Launcher activities on orientation change. |
| 2012 | if (mModel != null) { |
| 2013 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 2014 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2015 | |
| 2016 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2017 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2018 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 2019 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2020 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 2021 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 2022 | mWorkspace = null; |
| 2023 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 2024 | |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 2025 | PackageInstallerCompat.getInstance(this).onStop(); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2026 | LauncherAnimUtils.onDestroyActivity(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2027 | } |
| 2028 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2029 | public DragController getDragController() { |
| 2030 | return mDragController; |
| 2031 | } |
| 2032 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2033 | @Override |
| 2034 | public void startActivityForResult(Intent intent, int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2035 | if (requestCode >= 0) { |
| 2036 | setWaitingForResult(true); |
| 2037 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2038 | super.startActivityForResult(intent, requestCode); |
| 2039 | } |
| 2040 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2041 | /** |
| 2042 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2043 | * argument for {@link #startSearch} to true. |
| 2044 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2045 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2046 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2047 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2048 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2049 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2050 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2051 | if (initialQuery == null) { |
| 2052 | // Use any text typed in the launcher as the initial query |
| 2053 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2054 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2055 | if (appSearchData == null) { |
| 2056 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2057 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2058 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2059 | Rect sourceBounds = new Rect(); |
| 2060 | if (mSearchDropTargetBar != null) { |
| 2061 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2062 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2063 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2064 | startSearch(initialQuery, selectInitialQuery, |
| 2065 | appSearchData, sourceBounds); |
| 2066 | } |
| 2067 | |
| 2068 | public void startSearch(String initialQuery, |
| 2069 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2070 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2071 | appSearchData, sourceBounds); |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | /** |
| 2075 | * Starts the global search activity. This code is a copied from SearchManager |
| 2076 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2077 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2078 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2079 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2080 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2081 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2082 | if (globalSearchActivity == null) { |
| 2083 | Log.w(TAG, "No global search activity found."); |
| 2084 | return; |
| 2085 | } |
| 2086 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2087 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2088 | intent.setComponent(globalSearchActivity); |
| 2089 | // Make sure that we have a Bundle to put source in |
| 2090 | if (appSearchData == null) { |
| 2091 | appSearchData = new Bundle(); |
| 2092 | } else { |
| 2093 | appSearchData = new Bundle(appSearchData); |
| 2094 | } |
| 2095 | // Set source to package name of app that starts global search, if not set already. |
| 2096 | if (!appSearchData.containsKey("source")) { |
| 2097 | appSearchData.putString("source", getPackageName()); |
| 2098 | } |
| 2099 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2100 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2101 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2102 | } |
| 2103 | if (selectInitialQuery) { |
| 2104 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2105 | } |
| 2106 | intent.setSourceBounds(sourceBounds); |
| 2107 | try { |
| 2108 | startActivity(intent); |
| 2109 | } catch (ActivityNotFoundException ex) { |
| 2110 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2111 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2112 | } |
| 2113 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2114 | public boolean isOnCustomContent() { |
| 2115 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2116 | } |
| 2117 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2118 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2119 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2120 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2121 | if (!isOnCustomContent()) { |
| 2122 | // Close any open folders |
| 2123 | closeFolder(); |
| 2124 | // Stop resizing any widgets |
| 2125 | mWorkspace.exitWidgetResizeMode(); |
| 2126 | if (!mWorkspace.isInOverviewMode()) { |
| 2127 | // Show the overview mode |
| 2128 | showOverviewMode(true); |
| 2129 | } else { |
| 2130 | showWorkspace(true); |
| 2131 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2132 | } |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2133 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2134 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2135 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2136 | @Override |
| 2137 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2138 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2139 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2140 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2143 | public boolean isWorkspaceLocked() { |
| 2144 | return mWorkspaceLoading || mWaitingForResult; |
| 2145 | } |
| 2146 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2147 | public boolean isWorkspaceLoading() { |
| 2148 | return mWorkspaceLoading; |
| 2149 | } |
| 2150 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2151 | private void setWorkspaceLoading(boolean value) { |
| 2152 | boolean isLocked = isWorkspaceLocked(); |
| 2153 | mWorkspaceLoading = value; |
| 2154 | if (isLocked != isWorkspaceLocked()) { |
| 2155 | onWorkspaceLockedChanged(); |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | private void setWaitingForResult(boolean value) { |
| 2160 | boolean isLocked = isWorkspaceLocked(); |
| 2161 | mWaitingForResult = value; |
| 2162 | if (isLocked != isWorkspaceLocked()) { |
| 2163 | onWorkspaceLockedChanged(); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | protected void onWorkspaceLockedChanged() { } |
| 2168 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2169 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2170 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2171 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2172 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2173 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2174 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2175 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2176 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2177 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2178 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2179 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) { |
| 2180 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2181 | } |
| 2182 | |
| 2183 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2184 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int |
| 2185 | delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2186 | if (appWidgetInfo.configure != null) { |
| 2187 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2188 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2189 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2190 | // Launch over to configure widget, if needed |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2191 | mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this, |
| 2192 | mAppWidgetHost, REQUEST_CREATE_APPWIDGET); |
| 2193 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2194 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2195 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2196 | Runnable onComplete = new Runnable() { |
| 2197 | @Override |
| 2198 | public void run() { |
| 2199 | // Exit spring loaded mode if necessary after adding the widget |
| 2200 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2201 | null); |
| 2202 | } |
| 2203 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2204 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2205 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2206 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2207 | } |
| 2208 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2209 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2210 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2211 | // Close any folders that may be open. |
| 2212 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2213 | mWorkspace.moveToCustomContentScreen(animate); |
| 2214 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2215 | /** |
| 2216 | * Process a shortcut drop. |
| 2217 | * |
| 2218 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2219 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2220 | * @param cell The cell it should be added to, optional |
| 2221 | * @param position The location on the screen where it was dropped, optional |
| 2222 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2223 | void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2224 | int[] cell, int[] loc) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2225 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2226 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2227 | mPendingAddInfo.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2228 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2229 | |
| 2230 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2231 | mPendingAddInfo.cellX = cell[0]; |
| 2232 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2233 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2234 | |
| 2235 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2236 | createShortcutIntent.setComponent(componentName); |
| 2237 | processShortcut(createShortcutIntent); |
| 2238 | } |
| 2239 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2240 | /** |
| 2241 | * Process a widget drop. |
| 2242 | * |
| 2243 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2244 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2245 | * @param cell The cell it should be added to, optional |
| 2246 | * @param position The location on the screen where it was dropped, optional |
| 2247 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2248 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2249 | int[] cell, int[] span, int[] loc) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2250 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2251 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2252 | mPendingAddInfo.screenId = info.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2253 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2254 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2255 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2256 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2257 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2258 | mPendingAddInfo.cellX = cell[0]; |
| 2259 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2260 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2261 | if (span != null) { |
| 2262 | mPendingAddInfo.spanX = span[0]; |
| 2263 | mPendingAddInfo.spanY = span[1]; |
| 2264 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2265 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2266 | AppWidgetHostView hostView = info.boundWidget; |
| 2267 | int appWidgetId; |
| 2268 | if (hostView != null) { |
| 2269 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2270 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2271 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2272 | // In this case, we either need to start an activity to get permission to bind |
| 2273 | // 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] | 2274 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2275 | Bundle options = info.bindOptions; |
| 2276 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2277 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 2278 | appWidgetId, info.info, options); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2279 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2280 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2281 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2282 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2283 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2284 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2285 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2286 | mAppWidgetManager.getUser(mPendingAddWidgetInfo) |
| 2287 | .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2288 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2289 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2290 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2291 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2292 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2295 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2296 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2297 | } |
| 2298 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2299 | void processWallpaper(Intent intent) { |
| 2300 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2301 | } |
| 2302 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2303 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2304 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2305 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2306 | folderInfo.title = getText(R.string.folder_name); |
| 2307 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2308 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2309 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2310 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2311 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2312 | |
| 2313 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2314 | FolderIcon newFolder = |
| 2315 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2316 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2317 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2318 | // Force measure the new folder icon |
| 2319 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2320 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2321 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2322 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2323 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2324 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2325 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2326 | } |
| 2327 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2328 | protected ComponentName getWallpaperPickerComponent() { |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2329 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2330 | } |
| 2331 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2332 | /** |
| 2333 | * Registers various content observers. The current implementation registers |
| 2334 | * only a favorites observer to keep track of the favorites applications. |
| 2335 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2336 | private void registerContentObservers() { |
| 2337 | ContentResolver resolver = getContentResolver(); |
| 2338 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2339 | true, mWidgetObserver); |
| 2340 | } |
| 2341 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2342 | @Override |
| 2343 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2344 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2345 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2346 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2347 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2348 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 2349 | if (isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2350 | dumpState(); |
| 2351 | return true; |
| 2352 | } |
| 2353 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2354 | } |
| 2355 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2356 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2357 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2358 | return true; |
| 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | return super.dispatchKeyEvent(event); |
| 2363 | } |
| 2364 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2365 | @Override |
| 2366 | public void onBackPressed() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2367 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2368 | if (mAppsCustomizeContent.getContentType() == |
| 2369 | AppsCustomizePagedView.ContentType.Applications) { |
| 2370 | showWorkspace(true); |
| 2371 | } else { |
| 2372 | showOverviewMode(true); |
| 2373 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2374 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2375 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2376 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2377 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2378 | if (openFolder.isEditingName()) { |
| 2379 | openFolder.dismissEditingName(); |
| 2380 | } else { |
| 2381 | closeFolder(); |
| 2382 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2383 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2384 | mWorkspace.exitWidgetResizeMode(); |
| 2385 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2386 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2387 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2388 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2389 | } |
| 2390 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2391 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2392 | * Re-listen when widgets are reset. |
| 2393 | */ |
| 2394 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2395 | if (mAppWidgetHost != null) { |
| 2396 | mAppWidgetHost.startListening(); |
| 2397 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2401 | * Launches the intent referred by the clicked shortcut. |
| 2402 | * |
| 2403 | * @param v The view representing the clicked shortcut. |
| 2404 | */ |
| 2405 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2406 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2407 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2408 | if (v.getWindowToken() == null) { |
| 2409 | return; |
| 2410 | } |
| 2411 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2412 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2413 | return; |
| 2414 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2415 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2416 | if (v instanceof Workspace) { |
| 2417 | if (mWorkspace.isInOverviewMode()) { |
| 2418 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2419 | } |
| 2420 | return; |
| 2421 | } |
| 2422 | |
| 2423 | if (v instanceof CellLayout) { |
| 2424 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2425 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2429 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2430 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2431 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2432 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2433 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2434 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2435 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2436 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2437 | onClickAllAppsButton(v); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2438 | } else if (tag instanceof AppInfo) { |
| 2439 | startAppShortcutOrInfoActivity(v); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2440 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 2441 | if (v instanceof PendingAppWidgetHostView) { |
| 2442 | onClickPendingWidget((PendingAppWidgetHostView) v); |
| 2443 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2444 | } |
| 2445 | } |
| 2446 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2447 | public void onClickPagedViewIcon(View v) { |
| 2448 | startAppShortcutOrInfoActivity(v); |
| 2449 | } |
| 2450 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2451 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2452 | return false; |
| 2453 | } |
| 2454 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2455 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2456 | * Event handler for the app widget view which has not fully restored. |
| 2457 | */ |
| 2458 | public void onClickPendingWidget(PendingAppWidgetHostView v) { |
| 2459 | if (v.isReadyForClickSetup()) { |
| 2460 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
| 2461 | int widgetId = info.appWidgetId; |
| 2462 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); |
| 2463 | if (appWidgetInfo != null) { |
| 2464 | mPendingAddWidgetInfo = appWidgetInfo; |
| 2465 | mPendingAddInfo.copyFrom(info); |
| 2466 | mPendingAddWidgetId = widgetId; |
| 2467 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 2468 | AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo, |
| 2469 | info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | } |
| 2473 | |
| 2474 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2475 | * Event handler for the search button |
| 2476 | * |
| 2477 | * @param v The view that was clicked. |
| 2478 | */ |
| 2479 | public void onClickSearchButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2480 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2481 | |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2482 | onSearchRequested(); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2486 | * Event handler for the voice button |
| 2487 | * |
| 2488 | * @param v The view that was clicked. |
| 2489 | */ |
| 2490 | public void onClickVoiceButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2491 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2492 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2493 | startVoice(); |
| 2494 | } |
| 2495 | |
| 2496 | public void startVoice() { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2497 | try { |
| 2498 | final SearchManager searchManager = |
| 2499 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2500 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 2501 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2502 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2503 | if (activityName != null) { |
| 2504 | intent.setPackage(activityName.getPackageName()); |
| 2505 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2506 | startActivity(null, intent, "onClickVoiceButton"); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2507 | } catch (ActivityNotFoundException e) { |
| 2508 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2509 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2510 | startActivitySafely(null, intent, "onClickVoiceButton"); |
| 2511 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2515 | * Event handler for the "grid" button that appears on the home screen, which |
| 2516 | * enters all apps mode. |
| 2517 | * |
| 2518 | * @param v The view that was clicked. |
| 2519 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2520 | protected void onClickAllAppsButton(View v) { |
| 2521 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2522 | if (isAllAppsVisible()) { |
| 2523 | showWorkspace(true); |
| 2524 | } else { |
| 2525 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | /** |
| 2530 | * Event handler for an app shortcut click. |
| 2531 | * |
| 2532 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2533 | */ |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2534 | protected void onClickAppShortcut(final View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2535 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2536 | Object tag = v.getTag(); |
| 2537 | if (!(tag instanceof ShortcutInfo)) { |
| 2538 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2539 | } |
| 2540 | |
| 2541 | // Open shortcut |
| 2542 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
| 2543 | final Intent intent = shortcut.intent; |
| 2544 | |
| 2545 | // Check for special shortcuts |
| 2546 | if (intent.getComponent() != null) { |
| 2547 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2548 | |
| 2549 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2550 | MemoryDumpActivity.startDump(this); |
| 2551 | return; |
| 2552 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2553 | toggleShowWeightWatcher(); |
| 2554 | return; |
| 2555 | } |
| 2556 | } |
| 2557 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2558 | // Check for abandoned promise |
| 2559 | if (shortcut.isAbandoned() && v instanceof BubbleTextView) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2560 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 2561 | builder.setTitle(R.string.abandoned_promises_title); |
Chris Wren | 803a4be | 2014-07-01 16:52:49 -0400 | [diff] [blame] | 2562 | builder.setMessage(R.string.abandoned_promise_explanation); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2563 | builder.setPositiveButton(R.string.abandoned_search, |
| 2564 | new DialogInterface.OnClickListener() { |
| 2565 | public void onClick(DialogInterface dialog, int id) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2566 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2567 | } |
| 2568 | } |
| 2569 | ); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2570 | builder.setNeutralButton(R.string.abandoned_clean_this, |
| 2571 | new DialogInterface.OnClickListener() { |
| 2572 | public void onClick(DialogInterface dialog, int id) { |
| 2573 | final BubbleTextView bubble = (BubbleTextView) v; |
| 2574 | final UserHandleCompat user = UserHandleCompat.myUserHandle(); |
| 2575 | mWorkspace.removeAbandonedPromise(bubble, user); |
| 2576 | } |
| 2577 | }); |
| 2578 | builder.create().show(); |
| 2579 | return; |
| 2580 | } |
| 2581 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2582 | // Start activities |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2583 | startAppShortcutOrInfoActivity(v); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2584 | } |
| 2585 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2586 | private void startAppShortcutOrInfoActivity(View v) { |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2587 | Object tag = v.getTag(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2588 | final ShortcutInfo shortcut; |
| 2589 | final Intent intent; |
| 2590 | if (tag instanceof ShortcutInfo) { |
| 2591 | shortcut = (ShortcutInfo) tag; |
| 2592 | intent = shortcut.intent; |
| 2593 | int[] pos = new int[2]; |
| 2594 | v.getLocationOnScreen(pos); |
| 2595 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2596 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 2597 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2598 | } else if (tag instanceof AppInfo) { |
| 2599 | shortcut = null; |
| 2600 | intent = ((AppInfo) tag).intent; |
| 2601 | } else { |
| 2602 | throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); |
| 2603 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2604 | |
| 2605 | boolean success = startActivitySafely(v, intent, tag); |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2606 | mStats.recordLaunch(intent, shortcut); |
| 2607 | |
| 2608 | if (success && v instanceof BubbleTextView) { |
| 2609 | mWaitingForResume = (BubbleTextView) v; |
| 2610 | mWaitingForResume.setStayPressed(true); |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | /** |
| 2615 | * Event handler for a folder icon click. |
| 2616 | * |
| 2617 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2618 | */ |
| 2619 | protected void onClickFolderIcon(View v) { |
| 2620 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2621 | if (!(v instanceof FolderIcon)){ |
| 2622 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2623 | } |
| 2624 | |
| 2625 | FolderIcon folderIcon = (FolderIcon) v; |
| 2626 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2627 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2628 | |
| 2629 | // If the folder info reports that the associated folder is open, then verify that |
| 2630 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2631 | if (info.opened && openFolder == null) { |
| 2632 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2633 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2634 | info.opened = false; |
| 2635 | } |
| 2636 | |
| 2637 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2638 | // Close any open folder |
| 2639 | closeFolder(); |
| 2640 | // Open the requested folder |
| 2641 | openFolder(folderIcon); |
| 2642 | } else { |
| 2643 | // Find the open folder... |
| 2644 | int folderScreen; |
| 2645 | if (openFolder != null) { |
| 2646 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2647 | // .. and close it |
| 2648 | closeFolder(openFolder); |
| 2649 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2650 | // Close any folder open on the current screen |
| 2651 | closeFolder(); |
| 2652 | // Pull the folder onto this screen |
| 2653 | openFolder(folderIcon); |
| 2654 | } |
| 2655 | } |
| 2656 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2659 | /** |
| 2660 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2661 | * on the home screen. |
| 2662 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2663 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2664 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2665 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2666 | } |
| 2667 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2668 | /** |
| 2669 | * Event handler for the wallpaper picker button that appears after a long press |
| 2670 | * on the home screen. |
| 2671 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2672 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2673 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2674 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2675 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2676 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
| 2677 | } |
| 2678 | |
| 2679 | /** |
| 2680 | * Event handler for a click on the settings button that appears after a long press |
| 2681 | * on the home screen. |
| 2682 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2683 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2684 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
| 2685 | } |
| 2686 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2687 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2688 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2689 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2692 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2693 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2694 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2695 | } |
| 2696 | |
| 2697 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2698 | if (mHapticFeedbackTouchListener == null) { |
| 2699 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2700 | @Override |
| 2701 | public boolean onTouch(View v, MotionEvent event) { |
| 2702 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2703 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2704 | } |
| 2705 | return false; |
| 2706 | } |
| 2707 | }; |
| 2708 | } |
| 2709 | return mHapticFeedbackTouchListener; |
| 2710 | } |
| 2711 | |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2712 | public void onDragStarted(View view) {} |
| 2713 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2714 | /** |
| 2715 | * Called when the user stops interacting with the launcher. |
| 2716 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2717 | */ |
| 2718 | protected void onInteractionEnd() {} |
| 2719 | |
| 2720 | /** |
| 2721 | * Called when the user starts interacting with the launcher. |
| 2722 | * The possible interactions are: |
| 2723 | * - open all apps |
| 2724 | * - reorder an app shortcut, or a widget |
| 2725 | * - open the overview mode. |
| 2726 | * This is a good time to stop doing things that only make sense |
| 2727 | * when the user is on the homescreen and not doing housekeeping. |
| 2728 | */ |
| 2729 | protected void onInteractionBegin() {} |
| 2730 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2731 | void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2732 | String packageName = componentName.getPackageName(); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 2733 | try { |
| 2734 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2735 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
| 2736 | launcherApps.showAppDetailsForProfile(componentName, user); |
| 2737 | } catch (SecurityException e) { |
| 2738 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2739 | Log.e(TAG, "Launcher does not have permission to launch settings"); |
| 2740 | } catch (ActivityNotFoundException e) { |
| 2741 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2742 | Log.e(TAG, "Unable to launch settings"); |
| 2743 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2746 | // returns true if the activity was started |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2747 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags, |
| 2748 | UserHandleCompat user) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2749 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2750 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2751 | // We may give them the option of disabling apps this way. |
| 2752 | int messageId = R.string.uninstall_system_app_text; |
| 2753 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2754 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2755 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2756 | String packageName = componentName.getPackageName(); |
| 2757 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2758 | Intent intent = new Intent( |
| 2759 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2760 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2761 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 2762 | if (user != null) { |
| 2763 | user.addToIntent(intent, Intent.EXTRA_USER); |
| 2764 | } |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2765 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2766 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2767 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2770 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 2771 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2772 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2773 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 2774 | // private contract between launcher and may be ignored in the future). |
| 2775 | boolean useLaunchAnimation = (v != null) && |
| 2776 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2777 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2778 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2779 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2780 | UserHandleCompat user = null; |
| 2781 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 2782 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 2783 | user = userManager.getUserForSerialNumber(serialNumber); |
| 2784 | } |
| 2785 | |
| 2786 | Bundle optsBundle = null; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2787 | if (useLaunchAnimation) { |
Adam Cohen | 4da294d | 2014-07-28 10:56:19 -0700 | [diff] [blame] | 2788 | ActivityOptions opts = Utilities.isLmp() ? |
| 2789 | ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) : |
| 2790 | ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); |
Adam Cohen | 6ea3b11 | 2014-06-11 11:38:49 -0700 | [diff] [blame] | 2791 | optsBundle = opts.toBundle(); |
| 2792 | } |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2793 | |
| 2794 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 2795 | // Could be launching some bookkeeping activity |
| 2796 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2797 | } else { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2798 | // TODO Component can be null when shortcuts are supported for secondary user |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 2799 | launcherApps.startActivityForProfile(intent.getComponent(), user, |
| 2800 | intent.getSourceBounds(), optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2801 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2802 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2803 | } catch (SecurityException e) { |
| 2804 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2805 | 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] | 2806 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2807 | "or use the exported attribute for this activity. " |
| 2808 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2809 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2810 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2811 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2812 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2813 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 2814 | boolean success = false; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 2815 | if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { |
| 2816 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 2817 | return false; |
| 2818 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2819 | try { |
| 2820 | success = startActivity(v, intent, tag); |
| 2821 | } catch (ActivityNotFoundException e) { |
| 2822 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2823 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 2824 | } |
| 2825 | return success; |
| 2826 | } |
| 2827 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2828 | /** |
| 2829 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 2830 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 2831 | */ |
| 2832 | private void copyFolderIconToImage(FolderIcon fi) { |
| 2833 | final int width = fi.getMeasuredWidth(); |
| 2834 | final int height = fi.getMeasuredHeight(); |
| 2835 | |
| 2836 | // Lazy load ImageView, Bitmap and Canvas |
| 2837 | if (mFolderIconImageView == null) { |
| 2838 | mFolderIconImageView = new ImageView(this); |
| 2839 | } |
| 2840 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 2841 | mFolderIconBitmap.getHeight() != height) { |
| 2842 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 2843 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 2844 | } |
| 2845 | |
| 2846 | DragLayer.LayoutParams lp; |
| 2847 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 2848 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 2849 | } else { |
| 2850 | lp = new DragLayer.LayoutParams(width, height); |
| 2851 | } |
| 2852 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2853 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 2854 | // view size by this scale factor. |
| 2855 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2856 | lp.customPosition = true; |
| 2857 | lp.x = mRectForFolderAnimation.left; |
| 2858 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2859 | lp.width = (int) (scale * width); |
| 2860 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2861 | |
| 2862 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2863 | fi.draw(mFolderIconCanvas); |
| 2864 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2865 | if (fi.getFolder() != null) { |
| 2866 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 2867 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2868 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2869 | // Just in case this image view is still in the drag layer from a previous animation, |
| 2870 | // we remove it and re-add it. |
| 2871 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 2872 | mDragLayer.removeView(mFolderIconImageView); |
| 2873 | } |
| 2874 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2875 | if (fi.getFolder() != null) { |
| 2876 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2877 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2878 | } |
| 2879 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2880 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2881 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2882 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 2883 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 2884 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 2885 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2886 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 2887 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2888 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 2889 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 2890 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2893 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 2894 | copyFolderIconToImage(fi); |
| 2895 | fi.setVisibility(View.INVISIBLE); |
| 2896 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2897 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2898 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 2899 | if (Utilities.isLmp()) { |
| 2900 | oa.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 2901 | } |
| 2902 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2903 | oa.start(); |
| 2904 | } |
| 2905 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2906 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2907 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2908 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 2909 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 2910 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 2911 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2912 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2913 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2914 | // We remove and re-draw the FolderIcon in-case it has changed |
| 2915 | mDragLayer.removeView(mFolderIconImageView); |
| 2916 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2917 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2918 | scaleX, scaleY); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 2919 | oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2920 | oa.addListener(new AnimatorListenerAdapter() { |
| 2921 | @Override |
| 2922 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2923 | if (cl != null) { |
| 2924 | cl.clearFolderLeaveBehind(); |
| 2925 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 2926 | mDragLayer.removeView(mFolderIconImageView); |
| 2927 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2928 | } |
| 2929 | } |
| 2930 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2931 | oa.start(); |
| 2932 | } |
| 2933 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2934 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 2935 | * 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] | 2936 | * is animated relative to the specified View. If the View is null, no animation |
| 2937 | * is played. |
| 2938 | * |
| 2939 | * @param folderInfo The FolderInfo describing the folder to open. |
| 2940 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2941 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2942 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2943 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2944 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2945 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2946 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2947 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 2948 | // There was a one-off crash where the folder had a parent already. |
| 2949 | if (folder.getParent() == null) { |
| 2950 | mDragLayer.addView(folder); |
| 2951 | mDragController.addDropTarget((DropTarget) folder); |
| 2952 | } else { |
| 2953 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 2954 | folder.getParent() + ")."); |
| 2955 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2956 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2957 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 2958 | |
| 2959 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 2960 | // the workspace items |
| 2961 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2962 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 2966 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2967 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 2968 | if (folder.isEditingName()) { |
| 2969 | folder.dismissEditingName(); |
| 2970 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2971 | closeFolder(folder); |
| 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | void closeFolder(Folder folder) { |
| 2976 | folder.getInfo().opened = false; |
| 2977 | |
| 2978 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 2979 | if (parent != null) { |
| 2980 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 2981 | shrinkAndFadeInFolderIcon(fi); |
| 2982 | } |
| 2983 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 2984 | |
| 2985 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 2986 | // longer occludeds the workspace items |
| 2987 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2988 | } |
| 2989 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2990 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 2991 | if (!isDraggingEnabled()) return false; |
| 2992 | if (isWorkspaceLocked()) return false; |
| 2993 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2994 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2995 | if (v instanceof Workspace) { |
| 2996 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 2997 | if (mWorkspace.enterOverviewMode()) { |
| 2998 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2999 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 3000 | return true; |
| 3001 | } else { |
| 3002 | return false; |
| 3003 | } |
Adam Cohen | aa4c8c1 | 2014-06-06 11:52:52 -0700 | [diff] [blame] | 3004 | } else { |
| 3005 | return false; |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3006 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 3009 | CellLayout.CellInfo longClickCellInfo = null; |
| 3010 | View itemUnderLongClick = null; |
| 3011 | if (v.getTag() instanceof ItemInfo) { |
| 3012 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3013 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 3014 | itemUnderLongClick = longClickCellInfo.cell; |
| 3015 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3016 | } |
| 3017 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3018 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 3019 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3020 | final boolean inHotseat = isHotseatLayout(v); |
| 3021 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3022 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3023 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3024 | // User long pressed on empty space |
| 3025 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 3026 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 3027 | if (mWorkspace.isInOverviewMode()) { |
| 3028 | mWorkspace.startReordering(v); |
| 3029 | } else { |
| 3030 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 3031 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3032 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 3033 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 3034 | mHotseat.getOrderInHotseat( |
| 3035 | longClickCellInfo.cellX, |
| 3036 | longClickCellInfo.cellY)); |
| 3037 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3038 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3039 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3040 | } |
| 3041 | } |
| 3042 | } |
| 3043 | return true; |
| 3044 | } |
| 3045 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3046 | boolean isHotseatLayout(View layout) { |
| 3047 | return mHotseat != null && layout != null && |
| 3048 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 3049 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 3050 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3051 | /** |
| 3052 | * Returns the CellLayout of the specified container at the specified screen. |
| 3053 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3054 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3055 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 3056 | if (mHotseat != null) { |
| 3057 | return mHotseat.getLayout(); |
| 3058 | } else { |
| 3059 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 3060 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3061 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3062 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 3063 | } |
| 3064 | } |
| 3065 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3066 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3067 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 3068 | } |
| 3069 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3070 | private void setWorkspaceBackground(boolean workspace) { |
| 3071 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 3072 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 3075 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3076 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 3077 | int curflags = getWindow().getAttributes().flags |
| 3078 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 3079 | if (wpflags != curflags) { |
| 3080 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 3081 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 3082 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3085 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3086 | if (v instanceof LauncherTransitionable) { |
| 3087 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3088 | } |
| 3089 | } |
| 3090 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3091 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3092 | if (v instanceof LauncherTransitionable) { |
| 3093 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3094 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3095 | |
| 3096 | // Update the workspace transition step as well |
| 3097 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3098 | } |
| 3099 | |
| 3100 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3101 | if (v instanceof LauncherTransitionable) { |
| 3102 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3103 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3107 | if (v instanceof LauncherTransitionable) { |
| 3108 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3109 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3110 | |
| 3111 | // Update the workspace transition step as well |
| 3112 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3113 | } |
| 3114 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3115 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3116 | * Things to test when changing the following seven functions. |
| 3117 | * - Home from workspace |
| 3118 | * - from center screen |
| 3119 | * - from other screens |
| 3120 | * - Home from all apps |
| 3121 | * - from center screen |
| 3122 | * - from other screens |
| 3123 | * - Back from all apps |
| 3124 | * - from center screen |
| 3125 | * - from other screens |
| 3126 | * - Launch app from workspace and quit |
| 3127 | * - with back |
| 3128 | * - with home |
| 3129 | * - Launch app from all apps and quit |
| 3130 | * - with back |
| 3131 | * - with home |
| 3132 | * - Go to a screen that's not the default, then all |
| 3133 | * apps, and launch and app, and go back |
| 3134 | * - with back |
| 3135 | * -with home |
| 3136 | * - On workspace, long press power and go back |
| 3137 | * - with back |
| 3138 | * - with home |
| 3139 | * - On all apps, long press power and go back |
| 3140 | * - with back |
| 3141 | * - with home |
| 3142 | * - On workspace, power off |
| 3143 | * - On all apps, power off |
| 3144 | * - Launch an app and turn off the screen while in that app |
| 3145 | * - Go back with home key |
| 3146 | * - Go back with back key TODO: make this not go to workspace |
| 3147 | * - From all apps |
| 3148 | * - From workspace |
| 3149 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3150 | * - From all apps |
| 3151 | * - From the center workspace |
| 3152 | * - From another workspace |
| 3153 | */ |
| 3154 | |
| 3155 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3156 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3157 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3158 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3159 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3160 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3161 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3162 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3163 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3164 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3165 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3166 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3167 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3168 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3169 | mStateAnimation.cancel(); |
| 3170 | mStateAnimation = null; |
| 3171 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3172 | |
| 3173 | boolean material = Utilities.isLmp(); |
| 3174 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3175 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3176 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3177 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); |
| 3178 | final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3179 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3180 | final int itemsAlphaStagger = |
| 3181 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3182 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3183 | final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3184 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3185 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3186 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3187 | Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ? |
| 3188 | Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3189 | Animator workspaceAnim = |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3190 | mWorkspace.getChangeStateAnimation(workspaceState, animated); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3191 | if (!LauncherAppState.isDisableAllApps() |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3192 | || contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3193 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3194 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3195 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3196 | |
| 3197 | if (animated) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3198 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 3199 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3200 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3201 | toView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3202 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3203 | final View page = content.getPageAt(content.getCurrentPage()); |
| 3204 | final View revealView = toView.findViewById(R.id.fake_page); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3205 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3206 | final float initialPanelAlpha = 1f; |
| 3207 | |
| 3208 | final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; |
| 3209 | if (isWidgetTray) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3210 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3211 | } else { |
| 3212 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3213 | } |
| 3214 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3215 | // Hide the real page background, and swap in the fake one |
| 3216 | revealView.setVisibility(View.VISIBLE); |
| 3217 | content.setPageBackgroundsVisible(false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3218 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3219 | int width = revealView.getMeasuredWidth(); |
| 3220 | int height = revealView.getMeasuredHeight(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3221 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3222 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3223 | revealView.setTranslationY(0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3224 | revealView.setTranslationX(0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3225 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3226 | // Get the y delta between the center of the page and the center of the all apps button |
| 3227 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3228 | getAllAppsButton(), null); |
| 3229 | float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3230 | float xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3231 | |
| 3232 | float initAlpha = isWidgetTray ? 0.3f : 1f; |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3233 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3234 | PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3235 | PropertyValuesHolder panelDriftY = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3236 | PropertyValuesHolder.ofFloat("translationY", yDrift, 0); |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3237 | PropertyValuesHolder panelDriftX = |
| 3238 | PropertyValuesHolder.ofFloat("translationX", xDrift, 0); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3239 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3240 | ObjectAnimator panelAlphaAndDrift = |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3241 | LauncherAnimUtils.ofPropertyValuesHolder(revealView, panelAlpha, panelDriftY, panelDriftX); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3242 | panelAlphaAndDrift.setDuration(revealDuration); |
| 3243 | panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3244 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3245 | mStateAnimation.play(panelAlphaAndDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3246 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3247 | if (page != null) { |
| 3248 | page.setVisibility(View.VISIBLE); |
| 3249 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3250 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3251 | ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", yDrift, 0); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3252 | pageDrift.setDuration(revealDuration); |
| 3253 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3254 | pageDrift.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3255 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3256 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3257 | page.setAlpha(0f); |
| 3258 | ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 0f, 1f); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3259 | itemsAlpha.setDuration(revealDuration); |
| 3260 | itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 3261 | itemsAlpha.setStartDelay(itemsAlphaStagger); |
| 3262 | mStateAnimation.play(itemsAlpha); |
| 3263 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3264 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3265 | View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator); |
| 3266 | pageIndicators.setAlpha(0.01f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3267 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3268 | LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3269 | indicatorsAlpha.setDuration(revealDuration); |
| 3270 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3271 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3272 | if (material) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3273 | final View allApps = getAllAppsButton(); |
| 3274 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3275 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3276 | float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 3277 | Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2, |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3278 | height / 2, startRadius, revealRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3279 | reveal.setDuration(revealDuration); |
| 3280 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3281 | |
| 3282 | reveal.addListener(new AnimatorListenerAdapter() { |
| 3283 | public void onAnimationStart(Animator animation) { |
| 3284 | if (!isWidgetTray) { |
| 3285 | allApps.setVisibility(View.INVISIBLE); |
| 3286 | } |
| 3287 | } |
| 3288 | public void onAnimationEnd(Animator animation) { |
| 3289 | if (!isWidgetTray) { |
| 3290 | allApps.setVisibility(View.VISIBLE); |
| 3291 | } |
| 3292 | } |
| 3293 | }); |
| 3294 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3295 | mStateAnimation.play(reveal); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3296 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3297 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3298 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
| 3299 | @Override |
| 3300 | public void onAnimationEnd(Animator animation) { |
| 3301 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3302 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
| 3303 | |
| 3304 | revealView.setVisibility(View.INVISIBLE); |
| 3305 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3306 | if (page != null) { |
| 3307 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3308 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3309 | content.setPageBackgroundsVisible(true); |
| 3310 | |
| 3311 | // Hide the search bar |
| 3312 | if (mSearchDropTargetBar != null) { |
| 3313 | mSearchDropTargetBar.hideSearchBar(false); |
| 3314 | } |
| 3315 | } |
| 3316 | |
| 3317 | @Override |
| 3318 | public void onAnimationStart(Animator animation) { |
| 3319 | // Prepare the position |
| 3320 | toView.bringToFront(); |
| 3321 | toView.setVisibility(View.VISIBLE); |
| 3322 | } |
| 3323 | }); |
| 3324 | |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3325 | boolean delayAnim = false; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3326 | if (workspaceAnim != null) { |
| 3327 | mStateAnimation.play(workspaceAnim); |
| 3328 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3329 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3330 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3331 | |
| 3332 | // If any of the objects being animated haven't been measured/laid out |
| 3333 | // yet, delay the animation until we get a layout pass |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3334 | if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3335 | (mWorkspace.getMeasuredWidth() == 0) || |
| 3336 | (toView.getMeasuredWidth() == 0)) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3337 | delayAnim = true; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3338 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3339 | |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3340 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3341 | final Runnable startAnimRunnable = new Runnable() { |
| 3342 | public void run() { |
| 3343 | // Check that mStateAnimation hasn't changed while |
| 3344 | // we waited for a layout/draw pass |
| 3345 | if (mStateAnimation != stateAnimation) |
| 3346 | return; |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3347 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3348 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3349 | LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3350 | } |
| 3351 | }; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3352 | if (delayAnim) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3353 | toView.bringToFront(); |
| 3354 | toView.setVisibility(View.VISIBLE); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3355 | final ViewTreeObserver observer = toView.getViewTreeObserver(); |
| 3356 | observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { |
| 3357 | public void onGlobalLayout() { |
| 3358 | startAnimRunnable.run(); |
| 3359 | toView.getViewTreeObserver().removeOnGlobalLayoutListener(this); |
| 3360 | } |
| 3361 | }); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3362 | } else { |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3363 | startAnimRunnable.run(); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3364 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3365 | } else { |
| 3366 | toView.setTranslationX(0.0f); |
| 3367 | toView.setTranslationY(0.0f); |
| 3368 | toView.setScaleX(1.0f); |
| 3369 | toView.setScaleY(1.0f); |
| 3370 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3371 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3372 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3373 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3374 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3375 | if (mSearchDropTargetBar != null) { |
| 3376 | mSearchDropTargetBar.hideSearchBar(false); |
| 3377 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3378 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3379 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3380 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3381 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3382 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3383 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3384 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3385 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | /** |
| 3389 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3390 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3391 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3392 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3393 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3394 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3395 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3396 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3397 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3398 | mStateAnimation.cancel(); |
| 3399 | mStateAnimation = null; |
| 3400 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3401 | |
| 3402 | boolean material = Utilities.isLmp(); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3403 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3404 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3405 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3406 | final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3407 | final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3408 | final int itemsAlphaStagger = |
| 3409 | res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3410 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3411 | final float scaleFactor = (float) |
| 3412 | res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
| 3413 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3414 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3415 | Animator workspaceAnim = null; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3416 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3417 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3418 | toState, animated); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3419 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3420 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3421 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3422 | toState, animated); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3423 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3424 | |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3425 | showHotseat(animated); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3426 | if (animated) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3427 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3428 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3429 | final AppsCustomizePagedView content = (AppsCustomizePagedView) |
| 3430 | fromView.findViewById(R.id.apps_customize_pane_content); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3431 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3432 | final View page = content.getPageAt(content.getNextPage()); |
| 3433 | final View revealView = fromView.findViewById(R.id.fake_page); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3434 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3435 | AppsCustomizePagedView.ContentType contentType = content.getContentType(); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3436 | final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; |
| 3437 | |
| 3438 | if (isWidgetTray) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3439 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); |
| 3440 | } else { |
| 3441 | revealView.setBackground(res.getDrawable(R.drawable.quantum_panel)); |
| 3442 | } |
| 3443 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3444 | int width = revealView.getMeasuredWidth(); |
| 3445 | int height = revealView.getMeasuredHeight(); |
| 3446 | float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3447 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3448 | // Hide the real page background, and swap in the fake one |
| 3449 | revealView.setVisibility(View.VISIBLE); |
| 3450 | content.setPageBackgroundsVisible(false); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3451 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3452 | final View allAppsButton = getAllAppsButton(); |
| 3453 | revealView.setTranslationY(0); |
| 3454 | int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, |
| 3455 | allAppsButton, null); |
| 3456 | float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1]; |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3457 | float xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0]; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3458 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3459 | revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3460 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3461 | // The vertical motion of the apps panel should be delayed by one frame |
| 3462 | // from the conceal animation in order to give the right feel. We correpsondingly |
| 3463 | // shorten the duration so that the slide and conceal end at the same time. |
Adam Cohen | 94afab4 | 2014-08-24 16:10:54 -0700 | [diff] [blame] | 3464 | ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift); |
| 3465 | panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3466 | panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3467 | panelDriftY.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3468 | mStateAnimation.play(panelDriftY); |
| 3469 | |
| 3470 | ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", 0, xDrift); |
| 3471 | panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
| 3472 | panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
| 3473 | panelDriftX.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3474 | mStateAnimation.play(panelDriftX); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3475 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3476 | if (isWidgetTray) { |
| 3477 | ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, 0.4f); |
| 3478 | panelAlpha.setDuration(revealDuration); |
| 3479 | panelAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3480 | mStateAnimation.play(panelAlpha); |
| 3481 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3482 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3483 | if (page != null) { |
| 3484 | page.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3485 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3486 | ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", |
| 3487 | 0, yDrift); |
| 3488 | pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3489 | pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3490 | pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3491 | mStateAnimation.play(pageDrift); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3492 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3493 | page.setAlpha(1f); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3494 | ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f); |
| 3495 | itemsAlpha.setDuration(100); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3496 | itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3497 | mStateAnimation.play(itemsAlpha); |
| 3498 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3499 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3500 | View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3501 | pageIndicators.setAlpha(1f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3502 | ObjectAnimator indicatorsAlpha = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3503 | LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3504 | indicatorsAlpha.setDuration(revealDuration); |
| 3505 | indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 3506 | mStateAnimation.play(indicatorsAlpha); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3507 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3508 | width = revealView.getMeasuredWidth(); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3509 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3510 | if (material) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3511 | if (!isWidgetTray) { |
| 3512 | allAppsButton.setVisibility(View.INVISIBLE); |
| 3513 | } |
| 3514 | int allAppsButtonSize = LauncherAppState.getInstance(). |
| 3515 | getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize; |
| 3516 | float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2; |
Nilesh Agrawal | 300c150 | 2014-07-22 13:20:54 -0700 | [diff] [blame] | 3517 | Animator reveal = |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3518 | LauncherAnimUtils.createCircularReveal(revealView, width / 2, |
| 3519 | height / 2, revealRadius, finalRadius); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3520 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 3521 | reveal.setDuration(revealDuration); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3522 | reveal.setStartDelay(itemsAlphaStagger); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3523 | |
| 3524 | reveal.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3525 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3526 | revealView.setVisibility(View.INVISIBLE); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 3527 | if (!isWidgetTray) { |
| 3528 | allAppsButton.setVisibility(View.VISIBLE); |
| 3529 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3530 | } |
| 3531 | }); |
| 3532 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3533 | mStateAnimation.play(reveal); |
| 3534 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3535 | |
| 3536 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3537 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
| 3538 | mAppsCustomizeContent.stopScrolling(); |
| 3539 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3540 | if (workspaceAnim != null) { |
| 3541 | mStateAnimation.play(workspaceAnim); |
| 3542 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3543 | |
| 3544 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3545 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3546 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3547 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3548 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3549 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3550 | if (onCompleteRunnable != null) { |
| 3551 | onCompleteRunnable.run(); |
| 3552 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3553 | |
| 3554 | revealView.setLayerType(View.LAYER_TYPE_NONE, null); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 3555 | if (page != null) { |
| 3556 | page.setLayerType(View.LAYER_TYPE_NONE, null); |
| 3557 | } |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 3558 | content.setPageBackgroundsVisible(true); |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3559 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3560 | } |
| 3561 | }); |
| 3562 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3563 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3564 | dispatchOnLauncherTransitionStart(toView, animated, true); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3565 | LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3566 | } else { |
| 3567 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3568 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3569 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3570 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3571 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3572 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3573 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3574 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3577 | @Override |
| 3578 | public void onTrimMemory(int level) { |
| 3579 | super.onTrimMemory(level); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 3580 | if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) { |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3581 | mAppsCustomizeTabHost.onTrimMemory(); |
| 3582 | } |
| 3583 | } |
| 3584 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3585 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3586 | showWorkspace(animated, null); |
| 3587 | } |
| 3588 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3589 | protected void showWorkspace() { |
| 3590 | showWorkspace(true); |
| 3591 | } |
| 3592 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3593 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 3594 | if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3595 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3596 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3597 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3598 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3599 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3600 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3601 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3602 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3603 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3604 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3605 | // Set focus to the AppsCustomize button |
| 3606 | if (mAllAppsButton != null) { |
| 3607 | mAllAppsButton.requestFocus(); |
| 3608 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3609 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3610 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3611 | // Change the state *after* we've called all the transition code |
| 3612 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3613 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3614 | // Resume the auto-advance of widgets |
| 3615 | mUserPresent = true; |
| 3616 | updateRunning(); |
| 3617 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3618 | // Send an accessibility event to announce the context change |
| 3619 | getWindow().getDecorView() |
| 3620 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3621 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3622 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3623 | } |
| 3624 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3625 | void showOverviewMode(boolean animated) { |
| 3626 | mWorkspace.setVisibility(View.VISIBLE); |
| 3627 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3628 | mState = State.WORKSPACE; |
| 3629 | onWorkspaceShown(animated); |
| 3630 | } |
| 3631 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3632 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3633 | } |
| 3634 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3635 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3636 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3637 | if (mState != State.WORKSPACE) return; |
| 3638 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3639 | if (resetPageToZero) { |
| 3640 | mAppsCustomizeTabHost.reset(); |
| 3641 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3642 | showAppsCustomizeHelper(animated, false, contentType); |
Adam Cohen | dcc5e71 | 2014-06-23 15:38:55 -0400 | [diff] [blame] | 3643 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3644 | @Override |
| 3645 | public void run() { |
| 3646 | // We post this in-case the all apps view isn't yet constructed. |
| 3647 | mAppsCustomizeTabHost.requestFocus(); |
| 3648 | } |
| 3649 | }); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3650 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3651 | // Change the state *after* we've called all the transition code |
| 3652 | mState = State.APPS_CUSTOMIZE; |
| 3653 | |
| 3654 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3655 | mUserPresent = false; |
| 3656 | updateRunning(); |
| 3657 | closeFolder(); |
| 3658 | |
| 3659 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3660 | getWindow().getDecorView() |
| 3661 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3664 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3665 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3666 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3667 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3668 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3669 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3670 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3671 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3672 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3673 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 3674 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 3675 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3676 | @Override |
| 3677 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3678 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3679 | // Before we show workspace, hide all apps again because |
| 3680 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 3681 | // clean up our state transition functions |
| 3682 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3683 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3684 | } else { |
| 3685 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3686 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3687 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3688 | }, delay); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3689 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3690 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3691 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3692 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3693 | final boolean animated = true; |
| 3694 | final boolean springLoaded = true; |
| 3695 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3696 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3697 | } |
| 3698 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 3699 | } |
| 3700 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3701 | void lockAllApps() { |
| 3702 | // TODO |
| 3703 | } |
| 3704 | |
| 3705 | void unlockAllApps() { |
| 3706 | // TODO |
| 3707 | } |
| 3708 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3709 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3710 | * Shows the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3711 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3712 | void showHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3713 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3714 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3715 | if (mHotseat.getAlpha() != 1f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3716 | int duration = 0; |
| 3717 | if (mSearchDropTargetBar != null) { |
| 3718 | duration = mSearchDropTargetBar.getTransitionInDuration(); |
| 3719 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3720 | mHotseat.animate().alpha(1f).setDuration(duration); |
| 3721 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3722 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3723 | mHotseat.setAlpha(1f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3729 | * Hides the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3730 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3731 | void hideHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3732 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3733 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3734 | if (mHotseat.getAlpha() != 0f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3735 | int duration = 0; |
| 3736 | if (mSearchDropTargetBar != null) { |
| 3737 | duration = mSearchDropTargetBar.getTransitionOutDuration(); |
| 3738 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3739 | mHotseat.animate().alpha(0f).setDuration(duration); |
| 3740 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3741 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3742 | mHotseat.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3743 | } |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3744 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3745 | } |
| 3746 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3747 | /** |
| 3748 | * Add an item from all apps or customize onto the given workspace screen. |
| 3749 | * If layout is null, add to the current screen. |
| 3750 | */ |
| 3751 | void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3752 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 3753 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 3754 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3755 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3756 | |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3757 | /** Maps the current orientation to an index for referencing orientation correct global icons */ |
| 3758 | private int getCurrentOrientationIndexForGlobalIcons() { |
| 3759 | // default - 0, landscape - 1 |
| 3760 | switch (getResources().getConfiguration().orientation) { |
| 3761 | case Configuration.ORIENTATION_LANDSCAPE: |
| 3762 | return 1; |
| 3763 | default: |
| 3764 | return 0; |
| 3765 | } |
| 3766 | } |
| 3767 | |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3768 | private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3769 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3770 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3771 | // Look for the toolbar icon specified in the activity meta-data |
| 3772 | Bundle metaData = packageManager.getActivityInfo( |
| 3773 | activityName, PackageManager.GET_META_DATA).metaData; |
| 3774 | if (metaData != null) { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3775 | int iconResId = metaData.getInt(resourceName); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3776 | if (iconResId != 0) { |
| 3777 | Resources res = packageManager.getResourcesForActivity(activityName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3778 | return res.getDrawable(iconResId); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3779 | } |
| 3780 | } |
| 3781 | } catch (NameNotFoundException e) { |
Michael Jurka | b6052a9 | 2011-07-12 17:02:45 -0700 | [diff] [blame] | 3782 | // This can happen if the activity defines an invalid drawable |
| 3783 | Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + |
| 3784 | " not found", e); |
Mathew Inwood | 70d5102 | 2011-07-12 13:41:41 +0100 | [diff] [blame] | 3785 | } catch (Resources.NotFoundException nfe) { |
| 3786 | // This can happen if the activity defines an invalid drawable |
| 3787 | Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), |
| 3788 | nfe); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3789 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3790 | return null; |
| 3791 | } |
| 3792 | |
| 3793 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3794 | private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3795 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 3796 | String toolbarResourceName) { |
| 3797 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3798 | Resources r = getResources(); |
| 3799 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 3800 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3801 | |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3802 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3803 | // If we were unable to find the icon via the meta-data, use a generic one |
| 3804 | if (toolbarIcon == null) { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3805 | toolbarIcon = r.getDrawable(fallbackDrawableId); |
| 3806 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3807 | if (button != null) { |
| 3808 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 3809 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3810 | return null; |
| 3811 | } else { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3812 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3813 | if (button != null) { |
| 3814 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 3815 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3816 | return toolbarIcon.getConstantState(); |
| 3817 | } |
| 3818 | } |
| 3819 | |
| 3820 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3821 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3822 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 3823 | String toolbarResourceName) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3824 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3825 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3826 | |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 3827 | if (button != null) { |
| 3828 | // If we were unable to find the icon via the meta-data, use a |
| 3829 | // generic one |
| 3830 | if (toolbarIcon == null) { |
| 3831 | button.setImageResource(fallbackDrawableId); |
| 3832 | } else { |
| 3833 | button.setImageDrawable(toolbarIcon); |
| 3834 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3835 | } |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 3836 | |
| 3837 | return toolbarIcon != null ? toolbarIcon.getConstantState() : null; |
| 3838 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3841 | private void updateTextButtonWithDrawable(int buttonId, Drawable d) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3842 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3843 | button.setCompoundDrawables(d, null, null, null); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3844 | } |
| 3845 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3846 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3847 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3848 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3849 | } |
| 3850 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3851 | private void invalidatePressedFocusedStates(View container, View button) { |
| 3852 | if (container instanceof HolographicLinearLayout) { |
| 3853 | HolographicLinearLayout layout = (HolographicLinearLayout) container; |
| 3854 | layout.invalidatePressedFocusedStates(); |
| 3855 | } else if (button instanceof HolographicImageView) { |
| 3856 | HolographicImageView view = (HolographicImageView) button; |
| 3857 | view.invalidatePressedFocusedStates(); |
| 3858 | } |
| 3859 | } |
| 3860 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3861 | public View getQsbBar() { |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3862 | if (mQsb == null) { |
| 3863 | mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false); |
| 3864 | mSearchDropTargetBar.addView(mQsb); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3865 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3866 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | protected boolean updateGlobalSearchIcon() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3870 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3871 | final ImageView searchButton = (ImageView) findViewById(R.id.search_button); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3872 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 3873 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3874 | |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3875 | final SearchManager searchManager = |
| 3876 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3877 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 3878 | if (activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3879 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3880 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3881 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 3882 | TOOLBAR_SEARCH_ICON_METADATA_NAME); |
| 3883 | if (sGlobalSearchIcon[coi] == null) { |
| 3884 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 3885 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 3886 | TOOLBAR_ICON_METADATA_NAME); |
| 3887 | } |
| 3888 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3889 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); |
| 3890 | searchButton.setVisibility(View.VISIBLE); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3891 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3892 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3893 | } else { |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 3894 | // We disable both search and voice search when there is no global search provider |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3895 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); |
| 3896 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 3897 | if (searchButton != null) searchButton.setVisibility(View.GONE); |
| 3898 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3899 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3900 | return false; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3904 | protected void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3905 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
| 3906 | final View searchButton = (ImageView) findViewById(R.id.search_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3907 | updateButtonWithDrawable(R.id.search_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3908 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3909 | } |
| 3910 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3911 | protected boolean updateVoiceSearchIcon(boolean searchVisible) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3912 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3913 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3914 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3915 | // We only show/update the voice search icon if the search icon is enabled as well |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3916 | final SearchManager searchManager = |
| 3917 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3918 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 3919 | |
| 3920 | ComponentName activityName = null; |
| 3921 | if (globalSearchActivity != null) { |
| 3922 | // Check if the global search activity handles voice search |
| 3923 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3924 | intent.setPackage(globalSearchActivity.getPackageName()); |
| 3925 | activityName = intent.resolveActivity(getPackageManager()); |
| 3926 | } |
| 3927 | |
| 3928 | if (activityName == null) { |
| 3929 | // Fallback: check if an activity other than the global search activity |
| 3930 | // resolves this |
| 3931 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3932 | activityName = intent.resolveActivity(getPackageManager()); |
| 3933 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3934 | if (searchVisible && activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3935 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3936 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3937 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 3938 | TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); |
| 3939 | if (sVoiceSearchIcon[coi] == null) { |
| 3940 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 3941 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 3942 | TOOLBAR_ICON_METADATA_NAME); |
| 3943 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3944 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3945 | voiceButton.setVisibility(View.VISIBLE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3946 | updateVoiceButtonProxyVisible(false); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3947 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3948 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3949 | } else { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3950 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 3951 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3952 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3953 | return false; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3954 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3955 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3956 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3957 | protected void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3958 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
| 3959 | final View voiceButton = findViewById(R.id.voice_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3960 | updateButtonWithDrawable(R.id.voice_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3961 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3962 | } |
| 3963 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3964 | public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) { |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3965 | final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); |
| 3966 | if (voiceButtonProxy != null) { |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3967 | boolean visible = !forceDisableVoiceButtonProxy && |
| 3968 | mWorkspace.shouldVoiceButtonProxyBeVisible(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3969 | voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3970 | voiceButtonProxy.bringToFront(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3971 | } |
| 3972 | } |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3973 | |
| 3974 | /** |
| 3975 | * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy |
| 3976 | * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns. |
| 3977 | */ |
| 3978 | public void disableVoiceButtonProxy(boolean disabled) { |
| 3979 | updateVoiceButtonProxyVisible(disabled); |
| 3980 | } |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3981 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3982 | @Override |
| 3983 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3984 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3985 | final List<CharSequence> text = event.getText(); |
| 3986 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3987 | // Populate event with a fake title based on the current state. |
| 3988 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3989 | text.add(mAppsCustomizeTabHost.getContentTag()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3990 | } else { |
| 3991 | text.add(getString(R.string.all_apps_home_button_label)); |
| 3992 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3993 | return result; |
| 3994 | } |
| 3995 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3996 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 3997 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3998 | */ |
| 3999 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 4000 | @Override |
| 4001 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 4002 | closeSystemDialogs(); |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 4007 | * Receives notifications whenever the appwidgets are reset. |
| 4008 | */ |
| 4009 | private class AppWidgetResetObserver extends ContentObserver { |
| 4010 | public AppWidgetResetObserver() { |
| 4011 | super(new Handler()); |
| 4012 | } |
| 4013 | |
| 4014 | @Override |
| 4015 | public void onChange(boolean selfChange) { |
| 4016 | onAppWidgetReset(); |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4021 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 4022 | * in onResume. |
| 4023 | * |
| 4024 | * This needs to be called from incoming places where resources might have been loaded |
| 4025 | * while we are paused. That is becaues the Configuration might be wrong |
| 4026 | * when we're not running, and if it comes back to what it was when we |
| 4027 | * were paused, we are not restarted. |
| 4028 | * |
| 4029 | * Implementation of the method from LauncherModel.Callbacks. |
| 4030 | * |
| 4031 | * @return true if we are currently paused. The caller might be able to |
| 4032 | * skip some work in that case since we will come back again. |
| 4033 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4034 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4035 | if (mPaused) { |
| 4036 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4037 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4038 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4039 | } |
| 4040 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4041 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4042 | return true; |
| 4043 | } else { |
| 4044 | return false; |
| 4045 | } |
| 4046 | } |
| 4047 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4048 | private boolean waitUntilResume(Runnable run) { |
| 4049 | return waitUntilResume(run, false); |
| 4050 | } |
| 4051 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4052 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 4053 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4056 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4057 | * If the activity is currently paused, signal that we need to re-run the loader |
| 4058 | * in onResume. |
| 4059 | * |
| 4060 | * This needs to be called from incoming places where resources might have been loaded |
| 4061 | * while we are paused. That is becaues the Configuration might be wrong |
| 4062 | * when we're not running, and if it comes back to what it was when we |
| 4063 | * were paused, we are not restarted. |
| 4064 | * |
| 4065 | * Implementation of the method from LauncherModel.Callbacks. |
| 4066 | * |
| 4067 | * @return true if we are currently paused. The caller might be able to |
| 4068 | * skip some work in that case since we will come back again. |
| 4069 | */ |
| 4070 | public boolean setLoadOnResume() { |
| 4071 | if (mPaused) { |
| 4072 | Log.i(TAG, "setLoadOnResume"); |
| 4073 | mOnResumeNeedsLoad = true; |
| 4074 | return true; |
| 4075 | } else { |
| 4076 | return false; |
| 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4081 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4082 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4083 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4084 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4085 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 4086 | } else { |
| 4087 | return SCREEN_COUNT / 2; |
| 4088 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4089 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4090 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4091 | /** |
| 4092 | * Refreshes the shortcuts shown on the workspace. |
| 4093 | * |
| 4094 | * Implementation of the method from LauncherModel.Callbacks. |
| 4095 | */ |
| 4096 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4097 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 4098 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4099 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 4100 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 4101 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4102 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4103 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4104 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4105 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 4106 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4107 | |
Michael Jurka | 05bf644 | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 4108 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4109 | if (mHotseat != null) { |
| 4110 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4111 | } |
| 4112 | } |
| 4113 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4114 | @Override |
| 4115 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4116 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4117 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 4118 | // If there are no screens, we need to have an empty screen |
| 4119 | if (orderedScreenIds.size() == 0) { |
| 4120 | mWorkspace.addExtraEmptyScreen(); |
| 4121 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4122 | |
| 4123 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4124 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 4125 | if (hasCustomContentToLeft()) { |
| 4126 | mWorkspace.createCustomContentContainer(); |
| 4127 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 4128 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | @Override |
| 4132 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 4133 | // Log to disk |
| 4134 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 4135 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 4136 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4137 | int count = orderedScreenIds.size(); |
| 4138 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 4139 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4140 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4141 | } |
| 4142 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4143 | private boolean shouldShowWeightWatcher() { |
| 4144 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4145 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b80 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 4146 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 4147 | |
| 4148 | return show; |
| 4149 | } |
| 4150 | |
| 4151 | private void toggleShowWeightWatcher() { |
| 4152 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 4153 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 4154 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 4155 | |
| 4156 | show = !show; |
| 4157 | |
| 4158 | SharedPreferences.Editor editor = sp.edit(); |
| 4159 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 4160 | editor.commit(); |
| 4161 | |
| 4162 | if (mWeightWatcher != null) { |
| 4163 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 4164 | } |
| 4165 | } |
| 4166 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4167 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 4168 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4169 | final ArrayList<ItemInfo> addAnimated, |
| 4170 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4171 | Runnable r = new Runnable() { |
| 4172 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4173 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4174 | } |
| 4175 | }; |
| 4176 | if (waitUntilResume(r)) { |
| 4177 | return; |
| 4178 | } |
| 4179 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4180 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4181 | if (newScreens != null) { |
| 4182 | bindAddScreens(newScreens); |
| 4183 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4184 | |
| 4185 | // We add the items without animation on non-visible pages, and with |
| 4186 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4187 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4188 | bindItems(addNotAnimated, 0, |
| 4189 | addNotAnimated.size(), false); |
| 4190 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 4191 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4192 | bindItems(addAnimated, 0, |
| 4193 | addAnimated.size(), true); |
| 4194 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4195 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4196 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 4197 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 4198 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4199 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4200 | addedApps != null && mAppsCustomizeContent != null) { |
| 4201 | mAppsCustomizeContent.addApps(addedApps); |
| 4202 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4203 | } |
| 4204 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4205 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4206 | * Bind the items start-end from the list. |
| 4207 | * |
| 4208 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4209 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4210 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 4211 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4212 | Runnable r = new Runnable() { |
| 4213 | public void run() { |
| 4214 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 4215 | } |
| 4216 | }; |
| 4217 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4218 | return; |
| 4219 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4220 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4221 | // 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] | 4222 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 4223 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4224 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4225 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4226 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4227 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4228 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4229 | |
| 4230 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4231 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4232 | mHotseat == null) { |
| 4233 | continue; |
| 4234 | } |
| 4235 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4236 | switch (item.itemType) { |
| 4237 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4238 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4239 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4240 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4241 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4242 | /* |
| 4243 | * TODO: FIX collision case |
| 4244 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4245 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4246 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4247 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4248 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4249 | Object tag = v.getTag(); |
| 4250 | String desc = "Collision while binding workspace item: " + item |
| 4251 | + ". Collides with " + tag; |
| 4252 | if (LauncherAppState.isDogfoodBuild()) { |
| 4253 | throw (new RuntimeException(desc)); |
| 4254 | } else { |
| 4255 | Log.d(TAG, desc); |
| 4256 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4257 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4258 | } |
| 4259 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4260 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4261 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4262 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4263 | // Animate all the applications up now |
| 4264 | shortcut.setAlpha(0f); |
| 4265 | shortcut.setScaleX(0f); |
| 4266 | shortcut.setScaleY(0f); |
| 4267 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4268 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4269 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4270 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4271 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4272 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4273 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4274 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4275 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4276 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4277 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4278 | default: |
| 4279 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4280 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4281 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4282 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4283 | if (animateIcons) { |
| 4284 | // Animate to the correct page |
| 4285 | if (newShortcutsScreenId > -1) { |
| 4286 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4287 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4288 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4289 | public void run() { |
| 4290 | anim.playTogether(bounceAnims); |
| 4291 | anim.start(); |
| 4292 | } |
| 4293 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4294 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4295 | // We post the animation slightly delayed to prevent slowdowns |
| 4296 | // when we are loading right after we return to launcher. |
| 4297 | mWorkspace.postDelayed(new Runnable() { |
| 4298 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4299 | if (mWorkspace != null) { |
| 4300 | mWorkspace.snapToPage(newScreenIndex); |
| 4301 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4302 | NEW_APPS_ANIMATION_DELAY); |
| 4303 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4304 | } |
| 4305 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4306 | } else { |
| 4307 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4308 | } |
| 4309 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4310 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4311 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4312 | } |
| 4313 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4314 | /** |
| 4315 | * Implementation of the method from LauncherModel.Callbacks. |
| 4316 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4317 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4318 | Runnable r = new Runnable() { |
| 4319 | public void run() { |
| 4320 | bindFolders(folders); |
| 4321 | } |
| 4322 | }; |
| 4323 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4324 | return; |
| 4325 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4326 | sFolders.clear(); |
| 4327 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4328 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4329 | |
| 4330 | /** |
| 4331 | * Add the views for a widget to the workspace. |
| 4332 | * |
| 4333 | * Implementation of the method from LauncherModel.Callbacks. |
| 4334 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4335 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4336 | Runnable r = new Runnable() { |
| 4337 | public void run() { |
| 4338 | bindAppWidget(item); |
| 4339 | } |
| 4340 | }; |
| 4341 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4342 | return; |
| 4343 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4344 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4345 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4346 | if (DEBUG_WIDGETS) { |
| 4347 | Log.d(TAG, "bindAppWidget: " + item); |
| 4348 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4349 | final Workspace workspace = mWorkspace; |
| 4350 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4351 | AppWidgetProviderInfo appWidgetInfo; |
| 4352 | if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) && |
| 4353 | ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { |
| 4354 | |
| 4355 | appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName); |
| 4356 | if (appWidgetInfo == null) { |
| 4357 | if (DEBUG_WIDGETS) { |
| 4358 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4359 | + " belongs to component " + item.providerName |
| 4360 | + ", as the povider is null"); |
| 4361 | } |
| 4362 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4363 | return; |
| 4364 | } |
| 4365 | // Note: This assumes that the id remap broadcast is received before this step. |
| 4366 | // If that is not the case, the id remap will be ignored and user may see the |
| 4367 | // click to setup view. |
| 4368 | PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null); |
| 4369 | pendingInfo.spanX = item.spanX; |
| 4370 | pendingInfo.spanY = item.spanY; |
| 4371 | pendingInfo.minSpanX = item.minSpanX; |
| 4372 | pendingInfo.minSpanY = item.minSpanY; |
| 4373 | Bundle options = |
| 4374 | AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo); |
| 4375 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4376 | int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 4377 | boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( |
| 4378 | newWidgetId, appWidgetInfo, options); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4379 | |
| 4380 | // TODO consider showing a permission dialog when the widget is clicked. |
| 4381 | if (!success) { |
| 4382 | mAppWidgetHost.deleteAppWidgetId(newWidgetId); |
| 4383 | if (DEBUG_WIDGETS) { |
| 4384 | Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId |
| 4385 | + " belongs to component " + item.providerName |
| 4386 | + ", as the launcher is unable to bing a new widget id"); |
| 4387 | } |
| 4388 | LauncherModel.deleteItemFromDatabase(this, item); |
| 4389 | return; |
| 4390 | } |
| 4391 | |
| 4392 | item.appWidgetId = newWidgetId; |
| 4393 | |
| 4394 | // If the widget has a configure activity, it is still needs to set it up, otherwise |
| 4395 | // the widget is ready to go. |
| 4396 | item.restoreStatus = (appWidgetInfo.configure == null) |
| 4397 | ? LauncherAppWidgetInfo.RESTORE_COMPLETED |
| 4398 | : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; |
| 4399 | |
| 4400 | LauncherModel.updateItemInDatabase(this, item); |
| 4401 | } |
| 4402 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4403 | if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { |
| 4404 | final int appWidgetId = item.appWidgetId; |
| 4405 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 4406 | if (DEBUG_WIDGETS) { |
| 4407 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 4408 | } |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4409 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4410 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4411 | } else { |
| 4412 | appWidgetInfo = null; |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4413 | PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item); |
| 4414 | view.updateIcon(mIconCache); |
| 4415 | item.hostView = view; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4416 | item.hostView.updateAppWidget(null); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4417 | item.hostView.setOnClickListener(this); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4418 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4419 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4420 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4421 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4422 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4423 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4424 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4425 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4426 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4427 | workspace.requestLayout(); |
| 4428 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4429 | if (DEBUG_WIDGETS) { |
| 4430 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4431 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4432 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4433 | } |
| 4434 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4435 | /** |
| 4436 | * Restores a pending widget. |
| 4437 | * |
| 4438 | * @param appWidgetId The app widget id |
| 4439 | * @param cellInfo The position on screen where to create the widget. |
| 4440 | */ |
| 4441 | private void completeRestoreAppWidget(final int appWidgetId) { |
| 4442 | LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId); |
| 4443 | if ((view == null) || !(view instanceof PendingAppWidgetHostView)) { |
| 4444 | Log.e(TAG, "Widget update called, when the widget no longer exists."); |
| 4445 | return; |
| 4446 | } |
| 4447 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4448 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4449 | info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; |
| 4450 | |
| 4451 | mWorkspace.reinflateWidgetsIfNecessary(); |
| 4452 | LauncherModel.updateItemInDatabase(this, info); |
| 4453 | } |
| 4454 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4455 | public void onPageBoundSynchronously(int page) { |
| 4456 | mSynchronouslyBoundPages.add(page); |
| 4457 | } |
| 4458 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4459 | /** |
| 4460 | * Callback saying that there aren't any more items to bind. |
| 4461 | * |
| 4462 | * Implementation of the method from LauncherModel.Callbacks. |
| 4463 | */ |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4464 | public void finishBindingItems(final boolean upgradePath) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4465 | Runnable r = new Runnable() { |
| 4466 | public void run() { |
| 4467 | finishBindingItems(upgradePath); |
| 4468 | } |
| 4469 | }; |
| 4470 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4471 | return; |
| 4472 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4473 | if (mSavedState != null) { |
| 4474 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4475 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4476 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4477 | mSavedState = null; |
| 4478 | } |
| 4479 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4480 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4481 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4482 | setWorkspaceLoading(false); |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4483 | sendLoadingCompleteBroadcastIfNecessary(); |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 4484 | |
| 4485 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4486 | // widget configuration forced an orientation change), process them now. |
| 4487 | if (sPendingAddItem != null) { |
| 4488 | final long screenId = completeAdd(sPendingAddItem); |
| 4489 | |
| 4490 | // TODO: this moves the user to the page where the pending item was added. Ideally, |
| 4491 | // the screen would be guaranteed to exist after bind, and the page would be set through |
| 4492 | // the workspace restore process. |
| 4493 | mWorkspace.post(new Runnable() { |
| 4494 | @Override |
| 4495 | public void run() { |
| 4496 | mWorkspace.snapToScreenId(screenId); |
| 4497 | } |
| 4498 | }); |
| 4499 | sPendingAddItem = null; |
| 4500 | } |
| 4501 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4502 | if (upgradePath) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4503 | mWorkspace.getUniqueComponents(true, null); |
| 4504 | mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4505 | } |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4506 | PackageInstallerCompat.getInstance(this).onFinishBind(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4507 | } |
| 4508 | |
Adam Cohen | 3ed316a | 2014-07-23 18:21:20 -0700 | [diff] [blame] | 4509 | private void sendLoadingCompleteBroadcastIfNecessary() { |
| 4510 | if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) { |
| 4511 | String permission = |
| 4512 | getResources().getString(R.string.receive_first_load_broadcast_permission); |
| 4513 | Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE); |
| 4514 | sendBroadcast(intent, permission); |
| 4515 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4516 | editor.putBoolean(FIRST_LOAD_COMPLETE, true); |
| 4517 | editor.apply(); |
| 4518 | } |
| 4519 | } |
| 4520 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4521 | public boolean isAllAppsButtonRank(int rank) { |
| 4522 | if (mHotseat != null) { |
| 4523 | return mHotseat.isAllAppsButtonRank(rank); |
| 4524 | } |
| 4525 | return false; |
| 4526 | } |
| 4527 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4528 | private boolean canRunNewAppsAnimation() { |
| 4529 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4530 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4531 | } |
| 4532 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4533 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4534 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4535 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4536 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4537 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4538 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4539 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4540 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4541 | return bounceAnim; |
| 4542 | } |
| 4543 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4544 | public boolean useVerticalBarLayout() { |
| 4545 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4546 | getDeviceProfile().isVerticalBarLayout(); |
| 4547 | } |
| 4548 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4549 | protected Rect getSearchBarBounds() { |
| 4550 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4551 | getDeviceProfile().getSearchBarBounds(); |
| 4552 | } |
| 4553 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4554 | @Override |
| 4555 | public void bindSearchablesChanged() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4556 | boolean searchVisible = updateGlobalSearchIcon(); |
| 4557 | boolean voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4558 | if (mSearchDropTargetBar != null) { |
| 4559 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 4560 | } |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4561 | } |
| 4562 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4563 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4564 | * Add the icons for all apps. |
| 4565 | * |
| 4566 | * Implementation of the method from LauncherModel.Callbacks. |
| 4567 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4568 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4569 | if (LauncherAppState.isDisableAllApps()) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4570 | if (mIntentsOnWorkspaceFromUpgradePath != null) { |
| 4571 | if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) { |
| 4572 | getHotseat().addAllAppsFolder(mIconCache, apps, |
| 4573 | mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace); |
| 4574 | } |
| 4575 | mIntentsOnWorkspaceFromUpgradePath = null; |
Daniel Sandler | 8707e0f | 2013-08-15 15:54:18 -0700 | [diff] [blame] | 4576 | } |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4577 | if (mAppsCustomizeContent != null) { |
| 4578 | mAppsCustomizeContent.onPackagesUpdated( |
| 4579 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
| 4580 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4581 | } else { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 4582 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4583 | mAppsCustomizeContent.setApps(apps); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 4584 | mAppsCustomizeContent.onPackagesUpdated( |
| 4585 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4586 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4587 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | /** |
| 4591 | * A package was updated. |
| 4592 | * |
| 4593 | * Implementation of the method from LauncherModel.Callbacks. |
| 4594 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4595 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4596 | Runnable r = new Runnable() { |
| 4597 | public void run() { |
| 4598 | bindAppsUpdated(apps); |
| 4599 | } |
| 4600 | }; |
| 4601 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4602 | return; |
| 4603 | } |
| 4604 | |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 4605 | if (mWorkspace != null) { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4606 | mWorkspace.updateShortcutsAndWidgets(apps); |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 4607 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4608 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4609 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4610 | mAppsCustomizeContent != null) { |
| 4611 | mAppsCustomizeContent.updateApps(apps); |
| 4612 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4616 | * Update the state of a package, typically related to install state. |
| 4617 | * |
| 4618 | * Implementation of the method from LauncherModel.Callbacks. |
| 4619 | */ |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4620 | @Override |
| 4621 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4622 | if (mWorkspace != null) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4623 | mWorkspace.updatePackageState(installInfo); |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4624 | } |
| 4625 | } |
| 4626 | |
| 4627 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4628 | * A package was uninstalled. We take both the super set of packageNames |
| 4629 | * in addition to specific applications to remove, the reason being that |
| 4630 | * this can be called when a package is updated as well. In that scenario, |
| 4631 | * we only remove specific components from the workspace, where as |
| 4632 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4633 | * |
| 4634 | * Implementation of the method from LauncherModel.Callbacks. |
| 4635 | */ |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4636 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4637 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4638 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4639 | public void run() { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4640 | bindComponentsRemoved(packageNames, appInfos, user); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4641 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4642 | }; |
| 4643 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4644 | return; |
| 4645 | } |
| 4646 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4647 | if (!packageNames.isEmpty()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4648 | mWorkspace.removeItemsByPackageName(packageNames, user); |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4649 | } |
| 4650 | if (!appInfos.isEmpty()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4651 | mWorkspace.removeItemsByApplicationInfo(appInfos, user); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 4652 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4653 | |
Winson Chung | a182096 | 2011-10-03 16:31:06 -0700 | [diff] [blame] | 4654 | // Notify the drag controller |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4655 | mDragController.onAppsRemoved(packageNames, appInfos); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4656 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4657 | // Update AllApps |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4658 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4659 | mAppsCustomizeContent != null) { |
| 4660 | mAppsCustomizeContent.removeApps(appInfos); |
| 4661 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4662 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4663 | |
| 4664 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4665 | * A number of packages were updated. |
| 4666 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4667 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 4668 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4669 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4670 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 4671 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4672 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4673 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4674 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 4675 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 4676 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4677 | return; |
| 4678 | } |
| 4679 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4680 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4681 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4682 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4683 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4686 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 4687 | final Display d = getWindowManager().getDefaultDisplay(); |
| 4688 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 4689 | switch (d.getRotation()) { |
| 4690 | case Surface.ROTATION_0: |
| 4691 | case Surface.ROTATION_180: |
| 4692 | // We are currently in the same basic orientation as the natural orientation |
| 4693 | naturalOri = configOri; |
| 4694 | break; |
| 4695 | case Surface.ROTATION_90: |
| 4696 | case Surface.ROTATION_270: |
| 4697 | // We are currently in the other basic orientation to the natural orientation |
| 4698 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 4699 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 4700 | break; |
| 4701 | } |
| 4702 | |
| 4703 | int[] oriMap = { |
| 4704 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 4705 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 4706 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 4707 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 4708 | }; |
| 4709 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 4710 | // is landscape. |
| 4711 | int indexOffset = 0; |
| 4712 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 4713 | indexOffset = 1; |
| 4714 | } |
| 4715 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 4716 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 4717 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4718 | public boolean isRotationEnabled() { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 4719 | boolean enableRotation = sForceEnableRotation || |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4720 | getResources().getBoolean(R.bool.allow_rotation); |
| 4721 | return enableRotation; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4722 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4723 | public void lockScreenOrientation() { |
| 4724 | if (isRotationEnabled()) { |
| 4725 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 4726 | .getConfiguration().orientation)); |
| 4727 | } |
| 4728 | } |
| 4729 | public void unlockScreenOrientation(boolean immediate) { |
| 4730 | if (isRotationEnabled()) { |
| 4731 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4732 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4733 | } else { |
| 4734 | mHandler.postDelayed(new Runnable() { |
| 4735 | public void run() { |
| 4736 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 4737 | } |
| 4738 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4739 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4740 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4741 | } |
| 4742 | |
Sandeep Siddhartha | d4d3d08 | 2013-12-26 15:42:52 -0800 | [diff] [blame] | 4743 | /** |
| 4744 | * Called when the SearchBar hint should be changed. |
| 4745 | * |
| 4746 | * @param hint the hint to be displayed in the search bar. |
| 4747 | */ |
| 4748 | protected void onSearchBarHintChanged(String hint) { |
Sunny Goyal | 424418b | 2014-08-22 16:09:37 -0700 | [diff] [blame^] | 4749 | |
Sandeep Siddhartha | d4d3d08 | 2013-12-26 15:42:52 -0800 | [diff] [blame] | 4750 | } |
| 4751 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4752 | protected boolean isLauncherPreinstalled() { |
| 4753 | PackageManager pm = getPackageManager(); |
| 4754 | try { |
| 4755 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 4756 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4757 | return true; |
| 4758 | } else { |
| 4759 | return false; |
| 4760 | } |
| 4761 | } catch (NameNotFoundException e) { |
| 4762 | e.printStackTrace(); |
| 4763 | return false; |
| 4764 | } |
| 4765 | } |
| 4766 | |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 4767 | /** |
| 4768 | * This method indicates whether or not we should suggest default wallpaper dimensions |
| 4769 | * when our wallpaper cropper was not yet used to set a wallpaper. |
| 4770 | */ |
| 4771 | protected boolean overrideWallpaperDimensions() { |
| 4772 | return true; |
| 4773 | } |
| 4774 | |
Adam Cohen | 5eed5d8 | 2014-05-19 13:12:13 -0700 | [diff] [blame] | 4775 | protected boolean shouldClingFocusHotseatApp() { |
| 4776 | return false; |
| 4777 | } |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 4778 | protected String getFirstRunClingSearchBarHint() { |
| 4779 | return ""; |
| 4780 | } |
| 4781 | protected String getFirstRunCustomContentHint() { |
| 4782 | return ""; |
| 4783 | } |
Winson Chung | 3a6e7f3 | 2013-10-09 15:50:52 -0700 | [diff] [blame] | 4784 | protected int getFirstRunFocusedHotseatAppDrawableId() { |
| 4785 | return -1; |
| 4786 | } |
| 4787 | protected ComponentName getFirstRunFocusedHotseatAppComponentName() { |
| 4788 | return null; |
| 4789 | } |
| 4790 | protected int getFirstRunFocusedHotseatAppRank() { |
| 4791 | return -1; |
| 4792 | } |
| 4793 | protected String getFirstRunFocusedHotseatAppBubbleTitle() { |
| 4794 | return ""; |
| 4795 | } |
| 4796 | protected String getFirstRunFocusedHotseatAppBubbleDescription() { |
| 4797 | return ""; |
| 4798 | } |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 4799 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4800 | /** |
| 4801 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 4802 | * before showing the standard launcher experience. |
| 4803 | */ |
| 4804 | protected boolean hasFirstRunActivity() { |
| 4805 | return false; |
| 4806 | } |
| 4807 | |
| 4808 | /** |
| 4809 | * To be overridden by subclasses to launch any first run activity |
| 4810 | */ |
| 4811 | protected Intent getFirstRunActivity() { |
| 4812 | return null; |
| 4813 | } |
| 4814 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4815 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4816 | return !ActivityManager.isRunningInTestHarness() && |
| 4817 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4818 | } |
| 4819 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 4820 | protected boolean hasRunFirstRunActivity() { |
| 4821 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 4822 | } |
| 4823 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4824 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4825 | if (shouldRunFirstRunActivity() && |
| 4826 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4827 | Intent firstRunIntent = getFirstRunActivity(); |
| 4828 | if (firstRunIntent != null) { |
| 4829 | startActivity(firstRunIntent); |
| 4830 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4831 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4832 | } |
| 4833 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4834 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | private void markFirstRunActivityShown() { |
| 4838 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4839 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 4840 | editor.apply(); |
| 4841 | } |
| 4842 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4843 | /** |
| 4844 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 4845 | * screen that must be displayed and dismissed. |
| 4846 | */ |
| 4847 | protected boolean hasDismissableIntroScreen() { |
| 4848 | return false; |
| 4849 | } |
| 4850 | |
| 4851 | /** |
| 4852 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 4853 | */ |
| 4854 | protected View getIntroScreen() { |
| 4855 | return null; |
| 4856 | } |
| 4857 | |
| 4858 | /** |
| 4859 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 4860 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 4861 | */ |
| 4862 | private boolean shouldShowIntroScreen() { |
| 4863 | return hasDismissableIntroScreen() && |
| 4864 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 4865 | } |
| 4866 | |
| 4867 | protected void showIntroScreen() { |
| 4868 | View introScreen = getIntroScreen(); |
| 4869 | changeWallpaperVisiblity(false); |
| 4870 | if (introScreen != null) { |
| 4871 | mDragLayer.showOverlayView(introScreen); |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | public void dismissIntroScreen() { |
| 4876 | markIntroScreenDismissed(); |
| 4877 | if (showFirstRunActivity()) { |
| 4878 | // We delay hiding the intro view until the first run activity is showing. This |
| 4879 | // avoids a blip. |
| 4880 | mWorkspace.postDelayed(new Runnable() { |
| 4881 | @Override |
| 4882 | public void run() { |
| 4883 | mDragLayer.dismissOverlayView(); |
| 4884 | } |
| 4885 | }, ACTIVITY_START_DELAY); |
| 4886 | } else { |
| 4887 | mDragLayer.dismissOverlayView(); |
| 4888 | } |
| 4889 | changeWallpaperVisiblity(true); |
| 4890 | } |
| 4891 | |
| 4892 | private void markIntroScreenDismissed() { |
| 4893 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4894 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 4895 | editor.apply(); |
| 4896 | } |
| 4897 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4898 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4899 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 4900 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 4901 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 4902 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4906 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 4907 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 4908 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 4909 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4910 | } |
| 4911 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4912 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4913 | // Called from search suggestion, not supported in other profiles. |
| 4914 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 4915 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 4916 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 4917 | myUser); |
| 4918 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4919 | return null; |
| 4920 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4921 | return new AppInfo(this, activityInfo, myUser, mIconCache, null); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 4925 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4926 | // Called from search suggestion, not supported in other profiles. |
| 4927 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 4928 | UserHandleCompat.myUserHandle()); |
| 4929 | } |
| 4930 | |
| 4931 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 4932 | Bitmap icon, UserHandleCompat user) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 4933 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 4934 | CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 4935 | return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4936 | } |
| 4937 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 4938 | protected void moveWorkspaceToDefaultScreen() { |
| 4939 | mWorkspace.moveToDefaultScreen(false); |
| 4940 | } |
| 4941 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4942 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 4943 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 4944 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 4945 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 4948 | @Override |
| 4949 | public void onPageSwitch(View newPage, int newPageIndex) { |
| 4950 | } |
| 4951 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4952 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4953 | * Prints out out state for debugging. |
| 4954 | */ |
| 4955 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 4956 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 4957 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 4958 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 4959 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 4960 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 4961 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4962 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4963 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4964 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4965 | if (mAppsCustomizeContent != null) { |
| 4966 | mAppsCustomizeContent.dumpState(); |
| 4967 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 4968 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4969 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 4970 | |
| 4971 | @Override |
| 4972 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 4973 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4974 | synchronized (sDumpLogs) { |
| 4975 | writer.println(" "); |
| 4976 | writer.println("Debug logs: "); |
| 4977 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 4978 | writer.println(" " + sDumpLogs.get(i)); |
| 4979 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 4980 | } |
| 4981 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 4982 | |
| 4983 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 4984 | if (DEBUG_DUMP_LOG) { |
| 4985 | synchronized (sDumpLogs) { |
| 4986 | Log.d(TAG, ""); |
| 4987 | Log.d(TAG, "*********************"); |
| 4988 | Log.d(TAG, "Launcher debug logs: "); |
| 4989 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 4990 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 4991 | } |
| 4992 | Log.d(TAG, "*********************"); |
| 4993 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4994 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 4995 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 4999 | addDumpLog(tag, log, null, debugLog); |
| 5000 | } |
| 5001 | |
| 5002 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5003 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5004 | if (e != null) { |
| 5005 | Log.d(tag, log, e); |
| 5006 | } else { |
| 5007 | Log.d(tag, log); |
| 5008 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5009 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5010 | if (DEBUG_DUMP_LOG) { |
| 5011 | sDateStamp.setTime(System.currentTimeMillis()); |
| 5012 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 5013 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 5014 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5015 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5016 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5017 | } |
| 5018 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5019 | public void dumpLogsToLocalData() { |
| 5020 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5021 | new AsyncTask<Void, Void, Void>() { |
| 5022 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5023 | boolean success = false; |
| 5024 | sDateStamp.setTime(sRunStart); |
| 5025 | String FILENAME = sDateStamp.getMonth() + "-" |
| 5026 | + sDateStamp.getDay() + "_" |
| 5027 | + sDateStamp.getHours() + "-" |
| 5028 | + sDateStamp.getMinutes() + "_" |
| 5029 | + sDateStamp.getSeconds() + ".txt"; |
| 5030 | |
| 5031 | FileOutputStream fos = null; |
| 5032 | File outFile = null; |
| 5033 | try { |
| 5034 | outFile = new File(getFilesDir(), FILENAME); |
| 5035 | outFile.createNewFile(); |
| 5036 | fos = new FileOutputStream(outFile); |
| 5037 | } catch (Exception e) { |
| 5038 | e.printStackTrace(); |
| 5039 | } |
| 5040 | if (fos != null) { |
| 5041 | PrintWriter writer = new PrintWriter(fos); |
| 5042 | |
| 5043 | writer.println(" "); |
| 5044 | writer.println("Debug logs: "); |
| 5045 | synchronized (sDumpLogs) { |
| 5046 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 5047 | writer.println(" " + sDumpLogs.get(i)); |
| 5048 | } |
| 5049 | } |
| 5050 | writer.close(); |
| 5051 | } |
| 5052 | try { |
| 5053 | if (fos != null) { |
| 5054 | fos.close(); |
| 5055 | success = true; |
| 5056 | } |
| 5057 | } catch (IOException e) { |
| 5058 | e.printStackTrace(); |
| 5059 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5060 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 5061 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 5062 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 5063 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 5064 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5065 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5066 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 5067 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 5068 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 5069 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5070 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 5071 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 5072 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 5073 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 5074 | |
| 5075 | interface DebugIntents { |
| 5076 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 5077 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 5078 | } |