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