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