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