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