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