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