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