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