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