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