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