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