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