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