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