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