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