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