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