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