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