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