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