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