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