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