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