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