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