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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | import android.app.Dialog; |
Mike LeBeau | 736cf28 | 2009-07-02 17:46:59 -0700 | [diff] [blame] | 22 | import android.app.ISearchManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 23 | import android.app.SearchManager; |
| 24 | import android.app.StatusBarManager; |
Dianne Hackborn | 8355ae3 | 2009-09-07 21:47:51 -0700 | [diff] [blame] | 25 | import android.app.WallpaperInfo; |
Dianne Hackborn | 107f839 | 2009-08-05 21:32:16 -0700 | [diff] [blame] | 26 | import android.app.WallpaperManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 29 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.content.DialogInterface; |
| 32 | import android.content.Intent; |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 33 | import android.content.Intent.ShortcutIconResource; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 8355ae3 | 2009-09-07 21:47:51 -0700 | [diff] [blame] | 35 | import android.content.pm.LabeledIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
| 37 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 39 | import android.content.res.Resources; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 40 | import android.database.ContentObserver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.graphics.Bitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | import android.os.Bundle; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 44 | import android.os.Handler; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 45 | import android.os.Parcelable; |
| 46 | import android.os.RemoteException; |
| 47 | import android.os.ServiceManager; |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 48 | import android.os.SystemClock; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 49 | import android.provider.LiveFolders; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | import android.text.Selection; |
| 51 | import android.text.SpannableStringBuilder; |
| 52 | import android.text.TextUtils; |
| 53 | import android.text.method.TextKeyListener; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 54 | import static android.util.Log.*; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 55 | import android.util.Log; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 56 | import android.view.Display; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | import android.view.KeyEvent; |
| 58 | import android.view.LayoutInflater; |
| 59 | import android.view.Menu; |
| 60 | import android.view.MenuItem; |
| 61 | import android.view.View; |
| 62 | import android.view.ViewGroup; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 63 | import android.view.View.OnLongClickListener; |
| 64 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 65 | import android.widget.EditText; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 66 | import android.widget.TextView; |
| 67 | import android.widget.Toast; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 68 | import android.appwidget.AppWidgetManager; |
| 69 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 71 | import java.util.ArrayList; |
Joe Onorato | ad72e17 | 2009-11-06 16:25:04 -0500 | [diff] [blame] | 72 | import java.util.Map.Entry; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 73 | import java.util.HashMap; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 74 | import java.io.DataOutputStream; |
| 75 | import java.io.FileNotFoundException; |
| 76 | import java.io.IOException; |
| 77 | import java.io.DataInputStream; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Default launcher application. |
| 81 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 82 | public final class Launcher extends Activity |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 83 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 84 | static final String LOG_TAG = "Launcher"; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 85 | static final String TAG = LOG_TAG; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 86 | static final boolean LOGD = false; |
| 87 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 88 | static final boolean PROFILE_STARTUP = false; |
| 89 | static final boolean PROFILE_ROTATE = false; |
| 90 | static final boolean DEBUG_USER_INTERFACE = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 91 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 92 | private static final int WALLPAPER_SCREENS_SPAN = 2; |
| 93 | |
| 94 | private static final int MENU_GROUP_ADD = 1; |
| 95 | private static final int MENU_ADD = Menu.FIRST + 1; |
| 96 | private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1; |
| 97 | private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1; |
| 98 | private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1; |
Romain Guy | 94dabf1 | 2009-07-21 10:55:43 -0700 | [diff] [blame] | 99 | private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 100 | |
| 101 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
| 102 | private static final int REQUEST_CREATE_LIVE_FOLDER = 4; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 103 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 104 | private static final int REQUEST_PICK_APPLICATION = 6; |
| 105 | private static final int REQUEST_PICK_SHORTCUT = 7; |
| 106 | private static final int REQUEST_PICK_LIVE_FOLDER = 8; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 107 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 108 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 109 | |
| 110 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 111 | |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 112 | static final String EXTRA_CUSTOM_WIDGET = "custom_widget"; |
| 113 | static final String SEARCH_WIDGET = "search_widget"; |
| 114 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 115 | static final int SCREEN_COUNT = 5; |
| 116 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 117 | static final int NUMBER_CELLS_X = 4; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 118 | static final int NUMBER_CELLS_Y = 4; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 119 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 120 | static final int DIALOG_CREATE_SHORTCUT = 1; |
| 121 | static final int DIALOG_RENAME_FOLDER = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 122 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 123 | private static final String PREFERENCES = "launcher.preferences"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 124 | |
| 125 | // Type: int |
| 126 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
| 127 | // Type: boolean |
| 128 | private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder"; |
| 129 | // Type: long |
| 130 | private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder"; |
| 131 | // Type: int |
| 132 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 133 | // Type: int |
| 134 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX"; |
| 135 | // Type: int |
| 136 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY"; |
| 137 | // Type: int |
| 138 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX"; |
| 139 | // Type: int |
| 140 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY"; |
| 141 | // Type: int |
| 142 | private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX"; |
| 143 | // Type: int |
| 144 | private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY"; |
| 145 | // Type: int[] |
| 146 | private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells"; |
| 147 | // Type: boolean |
| 148 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 149 | // Type: long |
| 150 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; |
| 151 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 152 | static final int APPWIDGET_HOST_ID = 1024; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 154 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 155 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 156 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 157 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 158 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 159 | private LayoutInflater mInflater; |
| 160 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 161 | private DragController mDragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 162 | private Workspace mWorkspace; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 163 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 164 | private AppWidgetManager mAppWidgetManager; |
| 165 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 166 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 167 | private CellLayout.CellInfo mAddItemCellInfo; |
| 168 | private CellLayout.CellInfo mMenuAddInfo; |
| 169 | private final int[] mCellCoordinates = new int[2]; |
| 170 | private FolderInfo mFolderInfo; |
| 171 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 172 | private DeleteZone mDeleteZone; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 173 | private HandleView mHandleView; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 174 | private AllAppsView mAllAppsGrid; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 175 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 176 | private Bundle mSavedState; |
| 177 | |
| 178 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 179 | |
Mike LeBeau | 736cf28 | 2009-07-02 17:46:59 -0700 | [diff] [blame] | 180 | private boolean mIsNewIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 181 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 182 | private boolean mWorkspaceLoading = true; |
| 183 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 184 | private boolean mRestoring; |
| 185 | private boolean mWaitingForResult; |
Joe Onorato | ff3862d | 2009-10-07 10:35:51 -0700 | [diff] [blame] | 186 | private boolean mExitingBecauseOfLaunch; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 187 | |
| 188 | private Bundle mSavedInstanceState; |
| 189 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 190 | private LauncherModel mModel; |
| 191 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 192 | private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>(); |
| 193 | private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 194 | |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 195 | public static long lastStartTime; |
| 196 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 197 | @Override |
| 198 | protected void onCreate(Bundle savedInstanceState) { |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 199 | lastStartTime = SystemClock.uptimeMillis(); |
| 200 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 201 | super.onCreate(savedInstanceState); |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 202 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 203 | mModel = ((LauncherApplication)getApplication()).setLauncher(this); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 204 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 205 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 206 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 207 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 208 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 209 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 210 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 211 | if (PROFILE_STARTUP) { |
| 212 | android.os.Debug.startMethodTracing("/sdcard/launcher"); |
| 213 | } |
| 214 | |
| 215 | checkForLocaleChange(); |
| 216 | setWallpaperDimension(); |
| 217 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 218 | setContentView(R.layout.launcher); |
| 219 | setupViews(); |
| 220 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 221 | registerContentObservers(); |
| 222 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 223 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 224 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 225 | mSavedState = savedInstanceState; |
| 226 | restoreState(mSavedState); |
| 227 | |
| 228 | if (PROFILE_STARTUP) { |
| 229 | android.os.Debug.stopMethodTracing(); |
| 230 | } |
| 231 | |
Joe Onorato | 1d8e7bb | 2009-10-15 19:49:43 -0700 | [diff] [blame] | 232 | // We have a new AllAppsView, we need to re-bind everything, and it could have |
| 233 | // changed in our absence. |
| 234 | mModel.setAllAppsDirty(); |
| 235 | mModel.setWorkspaceDirty(); |
| 236 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 237 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 238 | mModel.startLoader(this, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | // For handling default keys |
| 242 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 243 | Selection.setSelection(mDefaultKeySsb, 0); |
| 244 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 245 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 246 | private void checkForLocaleChange() { |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 247 | final LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 248 | readConfiguration(this, localeConfiguration); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 249 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 250 | final Configuration configuration = getResources().getConfiguration(); |
| 251 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 252 | final String previousLocale = localeConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 253 | final String locale = configuration.locale.toString(); |
| 254 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 255 | final int previousMcc = localeConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 256 | final int mcc = configuration.mcc; |
| 257 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 258 | final int previousMnc = localeConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 259 | final int mnc = configuration.mnc; |
| 260 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 261 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 262 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 263 | if (localeChanged) { |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 264 | localeConfiguration.locale = locale; |
| 265 | localeConfiguration.mcc = mcc; |
| 266 | localeConfiguration.mnc = mnc; |
| 267 | |
| 268 | writeConfiguration(this, localeConfiguration); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 269 | AppInfoCache.flush(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
| 273 | private static class LocaleConfiguration { |
| 274 | public String locale; |
| 275 | public int mcc = -1; |
| 276 | public int mnc = -1; |
| 277 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 278 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 279 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 280 | DataInputStream in = null; |
| 281 | try { |
| 282 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 283 | configuration.locale = in.readUTF(); |
| 284 | configuration.mcc = in.readInt(); |
| 285 | configuration.mnc = in.readInt(); |
| 286 | } catch (FileNotFoundException e) { |
| 287 | // Ignore |
| 288 | } catch (IOException e) { |
| 289 | // Ignore |
| 290 | } finally { |
| 291 | if (in != null) { |
| 292 | try { |
| 293 | in.close(); |
| 294 | } catch (IOException e) { |
| 295 | // Ignore |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 302 | DataOutputStream out = null; |
| 303 | try { |
| 304 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 305 | out.writeUTF(configuration.locale); |
| 306 | out.writeInt(configuration.mcc); |
| 307 | out.writeInt(configuration.mnc); |
| 308 | out.flush(); |
| 309 | } catch (FileNotFoundException e) { |
| 310 | // Ignore |
| 311 | } catch (IOException e) { |
| 312 | //noinspection ResultOfMethodCallIgnored |
| 313 | context.getFileStreamPath(PREFERENCES).delete(); |
| 314 | } finally { |
| 315 | if (out != null) { |
| 316 | try { |
| 317 | out.close(); |
| 318 | } catch (IOException e) { |
| 319 | // Ignore |
| 320 | } |
| 321 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | static int getScreen() { |
| 326 | synchronized (sLock) { |
| 327 | return sScreen; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | static void setScreen(int screen) { |
| 332 | synchronized (sLock) { |
| 333 | sScreen = screen; |
| 334 | } |
| 335 | } |
| 336 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 337 | private void setWallpaperDimension() { |
Dianne Hackborn | 107f839 | 2009-08-05 21:32:16 -0700 | [diff] [blame] | 338 | WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 339 | |
| 340 | Display display = getWindowManager().getDefaultDisplay(); |
| 341 | boolean isPortrait = display.getWidth() < display.getHeight(); |
| 342 | |
| 343 | final int width = isPortrait ? display.getWidth() : display.getHeight(); |
| 344 | final int height = isPortrait ? display.getHeight() : display.getWidth(); |
Dianne Hackborn | 6427180 | 2009-08-08 20:54:24 -0700 | [diff] [blame] | 345 | wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | @Override |
| 349 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 350 | mWaitingForResult = false; |
| 351 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 352 | // The pattern used here is that a user PICKs a specific application, |
| 353 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 354 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 355 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 356 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 357 | |
Romain Guy | 94dabf1 | 2009-07-21 10:55:43 -0700 | [diff] [blame] | 358 | if (resultCode == RESULT_OK && mAddItemCellInfo != null) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 359 | switch (requestCode) { |
| 360 | case REQUEST_PICK_APPLICATION: |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 361 | completeAddApplication(this, data, mAddItemCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 362 | break; |
| 363 | case REQUEST_PICK_SHORTCUT: |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 364 | processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 365 | break; |
| 366 | case REQUEST_CREATE_SHORTCUT: |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 367 | completeAddShortcut(data, mAddItemCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 368 | break; |
| 369 | case REQUEST_PICK_LIVE_FOLDER: |
| 370 | addLiveFolder(data); |
| 371 | break; |
| 372 | case REQUEST_CREATE_LIVE_FOLDER: |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 373 | completeAddLiveFolder(data, mAddItemCellInfo); |
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_PICK_APPWIDGET: |
| 376 | addAppWidget(data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 377 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 378 | case REQUEST_CREATE_APPWIDGET: |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 379 | completeAddAppWidget(data, mAddItemCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 380 | break; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 381 | case REQUEST_PICK_WALLPAPER: |
| 382 | // We just wanted the activity result here so we can clear mWaitingForResult |
| 383 | break; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 384 | } |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 385 | } else if ((requestCode == REQUEST_PICK_APPWIDGET || |
| 386 | requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED && |
| 387 | data != null) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 388 | // Clean up the appWidgetId if we canceled |
| 389 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
| 390 | if (appWidgetId != -1) { |
| 391 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 392 | } |
| 393 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | @Override |
| 397 | protected void onResume() { |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 398 | if (lastStartTime == 0) { |
| 399 | lastStartTime = SystemClock.uptimeMillis(); |
| 400 | } |
| 401 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 402 | super.onResume(); |
| 403 | |
| 404 | if (mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 405 | mWorkspaceLoading = true; |
| 406 | mModel.startLoader(this, true); |
| 407 | mRestoring = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 408 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 409 | |
Mike LeBeau | 736cf28 | 2009-07-02 17:46:59 -0700 | [diff] [blame] | 410 | // If this was a new intent (i.e., the mIsNewIntent flag got set to true by |
| 411 | // onNewIntent), then close the search dialog if needed, because it probably |
| 412 | // came from the user pressing 'home' (rather than, for example, pressing 'back'). |
| 413 | if (mIsNewIntent) { |
| 414 | // Post to a handler so that this happens after the search dialog tries to open |
| 415 | // itself again. |
| 416 | mWorkspace.post(new Runnable() { |
| 417 | public void run() { |
| 418 | ISearchManager searchManagerService = ISearchManager.Stub.asInterface( |
| 419 | ServiceManager.getService(Context.SEARCH_SERVICE)); |
| 420 | try { |
| 421 | searchManagerService.stopSearch(); |
| 422 | } catch (RemoteException e) { |
| 423 | e(LOG_TAG, "error stopping search", e); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 424 | } |
Mike LeBeau | 736cf28 | 2009-07-02 17:46:59 -0700 | [diff] [blame] | 425 | } |
| 426 | }); |
| 427 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 428 | |
Mike LeBeau | 736cf28 | 2009-07-02 17:46:59 -0700 | [diff] [blame] | 429 | mIsNewIntent = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 433 | protected void onPause() { |
| 434 | super.onPause(); |
Joe Onorato | ff3862d | 2009-10-07 10:35:51 -0700 | [diff] [blame] | 435 | if (mExitingBecauseOfLaunch) { |
| 436 | mExitingBecauseOfLaunch = false; |
| 437 | closeAllApps(false); |
| 438 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 439 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 440 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 441 | @Override |
| 442 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 443 | // Flag the loader to stop early before switching |
| 444 | mModel.stopLoader(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 445 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 446 | if (PROFILE_ROTATE) { |
| 447 | android.os.Debug.startMethodTracing("/sdcard/launcher-rotate"); |
| 448 | } |
| 449 | return null; |
| 450 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 451 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 452 | private boolean acceptFilter() { |
| 453 | final InputMethodManager inputManager = (InputMethodManager) |
| 454 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 455 | return !inputManager.isFullscreenMode(); |
| 456 | } |
| 457 | |
| 458 | @Override |
| 459 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 460 | boolean handled = super.onKeyDown(keyCode, event); |
| 461 | if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) { |
| 462 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 463 | keyCode, event); |
| 464 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 465 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 466 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 467 | // showSearchDialog() |
| 468 | // If there are multiple keystrokes before the search dialog takes focus, |
| 469 | // onSearchRequested() will be called for every keystroke, |
| 470 | // but it is idempotent, so it's fine. |
| 471 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | |
| 475 | return handled; |
| 476 | } |
| 477 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 478 | private String getTypedText() { |
| 479 | return mDefaultKeySsb.toString(); |
| 480 | } |
| 481 | |
| 482 | private void clearTypedText() { |
| 483 | mDefaultKeySsb.clear(); |
| 484 | mDefaultKeySsb.clearSpans(); |
| 485 | Selection.setSelection(mDefaultKeySsb, 0); |
| 486 | } |
| 487 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 488 | /** |
| 489 | * Restores the previous state, if it exists. |
| 490 | * |
| 491 | * @param savedState The previous state. |
| 492 | */ |
| 493 | private void restoreState(Bundle savedState) { |
| 494 | if (savedState == null) { |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); |
| 499 | if (currentScreen > -1) { |
| 500 | mWorkspace.setCurrentScreen(currentScreen); |
| 501 | } |
| 502 | |
| 503 | final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
| 504 | if (addScreen > -1) { |
| 505 | mAddItemCellInfo = new CellLayout.CellInfo(); |
| 506 | final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo; |
| 507 | addItemCellInfo.valid = true; |
| 508 | addItemCellInfo.screen = addScreen; |
| 509 | addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 510 | addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
| 511 | addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 512 | addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 513 | addItemCellInfo.findVacantCellsFromOccupied( |
| 514 | savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS), |
| 515 | savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X), |
| 516 | savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y)); |
| 517 | mRestoring = true; |
| 518 | } |
| 519 | |
| 520 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 521 | if (renameFolder) { |
| 522 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 523 | mFolderInfo = mModel.getFolderById(this, mFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 524 | mRestoring = true; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * Finds all the views we need and configure them properly. |
| 530 | */ |
| 531 | private void setupViews() { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 532 | DragController dragController = mDragController; |
| 533 | |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 534 | DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 535 | dragLayer.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 536 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 537 | mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 538 | mAllAppsGrid.setLauncher(this); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 539 | mAllAppsGrid.setDragController(dragController); |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 540 | mAllAppsGrid.setWillNotDraw(false); // We don't want a hole punched in our window. |
Mike Cleron | b6082fa0 | 2009-10-19 17:03:36 -0700 | [diff] [blame] | 541 | // Manage focusability manually since this thing is always visible |
| 542 | mAllAppsGrid.setFocusable(false); |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 543 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 544 | mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); |
| 545 | final Workspace workspace = mWorkspace; |
| 546 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 547 | DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone); |
| 548 | mDeleteZone = deleteZone; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 549 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 550 | mHandleView = (HandleView) findViewById(R.id.all_apps_button); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 551 | mHandleView.setLauncher(this); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 552 | mHandleView.setOnClickListener(this); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 553 | /* TODO |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 554 | TransitionDrawable handleIcon = (TransitionDrawable) mHandleView.getDrawable(); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 555 | handleIocon.setCrossFadeEnabled(true); |
| 556 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 557 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 558 | workspace.setOnLongClickListener(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 559 | workspace.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 560 | workspace.setLauncher(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 561 | |
| 562 | deleteZone.setLauncher(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 563 | deleteZone.setDragController(dragController); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 564 | deleteZone.setHandle(mHandleView); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 565 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 566 | dragController.setDragScoller(workspace); |
| 567 | dragController.setDragListener(deleteZone); |
| 568 | dragController.setScrollView(dragLayer); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 569 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 570 | // The order here is bottom to top. |
| 571 | dragController.addDropTarget(workspace); |
| 572 | dragController.addDropTarget(deleteZone); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Creates a view representing a shortcut. |
| 577 | * |
| 578 | * @param info The data structure describing the shortcut. |
| 579 | * |
| 580 | * @return A View inflated from R.layout.application. |
| 581 | */ |
| 582 | View createShortcut(ApplicationInfo info) { |
| 583 | return createShortcut(R.layout.application, |
| 584 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info); |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * Creates a view representing a shortcut inflated from the specified resource. |
| 589 | * |
| 590 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 591 | * @param parent The group the shortcut belongs to. |
| 592 | * @param info The data structure describing the shortcut. |
| 593 | * |
| 594 | * @return A View inflated from layoutResId. |
| 595 | */ |
| 596 | View createShortcut(int layoutResId, ViewGroup parent, ApplicationInfo info) { |
| 597 | TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false); |
| 598 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 599 | if (info.icon == null) { |
| 600 | info.icon = AppInfoCache.getIconDrawable(getPackageManager(), info); |
| 601 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 602 | if (!info.filtered) { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 603 | info.icon = Utilities.createIconThumbnail(info.icon, this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 604 | info.filtered = true; |
| 605 | } |
| 606 | |
| 607 | favorite.setCompoundDrawablesWithIntrinsicBounds(null, info.icon, null, null); |
| 608 | favorite.setText(info.title); |
| 609 | favorite.setTag(info); |
| 610 | favorite.setOnClickListener(this); |
| 611 | |
| 612 | return favorite; |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * Add an application shortcut to the workspace. |
| 617 | * |
| 618 | * @param data The intent describing the application. |
| 619 | * @param cellInfo The position on screen where to create the shortcut. |
| 620 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 621 | void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 622 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 623 | if (!findSingleSlot(cellInfo)) return; |
| 624 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 625 | final ApplicationInfo info = infoFromApplicationIntent(context, data); |
| 626 | if (info != null) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 627 | mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked()); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
| 631 | private static ApplicationInfo infoFromApplicationIntent(Context context, Intent data) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 632 | ComponentName component = data.getComponent(); |
| 633 | PackageManager packageManager = context.getPackageManager(); |
| 634 | ActivityInfo activityInfo = null; |
| 635 | try { |
| 636 | activityInfo = packageManager.getActivityInfo(component, 0 /* no flags */); |
| 637 | } catch (NameNotFoundException e) { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 638 | 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] | 639 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 640 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 641 | if (activityInfo != null) { |
| 642 | ApplicationInfo itemInfo = new ApplicationInfo(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 643 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 644 | itemInfo.title = activityInfo.loadLabel(packageManager); |
| 645 | if (itemInfo.title == null) { |
| 646 | itemInfo.title = activityInfo.name; |
| 647 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 648 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 649 | itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK | |
| 650 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 651 | itemInfo.icon = activityInfo.loadIcon(packageManager); |
| 652 | itemInfo.container = ItemInfo.NO_ID; |
| 653 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 654 | return itemInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 655 | } |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 656 | |
| 657 | return null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 658 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 659 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 660 | /** |
| 661 | * Add a shortcut to the workspace. |
| 662 | * |
| 663 | * @param data The intent describing the shortcut. |
| 664 | * @param cellInfo The position on screen where to create the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 665 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 666 | private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 667 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 668 | if (!findSingleSlot(cellInfo)) return; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 669 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 670 | final ApplicationInfo info = addShortcut(this, data, cellInfo, false); |
| 671 | |
| 672 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 673 | final View view = createShortcut(info); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 674 | mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, |
| 675 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 679 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 680 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 681 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 682 | * |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 683 | * @param data The intent describing the appWidgetId. |
| 684 | * @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] | 685 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 686 | private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 687 | Bundle extras = data.getExtras(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 688 | int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 689 | |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 690 | if (LOGD) d(LOG_TAG, "dumping extras content=" + extras.toString()); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 691 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 692 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 693 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 694 | // Calculate the grid spans needed to fit this widget |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 695 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 696 | int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 697 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 698 | // Try finding open space on Launcher screen |
| 699 | final int[] xy = mCellCoordinates; |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 700 | if (!findSlot(cellInfo, xy, spans[0], spans[1])) { |
| 701 | if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 702 | return; |
| 703 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 704 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 705 | // Build Launcher-specific widget info and save to database |
| 706 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 707 | launcherInfo.spanX = spans[0]; |
| 708 | launcherInfo.spanY = spans[1]; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 709 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 710 | LauncherModel.addItemToDatabase(this, launcherInfo, |
| 711 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 712 | mWorkspace.getCurrentScreen(), xy[0], xy[1], false); |
| 713 | |
| 714 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 715 | mDesktopItems.add(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 716 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 717 | // Perform actual inflation because we're live |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 718 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 719 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 720 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 721 | launcherInfo.hostView.setTag(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 722 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 723 | mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 724 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 725 | } |
| 726 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 727 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 728 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
| 729 | mDesktopItems.remove(launcherInfo); |
| 730 | launcherInfo.hostView = null; |
| 731 | } |
| 732 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 733 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 734 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | static ApplicationInfo addShortcut(Context context, Intent data, |
| 738 | CellLayout.CellInfo cellInfo, boolean notify) { |
| 739 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 740 | final ApplicationInfo info = infoFromShortcutIntent(context, data); |
| 741 | LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 742 | cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify); |
| 743 | |
| 744 | return info; |
| 745 | } |
| 746 | |
| 747 | private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 748 | Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); |
| 749 | String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
| 750 | Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); |
| 751 | |
| 752 | Drawable icon = null; |
| 753 | boolean filtered = false; |
| 754 | boolean customIcon = false; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 755 | ShortcutIconResource iconResource = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 756 | |
| 757 | if (bitmap != null) { |
| 758 | icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context)); |
| 759 | filtered = true; |
| 760 | customIcon = true; |
| 761 | } else { |
| 762 | Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 763 | if (extra != null && extra instanceof ShortcutIconResource) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 764 | try { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 765 | iconResource = (ShortcutIconResource) extra; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 766 | final PackageManager packageManager = context.getPackageManager(); |
| 767 | Resources resources = packageManager.getResourcesForApplication( |
| 768 | iconResource.packageName); |
| 769 | final int id = resources.getIdentifier(iconResource.resourceName, null, null); |
| 770 | icon = resources.getDrawable(id); |
| 771 | } catch (Exception e) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 772 | w(LOG_TAG, "Could not load shortcut icon: " + extra); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | if (icon == null) { |
| 778 | icon = context.getPackageManager().getDefaultActivityIcon(); |
| 779 | } |
| 780 | |
| 781 | final ApplicationInfo info = new ApplicationInfo(); |
| 782 | info.icon = icon; |
| 783 | info.filtered = filtered; |
| 784 | info.title = name; |
| 785 | info.intent = intent; |
| 786 | info.customIcon = customIcon; |
| 787 | info.iconResource = iconResource; |
| 788 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 789 | return info; |
| 790 | } |
| 791 | |
| 792 | @Override |
| 793 | protected void onNewIntent(Intent intent) { |
| 794 | super.onNewIntent(intent); |
| 795 | |
| 796 | // Close the menu |
| 797 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
| 798 | getWindow().closeAllPanels(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 799 | |
Joe Onorato | 742966b | 2009-10-07 10:26:17 -0700 | [diff] [blame] | 800 | // Whatever we were doing is hereby canceled. |
| 801 | mWaitingForResult = false; |
| 802 | |
Mike LeBeau | 736cf28 | 2009-07-02 17:46:59 -0700 | [diff] [blame] | 803 | // Set this flag so that onResume knows to close the search dialog if it's open, |
| 804 | // because this was a new intent (thus a press of 'home' or some such) rather than |
| 805 | // for example onResume being called when the user pressed the 'back' button. |
| 806 | mIsNewIntent = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 807 | |
| 808 | try { |
| 809 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 810 | // Unlock the workspace if the dialog was showing |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 811 | } catch (Exception e) { |
| 812 | // An exception is thrown if the dialog is not visible, which is fine |
| 813 | } |
| 814 | |
| 815 | try { |
| 816 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 817 | // Unlock the workspace if the dialog was showing |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 818 | } catch (Exception e) { |
| 819 | // An exception is thrown if the dialog is not visible, which is fine |
| 820 | } |
| 821 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 822 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != |
| 823 | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 824 | |
Romain Guy | 94dabf1 | 2009-07-21 10:55:43 -0700 | [diff] [blame] | 825 | if (!mWorkspace.isDefaultScreenShowing()) { |
| 826 | mWorkspace.moveToDefaultScreen(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 827 | } |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 828 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 829 | closeAllApps(true); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 830 | |
| 831 | final View v = getWindow().peekDecorView(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 832 | if (v != null && v.getWindowToken() != null) { |
| 833 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 834 | INPUT_METHOD_SERVICE); |
| 835 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
| 836 | } |
| 837 | } else { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 838 | closeAllApps(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | @Override |
| 844 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 845 | // Do not call super here |
| 846 | mSavedInstanceState = savedInstanceState; |
| 847 | } |
| 848 | |
| 849 | @Override |
| 850 | protected void onSaveInstanceState(Bundle outState) { |
| 851 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen()); |
| 852 | |
| 853 | final ArrayList<Folder> folders = mWorkspace.getOpenFolders(); |
| 854 | if (folders.size() > 0) { |
| 855 | final int count = folders.size(); |
| 856 | long[] ids = new long[count]; |
| 857 | for (int i = 0; i < count; i++) { |
| 858 | final FolderInfo info = folders.get(i).getInfo(); |
| 859 | ids[i] = info.id; |
| 860 | } |
| 861 | outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids); |
| 862 | } else { |
| 863 | super.onSaveInstanceState(outState); |
| 864 | } |
| 865 | |
Romain Guy | 3cf604f | 2009-06-16 13:12:53 -0700 | [diff] [blame] | 866 | final boolean isConfigurationChange = getChangingConfigurations() != 0; |
| 867 | |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 868 | // When the drawer is opened and we are saving the state because of a |
| 869 | // configuration change |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 870 | // TODO should not do this if the drawer is currently closing. |
| 871 | if (isAllAppsVisible() && isConfigurationChange) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 872 | outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 873 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 874 | |
| 875 | if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) { |
| 876 | final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo; |
| 877 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen); |
| 878 | |
| 879 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen); |
| 880 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX); |
| 881 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY); |
| 882 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX); |
| 883 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY); |
| 884 | outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX()); |
| 885 | outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY()); |
| 886 | outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS, |
| 887 | layout.getOccupiedCells()); |
| 888 | } |
| 889 | |
| 890 | if (mFolderInfo != null && mWaitingForResult) { |
| 891 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 892 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 898 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 899 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 900 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 901 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 902 | } catch (NullPointerException ex) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 903 | 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] | 904 | } |
| 905 | |
| 906 | TextKeyListener.getInstance().release(); |
| 907 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 908 | mModel.stopLoader(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 909 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 910 | unbindDesktopItems(); |
| 911 | AppInfoCache.unbindDrawables(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 912 | |
| 913 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | @Override |
| 917 | public void startActivityForResult(Intent intent, int requestCode) { |
Romain Guy | 08f9749 | 2009-06-29 14:41:20 -0700 | [diff] [blame] | 918 | if (requestCode >= 0) mWaitingForResult = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 919 | super.startActivityForResult(intent, requestCode); |
| 920 | } |
| 921 | |
| 922 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 923 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 924 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 925 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 926 | closeAllApps(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 927 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 928 | // Slide the search widget to the top, if it's on the current screen, |
| 929 | // otherwise show the search dialog immediately. |
| 930 | Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen(); |
| 931 | if (searchWidget == null) { |
| 932 | showSearchDialog(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 933 | } else { |
| 934 | searchWidget.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 935 | // show the currently typed text in the search widget while sliding |
| 936 | searchWidget.setQuery(getTypedText()); |
| 937 | } |
| 938 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 939 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 940 | /** |
| 941 | * Show the search dialog immediately, without changing the search widget. |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 942 | * |
| 943 | * @see Activity#startSearch(String, boolean, android.os.Bundle, boolean) |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 944 | */ |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 945 | void showSearchDialog(String initialQuery, boolean selectInitialQuery, |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 946 | Bundle appSearchData, boolean globalSearch) { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 947 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 948 | if (initialQuery == null) { |
| 949 | // Use any text typed in the launcher as the initial query |
| 950 | initialQuery = getTypedText(); |
| 951 | clearTypedText(); |
| 952 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 953 | if (appSearchData == null) { |
| 954 | appSearchData = new Bundle(); |
| 955 | appSearchData.putString(SearchManager.SOURCE, "launcher-search"); |
| 956 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 957 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 958 | final SearchManager searchManager = |
| 959 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 960 | |
| 961 | final Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen(); |
| 962 | if (searchWidget != null) { |
| 963 | // This gets called when the user leaves the search dialog to go back to |
| 964 | // the Launcher. |
| 965 | searchManager.setOnCancelListener(new SearchManager.OnCancelListener() { |
| 966 | public void onCancel() { |
| 967 | searchManager.setOnCancelListener(null); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 968 | stopSearch(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 969 | } |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 970 | }); |
| 971 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 972 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 973 | searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 974 | appSearchData, globalSearch); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 975 | } |
| 976 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 977 | /** |
| 978 | * Cancel search dialog if it is open. |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 979 | */ |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 980 | void stopSearch() { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 981 | // Close search dialog |
| 982 | SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
Bjorn Bringert | 0879cef | 2009-07-08 12:38:25 +0100 | [diff] [blame] | 983 | searchManager.stopSearch(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 984 | // Restore search widget to its normal position |
| 985 | Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen(); |
| 986 | if (searchWidget != null) { |
| 987 | searchWidget.stopSearch(false); |
| 988 | } |
| 989 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 990 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 991 | @Override |
| 992 | public boolean onCreateOptionsMenu(Menu menu) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 993 | if (isWorkspaceLocked()) { |
| 994 | return false; |
| 995 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 996 | |
| 997 | super.onCreateOptionsMenu(menu); |
| 998 | menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add) |
| 999 | .setIcon(android.R.drawable.ic_menu_add) |
| 1000 | .setAlphabeticShortcut('A'); |
| 1001 | menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) |
| 1002 | .setIcon(android.R.drawable.ic_menu_gallery) |
| 1003 | .setAlphabeticShortcut('W'); |
| 1004 | menu.add(0, MENU_SEARCH, 0, R.string.menu_search) |
| 1005 | .setIcon(android.R.drawable.ic_search_category_default) |
| 1006 | .setAlphabeticShortcut(SearchManager.MENU_KEY); |
| 1007 | menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications) |
| 1008 | .setIcon(com.android.internal.R.drawable.ic_menu_notifications) |
| 1009 | .setAlphabeticShortcut('N'); |
| 1010 | |
| 1011 | final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1012 | settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1013 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1014 | |
| 1015 | menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) |
| 1016 | .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') |
| 1017 | .setIntent(settings); |
| 1018 | |
| 1019 | return true; |
| 1020 | } |
| 1021 | |
| 1022 | @Override |
| 1023 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 1024 | super.onPrepareOptionsMenu(menu); |
| 1025 | |
| 1026 | mMenuAddInfo = mWorkspace.findAllVacantCells(null); |
| 1027 | menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid); |
| 1028 | |
| 1029 | return true; |
| 1030 | } |
| 1031 | |
| 1032 | @Override |
| 1033 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1034 | switch (item.getItemId()) { |
| 1035 | case MENU_ADD: |
| 1036 | addItems(); |
| 1037 | return true; |
| 1038 | case MENU_WALLPAPER_SETTINGS: |
| 1039 | startWallpaper(); |
| 1040 | return true; |
| 1041 | case MENU_SEARCH: |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1042 | onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1043 | return true; |
| 1044 | case MENU_NOTIFICATIONS: |
| 1045 | showNotifications(); |
| 1046 | return true; |
| 1047 | } |
| 1048 | |
| 1049 | return super.onOptionsItemSelected(item); |
| 1050 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1051 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1052 | /** |
| 1053 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1054 | * argument for {@link #startSearch} to true. |
| 1055 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1056 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1057 | @Override |
| 1058 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1059 | startSearch(null, false, null, true); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1060 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1063 | public boolean isWorkspaceLocked() { |
| 1064 | return mWorkspaceLoading || mWaitingForResult; |
| 1065 | } |
| 1066 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1067 | private void addItems() { |
Joe Onorato | e616866 | 2009-11-08 13:39:30 -0500 | [diff] [blame] | 1068 | closeAllApps(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1069 | showAddDialog(mMenuAddInfo); |
| 1070 | } |
| 1071 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1072 | void addAppWidget(Intent data) { |
| 1073 | // TODO: catch bad widget exception when sent |
| 1074 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1075 | |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1076 | String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET); |
| 1077 | if (SEARCH_WIDGET.equals(customWidget)) { |
| 1078 | // We don't need this any more, since this isn't a real app widget. |
| 1079 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 1080 | // add the search widget |
| 1081 | addSearch(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1082 | } else { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1083 | AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1084 | |
| 1085 | if (appWidget.configure != null) { |
| 1086 | // Launch over to configure widget, if needed |
| 1087 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
| 1088 | intent.setComponent(appWidget.configure); |
| 1089 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 1090 | |
| 1091 | startActivityForResult(intent, REQUEST_CREATE_APPWIDGET); |
| 1092 | } else { |
| 1093 | // Otherwise just add it |
| 1094 | onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data); |
| 1095 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1098 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1099 | void addSearch() { |
| 1100 | final Widget info = Widget.makeSearch(); |
| 1101 | final CellLayout.CellInfo cellInfo = mAddItemCellInfo; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1102 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1103 | final int[] xy = mCellCoordinates; |
| 1104 | final int spanX = info.spanX; |
| 1105 | final int spanY = info.spanY; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1106 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1107 | if (!findSlot(cellInfo, xy, spanX, spanY)) return; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1108 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1109 | LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 1110 | mWorkspace.getCurrentScreen(), xy[0], xy[1], false); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1111 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1112 | final View view = mInflater.inflate(info.layoutResource, null); |
| 1113 | view.setTag(info); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1114 | Search search = (Search) view.findViewById(R.id.widget_search); |
| 1115 | search.setLauncher(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1116 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1117 | mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY); |
| 1118 | } |
| 1119 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1120 | void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1121 | // Handle case where user selected "Applications" |
| 1122 | String applicationName = getResources().getString(R.string.group_applications); |
| 1123 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1124 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1125 | if (applicationName != null && applicationName.equals(shortcutName)) { |
| 1126 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1127 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1128 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1129 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1130 | pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1131 | startActivityForResult(pickIntent, requestCodeApplication); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1132 | } else { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1133 | startActivityForResult(intent, requestCodeShortcut); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1134 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | void addLiveFolder(Intent intent) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1138 | // Handle case where user selected "Folder" |
Jeffrey Sharkey | c4bbd0a | 2009-03-24 22:47:52 -0700 | [diff] [blame] | 1139 | String folderName = getResources().getString(R.string.group_folder); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1140 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1141 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1142 | if (folderName != null && folderName.equals(shortcutName)) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1143 | addFolder(); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1144 | } else { |
| 1145 | startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER); |
| 1146 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1147 | } |
| 1148 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1149 | void addFolder() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1150 | UserFolderInfo folderInfo = new UserFolderInfo(); |
| 1151 | folderInfo.title = getText(R.string.folder_name); |
| 1152 | |
| 1153 | CellLayout.CellInfo cellInfo = mAddItemCellInfo; |
| 1154 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 1155 | if (!findSingleSlot(cellInfo)) return; |
| 1156 | |
| 1157 | // Update the model |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1158 | LauncherModel.addItemToDatabase(this, folderInfo, |
| 1159 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1160 | mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1161 | mFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1162 | |
| 1163 | // Create the view |
| 1164 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
| 1165 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo); |
| 1166 | mWorkspace.addInCurrentScreen(newFolder, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1167 | cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1168 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1169 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1170 | void removeFolder(FolderInfo folder) { |
| 1171 | mFolders.remove(folder.id); |
| 1172 | } |
| 1173 | |
| 1174 | private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1175 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 1176 | if (!findSingleSlot(cellInfo)) return; |
| 1177 | |
| 1178 | final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false); |
| 1179 | |
| 1180 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1181 | final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this, |
| 1182 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1183 | mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, |
| 1184 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | static LiveFolderInfo addLiveFolder(Context context, Intent data, |
| 1189 | CellLayout.CellInfo cellInfo, boolean notify) { |
| 1190 | |
| 1191 | Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT); |
| 1192 | String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME); |
| 1193 | |
| 1194 | Drawable icon = null; |
| 1195 | boolean filtered = false; |
| 1196 | Intent.ShortcutIconResource iconResource = null; |
| 1197 | |
| 1198 | Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON); |
| 1199 | if (extra != null && extra instanceof Intent.ShortcutIconResource) { |
| 1200 | try { |
| 1201 | iconResource = (Intent.ShortcutIconResource) extra; |
| 1202 | final PackageManager packageManager = context.getPackageManager(); |
| 1203 | Resources resources = packageManager.getResourcesForApplication( |
| 1204 | iconResource.packageName); |
| 1205 | final int id = resources.getIdentifier(iconResource.resourceName, null, null); |
| 1206 | icon = resources.getDrawable(id); |
| 1207 | } catch (Exception e) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1208 | 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] | 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | if (icon == null) { |
| 1213 | icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder); |
| 1214 | } |
| 1215 | |
| 1216 | final LiveFolderInfo info = new LiveFolderInfo(); |
| 1217 | info.icon = icon; |
| 1218 | info.filtered = filtered; |
| 1219 | info.title = name; |
| 1220 | info.iconResource = iconResource; |
| 1221 | info.uri = data.getData(); |
| 1222 | info.baseIntent = baseIntent; |
| 1223 | info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, |
| 1224 | LiveFolders.DISPLAY_MODE_GRID); |
| 1225 | |
| 1226 | LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 1227 | cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1228 | mFolders.put(info.id, info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1229 | |
| 1230 | return info; |
| 1231 | } |
| 1232 | |
| 1233 | private boolean findSingleSlot(CellLayout.CellInfo cellInfo) { |
| 1234 | final int[] xy = new int[2]; |
| 1235 | if (findSlot(cellInfo, xy, 1, 1)) { |
| 1236 | cellInfo.cellX = xy[0]; |
| 1237 | cellInfo.cellY = xy[1]; |
| 1238 | return true; |
| 1239 | } |
| 1240 | return false; |
| 1241 | } |
| 1242 | |
| 1243 | private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) { |
| 1244 | if (!cellInfo.findCellForSpan(xy, spanX, spanY)) { |
| 1245 | boolean[] occupied = mSavedState != null ? |
| 1246 | mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null; |
| 1247 | cellInfo = mWorkspace.findAllVacantCells(occupied); |
| 1248 | if (!cellInfo.findCellForSpan(xy, spanX, spanY)) { |
| 1249 | Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show(); |
| 1250 | return false; |
| 1251 | } |
| 1252 | } |
| 1253 | return true; |
| 1254 | } |
| 1255 | |
| 1256 | private void showNotifications() { |
| 1257 | final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE); |
| 1258 | if (statusBar != null) { |
| 1259 | statusBar.expand(); |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | private void startWallpaper() { |
Joe Onorato | e616866 | 2009-11-08 13:39:30 -0500 | [diff] [blame] | 1264 | closeAllApps(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1265 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
Dianne Hackborn | 8355ae3 | 2009-09-07 21:47:51 -0700 | [diff] [blame] | 1266 | Intent chooser = Intent.createChooser(pickWallpaper, |
| 1267 | getText(R.string.chooser_wallpaper)); |
| 1268 | WallpaperManager wm = (WallpaperManager) |
| 1269 | getSystemService(Context.WALLPAPER_SERVICE); |
| 1270 | WallpaperInfo wi = wm.getWallpaperInfo(); |
| 1271 | if (wi != null && wi.getSettingsActivity() != null) { |
| 1272 | LabeledIntent li = new LabeledIntent(getPackageName(), |
| 1273 | R.string.configure_wallpaper, 0); |
| 1274 | li.setClassName(wi.getPackageName(), wi.getSettingsActivity()); |
| 1275 | chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li }); |
| 1276 | } |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 1277 | startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 1280 | private void registerContentObservers() { |
| 1281 | ContentResolver resolver = getContentResolver(); |
| 1282 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 1283 | true, mWidgetObserver); |
| 1284 | } |
| 1285 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1286 | @Override |
| 1287 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 1288 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 1289 | switch (event.getKeyCode()) { |
| 1290 | case KeyEvent.KEYCODE_BACK: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1291 | return true; |
| 1292 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1293 | return true; |
| 1294 | } |
| 1295 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 1296 | switch (event.getKeyCode()) { |
| 1297 | case KeyEvent.KEYCODE_BACK: |
| 1298 | if (!event.isCanceled()) { |
| 1299 | mWorkspace.dispatchKeyEvent(event); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1300 | if (isAllAppsVisible()) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1301 | closeAllApps(true); |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1302 | } else { |
| 1303 | closeFolder(); |
| 1304 | } |
| 1305 | } |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1306 | return true; |
| 1307 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1308 | return true; |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | return super.dispatchKeyEvent(event); |
| 1313 | } |
| 1314 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1315 | private void closeFolder() { |
| 1316 | Folder folder = mWorkspace.getOpenFolder(); |
| 1317 | if (folder != null) { |
| 1318 | closeFolder(folder); |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | void closeFolder(Folder folder) { |
| 1323 | folder.getInfo().opened = false; |
| 1324 | ViewGroup parent = (ViewGroup) folder.getParent(); |
| 1325 | if (parent != null) { |
| 1326 | parent.removeView(folder); |
Joe Onorato | b6341e9 | 2009-11-02 10:41:48 -0500 | [diff] [blame] | 1327 | if (folder instanceof DropTarget) { |
| 1328 | // Live folders aren't DropTargets. |
| 1329 | mDragController.removeDropTarget((DropTarget)folder); |
| 1330 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1331 | } |
| 1332 | folder.onClose(); |
| 1333 | } |
| 1334 | |
| 1335 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 1336 | * Re-listen when widgets are reset. |
| 1337 | */ |
| 1338 | private void onAppWidgetReset() { |
| 1339 | mAppWidgetHost.startListening(); |
| 1340 | } |
| 1341 | |
| 1342 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1343 | * Go through the and disconnect any of the callbacks in the drawables and the views or we |
| 1344 | * leak the previous Home screen on orientation change. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1345 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1346 | private void unbindDesktopItems() { |
| 1347 | for (ItemInfo item: mDesktopItems) { |
| 1348 | item.unbind(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1349 | } |
| 1350 | } |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1351 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1352 | /** |
| 1353 | * Launches the intent referred by the clicked shortcut. |
| 1354 | * |
| 1355 | * @param v The view representing the clicked shortcut. |
| 1356 | */ |
| 1357 | public void onClick(View v) { |
| 1358 | Object tag = v.getTag(); |
| 1359 | if (tag instanceof ApplicationInfo) { |
| 1360 | // Open shortcut |
| 1361 | final Intent intent = ((ApplicationInfo) tag).intent; |
| 1362 | startActivitySafely(intent); |
Joe Onorato | ff3862d | 2009-10-07 10:35:51 -0700 | [diff] [blame] | 1363 | mExitingBecauseOfLaunch = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1364 | } else if (tag instanceof FolderInfo) { |
| 1365 | handleFolderClick((FolderInfo) tag); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1366 | } else if (v == mHandleView) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1367 | Log.d(TAG, "onClick"); |
| 1368 | if (isAllAppsVisible()) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1369 | closeAllApps(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1370 | } else { |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1371 | showAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1372 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | void startActivitySafely(Intent intent) { |
| 1377 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1378 | try { |
| 1379 | startActivity(intent); |
| 1380 | } catch (ActivityNotFoundException e) { |
| 1381 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 1382 | } catch (SecurityException e) { |
| 1383 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1384 | 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] | 1385 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
| 1386 | "or use the exported attribute for this activity.", e); |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | private void handleFolderClick(FolderInfo folderInfo) { |
| 1391 | if (!folderInfo.opened) { |
| 1392 | // Close any open folder |
| 1393 | closeFolder(); |
| 1394 | // Open the requested folder |
| 1395 | openFolder(folderInfo); |
| 1396 | } else { |
| 1397 | // Find the open folder... |
| 1398 | Folder openFolder = mWorkspace.getFolderForTag(folderInfo); |
| 1399 | int folderScreen; |
| 1400 | if (openFolder != null) { |
| 1401 | folderScreen = mWorkspace.getScreenForView(openFolder); |
| 1402 | // .. and close it |
| 1403 | closeFolder(openFolder); |
| 1404 | if (folderScreen != mWorkspace.getCurrentScreen()) { |
| 1405 | // Close any folder open on the current screen |
| 1406 | closeFolder(); |
| 1407 | // Pull the folder onto this screen |
| 1408 | openFolder(folderInfo); |
| 1409 | } |
| 1410 | } |
| 1411 | } |
| 1412 | } |
| 1413 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1414 | /** |
| 1415 | * Opens the user fodler described by the specified tag. The opening of the folder |
| 1416 | * is animated relative to the specified View. If the View is null, no animation |
| 1417 | * is played. |
| 1418 | * |
| 1419 | * @param folderInfo The FolderInfo describing the folder to open. |
| 1420 | */ |
| 1421 | private void openFolder(FolderInfo folderInfo) { |
| 1422 | Folder openFolder; |
| 1423 | |
| 1424 | if (folderInfo instanceof UserFolderInfo) { |
| 1425 | openFolder = UserFolder.fromXml(this); |
| 1426 | } else if (folderInfo instanceof LiveFolderInfo) { |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 1427 | openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1428 | } else { |
| 1429 | return; |
| 1430 | } |
| 1431 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1432 | openFolder.setDragController(mDragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1433 | openFolder.setLauncher(this); |
| 1434 | |
| 1435 | openFolder.bind(folderInfo); |
| 1436 | folderInfo.opened = true; |
| 1437 | |
| 1438 | mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4); |
| 1439 | openFolder.onOpen(); |
| 1440 | } |
| 1441 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1442 | public boolean onLongClick(View v) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1443 | if (isWorkspaceLocked()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1444 | return false; |
| 1445 | } |
| 1446 | |
| 1447 | if (!(v instanceof CellLayout)) { |
| 1448 | v = (View) v.getParent(); |
| 1449 | } |
| 1450 | |
| 1451 | CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag(); |
| 1452 | |
| 1453 | // This happens when long clicking an item with the dpad/trackball |
| 1454 | if (cellInfo == null) { |
| 1455 | return true; |
| 1456 | } |
| 1457 | |
| 1458 | if (mWorkspace.allowLongPress()) { |
| 1459 | if (cellInfo.cell == null) { |
| 1460 | if (cellInfo.valid) { |
| 1461 | // User long pressed on empty space |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1462 | mWorkspace.setAllowLongPress(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1463 | showAddDialog(cellInfo); |
| 1464 | } |
| 1465 | } else { |
| 1466 | if (!(cellInfo.cell instanceof Folder)) { |
| 1467 | // User long pressed on an item |
| 1468 | mWorkspace.startDrag(cellInfo); |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | return true; |
| 1473 | } |
| 1474 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1475 | View getDrawerHandle() { |
| 1476 | return mHandleView; |
| 1477 | } |
| 1478 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1479 | Workspace getWorkspace() { |
| 1480 | return mWorkspace; |
| 1481 | } |
| 1482 | |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1483 | /* TODO |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1484 | GridView getApplicationsGrid() { |
| 1485 | return mAllAppsGrid; |
| 1486 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1487 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1488 | |
| 1489 | @Override |
| 1490 | protected Dialog onCreateDialog(int id) { |
| 1491 | switch (id) { |
| 1492 | case DIALOG_CREATE_SHORTCUT: |
| 1493 | return new CreateShortcut().createDialog(); |
| 1494 | case DIALOG_RENAME_FOLDER: |
| 1495 | return new RenameFolder().createDialog(); |
| 1496 | } |
| 1497 | |
| 1498 | return super.onCreateDialog(id); |
| 1499 | } |
| 1500 | |
| 1501 | @Override |
| 1502 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 1503 | switch (id) { |
| 1504 | case DIALOG_CREATE_SHORTCUT: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1505 | break; |
| 1506 | case DIALOG_RENAME_FOLDER: |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1507 | if (mFolderInfo != null) { |
| 1508 | EditText input = (EditText) dialog.findViewById(R.id.folder_name); |
| 1509 | final CharSequence text = mFolderInfo.title; |
| 1510 | input.setText(text); |
| 1511 | input.setSelection(0, text.length()); |
| 1512 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1513 | break; |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | void showRenameDialog(FolderInfo info) { |
| 1518 | mFolderInfo = info; |
| 1519 | mWaitingForResult = true; |
| 1520 | showDialog(DIALOG_RENAME_FOLDER); |
| 1521 | } |
| 1522 | |
| 1523 | private void showAddDialog(CellLayout.CellInfo cellInfo) { |
| 1524 | mAddItemCellInfo = cellInfo; |
| 1525 | mWaitingForResult = true; |
| 1526 | showDialog(DIALOG_CREATE_SHORTCUT); |
| 1527 | } |
| 1528 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1529 | private void pickShortcut(int requestCode, int title) { |
| 1530 | Bundle bundle = new Bundle(); |
| 1531 | |
| 1532 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 1533 | shortcutNames.add(getString(R.string.group_applications)); |
| 1534 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
| 1535 | |
| 1536 | ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>(); |
| 1537 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 1538 | R.drawable.ic_launcher_application)); |
| 1539 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 1540 | |
| 1541 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1542 | pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT)); |
| 1543 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title)); |
| 1544 | pickIntent.putExtras(bundle); |
| 1545 | |
| 1546 | startActivityForResult(pickIntent, requestCode); |
| 1547 | } |
| 1548 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1549 | private class RenameFolder { |
| 1550 | private EditText mInput; |
| 1551 | |
| 1552 | Dialog createDialog() { |
| 1553 | mWaitingForResult = true; |
| 1554 | final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null); |
| 1555 | mInput = (EditText) layout.findViewById(R.id.folder_name); |
| 1556 | |
| 1557 | AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 1558 | builder.setIcon(0); |
| 1559 | builder.setTitle(getString(R.string.rename_folder_title)); |
| 1560 | builder.setCancelable(true); |
| 1561 | builder.setOnCancelListener(new Dialog.OnCancelListener() { |
| 1562 | public void onCancel(DialogInterface dialog) { |
| 1563 | cleanup(); |
| 1564 | } |
| 1565 | }); |
| 1566 | builder.setNegativeButton(getString(R.string.cancel_action), |
| 1567 | new Dialog.OnClickListener() { |
| 1568 | public void onClick(DialogInterface dialog, int which) { |
| 1569 | cleanup(); |
| 1570 | } |
| 1571 | } |
| 1572 | ); |
| 1573 | builder.setPositiveButton(getString(R.string.rename_action), |
| 1574 | new Dialog.OnClickListener() { |
| 1575 | public void onClick(DialogInterface dialog, int which) { |
| 1576 | changeFolderName(); |
| 1577 | } |
| 1578 | } |
| 1579 | ); |
| 1580 | builder.setView(layout); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1581 | |
| 1582 | final AlertDialog dialog = builder.create(); |
| 1583 | dialog.setOnShowListener(new DialogInterface.OnShowListener() { |
| 1584 | public void onShow(DialogInterface dialog) { |
Joe Onorato | d753b42 | 2009-11-08 13:31:11 -0500 | [diff] [blame] | 1585 | mInput.requestFocus(); |
| 1586 | InputMethodManager inputManager = (InputMethodManager) |
| 1587 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1588 | inputManager.showSoftInput(mInput, 0); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1589 | } |
| 1590 | }); |
| 1591 | |
| 1592 | return dialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | private void changeFolderName() { |
| 1596 | final String name = mInput.getText().toString(); |
| 1597 | if (!TextUtils.isEmpty(name)) { |
| 1598 | // Make sure we have the right folder info |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1599 | mFolderInfo = mFolders.get(mFolderInfo.id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1600 | mFolderInfo.title = name; |
| 1601 | LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo); |
| 1602 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1603 | if (mWorkspaceLoading) { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 1604 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1605 | mModel.setWorkspaceDirty(); |
| 1606 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1607 | } else { |
| 1608 | final FolderIcon folderIcon = (FolderIcon) |
| 1609 | mWorkspace.getViewForTag(mFolderInfo); |
| 1610 | if (folderIcon != null) { |
| 1611 | folderIcon.setText(name); |
| 1612 | getWorkspace().requestLayout(); |
| 1613 | } else { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 1614 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1615 | mModel.setWorkspaceDirty(); |
| 1616 | mWorkspaceLoading = true; |
| 1617 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | } |
| 1621 | cleanup(); |
| 1622 | } |
| 1623 | |
| 1624 | private void cleanup() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1625 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 1626 | mWaitingForResult = false; |
| 1627 | mFolderInfo = null; |
| 1628 | } |
| 1629 | } |
| 1630 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1631 | boolean isAllAppsVisible() { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1632 | return mAllAppsGrid.isVisible(); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1633 | } |
| 1634 | |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1635 | void showAllApps() { |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 1636 | mAllAppsGrid.zoom(1.0f); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1637 | //mWorkspace.hide(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1638 | |
Mike Cleron | b6082fa0 | 2009-10-19 17:03:36 -0700 | [diff] [blame] | 1639 | mAllAppsGrid.setFocusable(true); |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 1640 | mAllAppsGrid.requestFocus(); |
Mike Cleron | b6082fa0 | 2009-10-19 17:03:36 -0700 | [diff] [blame] | 1641 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 1642 | // TODO: fade these two too |
| 1643 | mDeleteZone.setVisibility(View.GONE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1644 | //mHandleView.setVisibility(View.GONE); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1645 | } |
| 1646 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1647 | void closeAllApps(boolean animated) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1648 | if (mAllAppsGrid.isVisible()) { |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 1649 | mAllAppsGrid.zoom(0.0f); |
Mike Cleron | b6082fa0 | 2009-10-19 17:03:36 -0700 | [diff] [blame] | 1650 | mAllAppsGrid.setFocusable(false); |
Joe Onorato | e77c08d | 2009-08-01 00:01:20 -0700 | [diff] [blame] | 1651 | mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus(); |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 1652 | |
Mike Cleron | b6082fa0 | 2009-10-19 17:03:36 -0700 | [diff] [blame] | 1653 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 1654 | // TODO: fade these two too |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1655 | /* |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 1656 | mDeleteZone.setVisibility(View.VISIBLE); |
| 1657 | mHandleView.setVisibility(View.VISIBLE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1658 | */ |
Joe Onorato | e77c08d | 2009-08-01 00:01:20 -0700 | [diff] [blame] | 1659 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 1662 | void lockAllApps() { |
| 1663 | // TODO |
| 1664 | } |
| 1665 | |
| 1666 | void unlockAllApps() { |
| 1667 | // TODO |
| 1668 | } |
| 1669 | |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1670 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1671 | * Displays the shortcut creation dialog and launches, if necessary, the |
| 1672 | * appropriate activity. |
| 1673 | */ |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1674 | private class CreateShortcut implements DialogInterface.OnClickListener, |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1675 | DialogInterface.OnCancelListener, DialogInterface.OnDismissListener, |
| 1676 | DialogInterface.OnShowListener { |
| 1677 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1678 | private AddAdapter mAdapter; |
Romain Guy | 9ffb543 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 1679 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1680 | Dialog createDialog() { |
| 1681 | mWaitingForResult = true; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1682 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1683 | mAdapter = new AddAdapter(Launcher.this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1684 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1685 | final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 1686 | builder.setTitle(getString(R.string.menu_item_add_item)); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1687 | builder.setAdapter(mAdapter, this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1688 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1689 | builder.setInverseBackgroundForced(true); |
| 1690 | |
| 1691 | AlertDialog dialog = builder.create(); |
| 1692 | dialog.setOnCancelListener(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1693 | dialog.setOnDismissListener(this); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1694 | dialog.setOnShowListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1695 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1696 | return dialog; |
| 1697 | } |
| 1698 | |
| 1699 | public void onCancel(DialogInterface dialog) { |
| 1700 | mWaitingForResult = false; |
| 1701 | cleanup(); |
| 1702 | } |
| 1703 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1704 | public void onDismiss(DialogInterface dialog) { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1707 | private void cleanup() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1708 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 1709 | } |
| 1710 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1711 | /** |
| 1712 | * Handle the action clicked in the "Add to home" dialog. |
| 1713 | */ |
| 1714 | public void onClick(DialogInterface dialog, int which) { |
| 1715 | Resources res = getResources(); |
| 1716 | cleanup(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1717 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1718 | switch (which) { |
| 1719 | case AddAdapter.ITEM_SHORTCUT: { |
| 1720 | // Insert extra item to handle picking application |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1721 | pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1722 | break; |
| 1723 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1724 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1725 | case AddAdapter.ITEM_APPWIDGET: { |
| 1726 | int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1727 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1728 | Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); |
| 1729 | pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 1730 | // add the search widget |
| 1731 | ArrayList<AppWidgetProviderInfo> customInfo = |
| 1732 | new ArrayList<AppWidgetProviderInfo>(); |
| 1733 | AppWidgetProviderInfo info = new AppWidgetProviderInfo(); |
| 1734 | info.provider = new ComponentName(getPackageName(), "XXX.YYY"); |
| 1735 | info.label = getString(R.string.group_search); |
| 1736 | info.icon = R.drawable.ic_search_widget; |
| 1737 | customInfo.add(info); |
| 1738 | pickIntent.putParcelableArrayListExtra( |
| 1739 | AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo); |
| 1740 | ArrayList<Bundle> customExtras = new ArrayList<Bundle>(); |
| 1741 | Bundle b = new Bundle(); |
| 1742 | b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET); |
| 1743 | customExtras.add(b); |
| 1744 | pickIntent.putParcelableArrayListExtra( |
| 1745 | AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras); |
| 1746 | // start the pick activity |
| 1747 | startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); |
| 1748 | break; |
| 1749 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1750 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1751 | case AddAdapter.ITEM_LIVE_FOLDER: { |
| 1752 | // Insert extra item to handle inserting folder |
| 1753 | Bundle bundle = new Bundle(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1754 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1755 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 1756 | shortcutNames.add(res.getString(R.string.group_folder)); |
| 1757 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1758 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1759 | ArrayList<ShortcutIconResource> shortcutIcons = |
| 1760 | new ArrayList<ShortcutIconResource>(); |
| 1761 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 1762 | R.drawable.ic_launcher_folder)); |
| 1763 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 1764 | |
| 1765 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1766 | pickIntent.putExtra(Intent.EXTRA_INTENT, |
| 1767 | new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER)); |
| 1768 | pickIntent.putExtra(Intent.EXTRA_TITLE, |
| 1769 | getText(R.string.title_select_live_folder)); |
| 1770 | pickIntent.putExtras(bundle); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1771 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1772 | startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER); |
| 1773 | break; |
| 1774 | } |
| 1775 | |
| 1776 | case AddAdapter.ITEM_WALLPAPER: { |
| 1777 | startWallpaper(); |
| 1778 | break; |
| 1779 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1780 | } |
| 1781 | } |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1782 | |
| 1783 | public void onShow(DialogInterface dialog) { |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1784 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame^] | 1788 | * Receives notifications whenever the appwidgets are reset. |
| 1789 | */ |
| 1790 | private class AppWidgetResetObserver extends ContentObserver { |
| 1791 | public AppWidgetResetObserver() { |
| 1792 | super(new Handler()); |
| 1793 | } |
| 1794 | |
| 1795 | @Override |
| 1796 | public void onChange(boolean selfChange) { |
| 1797 | onAppWidgetReset(); |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1802 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1803 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1804 | public int getCurrentWorkspaceScreen() { |
| 1805 | return mWorkspace.getCurrentScreen(); |
| 1806 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1807 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1808 | /** |
| 1809 | * Refreshes the shortcuts shown on the workspace. |
| 1810 | * |
| 1811 | * Implementation of the method from LauncherModel.Callbacks. |
| 1812 | */ |
| 1813 | public void startBinding() { |
| 1814 | final Workspace workspace = mWorkspace; |
| 1815 | int count = workspace.getChildCount(); |
| 1816 | for (int i = 0; i < count; i++) { |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 1817 | // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate(). |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1818 | ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); |
| 1819 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1820 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1821 | if (DEBUG_USER_INTERFACE) { |
| 1822 | android.widget.Button finishButton = new android.widget.Button(this); |
| 1823 | finishButton.setText("Finish"); |
| 1824 | workspace.addInScreen(finishButton, 1, 0, 0, 1, 1); |
| 1825 | |
| 1826 | finishButton.setOnClickListener(new android.widget.Button.OnClickListener() { |
| 1827 | public void onClick(View v) { |
| 1828 | finish(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1829 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1830 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1831 | } |
| 1832 | } |
| 1833 | |
| 1834 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1835 | * Bind the items start-end from the list. |
| 1836 | * |
| 1837 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1838 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1839 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { |
| 1840 | |
| 1841 | final Workspace workspace = mWorkspace; |
| 1842 | |
| 1843 | for (int i=start; i<end; i++) { |
| 1844 | final ItemInfo item = shortcuts.get(i); |
| 1845 | mDesktopItems.add(item); |
| 1846 | switch (item.itemType) { |
| 1847 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 1848 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 1849 | final View shortcut = createShortcut((ApplicationInfo) item); |
| 1850 | workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, |
| 1851 | false); |
| 1852 | break; |
| 1853 | case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: |
| 1854 | final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
| 1855 | (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()), |
| 1856 | (UserFolderInfo) item); |
| 1857 | workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 1858 | false); |
| 1859 | break; |
| 1860 | case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: |
| 1861 | final FolderIcon newLiveFolder = LiveFolderIcon.fromXml( |
| 1862 | R.layout.live_folder_icon, this, |
| 1863 | (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()), |
| 1864 | (LiveFolderInfo) item); |
| 1865 | workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 1866 | false); |
| 1867 | break; |
| 1868 | case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH: |
| 1869 | final int screen = workspace.getCurrentScreen(); |
| 1870 | final View view = mInflater.inflate(R.layout.widget_search, |
| 1871 | (ViewGroup) workspace.getChildAt(screen), false); |
| 1872 | |
| 1873 | Search search = (Search) view.findViewById(R.id.widget_search); |
| 1874 | search.setLauncher(this); |
| 1875 | |
| 1876 | final Widget widget = (Widget) item; |
| 1877 | view.setTag(widget); |
| 1878 | |
| 1879 | workspace.addWidget(view, widget, false); |
| 1880 | break; |
| 1881 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1882 | } |
| 1883 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1884 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1885 | } |
| 1886 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1887 | /** |
| 1888 | * Implementation of the method from LauncherModel.Callbacks. |
| 1889 | */ |
Joe Onorato | ad72e17 | 2009-11-06 16:25:04 -0500 | [diff] [blame] | 1890 | public void bindFolders(HashMap<Long, FolderInfo> folders) { |
| 1891 | mFolders.clear(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1892 | mFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1893 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1894 | |
| 1895 | /** |
| 1896 | * Add the views for a widget to the workspace. |
| 1897 | * |
| 1898 | * Implementation of the method from LauncherModel.Callbacks. |
| 1899 | */ |
| 1900 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
| 1901 | final Workspace workspace = mWorkspace; |
| 1902 | |
| 1903 | final int appWidgetId = item.appWidgetId; |
| 1904 | final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1905 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1906 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1907 | item.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1908 | item.hostView.setTag(item); |
| 1909 | |
| 1910 | workspace.addInScreen(item.hostView, item.screen, item.cellX, |
| 1911 | item.cellY, item.spanX, item.spanY, false); |
| 1912 | |
| 1913 | workspace.requestLayout(); |
| 1914 | |
| 1915 | mDesktopItems.add(item); |
| 1916 | } |
| 1917 | |
| 1918 | /** |
| 1919 | * Callback saying that there aren't any more items to bind. |
| 1920 | * |
| 1921 | * Implementation of the method from LauncherModel.Callbacks. |
| 1922 | */ |
| 1923 | public void finishBindingItems() { |
| 1924 | if (mSavedState != null) { |
| 1925 | if (!mWorkspace.hasFocus()) { |
| 1926 | mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus(); |
| 1927 | } |
| 1928 | |
| 1929 | final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS); |
| 1930 | if (userFolders != null) { |
| 1931 | for (long folderId : userFolders) { |
| 1932 | final FolderInfo info = mFolders.get(folderId); |
| 1933 | if (info != null) { |
| 1934 | openFolder(info); |
| 1935 | } |
| 1936 | } |
| 1937 | final Folder openFolder = mWorkspace.getOpenFolder(); |
| 1938 | if (openFolder != null) { |
| 1939 | openFolder.requestFocus(); |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | final boolean allApps = mSavedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false); |
| 1944 | if (allApps) { |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1945 | showAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | mSavedState = null; |
| 1949 | } |
| 1950 | |
| 1951 | if (mSavedInstanceState != null) { |
| 1952 | super.onRestoreInstanceState(mSavedInstanceState); |
| 1953 | mSavedInstanceState = null; |
| 1954 | } |
| 1955 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1956 | Log.d(TAG, "finishBindingItems done"); |
| 1957 | mWorkspaceLoading = false; |
| 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * Add the icons for all apps. |
| 1962 | * |
| 1963 | * Implementation of the method from LauncherModel.Callbacks. |
| 1964 | */ |
| 1965 | public void bindAllApplications(ArrayList<ApplicationInfo> apps) { |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 1966 | mAllAppsGrid.setApps(apps); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | /** |
| 1970 | * A package was installed. |
| 1971 | * |
| 1972 | * Implementation of the method from LauncherModel.Callbacks. |
| 1973 | */ |
| 1974 | public void bindPackageAdded(ArrayList<ApplicationInfo> apps) { |
| 1975 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1976 | mAllAppsGrid.addApps(apps); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | /** |
| 1980 | * A package was updated. |
| 1981 | * |
| 1982 | * Implementation of the method from LauncherModel.Callbacks. |
| 1983 | */ |
| 1984 | public void bindPackageUpdated(String packageName, ArrayList<ApplicationInfo> apps) { |
| 1985 | removeDialog(DIALOG_CREATE_SHORTCUT); |
| 1986 | mWorkspace.updateShortcutsForPackage(packageName); |
| 1987 | } |
| 1988 | |
| 1989 | /** |
| 1990 | * A package was uninstalled. |
| 1991 | * |
| 1992 | * Implementation of the method from LauncherModel.Callbacks. |
| 1993 | */ |
| 1994 | public void bindPackageRemoved(String packageName, ArrayList<ApplicationInfo> apps) { |
| 1995 | removeDialog(DIALOG_CREATE_SHORTCUT); |
| 1996 | mWorkspace.removeShortcutsForPackage(packageName); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1997 | mAllAppsGrid.removeApps(apps); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1998 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1999 | } |