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