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