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