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