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