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