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