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