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