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