The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
| 21 | import android.app.Application; |
| 22 | import android.app.Dialog; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 23 | import android.app.IWallpaperService; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 24 | import android.app.SearchManager; |
| 25 | import android.app.StatusBarManager; |
| 26 | import android.content.ActivityNotFoundException; |
| 27 | import android.content.BroadcastReceiver; |
| 28 | import android.content.ComponentName; |
| 29 | import android.content.ContentResolver; |
| 30 | import android.content.Context; |
| 31 | import android.content.DialogInterface; |
| 32 | import android.content.Intent; |
| 33 | import android.content.IntentFilter; |
| 34 | import android.content.SharedPreferences; |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 35 | import android.content.Intent.ShortcutIconResource; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.content.pm.ActivityInfo; |
| 37 | import android.content.pm.PackageManager; |
| 38 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 40 | import android.content.res.Resources; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.database.ContentObserver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | import android.graphics.Bitmap; |
| 43 | import android.graphics.Rect; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 44 | import android.graphics.PorterDuffXfermode; |
| 45 | import android.graphics.PorterDuff; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 46 | import android.graphics.drawable.BitmapDrawable; |
| 47 | import android.graphics.drawable.Drawable; |
| 48 | import android.graphics.drawable.TransitionDrawable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 49 | import android.os.Bundle; |
| 50 | import android.os.Handler; |
| 51 | import android.os.IBinder; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 52 | import android.os.Looper; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 53 | import android.os.Message; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 54 | import android.os.MessageQueue; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 55 | import android.os.Parcelable; |
| 56 | import android.os.RemoteException; |
| 57 | import android.os.ServiceManager; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 58 | import android.provider.LiveFolders; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 59 | import android.text.Selection; |
| 60 | import android.text.SpannableStringBuilder; |
| 61 | import android.text.TextUtils; |
| 62 | import android.text.method.TextKeyListener; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 63 | import static android.util.Log.*; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 64 | import android.view.Display; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 65 | import android.view.KeyEvent; |
| 66 | import android.view.LayoutInflater; |
| 67 | import android.view.Menu; |
| 68 | import android.view.MenuItem; |
| 69 | import android.view.View; |
| 70 | import android.view.ViewGroup; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 71 | import android.view.MotionEvent; |
| 72 | import android.view.Gravity; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 73 | import android.view.View.OnLongClickListener; |
| 74 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 75 | import android.widget.EditText; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 76 | import android.widget.GridView; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 77 | import android.widget.SlidingDrawer; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | import android.widget.TextView; |
| 79 | import android.widget.Toast; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 80 | import android.widget.ImageView; |
| 81 | import android.widget.PopupWindow; |
| 82 | import android.widget.ViewSwitcher; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 83 | import android.appwidget.AppWidgetManager; |
| 84 | import android.appwidget.AppWidgetProviderInfo; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 85 | import android.gesture.GestureOverlayView; |
| 86 | import android.gesture.GestureLibraries; |
| 87 | import android.gesture.GestureLibrary; |
| 88 | import android.gesture.Gesture; |
| 89 | import android.gesture.Prediction; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 90 | |
| 91 | import java.lang.ref.WeakReference; |
| 92 | import java.util.ArrayList; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 93 | import java.util.LinkedList; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * Default launcher application. |
| 97 | */ |
| 98 | public final class Launcher extends Activity implements View.OnClickListener, OnLongClickListener { |
| 99 | static final String LOG_TAG = "Launcher"; |
| 100 | static final boolean LOGD = false; |
| 101 | |
| 102 | private static final boolean PROFILE_STARTUP = false; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 103 | private static final boolean PROFILE_DRAWER = false; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 104 | private static final boolean PROFILE_ROTATE = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 105 | private static final boolean DEBUG_USER_INTERFACE = false; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 106 | private static final boolean DEBUG_GESTURES = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 107 | |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame^] | 108 | private static final boolean CONFIG_GESTURES_IMMEDIATE_MODE = true; |
| 109 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | private static final int WALLPAPER_SCREENS_SPAN = 2; |
| 111 | |
| 112 | private static final int MENU_GROUP_ADD = 1; |
| 113 | private static final int MENU_ADD = Menu.FIRST + 1; |
| 114 | private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1; |
| 115 | private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1; |
| 116 | private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 117 | private static final int MENU_GESTURES = MENU_NOTIFICATIONS + 1; |
| 118 | private static final int MENU_SETTINGS = MENU_GESTURES + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 119 | |
| 120 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
| 121 | private static final int REQUEST_CREATE_LIVE_FOLDER = 4; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 122 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 123 | private static final int REQUEST_PICK_APPLICATION = 6; |
| 124 | private static final int REQUEST_PICK_SHORTCUT = 7; |
| 125 | private static final int REQUEST_PICK_LIVE_FOLDER = 8; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 126 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 127 | private static final int REQUEST_PICK_GESTURE_ACTION = 10; |
| 128 | private static final int REQUEST_CREATE_GESTURE_ACTION = 11; |
| 129 | private static final int REQUEST_CREATE_GESTURE_APPLICATION_ACTION = 12; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 130 | |
| 131 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 132 | |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 133 | static final String EXTRA_CUSTOM_WIDGET = "custom_widget"; |
| 134 | static final String SEARCH_WIDGET = "search_widget"; |
| 135 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 136 | static final int SCREEN_COUNT = 3; |
| 137 | static final int DEFAULT_SCREN = 1; |
| 138 | static final int NUMBER_CELLS_X = 4; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 139 | static final int NUMBER_CELLS_Y = 4; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 140 | |
| 141 | private static final int DIALOG_CREATE_SHORTCUT = 1; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 142 | static final int DIALOG_RENAME_FOLDER = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 143 | |
| 144 | private static final String PREFERENCES = "launcher"; |
| 145 | private static final String KEY_LOCALE = "locale"; |
| 146 | private static final String KEY_MCC = "mcc"; |
| 147 | private static final String KEY_MNC = "mnc"; |
| 148 | |
| 149 | // Type: int |
| 150 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
| 151 | // Type: boolean |
| 152 | private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder"; |
| 153 | // Type: long |
| 154 | private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder"; |
| 155 | // Type: int |
| 156 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 157 | // Type: int |
| 158 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX"; |
| 159 | // Type: int |
| 160 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY"; |
| 161 | // Type: int |
| 162 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX"; |
| 163 | // Type: int |
| 164 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY"; |
| 165 | // Type: int |
| 166 | private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX"; |
| 167 | // Type: int |
| 168 | private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY"; |
| 169 | // Type: int[] |
| 170 | private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells"; |
| 171 | // Type: boolean |
| 172 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 173 | // Type: long |
| 174 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 175 | // Type: Gesture (Parcelable) |
| 176 | private static final String RUNTIME_STATE_PENDING_GESTURE = "launcher.gesture"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 177 | |
The Android Open Source Project | bc219c3 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 178 | private static final LauncherModel sModel = new LauncherModel(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 179 | |
| 180 | private static Bitmap sWallpaper; |
| 181 | |
| 182 | private static final Object sLock = new Object(); |
| 183 | private static int sScreen = DEFAULT_SCREN; |
| 184 | |
| 185 | private static WallpaperIntentReceiver sWallpaperReceiver; |
| 186 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 187 | private static GestureLibrary sLibrary; |
| 188 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 189 | private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver(); |
| 190 | private final ContentObserver mObserver = new FavoritesChangeObserver(); |
| 191 | |
| 192 | private LayoutInflater mInflater; |
| 193 | |
| 194 | private DragLayer mDragLayer; |
| 195 | private Workspace mWorkspace; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 196 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 197 | private AppWidgetManager mAppWidgetManager; |
| 198 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 199 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 200 | static final int APPWIDGET_HOST_ID = 1024; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 201 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 202 | private CellLayout.CellInfo mAddItemCellInfo; |
| 203 | private CellLayout.CellInfo mMenuAddInfo; |
| 204 | private final int[] mCellCoordinates = new int[2]; |
| 205 | private FolderInfo mFolderInfo; |
| 206 | |
| 207 | private SlidingDrawer mDrawer; |
| 208 | private TransitionDrawable mHandleIcon; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 209 | private HandleView mHandleView; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 210 | private AllAppsGridView mAllAppsGrid; |
| 211 | |
| 212 | private boolean mDesktopLocked = true; |
| 213 | private Bundle mSavedState; |
| 214 | |
| 215 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 216 | |
| 217 | private boolean mDestroyed; |
| 218 | |
| 219 | private boolean mRestoring; |
| 220 | private boolean mWaitingForResult; |
| 221 | private boolean mLocaleChanged; |
| 222 | |
| 223 | private Bundle mSavedInstanceState; |
| 224 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 225 | private DesktopBinder mBinder; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 226 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 227 | private View mGesturesPanel; |
| 228 | private GestureOverlayView mGesturesOverlay; |
| 229 | private ViewSwitcher mGesturesPrompt; |
| 230 | private ImageView mGesturesAdd; |
| 231 | private PopupWindow mGesturesWindow; |
| 232 | private Launcher.GesturesProcessor mGesturesProcessor; |
| 233 | private Gesture mCurrentGesture; |
| 234 | private GesturesAction mGesturesAction; |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 235 | private boolean mHideGesturesPanel; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 236 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 237 | @Override |
| 238 | protected void onCreate(Bundle savedInstanceState) { |
| 239 | super.onCreate(savedInstanceState); |
| 240 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 241 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 242 | if (sLibrary == null) { |
| 243 | // The context is not kept by the library so it's safe to do this |
| 244 | sLibrary = GestureLibraries.fromPrivateFile(Launcher.this, |
| 245 | GesturesConstants.STORE_NAME); |
| 246 | } |
| 247 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 248 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 249 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 250 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 251 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 252 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 253 | if (PROFILE_STARTUP) { |
| 254 | android.os.Debug.startMethodTracing("/sdcard/launcher"); |
| 255 | } |
| 256 | |
| 257 | checkForLocaleChange(); |
| 258 | setWallpaperDimension(); |
| 259 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 260 | setContentView(R.layout.launcher); |
| 261 | setupViews(); |
| 262 | |
| 263 | registerIntentReceivers(); |
| 264 | registerContentObservers(); |
| 265 | |
| 266 | mSavedState = savedInstanceState; |
| 267 | restoreState(mSavedState); |
| 268 | |
| 269 | if (PROFILE_STARTUP) { |
| 270 | android.os.Debug.stopMethodTracing(); |
| 271 | } |
| 272 | |
| 273 | if (!mRestoring) { |
| 274 | startLoaders(); |
| 275 | } |
| 276 | |
| 277 | // For handling default keys |
| 278 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 279 | Selection.setSelection(mDefaultKeySsb, 0); |
| 280 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 281 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 282 | private void checkForLocaleChange() { |
| 283 | final SharedPreferences preferences = getSharedPreferences(PREFERENCES, MODE_PRIVATE); |
| 284 | final Configuration configuration = getResources().getConfiguration(); |
| 285 | |
| 286 | final String previousLocale = preferences.getString(KEY_LOCALE, null); |
| 287 | final String locale = configuration.locale.toString(); |
| 288 | |
| 289 | final int previousMcc = preferences.getInt(KEY_MCC, -1); |
| 290 | final int mcc = configuration.mcc; |
| 291 | |
| 292 | final int previousMnc = preferences.getInt(KEY_MNC, -1); |
| 293 | final int mnc = configuration.mnc; |
| 294 | |
| 295 | mLocaleChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
| 296 | |
| 297 | if (mLocaleChanged) { |
| 298 | final SharedPreferences.Editor editor = preferences.edit(); |
| 299 | editor.putString(KEY_LOCALE, locale); |
| 300 | editor.putInt(KEY_MCC, mcc); |
| 301 | editor.putInt(KEY_MNC, mnc); |
| 302 | editor.commit(); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | static int getScreen() { |
| 307 | synchronized (sLock) { |
| 308 | return sScreen; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | static void setScreen(int screen) { |
| 313 | synchronized (sLock) { |
| 314 | sScreen = screen; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | private void startLoaders() { |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 319 | boolean loadApplications = sModel.loadApplications(true, this, mLocaleChanged); |
| 320 | sModel.loadUserItems(!mLocaleChanged, this, mLocaleChanged, loadApplications); |
| 321 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 322 | mRestoring = false; |
| 323 | } |
| 324 | |
| 325 | private void setWallpaperDimension() { |
| 326 | IBinder binder = ServiceManager.getService(WALLPAPER_SERVICE); |
| 327 | IWallpaperService wallpaperService = IWallpaperService.Stub.asInterface(binder); |
| 328 | |
| 329 | Display display = getWindowManager().getDefaultDisplay(); |
| 330 | boolean isPortrait = display.getWidth() < display.getHeight(); |
| 331 | |
| 332 | final int width = isPortrait ? display.getWidth() : display.getHeight(); |
| 333 | final int height = isPortrait ? display.getHeight() : display.getWidth(); |
| 334 | try { |
| 335 | wallpaperService.setDimensionHints(width * WALLPAPER_SCREENS_SPAN, height); |
| 336 | } catch (RemoteException e) { |
| 337 | // System is dead! |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 343 | mWaitingForResult = false; |
| 344 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 345 | // The pattern used here is that a user PICKs a specific application, |
| 346 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 347 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 348 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 349 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 350 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 351 | if (resultCode == RESULT_OK && (mAddItemCellInfo != null || |
| 352 | ((requestCode == REQUEST_PICK_GESTURE_ACTION || |
| 353 | requestCode == REQUEST_CREATE_GESTURE_ACTION || |
| 354 | requestCode == REQUEST_CREATE_GESTURE_APPLICATION_ACTION) && mCurrentGesture != null))) { |
| 355 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 356 | switch (requestCode) { |
| 357 | case REQUEST_PICK_APPLICATION: |
| 358 | completeAddApplication(this, data, mAddItemCellInfo, !mDesktopLocked); |
| 359 | break; |
| 360 | case REQUEST_PICK_SHORTCUT: |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 361 | processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 362 | break; |
| 363 | case REQUEST_CREATE_SHORTCUT: |
| 364 | completeAddShortcut(data, mAddItemCellInfo, !mDesktopLocked); |
| 365 | break; |
| 366 | case REQUEST_PICK_LIVE_FOLDER: |
| 367 | addLiveFolder(data); |
| 368 | break; |
| 369 | case REQUEST_CREATE_LIVE_FOLDER: |
| 370 | completeAddLiveFolder(data, mAddItemCellInfo, !mDesktopLocked); |
| 371 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 372 | case REQUEST_PICK_APPWIDGET: |
| 373 | addAppWidget(data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 374 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 375 | case REQUEST_CREATE_APPWIDGET: |
| 376 | completeAddAppWidget(data, mAddItemCellInfo, !mDesktopLocked); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 377 | break; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 378 | case REQUEST_PICK_GESTURE_ACTION: |
| 379 | processShortcut(data, REQUEST_CREATE_GESTURE_APPLICATION_ACTION, |
| 380 | REQUEST_CREATE_GESTURE_ACTION); |
| 381 | break; |
| 382 | case REQUEST_CREATE_GESTURE_ACTION: |
| 383 | completeCreateGesture(data, true); |
| 384 | break; |
| 385 | case REQUEST_CREATE_GESTURE_APPLICATION_ACTION: |
| 386 | completeCreateGesture(data, false); |
| 387 | break; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 388 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 389 | } else if (requestCode == REQUEST_PICK_APPWIDGET && |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 390 | resultCode == RESULT_CANCELED && data != null) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 391 | // Clean up the appWidgetId if we canceled |
| 392 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
| 393 | if (appWidgetId != -1) { |
| 394 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 395 | } |
| 396 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | @Override |
| 400 | protected void onResume() { |
| 401 | super.onResume(); |
| 402 | |
| 403 | if (mRestoring) { |
| 404 | startLoaders(); |
| 405 | } |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 406 | |
| 407 | // Make sure that the search gadget (if any) is in its normal place. |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 408 | stopSearch(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 412 | protected void onPause() { |
| 413 | super.onPause(); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 414 | if (mGesturesWindow != null) { |
| 415 | mGesturesWindow.setAnimationStyle(0); |
| 416 | mGesturesWindow.update(); |
| 417 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 418 | closeDrawer(false); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 419 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 420 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 421 | @Override |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 422 | protected void onStop() { |
| 423 | super.onStop(); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 424 | if (mHideGesturesPanel) { |
| 425 | mHideGesturesPanel = false; |
| 426 | hideGesturesPanel(); |
| 427 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | @Override |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 431 | public Object onRetainNonConfigurationInstance() { |
| 432 | // Flag any binder to stop early before switching |
| 433 | if (mBinder != null) { |
| 434 | mBinder.mTerminate = true; |
| 435 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 436 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 437 | if (PROFILE_ROTATE) { |
| 438 | android.os.Debug.startMethodTracing("/sdcard/launcher-rotate"); |
| 439 | } |
| 440 | return null; |
| 441 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 442 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 443 | private boolean acceptFilter() { |
| 444 | final InputMethodManager inputManager = (InputMethodManager) |
| 445 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 446 | return !inputManager.isFullscreenMode(); |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 451 | boolean handled = super.onKeyDown(keyCode, event); |
| 452 | if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) { |
| 453 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 454 | keyCode, event); |
| 455 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 456 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 457 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 458 | // showSearchDialog() |
| 459 | // If there are multiple keystrokes before the search dialog takes focus, |
| 460 | // onSearchRequested() will be called for every keystroke, |
| 461 | // but it is idempotent, so it's fine. |
| 462 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
| 466 | return handled; |
| 467 | } |
| 468 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 469 | private String getTypedText() { |
| 470 | return mDefaultKeySsb.toString(); |
| 471 | } |
| 472 | |
| 473 | private void clearTypedText() { |
| 474 | mDefaultKeySsb.clear(); |
| 475 | mDefaultKeySsb.clearSpans(); |
| 476 | Selection.setSelection(mDefaultKeySsb, 0); |
| 477 | } |
| 478 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 479 | /** |
| 480 | * Restores the previous state, if it exists. |
| 481 | * |
| 482 | * @param savedState The previous state. |
| 483 | */ |
| 484 | private void restoreState(Bundle savedState) { |
| 485 | if (savedState == null) { |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); |
| 490 | if (currentScreen > -1) { |
| 491 | mWorkspace.setCurrentScreen(currentScreen); |
| 492 | } |
| 493 | |
| 494 | final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
| 495 | if (addScreen > -1) { |
| 496 | mAddItemCellInfo = new CellLayout.CellInfo(); |
| 497 | final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo; |
| 498 | addItemCellInfo.valid = true; |
| 499 | addItemCellInfo.screen = addScreen; |
| 500 | addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 501 | addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
| 502 | addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 503 | addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 504 | addItemCellInfo.findVacantCellsFromOccupied( |
| 505 | savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS), |
| 506 | savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X), |
| 507 | savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y)); |
| 508 | mRestoring = true; |
| 509 | } |
| 510 | |
| 511 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 512 | if (renameFolder) { |
| 513 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
| 514 | mFolderInfo = sModel.getFolderById(this, id); |
| 515 | mRestoring = true; |
| 516 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 517 | |
| 518 | mCurrentGesture = (Gesture) savedState.get(RUNTIME_STATE_PENDING_GESTURE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Finds all the views we need and configure them properly. |
| 523 | */ |
| 524 | private void setupViews() { |
| 525 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 526 | final DragLayer dragLayer = mDragLayer; |
| 527 | |
| 528 | mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); |
| 529 | final Workspace workspace = mWorkspace; |
| 530 | |
| 531 | mDrawer = (SlidingDrawer) dragLayer.findViewById(R.id.drawer); |
| 532 | final SlidingDrawer drawer = mDrawer; |
| 533 | |
| 534 | mAllAppsGrid = (AllAppsGridView) drawer.getContent(); |
| 535 | final AllAppsGridView grid = mAllAppsGrid; |
| 536 | |
| 537 | final DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone); |
| 538 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 539 | mHandleView = (HandleView) drawer.findViewById(R.id.all_apps); |
| 540 | mHandleView.setLauncher(this); |
| 541 | mHandleIcon = (TransitionDrawable) mHandleView.getDrawable(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 542 | mHandleIcon.setCrossFadeEnabled(true); |
| 543 | |
| 544 | drawer.lock(); |
| 545 | final DrawerManager drawerManager = new DrawerManager(); |
| 546 | drawer.setOnDrawerOpenListener(drawerManager); |
| 547 | drawer.setOnDrawerCloseListener(drawerManager); |
| 548 | drawer.setOnDrawerScrollListener(drawerManager); |
| 549 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 550 | grid.setTextFilterEnabled(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 551 | grid.setDragger(dragLayer); |
| 552 | grid.setLauncher(this); |
| 553 | |
| 554 | workspace.setOnLongClickListener(this); |
| 555 | workspace.setDragger(dragLayer); |
| 556 | workspace.setLauncher(this); |
| 557 | loadWallpaper(); |
| 558 | |
| 559 | deleteZone.setLauncher(this); |
| 560 | deleteZone.setDragController(dragLayer); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 561 | deleteZone.setHandle(mHandleView); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 562 | |
| 563 | dragLayer.setIgnoredDropTarget(grid); |
| 564 | dragLayer.setDragScoller(workspace); |
| 565 | dragLayer.setDragListener(deleteZone); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 566 | |
| 567 | mGesturesPanel = mInflater.inflate(R.layout.gestures, mDragLayer, false); |
| 568 | final View gesturesPanel = mGesturesPanel; |
| 569 | |
| 570 | mGesturesPrompt = (ViewSwitcher) gesturesPanel.findViewById(R.id.gestures_actions); |
| 571 | mGesturesAction = new GesturesAction(); |
| 572 | |
| 573 | mGesturesPrompt.getChildAt(0).setOnClickListener(mGesturesAction); |
| 574 | mGesturesPrompt.getChildAt(1).setOnClickListener(mGesturesAction); |
| 575 | |
| 576 | mGesturesAdd = (ImageView) gesturesPanel.findViewById(R.id.gestures_add); |
| 577 | final ImageView gesturesAdd = mGesturesAdd; |
| 578 | gesturesAdd.setAlpha(128); |
| 579 | gesturesAdd.setEnabled(false); |
| 580 | gesturesAdd.setOnClickListener(new View.OnClickListener() { |
| 581 | public void onClick(View v) { |
| 582 | createGesture(); |
| 583 | } |
| 584 | }); |
| 585 | |
| 586 | mGesturesOverlay = (GestureOverlayView) gesturesPanel.findViewById(R.id.gestures_overlay); |
| 587 | mGesturesProcessor = new GesturesProcessor(); |
| 588 | |
| 589 | final GestureOverlayView overlay = mGesturesOverlay; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 590 | overlay.addOnGestureListener(mGesturesProcessor); |
Romain Guy | b873424 | 2009-06-10 11:53:57 -0700 | [diff] [blame] | 591 | overlay.getGesturePaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | private void createGesture() { |
| 595 | mCurrentGesture = mGesturesOverlay.getGesture(); |
| 596 | mWaitingForResult = true; |
| 597 | pickShortcut(REQUEST_PICK_GESTURE_ACTION, R.string.title_select_shortcut); |
| 598 | } |
| 599 | |
| 600 | private void completeCreateGesture(Intent data, boolean isShortcut) { |
| 601 | ApplicationInfo info; |
| 602 | |
| 603 | if (isShortcut) { |
| 604 | info = infoFromShortcutIntent(this, data); |
| 605 | } else { |
| 606 | info = infoFromApplicationIntent(this, data); |
| 607 | } |
| 608 | |
| 609 | boolean success = false; |
| 610 | if (info != null) { |
| 611 | info.isGesture = true; |
| 612 | |
| 613 | if (LauncherModel.addGestureToDatabase(this, info, false)) { |
| 614 | mGesturesProcessor.addGesture(String.valueOf(info.id), mCurrentGesture); |
| 615 | mGesturesProcessor.update(info, mCurrentGesture); |
| 616 | Toast.makeText(this, getString(R.string.gestures_created, info.title), |
| 617 | Toast.LENGTH_SHORT).show(); |
| 618 | success = true; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | if (!success) { |
| 623 | Toast.makeText(this, getString(R.string.gestures_failed), Toast.LENGTH_SHORT).show(); |
| 624 | } |
| 625 | |
| 626 | mCurrentGesture = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Creates a view representing a shortcut. |
| 631 | * |
| 632 | * @param info The data structure describing the shortcut. |
| 633 | * |
| 634 | * @return A View inflated from R.layout.application. |
| 635 | */ |
| 636 | View createShortcut(ApplicationInfo info) { |
| 637 | return createShortcut(R.layout.application, |
| 638 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info); |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Creates a view representing a shortcut inflated from the specified resource. |
| 643 | * |
| 644 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 645 | * @param parent The group the shortcut belongs to. |
| 646 | * @param info The data structure describing the shortcut. |
| 647 | * |
| 648 | * @return A View inflated from layoutResId. |
| 649 | */ |
| 650 | View createShortcut(int layoutResId, ViewGroup parent, ApplicationInfo info) { |
| 651 | TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false); |
| 652 | |
| 653 | if (!info.filtered) { |
| 654 | info.icon = Utilities.createIconThumbnail(info.icon, this); |
| 655 | info.filtered = true; |
| 656 | } |
| 657 | |
| 658 | favorite.setCompoundDrawablesWithIntrinsicBounds(null, info.icon, null, null); |
| 659 | favorite.setText(info.title); |
| 660 | favorite.setTag(info); |
| 661 | favorite.setOnClickListener(this); |
| 662 | |
| 663 | return favorite; |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * Add an application shortcut to the workspace. |
| 668 | * |
| 669 | * @param data The intent describing the application. |
| 670 | * @param cellInfo The position on screen where to create the shortcut. |
| 671 | */ |
| 672 | void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo, |
| 673 | boolean insertAtFirst) { |
| 674 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 675 | if (!findSingleSlot(cellInfo)) return; |
| 676 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 677 | final ApplicationInfo info = infoFromApplicationIntent(context, data); |
| 678 | if (info != null) { |
| 679 | mWorkspace.addApplicationShortcut(info, cellInfo, insertAtFirst); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | private static ApplicationInfo infoFromApplicationIntent(Context context, Intent data) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 684 | ComponentName component = data.getComponent(); |
| 685 | PackageManager packageManager = context.getPackageManager(); |
| 686 | ActivityInfo activityInfo = null; |
| 687 | try { |
| 688 | activityInfo = packageManager.getActivityInfo(component, 0 /* no flags */); |
| 689 | } catch (NameNotFoundException e) { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 690 | e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 691 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 692 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 693 | if (activityInfo != null) { |
| 694 | ApplicationInfo itemInfo = new ApplicationInfo(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 695 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 696 | itemInfo.title = activityInfo.loadLabel(packageManager); |
| 697 | if (itemInfo.title == null) { |
| 698 | itemInfo.title = activityInfo.name; |
| 699 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 700 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 701 | itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK | |
| 702 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 703 | itemInfo.icon = activityInfo.loadIcon(packageManager); |
| 704 | itemInfo.container = ItemInfo.NO_ID; |
| 705 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 706 | return itemInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 707 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 708 | |
| 709 | return null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 710 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 711 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 712 | /** |
| 713 | * Add a shortcut to the workspace. |
| 714 | * |
| 715 | * @param data The intent describing the shortcut. |
| 716 | * @param cellInfo The position on screen where to create the shortcut. |
| 717 | * @param insertAtFirst |
| 718 | */ |
| 719 | private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo, |
| 720 | boolean insertAtFirst) { |
| 721 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 722 | if (!findSingleSlot(cellInfo)) return; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 723 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 724 | final ApplicationInfo info = addShortcut(this, data, cellInfo, false); |
| 725 | |
| 726 | if (!mRestoring) { |
| 727 | sModel.addDesktopItem(info); |
| 728 | |
| 729 | final View view = createShortcut(info); |
| 730 | mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst); |
| 731 | } else if (sModel.isDesktopLoaded()) { |
| 732 | sModel.addDesktopItem(info); |
| 733 | } |
| 734 | } |
| 735 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 736 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 737 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 738 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 739 | * |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 740 | * @param data The intent describing the appWidgetId. |
| 741 | * @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] | 742 | */ |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 743 | private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 744 | boolean insertAtFirst) { |
| 745 | |
| 746 | Bundle extras = data.getExtras(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 747 | int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 748 | |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 749 | d(LOG_TAG, "dumping extras content="+extras.toString()); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 750 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 751 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 752 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 753 | // Calculate the grid spans needed to fit this widget |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 754 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 755 | int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 756 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 757 | // Try finding open space on Launcher screen |
| 758 | final int[] xy = mCellCoordinates; |
| 759 | if (!findSlot(cellInfo, xy, spans[0], spans[1])) return; |
| 760 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 761 | // Build Launcher-specific widget info and save to database |
| 762 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 763 | launcherInfo.spanX = spans[0]; |
| 764 | launcherInfo.spanY = spans[1]; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 765 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 766 | LauncherModel.addItemToDatabase(this, launcherInfo, |
| 767 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 768 | mWorkspace.getCurrentScreen(), xy[0], xy[1], false); |
| 769 | |
| 770 | if (!mRestoring) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 771 | sModel.addDesktopAppWidget(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 772 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 773 | // Perform actual inflation because we're live |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 774 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 775 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 776 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 777 | launcherInfo.hostView.setTag(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 778 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 779 | mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1], |
| 780 | launcherInfo.spanX, launcherInfo.spanY, insertAtFirst); |
| 781 | } else if (sModel.isDesktopLoaded()) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 782 | sModel.addDesktopAppWidget(launcherInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 783 | } |
| 784 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 785 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 786 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 787 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 788 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 789 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 790 | static ApplicationInfo addShortcut(Context context, Intent data, |
| 791 | CellLayout.CellInfo cellInfo, boolean notify) { |
| 792 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 793 | final ApplicationInfo info = infoFromShortcutIntent(context, data); |
| 794 | LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 795 | cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify); |
| 796 | |
| 797 | return info; |
| 798 | } |
| 799 | |
| 800 | private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 801 | Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); |
| 802 | String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
| 803 | Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); |
| 804 | |
| 805 | Drawable icon = null; |
| 806 | boolean filtered = false; |
| 807 | boolean customIcon = false; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 808 | ShortcutIconResource iconResource = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 809 | |
| 810 | if (bitmap != null) { |
| 811 | icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context)); |
| 812 | filtered = true; |
| 813 | customIcon = true; |
| 814 | } else { |
| 815 | Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 816 | if (extra != null && extra instanceof ShortcutIconResource) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 817 | try { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 818 | iconResource = (ShortcutIconResource) extra; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 819 | final PackageManager packageManager = context.getPackageManager(); |
| 820 | Resources resources = packageManager.getResourcesForApplication( |
| 821 | iconResource.packageName); |
| 822 | final int id = resources.getIdentifier(iconResource.resourceName, null, null); |
| 823 | icon = resources.getDrawable(id); |
| 824 | } catch (Exception e) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 825 | w(LOG_TAG, "Could not load shortcut icon: " + extra); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | if (icon == null) { |
| 831 | icon = context.getPackageManager().getDefaultActivityIcon(); |
| 832 | } |
| 833 | |
| 834 | final ApplicationInfo info = new ApplicationInfo(); |
| 835 | info.icon = icon; |
| 836 | info.filtered = filtered; |
| 837 | info.title = name; |
| 838 | info.intent = intent; |
| 839 | info.customIcon = customIcon; |
| 840 | info.iconResource = iconResource; |
| 841 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 842 | return info; |
| 843 | } |
| 844 | |
| 845 | @Override |
| 846 | protected void onNewIntent(Intent intent) { |
| 847 | super.onNewIntent(intent); |
| 848 | |
| 849 | // Close the menu |
| 850 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
| 851 | getWindow().closeAllPanels(); |
| 852 | |
| 853 | try { |
| 854 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 855 | // Unlock the workspace if the dialog was showing |
| 856 | mWorkspace.unlock(); |
| 857 | } catch (Exception e) { |
| 858 | // An exception is thrown if the dialog is not visible, which is fine |
| 859 | } |
| 860 | |
| 861 | try { |
| 862 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 863 | // Unlock the workspace if the dialog was showing |
| 864 | mWorkspace.unlock(); |
| 865 | } catch (Exception e) { |
| 866 | // An exception is thrown if the dialog is not visible, which is fine |
| 867 | } |
| 868 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 869 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != |
| 870 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 871 | |
| 872 | if (mGesturesPanel != null && mDragLayer.getWindowVisibility() == View.VISIBLE) { |
Romain Guy | b873424 | 2009-06-10 11:53:57 -0700 | [diff] [blame] | 873 | SearchManager searchManager = |
| 874 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 875 | if (!searchManager.isVisible()) { |
| 876 | onHomeKeyPressed(); |
| 877 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 878 | } |
| 879 | closeDrawer(); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 880 | |
| 881 | final View v = getWindow().peekDecorView(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 882 | if (v != null && v.getWindowToken() != null) { |
| 883 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 884 | INPUT_METHOD_SERVICE); |
| 885 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 886 | } |
| 887 | } else { |
| 888 | closeDrawer(false); |
| 889 | } |
| 890 | } |
| 891 | } |
| 892 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 893 | private void onHomeKeyPressed() { |
| 894 | if (mGesturesWindow == null || !mGesturesWindow.isShowing()) { |
| 895 | showGesturesPanel(); |
| 896 | } else { |
| 897 | hideGesturesPanel(); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | private void showGesturesPanel() { |
| 902 | resetGesturesPrompt(); |
| 903 | |
| 904 | mGesturesAdd.setEnabled(false); |
| 905 | mGesturesAdd.setAlpha(128); |
| 906 | |
| 907 | mGesturesOverlay.clear(false); |
| 908 | |
| 909 | PopupWindow window; |
| 910 | if (mGesturesWindow == null) { |
| 911 | mGesturesWindow = new PopupWindow(this); |
| 912 | window = mGesturesWindow; |
| 913 | window.setFocusable(true); |
| 914 | window.setTouchable(true); |
| 915 | window.setBackgroundDrawable(null); |
| 916 | window.setContentView(mGesturesPanel); |
| 917 | } else { |
| 918 | window = mGesturesWindow; |
| 919 | } |
| 920 | window.setAnimationStyle(com.android.internal.R.style.Animation_SlidingCard); |
| 921 | |
| 922 | final int[] xy = new int[2]; |
| 923 | final DragLayer dragLayer = mDragLayer; |
| 924 | dragLayer.getLocationOnScreen(xy); |
| 925 | |
| 926 | window.setWidth(dragLayer.getWidth()); |
| 927 | window.setHeight(dragLayer.getHeight() - 1); |
| 928 | window.showAtLocation(dragLayer, Gravity.TOP | Gravity.LEFT, xy[0], xy[1] + 1); |
| 929 | } |
| 930 | |
| 931 | private void resetGesturesPrompt() { |
| 932 | mGesturesAction.intent = null; |
| 933 | final TextView prompt = (TextView) mGesturesPrompt.getCurrentView(); |
| 934 | prompt.setText(R.string.gestures_instructions); |
| 935 | prompt.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); |
| 936 | prompt.setClickable(false); |
| 937 | } |
| 938 | |
| 939 | private void resetGesturesNextPrompt() { |
| 940 | mGesturesAction.intent = null; |
| 941 | setGesturesNextPrompt(null, getString(R.string.gestures_instructions)); |
| 942 | mGesturesPrompt.getNextView().setClickable(false); |
| 943 | } |
| 944 | |
| 945 | private void setGesturesNextPrompt(Drawable icon, CharSequence title) { |
| 946 | final TextView prompt = (TextView) mGesturesPrompt.getNextView(); |
| 947 | prompt.setText(title); |
| 948 | prompt.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); |
| 949 | prompt.setClickable(true); |
| 950 | mGesturesPrompt.showNext(); |
| 951 | } |
| 952 | |
| 953 | void hideGesturesPanel() { |
| 954 | if (mGesturesWindow != null) { |
| 955 | mGesturesWindow.setAnimationStyle(com.android.internal.R.style.Animation_SlidingCard); |
| 956 | mGesturesWindow.update(); |
| 957 | mGesturesWindow.dismiss(); |
| 958 | } |
| 959 | } |
| 960 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 961 | @Override |
| 962 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 963 | // Do not call super here |
| 964 | mSavedInstanceState = savedInstanceState; |
| 965 | } |
| 966 | |
| 967 | @Override |
| 968 | protected void onSaveInstanceState(Bundle outState) { |
| 969 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen()); |
| 970 | |
| 971 | final ArrayList<Folder> folders = mWorkspace.getOpenFolders(); |
| 972 | if (folders.size() > 0) { |
| 973 | final int count = folders.size(); |
| 974 | long[] ids = new long[count]; |
| 975 | for (int i = 0; i < count; i++) { |
| 976 | final FolderInfo info = folders.get(i).getInfo(); |
| 977 | ids[i] = info.id; |
| 978 | } |
| 979 | outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids); |
| 980 | } else { |
| 981 | super.onSaveInstanceState(outState); |
| 982 | } |
| 983 | |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 984 | // When the drawer is opened and we are saving the state because of a |
| 985 | // configuration change |
| 986 | if (mDrawer.isOpened() && getChangingConfigurations() != 0) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 987 | outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 988 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 989 | |
| 990 | if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) { |
| 991 | final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo; |
| 992 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen); |
| 993 | |
| 994 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen); |
| 995 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX); |
| 996 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY); |
| 997 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX); |
| 998 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY); |
| 999 | outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX()); |
| 1000 | outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY()); |
| 1001 | outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS, |
| 1002 | layout.getOccupiedCells()); |
| 1003 | } |
| 1004 | |
| 1005 | if (mFolderInfo != null && mWaitingForResult) { |
| 1006 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1007 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1008 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1009 | |
| 1010 | if (mCurrentGesture != null && mWaitingForResult) { |
| 1011 | outState.putParcelable(RUNTIME_STATE_PENDING_GESTURE, mCurrentGesture); |
| 1012 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | @Override |
| 1016 | public void onDestroy() { |
| 1017 | mDestroyed = true; |
| 1018 | |
| 1019 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1020 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1021 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1022 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1023 | } catch (NullPointerException ex) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1024 | w(LOG_TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | TextKeyListener.getInstance().release(); |
| 1028 | |
| 1029 | mAllAppsGrid.clearTextFilter(); |
| 1030 | mAllAppsGrid.setAdapter(null); |
| 1031 | sModel.unbind(); |
| 1032 | sModel.abortLoaders(); |
| 1033 | |
| 1034 | getContentResolver().unregisterContentObserver(mObserver); |
| 1035 | unregisterReceiver(mApplicationsReceiver); |
| 1036 | } |
| 1037 | |
| 1038 | @Override |
| 1039 | public void startActivityForResult(Intent intent, int requestCode) { |
| 1040 | mWaitingForResult = true; |
| 1041 | super.startActivityForResult(intent, requestCode); |
| 1042 | } |
| 1043 | |
| 1044 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1045 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1046 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1047 | |
| 1048 | closeDrawer(false); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1049 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1050 | // Slide the search widget to the top, if it's on the current screen, |
| 1051 | // otherwise show the search dialog immediately. |
| 1052 | Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen(); |
| 1053 | if (searchWidget == null) { |
| 1054 | showSearchDialog(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 1055 | } else { |
| 1056 | searchWidget.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 1057 | // show the currently typed text in the search widget while sliding |
| 1058 | searchWidget.setQuery(getTypedText()); |
| 1059 | } |
| 1060 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1061 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1062 | /** |
| 1063 | * Show the search dialog immediately, without changing the search widget. |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1064 | * |
| 1065 | * @see Activity#startSearch(String, boolean, android.os.Bundle, boolean) |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1066 | */ |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1067 | void showSearchDialog(String initialQuery, boolean selectInitialQuery, |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1068 | Bundle appSearchData, boolean globalSearch) { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1069 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1070 | if (initialQuery == null) { |
| 1071 | // Use any text typed in the launcher as the initial query |
| 1072 | initialQuery = getTypedText(); |
| 1073 | clearTypedText(); |
| 1074 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1075 | if (appSearchData == null) { |
| 1076 | appSearchData = new Bundle(); |
| 1077 | appSearchData.putString(SearchManager.SOURCE, "launcher-search"); |
| 1078 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1079 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1080 | final SearchManager searchManager = |
| 1081 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 1082 | |
| 1083 | final Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen(); |
| 1084 | if (searchWidget != null) { |
| 1085 | // This gets called when the user leaves the search dialog to go back to |
| 1086 | // the Launcher. |
| 1087 | searchManager.setOnCancelListener(new SearchManager.OnCancelListener() { |
| 1088 | public void onCancel() { |
| 1089 | searchManager.setOnCancelListener(null); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1090 | stopSearch(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1091 | } |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1092 | }); |
| 1093 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1094 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1095 | searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1096 | appSearchData, globalSearch); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1097 | } |
| 1098 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1099 | /** |
| 1100 | * Cancel search dialog if it is open. |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1101 | */ |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1102 | void stopSearch() { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1103 | // Close search dialog |
| 1104 | SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 1105 | if (searchManager.isVisible()) { |
| 1106 | searchManager.stopSearch(); |
| 1107 | } |
| 1108 | // Restore search widget to its normal position |
| 1109 | Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen(); |
| 1110 | if (searchWidget != null) { |
| 1111 | searchWidget.stopSearch(false); |
| 1112 | } |
| 1113 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1114 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1115 | @Override |
| 1116 | public boolean onCreateOptionsMenu(Menu menu) { |
| 1117 | if (mDesktopLocked) return false; |
| 1118 | |
| 1119 | super.onCreateOptionsMenu(menu); |
| 1120 | menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add) |
| 1121 | .setIcon(android.R.drawable.ic_menu_add) |
| 1122 | .setAlphabeticShortcut('A'); |
| 1123 | menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) |
| 1124 | .setIcon(android.R.drawable.ic_menu_gallery) |
| 1125 | .setAlphabeticShortcut('W'); |
| 1126 | menu.add(0, MENU_SEARCH, 0, R.string.menu_search) |
| 1127 | .setIcon(android.R.drawable.ic_search_category_default) |
| 1128 | .setAlphabeticShortcut(SearchManager.MENU_KEY); |
| 1129 | menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications) |
| 1130 | .setIcon(com.android.internal.R.drawable.ic_menu_notifications) |
| 1131 | .setAlphabeticShortcut('N'); |
| 1132 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1133 | final Intent gestures = new Intent(this, GesturesActivity.class); |
| 1134 | menu.add(0, MENU_GESTURES, 0, R.string.menu_gestures) |
| 1135 | .setIcon(com.android.internal.R.drawable.ic_menu_compose).setAlphabeticShortcut('G') |
| 1136 | .setIntent(gestures); |
| 1137 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1138 | final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1139 | settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1140 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1141 | |
| 1142 | menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) |
| 1143 | .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') |
| 1144 | .setIntent(settings); |
| 1145 | |
| 1146 | return true; |
| 1147 | } |
| 1148 | |
| 1149 | @Override |
| 1150 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 1151 | super.onPrepareOptionsMenu(menu); |
| 1152 | |
| 1153 | mMenuAddInfo = mWorkspace.findAllVacantCells(null); |
| 1154 | menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid); |
| 1155 | |
| 1156 | return true; |
| 1157 | } |
| 1158 | |
| 1159 | @Override |
| 1160 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1161 | switch (item.getItemId()) { |
| 1162 | case MENU_ADD: |
| 1163 | addItems(); |
| 1164 | return true; |
| 1165 | case MENU_WALLPAPER_SETTINGS: |
| 1166 | startWallpaper(); |
| 1167 | return true; |
| 1168 | case MENU_SEARCH: |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1169 | onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1170 | return true; |
| 1171 | case MENU_NOTIFICATIONS: |
| 1172 | showNotifications(); |
| 1173 | return true; |
| 1174 | } |
| 1175 | |
| 1176 | return super.onOptionsItemSelected(item); |
| 1177 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1178 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1179 | /** |
| 1180 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1181 | * argument for {@link #startSearch} to true. |
| 1182 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1183 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1184 | @Override |
| 1185 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1186 | startSearch(null, false, null, true); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1187 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1190 | private void addItems() { |
| 1191 | showAddDialog(mMenuAddInfo); |
| 1192 | } |
| 1193 | |
| 1194 | private void removeShortcutsForPackage(String packageName) { |
| 1195 | if (packageName != null && packageName.length() > 0) { |
| 1196 | mWorkspace.removeShortcutsForPackage(packageName); |
| 1197 | } |
| 1198 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1199 | |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1200 | private void updateShortcutsForPackage(String packageName) { |
| 1201 | if (packageName != null && packageName.length() > 0) { |
| 1202 | mWorkspace.updateShortcutsForPackage(packageName); |
| 1203 | } |
| 1204 | } |
| 1205 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1206 | void addAppWidget(Intent data) { |
| 1207 | // TODO: catch bad widget exception when sent |
| 1208 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1209 | |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1210 | String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET); |
| 1211 | if (SEARCH_WIDGET.equals(customWidget)) { |
| 1212 | // We don't need this any more, since this isn't a real app widget. |
| 1213 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 1214 | // add the search widget |
| 1215 | addSearch(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1216 | } else { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1217 | AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1218 | |
| 1219 | if (appWidget.configure != null) { |
| 1220 | // Launch over to configure widget, if needed |
| 1221 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
| 1222 | intent.setComponent(appWidget.configure); |
| 1223 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 1224 | |
| 1225 | startActivityForResult(intent, REQUEST_CREATE_APPWIDGET); |
| 1226 | } else { |
| 1227 | // Otherwise just add it |
| 1228 | onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data); |
| 1229 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1230 | } |
| 1231 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1232 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1233 | void addSearch() { |
| 1234 | final Widget info = Widget.makeSearch(); |
| 1235 | final CellLayout.CellInfo cellInfo = mAddItemCellInfo; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1236 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1237 | final int[] xy = mCellCoordinates; |
| 1238 | final int spanX = info.spanX; |
| 1239 | final int spanY = info.spanY; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1240 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1241 | if (!findSlot(cellInfo, xy, spanX, spanY)) return; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1242 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1243 | sModel.addDesktopItem(info); |
| 1244 | LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 1245 | mWorkspace.getCurrentScreen(), xy[0], xy[1], false); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1246 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1247 | final View view = mInflater.inflate(info.layoutResource, null); |
| 1248 | view.setTag(info); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1249 | Search search = (Search) view.findViewById(R.id.widget_search); |
| 1250 | search.setLauncher(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1251 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1252 | mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY); |
| 1253 | } |
| 1254 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1255 | void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1256 | // Handle case where user selected "Applications" |
| 1257 | String applicationName = getResources().getString(R.string.group_applications); |
| 1258 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1259 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1260 | if (applicationName != null && applicationName.equals(shortcutName)) { |
| 1261 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1262 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1263 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1264 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1265 | pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1266 | startActivityForResult(pickIntent, requestCodeApplication); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1267 | } else { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1268 | startActivityForResult(intent, requestCodeShortcut); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1269 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | void addLiveFolder(Intent intent) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1273 | // Handle case where user selected "Folder" |
Jeffrey Sharkey | c4bbd0a | 2009-03-24 22:47:52 -0700 | [diff] [blame] | 1274 | String folderName = getResources().getString(R.string.group_folder); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1275 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1276 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1277 | if (folderName != null && folderName.equals(shortcutName)) { |
| 1278 | addFolder(!mDesktopLocked); |
| 1279 | } else { |
| 1280 | startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER); |
| 1281 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | void addFolder(boolean insertAtFirst) { |
| 1285 | UserFolderInfo folderInfo = new UserFolderInfo(); |
| 1286 | folderInfo.title = getText(R.string.folder_name); |
| 1287 | |
| 1288 | CellLayout.CellInfo cellInfo = mAddItemCellInfo; |
| 1289 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 1290 | if (!findSingleSlot(cellInfo)) return; |
| 1291 | |
| 1292 | // Update the model |
| 1293 | LauncherModel.addItemToDatabase(this, folderInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 1294 | mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false); |
| 1295 | sModel.addDesktopItem(folderInfo); |
| 1296 | sModel.addFolder(folderInfo); |
| 1297 | |
| 1298 | // Create the view |
| 1299 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
| 1300 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo); |
| 1301 | mWorkspace.addInCurrentScreen(newFolder, |
| 1302 | cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst); |
| 1303 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1304 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1305 | private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo, |
| 1306 | boolean insertAtFirst) { |
| 1307 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 1308 | if (!findSingleSlot(cellInfo)) return; |
| 1309 | |
| 1310 | final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false); |
| 1311 | |
| 1312 | if (!mRestoring) { |
| 1313 | sModel.addDesktopItem(info); |
| 1314 | |
| 1315 | final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this, |
| 1316 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info); |
| 1317 | mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, insertAtFirst); |
| 1318 | } else if (sModel.isDesktopLoaded()) { |
| 1319 | sModel.addDesktopItem(info); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | static LiveFolderInfo addLiveFolder(Context context, Intent data, |
| 1324 | CellLayout.CellInfo cellInfo, boolean notify) { |
| 1325 | |
| 1326 | Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT); |
| 1327 | String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME); |
| 1328 | |
| 1329 | Drawable icon = null; |
| 1330 | boolean filtered = false; |
| 1331 | Intent.ShortcutIconResource iconResource = null; |
| 1332 | |
| 1333 | Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON); |
| 1334 | if (extra != null && extra instanceof Intent.ShortcutIconResource) { |
| 1335 | try { |
| 1336 | iconResource = (Intent.ShortcutIconResource) extra; |
| 1337 | final PackageManager packageManager = context.getPackageManager(); |
| 1338 | Resources resources = packageManager.getResourcesForApplication( |
| 1339 | iconResource.packageName); |
| 1340 | final int id = resources.getIdentifier(iconResource.resourceName, null, null); |
| 1341 | icon = resources.getDrawable(id); |
| 1342 | } catch (Exception e) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1343 | w(LOG_TAG, "Could not load live folder icon: " + extra); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | if (icon == null) { |
| 1348 | icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder); |
| 1349 | } |
| 1350 | |
| 1351 | final LiveFolderInfo info = new LiveFolderInfo(); |
| 1352 | info.icon = icon; |
| 1353 | info.filtered = filtered; |
| 1354 | info.title = name; |
| 1355 | info.iconResource = iconResource; |
| 1356 | info.uri = data.getData(); |
| 1357 | info.baseIntent = baseIntent; |
| 1358 | info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, |
| 1359 | LiveFolders.DISPLAY_MODE_GRID); |
| 1360 | |
| 1361 | LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 1362 | cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify); |
| 1363 | sModel.addFolder(info); |
| 1364 | |
| 1365 | return info; |
| 1366 | } |
| 1367 | |
| 1368 | private boolean findSingleSlot(CellLayout.CellInfo cellInfo) { |
| 1369 | final int[] xy = new int[2]; |
| 1370 | if (findSlot(cellInfo, xy, 1, 1)) { |
| 1371 | cellInfo.cellX = xy[0]; |
| 1372 | cellInfo.cellY = xy[1]; |
| 1373 | return true; |
| 1374 | } |
| 1375 | return false; |
| 1376 | } |
| 1377 | |
| 1378 | private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) { |
| 1379 | if (!cellInfo.findCellForSpan(xy, spanX, spanY)) { |
| 1380 | boolean[] occupied = mSavedState != null ? |
| 1381 | mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null; |
| 1382 | cellInfo = mWorkspace.findAllVacantCells(occupied); |
| 1383 | if (!cellInfo.findCellForSpan(xy, spanX, spanY)) { |
| 1384 | Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show(); |
| 1385 | return false; |
| 1386 | } |
| 1387 | } |
| 1388 | return true; |
| 1389 | } |
| 1390 | |
| 1391 | private void showNotifications() { |
| 1392 | final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE); |
| 1393 | if (statusBar != null) { |
| 1394 | statusBar.expand(); |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | private void startWallpaper() { |
| 1399 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 1400 | startActivity(Intent.createChooser(pickWallpaper, getString(R.string.chooser_wallpaper))); |
| 1401 | } |
| 1402 | |
| 1403 | /** |
| 1404 | * Registers various intent receivers. The current implementation registers |
| 1405 | * only a wallpaper intent receiver to let other applications change the |
| 1406 | * wallpaper. |
| 1407 | */ |
| 1408 | private void registerIntentReceivers() { |
| 1409 | if (sWallpaperReceiver == null) { |
| 1410 | final Application application = getApplication(); |
| 1411 | |
| 1412 | sWallpaperReceiver = new WallpaperIntentReceiver(application, this); |
| 1413 | |
| 1414 | IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED); |
| 1415 | application.registerReceiver(sWallpaperReceiver, filter); |
| 1416 | } else { |
| 1417 | sWallpaperReceiver.setLauncher(this); |
| 1418 | } |
| 1419 | |
| 1420 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 1421 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 1422 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| 1423 | filter.addDataScheme("package"); |
| 1424 | registerReceiver(mApplicationsReceiver, filter); |
| 1425 | } |
| 1426 | |
| 1427 | /** |
| 1428 | * Registers various content observers. The current implementation registers |
| 1429 | * only a favorites observer to keep track of the favorites applications. |
| 1430 | */ |
| 1431 | private void registerContentObservers() { |
| 1432 | ContentResolver resolver = getContentResolver(); |
| 1433 | resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true, mObserver); |
| 1434 | } |
| 1435 | |
| 1436 | @Override |
| 1437 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 1438 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 1439 | switch (event.getKeyCode()) { |
| 1440 | case KeyEvent.KEYCODE_BACK: |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1441 | mWorkspace.dispatchKeyEvent(event); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1442 | if (mDrawer.isOpened()) { |
| 1443 | closeDrawer(); |
| 1444 | } else { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1445 | closeFolder(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1446 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1447 | return true; |
| 1448 | case KeyEvent.KEYCODE_HOME: |
| 1449 | return true; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | return super.dispatchKeyEvent(event); |
| 1454 | } |
| 1455 | |
| 1456 | private void closeDrawer() { |
| 1457 | closeDrawer(true); |
| 1458 | } |
| 1459 | |
| 1460 | private void closeDrawer(boolean animated) { |
| 1461 | if (mDrawer.isOpened()) { |
| 1462 | if (animated) { |
| 1463 | mDrawer.animateClose(); |
| 1464 | } else { |
| 1465 | mDrawer.close(); |
| 1466 | } |
| 1467 | if (mDrawer.hasFocus()) { |
| 1468 | mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus(); |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | private void closeFolder() { |
| 1474 | Folder folder = mWorkspace.getOpenFolder(); |
| 1475 | if (folder != null) { |
| 1476 | closeFolder(folder); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | void closeFolder(Folder folder) { |
| 1481 | folder.getInfo().opened = false; |
| 1482 | ViewGroup parent = (ViewGroup) folder.getParent(); |
| 1483 | if (parent != null) { |
| 1484 | parent.removeView(folder); |
| 1485 | } |
| 1486 | folder.onClose(); |
| 1487 | } |
| 1488 | |
| 1489 | /** |
| 1490 | * When the notification that favorites have changed is received, requests |
| 1491 | * a favorites list refresh. |
| 1492 | */ |
| 1493 | private void onFavoritesChanged() { |
| 1494 | mDesktopLocked = true; |
| 1495 | mDrawer.lock(); |
| 1496 | sModel.loadUserItems(false, this, false, false); |
| 1497 | } |
| 1498 | |
| 1499 | void onDesktopItemsLoaded() { |
| 1500 | if (mDestroyed) return; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1501 | bindDesktopItems(); |
| 1502 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1503 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1504 | /** |
| 1505 | * Refreshes the shortcuts shown on the workspace. |
| 1506 | */ |
| 1507 | private void bindDesktopItems() { |
| 1508 | final ArrayList<ItemInfo> shortcuts = sModel.getDesktopItems(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1509 | final ArrayList<LauncherAppWidgetInfo> appWidgets = sModel.getDesktopAppWidgets(); |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1510 | final ApplicationsAdapter drawerAdapter = sModel.getApplicationsAdapter(); |
| 1511 | if (shortcuts == null || appWidgets == null || drawerAdapter == null) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1512 | return; |
| 1513 | } |
| 1514 | |
| 1515 | final Workspace workspace = mWorkspace; |
| 1516 | int count = workspace.getChildCount(); |
| 1517 | for (int i = 0; i < count; i++) { |
| 1518 | ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); |
| 1519 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1520 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1521 | if (DEBUG_USER_INTERFACE) { |
| 1522 | android.widget.Button finishButton = new android.widget.Button(this); |
| 1523 | finishButton.setText("Finish"); |
| 1524 | workspace.addInScreen(finishButton, 1, 0, 0, 1, 1); |
| 1525 | |
| 1526 | finishButton.setOnClickListener(new android.widget.Button.OnClickListener() { |
| 1527 | public void onClick(View v) { |
| 1528 | finish(); |
| 1529 | } |
| 1530 | }); |
| 1531 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1532 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1533 | // Flag any old binder to terminate early |
| 1534 | if (mBinder != null) { |
| 1535 | mBinder.mTerminate = true; |
| 1536 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1537 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1538 | mBinder = new DesktopBinder(this, shortcuts, appWidgets, drawerAdapter); |
Jeffrey Sharkey | 2d132af | 2009-03-24 21:21:09 -0700 | [diff] [blame] | 1539 | mBinder.startBindingItems(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | private void bindItems(Launcher.DesktopBinder binder, |
| 1543 | ArrayList<ItemInfo> shortcuts, int start, int count) { |
| 1544 | |
| 1545 | final Workspace workspace = mWorkspace; |
| 1546 | final boolean desktopLocked = mDesktopLocked; |
| 1547 | |
| 1548 | final int end = Math.min(start + DesktopBinder.ITEMS_COUNT, count); |
| 1549 | int i = start; |
| 1550 | |
| 1551 | for ( ; i < end; i++) { |
| 1552 | final ItemInfo item = shortcuts.get(i); |
| 1553 | switch (item.itemType) { |
| 1554 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 1555 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 1556 | final View shortcut = createShortcut((ApplicationInfo) item); |
| 1557 | workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, |
| 1558 | !desktopLocked); |
| 1559 | break; |
| 1560 | case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: |
| 1561 | final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
| 1562 | (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()), |
| 1563 | (UserFolderInfo) item); |
| 1564 | workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 1565 | !desktopLocked); |
| 1566 | break; |
| 1567 | case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: |
| 1568 | final FolderIcon newLiveFolder = LiveFolderIcon.fromXml( |
| 1569 | R.layout.live_folder_icon, this, |
| 1570 | (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()), |
| 1571 | (LiveFolderInfo) item); |
| 1572 | workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 1573 | !desktopLocked); |
| 1574 | break; |
| 1575 | case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH: |
| 1576 | final int screen = workspace.getCurrentScreen(); |
| 1577 | final View view = mInflater.inflate(R.layout.widget_search, |
| 1578 | (ViewGroup) workspace.getChildAt(screen), false); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1579 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1580 | Search search = (Search) view.findViewById(R.id.widget_search); |
| 1581 | search.setLauncher(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1582 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1583 | final Widget widget = (Widget) item; |
| 1584 | view.setTag(widget); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1585 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1586 | workspace.addWidget(view, widget, !desktopLocked); |
| 1587 | break; |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | workspace.requestLayout(); |
| 1592 | |
| 1593 | if (end >= count) { |
| 1594 | finishBindDesktopItems(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1595 | binder.startBindingDrawer(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1596 | } else { |
| 1597 | binder.obtainMessage(DesktopBinder.MESSAGE_BIND_ITEMS, i, count).sendToTarget(); |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | private void finishBindDesktopItems() { |
| 1602 | if (mSavedState != null) { |
| 1603 | if (!mWorkspace.hasFocus()) { |
| 1604 | mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus(); |
| 1605 | } |
| 1606 | |
| 1607 | final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS); |
| 1608 | if (userFolders != null) { |
| 1609 | for (long folderId : userFolders) { |
| 1610 | final FolderInfo info = sModel.findFolderById(folderId); |
| 1611 | if (info != null) { |
| 1612 | openFolder(info); |
| 1613 | } |
| 1614 | } |
| 1615 | final Folder openFolder = mWorkspace.getOpenFolder(); |
| 1616 | if (openFolder != null) { |
| 1617 | openFolder.requestFocus(); |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | final boolean allApps = mSavedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false); |
| 1622 | if (allApps) { |
| 1623 | mDrawer.open(); |
| 1624 | } |
| 1625 | |
| 1626 | mSavedState = null; |
| 1627 | } |
| 1628 | |
| 1629 | if (mSavedInstanceState != null) { |
| 1630 | super.onRestoreInstanceState(mSavedInstanceState); |
| 1631 | mSavedInstanceState = null; |
| 1632 | } |
| 1633 | |
| 1634 | if (mDrawer.isOpened() && !mDrawer.hasFocus()) { |
| 1635 | mDrawer.requestFocus(); |
| 1636 | } |
| 1637 | |
| 1638 | mDesktopLocked = false; |
| 1639 | mDrawer.unlock(); |
| 1640 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1641 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1642 | private void bindDrawer(Launcher.DesktopBinder binder, |
| 1643 | ApplicationsAdapter drawerAdapter) { |
| 1644 | mAllAppsGrid.setAdapter(drawerAdapter); |
| 1645 | binder.startBindingAppWidgetsWhenIdle(); |
| 1646 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1647 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1648 | private void bindAppWidgets(Launcher.DesktopBinder binder, |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1649 | LinkedList<LauncherAppWidgetInfo> appWidgets) { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1650 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1651 | final Workspace workspace = mWorkspace; |
| 1652 | final boolean desktopLocked = mDesktopLocked; |
| 1653 | |
Jeffrey Sharkey | d18299f | 2009-03-24 18:11:49 -0700 | [diff] [blame] | 1654 | if (!appWidgets.isEmpty()) { |
| 1655 | final LauncherAppWidgetInfo item = appWidgets.removeFirst(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1656 | |
Jeffrey Sharkey | d18299f | 2009-03-24 18:11:49 -0700 | [diff] [blame] | 1657 | final int appWidgetId = item.appWidgetId; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1658 | final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Jeffrey Sharkey | d18299f | 2009-03-24 18:11:49 -0700 | [diff] [blame] | 1659 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1660 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1661 | if (LOGD) d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s", appWidgetId, appWidgetInfo)); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1662 | |
Jeffrey Sharkey | d18299f | 2009-03-24 18:11:49 -0700 | [diff] [blame] | 1663 | item.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1664 | item.hostView.setTag(item); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1665 | |
Jeffrey Sharkey | d18299f | 2009-03-24 18:11:49 -0700 | [diff] [blame] | 1666 | workspace.addInScreen(item.hostView, item.screen, item.cellX, |
| 1667 | item.cellY, item.spanX, item.spanY, !desktopLocked); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1668 | |
Jeffrey Sharkey | d18299f | 2009-03-24 18:11:49 -0700 | [diff] [blame] | 1669 | workspace.requestLayout(); |
| 1670 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1671 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1672 | if (appWidgets.isEmpty()) { |
| 1673 | if (PROFILE_ROTATE) { |
| 1674 | android.os.Debug.stopMethodTracing(); |
| 1675 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1676 | } else { |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1677 | binder.obtainMessage(DesktopBinder.MESSAGE_BIND_APPWIDGETS).sendToTarget(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1678 | } |
| 1679 | } |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1680 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1681 | DragController getDragController() { |
| 1682 | return mDragLayer; |
| 1683 | } |
| 1684 | |
| 1685 | /** |
| 1686 | * Launches the intent referred by the clicked shortcut. |
| 1687 | * |
| 1688 | * @param v The view representing the clicked shortcut. |
| 1689 | */ |
| 1690 | public void onClick(View v) { |
| 1691 | Object tag = v.getTag(); |
| 1692 | if (tag instanceof ApplicationInfo) { |
| 1693 | // Open shortcut |
| 1694 | final Intent intent = ((ApplicationInfo) tag).intent; |
| 1695 | startActivitySafely(intent); |
| 1696 | } else if (tag instanceof FolderInfo) { |
| 1697 | handleFolderClick((FolderInfo) tag); |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | void startActivitySafely(Intent intent) { |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 1702 | mHideGesturesPanel = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1703 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1704 | try { |
| 1705 | startActivity(intent); |
| 1706 | } catch (ActivityNotFoundException e) { |
| 1707 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 1708 | } catch (SecurityException e) { |
| 1709 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1710 | e(LOG_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] | 1711 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
| 1712 | "or use the exported attribute for this activity.", e); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | private void handleFolderClick(FolderInfo folderInfo) { |
| 1717 | if (!folderInfo.opened) { |
| 1718 | // Close any open folder |
| 1719 | closeFolder(); |
| 1720 | // Open the requested folder |
| 1721 | openFolder(folderInfo); |
| 1722 | } else { |
| 1723 | // Find the open folder... |
| 1724 | Folder openFolder = mWorkspace.getFolderForTag(folderInfo); |
| 1725 | int folderScreen; |
| 1726 | if (openFolder != null) { |
| 1727 | folderScreen = mWorkspace.getScreenForView(openFolder); |
| 1728 | // .. and close it |
| 1729 | closeFolder(openFolder); |
| 1730 | if (folderScreen != mWorkspace.getCurrentScreen()) { |
| 1731 | // Close any folder open on the current screen |
| 1732 | closeFolder(); |
| 1733 | // Pull the folder onto this screen |
| 1734 | openFolder(folderInfo); |
| 1735 | } |
| 1736 | } |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | private void loadWallpaper() { |
| 1741 | // The first time the application is started, we load the wallpaper from |
| 1742 | // the ApplicationContext |
| 1743 | if (sWallpaper == null) { |
| 1744 | final Drawable drawable = getWallpaper(); |
| 1745 | if (drawable instanceof BitmapDrawable) { |
| 1746 | sWallpaper = ((BitmapDrawable) drawable).getBitmap(); |
| 1747 | } else { |
| 1748 | throw new IllegalStateException("The wallpaper must be a BitmapDrawable."); |
| 1749 | } |
| 1750 | } |
| 1751 | mWorkspace.loadWallpaper(sWallpaper); |
| 1752 | } |
| 1753 | |
| 1754 | /** |
| 1755 | * Opens the user fodler described by the specified tag. The opening of the folder |
| 1756 | * is animated relative to the specified View. If the View is null, no animation |
| 1757 | * is played. |
| 1758 | * |
| 1759 | * @param folderInfo The FolderInfo describing the folder to open. |
| 1760 | */ |
| 1761 | private void openFolder(FolderInfo folderInfo) { |
| 1762 | Folder openFolder; |
| 1763 | |
| 1764 | if (folderInfo instanceof UserFolderInfo) { |
| 1765 | openFolder = UserFolder.fromXml(this); |
| 1766 | } else if (folderInfo instanceof LiveFolderInfo) { |
| 1767 | openFolder = com.android.launcher.LiveFolder.fromXml(this, folderInfo); |
| 1768 | } else { |
| 1769 | return; |
| 1770 | } |
| 1771 | |
| 1772 | openFolder.setDragger(mDragLayer); |
| 1773 | openFolder.setLauncher(this); |
| 1774 | |
| 1775 | openFolder.bind(folderInfo); |
| 1776 | folderInfo.opened = true; |
| 1777 | |
| 1778 | mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4); |
| 1779 | openFolder.onOpen(); |
| 1780 | } |
| 1781 | |
| 1782 | /** |
| 1783 | * Returns true if the workspace is being loaded. When the workspace is loading, |
| 1784 | * no user interaction should be allowed to avoid any conflict. |
| 1785 | * |
| 1786 | * @return True if the workspace is locked, false otherwise. |
| 1787 | */ |
| 1788 | boolean isWorkspaceLocked() { |
| 1789 | return mDesktopLocked; |
| 1790 | } |
| 1791 | |
| 1792 | public boolean onLongClick(View v) { |
| 1793 | if (mDesktopLocked) { |
| 1794 | return false; |
| 1795 | } |
| 1796 | |
| 1797 | if (!(v instanceof CellLayout)) { |
| 1798 | v = (View) v.getParent(); |
| 1799 | } |
| 1800 | |
| 1801 | CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag(); |
| 1802 | |
| 1803 | // This happens when long clicking an item with the dpad/trackball |
| 1804 | if (cellInfo == null) { |
| 1805 | return true; |
| 1806 | } |
| 1807 | |
| 1808 | if (mWorkspace.allowLongPress()) { |
| 1809 | if (cellInfo.cell == null) { |
| 1810 | if (cellInfo.valid) { |
| 1811 | // User long pressed on empty space |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1812 | mWorkspace.setAllowLongPress(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1813 | showAddDialog(cellInfo); |
| 1814 | } |
| 1815 | } else { |
| 1816 | if (!(cellInfo.cell instanceof Folder)) { |
| 1817 | // User long pressed on an item |
| 1818 | mWorkspace.startDrag(cellInfo); |
| 1819 | } |
| 1820 | } |
| 1821 | } |
| 1822 | return true; |
| 1823 | } |
| 1824 | |
| 1825 | static LauncherModel getModel() { |
| 1826 | return sModel; |
| 1827 | } |
| 1828 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1829 | static GestureLibrary getGestureLibrary() { |
| 1830 | return sLibrary; |
| 1831 | } |
| 1832 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1833 | void closeAllApplications() { |
| 1834 | mDrawer.close(); |
| 1835 | } |
| 1836 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1837 | View getDrawerHandle() { |
| 1838 | return mHandleView; |
| 1839 | } |
| 1840 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1841 | boolean isDrawerDown() { |
| 1842 | return !mDrawer.isMoving() && !mDrawer.isOpened(); |
| 1843 | } |
| 1844 | |
| 1845 | boolean isDrawerUp() { |
| 1846 | return mDrawer.isOpened() && !mDrawer.isMoving(); |
| 1847 | } |
| 1848 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1849 | boolean isDrawerMoving() { |
| 1850 | return mDrawer.isMoving(); |
| 1851 | } |
| 1852 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1853 | Workspace getWorkspace() { |
| 1854 | return mWorkspace; |
| 1855 | } |
| 1856 | |
| 1857 | GridView getApplicationsGrid() { |
| 1858 | return mAllAppsGrid; |
| 1859 | } |
| 1860 | |
| 1861 | @Override |
| 1862 | protected Dialog onCreateDialog(int id) { |
| 1863 | switch (id) { |
| 1864 | case DIALOG_CREATE_SHORTCUT: |
| 1865 | return new CreateShortcut().createDialog(); |
| 1866 | case DIALOG_RENAME_FOLDER: |
| 1867 | return new RenameFolder().createDialog(); |
| 1868 | } |
| 1869 | |
| 1870 | return super.onCreateDialog(id); |
| 1871 | } |
| 1872 | |
| 1873 | @Override |
| 1874 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 1875 | switch (id) { |
| 1876 | case DIALOG_CREATE_SHORTCUT: |
| 1877 | mWorkspace.lock(); |
| 1878 | break; |
| 1879 | case DIALOG_RENAME_FOLDER: |
| 1880 | mWorkspace.lock(); |
| 1881 | EditText input = (EditText) dialog.findViewById(R.id.folder_name); |
| 1882 | final CharSequence text = mFolderInfo.title; |
| 1883 | input.setText(text); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1884 | input.setSelection(0, text.length()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1885 | break; |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | void showRenameDialog(FolderInfo info) { |
| 1890 | mFolderInfo = info; |
| 1891 | mWaitingForResult = true; |
| 1892 | showDialog(DIALOG_RENAME_FOLDER); |
| 1893 | } |
| 1894 | |
| 1895 | private void showAddDialog(CellLayout.CellInfo cellInfo) { |
| 1896 | mAddItemCellInfo = cellInfo; |
| 1897 | mWaitingForResult = true; |
| 1898 | showDialog(DIALOG_CREATE_SHORTCUT); |
| 1899 | } |
| 1900 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1901 | private void pickShortcut(int requestCode, int title) { |
| 1902 | Bundle bundle = new Bundle(); |
| 1903 | |
| 1904 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 1905 | shortcutNames.add(getString(R.string.group_applications)); |
| 1906 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
| 1907 | |
| 1908 | ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>(); |
| 1909 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 1910 | R.drawable.ic_launcher_application)); |
| 1911 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 1912 | |
| 1913 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1914 | pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT)); |
| 1915 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title)); |
| 1916 | pickIntent.putExtras(bundle); |
| 1917 | |
| 1918 | startActivityForResult(pickIntent, requestCode); |
| 1919 | } |
| 1920 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1921 | private class RenameFolder { |
| 1922 | private EditText mInput; |
| 1923 | |
| 1924 | Dialog createDialog() { |
| 1925 | mWaitingForResult = true; |
| 1926 | final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null); |
| 1927 | mInput = (EditText) layout.findViewById(R.id.folder_name); |
| 1928 | |
| 1929 | AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 1930 | builder.setIcon(0); |
| 1931 | builder.setTitle(getString(R.string.rename_folder_title)); |
| 1932 | builder.setCancelable(true); |
| 1933 | builder.setOnCancelListener(new Dialog.OnCancelListener() { |
| 1934 | public void onCancel(DialogInterface dialog) { |
| 1935 | cleanup(); |
| 1936 | } |
| 1937 | }); |
| 1938 | builder.setNegativeButton(getString(R.string.cancel_action), |
| 1939 | new Dialog.OnClickListener() { |
| 1940 | public void onClick(DialogInterface dialog, int which) { |
| 1941 | cleanup(); |
| 1942 | } |
| 1943 | } |
| 1944 | ); |
| 1945 | builder.setPositiveButton(getString(R.string.rename_action), |
| 1946 | new Dialog.OnClickListener() { |
| 1947 | public void onClick(DialogInterface dialog, int which) { |
| 1948 | changeFolderName(); |
| 1949 | } |
| 1950 | } |
| 1951 | ); |
| 1952 | builder.setView(layout); |
| 1953 | return builder.create(); |
| 1954 | } |
| 1955 | |
| 1956 | private void changeFolderName() { |
| 1957 | final String name = mInput.getText().toString(); |
| 1958 | if (!TextUtils.isEmpty(name)) { |
| 1959 | // Make sure we have the right folder info |
| 1960 | mFolderInfo = sModel.findFolderById(mFolderInfo.id); |
| 1961 | mFolderInfo.title = name; |
| 1962 | LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo); |
| 1963 | |
| 1964 | if (mDesktopLocked) { |
| 1965 | mDrawer.lock(); |
| 1966 | sModel.loadUserItems(false, Launcher.this, false, false); |
| 1967 | } else { |
| 1968 | final FolderIcon folderIcon = (FolderIcon) |
| 1969 | mWorkspace.getViewForTag(mFolderInfo); |
| 1970 | if (folderIcon != null) { |
| 1971 | folderIcon.setText(name); |
| 1972 | getWorkspace().requestLayout(); |
| 1973 | } else { |
| 1974 | mDesktopLocked = true; |
| 1975 | mDrawer.lock(); |
| 1976 | sModel.loadUserItems(false, Launcher.this, false, false); |
| 1977 | } |
| 1978 | } |
| 1979 | } |
| 1980 | cleanup(); |
| 1981 | } |
| 1982 | |
| 1983 | private void cleanup() { |
| 1984 | mWorkspace.unlock(); |
| 1985 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 1986 | mWaitingForResult = false; |
| 1987 | mFolderInfo = null; |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | /** |
| 1992 | * Displays the shortcut creation dialog and launches, if necessary, the |
| 1993 | * appropriate activity. |
| 1994 | */ |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1995 | private class CreateShortcut implements DialogInterface.OnClickListener, |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1996 | DialogInterface.OnCancelListener, DialogInterface.OnDismissListener { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1997 | private AddAdapter mAdapter; |
Romain Guy | 9ffb543 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 1998 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1999 | Dialog createDialog() { |
| 2000 | mWaitingForResult = true; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2001 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2002 | mAdapter = new AddAdapter(Launcher.this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2003 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2004 | final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 2005 | builder.setTitle(getString(R.string.menu_item_add_item)); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2006 | builder.setAdapter(mAdapter, this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2007 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2008 | builder.setInverseBackgroundForced(true); |
| 2009 | |
| 2010 | AlertDialog dialog = builder.create(); |
| 2011 | dialog.setOnCancelListener(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2012 | dialog.setOnDismissListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2013 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2014 | return dialog; |
| 2015 | } |
| 2016 | |
| 2017 | public void onCancel(DialogInterface dialog) { |
| 2018 | mWaitingForResult = false; |
| 2019 | cleanup(); |
| 2020 | } |
| 2021 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2022 | public void onDismiss(DialogInterface dialog) { |
| 2023 | mWorkspace.unlock(); |
| 2024 | } |
| 2025 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2026 | private void cleanup() { |
| 2027 | mWorkspace.unlock(); |
| 2028 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 2029 | } |
| 2030 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2031 | /** |
| 2032 | * Handle the action clicked in the "Add to home" dialog. |
| 2033 | */ |
| 2034 | public void onClick(DialogInterface dialog, int which) { |
| 2035 | Resources res = getResources(); |
| 2036 | cleanup(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2037 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2038 | switch (which) { |
| 2039 | case AddAdapter.ITEM_SHORTCUT: { |
| 2040 | // Insert extra item to handle picking application |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2041 | pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2042 | break; |
| 2043 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2044 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2045 | case AddAdapter.ITEM_APPWIDGET: { |
| 2046 | int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2047 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2048 | Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); |
| 2049 | pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 2050 | // add the search widget |
| 2051 | ArrayList<AppWidgetProviderInfo> customInfo = |
| 2052 | new ArrayList<AppWidgetProviderInfo>(); |
| 2053 | AppWidgetProviderInfo info = new AppWidgetProviderInfo(); |
| 2054 | info.provider = new ComponentName(getPackageName(), "XXX.YYY"); |
| 2055 | info.label = getString(R.string.group_search); |
| 2056 | info.icon = R.drawable.ic_search_widget; |
| 2057 | customInfo.add(info); |
| 2058 | pickIntent.putParcelableArrayListExtra( |
| 2059 | AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo); |
| 2060 | ArrayList<Bundle> customExtras = new ArrayList<Bundle>(); |
| 2061 | Bundle b = new Bundle(); |
| 2062 | b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET); |
| 2063 | customExtras.add(b); |
| 2064 | pickIntent.putParcelableArrayListExtra( |
| 2065 | AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras); |
| 2066 | // start the pick activity |
| 2067 | startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); |
| 2068 | break; |
| 2069 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2070 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2071 | case AddAdapter.ITEM_LIVE_FOLDER: { |
| 2072 | // Insert extra item to handle inserting folder |
| 2073 | Bundle bundle = new Bundle(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2074 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2075 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 2076 | shortcutNames.add(res.getString(R.string.group_folder)); |
| 2077 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2078 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2079 | ArrayList<ShortcutIconResource> shortcutIcons = |
| 2080 | new ArrayList<ShortcutIconResource>(); |
| 2081 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 2082 | R.drawable.ic_launcher_folder)); |
| 2083 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 2084 | |
| 2085 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 2086 | pickIntent.putExtra(Intent.EXTRA_INTENT, |
| 2087 | new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER)); |
| 2088 | pickIntent.putExtra(Intent.EXTRA_TITLE, |
| 2089 | getText(R.string.title_select_live_folder)); |
| 2090 | pickIntent.putExtras(bundle); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2091 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2092 | startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER); |
| 2093 | break; |
| 2094 | } |
| 2095 | |
| 2096 | case AddAdapter.ITEM_WALLPAPER: { |
| 2097 | startWallpaper(); |
| 2098 | break; |
| 2099 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | /** |
| 2105 | * Receives notifications when applications are added/removed. |
| 2106 | */ |
| 2107 | private class ApplicationsIntentReceiver extends BroadcastReceiver { |
| 2108 | @Override |
| 2109 | public void onReceive(Context context, Intent intent) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2110 | final String action = intent.getAction(); |
| 2111 | final String packageName = intent.getData().getSchemeSpecificPart(); |
| 2112 | final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); |
| 2113 | |
| 2114 | if (LauncherModel.DEBUG_LOADERS) { |
| 2115 | d(LauncherModel.LOG_TAG, "application intent received: " + action + |
| 2116 | ", replacing=" + replacing); |
| 2117 | d(LauncherModel.LOG_TAG, " --> " + intent.getData()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2118 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2119 | |
| 2120 | if (!Intent.ACTION_PACKAGE_CHANGED.equals(action)) { |
| 2121 | if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) { |
| 2122 | if (!replacing) { |
| 2123 | removeShortcutsForPackage(packageName); |
| 2124 | if (LauncherModel.DEBUG_LOADERS) { |
| 2125 | d(LauncherModel.LOG_TAG, " --> remove package"); |
| 2126 | } |
| 2127 | sModel.removePackage(Launcher.this, packageName); |
| 2128 | } |
| 2129 | // else, we are replacing the package, so a PACKAGE_ADDED will be sent |
| 2130 | // later, we will update the package at this time |
| 2131 | } else { |
| 2132 | if (!replacing) { |
| 2133 | if (LauncherModel.DEBUG_LOADERS) { |
| 2134 | d(LauncherModel.LOG_TAG, " --> add package"); |
| 2135 | } |
| 2136 | sModel.addPackage(Launcher.this, packageName); |
| 2137 | } else { |
| 2138 | if (LauncherModel.DEBUG_LOADERS) { |
| 2139 | d(LauncherModel.LOG_TAG, " --> update package " + packageName); |
| 2140 | } |
| 2141 | sModel.updatePackage(Launcher.this, packageName); |
| 2142 | updateShortcutsForPackage(packageName); |
| 2143 | } |
| 2144 | } |
| 2145 | removeDialog(DIALOG_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2146 | } else { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2147 | if (LauncherModel.DEBUG_LOADERS) { |
| 2148 | d(LauncherModel.LOG_TAG, " --> sync package " + packageName); |
| 2149 | } |
| 2150 | sModel.syncPackage(Launcher.this, packageName); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2151 | } |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | /** |
| 2156 | * Receives notifications whenever the user favorites have changed. |
| 2157 | */ |
| 2158 | private class FavoritesChangeObserver extends ContentObserver { |
| 2159 | public FavoritesChangeObserver() { |
| 2160 | super(new Handler()); |
| 2161 | } |
| 2162 | |
| 2163 | @Override |
| 2164 | public void onChange(boolean selfChange) { |
| 2165 | onFavoritesChanged(); |
| 2166 | } |
| 2167 | } |
| 2168 | |
| 2169 | /** |
| 2170 | * Receives intents from other applications to change the wallpaper. |
| 2171 | */ |
| 2172 | private static class WallpaperIntentReceiver extends BroadcastReceiver { |
| 2173 | private final Application mApplication; |
| 2174 | private WeakReference<Launcher> mLauncher; |
| 2175 | |
| 2176 | WallpaperIntentReceiver(Application application, Launcher launcher) { |
| 2177 | mApplication = application; |
| 2178 | setLauncher(launcher); |
| 2179 | } |
| 2180 | |
| 2181 | void setLauncher(Launcher launcher) { |
| 2182 | mLauncher = new WeakReference<Launcher>(launcher); |
| 2183 | } |
| 2184 | |
| 2185 | @Override |
| 2186 | public void onReceive(Context context, Intent intent) { |
| 2187 | // Load the wallpaper from the ApplicationContext and store it locally |
| 2188 | // until the Launcher Activity is ready to use it |
| 2189 | final Drawable drawable = mApplication.getWallpaper(); |
| 2190 | if (drawable instanceof BitmapDrawable) { |
| 2191 | sWallpaper = ((BitmapDrawable) drawable).getBitmap(); |
| 2192 | } else { |
| 2193 | throw new IllegalStateException("The wallpaper must be a BitmapDrawable."); |
| 2194 | } |
| 2195 | |
| 2196 | // If Launcher is alive, notify we have a new wallpaper |
| 2197 | if (mLauncher != null) { |
| 2198 | final Launcher launcher = mLauncher.get(); |
| 2199 | if (launcher != null) { |
| 2200 | launcher.loadWallpaper(); |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | private class DrawerManager implements SlidingDrawer.OnDrawerOpenListener, |
| 2207 | SlidingDrawer.OnDrawerCloseListener, SlidingDrawer.OnDrawerScrollListener { |
| 2208 | private boolean mOpen; |
| 2209 | |
| 2210 | public void onDrawerOpened() { |
| 2211 | if (!mOpen) { |
| 2212 | mHandleIcon.reverseTransition(150); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2213 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2214 | final Rect bounds = mWorkspace.mDrawerBounds; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2215 | offsetBoundsToDragLayer(bounds, mAllAppsGrid); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2216 | |
| 2217 | mOpen = true; |
| 2218 | } |
| 2219 | } |
| 2220 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2221 | private void offsetBoundsToDragLayer(Rect bounds, View view) { |
| 2222 | view.getDrawingRect(bounds); |
| 2223 | |
| 2224 | while (view != mDragLayer) { |
| 2225 | bounds.offset(view.getLeft(), view.getTop()); |
| 2226 | view = (View) view.getParent(); |
| 2227 | } |
| 2228 | } |
| 2229 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2230 | public void onDrawerClosed() { |
| 2231 | if (mOpen) { |
| 2232 | mHandleIcon.reverseTransition(150); |
| 2233 | mWorkspace.mDrawerBounds.setEmpty(); |
| 2234 | mOpen = false; |
| 2235 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2236 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2237 | mAllAppsGrid.setSelection(0); |
| 2238 | mAllAppsGrid.clearTextFilter(); |
| 2239 | } |
| 2240 | |
| 2241 | public void onScrollStarted() { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2242 | if (PROFILE_DRAWER) { |
| 2243 | android.os.Debug.startMethodTracing("/sdcard/launcher-drawer"); |
| 2244 | } |
| 2245 | |
| 2246 | mWorkspace.mDrawerContentWidth = mAllAppsGrid.getWidth(); |
| 2247 | mWorkspace.mDrawerContentHeight = mAllAppsGrid.getHeight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | public void onScrollEnded() { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2251 | if (PROFILE_DRAWER) { |
| 2252 | android.os.Debug.stopMethodTracing(); |
| 2253 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 2257 | private static class DesktopBinder extends Handler implements MessageQueue.IdleHandler { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2258 | static final int MESSAGE_BIND_ITEMS = 0x1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2259 | static final int MESSAGE_BIND_APPWIDGETS = 0x2; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2260 | static final int MESSAGE_BIND_DRAWER = 0x3; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2261 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2262 | // Number of items to bind in every pass |
| 2263 | static final int ITEMS_COUNT = 6; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2264 | |
| 2265 | private final ArrayList<ItemInfo> mShortcuts; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 2266 | private final LinkedList<LauncherAppWidgetInfo> mAppWidgets; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2267 | private final ApplicationsAdapter mDrawerAdapter; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2268 | private final WeakReference<Launcher> mLauncher; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2269 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2270 | public boolean mTerminate = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2271 | |
| 2272 | DesktopBinder(Launcher launcher, ArrayList<ItemInfo> shortcuts, |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2273 | ArrayList<LauncherAppWidgetInfo> appWidgets, |
| 2274 | ApplicationsAdapter drawerAdapter) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2275 | |
| 2276 | mLauncher = new WeakReference<Launcher>(launcher); |
| 2277 | mShortcuts = shortcuts; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2278 | mDrawerAdapter = drawerAdapter; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2279 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 2280 | // Sort widgets so active workspace is bound first |
| 2281 | final int currentScreen = launcher.mWorkspace.getCurrentScreen(); |
| 2282 | final int size = appWidgets.size(); |
| 2283 | mAppWidgets = new LinkedList<LauncherAppWidgetInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2284 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 2285 | for (int i = 0; i < size; i++) { |
| 2286 | LauncherAppWidgetInfo appWidgetInfo = appWidgets.get(i); |
| 2287 | if (appWidgetInfo.screen == currentScreen) { |
| 2288 | mAppWidgets.addFirst(appWidgetInfo); |
| 2289 | } else { |
| 2290 | mAppWidgets.addLast(appWidgetInfo); |
| 2291 | } |
| 2292 | } |
| 2293 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2294 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2295 | public void startBindingItems() { |
| 2296 | obtainMessage(MESSAGE_BIND_ITEMS, 0, mShortcuts.size()).sendToTarget(); |
| 2297 | } |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2298 | |
| 2299 | public void startBindingDrawer() { |
| 2300 | obtainMessage(MESSAGE_BIND_DRAWER).sendToTarget(); |
| 2301 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2302 | |
Jeffrey Sharkey | 2d132af | 2009-03-24 21:21:09 -0700 | [diff] [blame] | 2303 | public void startBindingAppWidgetsWhenIdle() { |
| 2304 | // Ask for notification when message queue becomes idle |
| 2305 | final MessageQueue messageQueue = Looper.myQueue(); |
| 2306 | messageQueue.addIdleHandler(this); |
| 2307 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2308 | |
Jeffrey Sharkey | 2d132af | 2009-03-24 21:21:09 -0700 | [diff] [blame] | 2309 | public boolean queueIdle() { |
| 2310 | // Queue is idle, so start binding items |
| 2311 | startBindingAppWidgets(); |
| 2312 | return false; |
| 2313 | } |
| 2314 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 2315 | public void startBindingAppWidgets() { |
| 2316 | obtainMessage(MESSAGE_BIND_APPWIDGETS).sendToTarget(); |
| 2317 | } |
| 2318 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2319 | @Override |
| 2320 | public void handleMessage(Message msg) { |
| 2321 | Launcher launcher = mLauncher.get(); |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 2322 | if (launcher == null || mTerminate) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2323 | return; |
| 2324 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2325 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2326 | switch (msg.what) { |
| 2327 | case MESSAGE_BIND_ITEMS: { |
| 2328 | launcher.bindItems(this, mShortcuts, msg.arg1, msg.arg2); |
| 2329 | break; |
| 2330 | } |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2331 | case MESSAGE_BIND_DRAWER: { |
| 2332 | launcher.bindDrawer(this, mDrawerAdapter); |
| 2333 | break; |
| 2334 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2335 | case MESSAGE_BIND_APPWIDGETS: { |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 2336 | launcher.bindAppWidgets(this, mAppWidgets); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2337 | break; |
| 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2342 | |
| 2343 | private class GesturesProcessor implements GestureOverlayView.OnGestureListener, |
| 2344 | GestureOverlayView.OnGesturePerformedListener { |
| 2345 | |
| 2346 | private final GestureMatcher mMatcher = new GestureMatcher(); |
| 2347 | |
| 2348 | GesturesProcessor() { |
| 2349 | // TODO: Maybe the load should happen on a background thread? |
| 2350 | sLibrary.load(); |
| 2351 | } |
| 2352 | |
| 2353 | public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame^] | 2354 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 2355 | if (!CONFIG_GESTURES_IMMEDIATE_MODE) { |
| 2356 | overlay.removeCallbacks(mMatcher); |
| 2357 | resetGesturesNextPrompt(); |
| 2358 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2359 | |
| 2360 | mGesturesAdd.setAlpha(128); |
| 2361 | mGesturesAdd.setEnabled(false); |
| 2362 | } |
| 2363 | |
| 2364 | public void onGesture(GestureOverlayView overlay, MotionEvent event) { |
| 2365 | } |
| 2366 | |
| 2367 | public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { |
| 2368 | } |
| 2369 | |
| 2370 | public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame^] | 2371 | if (CONFIG_GESTURES_IMMEDIATE_MODE) { |
| 2372 | mMatcher.gesture = overlay.getGesture(); |
| 2373 | if (mMatcher.gesture.getLength() < GesturesConstants.LENGTH_THRESHOLD) { |
| 2374 | overlay.clear(false); |
| 2375 | } else { |
| 2376 | mMatcher.run(); |
| 2377 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2378 | } else { |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame^] | 2379 | overlay.removeCallbacks(mMatcher); |
| 2380 | |
| 2381 | mMatcher.gesture = overlay.getGesture(); |
| 2382 | if (mMatcher.gesture.getLength() < GesturesConstants.LENGTH_THRESHOLD) { |
| 2383 | overlay.clear(false); |
| 2384 | } else { |
| 2385 | overlay.postDelayed(mMatcher, GesturesConstants.MATCH_DELAY); |
| 2386 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | private void matchGesture(Gesture gesture) { |
| 2391 | mGesturesAdd.setAlpha(255); |
| 2392 | mGesturesAdd.setEnabled(true); |
| 2393 | |
| 2394 | if (gesture != null) { |
| 2395 | final ArrayList<Prediction> predictions = sLibrary.recognize(gesture); |
| 2396 | |
| 2397 | if (DEBUG_GESTURES) { |
| 2398 | for (Prediction p : predictions) { |
| 2399 | d(LOG_TAG, String.format("name=%s, score=%f", p.name, p.score)); |
| 2400 | } |
| 2401 | } |
| 2402 | |
| 2403 | boolean match = false; |
| 2404 | if (predictions.size() > 0) { |
| 2405 | final Prediction prediction = predictions.get(0); |
| 2406 | if (prediction.score > GesturesConstants.PREDICTION_THRESHOLD) { |
| 2407 | match = true; |
| 2408 | |
| 2409 | ApplicationInfo info = sModel.queryGesture(Launcher.this, prediction.name); |
| 2410 | if (info != null) { |
| 2411 | updatePrompt(info); |
| 2412 | } |
| 2413 | } |
| 2414 | } |
| 2415 | |
| 2416 | if (!match){ |
| 2417 | setGesturesNextPrompt(null, getString(R.string.gestures_unknown)); |
| 2418 | } |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | private void updatePrompt(ApplicationInfo info) { |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame^] | 2423 | if (mGesturesAction.intent != null && |
| 2424 | info.intent.toURI().equals(mGesturesAction.intent.toURI()) && |
| 2425 | info.title.equals(((TextView) mGesturesPrompt.getCurrentView()).getText())) { |
| 2426 | return; |
| 2427 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2428 | setGesturesNextPrompt(info.icon, info.title); |
| 2429 | mGesturesAction.intent = info.intent; |
| 2430 | } |
| 2431 | |
| 2432 | public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) { |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame^] | 2433 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 2434 | if (!CONFIG_GESTURES_IMMEDIATE_MODE) { |
| 2435 | overlay.removeCallbacks(mMatcher); |
| 2436 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | void addGesture(String name, Gesture gesture) { |
| 2440 | sLibrary.addGesture(name, gesture); |
| 2441 | // TODO: On a background thread? |
| 2442 | sLibrary.save(); |
| 2443 | } |
| 2444 | |
| 2445 | void update(ApplicationInfo info, Gesture gesture) { |
| 2446 | mGesturesOverlay.setGesture(gesture); |
Romain Guy | b873424 | 2009-06-10 11:53:57 -0700 | [diff] [blame] | 2447 | updatePrompt(info); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | class GestureMatcher implements Runnable { |
| 2451 | Gesture gesture; |
| 2452 | |
| 2453 | public void run() { |
| 2454 | if (gesture != null) { |
| 2455 | matchGesture(gesture); |
| 2456 | } |
| 2457 | } |
| 2458 | } |
| 2459 | } |
| 2460 | |
| 2461 | private class GesturesAction implements View.OnClickListener { |
| 2462 | Intent intent; |
| 2463 | |
| 2464 | public void onClick(View v) { |
| 2465 | if (intent != null) { |
| 2466 | startActivitySafely(intent); |
| 2467 | } |
| 2468 | } |
| 2469 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2470 | } |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 2471 | |