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