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; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 26 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
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; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.app.SearchManager; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 31 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 32 | import android.appwidget.AppWidgetManager; |
| 33 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 35 | import android.content.BroadcastReceiver; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 36 | import android.content.ComponentCallbacks2; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 37 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 38 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | import android.content.Context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 40 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 41 | import android.content.IntentFilter; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 42 | import android.content.SharedPreferences; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 43 | import android.content.pm.ActivityInfo; |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 44 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 46 | import android.content.pm.PackageManager.NameNotFoundException; |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 47 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 49 | import android.content.res.Resources; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 50 | import android.database.ContentObserver; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 51 | import android.graphics.Bitmap; |
| 52 | import android.graphics.Canvas; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame^] | 53 | import android.graphics.Color; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 54 | import android.graphics.Point; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 55 | import android.graphics.PorterDuff; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 56 | import android.graphics.Rect; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 57 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 58 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 59 | import android.os.AsyncTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 60 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 61 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 62 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 63 | import android.os.Message; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 64 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 65 | import android.os.SystemClock; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 66 | import android.provider.Settings; |
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; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame^] | 83 | import android.view.Window; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 84 | import android.view.View.OnClickListener; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 85 | import android.view.View.OnLongClickListener; |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 86 | import android.view.ViewGroup; |
| 87 | import android.view.ViewTreeObserver; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 88 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
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 | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 91 | import android.view.animation.AccelerateDecelerateInterpolator; |
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; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 99 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 100 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 101 | import com.android.launcher3.compat.LauncherAppsCompat; |
| 102 | import com.android.launcher3.compat.UserHandleCompat; |
| 103 | import com.android.launcher3.compat.UserManagerCompat; |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 104 | import com.android.launcher3.DropTarget.DragObject; |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 105 | import com.android.launcher3.PagedView.PageSwitchListener; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 106 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 107 | import java.io.DataInputStream; |
| 108 | import java.io.DataOutputStream; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 109 | import java.io.File; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 110 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 111 | import java.io.FileNotFoundException; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 112 | import java.io.FileOutputStream; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 113 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 114 | import java.io.PrintWriter; |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame^] | 115 | import java.lang.reflect.Field; |
| 116 | import java.lang.reflect.InvocationTargetException; |
| 117 | import java.lang.reflect.Method; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 118 | import java.text.DateFormat; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 119 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 120 | import java.util.Collection; |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 121 | import java.util.Date; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 122 | import java.util.HashMap; |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 123 | import java.util.List; |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 124 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 125 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 126 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 127 | /** |
| 128 | * Default launcher application. |
| 129 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 130 | public class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 131 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 132 | View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 133 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 134 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 135 | |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 136 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 137 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 138 | static final boolean DEBUG_STRICT_MODE = false; |
Daniel Sandler | f061f82 | 2013-06-27 13:59:36 -0400 | [diff] [blame] | 139 | static final boolean DEBUG_RESUME_TIME = false; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 140 | static final boolean DEBUG_DUMP_LOG = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 141 | |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 142 | static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run |
| 143 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 144 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 145 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 146 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 147 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 148 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 149 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 150 | private static final int REQUEST_BIND_APPWIDGET = 11; |
| 151 | |
Mathew Inwood | 876a846 | 2013-06-14 14:12:41 +0100 | [diff] [blame] | 152 | /** |
| 153 | * IntentStarter uses request codes starting with this. This must be greater than all activity |
| 154 | * request codes used internally. |
| 155 | */ |
| 156 | protected static final int REQUEST_LAST = 100; |
| 157 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 158 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 159 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 160 | static final int SCREEN_COUNT = 5; |
| 161 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 162 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 163 | private static final String PREFERENCES = "launcher.preferences"; |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 164 | // To turn on these properties, type |
| 165 | // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS] |
| 166 | static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate"; |
| 167 | static final String DUMP_STATE_PROPERTY = "launcher_dump_state"; |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 168 | static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 169 | |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 170 | // The Intent extra that defines whether to ignore the launch animation |
| 171 | static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 172 | "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 174 | // Type: int |
| 175 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 176 | // Type: int |
| 177 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 178 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 179 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 180 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 181 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 182 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 183 | 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] | 184 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 185 | 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] | 186 | // Type: boolean |
| 187 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 188 | // Type: long |
| 189 | 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] | 190 | // Type: int |
| 191 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x"; |
| 192 | // Type: int |
| 193 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y"; |
| 194 | // Type: parcelable |
| 195 | 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] | 196 | // Type: parcelable |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 197 | 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] | 198 | // Type: int[] |
| 199 | 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] | 200 | |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 201 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 202 | static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed"; |
Adam Cohen | b54a598 | 2014-01-08 15:21:04 -0800 | [diff] [blame] | 203 | static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; |
| 204 | |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 205 | 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] | 206 | private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 207 | "com.android.launcher.toolbar_search_icon"; |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 208 | private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME = |
Bjorn Bringert | e441bbc | 2013-06-06 21:54:20 +0100 | [diff] [blame] | 209 | "com.android.launcher.toolbar_voice_search_icon"; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 210 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 211 | public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; |
Daniel Sandler | 6053b800 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 212 | public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 213 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 214 | public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; |
| 215 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 216 | /** The different states that Launcher can be in. */ |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 217 | private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 218 | private State mState = State.WORKSPACE; |
| 219 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 220 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 221 | static final int APPWIDGET_HOST_ID = 1024; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 222 | public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 223 | private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; |
Adam Cohen | 646fdf7 | 2014-04-08 16:59:36 -0700 | [diff] [blame] | 224 | private static final int ACTIVITY_START_DELAY = 1000; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 225 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 226 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 227 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 228 | |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 229 | private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>(); |
| 230 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 231 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 232 | // 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] | 233 | private static int NEW_APPS_PAGE_MOVE_DELAY = 500; |
| 234 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 235 | private static int NEW_APPS_ANIMATION_DELAY = 500; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 236 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 237 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 238 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 239 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 240 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 241 | private LayoutInflater mInflater; |
| 242 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 243 | private Workspace mWorkspace; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 244 | private View mLauncherView; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 245 | private View mPageIndicators; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 246 | private DragLayer mDragLayer; |
| 247 | private DragController mDragController; |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 248 | private View mWeightWatcher; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 249 | private LauncherClings mLauncherClings; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 250 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 251 | private AppWidgetManager mAppWidgetManager; |
| 252 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 253 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 254 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 255 | private AppWidgetProviderInfo mPendingAddWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 256 | private int mPendingAddWidgetId = -1; |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 257 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 258 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 259 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 260 | private FolderInfo mFolderInfo; |
| 261 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 262 | private Hotseat mHotseat; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 263 | private ViewGroup mOverviewPanel; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 264 | |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 265 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 266 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 267 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 268 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 269 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 270 | private boolean mAutoAdvanceRunning = false; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 271 | private View mQsb; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 272 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 273 | private Bundle mSavedState; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 274 | // We set the state in both onCreate and then onNewIntent in some cases, which causes both |
| 275 | // scroll issues (because the workspace may not have been measured yet) and extra work. |
| 276 | // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. |
| 277 | private State mOnResumeState = State.NONE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 278 | |
| 279 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 280 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 281 | private boolean mWorkspaceLoading = true; |
| 282 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 283 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 284 | private boolean mRestoring; |
| 285 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 286 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 287 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 288 | private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>(); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 289 | private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>(); |
| 290 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 291 | // Keep track of whether the user has left launcher |
| 292 | private static boolean sPausedFromUserAction = false; |
| 293 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 294 | private Bundle mSavedInstanceState; |
| 295 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 296 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 297 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 298 | private boolean mUserPresent = true; |
| 299 | private boolean mVisible = false; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 300 | private boolean mHasFocus = false; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 301 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 302 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 303 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 304 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 305 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 306 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 307 | private View.OnTouchListener mHapticFeedbackTouchListener; |
| 308 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 309 | // Related to the auto-advancing of widgets |
| 310 | private final int ADVANCE_MSG = 1; |
| 311 | private final int mAdvanceInterval = 20000; |
| 312 | private final int mAdvanceStagger = 250; |
| 313 | private long mAutoAdvanceSentTime; |
| 314 | private long mAutoAdvanceTimeLeft = -1; |
| 315 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 316 | new HashMap<View, AppWidgetProviderInfo>(); |
| 317 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 318 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 319 | // match the sensor state. |
| 320 | private final int mRestoreScreenOrientationDelay = 500; |
| 321 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 322 | // External icons saved in case of resource changes, orientation, etc. |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 323 | private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; |
| 324 | private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; |
| 325 | private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2]; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 326 | |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 327 | private Intent mAppMarketIntent = null; |
| 328 | private static final boolean DISABLE_MARKET_BUTTON = true; |
| 329 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 330 | private Drawable mWorkspaceBackgroundDrawable; |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 331 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 332 | private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 333 | private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 334 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 335 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 336 | static Date sDateStamp = new Date(); |
| 337 | static DateFormat sDateFormat = |
| 338 | DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 339 | static long sRunStart = System.currentTimeMillis(); |
| 340 | static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 341 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 342 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 343 | // it from the context. |
| 344 | private SharedPreferences mSharedPrefs; |
| 345 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 346 | private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null; |
| 347 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 348 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 349 | // when we scroll to that page on resume. |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 350 | private ImageView mFolderIconImageView; |
| 351 | private Bitmap mFolderIconBitmap; |
| 352 | private Canvas mFolderIconCanvas; |
| 353 | private Rect mRectForFolderAnimation = new Rect(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 354 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 355 | private BubbleTextView mWaitingForResume; |
| 356 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 357 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 358 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 359 | if (mWorkspace != null) { |
| 360 | mWorkspace.buildPageHardwareLayers(); |
| 361 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 362 | } |
| 363 | }; |
| 364 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 365 | private static ArrayList<PendingAddArguments> sPendingAddList |
| 366 | = new ArrayList<PendingAddArguments>(); |
| 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; |
| 377 | } |
| 378 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 379 | private Stats mStats; |
| 380 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 381 | static boolean isPropertyEnabled(String propertyName) { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 382 | return Log.isLoggable(propertyName, Log.VERBOSE); |
Michael Jurka | 9bc8eba | 2012-05-21 20:36:44 -0700 | [diff] [blame] | 383 | } |
| 384 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 385 | @Override |
| 386 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 387 | if (DEBUG_STRICT_MODE) { |
| 388 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 389 | .detectDiskReads() |
| 390 | .detectDiskWrites() |
| 391 | .detectNetwork() // or .detectAll() for all detectable problems |
| 392 | .penaltyLog() |
| 393 | .build()); |
| 394 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 395 | .detectLeakedSqlLiteObjects() |
| 396 | .detectLeakedClosableObjects() |
| 397 | .penaltyLog() |
| 398 | .penaltyDeath() |
| 399 | .build()); |
| 400 | } |
| 401 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 402 | super.onCreate(savedInstanceState); |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 403 | |
Daniel Sandler | e060b0b | 2013-06-27 21:47:55 -0400 | [diff] [blame] | 404 | LauncherAppState.setApplicationContext(getApplicationContext()); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 405 | LauncherAppState app = LauncherAppState.getInstance(); |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 406 | LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 407 | // Determine the dynamic grid properties |
| 408 | Point smallestSize = new Point(); |
| 409 | Point largestSize = new Point(); |
| 410 | Point realSize = new Point(); |
| 411 | Display display = getWindowManager().getDefaultDisplay(); |
| 412 | display.getCurrentSizeRange(smallestSize, largestSize); |
| 413 | display.getRealSize(realSize); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 414 | DisplayMetrics dm = new DisplayMetrics(); |
| 415 | display.getMetrics(dm); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 416 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 417 | // Lazy-initialize the dynamic grid |
| 418 | DeviceProfile grid = app.initDynamicGrid(this, |
| 419 | Math.min(smallestSize.x, smallestSize.y), |
| 420 | Math.min(largestSize.x, largestSize.y), |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 421 | realSize.x, realSize.y, |
| 422 | dm.widthPixels, dm.heightPixels); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 423 | |
| 424 | // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 425 | mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 426 | Context.MODE_PRIVATE); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 427 | mModel = app.setLauncher(this); |
| 428 | mIconCache = app.getIconCache(); |
Winson Chung | e5467dc | 2013-10-14 17:03:04 -0700 | [diff] [blame] | 429 | mIconCache.flushInvalidIcons(grid); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 430 | mDragController = new DragController(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 431 | mLauncherClings = new LauncherClings(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 432 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 433 | |
Daniel Sandler | ff02d49 | 2013-08-05 02:12:05 -0400 | [diff] [blame] | 434 | mStats = new Stats(this); |
| 435 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 436 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 437 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 438 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 439 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 440 | |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 441 | // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, |
| 442 | // this also ensures that any synchronous binding below doesn't re-trigger another |
| 443 | // LauncherModel load. |
| 444 | mPaused = false; |
| 445 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 446 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 447 | android.os.Debug.startMethodTracing( |
| 448 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 449 | } |
| 450 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 451 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 452 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 453 | setContentView(R.layout.launcher); |
Michael Jurka | 7267fa5 | 2013-09-26 15:29:57 -0700 | [diff] [blame] | 454 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 455 | setupViews(); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 456 | grid.layout(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 457 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 458 | registerContentObservers(); |
| 459 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 460 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 461 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 462 | mSavedState = savedInstanceState; |
| 463 | restoreState(mSavedState); |
| 464 | |
| 465 | if (PROFILE_STARTUP) { |
| 466 | android.os.Debug.stopMethodTracing(); |
| 467 | } |
| 468 | |
| 469 | if (!mRestoring) { |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 470 | if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 471 | // If the user leaves launcher, then we should just load items asynchronously when |
| 472 | // they return. |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 473 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 474 | } else { |
| 475 | // We only load the page synchronously if the user rotates (or triggers a |
| 476 | // configuration change) while launcher is in the foreground |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 477 | mModel.startLoader(true, mWorkspace.getRestorePage()); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 478 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | // For handling default keys |
| 482 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 483 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 484 | |
| 485 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 486 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 487 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 488 | updateGlobalIcons(); |
| 489 | |
| 490 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
| 491 | unlockScreenOrientation(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 492 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 493 | if (shouldShowIntroScreen()) { |
| 494 | showIntroScreen(); |
| 495 | } else { |
| 496 | showFirstRunActivity(); |
| 497 | } |
| 498 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 499 | // The two first run cling paths are mutually exclusive, if the launcher is preinstalled |
| 500 | // on the device, then we always show the first run cling experience (or if there is no |
| 501 | // launcher2). Otherwise, we prompt the user upon started for migration |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 502 | if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) { |
| 503 | if (mModel.canMigrateFromOldLauncherDb(this)) { |
| 504 | mLauncherClings.showMigrationCling(); |
| 505 | } else { |
| 506 | mLauncherClings.showFirstRunCling(); |
| 507 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 508 | } else { |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 509 | mLauncherClings.removeFirstRunAndMigrationClings(); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 510 | } |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 513 | @Override |
| 514 | public void onLauncherProviderChange() { } |
| 515 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 516 | protected void onUserLeaveHint() { |
| 517 | super.onUserLeaveHint(); |
| 518 | sPausedFromUserAction = true; |
| 519 | } |
| 520 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 521 | /** To be overriden by subclasses to hint to Launcher that we have custom content */ |
| 522 | protected boolean hasCustomContentToLeft() { |
| 523 | return false; |
| 524 | } |
| 525 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 526 | /** |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 527 | * 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] | 528 | * {@link #addToCustomContentPage}. This will only be invoked if |
| 529 | * {@link #hasCustomContentToLeft()} is {@code true}. |
| 530 | */ |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 531 | protected void populateCustomContentContainer() { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /** |
| 535 | * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to |
| 536 | * ensure the custom content page is added or removed if necessary. |
| 537 | */ |
| 538 | protected void invalidateHasCustomContentToLeft() { |
Dave Hawkey | 3a733a7 | 2013-09-30 11:52:21 -0600 | [diff] [blame] | 539 | if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 540 | // Not bound yet, wait for bindScreens to be called. |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) { |
| 545 | // Create the custom content page and call the subclass to populate it. |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 546 | mWorkspace.createCustomContentContainer(); |
| 547 | populateCustomContentContainer(); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 548 | } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) { |
| 549 | mWorkspace.removeCustomContentPage(); |
| 550 | } |
| 551 | } |
| 552 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 553 | private void updateGlobalIcons() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 554 | boolean searchVisible = false; |
| 555 | boolean voiceVisible = false; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 556 | // 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] | 557 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 558 | if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null || |
| 559 | sAppMarketIcon[coi] == null) { |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 560 | if (!DISABLE_MARKET_BUTTON) { |
| 561 | updateAppMarketIcon(); |
| 562 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 563 | searchVisible = updateGlobalSearchIcon(); |
| 564 | voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 565 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 566 | if (sGlobalSearchIcon[coi] != null) { |
| 567 | updateGlobalSearchIcon(sGlobalSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 568 | searchVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 569 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 570 | if (sVoiceSearchIcon[coi] != null) { |
| 571 | updateVoiceSearchIcon(sVoiceSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 572 | voiceVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 573 | } |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 574 | if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 575 | updateAppMarketIcon(sAppMarketIcon[coi]); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 576 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 577 | if (mSearchDropTargetBar != null) { |
| 578 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 579 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 580 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 581 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 582 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 583 | if (sLocaleConfiguration == null) { |
| 584 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 585 | @Override |
| 586 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 587 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 588 | readConfiguration(Launcher.this, localeConfiguration); |
| 589 | return localeConfiguration; |
| 590 | } |
| 591 | |
| 592 | @Override |
| 593 | protected void onPostExecute(LocaleConfiguration result) { |
| 594 | sLocaleConfiguration = result; |
| 595 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 596 | } |
| 597 | }.execute(); |
| 598 | return; |
| 599 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 600 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 601 | final Configuration configuration = getResources().getConfiguration(); |
| 602 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 603 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 604 | final String locale = configuration.locale.toString(); |
| 605 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 606 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 607 | final int mcc = configuration.mcc; |
| 608 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 609 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 610 | final int mnc = configuration.mnc; |
| 611 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 612 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 613 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 614 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 615 | sLocaleConfiguration.locale = locale; |
| 616 | sLocaleConfiguration.mcc = mcc; |
| 617 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 618 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 619 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 620 | |
| 621 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 622 | new AsyncTask<Void, Void, Void>() { |
| 623 | public Void doInBackground(Void ... args) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 624 | writeConfiguration(Launcher.this, localeConfiguration); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 625 | return null; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 626 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 627 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
| 631 | private static class LocaleConfiguration { |
| 632 | public String locale; |
| 633 | public int mcc = -1; |
| 634 | public int mnc = -1; |
| 635 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 636 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 637 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 638 | DataInputStream in = null; |
| 639 | try { |
| 640 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 641 | configuration.locale = in.readUTF(); |
| 642 | configuration.mcc = in.readInt(); |
| 643 | configuration.mnc = in.readInt(); |
| 644 | } catch (FileNotFoundException e) { |
| 645 | // Ignore |
| 646 | } catch (IOException e) { |
| 647 | // Ignore |
| 648 | } finally { |
| 649 | if (in != null) { |
| 650 | try { |
| 651 | in.close(); |
| 652 | } catch (IOException e) { |
| 653 | // Ignore |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 660 | DataOutputStream out = null; |
| 661 | try { |
| 662 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 663 | out.writeUTF(configuration.locale); |
| 664 | out.writeInt(configuration.mcc); |
| 665 | out.writeInt(configuration.mnc); |
| 666 | out.flush(); |
| 667 | } catch (FileNotFoundException e) { |
| 668 | // Ignore |
| 669 | } catch (IOException e) { |
| 670 | //noinspection ResultOfMethodCallIgnored |
| 671 | context.getFileStreamPath(PREFERENCES).delete(); |
| 672 | } finally { |
| 673 | if (out != null) { |
| 674 | try { |
| 675 | out.close(); |
| 676 | } catch (IOException e) { |
| 677 | // Ignore |
| 678 | } |
| 679 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Anton Hansson | a2f665f | 2013-09-26 12:18:32 +0100 | [diff] [blame] | 683 | public Stats getStats() { |
| 684 | return mStats; |
| 685 | } |
| 686 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 687 | public LayoutInflater getInflater() { |
| 688 | return mInflater; |
| 689 | } |
| 690 | |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 691 | boolean isDraggingEnabled() { |
| 692 | // We prevent dragging when we are loading the workspace as it is possible to pick up a view |
| 693 | // that is subsequently removed from the workspace in startBinding(). |
| 694 | return !mModel.isLoadingWorkspace(); |
| 695 | } |
| 696 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 697 | static int getScreen() { |
| 698 | synchronized (sLock) { |
| 699 | return sScreen; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | static void setScreen(int screen) { |
| 704 | synchronized (sLock) { |
| 705 | sScreen = screen; |
| 706 | } |
| 707 | } |
| 708 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 709 | /** |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 710 | * Copied from View -- the View version of the method isn't called |
| 711 | * anywhere else in our process and only exists for API level 17+, |
| 712 | * so it's ok to keep our own version with no API requirement. |
| 713 | */ |
| 714 | public static int generateViewId() { |
| 715 | for (;;) { |
| 716 | final int result = sNextGeneratedId.get(); |
| 717 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 718 | int newValue = result + 1; |
| 719 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 720 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 721 | return result; |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | public int getViewIdForItem(ItemInfo info) { |
| 727 | // This cast is safe given the > 2B range for int. |
| 728 | int itemId = (int) info.id; |
| 729 | if (mItemIdToViewId.containsKey(itemId)) { |
| 730 | return mItemIdToViewId.get(itemId); |
| 731 | } |
| 732 | int viewId = generateViewId(); |
| 733 | mItemIdToViewId.put(itemId, viewId); |
| 734 | return viewId; |
| 735 | } |
| 736 | |
| 737 | /** |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 738 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 739 | * a configuration step, this allows the proper animations to run after other transitions. |
| 740 | */ |
| 741 | private boolean completeAdd(PendingAddArguments args) { |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 742 | boolean result = false; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 743 | switch (args.requestCode) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 744 | case REQUEST_PICK_SHORTCUT: |
| 745 | processShortcut(args.intent); |
| 746 | break; |
| 747 | case REQUEST_CREATE_SHORTCUT: |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 748 | completeAddShortcut(args.intent, args.container, args.screenId, args.cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 749 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 750 | result = true; |
| 751 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 752 | case REQUEST_CREATE_APPWIDGET: |
| 753 | int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 754 | completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 755 | result = true; |
| 756 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 757 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 758 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 759 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 760 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 761 | resetAddInfo(); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 762 | return result; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 763 | } |
| 764 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 765 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 766 | protected void onActivityResult( |
| 767 | final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 768 | // Reset the startActivity waiting flag |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 769 | setWaitingForResult(false); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 770 | int pendingAddWidgetId = mPendingAddWidgetId; |
| 771 | mPendingAddWidgetId = -1; |
Winson Chung | e341d30 | 2013-08-16 14:31:00 -0700 | [diff] [blame] | 772 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 773 | Runnable exitSpringLoaded = new Runnable() { |
| 774 | @Override |
| 775 | public void run() { |
| 776 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 777 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
| 778 | } |
| 779 | }; |
| 780 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 781 | if (requestCode == REQUEST_BIND_APPWIDGET) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 782 | final int appWidgetId = data != null ? |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 783 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 784 | if (resultCode == RESULT_CANCELED) { |
| 785 | completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 786 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 787 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 788 | } else if (resultCode == RESULT_OK) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 789 | addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, |
| 790 | mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 791 | } |
| 792 | return; |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 793 | } else if (requestCode == REQUEST_PICK_WALLPAPER) { |
| 794 | if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) { |
| 795 | mWorkspace.exitOverviewMode(false); |
| 796 | } |
| 797 | return; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 798 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 799 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 800 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 801 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 802 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 803 | // We have special handling for widgets |
| 804 | if (isWidgetDrop) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 805 | final int appWidgetId; |
| 806 | int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) |
| 807 | : -1; |
| 808 | if (widgetId < 0) { |
| 809 | appWidgetId = pendingAddWidgetId; |
| 810 | } else { |
| 811 | appWidgetId = widgetId; |
| 812 | } |
| 813 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 814 | final int result; |
| 815 | final Runnable onComplete; |
Adam Cohen | f0129b1 | 2013-11-04 17:57:36 -0800 | [diff] [blame] | 816 | if (appWidgetId < 0 || resultCode == RESULT_CANCELED) { |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 817 | Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" + |
| 818 | "widget configuration activity."); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 819 | result = RESULT_CANCELED; |
| 820 | completeTwoStageWidgetDrop(result, appWidgetId); |
| 821 | onComplete = new Runnable() { |
| 822 | @Override |
| 823 | public void run() { |
| 824 | exitSpringLoadedDragModeDelayed(false, 0, null); |
| 825 | } |
| 826 | }; |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 827 | } else { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 828 | result = resultCode; |
Adam Cohen | 917e388 | 2013-10-31 15:03:35 -0700 | [diff] [blame] | 829 | final CellLayout dropLayout = |
| 830 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
| 831 | dropLayout.setDropPending(true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 832 | onComplete = new Runnable() { |
| 833 | @Override |
| 834 | public void run() { |
| 835 | completeTwoStageWidgetDrop(result, appWidgetId); |
Adam Cohen | 917e388 | 2013-10-31 15:03:35 -0700 | [diff] [blame] | 836 | dropLayout.setDropPending(false); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 837 | } |
| 838 | }; |
Winson Chung | 5aaab77 | 2012-04-27 15:24:02 -0700 | [diff] [blame] | 839 | } |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 840 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 841 | false); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 842 | return; |
| 843 | } |
| 844 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 845 | // The pattern used here is that a user PICKs a specific application, |
| 846 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 847 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 848 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 849 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Winson Chung | c7da555 | 2011-08-10 15:28:45 -0700 | [diff] [blame] | 850 | if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 851 | final PendingAddArguments args = new PendingAddArguments(); |
| 852 | args.requestCode = requestCode; |
| 853 | args.intent = data; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 854 | args.container = mPendingAddInfo.container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 855 | args.screenId = mPendingAddInfo.screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 856 | args.cellX = mPendingAddInfo.cellX; |
| 857 | args.cellY = mPendingAddInfo.cellY; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 858 | if (isWorkspaceLocked()) { |
| 859 | sPendingAddList.add(args); |
| 860 | } else { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 861 | completeAdd(args); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 862 | } |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 863 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 864 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
Adam Cohen | 0007472 | 2013-10-11 17:46:09 -0700 | [diff] [blame] | 865 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 866 | mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 867 | ON_ACTIVITY_RESULT_ANIMATION_DELAY, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 868 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 869 | mDragLayer.clearAnimatedView(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 873 | CellLayout cellLayout = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 874 | (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 875 | Runnable onCompleteRunnable = null; |
| 876 | int animationType = 0; |
| 877 | |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 878 | AppWidgetHostView boundWidget = null; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 879 | if (resultCode == RESULT_OK) { |
| 880 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 881 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 882 | mPendingAddWidgetInfo); |
| 883 | boundWidget = layout; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 884 | onCompleteRunnable = new Runnable() { |
| 885 | @Override |
| 886 | public void run() { |
| 887 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 888 | mPendingAddInfo.screenId, layout, null); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 889 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), |
| 890 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 891 | } |
| 892 | }; |
| 893 | } else if (resultCode == RESULT_CANCELED) { |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 894 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 895 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 896 | } |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 897 | if (mDragLayer.getAnimatedView() != null) { |
| 898 | mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, |
| 899 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
| 900 | animationType, boundWidget, true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 901 | } else if (onCompleteRunnable != null) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 902 | // The animated view may be null in the case of a rotation during widget configuration |
| 903 | onCompleteRunnable.run(); |
| 904 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | @Override |
Michael Jurka | cd496d7 | 2013-04-11 11:32:45 -0700 | [diff] [blame] | 908 | protected void onStop() { |
| 909 | super.onStop(); |
| 910 | FirstFrameAnimatorHelper.setIsVisible(false); |
| 911 | } |
| 912 | |
| 913 | @Override |
| 914 | protected void onStart() { |
| 915 | super.onStart(); |
| 916 | FirstFrameAnimatorHelper.setIsVisible(true); |
| 917 | } |
| 918 | |
| 919 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 920 | protected void onResume() { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 921 | long startTime = 0; |
| 922 | if (DEBUG_RESUME_TIME) { |
| 923 | startTime = System.currentTimeMillis(); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 924 | Log.v(TAG, "Launcher.onResume()"); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 925 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 926 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 927 | |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 928 | // Restore the previous launcher state |
| 929 | if (mOnResumeState == State.WORKSPACE) { |
| 930 | showWorkspace(false); |
| 931 | } else if (mOnResumeState == State.APPS_CUSTOMIZE) { |
Winson Chung | 07e045c6 | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 932 | showAllApps(false, mAppsCustomizeContent.getContentType(), false); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 933 | } |
| 934 | mOnResumeState = State.NONE; |
| 935 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 936 | // Background was set to gradient in onPause(), restore to black if in all apps. |
| 937 | setWorkspaceBackground(mState == State.WORKSPACE); |
| 938 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 939 | mPaused = false; |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 940 | sPausedFromUserAction = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 941 | if (mRestoring || mOnResumeNeedsLoad) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 942 | setWorkspaceLoading(true); |
Derek Prothro | 7aff399 | 2013-12-10 14:00:37 -0500 | [diff] [blame] | 943 | mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 944 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 945 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 946 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 947 | if (mBindOnResumeCallbacks.size() > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 948 | // We might have postponed some bind calls until onResume (see waitUntilResume) -- |
| 949 | // execute them here |
| 950 | long startTimeCallbacks = 0; |
| 951 | if (DEBUG_RESUME_TIME) { |
| 952 | startTimeCallbacks = System.currentTimeMillis(); |
| 953 | } |
| 954 | |
| 955 | if (mAppsCustomizeContent != null) { |
| 956 | mAppsCustomizeContent.setBulkBind(true); |
| 957 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 958 | for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) { |
| 959 | mBindOnResumeCallbacks.get(i).run(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 960 | } |
| 961 | if (mAppsCustomizeContent != null) { |
| 962 | mAppsCustomizeContent.setBulkBind(false); |
| 963 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 964 | mBindOnResumeCallbacks.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 965 | if (DEBUG_RESUME_TIME) { |
| 966 | Log.d(TAG, "Time spent processing callbacks in onResume: " + |
| 967 | (System.currentTimeMillis() - startTimeCallbacks)); |
| 968 | } |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 969 | } |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 970 | if (mOnResumeCallbacks.size() > 0) { |
| 971 | for (int i = 0; i < mOnResumeCallbacks.size(); i++) { |
| 972 | mOnResumeCallbacks.get(i).run(); |
| 973 | } |
| 974 | mOnResumeCallbacks.clear(); |
| 975 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 976 | |
| 977 | // Reset the pressed state of icons that were locked in the press state while activities |
| 978 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 979 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 980 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 981 | mWaitingForResume.setStayPressed(false); |
| 982 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 983 | if (mAppsCustomizeContent != null) { |
| 984 | // Resets the previous all apps icon press state |
| 985 | mAppsCustomizeContent.resetDrawableState(); |
| 986 | } |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 987 | |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 988 | // It is possible that widgets can receive updates while launcher is not in the foreground. |
| 989 | // Consequently, the widgets will be inflated in the orientation of the foreground activity |
| 990 | // (framework issue). On resuming, we ensure that any widgets are inflated for the current |
| 991 | // orientation. |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 992 | getWorkspace().reinflateWidgetsIfNecessary(); |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 993 | |
Winson Chung | 780fe59 | 2013-09-26 14:48:44 -0700 | [diff] [blame] | 994 | // Process any items that were added while Launcher was away. |
| 995 | InstallShortcutReceiver.disableAndFlushInstallQueue(this); |
| 996 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 997 | // Update the voice search button proxy |
| 998 | updateVoiceButtonProxyVisible(false); |
| 999 | |
Adam Cohen | f9426d5 | 2012-06-04 17:26:21 -0700 | [diff] [blame] | 1000 | // Again, as with the above scenario, it's possible that one or more of the global icons |
| 1001 | // were updated in the wrong orientation. |
| 1002 | updateGlobalIcons(); |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1003 | if (DEBUG_RESUME_TIME) { |
| 1004 | Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); |
| 1005 | } |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1006 | |
| 1007 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1008 | // If we are resuming and the custom content is the current page, we call onShow(). |
| 1009 | // It is also poassible that onShow will instead be called slightly after first layout |
| 1010 | // if PagedView#setRestorePage was set to the custom content page in onCreate(). |
| 1011 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1012 | mWorkspace.getCustomContentCallbacks().onShow(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1013 | } |
| 1014 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 1015 | mWorkspace.updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1016 | mWorkspace.onResume(); |
Adam Cohen | 06dff35 | 2012-06-01 17:17:08 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1019 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1020 | protected void onPause() { |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 1021 | // Ensure that items added to Launcher are queued until Launcher returns |
| 1022 | InstallShortcutReceiver.enableInstallQueue(); |
| 1023 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1024 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 1025 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 1026 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 1027 | mDragController.resetLastGestureUpTime(); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1028 | |
| 1029 | // We call onHide() aggressively. The custom content callbacks should be able to |
| 1030 | // debounce excess onHide calls. |
| 1031 | if (mWorkspace.getCustomContentCallbacks() != null) { |
| 1032 | mWorkspace.getCustomContentCallbacks().onHide(); |
| 1033 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1034 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1035 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1036 | QSBScroller mQsbScroller = new QSBScroller() { |
| 1037 | int scrollY = 0; |
| 1038 | |
| 1039 | @Override |
| 1040 | public void setScrollY(int scroll) { |
| 1041 | scrollY = scroll; |
| 1042 | |
| 1043 | if (mWorkspace.isOnOrMovingToCustomContent()) { |
| 1044 | mSearchDropTargetBar.setTranslationY(- scrollY); |
Mark Brophy | d7dc681 | 2013-09-20 17:27:32 +0100 | [diff] [blame] | 1045 | getQsbBar().setTranslationY(-scrollY); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | }; |
| 1049 | |
| 1050 | public void resetQSBScroll() { |
| 1051 | mSearchDropTargetBar.animate().translationY(0).start(); |
Mark Brophy | d7dc681 | 2013-09-20 17:27:32 +0100 | [diff] [blame] | 1052 | getQsbBar().animate().translationY(0).start(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | public interface CustomContentCallbacks { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1056 | // Custom content is completely shown. {@code fromResume} indicates whether this was caused |
| 1057 | // by a onResume or by scrolling otherwise. |
| 1058 | public void onShow(boolean fromResume); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1059 | |
| 1060 | // Custom content is completely hidden |
| 1061 | public void onHide(); |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1062 | |
| 1063 | // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing). |
| 1064 | public void onScrollProgressChanged(float progress); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1067 | protected boolean hasSettings() { |
| 1068 | return false; |
| 1069 | } |
| 1070 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1071 | public interface QSBScroller { |
| 1072 | public void setScrollY(int scrollY); |
| 1073 | } |
| 1074 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 1075 | public QSBScroller addToCustomContentPage(View customContent, |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1076 | CustomContentCallbacks callbacks, String description) { |
| 1077 | mWorkspace.addToCustomContentPage(customContent, callbacks, description); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1078 | return mQsbScroller; |
Adam Cohen | 66a01fd | 2013-06-11 12:48:00 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1081 | // The custom content needs to offset its content to account for the QSB |
| 1082 | public int getTopOffsetForCustomContent() { |
| 1083 | return mWorkspace.getPaddingTop(); |
| 1084 | } |
| 1085 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1086 | @Override |
| 1087 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1088 | // Flag the loader to stop early before switching |
| 1089 | mModel.stopLoader(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1090 | if (mAppsCustomizeContent != null) { |
| 1091 | mAppsCustomizeContent.surrender(); |
| 1092 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 1093 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1094 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1095 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1096 | // 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] | 1097 | @Override |
| 1098 | public void onWindowFocusChanged(boolean hasFocus) { |
| 1099 | super.onWindowFocusChanged(hasFocus); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1100 | mHasFocus = hasFocus; |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1101 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1102 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1103 | private boolean acceptFilter() { |
| 1104 | final InputMethodManager inputManager = (InputMethodManager) |
| 1105 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1106 | return !inputManager.isFullscreenMode(); |
| 1107 | } |
| 1108 | |
| 1109 | @Override |
| 1110 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1111 | final int uniChar = event.getUnicodeChar(); |
| 1112 | final boolean handled = super.onKeyDown(keyCode, event); |
| 1113 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 1114 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1115 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 1116 | keyCode, event); |
| 1117 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1118 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1119 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1120 | // showSearchDialog() |
| 1121 | // If there are multiple keystrokes before the search dialog takes focus, |
| 1122 | // onSearchRequested() will be called for every keystroke, |
| 1123 | // but it is idempotent, so it's fine. |
| 1124 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 1128 | // Eat the long press event so the keyboard doesn't come up. |
| 1129 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 1130 | return true; |
| 1131 | } |
| 1132 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1133 | return handled; |
| 1134 | } |
| 1135 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1136 | private String getTypedText() { |
| 1137 | return mDefaultKeySsb.toString(); |
| 1138 | } |
| 1139 | |
| 1140 | private void clearTypedText() { |
| 1141 | mDefaultKeySsb.clear(); |
| 1142 | mDefaultKeySsb.clearSpans(); |
| 1143 | Selection.setSelection(mDefaultKeySsb, 0); |
| 1144 | } |
| 1145 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1146 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1147 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 1148 | * State |
| 1149 | */ |
| 1150 | private static State intToState(int stateOrdinal) { |
| 1151 | State state = State.WORKSPACE; |
| 1152 | final State[] stateValues = State.values(); |
| 1153 | for (int i = 0; i < stateValues.length; i++) { |
| 1154 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 1155 | state = stateValues[i]; |
| 1156 | break; |
| 1157 | } |
| 1158 | } |
| 1159 | return state; |
| 1160 | } |
| 1161 | |
| 1162 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1163 | * Restores the previous state, if it exists. |
| 1164 | * |
| 1165 | * @param savedState The previous state. |
| 1166 | */ |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1167 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1168 | private void restoreState(Bundle savedState) { |
| 1169 | if (savedState == null) { |
| 1170 | return; |
| 1171 | } |
| 1172 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1173 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1174 | if (state == State.APPS_CUSTOMIZE) { |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1175 | mOnResumeState = State.APPS_CUSTOMIZE; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1176 | } |
| 1177 | |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1178 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1179 | PagedView.INVALID_RESTORE_PAGE); |
| 1180 | if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { |
Winson Chung | 8c87cd8 | 2013-07-23 16:20:10 -0700 | [diff] [blame] | 1181 | mWorkspace.setRestorePage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1182 | } |
| 1183 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1184 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1185 | final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1186 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1187 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 1188 | mPendingAddInfo.container = pendingAddContainer; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1189 | mPendingAddInfo.screenId = pendingAddScreen; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1190 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 1191 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1192 | mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 1193 | mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 1194 | mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1195 | mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID); |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1196 | setWaitingForResult(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1197 | mRestoring = true; |
| 1198 | } |
| 1199 | |
| 1200 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 1201 | if (renameFolder) { |
| 1202 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1203 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1204 | mRestoring = true; |
| 1205 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1206 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1207 | // Restore the AppsCustomize tab |
| 1208 | if (mAppsCustomizeTabHost != null) { |
| 1209 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 1210 | if (curTab != null) { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 1211 | mAppsCustomizeTabHost.setContentTypeImmediate( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1212 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1213 | mAppsCustomizeContent.loadAssociatedPages( |
| 1214 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1217 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 1218 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1219 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1220 | mItemIdToViewId = (HashMap<Integer, Integer>) |
| 1221 | savedState.getSerializable(RUNTIME_STATE_VIEW_IDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | /** |
| 1225 | * Finds all the views we need and configure them properly. |
| 1226 | */ |
| 1227 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1228 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1229 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1230 | mLauncherView = findViewById(R.id.launcher); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1231 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 1232 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 1233 | mWorkspace.setPageSwitchListener(this); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1234 | mPageIndicators = mDragLayer.findViewById(R.id.page_indicator); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1235 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 1236 | mLauncherView.setSystemUiVisibility( |
| 1237 | 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] | 1238 | mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1239 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1240 | // Setup the drag layer |
| 1241 | mDragLayer.setup(this, dragController); |
| 1242 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1243 | // Setup the hotseat |
| 1244 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 1245 | if (mHotseat != null) { |
| 1246 | mHotseat.setup(this); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 1247 | mHotseat.setOnLongClickListener(this); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1250 | mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1251 | View widgetButton = findViewById(R.id.widget_button); |
| 1252 | widgetButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1253 | @Override |
| 1254 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1255 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1256 | onClickAddWidgetButton(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1257 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1258 | } |
| 1259 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1260 | widgetButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1261 | |
| 1262 | View wallpaperButton = findViewById(R.id.wallpaper_button); |
| 1263 | wallpaperButton.setOnClickListener(new OnClickListener() { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1264 | @Override |
| 1265 | public void onClick(View arg0) { |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1266 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1267 | onClickWallpaperPicker(arg0); |
Winson Chung | 8e15fdf | 2013-11-11 15:47:45 -0800 | [diff] [blame] | 1268 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1269 | } |
| 1270 | }); |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 1271 | wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1272 | |
| 1273 | View settingsButton = findViewById(R.id.settings_button); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1274 | if (hasSettings()) { |
| 1275 | settingsButton.setOnClickListener(new OnClickListener() { |
| 1276 | @Override |
| 1277 | public void onClick(View arg0) { |
| 1278 | if (!mWorkspace.isSwitchingState()) { |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 1279 | onClickSettingsButton(arg0); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1280 | } |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 1281 | } |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1282 | }); |
| 1283 | settingsButton.setOnTouchListener(getHapticFeedbackTouchListener()); |
| 1284 | } else { |
| 1285 | settingsButton.setVisibility(View.GONE); |
| 1286 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams(); |
| 1287 | lp.gravity = Gravity.END | Gravity.TOP; |
| 1288 | widgetButton.requestLayout(); |
| 1289 | } |
| 1290 | |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 1291 | mOverviewPanel.setAlpha(0f); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1292 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1293 | // Setup the workspace |
| 1294 | mWorkspace.setHapticFeedbackEnabled(false); |
| 1295 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1296 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1297 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1298 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1299 | // Get the search/delete bar |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 1300 | mSearchDropTargetBar = (SearchDropTargetBar) |
| 1301 | mDragLayer.findViewById(R.id.search_drop_target_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1302 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1303 | // Setup AppsCustomize |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1304 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1305 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 1306 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 1307 | mAppsCustomizeContent.setup(this, dragController); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 1308 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1309 | // 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] | 1310 | dragController.setDragScoller(mWorkspace); |
| 1311 | dragController.setScrollView(mDragLayer); |
| 1312 | dragController.setMoveTarget(mWorkspace); |
| 1313 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 1314 | if (mSearchDropTargetBar != null) { |
| 1315 | mSearchDropTargetBar.setup(this, dragController); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1316 | } |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1317 | |
Daniel Sandler | a127b7a | 2013-06-17 14:25:46 -0400 | [diff] [blame] | 1318 | if (getResources().getBoolean(R.bool.debug_memory_enabled)) { |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1319 | Log.v(TAG, "adding WeightWatcher"); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1320 | mWeightWatcher = new WeightWatcher(this); |
| 1321 | mWeightWatcher.setAlpha(0.5f); |
| 1322 | ((FrameLayout) mLauncherView).addView(mWeightWatcher, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1323 | new FrameLayout.LayoutParams( |
| 1324 | FrameLayout.LayoutParams.MATCH_PARENT, |
Daniel Sandler | b9eb286 | 2013-06-14 20:17:30 -0400 | [diff] [blame] | 1325 | FrameLayout.LayoutParams.WRAP_CONTENT, |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1326 | Gravity.BOTTOM) |
| 1327 | ); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 1328 | |
| 1329 | boolean show = shouldShowWeightWatcher(); |
| 1330 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
Daniel Sandler | 924b993 | 2013-06-12 00:38:25 -0400 | [diff] [blame] | 1331 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | /** |
Anjali Koppal | 5ad4484 | 2014-03-10 20:34:39 -0700 | [diff] [blame] | 1335 | * Sets the all apps button. This method is called from {@link Hotseat}. |
| 1336 | */ |
| 1337 | public void setAllAppsButton(View allAppsButton) { |
| 1338 | mAllAppsButton = allAppsButton; |
| 1339 | } |
| 1340 | |
| 1341 | public View getAllAppsButton() { |
| 1342 | return mAllAppsButton; |
| 1343 | } |
| 1344 | |
| 1345 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1346 | * Creates a view representing a shortcut. |
| 1347 | * |
| 1348 | * @param info The data structure describing the shortcut. |
| 1349 | * |
| 1350 | * @return A View inflated from R.layout.application. |
| 1351 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1352 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1353 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1354 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1359 | * |
| 1360 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1361 | * @param parent The group the shortcut belongs to. |
| 1362 | * @param info The data structure describing the shortcut. |
| 1363 | * |
| 1364 | * @return A View inflated from layoutResId. |
| 1365 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1366 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1367 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
| 1368 | favorite.applyFromShortcutInfo(info, mIconCache); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1369 | favorite.setOnClickListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1370 | return favorite; |
| 1371 | } |
| 1372 | |
| 1373 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1374 | * Add a shortcut to the workspace. |
| 1375 | * |
| 1376 | * @param data The intent describing the shortcut. |
| 1377 | * @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] | 1378 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1379 | private void completeAddShortcut(Intent data, long container, long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1380 | int cellY) { |
| 1381 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1382 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1383 | CellLayout layout = getCellLayout(container, screenId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1384 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1385 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1386 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1387 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 1388 | if (info == null) { |
| 1389 | return; |
| 1390 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1391 | final View view = createShortcut(info); |
| 1392 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1393 | // First we check if we already know the exact location where we want to add this item. |
| 1394 | if (cellX >= 0 && cellY >= 0) { |
| 1395 | cellXY[0] = cellX; |
| 1396 | cellXY[1] = cellY; |
| 1397 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1398 | |
| 1399 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1400 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1401 | true, null,null)) { |
| 1402 | return; |
| 1403 | } |
| 1404 | DragObject dragObject = new DragObject(); |
| 1405 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1406 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 1407 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 1408 | return; |
| 1409 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1410 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1411 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1412 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1413 | foundCellSpan = (result != null); |
| 1414 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1415 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1419 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1420 | return; |
| 1421 | } |
| 1422 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1423 | 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] | 1424 | |
| 1425 | if (!mRestoring) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1426 | mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1427 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1428 | } |
| 1429 | } |
| 1430 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1431 | static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, |
| 1432 | int minHeight) { |
| 1433 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1434 | // We want to account for the extra amount of padding that we are adding to the widget |
| 1435 | // to ensure that it gets the full amount of space that it has requested |
| 1436 | int requiredWidth = minWidth + padding.left + padding.right; |
| 1437 | int requiredHeight = minHeight + padding.top + padding.bottom; |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 1438 | return CellLayout.rectToCell(requiredWidth, requiredHeight, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1441 | static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1442 | return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1445 | static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { |
| 1446 | return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1449 | static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1450 | return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1453 | static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { |
| 1454 | return getSpanForWidget(context, info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1455 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1456 | } |
| 1457 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1458 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1459 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1460 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1461 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1462 | * @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] | 1463 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1464 | private void completeAddAppWidget(final int appWidgetId, long container, long screenId, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1465 | AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1466 | if (appWidgetInfo == null) { |
| 1467 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1468 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1469 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1470 | // Calculate the grid spans needed to fit this widget |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1471 | CellLayout layout = getCellLayout(container, screenId); |
Adam Cohen | 0935386 | 2011-07-14 16:10:03 -0700 | [diff] [blame] | 1472 | |
Adam Cohen | 2f093b6 | 2012-04-30 18:59:53 -0700 | [diff] [blame] | 1473 | int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo); |
| 1474 | int[] spanXY = getSpanForWidget(this, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1475 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1476 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1477 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1478 | // if we are placing widgets on a "spring-loaded" screen |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1479 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1480 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1481 | int[] finalSpan = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1482 | boolean foundCellSpan = false; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1483 | if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { |
| 1484 | cellXY[0] = mPendingAddInfo.cellX; |
| 1485 | cellXY[1] = mPendingAddInfo.cellY; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1486 | spanXY[0] = mPendingAddInfo.spanX; |
| 1487 | spanXY[1] = mPendingAddInfo.spanY; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1488 | foundCellSpan = true; |
| 1489 | } else if (touchXY != null) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1490 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1491 | int[] result = layout.findNearestVacantArea( |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1492 | touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], |
| 1493 | spanXY[1], cellXY, finalSpan); |
| 1494 | spanXY[0] = finalSpan[0]; |
| 1495 | spanXY[1] = finalSpan[1]; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1496 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1497 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1498 | foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1501 | if (!foundCellSpan) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1502 | if (appWidgetId != -1) { |
| 1503 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 1504 | // to the caller... |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1505 | new AsyncTask<Void, Void, Void>() { |
| 1506 | public Void doInBackground(Void ... args) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1507 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1508 | return null; |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1509 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 1510 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1511 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1512 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1513 | return; |
| 1514 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1515 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1516 | // Build Launcher-specific widget info and save to database |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 1517 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, |
| 1518 | appWidgetInfo.provider); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1519 | launcherInfo.spanX = spanXY[0]; |
| 1520 | launcherInfo.spanY = spanXY[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1521 | launcherInfo.minSpanX = mPendingAddInfo.minSpanX; |
| 1522 | launcherInfo.minSpanY = mPendingAddInfo.minSpanY; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1523 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1524 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1525 | container, screenId, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1526 | |
| 1527 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1528 | if (hostView == null) { |
| 1529 | // Perform actual inflation because we're live |
| 1530 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1531 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1532 | } else { |
| 1533 | // The AppWidgetHostView has already been inflated and instantiated |
| 1534 | launcherInfo.hostView = hostView; |
| 1535 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1536 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1537 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1538 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 1539 | launcherInfo.notifyWidgetSizeChanged(this); |
| 1540 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1541 | mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1542 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1543 | |
| 1544 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1545 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1546 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1547 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1548 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1549 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1550 | @Override |
| 1551 | public void onReceive(Context context, Intent intent) { |
| 1552 | final String action = intent.getAction(); |
| 1553 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1554 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1555 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1556 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1557 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1558 | // 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] | 1559 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1560 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1561 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1562 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1563 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1564 | mUserPresent = true; |
| 1565 | updateRunning(); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1566 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { |
| 1567 | mModel.resetLoadedState(false, true); |
| 1568 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1569 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); |
| 1570 | } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { |
| 1571 | mModel.resetLoadedState(false, true); |
| 1572 | mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 1573 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 1574 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1575 | } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action) |
| 1576 | || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) { |
| 1577 | getModel().forceReload(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1578 | } |
| 1579 | } |
| 1580 | }; |
| 1581 | |
| 1582 | @Override |
| 1583 | public void onAttachedToWindow() { |
| 1584 | super.onAttachedToWindow(); |
| 1585 | |
| 1586 | // Listen for broadcasts related to user-presence |
| 1587 | final IntentFilter filter = new IntentFilter(); |
| 1588 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1589 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 1590 | // For handling managed profiles |
| 1591 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); |
| 1592 | filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 1593 | if (ENABLE_DEBUG_INTENTS) { |
| 1594 | filter.addAction(DebugIntents.DELETE_DATABASE); |
| 1595 | filter.addAction(DebugIntents.MIGRATE_DATABASE); |
| 1596 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1597 | registerReceiver(mReceiver, filter); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1598 | FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame^] | 1599 | setupTransparentSystemBarsForLmp(); |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1600 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1601 | mVisible = true; |
| 1602 | } |
| 1603 | |
Sandeep Siddhartha | 2efc7d9 | 2014-05-16 17:21:15 -0700 | [diff] [blame^] | 1604 | /** |
| 1605 | * Sets up transparent navigation and status bars in LMP. |
| 1606 | * This method is a no-op for other platform versions. |
| 1607 | */ |
| 1608 | private void setupTransparentSystemBarsForLmp() { |
| 1609 | // TODO(sansid): use the APIs directly when compiling against L sdk. |
| 1610 | // Currently we use reflection to access the flags and the API to set the transparency |
| 1611 | // on the System bars. |
| 1612 | if (Utilities.isLmp()) { |
| 1613 | try { |
| 1614 | getWindow().getAttributes().systemUiVisibility |= |
| 1615 | (View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1616 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1617 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 1618 | Field translucentStatusField = |
| 1619 | WindowManager.LayoutParams.class.getField("FLAG_TRANSLUCENT_STATUS"); |
| 1620 | Field translucentNavigationField = |
| 1621 | WindowManager.LayoutParams.class.getField("FLAG_TRANSLUCENT_NAVIGATION"); |
| 1622 | getWindow().clearFlags(translucentStatusField.getInt(null) |
| 1623 | | translucentNavigationField.getInt(null)); |
| 1624 | Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( |
| 1625 | "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); |
| 1626 | getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); |
| 1627 | |
| 1628 | Method setStatusBarColorMethod = |
| 1629 | Window.class.getDeclaredMethod("setStatusBarColor", int.class); |
| 1630 | Method setNavigationBarColorMethod = |
| 1631 | Window.class.getDeclaredMethod("setNavigationBarColor", int.class); |
| 1632 | setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1633 | setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); |
| 1634 | } catch (NoSuchFieldException e) { |
| 1635 | Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); |
| 1636 | } catch (NoSuchMethodException ex) { |
| 1637 | Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); |
| 1638 | } catch (IllegalAccessException e) { |
| 1639 | Log.w(TAG, "IllegalAccessException while setting up transparent bars"); |
| 1640 | } catch (IllegalArgumentException e) { |
| 1641 | Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); |
| 1642 | } catch (InvocationTargetException e) { |
| 1643 | Log.w(TAG, "InvocationTargetException while setting up transparent bars"); |
| 1644 | } finally {} |
| 1645 | } |
| 1646 | } |
| 1647 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1648 | @Override |
| 1649 | public void onDetachedFromWindow() { |
| 1650 | super.onDetachedFromWindow(); |
| 1651 | mVisible = false; |
| 1652 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1653 | if (mAttached) { |
| 1654 | unregisterReceiver(mReceiver); |
| 1655 | mAttached = false; |
| 1656 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1657 | updateRunning(); |
| 1658 | } |
| 1659 | |
| 1660 | public void onWindowVisibilityChanged(int visibility) { |
| 1661 | mVisible = visibility == View.VISIBLE; |
| 1662 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1663 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1664 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1665 | // is a more appropriate event to handle |
| 1666 | if (mVisible) { |
| 1667 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1668 | if (!mWorkspaceLoading) { |
| 1669 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1670 | // We want to let Launcher draw itself at least once before we force it to build |
| 1671 | // 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] | 1672 | // apps is nice and speedy. |
| 1673 | observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1674 | private boolean mStarted = false; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1675 | public void onDraw() { |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1676 | if (mStarted) return; |
| 1677 | mStarted = true; |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1678 | // We delay the layer building a bit in order to give |
| 1679 | // other message processing a time to run. In particular |
| 1680 | // this avoids a delay in hiding the IME if it was |
| 1681 | // currently shown, because doing that may involve |
| 1682 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1683 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1684 | final ViewTreeObserver.OnDrawListener listener = this; |
| 1685 | mWorkspace.post(new Runnable() { |
| 1686 | public void run() { |
Michael Jurka | b68e03a | 2013-04-11 11:36:41 -0700 | [diff] [blame] | 1687 | if (mWorkspace != null && |
| 1688 | mWorkspace.getViewTreeObserver() != null) { |
| 1689 | mWorkspace.getViewTreeObserver(). |
| 1690 | removeOnDrawListener(listener); |
| 1691 | } |
Michael Jurka | df96add | 2013-04-03 16:25:02 -0700 | [diff] [blame] | 1692 | } |
| 1693 | }); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1694 | return; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1695 | } |
| 1696 | }); |
| 1697 | } |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1698 | // When Launcher comes back to foreground, a different Activity might be responsible for |
| 1699 | // the app market intent, so refresh the icon |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 1700 | if (!DISABLE_MARKET_BUTTON) { |
| 1701 | updateAppMarketIcon(); |
| 1702 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1703 | clearTypedText(); |
| 1704 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | private void sendAdvanceMessage(long delay) { |
| 1708 | mHandler.removeMessages(ADVANCE_MSG); |
| 1709 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1710 | mHandler.sendMessageDelayed(msg, delay); |
| 1711 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1712 | } |
| 1713 | |
| 1714 | private void updateRunning() { |
| 1715 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1716 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1717 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1718 | if (autoAdvanceRunning) { |
| 1719 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1720 | sendAdvanceMessage(delay); |
| 1721 | } else { |
| 1722 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1723 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1724 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1725 | } |
| 1726 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1727 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | private final Handler mHandler = new Handler() { |
| 1733 | @Override |
| 1734 | public void handleMessage(Message msg) { |
| 1735 | if (msg.what == ADVANCE_MSG) { |
| 1736 | int i = 0; |
| 1737 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1738 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1739 | final int delay = mAdvanceStagger * i; |
| 1740 | if (v instanceof Advanceable) { |
| 1741 | postDelayed(new Runnable() { |
| 1742 | public void run() { |
| 1743 | ((Advanceable) v).advance(); |
| 1744 | } |
| 1745 | }, delay); |
| 1746 | } |
| 1747 | i++; |
| 1748 | } |
| 1749 | sendAdvanceMessage(mAdvanceInterval); |
| 1750 | } |
| 1751 | } |
| 1752 | }; |
| 1753 | |
| 1754 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1755 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1756 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1757 | if (v instanceof Advanceable) { |
| 1758 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1759 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1760 | updateRunning(); |
| 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | void removeWidgetToAutoAdvance(View hostView) { |
| 1765 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1766 | mWidgetsToAdvance.remove(hostView); |
| 1767 | updateRunning(); |
| 1768 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1771 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1772 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1773 | launcherInfo.hostView = null; |
| 1774 | } |
| 1775 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1776 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1777 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1778 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1781 | public DragLayer getDragLayer() { |
| 1782 | return mDragLayer; |
| 1783 | } |
| 1784 | |
| 1785 | public Workspace getWorkspace() { |
| 1786 | return mWorkspace; |
| 1787 | } |
| 1788 | |
| 1789 | public Hotseat getHotseat() { |
| 1790 | return mHotseat; |
| 1791 | } |
| 1792 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 1793 | public ViewGroup getOverviewPanel() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1794 | return mOverviewPanel; |
| 1795 | } |
| 1796 | |
| 1797 | public SearchDropTargetBar getSearchBar() { |
| 1798 | return mSearchDropTargetBar; |
| 1799 | } |
| 1800 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1801 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1802 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1803 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1804 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1805 | public LauncherModel getModel() { |
| 1806 | return mModel; |
| 1807 | } |
| 1808 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1809 | public LauncherClings getLauncherClings() { |
| 1810 | return mLauncherClings; |
| 1811 | } |
| 1812 | |
| 1813 | protected SharedPreferences getSharedPrefs() { |
| 1814 | return mSharedPrefs; |
| 1815 | } |
| 1816 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 1817 | public void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1818 | getWindow().closeAllPanels(); |
| 1819 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1820 | // Whatever we were doing is hereby canceled. |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1821 | setWaitingForResult(false); |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1822 | } |
| 1823 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1824 | @Override |
| 1825 | protected void onNewIntent(Intent intent) { |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1826 | long startTime = 0; |
| 1827 | if (DEBUG_RESUME_TIME) { |
| 1828 | startTime = System.currentTimeMillis(); |
| 1829 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1830 | super.onNewIntent(intent); |
| 1831 | |
| 1832 | // Close the menu |
| 1833 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1834 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1835 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1836 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1837 | final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & |
| 1838 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1839 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1840 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1841 | if (mWorkspace == null) { |
| 1842 | // Can be cases where mWorkspace is null, this prevents a NPE |
| 1843 | return; |
| 1844 | } |
| 1845 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1846 | // In all these cases, only animate if we're already on home |
| 1847 | mWorkspace.exitWidgetResizeMode(); |
| 1848 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1849 | openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1850 | mWorkspace.moveToDefaultScreen(true); |
Winson Chung | 4a2afa3 | 2012-07-19 14:53:05 -0700 | [diff] [blame] | 1851 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1852 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1853 | closeFolder(); |
| 1854 | exitSpringLoadedDragMode(); |
| 1855 | |
| 1856 | // If we are already on home, then just animate back to the workspace, |
| 1857 | // otherwise, just wait until onResume to set the state back to Workspace |
| 1858 | if (alreadyOnHome) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1859 | showWorkspace(true); |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1860 | } else { |
| 1861 | mOnResumeState = State.WORKSPACE; |
| 1862 | } |
| 1863 | |
| 1864 | final View v = getWindow().peekDecorView(); |
| 1865 | if (v != null && v.getWindowToken() != null) { |
| 1866 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1867 | INPUT_METHOD_SERVICE); |
| 1868 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 1869 | } |
| 1870 | |
| 1871 | // Reset the apps customize page |
Winson Chung | e7e97e6 | 2013-12-02 17:02:50 -0800 | [diff] [blame] | 1872 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1873 | mAppsCustomizeTabHost.reset(); |
| 1874 | } |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1875 | |
| 1876 | onHomeIntent(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1877 | } |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 1878 | |
Michael Jurka | 447bf84 | 2013-05-15 14:52:15 +0200 | [diff] [blame] | 1879 | if (DEBUG_RESUME_TIME) { |
| 1880 | Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); |
| 1881 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1882 | } |
| 1883 | |
Adam Copp | a120b8e | 2013-11-12 16:26:04 +0000 | [diff] [blame] | 1884 | /** |
| 1885 | * Override point for subclasses to prevent movement to the default screen when the home |
| 1886 | * button is pressed. Used (for example) in GEL, to prevent movement during a search. |
| 1887 | */ |
| 1888 | protected boolean shouldMoveToDefaultScreenOnHomeIntent() { |
| 1889 | return true; |
| 1890 | } |
| 1891 | |
| 1892 | /** |
| 1893 | * Override point for subclasses to provide custom behaviour for when a home intent is fired. |
| 1894 | */ |
| 1895 | protected void onHomeIntent() { |
| 1896 | // Do nothing |
| 1897 | } |
| 1898 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1899 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 1900 | public void onRestoreInstanceState(Bundle state) { |
| 1901 | super.onRestoreInstanceState(state); |
| 1902 | for (int page: mSynchronouslyBoundPages) { |
| 1903 | mWorkspace.restoreInstanceStateForChild(page); |
| 1904 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | @Override |
| 1908 | protected void onSaveInstanceState(Bundle outState) { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1909 | if (mWorkspace.getChildCount() > 0) { |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 1910 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, |
| 1911 | mWorkspace.getCurrentPageOffsetFromCustomContent()); |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 1912 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1913 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1914 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1915 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 1916 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 1917 | // this state is reflected. |
| 1918 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1919 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1920 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1921 | mWaitingForResult) { |
| 1922 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1923 | outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1924 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 1925 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 1926 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX); |
| 1927 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY); |
| 1928 | outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo); |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 1929 | outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | if (mFolderInfo != null && mWaitingForResult) { |
| 1933 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1934 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1935 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1936 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1937 | // Save the current AppsCustomize tab |
| 1938 | if (mAppsCustomizeTabHost != null) { |
Winson Chung | 07e045c6 | 2013-11-06 15:49:51 -0800 | [diff] [blame] | 1939 | AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType(); |
| 1940 | String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1941 | if (currentTabTag != null) { |
| 1942 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 1943 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1944 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 1945 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1946 | } |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1947 | outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | @Override |
| 1951 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1952 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1953 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1954 | // Remove all pending runnables |
| 1955 | mHandler.removeMessages(ADVANCE_MSG); |
| 1956 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 1957 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1958 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1959 | // Stop callbacks from LauncherModel |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 1960 | LauncherAppState app = (LauncherAppState.getInstance()); |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1961 | mModel.stopLoader(); |
| 1962 | app.setLauncher(null); |
| 1963 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1964 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1965 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1966 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1967 | 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] | 1968 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1969 | mAppWidgetHost = null; |
| 1970 | |
| 1971 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1972 | |
| 1973 | TextKeyListener.getInstance().release(); |
| 1974 | |
Winson Chung | 81b5225 | 2012-08-27 15:34:29 -0700 | [diff] [blame] | 1975 | // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace |
| 1976 | // to prevent leaking Launcher activities on orientation change. |
| 1977 | if (mModel != null) { |
| 1978 | mModel.unbindItemInfosAndClearQueuedBindRunnables(); |
| 1979 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1980 | |
| 1981 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1982 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1983 | |
Adam Cohen | accf3bf | 2012-04-30 16:07:43 -0700 | [diff] [blame] | 1984 | mDragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1985 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
Adam Cohen | d552dd9 | 2013-11-26 12:13:11 -0800 | [diff] [blame] | 1986 | mWorkspace.removeAllWorkspaceScreens(); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1987 | mWorkspace = null; |
| 1988 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 1989 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 1990 | LauncherAnimUtils.onDestroyActivity(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1991 | } |
| 1992 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1993 | public DragController getDragController() { |
| 1994 | return mDragController; |
| 1995 | } |
| 1996 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1997 | @Override |
| 1998 | public void startActivityForResult(Intent intent, int requestCode) { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 1999 | if (requestCode >= 0) { |
| 2000 | setWaitingForResult(true); |
| 2001 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2002 | super.startActivityForResult(intent, requestCode); |
| 2003 | } |
| 2004 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2005 | /** |
| 2006 | * Indicates that we want global search for this activity by setting the globalSearch |
| 2007 | * argument for {@link #startSearch} to true. |
| 2008 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2009 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2010 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2011 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2012 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2013 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2014 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2015 | if (initialQuery == null) { |
| 2016 | // Use any text typed in the launcher as the initial query |
| 2017 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2018 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2019 | if (appSearchData == null) { |
| 2020 | appSearchData = new Bundle(); |
Bjorn Bringert | 32b12d2 | 2013-06-06 13:00:41 +0100 | [diff] [blame] | 2021 | appSearchData.putString("source", "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2022 | } |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 2023 | Rect sourceBounds = new Rect(); |
| 2024 | if (mSearchDropTargetBar != null) { |
| 2025 | sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
| 2026 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2027 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2028 | startSearch(initialQuery, selectInitialQuery, |
| 2029 | appSearchData, sourceBounds); |
| 2030 | } |
| 2031 | |
| 2032 | public void startSearch(String initialQuery, |
| 2033 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2034 | startGlobalSearch(initialQuery, selectInitialQuery, |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2035 | appSearchData, sourceBounds); |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | /** |
| 2039 | * Starts the global search activity. This code is a copied from SearchManager |
| 2040 | */ |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2041 | private void startGlobalSearch(String initialQuery, |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2042 | boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2043 | final SearchManager searchManager = |
Michael Jurka | a33411c | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2044 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2045 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 2046 | if (globalSearchActivity == null) { |
| 2047 | Log.w(TAG, "No global search activity found."); |
| 2048 | return; |
| 2049 | } |
| 2050 | Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 2051 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2052 | intent.setComponent(globalSearchActivity); |
| 2053 | // Make sure that we have a Bundle to put source in |
| 2054 | if (appSearchData == null) { |
| 2055 | appSearchData = new Bundle(); |
| 2056 | } else { |
| 2057 | appSearchData = new Bundle(appSearchData); |
| 2058 | } |
| 2059 | // Set source to package name of app that starts global search, if not set already. |
| 2060 | if (!appSearchData.containsKey("source")) { |
| 2061 | appSearchData.putString("source", getPackageName()); |
| 2062 | } |
| 2063 | intent.putExtra(SearchManager.APP_DATA, appSearchData); |
| 2064 | if (!TextUtils.isEmpty(initialQuery)) { |
| 2065 | intent.putExtra(SearchManager.QUERY, initialQuery); |
| 2066 | } |
| 2067 | if (selectInitialQuery) { |
| 2068 | intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); |
| 2069 | } |
| 2070 | intent.setSourceBounds(sourceBounds); |
| 2071 | try { |
| 2072 | startActivity(intent); |
| 2073 | } catch (ActivityNotFoundException ex) { |
| 2074 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 2075 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2076 | } |
| 2077 | |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2078 | public boolean isOnCustomContent() { |
| 2079 | return mWorkspace.isOnOrMovingToCustomContent(); |
| 2080 | } |
| 2081 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2082 | @Override |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2083 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 2084 | super.onPrepareOptionsMenu(menu); |
Yura | 4f93ec6 | 2014-02-04 14:15:21 +0000 | [diff] [blame] | 2085 | if (!isOnCustomContent()) { |
| 2086 | // Close any open folders |
| 2087 | closeFolder(); |
| 2088 | // Stop resizing any widgets |
| 2089 | mWorkspace.exitWidgetResizeMode(); |
| 2090 | if (!mWorkspace.isInOverviewMode()) { |
| 2091 | // Show the overview mode |
| 2092 | showOverviewMode(true); |
| 2093 | } else { |
| 2094 | showWorkspace(true); |
| 2095 | } |
Winson Chung | e029874 | 2014-01-17 12:03:00 -0800 | [diff] [blame] | 2096 | } |
Michael Jurka | b94f3f8 | 2013-09-11 18:08:54 +0200 | [diff] [blame] | 2097 | return false; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 2098 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2099 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2100 | @Override |
| 2101 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2102 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2103 | // Use a custom animation for launching search |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2104 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2107 | public boolean isWorkspaceLocked() { |
| 2108 | return mWorkspaceLoading || mWaitingForResult; |
| 2109 | } |
| 2110 | |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 2111 | public boolean isWorkspaceLoading() { |
| 2112 | return mWorkspaceLoading; |
| 2113 | } |
| 2114 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 2115 | private void setWorkspaceLoading(boolean value) { |
| 2116 | boolean isLocked = isWorkspaceLocked(); |
| 2117 | mWorkspaceLoading = value; |
| 2118 | if (isLocked != isWorkspaceLocked()) { |
| 2119 | onWorkspaceLockedChanged(); |
| 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | private void setWaitingForResult(boolean value) { |
| 2124 | boolean isLocked = isWorkspaceLocked(); |
| 2125 | mWaitingForResult = value; |
| 2126 | if (isLocked != isWorkspaceLocked()) { |
| 2127 | onWorkspaceLockedChanged(); |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | protected void onWorkspaceLockedChanged() { } |
| 2132 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2133 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2134 | mPendingAddInfo.container = ItemInfo.NO_ID; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2135 | mPendingAddInfo.screenId = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2136 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 2137 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2138 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2139 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2140 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2141 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2142 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2143 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) { |
| 2144 | addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0); |
| 2145 | } |
| 2146 | |
| 2147 | void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, |
| 2148 | final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int |
| 2149 | delay) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2150 | if (appWidgetInfo.configure != null) { |
| 2151 | mPendingAddWidgetInfo = appWidgetInfo; |
Adam Cohen | 4637b5a | 2013-11-04 18:21:24 -0800 | [diff] [blame] | 2152 | mPendingAddWidgetId = appWidgetId; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2153 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2154 | // Launch over to configure widget, if needed |
| 2155 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2156 | intent.setComponent(appWidgetInfo.configure); |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2157 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
Michael Jurka | a805e1a | 2013-08-22 15:00:33 +0200 | [diff] [blame] | 2158 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2159 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 2160 | // Otherwise just add it |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 2161 | Runnable onComplete = new Runnable() { |
| 2162 | @Override |
| 2163 | public void run() { |
| 2164 | // Exit spring loaded mode if necessary after adding the widget |
| 2165 | exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 2166 | null); |
| 2167 | } |
| 2168 | }; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2169 | completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2170 | appWidgetInfo); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 2171 | mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2172 | } |
| 2173 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2174 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2175 | protected void moveToCustomContentScreen(boolean animate) { |
Sandeep Siddhartha | f2b47f1 | 2013-09-26 19:49:27 -0700 | [diff] [blame] | 2176 | // Close any folders that may be open. |
| 2177 | closeFolder(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 2178 | mWorkspace.moveToCustomContentScreen(animate); |
| 2179 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2180 | /** |
| 2181 | * Process a shortcut drop. |
| 2182 | * |
| 2183 | * @param componentName The name of the component |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2184 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2185 | * @param cell The cell it should be added to, optional |
| 2186 | * @param position The location on the screen where it was dropped, optional |
| 2187 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2188 | void processShortcutFromDrop(ComponentName componentName, long container, long screenId, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2189 | int[] cell, int[] loc) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2190 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2191 | mPendingAddInfo.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2192 | mPendingAddInfo.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2193 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2194 | |
| 2195 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2196 | mPendingAddInfo.cellX = cell[0]; |
| 2197 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2198 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2199 | |
| 2200 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 2201 | createShortcutIntent.setComponent(componentName); |
| 2202 | processShortcut(createShortcutIntent); |
| 2203 | } |
| 2204 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2205 | /** |
| 2206 | * Process a widget drop. |
| 2207 | * |
| 2208 | * @param info The PendingAppWidgetInfo of the widget being added. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2209 | * @param screenId The ID of the screen where it should be added |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2210 | * @param cell The cell it should be added to, optional |
| 2211 | * @param position The location on the screen where it was dropped, optional |
| 2212 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2213 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2214 | int[] cell, int[] span, int[] loc) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2215 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2216 | mPendingAddInfo.container = info.container = container; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2217 | mPendingAddInfo.screenId = info.screenId = screenId; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2218 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2219 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 2220 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 2221 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2222 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2223 | mPendingAddInfo.cellX = cell[0]; |
| 2224 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2225 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2226 | if (span != null) { |
| 2227 | mPendingAddInfo.spanX = span[0]; |
| 2228 | mPendingAddInfo.spanY = span[1]; |
| 2229 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2230 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2231 | AppWidgetHostView hostView = info.boundWidget; |
| 2232 | int appWidgetId; |
| 2233 | if (hostView != null) { |
| 2234 | appWidgetId = hostView.getAppWidgetId(); |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2235 | addAppWidgetImpl(appWidgetId, info, hostView, info.info); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2236 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2237 | // In this case, we either need to start an activity to get permission to bind |
| 2238 | // 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] | 2239 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2240 | Bundle options = info.bindOptions; |
| 2241 | |
| 2242 | boolean success = false; |
| 2243 | if (options != null) { |
| 2244 | success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, |
| 2245 | info.componentName, options); |
| 2246 | } else { |
| 2247 | success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, |
| 2248 | info.componentName); |
| 2249 | } |
| 2250 | if (success) { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2251 | addAppWidgetImpl(appWidgetId, info, null, info.info); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2252 | } else { |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 2253 | mPendingAddWidgetInfo = info.info; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2254 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); |
| 2255 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2256 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 2257 | // TODO: we need to make sure that this accounts for the options bundle. |
| 2258 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2259 | startActivityForResult(intent, REQUEST_BIND_APPWIDGET); |
| 2260 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2261 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2264 | void processShortcut(Intent intent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2265 | Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2266 | } |
| 2267 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 2268 | void processWallpaper(Intent intent) { |
| 2269 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 2270 | } |
| 2271 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2272 | FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2273 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 2274 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2275 | folderInfo.title = getText(R.string.folder_name); |
| 2276 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2277 | // Update the model |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2278 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2279 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2280 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2281 | |
| 2282 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2283 | FolderIcon newFolder = |
| 2284 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2285 | mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2286 | isWorkspaceLocked()); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2287 | // Force measure the new folder icon |
| 2288 | CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); |
| 2289 | parent.getShortcutsAndWidgets().measureChild(newFolder); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2290 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2291 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2292 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2293 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2294 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2295 | } |
| 2296 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2297 | protected ComponentName getWallpaperPickerComponent() { |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 2298 | return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName()); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2299 | } |
| 2300 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2301 | /** |
| 2302 | * Registers various content observers. The current implementation registers |
| 2303 | * only a favorites observer to keep track of the favorites applications. |
| 2304 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2305 | private void registerContentObservers() { |
| 2306 | ContentResolver resolver = getContentResolver(); |
| 2307 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 2308 | true, mWidgetObserver); |
| 2309 | } |
| 2310 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2311 | @Override |
| 2312 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 2313 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 2314 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2315 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2316 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2317 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 2318 | if (isPropertyEnabled(DUMP_STATE_PROPERTY)) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2319 | dumpState(); |
| 2320 | return true; |
| 2321 | } |
| 2322 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2323 | } |
| 2324 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2325 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 2326 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2327 | return true; |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | return super.dispatchKeyEvent(event); |
| 2332 | } |
| 2333 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2334 | @Override |
| 2335 | public void onBackPressed() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2336 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2337 | if (mAppsCustomizeContent.getContentType() == |
| 2338 | AppsCustomizePagedView.ContentType.Applications) { |
| 2339 | showWorkspace(true); |
| 2340 | } else { |
| 2341 | showOverviewMode(true); |
| 2342 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2343 | } else if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2344 | mWorkspace.exitOverviewMode(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2345 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 2346 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 2347 | if (openFolder.isEditingName()) { |
| 2348 | openFolder.dismissEditingName(); |
| 2349 | } else { |
| 2350 | closeFolder(); |
| 2351 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2352 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2353 | mWorkspace.exitWidgetResizeMode(); |
| 2354 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 2355 | // Back button is a no-op here, but give at least some feedback for the button press |
| 2356 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2357 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 2358 | } |
| 2359 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2360 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2361 | * Re-listen when widgets are reset. |
| 2362 | */ |
| 2363 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 2364 | if (mAppWidgetHost != null) { |
| 2365 | mAppWidgetHost.startListening(); |
| 2366 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2370 | * Launches the intent referred by the clicked shortcut. |
| 2371 | * |
| 2372 | * @param v The view representing the clicked shortcut. |
| 2373 | */ |
| 2374 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2375 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 2376 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 2377 | if (v.getWindowToken() == null) { |
| 2378 | return; |
| 2379 | } |
| 2380 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 2381 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2382 | return; |
| 2383 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 2384 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2385 | if (v instanceof Workspace) { |
| 2386 | if (mWorkspace.isInOverviewMode()) { |
| 2387 | mWorkspace.exitOverviewMode(true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2388 | } |
| 2389 | return; |
| 2390 | } |
| 2391 | |
| 2392 | if (v instanceof CellLayout) { |
| 2393 | if (mWorkspace.isInOverviewMode()) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2394 | mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2395 | } |
| 2396 | } |
| 2397 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2398 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2399 | if (tag instanceof ShortcutInfo) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2400 | onClickAppShortcut(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2401 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2402 | if (v instanceof FolderIcon) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2403 | onClickFolderIcon(v); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2404 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2405 | } else if (v == mAllAppsButton) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2406 | onClickAllAppsButton(v); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2410 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2411 | return false; |
| 2412 | } |
| 2413 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2414 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2415 | * Event handler for the search button |
| 2416 | * |
| 2417 | * @param v The view that was clicked. |
| 2418 | */ |
| 2419 | public void onClickSearchButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2420 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2421 | |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 2422 | onSearchRequested(); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2426 | * Event handler for the voice button |
| 2427 | * |
| 2428 | * @param v The view that was clicked. |
| 2429 | */ |
| 2430 | public void onClickVoiceButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2431 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2432 | |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 2433 | startVoice(); |
| 2434 | } |
| 2435 | |
| 2436 | public void startVoice() { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2437 | try { |
| 2438 | final SearchManager searchManager = |
| 2439 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2440 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 2441 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2442 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2443 | if (activityName != null) { |
| 2444 | intent.setPackage(activityName.getPackageName()); |
| 2445 | } |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2446 | startActivity(null, intent, "onClickVoiceButton"); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2447 | } catch (ActivityNotFoundException e) { |
| 2448 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Andy Huang | f615f71 | 2012-06-07 13:38:04 -0700 | [diff] [blame] | 2449 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 2450 | startActivitySafely(null, intent, "onClickVoiceButton"); |
| 2451 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2455 | * Event handler for the "grid" button that appears on the home screen, which |
| 2456 | * enters all apps mode. |
| 2457 | * |
| 2458 | * @param v The view that was clicked. |
| 2459 | */ |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2460 | protected void onClickAllAppsButton(View v) { |
| 2461 | if (LOGD) Log.d(TAG, "onClickAllAppsButton"); |
| 2462 | if (isAllAppsVisible()) { |
| 2463 | showWorkspace(true); |
| 2464 | } else { |
| 2465 | showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false); |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | /** |
Mohammadinamul Sheik | 3b1a54a | 2014-03-18 11:28:19 -0700 | [diff] [blame] | 2470 | * Event handler for a paged view icon click. |
| 2471 | * @param v The view that was clicked. |
| 2472 | * @param appInfo The {link AppInfo} of the view. |
| 2473 | */ |
| 2474 | public void onClickPagedViewIcon(View v, AppInfo appInfo) { |
| 2475 | if (LOGD) Log.d(TAG, "onClickPagedViewIcon"); |
| 2476 | startActivitySafely(v, appInfo.intent, appInfo); |
| 2477 | getStats().recordLaunch(appInfo.intent); |
| 2478 | } |
| 2479 | |
| 2480 | /** |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2481 | * Event handler for an app shortcut click. |
| 2482 | * |
| 2483 | * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}. |
| 2484 | */ |
| 2485 | protected void onClickAppShortcut(View v) { |
| 2486 | if (LOGD) Log.d(TAG, "onClickAppShortcut"); |
| 2487 | Object tag = v.getTag(); |
| 2488 | if (!(tag instanceof ShortcutInfo)) { |
| 2489 | throw new IllegalArgumentException("Input must be a Shortcut"); |
| 2490 | } |
| 2491 | |
| 2492 | // Open shortcut |
| 2493 | final ShortcutInfo shortcut = (ShortcutInfo) tag; |
| 2494 | final Intent intent = shortcut.intent; |
| 2495 | |
| 2496 | // Check for special shortcuts |
| 2497 | if (intent.getComponent() != null) { |
| 2498 | final String shortcutClass = intent.getComponent().getClassName(); |
| 2499 | |
| 2500 | if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { |
| 2501 | MemoryDumpActivity.startDump(this); |
| 2502 | return; |
| 2503 | } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { |
| 2504 | toggleShowWeightWatcher(); |
| 2505 | return; |
| 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | // Start activities |
| 2510 | int[] pos = new int[2]; |
| 2511 | v.getLocationOnScreen(pos); |
| 2512 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 2513 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
| 2514 | |
| 2515 | boolean success = startActivitySafely(v, intent, tag); |
| 2516 | |
| 2517 | mStats.recordLaunch(intent, shortcut); |
| 2518 | |
| 2519 | if (success && v instanceof BubbleTextView) { |
| 2520 | mWaitingForResume = (BubbleTextView) v; |
| 2521 | mWaitingForResume.setStayPressed(true); |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | /** |
| 2526 | * Event handler for a folder icon click. |
| 2527 | * |
| 2528 | * @param v The view that was clicked. Must be an instance of {@link FolderIcon}. |
| 2529 | */ |
| 2530 | protected void onClickFolderIcon(View v) { |
| 2531 | if (LOGD) Log.d(TAG, "onClickFolder"); |
| 2532 | if (!(v instanceof FolderIcon)){ |
| 2533 | throw new IllegalArgumentException("Input must be a FolderIcon"); |
| 2534 | } |
| 2535 | |
| 2536 | FolderIcon folderIcon = (FolderIcon) v; |
| 2537 | final FolderInfo info = folderIcon.getFolderInfo(); |
| 2538 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 2539 | |
| 2540 | // If the folder info reports that the associated folder is open, then verify that |
| 2541 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 2542 | if (info.opened && openFolder == null) { |
| 2543 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 2544 | + info.screenId + " (" + info.cellX + ", " + info.cellY + ")"); |
| 2545 | info.opened = false; |
| 2546 | } |
| 2547 | |
| 2548 | if (!info.opened && !folderIcon.getFolder().isDestroyed()) { |
| 2549 | // Close any open folder |
| 2550 | closeFolder(); |
| 2551 | // Open the requested folder |
| 2552 | openFolder(folderIcon); |
| 2553 | } else { |
| 2554 | // Find the open folder... |
| 2555 | int folderScreen; |
| 2556 | if (openFolder != null) { |
| 2557 | folderScreen = mWorkspace.getPageForView(openFolder); |
| 2558 | // .. and close it |
| 2559 | closeFolder(openFolder); |
| 2560 | if (folderScreen != mWorkspace.getCurrentPage()) { |
| 2561 | // Close any folder open on the current screen |
| 2562 | closeFolder(); |
| 2563 | // Pull the folder onto this screen |
| 2564 | openFolder(folderIcon); |
| 2565 | } |
| 2566 | } |
| 2567 | } |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2570 | /** |
| 2571 | * Event handler for the (Add) Widgets button that appears after a long press |
| 2572 | * on the home screen. |
| 2573 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2574 | protected void onClickAddWidgetButton(View view) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2575 | if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); |
Sandeep Siddhartha | d805837 | 2014-01-28 10:41:15 -0800 | [diff] [blame] | 2576 | showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); |
| 2577 | } |
| 2578 | |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2579 | /** |
| 2580 | * Event handler for the wallpaper picker button that appears after a long press |
| 2581 | * on the home screen. |
| 2582 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2583 | protected void onClickWallpaperPicker(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2584 | if (LOGD) Log.d(TAG, "onClickWallpaperPicker"); |
| 2585 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 2586 | pickWallpaper.setComponent(getWallpaperPickerComponent()); |
| 2587 | startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER); |
| 2588 | } |
| 2589 | |
| 2590 | /** |
| 2591 | * Event handler for a click on the settings button that appears after a long press |
| 2592 | * on the home screen. |
| 2593 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 2594 | protected void onClickSettingsButton(View v) { |
Sandeep Siddhartha | a942030 | 2014-02-12 18:24:31 -0800 | [diff] [blame] | 2595 | if (LOGD) Log.d(TAG, "onClickSettingsButton"); |
| 2596 | } |
| 2597 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 2598 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 2599 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2600 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2601 | } |
| 2602 | |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 2603 | public void performHapticFeedbackOnTouchDown(View v) { |
| 2604 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 2605 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2606 | } |
| 2607 | |
| 2608 | public View.OnTouchListener getHapticFeedbackTouchListener() { |
| 2609 | if (mHapticFeedbackTouchListener == null) { |
| 2610 | mHapticFeedbackTouchListener = new View.OnTouchListener() { |
| 2611 | @Override |
| 2612 | public boolean onTouch(View v, MotionEvent event) { |
| 2613 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 2614 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 2615 | } |
| 2616 | return false; |
| 2617 | } |
| 2618 | }; |
| 2619 | } |
| 2620 | return mHapticFeedbackTouchListener; |
| 2621 | } |
| 2622 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2623 | public void onClickAppMarketButton(View v) { |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 2624 | if (!DISABLE_MARKET_BUTTON) { |
| 2625 | if (mAppMarketIntent != null) { |
| 2626 | startActivitySafely(v, mAppMarketIntent, "app market"); |
| 2627 | } else { |
| 2628 | Log.e(TAG, "Invalid app market intent."); |
| 2629 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2633 | public void onDragStarted(View view) {} |
| 2634 | |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 2635 | /** |
| 2636 | * Called when the user stops interacting with the launcher. |
| 2637 | * This implies that the user is now on the homescreen and is not doing housekeeping. |
| 2638 | */ |
| 2639 | protected void onInteractionEnd() {} |
| 2640 | |
| 2641 | /** |
| 2642 | * Called when the user starts interacting with the launcher. |
| 2643 | * The possible interactions are: |
| 2644 | * - open all apps |
| 2645 | * - reorder an app shortcut, or a widget |
| 2646 | * - open the overview mode. |
| 2647 | * This is a good time to stop doing things that only make sense |
| 2648 | * when the user is on the homescreen and not doing housekeeping. |
| 2649 | */ |
| 2650 | protected void onInteractionBegin() {} |
| 2651 | |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2652 | void startApplicationDetailsActivity(ComponentName componentName) { |
| 2653 | String packageName = componentName.getPackageName(); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2654 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 2655 | Uri.fromParts("package", packageName, null)); |
Adrian Roos | 850f913 | 2014-01-13 17:44:52 -0800 | [diff] [blame] | 2656 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | |
| 2657 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Winson Chung | 3b1b36b | 2012-04-24 18:51:14 -0700 | [diff] [blame] | 2658 | startActivitySafely(null, intent, "startApplicationDetailsActivity"); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2661 | // returns true if the activity was started |
| 2662 | boolean startApplicationUninstallActivity(ComponentName componentName, int flags) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 2663 | if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2664 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2665 | // We may give them the option of disabling apps this way. |
| 2666 | int messageId = R.string.uninstall_system_app_text; |
| 2667 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2668 | return false; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2669 | } else { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2670 | String packageName = componentName.getPackageName(); |
| 2671 | String className = componentName.getClassName(); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2672 | Intent intent = new Intent( |
| 2673 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2674 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 2675 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2676 | startActivity(intent); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2677 | return true; |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2678 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2681 | boolean startActivity(View v, Intent intent, Object tag) { |
Kenny Guy | b6cc40b | 2014-05-13 15:58:58 +0100 | [diff] [blame] | 2682 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2683 | try { |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2684 | // Only launch using the new animation if the shortcut has not opted out (this is a |
| 2685 | // private contract between launcher and may be ignored in the future). |
| 2686 | boolean useLaunchAnimation = (v != null) && |
| 2687 | !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2688 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 2689 | UserManagerCompat userManager = UserManagerCompat.getInstance(this); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 2690 | |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2691 | UserHandleCompat user = null; |
| 2692 | if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { |
| 2693 | long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); |
| 2694 | user = userManager.getUserForSerialNumber(serialNumber); |
| 2695 | } |
| 2696 | |
| 2697 | Bundle optsBundle = null; |
Winson Chung | 2672ff9 | 2012-05-04 16:22:30 -0700 | [diff] [blame] | 2698 | if (useLaunchAnimation) { |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2699 | ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, |
| 2700 | v.getMeasuredWidth(), v.getMeasuredHeight()); |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2701 | optsBundle = opts.toBundle(); |
| 2702 | } |
| 2703 | |
| 2704 | if (user == null || user.equals(UserHandleCompat.myUserHandle())) { |
| 2705 | // Could be launching some bookkeeping activity |
| 2706 | startActivity(intent, optsBundle); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2707 | } else { |
Kenny Guy | 1317e2d | 2014-05-08 18:52:50 +0100 | [diff] [blame] | 2708 | launcherApps.startActivityForProfile(intent.getComponent(), |
| 2709 | intent.getSourceBounds(), optsBundle, user); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 2710 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2711 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2712 | } catch (SecurityException e) { |
| 2713 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2714 | 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] | 2715 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2716 | "or use the exported attribute for this activity. " |
| 2717 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2718 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2719 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2720 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2721 | |
Michael Jurka | 86a720e | 2012-05-09 11:23:23 -0700 | [diff] [blame] | 2722 | boolean startActivitySafely(View v, Intent intent, Object tag) { |
| 2723 | boolean success = false; |
| 2724 | try { |
| 2725 | success = startActivity(v, intent, tag); |
| 2726 | } catch (ActivityNotFoundException e) { |
| 2727 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2728 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
| 2729 | } |
| 2730 | return success; |
| 2731 | } |
| 2732 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2733 | /** |
| 2734 | * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView |
| 2735 | * in the DragLayer in the exact absolute location of the original FolderIcon. |
| 2736 | */ |
| 2737 | private void copyFolderIconToImage(FolderIcon fi) { |
| 2738 | final int width = fi.getMeasuredWidth(); |
| 2739 | final int height = fi.getMeasuredHeight(); |
| 2740 | |
| 2741 | // Lazy load ImageView, Bitmap and Canvas |
| 2742 | if (mFolderIconImageView == null) { |
| 2743 | mFolderIconImageView = new ImageView(this); |
| 2744 | } |
| 2745 | if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || |
| 2746 | mFolderIconBitmap.getHeight() != height) { |
| 2747 | mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 2748 | mFolderIconCanvas = new Canvas(mFolderIconBitmap); |
| 2749 | } |
| 2750 | |
| 2751 | DragLayer.LayoutParams lp; |
| 2752 | if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { |
| 2753 | lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); |
| 2754 | } else { |
| 2755 | lp = new DragLayer.LayoutParams(width, height); |
| 2756 | } |
| 2757 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2758 | // The layout from which the folder is being opened may be scaled, adjust the starting |
| 2759 | // view size by this scale factor. |
| 2760 | float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2761 | lp.customPosition = true; |
| 2762 | lp.x = mRectForFolderAnimation.left; |
| 2763 | lp.y = mRectForFolderAnimation.top; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2764 | lp.width = (int) (scale * width); |
| 2765 | lp.height = (int) (scale * height); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2766 | |
| 2767 | mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2768 | fi.draw(mFolderIconCanvas); |
| 2769 | mFolderIconImageView.setImageBitmap(mFolderIconBitmap); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2770 | if (fi.getFolder() != null) { |
| 2771 | mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); |
| 2772 | mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2773 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2774 | // Just in case this image view is still in the drag layer from a previous animation, |
| 2775 | // we remove it and re-add it. |
| 2776 | if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { |
| 2777 | mDragLayer.removeView(mFolderIconImageView); |
| 2778 | } |
| 2779 | mDragLayer.addView(mFolderIconImageView, lp); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2780 | if (fi.getFolder() != null) { |
| 2781 | fi.getFolder().bringToFront(); |
Adam Cohen | 8ec2303 | 2012-06-08 14:46:22 -0700 | [diff] [blame] | 2782 | } |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2785 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2786 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2787 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 2788 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 2789 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 2790 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2791 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 2792 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2793 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 2794 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 2795 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2796 | } |
| 2797 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2798 | // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original |
| 2799 | copyFolderIconToImage(fi); |
| 2800 | fi.setVisibility(View.INVISIBLE); |
| 2801 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2802 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2803 | scaleX, scaleY); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2804 | oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); |
| 2805 | oa.start(); |
| 2806 | } |
| 2807 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2808 | private void shrinkAndFadeInFolderIcon(final FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 2809 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2810 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 2811 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 2812 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 2813 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2814 | final CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2815 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2816 | // We remove and re-draw the FolderIcon in-case it has changed |
| 2817 | mDragLayer.removeView(mFolderIconImageView); |
| 2818 | copyFolderIconToImage(fi); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2819 | ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2820 | scaleX, scaleY); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2821 | oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2822 | oa.addListener(new AnimatorListenerAdapter() { |
| 2823 | @Override |
| 2824 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2825 | if (cl != null) { |
| 2826 | cl.clearFolderLeaveBehind(); |
| 2827 | // Remove the ImageView copy of the FolderIcon and make the original visible. |
| 2828 | mDragLayer.removeView(mFolderIconImageView); |
| 2829 | fi.setVisibility(View.VISIBLE); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 2830 | } |
| 2831 | } |
| 2832 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2833 | oa.start(); |
| 2834 | } |
| 2835 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2836 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 2837 | * 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] | 2838 | * is animated relative to the specified View. If the View is null, no animation |
| 2839 | * is played. |
| 2840 | * |
| 2841 | * @param folderInfo The FolderInfo describing the folder to open. |
| 2842 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2843 | public void openFolder(FolderIcon folderIcon) { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 2844 | Folder folder = folderIcon.getFolder(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2845 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2846 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2847 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2848 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2849 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 2850 | // There was a one-off crash where the folder had a parent already. |
| 2851 | if (folder.getParent() == null) { |
| 2852 | mDragLayer.addView(folder); |
| 2853 | mDragController.addDropTarget((DropTarget) folder); |
| 2854 | } else { |
| 2855 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 2856 | folder.getParent() + ")."); |
| 2857 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2858 | folder.animateOpen(); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 2859 | growAndFadeOutFolderIcon(folderIcon); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 2860 | |
| 2861 | // Notify the accessibility manager that this folder "window" has appeared and occluded |
| 2862 | // the workspace items |
| 2863 | folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2864 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | public void closeFolder() { |
Adam Cohen | 37c717f | 2013-11-26 11:50:15 -0800 | [diff] [blame] | 2868 | Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null; |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2869 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 2870 | if (folder.isEditingName()) { |
| 2871 | folder.dismissEditingName(); |
| 2872 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2873 | closeFolder(folder); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 2874 | |
| 2875 | // Dismiss the folder cling |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 2876 | mLauncherClings.dismissFolderCling(null); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | void closeFolder(Folder folder) { |
| 2881 | folder.getInfo().opened = false; |
| 2882 | |
| 2883 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 2884 | if (parent != null) { |
| 2885 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 2886 | shrinkAndFadeInFolderIcon(fi); |
| 2887 | } |
| 2888 | folder.animateClosed(); |
Winson Chung | 83ca480 | 2013-04-12 15:10:52 -0700 | [diff] [blame] | 2889 | |
| 2890 | // Notify the accessibility manager that this folder "window" has disappeard and no |
| 2891 | // longer occludeds the workspace items |
| 2892 | getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2893 | } |
| 2894 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2895 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 2896 | if (!isDraggingEnabled()) return false; |
| 2897 | if (isWorkspaceLocked()) return false; |
| 2898 | if (mState != State.WORKSPACE) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2899 | |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2900 | if (v instanceof Workspace) { |
| 2901 | if (!mWorkspace.isInOverviewMode()) { |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 2902 | if (mWorkspace.enterOverviewMode()) { |
| 2903 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2904 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 2905 | return true; |
| 2906 | } else { |
| 2907 | return false; |
| 2908 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2909 | } |
Adam Cohen | 1697b79 | 2013-09-17 19:08:21 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
Adam Cohen | e0aaa0d | 2014-05-12 12:44:22 -0700 | [diff] [blame] | 2912 | CellLayout.CellInfo longClickCellInfo = null; |
| 2913 | View itemUnderLongClick = null; |
| 2914 | if (v.getTag() instanceof ItemInfo) { |
| 2915 | ItemInfo info = (ItemInfo) v.getTag(); |
| 2916 | longClickCellInfo = new CellLayout.CellInfo(v, info);; |
| 2917 | itemUnderLongClick = longClickCellInfo.cell; |
| 2918 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2919 | } |
| 2920 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2921 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 2922 | // on hotseat items. |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 2923 | final boolean inHotseat = isHotseatLayout(v); |
| 2924 | boolean allowLongPress = inHotseat || mWorkspace.allowLongPress(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2925 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2926 | if (itemUnderLongClick == null) { |
Adam Cohen | d3ecce9 | 2013-09-16 14:58:00 -0700 | [diff] [blame] | 2927 | // User long pressed on empty space |
| 2928 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2929 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 2930 | // Disabling reordering until we sort out some issues. |
| 2931 | if (mWorkspace.isInOverviewMode()) { |
| 2932 | mWorkspace.startReordering(v); |
| 2933 | } else { |
| 2934 | mWorkspace.enterOverviewMode(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2935 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2936 | } else { |
Dan Sandler | e26d094 | 2014-01-13 14:30:14 -0500 | [diff] [blame] | 2937 | final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank( |
| 2938 | mHotseat.getOrderInHotseat( |
| 2939 | longClickCellInfo.cellX, |
| 2940 | longClickCellInfo.cellY)); |
| 2941 | if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2942 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2943 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2944 | } |
| 2945 | } |
| 2946 | } |
| 2947 | return true; |
| 2948 | } |
| 2949 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2950 | boolean isHotseatLayout(View layout) { |
| 2951 | return mHotseat != null && layout != null && |
| 2952 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 2953 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2954 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2955 | /** |
| 2956 | * Returns the CellLayout of the specified container at the specified screen. |
| 2957 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2958 | CellLayout getCellLayout(long container, long screenId) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2959 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2960 | if (mHotseat != null) { |
| 2961 | return mHotseat.getLayout(); |
| 2962 | } else { |
| 2963 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2964 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2965 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2966 | return (CellLayout) mWorkspace.getScreenWithId(screenId); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2970 | public boolean isAllAppsVisible() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 2971 | return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2972 | } |
| 2973 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2974 | /** |
| 2975 | * Helper method for the cameraZoomIn/cameraZoomOut animations |
| 2976 | * @param view The view being animated |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2977 | * @param scaleFactor The scale factor used for the zoom |
| 2978 | */ |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2979 | private void setPivotsForZoom(View view, float scaleFactor) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2980 | view.setPivotX(view.getWidth() / 2.0f); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2981 | view.setPivotY(view.getHeight() / 2.0f); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2982 | } |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2983 | |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 2984 | private void setWorkspaceBackground(boolean workspace) { |
| 2985 | mLauncherView.setBackground(workspace ? |
Michael Jurka | 496fefb | 2013-05-06 15:39:11 +0200 | [diff] [blame] | 2986 | mWorkspaceBackgroundDrawable : null); |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 2989 | protected void changeWallpaperVisiblity(boolean visible) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 2990 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 2991 | int curflags = getWindow().getAttributes().flags |
| 2992 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2993 | if (wpflags != curflags) { |
| 2994 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 2995 | } |
Craig Mautner | 360310b | 2012-10-26 15:13:08 -0700 | [diff] [blame] | 2996 | setWorkspaceBackground(visible); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 2999 | private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { |
| 3000 | if (v instanceof LauncherTransitionable) { |
| 3001 | ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); |
| 3002 | } |
| 3003 | } |
| 3004 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3005 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 3006 | if (v instanceof LauncherTransitionable) { |
| 3007 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 3008 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3009 | |
| 3010 | // Update the workspace transition step as well |
| 3011 | dispatchOnLauncherTransitionStep(v, 0f); |
| 3012 | } |
| 3013 | |
| 3014 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 3015 | if (v instanceof LauncherTransitionable) { |
| 3016 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 3017 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 3021 | if (v instanceof LauncherTransitionable) { |
| 3022 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 3023 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3024 | |
| 3025 | // Update the workspace transition step as well |
| 3026 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3027 | } |
| 3028 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3029 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3030 | * Things to test when changing the following seven functions. |
| 3031 | * - Home from workspace |
| 3032 | * - from center screen |
| 3033 | * - from other screens |
| 3034 | * - Home from all apps |
| 3035 | * - from center screen |
| 3036 | * - from other screens |
| 3037 | * - Back from all apps |
| 3038 | * - from center screen |
| 3039 | * - from other screens |
| 3040 | * - Launch app from workspace and quit |
| 3041 | * - with back |
| 3042 | * - with home |
| 3043 | * - Launch app from all apps and quit |
| 3044 | * - with back |
| 3045 | * - with home |
| 3046 | * - Go to a screen that's not the default, then all |
| 3047 | * apps, and launch and app, and go back |
| 3048 | * - with back |
| 3049 | * -with home |
| 3050 | * - On workspace, long press power and go back |
| 3051 | * - with back |
| 3052 | * - with home |
| 3053 | * - On all apps, long press power and go back |
| 3054 | * - with back |
| 3055 | * - with home |
| 3056 | * - On workspace, power off |
| 3057 | * - On all apps, power off |
| 3058 | * - Launch an app and turn off the screen while in that app |
| 3059 | * - Go back with home key |
| 3060 | * - Go back with back key TODO: make this not go to workspace |
| 3061 | * - From all apps |
| 3062 | * - From workspace |
| 3063 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3064 | * - From all apps |
| 3065 | * - From the center workspace |
| 3066 | * - From another workspace |
| 3067 | */ |
| 3068 | |
| 3069 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3070 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 3071 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 3072 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3073 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3074 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3075 | AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType(); |
| 3076 | showAppsCustomizeHelper(animated, springLoaded, contentType); |
| 3077 | } |
| 3078 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, |
| 3079 | final AppsCustomizePagedView.ContentType contentType) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3080 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3081 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3082 | mStateAnimation.cancel(); |
| 3083 | mStateAnimation = null; |
| 3084 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3085 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3086 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3087 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); |
| 3088 | final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); |
| 3089 | final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3090 | final View fromView = mWorkspace; |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3091 | final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 3092 | final int startDelay = |
| 3093 | res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3094 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3095 | setPivotsForZoom(toView, scale); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3096 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3097 | // Shrink workspaces away if going to AppsCustomize from workspace |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3098 | Animator workspaceAnim = |
| 3099 | mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3100 | if (!LauncherAppState.isDisableAllApps() |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 3101 | || contentType == AppsCustomizePagedView.ContentType.Widgets) { |
| 3102 | // Set the content type for the all apps/widgets space |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3103 | mAppsCustomizeTabHost.setContentTypeImmediate(contentType); |
| 3104 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3105 | |
| 3106 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3107 | toView.setScaleX(scale); |
| 3108 | toView.setScaleY(scale); |
| 3109 | final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView); |
| 3110 | scaleAnim. |
| 3111 | scaleX(1f).scaleY(1f). |
| 3112 | setDuration(duration). |
| 3113 | setInterpolator(new Workspace.ZoomOutInterpolator()); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 3114 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3115 | toView.setVisibility(View.VISIBLE); |
Adam Cohen | c00f0b9 | 2011-12-06 19:45:06 -0800 | [diff] [blame] | 3116 | toView.setAlpha(0f); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3117 | final ObjectAnimator alphaAnim = LauncherAnimUtils |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3118 | .ofFloat(toView, "alpha", 0f, 1f) |
| 3119 | .setDuration(fadeDuration); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3120 | alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3121 | alphaAnim.addUpdateListener(new AnimatorUpdateListener() { |
| 3122 | @Override |
| 3123 | public void onAnimationUpdate(ValueAnimator animation) { |
Michael Jurka | 059798a | 2012-09-04 09:20:16 -0700 | [diff] [blame] | 3124 | if (animation == null) { |
| 3125 | throw new RuntimeException("animation is null"); |
| 3126 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3127 | float t = (Float) animation.getAnimatedValue(); |
| 3128 | dispatchOnLauncherTransitionStep(fromView, t); |
| 3129 | dispatchOnLauncherTransitionStep(toView, t); |
| 3130 | } |
| 3131 | }); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3132 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3133 | // toView should appear right at the end of the workspace shrink |
| 3134 | // animation |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3135 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3136 | mStateAnimation.play(scaleAnim).after(startDelay); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3137 | mStateAnimation.play(alphaAnim).after(startDelay); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3138 | |
| 3139 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3140 | @Override |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 3141 | public void onAnimationStart(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3142 | // Prepare the position |
| 3143 | toView.setTranslationX(0.0f); |
| 3144 | toView.setTranslationY(0.0f); |
| 3145 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3146 | toView.bringToFront(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3147 | } |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 3148 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3149 | public void onAnimationEnd(Animator animation) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3150 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 3151 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Winson Chung | 32174c8 | 2011-07-19 15:47:55 -0700 | [diff] [blame] | 3152 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3153 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3154 | if (mSearchDropTargetBar != null) { |
| 3155 | mSearchDropTargetBar.hideSearchBar(false); |
| 3156 | } |
Adam Cohen | f4ddea3 | 2011-09-12 13:46:42 -0700 | [diff] [blame] | 3157 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3158 | }); |
| 3159 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3160 | if (workspaceAnim != null) { |
| 3161 | mStateAnimation.play(workspaceAnim); |
| 3162 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3163 | |
| 3164 | boolean delayAnim = false; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3165 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3166 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
| 3167 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3168 | |
| 3169 | // If any of the objects being animated haven't been measured/laid out |
| 3170 | // yet, delay the animation until we get a layout pass |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3171 | if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3172 | (mWorkspace.getMeasuredWidth() == 0) || |
| 3173 | (toView.getMeasuredWidth() == 0)) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3174 | delayAnim = true; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3175 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3176 | |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3177 | final AnimatorSet stateAnimation = mStateAnimation; |
| 3178 | final Runnable startAnimRunnable = new Runnable() { |
| 3179 | public void run() { |
| 3180 | // Check that mStateAnimation hasn't changed while |
| 3181 | // we waited for a layout/draw pass |
| 3182 | if (mStateAnimation != stateAnimation) |
| 3183 | return; |
| 3184 | setPivotsForZoom(toView, scale); |
| 3185 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3186 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3187 | LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView); |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3188 | } |
| 3189 | }; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3190 | if (delayAnim) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3191 | final ViewTreeObserver observer = toView.getViewTreeObserver(); |
| 3192 | observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { |
| 3193 | public void onGlobalLayout() { |
| 3194 | startAnimRunnable.run(); |
| 3195 | toView.getViewTreeObserver().removeOnGlobalLayoutListener(this); |
| 3196 | } |
| 3197 | }); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3198 | } else { |
Michael Jurka | 3dcd79e | 2012-05-31 07:50:33 -0700 | [diff] [blame] | 3199 | startAnimRunnable.run(); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 3200 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3201 | } else { |
| 3202 | toView.setTranslationX(0.0f); |
| 3203 | toView.setTranslationY(0.0f); |
| 3204 | toView.setScaleX(1.0f); |
| 3205 | toView.setScaleY(1.0f); |
| 3206 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3207 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 3208 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3209 | if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3210 | // Hide the search bar |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3211 | if (mSearchDropTargetBar != null) { |
| 3212 | mSearchDropTargetBar.hideSearchBar(false); |
| 3213 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3214 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3215 | dispatchOnLauncherTransitionPrepare(fromView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3216 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 3217 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3218 | dispatchOnLauncherTransitionPrepare(toView, animated, false); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3219 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 3220 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3221 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | /** |
| 3225 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3226 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3227 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3228 | */ |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3229 | private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3230 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3231 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3232 | if (mStateAnimation != null) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3233 | mStateAnimation.setDuration(0); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3234 | mStateAnimation.cancel(); |
| 3235 | mStateAnimation = null; |
| 3236 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3237 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 3238 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3239 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3240 | final int fadeOutDuration = |
| 3241 | res.getInteger(R.integer.config_appsCustomizeFadeOutTime); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3242 | final float scaleFactor = (float) |
| 3243 | res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
| 3244 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3245 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3246 | Animator workspaceAnim = null; |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3247 | if (toState == Workspace.State.NORMAL) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3248 | int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger); |
| 3249 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3250 | toState, animated, stagger, -1); |
| 3251 | } else if (toState == Workspace.State.SPRING_LOADED || |
| 3252 | toState == Workspace.State.OVERVIEW) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3253 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3254 | toState, animated); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3255 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3256 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3257 | setPivotsForZoom(fromView, scaleFactor); |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3258 | showHotseat(animated); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3259 | if (animated) { |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3260 | final LauncherViewPropertyAnimator scaleAnim = |
| 3261 | new LauncherViewPropertyAnimator(fromView); |
| 3262 | scaleAnim. |
| 3263 | scaleX(scaleFactor).scaleY(scaleFactor). |
| 3264 | setDuration(duration). |
| 3265 | setInterpolator(new Workspace.ZoomInInterpolator()); |
| 3266 | |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3267 | final ObjectAnimator alphaAnim = LauncherAnimUtils |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3268 | .ofFloat(fromView, "alpha", 1f, 0f) |
| 3269 | .setDuration(fadeOutDuration); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 3270 | alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator()); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3271 | alphaAnim.addUpdateListener(new AnimatorUpdateListener() { |
| 3272 | @Override |
| 3273 | public void onAnimationUpdate(ValueAnimator animation) { |
| 3274 | float t = 1f - (Float) animation.getAnimatedValue(); |
| 3275 | dispatchOnLauncherTransitionStep(fromView, t); |
| 3276 | dispatchOnLauncherTransitionStep(toView, t); |
| 3277 | } |
| 3278 | }); |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 3279 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 3280 | mStateAnimation = LauncherAnimUtils.createAnimatorSet(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3281 | |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3282 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
| 3283 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Adam Cohen | 4fe4c93 | 2013-10-28 16:02:34 -0700 | [diff] [blame] | 3284 | mAppsCustomizeContent.stopScrolling(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3285 | |
| 3286 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 3287 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 3288 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3289 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3290 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 3291 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3292 | if (onCompleteRunnable != null) { |
| 3293 | onCompleteRunnable.run(); |
| 3294 | } |
Chet Haase | bc2f082 | 2012-10-26 17:59:53 -0700 | [diff] [blame] | 3295 | mAppsCustomizeContent.updateCurrentPageScroll(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3296 | } |
| 3297 | }); |
| 3298 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3299 | mStateAnimation.playTogether(scaleAnim, alphaAnim); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3300 | if (workspaceAnim != null) { |
| 3301 | mStateAnimation.play(workspaceAnim); |
| 3302 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3303 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3304 | dispatchOnLauncherTransitionStart(toView, animated, true); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 3305 | LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3306 | } else { |
| 3307 | fromView.setVisibility(View.GONE); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3308 | dispatchOnLauncherTransitionPrepare(fromView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3309 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 3310 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 3311 | dispatchOnLauncherTransitionPrepare(toView, animated, true); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3312 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 3313 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 3314 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3317 | @Override |
| 3318 | public void onTrimMemory(int level) { |
| 3319 | super.onTrimMemory(level); |
Winson Chung | c7450e3 | 2012-04-17 17:34:08 -0700 | [diff] [blame] | 3320 | if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) { |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 3321 | mAppsCustomizeTabHost.onTrimMemory(); |
| 3322 | } |
| 3323 | } |
| 3324 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3325 | protected void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3326 | showWorkspace(animated, null); |
| 3327 | } |
| 3328 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3329 | protected void showWorkspace() { |
| 3330 | showWorkspace(true); |
| 3331 | } |
| 3332 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3333 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3334 | if (mWorkspace.isInOverviewMode()) { |
| 3335 | mWorkspace.exitOverviewMode(animated); |
| 3336 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3337 | if (mState != State.WORKSPACE) { |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 3338 | boolean wasInSpringLoadedMode = (mState != State.WORKSPACE); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3339 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3340 | hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3341 | |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3342 | // Show the search bar (only animate if we were showing the drop target bar in spring |
| 3343 | // loaded mode) |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3344 | if (mSearchDropTargetBar != null) { |
Winson Chung | 04c0a5c | 2013-10-08 17:13:12 -0700 | [diff] [blame] | 3345 | mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3346 | } |
Winson Chung | c7d2b60 | 2012-05-16 17:02:20 -0700 | [diff] [blame] | 3347 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3348 | // Set focus to the AppsCustomize button |
| 3349 | if (mAllAppsButton != null) { |
| 3350 | mAllAppsButton.requestFocus(); |
| 3351 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3352 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 3353 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3354 | // Change the state *after* we've called all the transition code |
| 3355 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 3356 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3357 | // Resume the auto-advance of widgets |
| 3358 | mUserPresent = true; |
| 3359 | updateRunning(); |
| 3360 | |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3361 | // Send an accessibility event to announce the context change |
| 3362 | getWindow().getDecorView() |
| 3363 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3364 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3365 | onWorkspaceShown(animated); |
Bjorn Bringert | c459e52 | 2013-06-07 19:36:01 +0100 | [diff] [blame] | 3366 | } |
| 3367 | |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3368 | void showOverviewMode(boolean animated) { |
| 3369 | mWorkspace.setVisibility(View.VISIBLE); |
| 3370 | hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null); |
| 3371 | mState = State.WORKSPACE; |
| 3372 | onWorkspaceShown(animated); |
| 3373 | } |
| 3374 | |
Bjorn Bringert | 69688aa | 2013-06-11 20:26:38 +0100 | [diff] [blame] | 3375 | public void onWorkspaceShown(boolean animated) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3376 | } |
| 3377 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3378 | void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType, |
| 3379 | boolean resetPageToZero) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3380 | if (mState != State.WORKSPACE) return; |
| 3381 | |
Winson Chung | 82963d5 | 2013-10-09 11:20:57 -0700 | [diff] [blame] | 3382 | if (resetPageToZero) { |
| 3383 | mAppsCustomizeTabHost.reset(); |
| 3384 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3385 | showAppsCustomizeHelper(animated, false, contentType); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3386 | mAppsCustomizeTabHost.requestFocus(); |
| 3387 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3388 | // Change the state *after* we've called all the transition code |
| 3389 | mState = State.APPS_CUSTOMIZE; |
| 3390 | |
| 3391 | // Pause the auto-advance of widgets until we are out of AllApps |
| 3392 | mUserPresent = false; |
| 3393 | updateRunning(); |
| 3394 | closeFolder(); |
| 3395 | |
| 3396 | // Send an accessibility event to announce the context change |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3397 | getWindow().getDecorView() |
| 3398 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3401 | void enterSpringLoadedDragMode() { |
Winson Chung | c93e5ae | 2012-07-23 20:48:26 -0700 | [diff] [blame] | 3402 | if (isAllAppsVisible()) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 3403 | hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3404 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3405 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3406 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3407 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3408 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3409 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 3410 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 3411 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 3412 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3413 | @Override |
| 3414 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3415 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 3416 | // Before we show workspace, hide all apps again because |
| 3417 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 3418 | // clean up our state transition functions |
| 3419 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3420 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 3421 | } else { |
| 3422 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 3423 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3424 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3425 | }, delay); |
| 3426 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3427 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3428 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3429 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3430 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3431 | final boolean animated = true; |
| 3432 | final boolean springLoaded = true; |
| 3433 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3434 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3435 | } |
| 3436 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 3437 | } |
| 3438 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 3439 | void lockAllApps() { |
| 3440 | // TODO |
| 3441 | } |
| 3442 | |
| 3443 | void unlockAllApps() { |
| 3444 | // TODO |
| 3445 | } |
| 3446 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3447 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3448 | * Shows the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3449 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3450 | void showHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3451 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3452 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3453 | if (mHotseat.getAlpha() != 1f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3454 | int duration = 0; |
| 3455 | if (mSearchDropTargetBar != null) { |
| 3456 | duration = mSearchDropTargetBar.getTransitionInDuration(); |
| 3457 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3458 | mHotseat.animate().alpha(1f).setDuration(duration); |
| 3459 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3460 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3461 | mHotseat.setAlpha(1f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3462 | } |
| 3463 | } |
| 3464 | } |
| 3465 | |
| 3466 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3467 | * Hides the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3468 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3469 | void hideHotseat(boolean animated) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 3470 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3471 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3472 | if (mHotseat.getAlpha() != 0f) { |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 3473 | int duration = 0; |
| 3474 | if (mSearchDropTargetBar != null) { |
| 3475 | duration = mSearchDropTargetBar.getTransitionOutDuration(); |
| 3476 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 3477 | mHotseat.animate().alpha(0f).setDuration(duration); |
| 3478 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3479 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3480 | mHotseat.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3481 | } |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3482 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3483 | } |
| 3484 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3485 | /** |
| 3486 | * Add an item from all apps or customize onto the given workspace screen. |
| 3487 | * If layout is null, add to the current screen. |
| 3488 | */ |
| 3489 | void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3490 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 3491 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 3492 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3493 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3494 | |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3495 | /** Maps the current orientation to an index for referencing orientation correct global icons */ |
| 3496 | private int getCurrentOrientationIndexForGlobalIcons() { |
| 3497 | // default - 0, landscape - 1 |
| 3498 | switch (getResources().getConfiguration().orientation) { |
| 3499 | case Configuration.ORIENTATION_LANDSCAPE: |
| 3500 | return 1; |
| 3501 | default: |
| 3502 | return 0; |
| 3503 | } |
| 3504 | } |
| 3505 | |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3506 | private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3507 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3508 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3509 | // Look for the toolbar icon specified in the activity meta-data |
| 3510 | Bundle metaData = packageManager.getActivityInfo( |
| 3511 | activityName, PackageManager.GET_META_DATA).metaData; |
| 3512 | if (metaData != null) { |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3513 | int iconResId = metaData.getInt(resourceName); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3514 | if (iconResId != 0) { |
| 3515 | Resources res = packageManager.getResourcesForActivity(activityName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3516 | return res.getDrawable(iconResId); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | } catch (NameNotFoundException e) { |
Michael Jurka | b6052a9 | 2011-07-12 17:02:45 -0700 | [diff] [blame] | 3520 | // This can happen if the activity defines an invalid drawable |
| 3521 | Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + |
| 3522 | " not found", e); |
Mathew Inwood | 70d5102 | 2011-07-12 13:41:41 +0100 | [diff] [blame] | 3523 | } catch (Resources.NotFoundException nfe) { |
| 3524 | // This can happen if the activity defines an invalid drawable |
| 3525 | Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), |
| 3526 | nfe); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3527 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3528 | return null; |
| 3529 | } |
| 3530 | |
| 3531 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3532 | private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3533 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 3534 | String toolbarResourceName) { |
| 3535 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3536 | Resources r = getResources(); |
| 3537 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 3538 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3539 | |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3540 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3541 | // If we were unable to find the icon via the meta-data, use a generic one |
| 3542 | if (toolbarIcon == null) { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3543 | toolbarIcon = r.getDrawable(fallbackDrawableId); |
| 3544 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3545 | if (button != null) { |
| 3546 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 3547 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3548 | return null; |
| 3549 | } else { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 3550 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 3551 | if (button != null) { |
| 3552 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 3553 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3554 | return toolbarIcon.getConstantState(); |
| 3555 | } |
| 3556 | } |
| 3557 | |
| 3558 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3559 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3560 | int buttonId, ComponentName activityName, int fallbackDrawableId, |
| 3561 | String toolbarResourceName) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3562 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3563 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3564 | |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 3565 | if (button != null) { |
| 3566 | // If we were unable to find the icon via the meta-data, use a |
| 3567 | // generic one |
| 3568 | if (toolbarIcon == null) { |
| 3569 | button.setImageResource(fallbackDrawableId); |
| 3570 | } else { |
| 3571 | button.setImageDrawable(toolbarIcon); |
| 3572 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3573 | } |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 3574 | |
| 3575 | return toolbarIcon != null ? toolbarIcon.getConstantState() : null; |
| 3576 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3577 | } |
| 3578 | |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3579 | private void updateTextButtonWithDrawable(int buttonId, Drawable d) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3580 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3581 | button.setCompoundDrawables(d, null, null, null); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3582 | } |
| 3583 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3584 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3585 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3586 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3587 | } |
| 3588 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3589 | private void invalidatePressedFocusedStates(View container, View button) { |
| 3590 | if (container instanceof HolographicLinearLayout) { |
| 3591 | HolographicLinearLayout layout = (HolographicLinearLayout) container; |
| 3592 | layout.invalidatePressedFocusedStates(); |
| 3593 | } else if (button instanceof HolographicImageView) { |
| 3594 | HolographicImageView view = (HolographicImageView) button; |
| 3595 | view.invalidatePressedFocusedStates(); |
| 3596 | } |
| 3597 | } |
| 3598 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3599 | public View getQsbBar() { |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3600 | if (mQsb == null) { |
| 3601 | mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false); |
| 3602 | mSearchDropTargetBar.addView(mQsb); |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3603 | } |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 3604 | return mQsb; |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | protected boolean updateGlobalSearchIcon() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3608 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3609 | final ImageView searchButton = (ImageView) findViewById(R.id.search_button); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3610 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 3611 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3612 | |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3613 | final SearchManager searchManager = |
| 3614 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3615 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 3616 | if (activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3617 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3618 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3619 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 3620 | TOOLBAR_SEARCH_ICON_METADATA_NAME); |
| 3621 | if (sGlobalSearchIcon[coi] == null) { |
| 3622 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 3623 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, |
| 3624 | TOOLBAR_ICON_METADATA_NAME); |
| 3625 | } |
| 3626 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3627 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); |
| 3628 | searchButton.setVisibility(View.VISIBLE); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3629 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3630 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3631 | } else { |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 3632 | // 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] | 3633 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); |
| 3634 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 3635 | if (searchButton != null) searchButton.setVisibility(View.GONE); |
| 3636 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3637 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3638 | return false; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3639 | } |
| 3640 | } |
| 3641 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3642 | protected void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3643 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
| 3644 | final View searchButton = (ImageView) findViewById(R.id.search_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3645 | updateButtonWithDrawable(R.id.search_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3646 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3647 | } |
| 3648 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3649 | protected boolean updateVoiceSearchIcon(boolean searchVisible) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3650 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3651 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3652 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3653 | // 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] | 3654 | final SearchManager searchManager = |
| 3655 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3656 | ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); |
| 3657 | |
| 3658 | ComponentName activityName = null; |
| 3659 | if (globalSearchActivity != null) { |
| 3660 | // Check if the global search activity handles voice search |
| 3661 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3662 | intent.setPackage(globalSearchActivity.getPackageName()); |
| 3663 | activityName = intent.resolveActivity(getPackageManager()); |
| 3664 | } |
| 3665 | |
| 3666 | if (activityName == null) { |
| 3667 | // Fallback: check if an activity other than the global search activity |
| 3668 | // resolves this |
| 3669 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3670 | activityName = intent.resolveActivity(getPackageManager()); |
| 3671 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3672 | if (searchVisible && activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 3673 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3674 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Michael Jurka | ae65ee3 | 2012-04-30 11:45:54 -0700 | [diff] [blame] | 3675 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 3676 | TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); |
| 3677 | if (sVoiceSearchIcon[coi] == null) { |
| 3678 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
| 3679 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, |
| 3680 | TOOLBAR_ICON_METADATA_NAME); |
| 3681 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3682 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3683 | voiceButton.setVisibility(View.VISIBLE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3684 | updateVoiceButtonProxyVisible(false); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3685 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3686 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 3687 | } else { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3688 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
John Spurlock | 2c38e70 | 2013-09-18 10:48:25 -0400 | [diff] [blame] | 3689 | if (voiceButton != null) voiceButton.setVisibility(View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3690 | updateVoiceButtonProxyVisible(false); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3691 | return false; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3692 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3693 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3694 | |
Cristina Stancu | 476493b | 2013-08-07 17:20:14 +0100 | [diff] [blame] | 3695 | protected void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3696 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
| 3697 | final View voiceButton = findViewById(R.id.voice_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3698 | updateButtonWithDrawable(R.id.voice_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 3699 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3700 | } |
| 3701 | |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3702 | public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) { |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3703 | final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); |
| 3704 | if (voiceButtonProxy != null) { |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3705 | boolean visible = !forceDisableVoiceButtonProxy && |
| 3706 | mWorkspace.shouldVoiceButtonProxyBeVisible(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3707 | voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE); |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3708 | voiceButtonProxy.bringToFront(); |
Bjorn Bringert | ecf33e4 | 2013-06-11 15:46:07 +0100 | [diff] [blame] | 3709 | } |
| 3710 | } |
Winson Chung | 5841efa | 2013-09-30 18:06:44 -0700 | [diff] [blame] | 3711 | |
| 3712 | /** |
| 3713 | * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy |
| 3714 | * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns. |
| 3715 | */ |
| 3716 | public void disableVoiceButtonProxy(boolean disabled) { |
| 3717 | updateVoiceButtonProxyVisible(disabled); |
| 3718 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3719 | /** |
Winson Chung | eb66b14 | 2011-06-16 13:14:22 -0700 | [diff] [blame] | 3720 | * Sets the app market icon |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3721 | */ |
| 3722 | private void updateAppMarketIcon() { |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 3723 | if (!DISABLE_MARKET_BUTTON) { |
| 3724 | final View marketButton = findViewById(R.id.market_button); |
| 3725 | Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); |
| 3726 | // Find the app market activity by resolving an intent. |
| 3727 | // (If multiple app markets are installed, it will return the ResolverActivity.) |
| 3728 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
| 3729 | if (activityName != null) { |
| 3730 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 3731 | mAppMarketIntent = intent; |
| 3732 | sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity( |
| 3733 | R.id.market_button, activityName, R.drawable.ic_launcher_market_holo, |
| 3734 | TOOLBAR_ICON_METADATA_NAME); |
| 3735 | marketButton.setVisibility(View.VISIBLE); |
| 3736 | } else { |
| 3737 | // We should hide and disable the view so that we don't try and restore the visibility |
| 3738 | // of it when we swap between drag & normal states from IconDropTarget subclasses. |
| 3739 | marketButton.setVisibility(View.GONE); |
| 3740 | marketButton.setEnabled(false); |
| 3741 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3742 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3745 | private void updateAppMarketIcon(Drawable.ConstantState d) { |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 3746 | if (!DISABLE_MARKET_BUTTON) { |
| 3747 | // Ensure that the new drawable we are creating has the approprate toolbar icon bounds |
| 3748 | Resources r = getResources(); |
| 3749 | Drawable marketIconDrawable = d.newDrawable(r); |
| 3750 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 3751 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
| 3752 | marketIconDrawable.setBounds(0, 0, w, h); |
Winson Chung | 1b88409 | 2012-06-08 17:13:02 -0700 | [diff] [blame] | 3753 | |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 3754 | updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable); |
| 3755 | } |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3756 | } |
| 3757 | |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3758 | @Override |
| 3759 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3760 | final boolean result = super.dispatchPopulateAccessibilityEvent(event); |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3761 | final List<CharSequence> text = event.getText(); |
| 3762 | text.clear(); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3763 | // Populate event with a fake title based on the current state. |
| 3764 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | 4b37887 | 2013-10-04 18:58:04 -0700 | [diff] [blame] | 3765 | text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription()); |
alanv | 1d4fde6 | 2012-10-17 13:15:47 -0700 | [diff] [blame] | 3766 | } else { |
| 3767 | text.add(getString(R.string.all_apps_home_button_label)); |
| 3768 | } |
Michael Jurka | d7c2805 | 2012-04-27 15:43:36 -0700 | [diff] [blame] | 3769 | return result; |
| 3770 | } |
| 3771 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3772 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 3773 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3774 | */ |
| 3775 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 3776 | @Override |
| 3777 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3778 | closeSystemDialogs(); |
| 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 3783 | * Receives notifications whenever the appwidgets are reset. |
| 3784 | */ |
| 3785 | private class AppWidgetResetObserver extends ContentObserver { |
| 3786 | public AppWidgetResetObserver() { |
| 3787 | super(new Handler()); |
| 3788 | } |
| 3789 | |
| 3790 | @Override |
| 3791 | public void onChange(boolean selfChange) { |
| 3792 | onAppWidgetReset(); |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | /** |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3797 | * If the activity is currently paused, signal that we need to run the passed Runnable |
| 3798 | * in onResume. |
| 3799 | * |
| 3800 | * This needs to be called from incoming places where resources might have been loaded |
| 3801 | * while we are paused. That is becaues the Configuration might be wrong |
| 3802 | * when we're not running, and if it comes back to what it was when we |
| 3803 | * were paused, we are not restarted. |
| 3804 | * |
| 3805 | * Implementation of the method from LauncherModel.Callbacks. |
| 3806 | * |
| 3807 | * @return true if we are currently paused. The caller might be able to |
| 3808 | * skip some work in that case since we will come back again. |
| 3809 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3810 | private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3811 | if (mPaused) { |
| 3812 | Log.i(TAG, "Deferring update until onResume"); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3813 | if (deletePreviousRunnables) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3814 | while (mBindOnResumeCallbacks.remove(run)) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3815 | } |
| 3816 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3817 | mBindOnResumeCallbacks.add(run); |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3818 | return true; |
| 3819 | } else { |
| 3820 | return false; |
| 3821 | } |
| 3822 | } |
| 3823 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 3824 | private boolean waitUntilResume(Runnable run) { |
| 3825 | return waitUntilResume(run, false); |
| 3826 | } |
| 3827 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3828 | public void addOnResumeCallback(Runnable run) { |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 3829 | mOnResumeCallbacks.add(run); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3830 | } |
| 3831 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3832 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3833 | * If the activity is currently paused, signal that we need to re-run the loader |
| 3834 | * in onResume. |
| 3835 | * |
| 3836 | * This needs to be called from incoming places where resources might have been loaded |
| 3837 | * while we are paused. That is becaues the Configuration might be wrong |
| 3838 | * when we're not running, and if it comes back to what it was when we |
| 3839 | * were paused, we are not restarted. |
| 3840 | * |
| 3841 | * Implementation of the method from LauncherModel.Callbacks. |
| 3842 | * |
| 3843 | * @return true if we are currently paused. The caller might be able to |
| 3844 | * skip some work in that case since we will come back again. |
| 3845 | */ |
| 3846 | public boolean setLoadOnResume() { |
| 3847 | if (mPaused) { |
| 3848 | Log.i(TAG, "setLoadOnResume"); |
| 3849 | mOnResumeNeedsLoad = true; |
| 3850 | return true; |
| 3851 | } else { |
| 3852 | return false; |
| 3853 | } |
| 3854 | } |
| 3855 | |
| 3856 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3857 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3858 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3859 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3860 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3861 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3862 | } else { |
| 3863 | return SCREEN_COUNT / 2; |
| 3864 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3865 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3866 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3867 | /** |
| 3868 | * Refreshes the shortcuts shown on the workspace. |
| 3869 | * |
| 3870 | * Implementation of the method from LauncherModel.Callbacks. |
| 3871 | */ |
| 3872 | public void startBinding() { |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 3873 | setWorkspaceLoading(true); |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 3874 | |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3875 | // If we're starting binding all over again, clear any bind calls we'd postponed in |
| 3876 | // the past (see waitUntilResume) -- we don't need them since we're starting binding |
| 3877 | // from scratch again |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3878 | mBindOnResumeCallbacks.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3879 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3880 | // Clear the workspace because it's going to be rebound |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3881 | mWorkspace.clearDropTargets(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 3882 | mWorkspace.removeAllWorkspaceScreens(); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3883 | |
Michael Jurka | 05bf644e | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 3884 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3885 | if (mHotseat != null) { |
| 3886 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3887 | } |
| 3888 | } |
| 3889 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3890 | @Override |
| 3891 | public void bindScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3892 | bindAddScreens(orderedScreenIds); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 3893 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 3894 | // If there are no screens, we need to have an empty screen |
| 3895 | if (orderedScreenIds.size() == 0) { |
| 3896 | mWorkspace.addExtraEmptyScreen(); |
| 3897 | } |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 3898 | |
| 3899 | // Create the custom content page (this call updates mDefaultScreen which calls |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 3900 | // setCurrentPage() so ensure that all pages are added before calling this). |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 3901 | if (hasCustomContentToLeft()) { |
| 3902 | mWorkspace.createCustomContentContainer(); |
| 3903 | populateCustomContentContainer(); |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 3904 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | @Override |
| 3908 | public void bindAddScreens(ArrayList<Long> orderedScreenIds) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 3909 | // Log to disk |
| 3910 | Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); |
| 3911 | Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + |
| 3912 | TextUtils.join(", ", orderedScreenIds), true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3913 | int count = orderedScreenIds.size(); |
| 3914 | for (int i = 0; i < count; i++) { |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 3915 | mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3916 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3917 | } |
| 3918 | |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 3919 | private boolean shouldShowWeightWatcher() { |
| 3920 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 3921 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
Daniel Sandler | 6053b800 | 2013-08-15 15:44:26 -0700 | [diff] [blame] | 3922 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT); |
Adam Cohen | 39a0604 | 2013-07-19 14:30:12 -0700 | [diff] [blame] | 3923 | |
| 3924 | return show; |
| 3925 | } |
| 3926 | |
| 3927 | private void toggleShowWeightWatcher() { |
| 3928 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 3929 | SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 3930 | boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true); |
| 3931 | |
| 3932 | show = !show; |
| 3933 | |
| 3934 | SharedPreferences.Editor editor = sp.edit(); |
| 3935 | editor.putBoolean(SHOW_WEIGHT_WATCHER, show); |
| 3936 | editor.commit(); |
| 3937 | |
| 3938 | if (mWeightWatcher != null) { |
| 3939 | mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE); |
| 3940 | } |
| 3941 | } |
| 3942 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3943 | public void bindAppsAdded(final ArrayList<Long> newScreens, |
| 3944 | final ArrayList<ItemInfo> addNotAnimated, |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3945 | final ArrayList<ItemInfo> addAnimated, |
| 3946 | final ArrayList<AppInfo> addedApps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3947 | Runnable r = new Runnable() { |
| 3948 | public void run() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3949 | bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps); |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3950 | } |
| 3951 | }; |
| 3952 | if (waitUntilResume(r)) { |
| 3953 | return; |
| 3954 | } |
| 3955 | |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3956 | // Add the new screens |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 3957 | if (newScreens != null) { |
| 3958 | bindAddScreens(newScreens); |
| 3959 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3960 | |
| 3961 | // We add the items without animation on non-visible pages, and with |
| 3962 | // animations on the new page (which we will try and snap to). |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 3963 | if (addNotAnimated != null && !addNotAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3964 | bindItems(addNotAnimated, 0, |
| 3965 | addNotAnimated.size(), false); |
| 3966 | } |
Adam Cohen | 76a47a1 | 2014-02-05 11:47:43 -0800 | [diff] [blame] | 3967 | if (addAnimated != null && !addAnimated.isEmpty()) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3968 | bindItems(addAnimated, 0, |
| 3969 | addAnimated.size(), true); |
| 3970 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3971 | |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 3972 | // Remove the extra empty screen |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 3973 | mWorkspace.removeExtraEmptyScreen(false, false); |
Winson Chung | 8741298 | 2013-10-03 18:34:14 -0700 | [diff] [blame] | 3974 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 3975 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 3976 | addedApps != null && mAppsCustomizeContent != null) { |
| 3977 | mAppsCustomizeContent.addApps(addedApps); |
| 3978 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3979 | } |
| 3980 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3981 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3982 | * Bind the items start-end from the list. |
| 3983 | * |
| 3984 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3985 | */ |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 3986 | public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, |
| 3987 | final boolean forceAnimateIcons) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 3988 | Runnable r = new Runnable() { |
| 3989 | public void run() { |
| 3990 | bindItems(shortcuts, start, end, forceAnimateIcons); |
| 3991 | } |
| 3992 | }; |
| 3993 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 3994 | return; |
| 3995 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3996 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3997 | // 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] | 3998 | final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 3999 | final Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4000 | final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4001 | Workspace workspace = mWorkspace; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4002 | long newShortcutsScreenId = -1; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4003 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4004 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 4005 | |
| 4006 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 4007 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 4008 | mHotseat == null) { |
| 4009 | continue; |
| 4010 | } |
| 4011 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4012 | switch (item.itemType) { |
| 4013 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 4014 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4015 | ShortcutInfo info = (ShortcutInfo) item; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4016 | View shortcut = createShortcut(info); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4017 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4018 | /* |
| 4019 | * TODO: FIX collision case |
| 4020 | */ |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4021 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 4022 | CellLayout cl = mWorkspace.getScreenWithId(item.screenId); |
| 4023 | if (cl != null && cl.isOccupied(item.cellX, item.cellY)) { |
Adam Cohen | 8f006ed | 2014-04-03 18:12:34 -0700 | [diff] [blame] | 4024 | View v = cl.getChildAt(item.cellX, item.cellY); |
| 4025 | Object tag = v.getTag(); |
| 4026 | String desc = "Collision while binding workspace item: " + item |
| 4027 | + ". Collides with " + tag; |
| 4028 | if (LauncherAppState.isDogfoodBuild()) { |
| 4029 | throw (new RuntimeException(desc)); |
| 4030 | } else { |
| 4031 | Log.d(TAG, desc); |
| 4032 | } |
Winson Chung | ce37663 | 2013-07-11 16:12:41 -0700 | [diff] [blame] | 4033 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4034 | } |
| 4035 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4036 | workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, |
| 4037 | item.cellY, 1, 1); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4038 | if (animateIcons) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4039 | // Animate all the applications up now |
| 4040 | shortcut.setAlpha(0f); |
| 4041 | shortcut.setScaleX(0f); |
| 4042 | shortcut.setScaleY(0f); |
| 4043 | bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4044 | newShortcutsScreenId = item.screenId; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4045 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4046 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4047 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4048 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4049 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 4050 | (FolderInfo) item, mIconCache); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4051 | workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, |
| 4052 | item.cellY, 1, 1); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4053 | break; |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 4054 | default: |
| 4055 | throw new RuntimeException("Invalid Item Type"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4056 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4057 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4058 | |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4059 | if (animateIcons) { |
| 4060 | // Animate to the correct page |
| 4061 | if (newShortcutsScreenId > -1) { |
| 4062 | long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4063 | final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4064 | final Runnable startBounceAnimRunnable = new Runnable() { |
| 4065 | public void run() { |
| 4066 | anim.playTogether(bounceAnims); |
| 4067 | anim.start(); |
| 4068 | } |
| 4069 | }; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4070 | if (newShortcutsScreenId != currentScreenId) { |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4071 | // We post the animation slightly delayed to prevent slowdowns |
| 4072 | // when we are loading right after we return to launcher. |
| 4073 | mWorkspace.postDelayed(new Runnable() { |
| 4074 | public void run() { |
Ian Parkinson | 9444915 | 2014-01-21 13:09:59 +0000 | [diff] [blame] | 4075 | if (mWorkspace != null) { |
| 4076 | mWorkspace.snapToPage(newScreenIndex); |
| 4077 | mWorkspace.postDelayed(startBounceAnimRunnable, |
| 4078 | NEW_APPS_ANIMATION_DELAY); |
| 4079 | } |
Winson Chung | 94d6768 | 2013-09-25 16:29:40 -0700 | [diff] [blame] | 4080 | } |
| 4081 | }, NEW_APPS_PAGE_MOVE_DELAY); |
Winson Chung | b232383 | 2013-10-03 15:22:09 -0700 | [diff] [blame] | 4082 | } else { |
| 4083 | mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY); |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 4084 | } |
| 4085 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4086 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4087 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4088 | } |
| 4089 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4090 | /** |
| 4091 | * Implementation of the method from LauncherModel.Callbacks. |
| 4092 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4093 | public void bindFolders(final HashMap<Long, FolderInfo> folders) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4094 | Runnable r = new Runnable() { |
| 4095 | public void run() { |
| 4096 | bindFolders(folders); |
| 4097 | } |
| 4098 | }; |
| 4099 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4100 | return; |
| 4101 | } |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4102 | sFolders.clear(); |
| 4103 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4104 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4105 | |
| 4106 | /** |
| 4107 | * Add the views for a widget to the workspace. |
| 4108 | * |
| 4109 | * Implementation of the method from LauncherModel.Callbacks. |
| 4110 | */ |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4111 | public void bindAppWidget(final LauncherAppWidgetInfo item) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4112 | Runnable r = new Runnable() { |
| 4113 | public void run() { |
| 4114 | bindAppWidget(item); |
| 4115 | } |
| 4116 | }; |
| 4117 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4118 | return; |
| 4119 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 4120 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4121 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 4122 | if (DEBUG_WIDGETS) { |
| 4123 | Log.d(TAG, "bindAppWidget: " + item); |
| 4124 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4125 | final Workspace workspace = mWorkspace; |
| 4126 | |
| 4127 | final int appWidgetId = item.appWidgetId; |
| 4128 | final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4129 | if (DEBUG_WIDGETS) { |
| 4130 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 4131 | } |
| 4132 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4133 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 4134 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4135 | item.hostView.setTag(item); |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 4136 | item.onBindAppWidget(this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4137 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4138 | workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4139 | item.cellY, item.spanX, item.spanY, false); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 4140 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 4141 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4142 | workspace.requestLayout(); |
| 4143 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 4144 | if (DEBUG_WIDGETS) { |
| 4145 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 4146 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 4147 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4148 | } |
| 4149 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4150 | public void onPageBoundSynchronously(int page) { |
| 4151 | mSynchronouslyBoundPages.add(page); |
| 4152 | } |
| 4153 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4154 | /** |
| 4155 | * Callback saying that there aren't any more items to bind. |
| 4156 | * |
| 4157 | * Implementation of the method from LauncherModel.Callbacks. |
| 4158 | */ |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4159 | public void finishBindingItems(final boolean upgradePath) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4160 | Runnable r = new Runnable() { |
| 4161 | public void run() { |
| 4162 | finishBindingItems(upgradePath); |
| 4163 | } |
| 4164 | }; |
| 4165 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4166 | return; |
| 4167 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4168 | if (mSavedState != null) { |
| 4169 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4170 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4171 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4172 | mSavedState = null; |
| 4173 | } |
| 4174 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4175 | mWorkspace.restoreInstanceStateForRemainingPages(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4176 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 4177 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 4178 | // widget configuration forced an orientation change), process them now. |
| 4179 | for (int i = 0; i < sPendingAddList.size(); i++) { |
| 4180 | completeAdd(sPendingAddList.get(i)); |
| 4181 | } |
| 4182 | sPendingAddList.clear(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4183 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4184 | // Update the market app icon as necessary (the other icons will be managed in response to |
| 4185 | // package changes in bindSearchablesChanged() |
Winson Chung | d64a666 | 2013-09-30 11:06:59 -0700 | [diff] [blame] | 4186 | if (!DISABLE_MARKET_BUTTON) { |
| 4187 | updateAppMarketIcon(); |
| 4188 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 4189 | |
Anjali Koppal | ff7ceff | 2014-05-01 18:26:37 -0700 | [diff] [blame] | 4190 | setWorkspaceLoading(false); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4191 | if (upgradePath) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4192 | mWorkspace.getUniqueComponents(true, null); |
| 4193 | mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4194 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
Winson Chung | a0b7e86 | 2013-09-05 16:03:15 -0700 | [diff] [blame] | 4197 | public boolean isAllAppsButtonRank(int rank) { |
| 4198 | if (mHotseat != null) { |
| 4199 | return mHotseat.isAllAppsButtonRank(rank); |
| 4200 | } |
| 4201 | return false; |
| 4202 | } |
| 4203 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 4204 | private boolean canRunNewAppsAnimation() { |
| 4205 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 4206 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 4207 | } |
| 4208 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 4209 | private ValueAnimator createNewAppBounceAnimation(View v, int i) { |
| 4210 | ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v, |
| 4211 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 4212 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 4213 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 4214 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 4215 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 4216 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 4217 | return bounceAnim; |
| 4218 | } |
| 4219 | |
Adam Cohen | 2777273 | 2013-11-11 14:00:56 +0000 | [diff] [blame] | 4220 | public boolean useVerticalBarLayout() { |
| 4221 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4222 | getDeviceProfile().isVerticalBarLayout(); |
| 4223 | } |
| 4224 | |
Mac Duy Hai | 6def4f9 | 2013-11-28 16:17:33 +0000 | [diff] [blame] | 4225 | protected Rect getSearchBarBounds() { |
| 4226 | return LauncherAppState.getInstance().getDynamicGrid(). |
| 4227 | getDeviceProfile().getSearchBarBounds(); |
| 4228 | } |
| 4229 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4230 | @Override |
| 4231 | public void bindSearchablesChanged() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 4232 | boolean searchVisible = updateGlobalSearchIcon(); |
| 4233 | boolean voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | adf0c18 | 2012-08-23 14:59:07 -0700 | [diff] [blame] | 4234 | if (mSearchDropTargetBar != null) { |
| 4235 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
| 4236 | } |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 4237 | } |
| 4238 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 4239 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4240 | * Add the icons for all apps. |
| 4241 | * |
| 4242 | * Implementation of the method from LauncherModel.Callbacks. |
| 4243 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4244 | public void bindAllApplications(final ArrayList<AppInfo> apps) { |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4245 | if (LauncherAppState.isDisableAllApps()) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4246 | if (mIntentsOnWorkspaceFromUpgradePath != null) { |
| 4247 | if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) { |
| 4248 | getHotseat().addAllAppsFolder(mIconCache, apps, |
| 4249 | mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace); |
| 4250 | } |
| 4251 | mIntentsOnWorkspaceFromUpgradePath = null; |
Daniel Sandler | 8707e0f | 2013-08-15 15:54:18 -0700 | [diff] [blame] | 4252 | } |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4253 | if (mAppsCustomizeContent != null) { |
| 4254 | mAppsCustomizeContent.onPackagesUpdated( |
| 4255 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
| 4256 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4257 | } else { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 4258 | if (mAppsCustomizeContent != null) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4259 | mAppsCustomizeContent.setApps(apps); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 4260 | mAppsCustomizeContent.onPackagesUpdated( |
| 4261 | LauncherModel.getSortedWidgetsAndShortcuts(this)); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4262 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4263 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | /** |
| 4267 | * A package was updated. |
| 4268 | * |
| 4269 | * Implementation of the method from LauncherModel.Callbacks. |
| 4270 | */ |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 4271 | public void bindAppsUpdated(final ArrayList<AppInfo> apps) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4272 | Runnable r = new Runnable() { |
| 4273 | public void run() { |
| 4274 | bindAppsUpdated(apps); |
| 4275 | } |
| 4276 | }; |
| 4277 | if (waitUntilResume(r)) { |
Michael Jurka | 7607c2f | 2013-04-03 14:33:19 -0700 | [diff] [blame] | 4278 | return; |
| 4279 | } |
| 4280 | |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 4281 | if (mWorkspace != null) { |
| 4282 | mWorkspace.updateShortcuts(apps); |
| 4283 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4284 | |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4285 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4286 | mAppsCustomizeContent != null) { |
| 4287 | mAppsCustomizeContent.updateApps(apps); |
| 4288 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | /** |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4292 | * Update the state of a package, typically related to install state. |
| 4293 | * |
| 4294 | * Implementation of the method from LauncherModel.Callbacks. |
| 4295 | */ |
| 4296 | public void updatePackageState(String pkgName, int state) { |
| 4297 | if (mWorkspace != null) { |
| 4298 | mWorkspace.updatePackageState(pkgName, state); |
| 4299 | } |
| 4300 | } |
| 4301 | |
| 4302 | /** |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4303 | * A package was uninstalled. We take both the super set of packageNames |
| 4304 | * in addition to specific applications to remove, the reason being that |
| 4305 | * this can be called when a package is updated as well. In that scenario, |
| 4306 | * we only remove specific components from the workspace, where as |
| 4307 | * package-removal should clear all items by package name. |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4308 | * |
| 4309 | * Implementation of the method from LauncherModel.Callbacks. |
| 4310 | */ |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4311 | public void bindComponentsRemoved(final ArrayList<String> packageNames, |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4312 | final ArrayList<AppInfo> appInfos, final UserHandleCompat user) { |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4313 | Runnable r = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4314 | public void run() { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4315 | bindComponentsRemoved(packageNames, appInfos, user); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4316 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 4317 | }; |
| 4318 | if (waitUntilResume(r)) { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4319 | return; |
| 4320 | } |
| 4321 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4322 | if (!packageNames.isEmpty()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4323 | mWorkspace.removeItemsByPackageName(packageNames, user); |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4324 | } |
| 4325 | if (!appInfos.isEmpty()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4326 | mWorkspace.removeItemsByApplicationInfo(appInfos, user); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 4327 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4328 | |
Winson Chung | a182096 | 2011-10-03 16:31:06 -0700 | [diff] [blame] | 4329 | // Notify the drag controller |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4330 | mDragController.onAppsRemoved(packageNames, appInfos); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4331 | |
Winson Chung | df95eb1 | 2013-10-16 14:57:07 -0700 | [diff] [blame] | 4332 | // Update AllApps |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 4333 | if (!LauncherAppState.isDisableAllApps() && |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 4334 | mAppsCustomizeContent != null) { |
| 4335 | mAppsCustomizeContent.removeApps(appInfos); |
| 4336 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 4337 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4338 | |
| 4339 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4340 | * A number of packages were updated. |
| 4341 | */ |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4342 | private ArrayList<Object> mWidgetsAndShortcuts; |
| 4343 | private Runnable mBindPackagesUpdatedRunnable = new Runnable() { |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4344 | public void run() { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4345 | bindPackagesUpdated(mWidgetsAndShortcuts); |
| 4346 | mWidgetsAndShortcuts = null; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4347 | } |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4348 | }; |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4349 | public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { |
| 4350 | if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { |
| 4351 | mWidgetsAndShortcuts = widgetsAndShortcuts; |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4352 | return; |
| 4353 | } |
| 4354 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4355 | // Update the widgets pane |
Nilesh Agrawal | 306c1cf | 2013-12-12 14:56:00 -0800 | [diff] [blame] | 4356 | if (mAppsCustomizeContent != null) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 4357 | mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4358 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4359 | } |
| 4360 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4361 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 4362 | final Display d = getWindowManager().getDefaultDisplay(); |
| 4363 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 4364 | switch (d.getRotation()) { |
| 4365 | case Surface.ROTATION_0: |
| 4366 | case Surface.ROTATION_180: |
| 4367 | // We are currently in the same basic orientation as the natural orientation |
| 4368 | naturalOri = configOri; |
| 4369 | break; |
| 4370 | case Surface.ROTATION_90: |
| 4371 | case Surface.ROTATION_270: |
| 4372 | // We are currently in the other basic orientation to the natural orientation |
| 4373 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 4374 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 4375 | break; |
| 4376 | } |
| 4377 | |
| 4378 | int[] oriMap = { |
| 4379 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 4380 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 4381 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 4382 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 4383 | }; |
| 4384 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 4385 | // is landscape. |
| 4386 | int indexOffset = 0; |
| 4387 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 4388 | indexOffset = 1; |
| 4389 | } |
| 4390 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 4391 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 4392 | |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4393 | public boolean isRotationEnabled() { |
Michael Jurka | 0a457bf | 2012-11-19 14:05:05 -0800 | [diff] [blame] | 4394 | boolean enableRotation = sForceEnableRotation || |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4395 | getResources().getBoolean(R.bool.allow_rotation); |
| 4396 | return enableRotation; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4397 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4398 | public void lockScreenOrientation() { |
| 4399 | if (isRotationEnabled()) { |
| 4400 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 4401 | .getConfiguration().orientation)); |
| 4402 | } |
| 4403 | } |
| 4404 | public void unlockScreenOrientation(boolean immediate) { |
| 4405 | if (isRotationEnabled()) { |
| 4406 | if (immediate) { |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4407 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4408 | } else { |
| 4409 | mHandler.postDelayed(new Runnable() { |
| 4410 | public void run() { |
| 4411 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 4412 | } |
| 4413 | }, mRestoreScreenOrientationDelay); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 4414 | } |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 4415 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 4416 | } |
| 4417 | |
Sandeep Siddhartha | d4d3d08 | 2013-12-26 15:42:52 -0800 | [diff] [blame] | 4418 | /** |
| 4419 | * Called when the SearchBar hint should be changed. |
| 4420 | * |
| 4421 | * @param hint the hint to be displayed in the search bar. |
| 4422 | */ |
| 4423 | protected void onSearchBarHintChanged(String hint) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4424 | mLauncherClings.updateSearchBarHint(hint); |
Sandeep Siddhartha | d4d3d08 | 2013-12-26 15:42:52 -0800 | [diff] [blame] | 4425 | } |
| 4426 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 4427 | protected boolean isLauncherPreinstalled() { |
| 4428 | PackageManager pm = getPackageManager(); |
| 4429 | try { |
| 4430 | ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0); |
| 4431 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4432 | return true; |
| 4433 | } else { |
| 4434 | return false; |
| 4435 | } |
| 4436 | } catch (NameNotFoundException e) { |
| 4437 | e.printStackTrace(); |
| 4438 | return false; |
| 4439 | } |
| 4440 | } |
| 4441 | |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 4442 | protected String getFirstRunClingSearchBarHint() { |
| 4443 | return ""; |
| 4444 | } |
| 4445 | protected String getFirstRunCustomContentHint() { |
| 4446 | return ""; |
| 4447 | } |
Winson Chung | 3a6e7f3 | 2013-10-09 15:50:52 -0700 | [diff] [blame] | 4448 | protected int getFirstRunFocusedHotseatAppDrawableId() { |
| 4449 | return -1; |
| 4450 | } |
| 4451 | protected ComponentName getFirstRunFocusedHotseatAppComponentName() { |
| 4452 | return null; |
| 4453 | } |
| 4454 | protected int getFirstRunFocusedHotseatAppRank() { |
| 4455 | return -1; |
| 4456 | } |
| 4457 | protected String getFirstRunFocusedHotseatAppBubbleTitle() { |
| 4458 | return ""; |
| 4459 | } |
| 4460 | protected String getFirstRunFocusedHotseatAppBubbleDescription() { |
| 4461 | return ""; |
| 4462 | } |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 4463 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 4464 | public void dismissFirstRunCling(View v) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4465 | mLauncherClings.dismissFirstRunCling(v); |
| 4466 | } |
| 4467 | public void dismissMigrationClingCopyApps(View v) { |
| 4468 | mLauncherClings.dismissMigrationClingCopyApps(v); |
| 4469 | } |
| 4470 | public void dismissMigrationClingUseDefault(View v) { |
| 4471 | mLauncherClings.dismissMigrationClingUseDefault(v); |
| 4472 | } |
| 4473 | public void dismissMigrationWorkspaceCling(View v) { |
| 4474 | mLauncherClings.dismissMigrationWorkspaceCling(v); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 4475 | } |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 4476 | public void dismissWorkspaceCling(View v) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4477 | mLauncherClings.dismissWorkspaceCling(v); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 4478 | } |
| 4479 | public void dismissFolderCling(View v) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4480 | mLauncherClings.dismissFolderCling(v); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 4481 | } |
| 4482 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4483 | |
| 4484 | /** |
| 4485 | * To be overridden by subclasses to indicate that there is an activity to launch |
| 4486 | * before showing the standard launcher experience. |
| 4487 | */ |
| 4488 | protected boolean hasFirstRunActivity() { |
| 4489 | return false; |
| 4490 | } |
| 4491 | |
| 4492 | /** |
| 4493 | * To be overridden by subclasses to launch any first run activity |
| 4494 | */ |
| 4495 | protected Intent getFirstRunActivity() { |
| 4496 | return null; |
| 4497 | } |
| 4498 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4499 | private boolean shouldRunFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4500 | return !ActivityManager.isRunningInTestHarness() && |
| 4501 | !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4502 | } |
| 4503 | |
Adam Cohen | 4a9423d | 2014-03-28 14:22:31 -0700 | [diff] [blame] | 4504 | protected boolean hasRunFirstRunActivity() { |
| 4505 | return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false); |
| 4506 | } |
| 4507 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4508 | public boolean showFirstRunActivity() { |
Adam Cohen | bc4539d | 2014-01-14 14:05:32 -0800 | [diff] [blame] | 4509 | if (shouldRunFirstRunActivity() && |
| 4510 | hasFirstRunActivity()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4511 | Intent firstRunIntent = getFirstRunActivity(); |
| 4512 | if (firstRunIntent != null) { |
| 4513 | startActivity(firstRunIntent); |
| 4514 | markFirstRunActivityShown(); |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4515 | return true; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4516 | } |
| 4517 | } |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4518 | return false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4519 | } |
| 4520 | |
| 4521 | private void markFirstRunActivityShown() { |
| 4522 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4523 | editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); |
| 4524 | editor.apply(); |
| 4525 | } |
| 4526 | |
Adam Cohen | 432609a | 2014-03-13 17:03:22 -0700 | [diff] [blame] | 4527 | /** |
| 4528 | * To be overridden by subclasses to indicate that there is an in-activity full-screen intro |
| 4529 | * screen that must be displayed and dismissed. |
| 4530 | */ |
| 4531 | protected boolean hasDismissableIntroScreen() { |
| 4532 | return false; |
| 4533 | } |
| 4534 | |
| 4535 | /** |
| 4536 | * Full screen intro screen to be shown and dismissed before the launcher can be used. |
| 4537 | */ |
| 4538 | protected View getIntroScreen() { |
| 4539 | return null; |
| 4540 | } |
| 4541 | |
| 4542 | /** |
| 4543 | * To be overriden by subclasses to indicate whether the in-activity intro screen has been |
| 4544 | * dismissed. This method is ignored if #hasDismissableIntroScreen returns false. |
| 4545 | */ |
| 4546 | private boolean shouldShowIntroScreen() { |
| 4547 | return hasDismissableIntroScreen() && |
| 4548 | !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false); |
| 4549 | } |
| 4550 | |
| 4551 | protected void showIntroScreen() { |
| 4552 | View introScreen = getIntroScreen(); |
| 4553 | changeWallpaperVisiblity(false); |
| 4554 | if (introScreen != null) { |
| 4555 | mDragLayer.showOverlayView(introScreen); |
| 4556 | } |
| 4557 | } |
| 4558 | |
| 4559 | public void dismissIntroScreen() { |
| 4560 | markIntroScreenDismissed(); |
| 4561 | if (showFirstRunActivity()) { |
| 4562 | // We delay hiding the intro view until the first run activity is showing. This |
| 4563 | // avoids a blip. |
| 4564 | mWorkspace.postDelayed(new Runnable() { |
| 4565 | @Override |
| 4566 | public void run() { |
| 4567 | mDragLayer.dismissOverlayView(); |
| 4568 | } |
| 4569 | }, ACTIVITY_START_DELAY); |
| 4570 | } else { |
| 4571 | mDragLayer.dismissOverlayView(); |
| 4572 | } |
| 4573 | changeWallpaperVisiblity(true); |
| 4574 | } |
| 4575 | |
| 4576 | private void markIntroScreenDismissed() { |
| 4577 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 4578 | editor.putBoolean(INTRO_SCREEN_DISMISSED, true); |
| 4579 | editor.apply(); |
| 4580 | } |
| 4581 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4582 | void showWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4583 | if (mWorkspace != null) mWorkspace.setAlpha(1f); |
| 4584 | if (mHotseat != null) mHotseat.setAlpha(1f); |
| 4585 | if (mPageIndicators != null) mPageIndicators.setAlpha(1f); |
| 4586 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4587 | } |
| 4588 | |
| 4589 | void hideWorkspaceSearchAndHotseat() { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 4590 | if (mWorkspace != null) mWorkspace.setAlpha(0f); |
| 4591 | if (mHotseat != null) mHotseat.setAlpha(0f); |
| 4592 | if (mPageIndicators != null) mPageIndicators.setAlpha(0f); |
| 4593 | if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 4594 | } |
| 4595 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4596 | public ItemInfo createAppDragInfo(Intent appLaunchIntent) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4597 | // Called from search suggestion, not supported in other profiles. |
| 4598 | final UserHandleCompat myUser = UserHandleCompat.myUserHandle(); |
| 4599 | LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); |
| 4600 | LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent, |
| 4601 | myUser); |
| 4602 | if (activityInfo == null) { |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4603 | return null; |
| 4604 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4605 | return new AppInfo(this, activityInfo, myUser, mIconCache, null); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 4609 | Bitmap icon) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4610 | // Called from search suggestion, not supported in other profiles. |
| 4611 | return createShortcutDragInfo(shortcutIntent, caption, icon, |
| 4612 | UserHandleCompat.myUserHandle()); |
| 4613 | } |
| 4614 | |
| 4615 | public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, |
| 4616 | Bitmap icon, UserHandleCompat user) { |
| 4617 | return new ShortcutInfo(shortcutIntent, caption, icon, user); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
Mathew Inwood | b90860a | 2014-04-11 17:17:39 +0100 | [diff] [blame] | 4620 | protected void moveWorkspaceToDefaultScreen() { |
| 4621 | mWorkspace.moveToDefaultScreen(false); |
| 4622 | } |
| 4623 | |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4624 | public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) { |
| 4625 | dragView.setTag(dragInfo); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 4626 | mWorkspace.onExternalDragStartedWithItem(dragView); |
| 4627 | mWorkspace.beginExternalDragShared(dragView, source); |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Anjali Koppal | f5d2913 | 2014-02-28 13:33:27 -0800 | [diff] [blame] | 4630 | @Override |
| 4631 | public void onPageSwitch(View newPage, int newPageIndex) { |
| 4632 | } |
| 4633 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 4634 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4635 | * Prints out out state for debugging. |
| 4636 | */ |
| 4637 | public void dumpState() { |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 4638 | Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 4639 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 4640 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 4641 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 4642 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 4643 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 4644 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4645 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 4646 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 4647 | if (mAppsCustomizeContent != null) { |
| 4648 | mAppsCustomizeContent.dumpState(); |
| 4649 | } |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 4650 | Log.d(TAG, "END launcher3 dump state"); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 4651 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 4652 | |
| 4653 | @Override |
| 4654 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 4655 | super.dump(prefix, fd, writer, args); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4656 | synchronized (sDumpLogs) { |
| 4657 | writer.println(" "); |
| 4658 | writer.println("Debug logs: "); |
| 4659 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 4660 | writer.println(" " + sDumpLogs.get(i)); |
| 4661 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 4662 | } |
| 4663 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 4664 | |
| 4665 | public static void dumpDebugLogsToConsole() { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 4666 | if (DEBUG_DUMP_LOG) { |
| 4667 | synchronized (sDumpLogs) { |
| 4668 | Log.d(TAG, ""); |
| 4669 | Log.d(TAG, "*********************"); |
| 4670 | Log.d(TAG, "Launcher debug logs: "); |
| 4671 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 4672 | Log.d(TAG, " " + sDumpLogs.get(i)); |
| 4673 | } |
| 4674 | Log.d(TAG, "*********************"); |
| 4675 | Log.d(TAG, ""); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4676 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 4677 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | public static void addDumpLog(String tag, String log, boolean debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 4681 | addDumpLog(tag, log, null, debugLog); |
| 4682 | } |
| 4683 | |
| 4684 | public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4685 | if (debugLog) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 4686 | if (e != null) { |
| 4687 | Log.d(tag, log, e); |
| 4688 | } else { |
| 4689 | Log.d(tag, log); |
| 4690 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4691 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 4692 | if (DEBUG_DUMP_LOG) { |
| 4693 | sDateStamp.setTime(System.currentTimeMillis()); |
| 4694 | synchronized (sDumpLogs) { |
Dan Sandler | 295ae18 | 2013-12-10 16:05:47 -0500 | [diff] [blame] | 4695 | sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log |
| 4696 | + (e == null ? "" : (", Exception: " + e))); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4697 | } |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 4698 | } |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4699 | } |
| 4700 | |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 4701 | public void dumpLogsToLocalData() { |
| 4702 | if (DEBUG_DUMP_LOG) { |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 4703 | new AsyncTask<Void, Void, Void>() { |
| 4704 | public Void doInBackground(Void ... args) { |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 4705 | boolean success = false; |
| 4706 | sDateStamp.setTime(sRunStart); |
| 4707 | String FILENAME = sDateStamp.getMonth() + "-" |
| 4708 | + sDateStamp.getDay() + "_" |
| 4709 | + sDateStamp.getHours() + "-" |
| 4710 | + sDateStamp.getMinutes() + "_" |
| 4711 | + sDateStamp.getSeconds() + ".txt"; |
| 4712 | |
| 4713 | FileOutputStream fos = null; |
| 4714 | File outFile = null; |
| 4715 | try { |
| 4716 | outFile = new File(getFilesDir(), FILENAME); |
| 4717 | outFile.createNewFile(); |
| 4718 | fos = new FileOutputStream(outFile); |
| 4719 | } catch (Exception e) { |
| 4720 | e.printStackTrace(); |
| 4721 | } |
| 4722 | if (fos != null) { |
| 4723 | PrintWriter writer = new PrintWriter(fos); |
| 4724 | |
| 4725 | writer.println(" "); |
| 4726 | writer.println("Debug logs: "); |
| 4727 | synchronized (sDumpLogs) { |
| 4728 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 4729 | writer.println(" " + sDumpLogs.get(i)); |
| 4730 | } |
| 4731 | } |
| 4732 | writer.close(); |
| 4733 | } |
| 4734 | try { |
| 4735 | if (fos != null) { |
| 4736 | fos.close(); |
| 4737 | success = true; |
| 4738 | } |
| 4739 | } catch (IOException e) { |
| 4740 | e.printStackTrace(); |
| 4741 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 4742 | return null; |
Winson Chung | ede4129 | 2013-09-19 16:27:36 -0700 | [diff] [blame] | 4743 | } |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 4744 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 4745 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 4746 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4747 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 4748 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 4749 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 4750 | View getContent(); |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 4751 | void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 4752 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 4753 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 4754 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 4755 | } |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 4756 | |
| 4757 | interface DebugIntents { |
| 4758 | static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; |
| 4759 | static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; |
Adam Cohen | 8b5b05b | 2014-01-10 21:42:39 +0000 | [diff] [blame] | 4760 | } |