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