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 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 19 | import com.android.common.Search; |
| 20 | import com.android.launcher.R; |
Bjorn Bringert | 3e244cf | 2010-02-10 14:17:35 +0000 | [diff] [blame] | 21 | |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 22 | import android.app.Activity; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 23 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 24 | import android.app.Dialog; |
| 25 | import android.app.SearchManager; |
| 26 | import android.app.StatusBarManager; |
Dianne Hackborn | 107f839 | 2009-08-05 21:32:16 -0700 | [diff] [blame] | 27 | import android.app.WallpaperManager; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 28 | import android.appwidget.AppWidgetManager; |
| 29 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 31 | import android.content.BroadcastReceiver; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 32 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 33 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | import android.content.Context; |
| 35 | import android.content.DialogInterface; |
| 36 | import android.content.Intent; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 37 | import android.content.Intent.ShortcutIconResource; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 38 | import android.content.IntentFilter; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 39 | import android.content.pm.ActivityInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 40 | import android.content.pm.PackageManager; |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 41 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 43 | import android.content.res.Resources; |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 44 | import android.content.res.TypedArray; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 45 | import android.database.ContentObserver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 46 | import android.graphics.Bitmap; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 47 | import android.graphics.Canvas; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 48 | import android.graphics.Rect; |
Romain Guy | ff0c2e2 | 2009-11-10 12:09:59 -0800 | [diff] [blame] | 49 | import android.graphics.drawable.ColorDrawable; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 50 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 51 | import android.net.Uri; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | import android.os.Bundle; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 53 | import android.os.Handler; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | import android.os.Parcelable; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 55 | import android.os.SystemClock; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 56 | import android.os.SystemProperties; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 57 | import android.provider.LiveFolders; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 58 | import android.text.Selection; |
| 59 | import android.text.SpannableStringBuilder; |
| 60 | import android.text.TextUtils; |
| 61 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 62 | import android.util.Log; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 63 | import android.view.Display; |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 64 | import android.view.HapticFeedbackConstants; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 65 | import android.view.KeyEvent; |
| 66 | import android.view.LayoutInflater; |
| 67 | import android.view.Menu; |
| 68 | import android.view.MenuItem; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 69 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | import android.view.View; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 71 | import android.view.View.OnLongClickListener; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | import android.view.ViewGroup; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 73 | import android.view.WindowManager; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 74 | import android.view.animation.Animation; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 75 | import android.view.animation.Animation.AnimationListener; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 76 | import android.view.animation.AnimationUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 77 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | import android.widget.EditText; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 79 | import android.widget.ImageView; |
| 80 | import android.widget.LinearLayout; |
| 81 | import android.widget.PopupWindow; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 82 | import android.widget.TabHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 83 | import android.widget.TextView; |
| 84 | import android.widget.Toast; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 85 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 86 | import java.io.DataInputStream; |
| 87 | import java.io.DataOutputStream; |
| 88 | import java.io.FileNotFoundException; |
| 89 | import java.io.IOException; |
| 90 | import java.util.ArrayList; |
| 91 | import java.util.HashMap; |
| 92 | import java.util.List; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 93 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | /** |
| 95 | * Default launcher application. |
| 96 | */ |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 97 | public final class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 98 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
| 99 | AllAppsView.Watcher, View.OnTouchListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 100 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 101 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 102 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 103 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 104 | static final boolean DEBUG_WIDGETS = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 105 | static final boolean DEBUG_USER_INTERFACE = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 106 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 107 | private static final int WALLPAPER_SCREENS_SPAN = 2; |
| 108 | |
| 109 | private static final int MENU_GROUP_ADD = 1; |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 110 | private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1; |
| 111 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 112 | private static final int MENU_ADD = Menu.FIRST + 1; |
| 113 | private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1; |
| 114 | private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1; |
| 115 | private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1; |
Romain Guy | 94dabf1 | 2009-07-21 10:55:43 -0700 | [diff] [blame] | 116 | private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 117 | |
| 118 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
| 119 | private static final int REQUEST_CREATE_LIVE_FOLDER = 4; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 120 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 121 | private static final int REQUEST_PICK_APPLICATION = 6; |
| 122 | private static final int REQUEST_PICK_SHORTCUT = 7; |
| 123 | private static final int REQUEST_PICK_LIVE_FOLDER = 8; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 124 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 125 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 126 | |
| 127 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 128 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 129 | static final int SCREEN_COUNT = 5; |
| 130 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 131 | static final int NUMBER_CELLS_X = 4; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 132 | static final int NUMBER_CELLS_Y = 4; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 133 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 134 | static final int DIALOG_CREATE_SHORTCUT = 1; |
| 135 | static final int DIALOG_RENAME_FOLDER = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 136 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 137 | private static final String PREFERENCES = "launcher.preferences"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 138 | |
| 139 | // Type: int |
| 140 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
| 141 | // Type: boolean |
| 142 | private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder"; |
| 143 | // Type: long |
| 144 | private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder"; |
| 145 | // Type: int |
| 146 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 147 | // Type: int |
| 148 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX"; |
| 149 | // Type: int |
| 150 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY"; |
| 151 | // Type: int |
| 152 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX"; |
| 153 | // Type: int |
| 154 | private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY"; |
| 155 | // Type: int |
| 156 | private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX"; |
| 157 | // Type: int |
| 158 | private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY"; |
| 159 | // Type: int[] |
| 160 | private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells"; |
| 161 | // Type: boolean |
| 162 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 163 | // Type: long |
| 164 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; |
| 165 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 166 | static final int APPWIDGET_HOST_ID = 1024; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 167 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 168 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 169 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 170 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 171 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 172 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 173 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 174 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 175 | private LayoutInflater mInflater; |
| 176 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 177 | private DragController mDragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 178 | private Workspace mWorkspace; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 179 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 180 | private AppWidgetManager mAppWidgetManager; |
| 181 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 182 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 183 | private CellLayout.CellInfo mAddItemCellInfo; |
| 184 | private CellLayout.CellInfo mMenuAddInfo; |
| 185 | private final int[] mCellCoordinates = new int[2]; |
| 186 | private FolderInfo mFolderInfo; |
| 187 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 188 | private DeleteZone mDeleteZone; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 189 | private HandleView mHandleView; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 190 | private AllAppsView mAllAppsGrid; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 191 | private TabHost mHomeCustomizationDrawer; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 192 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 193 | private Bundle mSavedState; |
| 194 | |
| 195 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 196 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 197 | private boolean mWorkspaceLoading = true; |
| 198 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 199 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 200 | private boolean mRestoring; |
| 201 | private boolean mWaitingForResult; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 202 | |
| 203 | private Bundle mSavedInstanceState; |
| 204 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 205 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 206 | private IconCache mIconCache; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 207 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 208 | private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>(); |
| 209 | private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 210 | |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 211 | private ImageView mPreviousView; |
| 212 | private ImageView mNextView; |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 213 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 214 | // Hotseats (quick-launch icons next to AllApps) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 215 | private static final int NUM_HOTSEATS = 2; |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 216 | private String[] mHotseatConfig = null; |
| 217 | private Intent[] mHotseats = null; |
| 218 | private Drawable[] mHotseatIcons = null; |
| 219 | private CharSequence[] mHotseatLabels = null; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 220 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 221 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 222 | @Override |
| 223 | protected void onCreate(Bundle savedInstanceState) { |
| 224 | super.onCreate(savedInstanceState); |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 225 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 226 | if (LauncherApplication.isInPlaceRotationEnabled()) { |
| 227 | // hide the status bar (temporary until we get the status bar design figured out) |
| 228 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 229 | this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); |
| 230 | } |
| 231 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 232 | LauncherApplication app = ((LauncherApplication)getApplication()); |
| 233 | mModel = app.setLauncher(this); |
| 234 | mIconCache = app.getIconCache(); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 235 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 236 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 237 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 238 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 239 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 240 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 241 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 242 | if (PROFILE_STARTUP) { |
| 243 | android.os.Debug.startMethodTracing("/sdcard/launcher"); |
| 244 | } |
| 245 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 246 | loadHotseats(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 247 | checkForLocaleChange(); |
| 248 | setWallpaperDimension(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 249 | setContentView(R.layout.launcher); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 250 | mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost); |
| 251 | if (mHomeCustomizationDrawer != null) { |
| 252 | mHomeCustomizationDrawer.setup(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 253 | |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 254 | String widgetsLabel = getString(R.string.widgets_tab_label); |
| 255 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec("widgets") |
| 256 | .setIndicator(widgetsLabel).setContent(R.id.widget_chooser)); |
| 257 | String foldersLabel = getString(R.string.folders_tab_label); |
| 258 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec("folders") |
| 259 | .setIndicator(foldersLabel).setContent(R.id.folder_chooser)); |
| 260 | String shortcutsLabel = getString(R.string.shortcuts_tab_label); |
| 261 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec("shortcuts") |
| 262 | .setIndicator(shortcutsLabel).setContent(R.id.shortcut_chooser)); |
| 263 | String wallpapersLabel = getString(R.string.wallpapers_tab_label); |
| 264 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec("wallpapers") |
| 265 | .setIndicator(wallpapersLabel).setContent(R.id.wallpaperstab)); |
| 266 | |
| 267 | mHomeCustomizationDrawer.setCurrentTab(0); |
| 268 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 269 | setupViews(); |
| 270 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 271 | registerContentObservers(); |
| 272 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 273 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 274 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 275 | mSavedState = savedInstanceState; |
| 276 | restoreState(mSavedState); |
| 277 | |
| 278 | if (PROFILE_STARTUP) { |
| 279 | android.os.Debug.stopMethodTracing(); |
| 280 | } |
| 281 | |
| 282 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 283 | mModel.startLoader(this, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // For handling default keys |
| 287 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 288 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 289 | |
| 290 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 291 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 292 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 293 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 294 | @Override |
| 295 | public void onConfigurationChanged(Configuration newConfig) { |
| 296 | // TODO Auto-generated method stub |
| 297 | super.onConfigurationChanged(newConfig); |
| 298 | |
| 299 | if (LauncherApplication.isInPlaceRotationEnabled()) { |
| 300 | mModel.updateOrientation(); |
| 301 | mWorkspace.refreshWorkspaceChildren(); |
| 302 | mWorkspace.rotateCurrentScreensChildren(); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 307 | private void checkForLocaleChange() { |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 308 | final LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 309 | readConfiguration(this, localeConfiguration); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 310 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 311 | final Configuration configuration = getResources().getConfiguration(); |
| 312 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 313 | final String previousLocale = localeConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 314 | final String locale = configuration.locale.toString(); |
| 315 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 316 | final int previousMcc = localeConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 317 | final int mcc = configuration.mcc; |
| 318 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 319 | final int previousMnc = localeConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 320 | final int mnc = configuration.mnc; |
| 321 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 322 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 323 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 324 | if (localeChanged) { |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 325 | localeConfiguration.locale = locale; |
| 326 | localeConfiguration.mcc = mcc; |
| 327 | localeConfiguration.mnc = mnc; |
| 328 | |
| 329 | writeConfiguration(this, localeConfiguration); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 330 | mIconCache.flush(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 331 | |
| 332 | loadHotseats(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | private static class LocaleConfiguration { |
| 337 | public String locale; |
| 338 | public int mcc = -1; |
| 339 | public int mnc = -1; |
| 340 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 341 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 342 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 343 | DataInputStream in = null; |
| 344 | try { |
| 345 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 346 | configuration.locale = in.readUTF(); |
| 347 | configuration.mcc = in.readInt(); |
| 348 | configuration.mnc = in.readInt(); |
| 349 | } catch (FileNotFoundException e) { |
| 350 | // Ignore |
| 351 | } catch (IOException e) { |
| 352 | // Ignore |
| 353 | } finally { |
| 354 | if (in != null) { |
| 355 | try { |
| 356 | in.close(); |
| 357 | } catch (IOException e) { |
| 358 | // Ignore |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 365 | DataOutputStream out = null; |
| 366 | try { |
| 367 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 368 | out.writeUTF(configuration.locale); |
| 369 | out.writeInt(configuration.mcc); |
| 370 | out.writeInt(configuration.mnc); |
| 371 | out.flush(); |
| 372 | } catch (FileNotFoundException e) { |
| 373 | // Ignore |
| 374 | } catch (IOException e) { |
| 375 | //noinspection ResultOfMethodCallIgnored |
| 376 | context.getFileStreamPath(PREFERENCES).delete(); |
| 377 | } finally { |
| 378 | if (out != null) { |
| 379 | try { |
| 380 | out.close(); |
| 381 | } catch (IOException e) { |
| 382 | // Ignore |
| 383 | } |
| 384 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | static int getScreen() { |
| 389 | synchronized (sLock) { |
| 390 | return sScreen; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | static void setScreen(int screen) { |
| 395 | synchronized (sLock) { |
| 396 | sScreen = screen; |
| 397 | } |
| 398 | } |
| 399 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 400 | private void setWallpaperDimension() { |
Dianne Hackborn | 107f839 | 2009-08-05 21:32:16 -0700 | [diff] [blame] | 401 | WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 402 | |
| 403 | Display display = getWindowManager().getDefaultDisplay(); |
| 404 | boolean isPortrait = display.getWidth() < display.getHeight(); |
| 405 | |
| 406 | final int width = isPortrait ? display.getWidth() : display.getHeight(); |
| 407 | final int height = isPortrait ? display.getHeight() : display.getWidth(); |
Dianne Hackborn | 6427180 | 2009-08-08 20:54:24 -0700 | [diff] [blame] | 408 | wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 409 | } |
| 410 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 411 | // Note: This doesn't do all the client-id magic that BrowserProvider does |
| 412 | // in Browser. (http://b/2425179) |
| 413 | private Uri getDefaultBrowserUri() { |
| 414 | String url = getString(R.string.default_browser_url); |
| 415 | if (url.indexOf("{CID}") != -1) { |
| 416 | url = url.replace("{CID}", "android-google"); |
| 417 | } |
| 418 | return Uri.parse(url); |
| 419 | } |
| 420 | |
| 421 | // Load the Intent templates from arrays.xml to populate the hotseats. For |
| 422 | // each Intent, if it resolves to a single app, use that as the launch |
| 423 | // intent & use that app's label as the contentDescription. Otherwise, |
| 424 | // retain the ResolveActivity so the user can pick an app. |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 425 | private void loadHotseats() { |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 426 | if (mHotseatConfig == null) { |
| 427 | mHotseatConfig = getResources().getStringArray(R.array.hotseats); |
| 428 | if (mHotseatConfig.length > 0) { |
| 429 | mHotseats = new Intent[mHotseatConfig.length]; |
| 430 | mHotseatLabels = new CharSequence[mHotseatConfig.length]; |
| 431 | mHotseatIcons = new Drawable[mHotseatConfig.length]; |
| 432 | } else { |
| 433 | mHotseats = null; |
| 434 | mHotseatIcons = null; |
| 435 | mHotseatLabels = null; |
| 436 | } |
| 437 | |
| 438 | TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons); |
| 439 | for (int i=0; i<mHotseatConfig.length; i++) { |
| 440 | // load icon for this slot; currently unrelated to the actual activity |
| 441 | try { |
| 442 | mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i); |
| 443 | } catch (ArrayIndexOutOfBoundsException ex) { |
| 444 | Log.w(TAG, "Missing hotseat_icons array item #" + i); |
| 445 | mHotseatIcons[i] = null; |
| 446 | } |
| 447 | } |
| 448 | hotseatIconDrawables.recycle(); |
| 449 | } |
| 450 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 451 | PackageManager pm = getPackageManager(); |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 452 | for (int i=0; i<mHotseatConfig.length; i++) { |
| 453 | Intent intent = null; |
| 454 | if (mHotseatConfig[i].equals("*BROWSER*")) { |
| 455 | // magic value meaning "launch user's default web browser" |
| 456 | // replace it with a generic web request so we can see if there is indeed a default |
| 457 | String defaultUri = getString(R.string.default_browser_url); |
| 458 | intent = new Intent( |
| 459 | Intent.ACTION_VIEW, |
| 460 | ((defaultUri != null) |
| 461 | ? Uri.parse(defaultUri) |
| 462 | : getDefaultBrowserUri()) |
| 463 | ).addCategory(Intent.CATEGORY_BROWSABLE); |
| 464 | // note: if the user launches this without a default set, she |
| 465 | // will always be taken to the default URL above; this is |
| 466 | // unavoidable as we must specify a valid URL in order for the |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 467 | // chooser to appear, and once the user selects something, that |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 468 | // URL is unavoidably sent to the chosen app. |
| 469 | } else { |
| 470 | try { |
| 471 | intent = Intent.parseUri(mHotseatConfig[i], 0); |
| 472 | } catch (java.net.URISyntaxException ex) { |
| 473 | Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]); |
| 474 | // bogus; leave intent=null |
| 475 | } |
| 476 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 477 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 478 | if (intent == null) { |
| 479 | mHotseats[i] = null; |
| 480 | mHotseatLabels[i] = getText(R.string.activity_not_found); |
| 481 | continue; |
| 482 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 483 | |
| 484 | if (LOGD) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 485 | Log.d(TAG, "loadHotseats: hotseat " + i |
| 486 | + " initial intent=[" |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 487 | + intent.toUri(Intent.URI_INTENT_SCHEME) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 488 | + "]"); |
| 489 | } |
| 490 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 491 | ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 492 | List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 493 | if (LOGD) { |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 494 | Log.d(TAG, "Best match for intent: " + bestMatch); |
| 495 | Log.d(TAG, "All matches: "); |
| 496 | for (ResolveInfo ri : allMatches) { |
| 497 | Log.d(TAG, " --> " + ri); |
| 498 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 499 | } |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 500 | // did this resolve to a single app, or the resolver? |
| 501 | if (allMatches.size() == 0 || bestMatch == null) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 502 | // can't find any activity to handle this. let's leave the |
| 503 | // intent as-is and let Launcher show a toast when it fails |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 504 | // to launch. |
| 505 | mHotseats[i] = intent; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 506 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 507 | // set accessibility text to "Not installed" |
| 508 | mHotseatLabels[i] = getText(R.string.activity_not_found); |
| 509 | } else { |
| 510 | boolean found = false; |
| 511 | for (ResolveInfo ri : allMatches) { |
| 512 | if (bestMatch.activityInfo.name.equals(ri.activityInfo.name) |
| 513 | && bestMatch.activityInfo.applicationInfo.packageName |
| 514 | .equals(ri.activityInfo.applicationInfo.packageName)) { |
| 515 | found = true; |
| 516 | break; |
| 517 | } |
| 518 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 519 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 520 | if (!found) { |
| 521 | if (LOGD) Log.d(TAG, "Multiple options, no default yet"); |
| 522 | // the bestMatch is probably the ResolveActivity, meaning the |
| 523 | // user has not yet selected a default |
| 524 | // so: we'll keep the original intent for now |
| 525 | mHotseats[i] = intent; |
| 526 | |
| 527 | // set the accessibility text to "Select shortcut" |
| 528 | mHotseatLabels[i] = getText(R.string.title_select_shortcut); |
| 529 | } else { |
| 530 | // we have an app! |
| 531 | // now reconstruct the intent to launch it through the front |
| 532 | // door |
| 533 | ComponentName com = new ComponentName( |
| 534 | bestMatch.activityInfo.applicationInfo.packageName, |
| 535 | bestMatch.activityInfo.name); |
| 536 | mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com); |
| 537 | |
| 538 | // load the app label for accessibility |
| 539 | mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm); |
| 540 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | if (LOGD) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 544 | Log.d(TAG, "loadHotseats: hotseat " + i |
| 545 | + " final intent=[" |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 546 | + ((mHotseats[i] == null) |
| 547 | ? "null" |
| 548 | : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME)) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 549 | + "] label=[" + mHotseatLabels[i] |
| 550 | + "]" |
| 551 | ); |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 556 | @Override |
| 557 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 558 | mWaitingForResult = false; |
| 559 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 560 | // The pattern used here is that a user PICKs a specific application, |
| 561 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 562 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 563 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 564 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 565 | |
Romain Guy | 94dabf1 | 2009-07-21 10:55:43 -0700 | [diff] [blame] | 566 | if (resultCode == RESULT_OK && mAddItemCellInfo != null) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 567 | switch (requestCode) { |
| 568 | case REQUEST_PICK_APPLICATION: |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 569 | completeAddApplication(this, data, mAddItemCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 570 | break; |
| 571 | case REQUEST_PICK_SHORTCUT: |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 572 | processShortcut(data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 573 | break; |
| 574 | case REQUEST_CREATE_SHORTCUT: |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 575 | completeAddShortcut(data, mAddItemCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 576 | break; |
| 577 | case REQUEST_PICK_LIVE_FOLDER: |
| 578 | addLiveFolder(data); |
| 579 | break; |
| 580 | case REQUEST_CREATE_LIVE_FOLDER: |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 581 | completeAddLiveFolder(data, mAddItemCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 582 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 583 | case REQUEST_PICK_APPWIDGET: |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 584 | addAppWidgetFromPick(data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 585 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 586 | case REQUEST_CREATE_APPWIDGET: |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 587 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 588 | completeAddAppWidget(appWidgetId, mAddItemCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 589 | break; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 590 | case REQUEST_PICK_WALLPAPER: |
| 591 | // We just wanted the activity result here so we can clear mWaitingForResult |
| 592 | break; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 593 | } |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 594 | } else if ((requestCode == REQUEST_PICK_APPWIDGET || |
| 595 | requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED && |
| 596 | data != null) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 597 | // Clean up the appWidgetId if we canceled |
| 598 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
| 599 | if (appWidgetId != -1) { |
| 600 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 601 | } |
| 602 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | @Override |
| 606 | protected void onResume() { |
| 607 | super.onResume(); |
| 608 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 609 | mPaused = false; |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 610 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 611 | if (mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 612 | mWorkspaceLoading = true; |
| 613 | mModel.startLoader(this, true); |
| 614 | mRestoring = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
| 618 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 619 | protected void onPause() { |
| 620 | super.onPause(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 621 | // Some launcher layouts don't have a previous and next view |
| 622 | if (mPreviousView != null) { |
| 623 | dismissPreview(mPreviousView); |
Patrick Dubroy | ab962b7 | 2010-07-26 12:10:10 -0700 | [diff] [blame] | 624 | } |
| 625 | if (mNextView != null) { |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 626 | dismissPreview(mNextView); |
| 627 | } |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 628 | mDragController.cancelDrag(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 629 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 630 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 631 | @Override |
| 632 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 633 | // Flag the loader to stop early before switching |
| 634 | mModel.stopLoader(); |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 635 | mAllAppsGrid.surrender(); |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 636 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 637 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 638 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 639 | // We can't hide the IME if it was forced open. So don't bother |
| 640 | /* |
| 641 | @Override |
| 642 | public void onWindowFocusChanged(boolean hasFocus) { |
| 643 | super.onWindowFocusChanged(hasFocus); |
| 644 | |
| 645 | if (hasFocus) { |
| 646 | final InputMethodManager inputManager = (InputMethodManager) |
| 647 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 648 | WindowManager.LayoutParams lp = getWindow().getAttributes(); |
| 649 | inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new |
| 650 | android.os.Handler()) { |
| 651 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 652 | Log.d(TAG, "ResultReceiver got resultCode=" + resultCode); |
| 653 | } |
| 654 | }); |
| 655 | Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged"); |
| 656 | } |
| 657 | } |
| 658 | */ |
| 659 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 660 | private boolean acceptFilter() { |
| 661 | final InputMethodManager inputManager = (InputMethodManager) |
| 662 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 663 | return !inputManager.isFullscreenMode(); |
| 664 | } |
| 665 | |
| 666 | @Override |
| 667 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 668 | boolean handled = super.onKeyDown(keyCode, event); |
| 669 | if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) { |
| 670 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 671 | keyCode, event); |
| 672 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 673 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 674 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 675 | // showSearchDialog() |
| 676 | // If there are multiple keystrokes before the search dialog takes focus, |
| 677 | // onSearchRequested() will be called for every keystroke, |
| 678 | // but it is idempotent, so it's fine. |
| 679 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 683 | // Eat the long press event so the keyboard doesn't come up. |
| 684 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 685 | return true; |
| 686 | } |
| 687 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 688 | return handled; |
| 689 | } |
| 690 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 691 | private String getTypedText() { |
| 692 | return mDefaultKeySsb.toString(); |
| 693 | } |
| 694 | |
| 695 | private void clearTypedText() { |
| 696 | mDefaultKeySsb.clear(); |
| 697 | mDefaultKeySsb.clearSpans(); |
| 698 | Selection.setSelection(mDefaultKeySsb, 0); |
| 699 | } |
| 700 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 701 | /** |
| 702 | * Restores the previous state, if it exists. |
| 703 | * |
| 704 | * @param savedState The previous state. |
| 705 | */ |
| 706 | private void restoreState(Bundle savedState) { |
| 707 | if (savedState == null) { |
| 708 | return; |
| 709 | } |
| 710 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 711 | final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false); |
| 712 | if (allApps) { |
| 713 | showAllApps(false); |
| 714 | } |
| 715 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 716 | final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); |
| 717 | if (currentScreen > -1) { |
| 718 | mWorkspace.setCurrentScreen(currentScreen); |
| 719 | } |
| 720 | |
| 721 | final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
| 722 | if (addScreen > -1) { |
| 723 | mAddItemCellInfo = new CellLayout.CellInfo(); |
| 724 | final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo; |
| 725 | addItemCellInfo.valid = true; |
| 726 | addItemCellInfo.screen = addScreen; |
| 727 | addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 728 | addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
| 729 | addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); |
| 730 | addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); |
| 731 | addItemCellInfo.findVacantCellsFromOccupied( |
| 732 | savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS), |
| 733 | savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X), |
| 734 | savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y)); |
| 735 | mRestoring = true; |
| 736 | } |
| 737 | |
| 738 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 739 | if (renameFolder) { |
| 740 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 741 | mFolderInfo = mModel.getFolderById(this, mFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 742 | mRestoring = true; |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * Finds all the views we need and configure them properly. |
| 748 | */ |
| 749 | private void setupViews() { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 750 | DragController dragController = mDragController; |
| 751 | |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 752 | DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 753 | dragLayer.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 754 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 755 | mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 756 | mAllAppsGrid.setLauncher(this); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 757 | mAllAppsGrid.setDragController(dragController); |
Romain Guy | c16fea7 | 2010-03-12 17:17:56 -0800 | [diff] [blame] | 758 | ((View) 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] | 759 | // Manage focusability manually since this thing is always visible |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 760 | ((View) mAllAppsGrid).setFocusable(false); |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 761 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 762 | mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); |
| 763 | final Workspace workspace = mWorkspace; |
Joe Onorato | f0dde09 | 2010-02-16 18:25:23 -0500 | [diff] [blame] | 764 | workspace.setHapticFeedbackEnabled(false); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 765 | |
| 766 | // We only intercept touch events to dismiss the home customization drawer; if it doesn't |
| 767 | // exist, then no need to do this |
| 768 | if (mHomeCustomizationDrawer != null) |
| 769 | workspace.setOnInterceptTouchListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 770 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 771 | DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone); |
| 772 | mDeleteZone = deleteZone; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 773 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 774 | mHandleView = (HandleView) findViewById(R.id.all_apps_button); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 775 | mHandleView.setLauncher(this); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 776 | mHandleView.setOnClickListener(this); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 777 | mHandleView.setOnLongClickListener(this); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 778 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 779 | WidgetChooser widgetChooser = (WidgetChooser) findViewById(R.id.widget_chooser); |
| 780 | if (widgetChooser != null) { |
| 781 | WidgetListAdapter widgetGalleryAdapter = new WidgetListAdapter(this); |
| 782 | widgetChooser.setAdapter(widgetGalleryAdapter); |
| 783 | widgetChooser.setDragController(dragController); |
| 784 | widgetChooser.setLauncher(this); |
| 785 | |
| 786 | FolderChooser folderChooser = (FolderChooser) findViewById(R.id.folder_chooser); |
| 787 | IntentListAdapter folderTypes = new FolderListAdapter(this, LiveFolders.ACTION_CREATE_LIVE_FOLDER); |
| 788 | folderChooser.setAdapter(folderTypes); |
| 789 | folderChooser.setLauncher(this); |
| 790 | |
| 791 | ShortcutChooser shortcutChooser = (ShortcutChooser) findViewById(R.id.shortcut_chooser); |
| 792 | IntentListAdapter shortcutTypes = new ShortcutListAdapter(this, Intent.ACTION_CREATE_SHORTCUT); |
| 793 | shortcutChooser.setAdapter(shortcutTypes); |
| 794 | shortcutChooser.setLauncher(this); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 795 | } else { |
| 796 | ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left); |
| 797 | hotseatLeft.setContentDescription(mHotseatLabels[0]); |
| 798 | hotseatLeft.setImageDrawable(mHotseatIcons[0]); |
| 799 | ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right); |
| 800 | hotseatRight.setContentDescription(mHotseatLabels[1]); |
| 801 | hotseatRight.setImageDrawable(mHotseatIcons[1]); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 802 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 803 | mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen); |
| 804 | mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 805 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 806 | Drawable previous = mPreviousView.getDrawable(); |
| 807 | Drawable next = mNextView.getDrawable(); |
| 808 | mWorkspace.setIndicators(previous, next); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 809 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 810 | mPreviousView.setHapticFeedbackEnabled(false); |
| 811 | mPreviousView.setOnLongClickListener(this); |
| 812 | mNextView.setHapticFeedbackEnabled(false); |
| 813 | mNextView.setOnLongClickListener(this); |
| 814 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 815 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 816 | workspace.setOnLongClickListener(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 817 | workspace.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 818 | workspace.setLauncher(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 819 | |
| 820 | deleteZone.setLauncher(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 821 | deleteZone.setDragController(dragController); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 822 | int deleteZoneHandleId = LauncherApplication.isScreenXLarge() ? R.id.add_button : R.id.all_apps_button_cluster; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 823 | deleteZone.setHandle(findViewById(deleteZoneHandleId)); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 824 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 825 | dragController.setDragScoller(workspace); |
| 826 | dragController.setDragListener(deleteZone); |
| 827 | dragController.setScrollView(dragLayer); |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 828 | dragController.setMoveTarget(workspace); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 829 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 830 | // The order here is bottom to top. |
| 831 | dragController.addDropTarget(workspace); |
| 832 | dragController.addDropTarget(deleteZone); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 833 | } |
| 834 | |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 835 | @SuppressWarnings({"UnusedDeclaration"}) |
| 836 | public void previousScreen(View v) { |
Joe Onorato | 61597bd | 2009-11-19 12:51:57 -0800 | [diff] [blame] | 837 | if (!isAllAppsVisible()) { |
| 838 | mWorkspace.scrollLeft(); |
| 839 | } |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | @SuppressWarnings({"UnusedDeclaration"}) |
| 843 | public void nextScreen(View v) { |
Joe Onorato | 61597bd | 2009-11-19 12:51:57 -0800 | [diff] [blame] | 844 | if (!isAllAppsVisible()) { |
| 845 | mWorkspace.scrollRight(); |
| 846 | } |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 847 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 848 | |
| 849 | @SuppressWarnings({"UnusedDeclaration"}) |
| 850 | public void launchHotSeat(View v) { |
Daniel Sandler | 3e9454a | 2010-05-24 11:22:41 -0400 | [diff] [blame] | 851 | if (isAllAppsVisible()) return; |
| 852 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 853 | int index = -1; |
| 854 | if (v.getId() == R.id.hotseat_left) { |
| 855 | index = 0; |
| 856 | } else if (v.getId() == R.id.hotseat_right) { |
| 857 | index = 1; |
| 858 | } |
| 859 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 860 | // reload these every tap; you never know when they might change |
| 861 | loadHotseats(); |
| 862 | if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) { |
| 863 | Intent intent = mHotseats[index]; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 864 | startActivitySafely( |
| 865 | mHotseats[index], |
| 866 | "hotseat" |
| 867 | ); |
| 868 | } |
| 869 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 870 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 871 | /** |
| 872 | * Creates a view representing a shortcut. |
| 873 | * |
| 874 | * @param info The data structure describing the shortcut. |
| 875 | * |
| 876 | * @return A View inflated from R.layout.application. |
| 877 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 878 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 879 | return createShortcut(R.layout.application, |
| 880 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info); |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * Creates a view representing a shortcut inflated from the specified resource. |
| 885 | * |
| 886 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 887 | * @param parent The group the shortcut belongs to. |
| 888 | * @param info The data structure describing the shortcut. |
| 889 | * |
| 890 | * @return A View inflated from layoutResId. |
| 891 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 892 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 893 | TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false); |
| 894 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 895 | favorite.setCompoundDrawablesWithIntrinsicBounds(null, |
| 896 | new FastBitmapDrawable(info.getIcon(mIconCache)), |
| 897 | null, null); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 898 | favorite.setText(info.title); |
| 899 | favorite.setTag(info); |
| 900 | favorite.setOnClickListener(this); |
| 901 | |
| 902 | return favorite; |
| 903 | } |
| 904 | |
| 905 | /** |
| 906 | * Add an application shortcut to the workspace. |
| 907 | * |
| 908 | * @param data The intent describing the application. |
| 909 | * @param cellInfo The position on screen where to create the shortcut. |
| 910 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 911 | void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 912 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 913 | if (!findSingleSlot(cellInfo)) return; |
| 914 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 915 | final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(), |
| 916 | data, context); |
| 917 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 918 | if (info != null) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 919 | info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 920 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 921 | info.container = ItemInfo.NO_ID; |
| 922 | mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked()); |
| 923 | } else { |
| 924 | Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 925 | } |
| 926 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 927 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 928 | /** |
| 929 | * Add a shortcut to the workspace. |
| 930 | * |
| 931 | * @param data The intent describing the shortcut. |
| 932 | * @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] | 933 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 934 | private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 935 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 936 | if (!findSingleSlot(cellInfo)) return; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 937 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 938 | final ShortcutInfo info = mModel.addShortcut(this, data, cellInfo, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 939 | |
| 940 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 941 | final View view = createShortcut(info); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 942 | mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, |
| 943 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 947 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 948 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 949 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 950 | * |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 951 | * @param data The intent describing the appWidgetId. |
| 952 | * @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] | 953 | */ |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 954 | private void completeAddAppWidget(int appWidgetId, CellLayout.CellInfo cellInfo) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 955 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 956 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 957 | // Calculate the grid spans needed to fit this widget |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 958 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen); |
Patrick Dubroy | 8f86ddc | 2010-07-16 13:55:32 -0700 | [diff] [blame] | 959 | int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 960 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 961 | // Try finding open space on Launcher screen |
| 962 | final int[] xy = mCellCoordinates; |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 963 | if (!findSlot(cellInfo, xy, spans[0], spans[1])) { |
| 964 | if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 965 | return; |
| 966 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 967 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 968 | // Build Launcher-specific widget info and save to database |
| 969 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 970 | launcherInfo.spanX = spans[0]; |
| 971 | launcherInfo.spanY = spans[1]; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 972 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 973 | LauncherModel.addItemToDatabase(this, launcherInfo, |
| 974 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 975 | mWorkspace.getCurrentScreen(), xy[0], xy[1], false); |
| 976 | |
| 977 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 978 | mDesktopItems.add(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 979 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 980 | // Perform actual inflation because we're live |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 981 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 982 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 983 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 984 | launcherInfo.hostView.setTag(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 985 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 986 | mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 987 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 988 | } |
| 989 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 990 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 991 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
| 992 | mDesktopItems.remove(launcherInfo); |
| 993 | launcherInfo.hostView = null; |
| 994 | } |
| 995 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 996 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 997 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 998 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 999 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1000 | void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1001 | getWindow().closeAllPanels(); |
| 1002 | |
| 1003 | try { |
| 1004 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 1005 | // Unlock the workspace if the dialog was showing |
| 1006 | } catch (Exception e) { |
| 1007 | // An exception is thrown if the dialog is not visible, which is fine |
| 1008 | } |
| 1009 | |
| 1010 | try { |
| 1011 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 1012 | // Unlock the workspace if the dialog was showing |
| 1013 | } catch (Exception e) { |
| 1014 | // An exception is thrown if the dialog is not visible, which is fine |
| 1015 | } |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1016 | |
| 1017 | // Whatever we were doing is hereby canceled. |
| 1018 | mWaitingForResult = false; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1019 | } |
| 1020 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1021 | @Override |
| 1022 | protected void onNewIntent(Intent intent) { |
| 1023 | super.onNewIntent(intent); |
| 1024 | |
| 1025 | // Close the menu |
| 1026 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1027 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1028 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1029 | |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 1030 | boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1031 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
| 1032 | boolean allAppsVisible = isAllAppsVisible(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1033 | |
| 1034 | // TODO: Figure out the right thing to do in XLarge mode here |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1035 | if (!mWorkspace.isDefaultScreenShowing()) { |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 1036 | mWorkspace.moveToDefaultScreen(alreadyOnHome && !allAppsVisible); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1037 | } |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 1038 | closeAllApps(alreadyOnHome && allAppsVisible); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1039 | hideCustomizationDrawer(); |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1040 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1041 | final View v = getWindow().peekDecorView(); |
| 1042 | if (v != null && v.getWindowToken() != null) { |
| 1043 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1044 | INPUT_METHOD_SERVICE); |
| 1045 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | @Override |
| 1051 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 1052 | // Do not call super here |
| 1053 | mSavedInstanceState = savedInstanceState; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1054 | |
| 1055 | if (mHomeCustomizationDrawer != null) { |
| 1056 | String cur = savedInstanceState.getString("currentTab"); |
| 1057 | if (cur != null) { |
| 1058 | mHomeCustomizationDrawer.setCurrentTabByTag(cur); |
| 1059 | } |
| 1060 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | @Override |
| 1064 | protected void onSaveInstanceState(Bundle outState) { |
| 1065 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen()); |
| 1066 | |
| 1067 | final ArrayList<Folder> folders = mWorkspace.getOpenFolders(); |
| 1068 | if (folders.size() > 0) { |
| 1069 | final int count = folders.size(); |
| 1070 | long[] ids = new long[count]; |
| 1071 | for (int i = 0; i < count; i++) { |
| 1072 | final FolderInfo info = folders.get(i).getInfo(); |
| 1073 | ids[i] = info.id; |
| 1074 | } |
| 1075 | outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids); |
| 1076 | } else { |
| 1077 | super.onSaveInstanceState(outState); |
| 1078 | } |
| 1079 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1080 | // TODO should not do this if the drawer is currently closing. |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1081 | if (isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1082 | outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1083 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1084 | |
| 1085 | if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) { |
| 1086 | final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo; |
| 1087 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen); |
| 1088 | |
| 1089 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen); |
| 1090 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX); |
| 1091 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY); |
| 1092 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX); |
| 1093 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY); |
| 1094 | outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX()); |
| 1095 | outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY()); |
| 1096 | outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS, |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1097 | layout.getOccupiedCellsFlattened()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | if (mFolderInfo != null && mWaitingForResult) { |
| 1101 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1102 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1103 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1104 | |
| 1105 | if (mHomeCustomizationDrawer != null) { |
| 1106 | String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag(); |
| 1107 | if (currentTabTag != null) { |
| 1108 | outState.putString("currentTab", currentTabTag); |
| 1109 | } |
| 1110 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | @Override |
| 1114 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1115 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1116 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1117 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1118 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1119 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1120 | Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | TextKeyListener.getInstance().release(); |
| 1124 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1125 | mModel.stopLoader(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1126 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1127 | unbindDesktopItems(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1128 | |
| 1129 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1130 | |
Patrick Dubroy | ab962b7 | 2010-07-26 12:10:10 -0700 | [diff] [blame] | 1131 | // Some launcher layouts don't have a previous and next view |
| 1132 | if (mPreviousView != null) { |
| 1133 | dismissPreview(mPreviousView); |
| 1134 | } |
| 1135 | if (mNextView != null) { |
| 1136 | dismissPreview(mNextView); |
| 1137 | } |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1138 | |
| 1139 | unregisterReceiver(mCloseSystemDialogsReceiver); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | @Override |
| 1143 | public void startActivityForResult(Intent intent, int requestCode) { |
Romain Guy | 08f9749 | 2009-06-29 14:41:20 -0700 | [diff] [blame] | 1144 | if (requestCode >= 0) mWaitingForResult = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1145 | super.startActivityForResult(intent, requestCode); |
| 1146 | } |
| 1147 | |
| 1148 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1149 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1150 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1151 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1152 | closeAllApps(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1153 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1154 | if (initialQuery == null) { |
| 1155 | // Use any text typed in the launcher as the initial query |
| 1156 | initialQuery = getTypedText(); |
| 1157 | clearTypedText(); |
| 1158 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1159 | if (appSearchData == null) { |
| 1160 | appSearchData = new Bundle(); |
Bjorn Bringert | 3e244cf | 2010-02-10 14:17:35 +0000 | [diff] [blame] | 1161 | appSearchData.putString(Search.SOURCE, "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1162 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1163 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1164 | final SearchManager searchManager = |
| 1165 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1166 | searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1167 | appSearchData, globalSearch); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | @Override |
| 1171 | public boolean onCreateOptionsMenu(Menu menu) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1172 | if (isWorkspaceLocked()) { |
| 1173 | return false; |
| 1174 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1175 | |
| 1176 | super.onCreateOptionsMenu(menu); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1177 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1178 | menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add) |
| 1179 | .setIcon(android.R.drawable.ic_menu_add) |
| 1180 | .setAlphabeticShortcut('A'); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1181 | menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1182 | .setIcon(android.R.drawable.ic_menu_gallery) |
| 1183 | .setAlphabeticShortcut('W'); |
| 1184 | menu.add(0, MENU_SEARCH, 0, R.string.menu_search) |
| 1185 | .setIcon(android.R.drawable.ic_search_category_default) |
| 1186 | .setAlphabeticShortcut(SearchManager.MENU_KEY); |
| 1187 | menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications) |
| 1188 | .setIcon(com.android.internal.R.drawable.ic_menu_notifications) |
| 1189 | .setAlphabeticShortcut('N'); |
| 1190 | |
| 1191 | final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1192 | settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1193 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1194 | |
| 1195 | menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) |
| 1196 | .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') |
| 1197 | .setIntent(settings); |
| 1198 | |
| 1199 | return true; |
| 1200 | } |
| 1201 | |
| 1202 | @Override |
| 1203 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 1204 | super.onPrepareOptionsMenu(menu); |
| 1205 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1206 | // If all apps is animating, don't show the menu, because we don't know |
| 1207 | // which one to show. |
| 1208 | if (mAllAppsGrid.isVisible() && !mAllAppsGrid.isOpaque()) { |
| 1209 | return false; |
| 1210 | } |
| 1211 | |
| 1212 | // Only show the add and wallpaper options when we're not in all apps. |
| 1213 | boolean visible = !mAllAppsGrid.isOpaque(); |
| 1214 | menu.setGroupVisible(MENU_GROUP_ADD, visible); |
| 1215 | menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible); |
| 1216 | |
| 1217 | // Disable add if the workspace is full. |
| 1218 | if (visible) { |
| 1219 | mMenuAddInfo = mWorkspace.findAllVacantCells(null); |
| 1220 | menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid); |
| 1221 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1222 | |
| 1223 | return true; |
| 1224 | } |
| 1225 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1226 | // we need to initialize mAddItemCellInfo before adding something to the homescreen -- when |
| 1227 | // using the settings menu to add an item, something similar happens in showAddDialog |
| 1228 | public void prepareAddItemFromHomeCustomizationDrawer() { |
| 1229 | mMenuAddInfo = mWorkspace.findAllVacantCells(null); |
| 1230 | mAddItemCellInfo = mMenuAddInfo; |
| 1231 | } |
| 1232 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1233 | @Override |
| 1234 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1235 | switch (item.getItemId()) { |
| 1236 | case MENU_ADD: |
| 1237 | addItems(); |
| 1238 | return true; |
| 1239 | case MENU_WALLPAPER_SETTINGS: |
| 1240 | startWallpaper(); |
| 1241 | return true; |
| 1242 | case MENU_SEARCH: |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1243 | onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1244 | return true; |
| 1245 | case MENU_NOTIFICATIONS: |
| 1246 | showNotifications(); |
| 1247 | return true; |
| 1248 | } |
| 1249 | |
| 1250 | return super.onOptionsItemSelected(item); |
| 1251 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1252 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1253 | /** |
| 1254 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1255 | * argument for {@link #startSearch} to true. |
| 1256 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1257 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1258 | @Override |
| 1259 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1260 | startSearch(null, false, null, true); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1261 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1264 | public boolean isWorkspaceLocked() { |
| 1265 | return mWorkspaceLoading || mWaitingForResult; |
| 1266 | } |
| 1267 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1268 | private void addItems() { |
Joe Onorato | e616866 | 2009-11-08 13:39:30 -0500 | [diff] [blame] | 1269 | closeAllApps(true); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1270 | if (LauncherApplication.isScreenXLarge()) { |
| 1271 | // Animate the widget chooser up from the bottom of the screen |
| 1272 | if (!isCustomizationDrawerVisible()) { |
| 1273 | showCustomizationDrawer(); |
| 1274 | } |
| 1275 | } else { |
| 1276 | showAddDialog(mMenuAddInfo); |
| 1277 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1280 | void addAppWidgetFromDrop(ComponentName appWidgetProvider, CellLayout.CellInfo cellInfo) { |
| 1281 | mAddItemCellInfo = cellInfo; |
| 1282 | int appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
| 1283 | AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider); |
| 1284 | addAppWidgetImpl(appWidgetId); |
| 1285 | } |
| 1286 | |
| 1287 | void addAppWidgetFromPick(Intent data) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1288 | // TODO: catch bad widget exception when sent |
| 1289 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1290 | // TODO: Is this log message meaningful? |
| 1291 | if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras()); |
| 1292 | addAppWidgetImpl(appWidgetId); |
| 1293 | } |
| 1294 | |
| 1295 | void addAppWidgetImpl(int appWidgetId) { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1296 | AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1297 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1298 | if (appWidget.configure != null) { |
| 1299 | // Launch over to configure widget, if needed |
| 1300 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
| 1301 | intent.setComponent(appWidget.configure); |
| 1302 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 1303 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 1304 | startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1305 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1306 | // Otherwise just add it |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1307 | completeAddAppWidget(appWidgetId, mAddItemCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1308 | } |
| 1309 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1310 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1311 | void processShortcut(Intent intent) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1312 | // Handle case where user selected "Applications" |
| 1313 | String applicationName = getResources().getString(R.string.group_applications); |
| 1314 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1315 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1316 | if (applicationName != null && applicationName.equals(shortcutName)) { |
| 1317 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1318 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1319 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1320 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1321 | pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1322 | startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1323 | } else { |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1324 | startActivityForResult(intent, REQUEST_CREATE_SHORTCUT); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1325 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | void addLiveFolder(Intent intent) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1329 | // Handle case where user selected "Folder" |
Jeffrey Sharkey | c4bbd0a | 2009-03-24 22:47:52 -0700 | [diff] [blame] | 1330 | String folderName = getResources().getString(R.string.group_folder); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1331 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1332 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1333 | if (folderName != null && folderName.equals(shortcutName)) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1334 | addFolder(); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1335 | } else { |
| 1336 | startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER); |
| 1337 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1338 | } |
| 1339 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1340 | void addFolder() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1341 | UserFolderInfo folderInfo = new UserFolderInfo(); |
| 1342 | folderInfo.title = getText(R.string.folder_name); |
| 1343 | |
| 1344 | CellLayout.CellInfo cellInfo = mAddItemCellInfo; |
| 1345 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 1346 | if (!findSingleSlot(cellInfo)) return; |
| 1347 | |
| 1348 | // Update the model |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1349 | LauncherModel.addItemToDatabase(this, folderInfo, |
| 1350 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1351 | mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1352 | mFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1353 | |
| 1354 | // Create the view |
| 1355 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
| 1356 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo); |
| 1357 | mWorkspace.addInCurrentScreen(newFolder, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1358 | cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1359 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1360 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1361 | void removeFolder(FolderInfo folder) { |
| 1362 | mFolders.remove(folder.id); |
| 1363 | } |
| 1364 | |
| 1365 | private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1366 | cellInfo.screen = mWorkspace.getCurrentScreen(); |
| 1367 | if (!findSingleSlot(cellInfo)) return; |
| 1368 | |
| 1369 | final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false); |
| 1370 | |
| 1371 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1372 | final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this, |
| 1373 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1374 | mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, |
| 1375 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | static LiveFolderInfo addLiveFolder(Context context, Intent data, |
| 1380 | CellLayout.CellInfo cellInfo, boolean notify) { |
| 1381 | |
| 1382 | Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT); |
| 1383 | String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME); |
| 1384 | |
| 1385 | Drawable icon = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1386 | Intent.ShortcutIconResource iconResource = null; |
| 1387 | |
| 1388 | Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON); |
| 1389 | if (extra != null && extra instanceof Intent.ShortcutIconResource) { |
| 1390 | try { |
| 1391 | iconResource = (Intent.ShortcutIconResource) extra; |
| 1392 | final PackageManager packageManager = context.getPackageManager(); |
| 1393 | Resources resources = packageManager.getResourcesForApplication( |
| 1394 | iconResource.packageName); |
| 1395 | final int id = resources.getIdentifier(iconResource.resourceName, null, null); |
| 1396 | icon = resources.getDrawable(id); |
| 1397 | } catch (Exception e) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1398 | Log.w(TAG, "Could not load live folder icon: " + extra); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | if (icon == null) { |
| 1403 | icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder); |
| 1404 | } |
| 1405 | |
| 1406 | final LiveFolderInfo info = new LiveFolderInfo(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1407 | info.icon = Utilities.createIconBitmap(icon, context); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1408 | info.title = name; |
| 1409 | info.iconResource = iconResource; |
| 1410 | info.uri = data.getData(); |
| 1411 | info.baseIntent = baseIntent; |
| 1412 | info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, |
| 1413 | LiveFolders.DISPLAY_MODE_GRID); |
| 1414 | |
| 1415 | LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
| 1416 | cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1417 | mFolders.put(info.id, info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1418 | |
| 1419 | return info; |
| 1420 | } |
| 1421 | |
| 1422 | private boolean findSingleSlot(CellLayout.CellInfo cellInfo) { |
| 1423 | final int[] xy = new int[2]; |
| 1424 | if (findSlot(cellInfo, xy, 1, 1)) { |
| 1425 | cellInfo.cellX = xy[0]; |
| 1426 | cellInfo.cellY = xy[1]; |
| 1427 | return true; |
| 1428 | } |
| 1429 | return false; |
| 1430 | } |
| 1431 | |
| 1432 | private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) { |
| 1433 | if (!cellInfo.findCellForSpan(xy, spanX, spanY)) { |
| 1434 | boolean[] occupied = mSavedState != null ? |
| 1435 | mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null; |
| 1436 | cellInfo = mWorkspace.findAllVacantCells(occupied); |
| 1437 | if (!cellInfo.findCellForSpan(xy, spanX, spanY)) { |
| 1438 | Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show(); |
| 1439 | return false; |
| 1440 | } |
| 1441 | } |
| 1442 | return true; |
| 1443 | } |
| 1444 | |
| 1445 | private void showNotifications() { |
| 1446 | final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE); |
| 1447 | if (statusBar != null) { |
| 1448 | statusBar.expand(); |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | private void startWallpaper() { |
Joe Onorato | e616866 | 2009-11-08 13:39:30 -0500 | [diff] [blame] | 1453 | closeAllApps(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1454 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
Dianne Hackborn | 8355ae3 | 2009-09-07 21:47:51 -0700 | [diff] [blame] | 1455 | Intent chooser = Intent.createChooser(pickWallpaper, |
| 1456 | getText(R.string.chooser_wallpaper)); |
Romain Guy | f2826c7 | 2009-11-12 17:39:34 -0800 | [diff] [blame] | 1457 | // NOTE: Adds a configure option to the chooser if the wallpaper supports it |
| 1458 | // Removed in Eclair MR1 |
| 1459 | // WallpaperManager wm = (WallpaperManager) |
| 1460 | // getSystemService(Context.WALLPAPER_SERVICE); |
| 1461 | // WallpaperInfo wi = wm.getWallpaperInfo(); |
| 1462 | // if (wi != null && wi.getSettingsActivity() != null) { |
| 1463 | // LabeledIntent li = new LabeledIntent(getPackageName(), |
| 1464 | // R.string.configure_wallpaper, 0); |
| 1465 | // li.setClassName(wi.getPackageName(), wi.getSettingsActivity()); |
| 1466 | // chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li }); |
| 1467 | // } |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 1468 | startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1469 | } |
| 1470 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1471 | /** |
| 1472 | * Registers various content observers. The current implementation registers |
| 1473 | * only a favorites observer to keep track of the favorites applications. |
| 1474 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1475 | private void registerContentObservers() { |
| 1476 | ContentResolver resolver = getContentResolver(); |
| 1477 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 1478 | true, mWidgetObserver); |
| 1479 | } |
| 1480 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1481 | @Override |
| 1482 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 1483 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 1484 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1485 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1486 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1487 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jason Sams | eb5615d | 2009-11-30 11:50:10 -0800 | [diff] [blame] | 1488 | if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1489 | dumpState(); |
| 1490 | return true; |
| 1491 | } |
| 1492 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1493 | } |
| 1494 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 1495 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1496 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1497 | return true; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | return super.dispatchKeyEvent(event); |
| 1502 | } |
| 1503 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1504 | @Override |
| 1505 | public void onBackPressed() { |
| 1506 | if (isAllAppsVisible()) { |
| 1507 | closeAllApps(true); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1508 | } else if (isCustomizationDrawerVisible()) { |
| 1509 | hideCustomizationDrawer(); |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1510 | } else { |
| 1511 | closeFolder(); |
| 1512 | } |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1513 | // Some launcher layouts don't have a previous and next view |
| 1514 | if (mPreviousView != null) { |
| 1515 | dismissPreview(mPreviousView); |
| 1516 | dismissPreview(mNextView); |
| 1517 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1518 | } |
| 1519 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1520 | private void closeFolder() { |
| 1521 | Folder folder = mWorkspace.getOpenFolder(); |
| 1522 | if (folder != null) { |
| 1523 | closeFolder(folder); |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | void closeFolder(Folder folder) { |
| 1528 | folder.getInfo().opened = false; |
| 1529 | ViewGroup parent = (ViewGroup) folder.getParent(); |
| 1530 | if (parent != null) { |
| 1531 | parent.removeView(folder); |
Joe Onorato | b6341e9 | 2009-11-02 10:41:48 -0500 | [diff] [blame] | 1532 | if (folder instanceof DropTarget) { |
| 1533 | // Live folders aren't DropTargets. |
| 1534 | mDragController.removeDropTarget((DropTarget)folder); |
| 1535 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1536 | } |
| 1537 | folder.onClose(); |
| 1538 | } |
| 1539 | |
| 1540 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1541 | * Re-listen when widgets are reset. |
| 1542 | */ |
| 1543 | private void onAppWidgetReset() { |
| 1544 | mAppWidgetHost.startListening(); |
| 1545 | } |
| 1546 | |
| 1547 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1548 | * Go through the and disconnect any of the callbacks in the drawables and the views or we |
| 1549 | * leak the previous Home screen on orientation change. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1550 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1551 | private void unbindDesktopItems() { |
| 1552 | for (ItemInfo item: mDesktopItems) { |
| 1553 | item.unbind(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1554 | } |
| 1555 | } |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1556 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1557 | /** |
| 1558 | * Launches the intent referred by the clicked shortcut. |
| 1559 | * |
| 1560 | * @param v The view representing the clicked shortcut. |
| 1561 | */ |
| 1562 | public void onClick(View v) { |
| 1563 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1564 | if (tag instanceof ShortcutInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1565 | // Open shortcut |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1566 | final Intent intent = ((ShortcutInfo) tag).intent; |
Joe Onorato | 13724ea | 2009-12-02 21:16:35 -0800 | [diff] [blame] | 1567 | int[] pos = new int[2]; |
| 1568 | v.getLocationOnScreen(pos); |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1569 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 1570 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 1571 | startActivitySafely(intent, tag); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1572 | } else if (tag instanceof FolderInfo) { |
| 1573 | handleFolderClick((FolderInfo) tag); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1574 | } else if (v == mHandleView) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1575 | if (isAllAppsVisible()) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1576 | closeAllApps(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1577 | } else { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1578 | showAllApps(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1579 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1580 | } |
| 1581 | } |
| 1582 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1583 | public boolean onTouch(View v, MotionEvent event) { |
| 1584 | // this is being forwarded from mWorkspace; |
| 1585 | // clicking anywhere on the workspace causes the drawer to slide down |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1586 | hideCustomizationDrawer(); |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1587 | return false; |
| 1588 | } |
| 1589 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1590 | /** |
| 1591 | * Event handler for the "plus" button that appears on the home screen, which |
| 1592 | * enters home screen customization mode. |
| 1593 | * |
| 1594 | * @param v The view that was clicked. |
| 1595 | */ |
| 1596 | public void onClickAddButton(View v) { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1597 | addItems(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 1600 | void startActivitySafely(Intent intent, Object tag) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1601 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1602 | try { |
| 1603 | startActivity(intent); |
| 1604 | } catch (ActivityNotFoundException e) { |
| 1605 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1606 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1607 | } catch (SecurityException e) { |
| 1608 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1609 | Log.e(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] | 1610 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 1611 | "or use the exported attribute for this activity. " |
| 1612 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1613 | } |
| 1614 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1615 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 1616 | void startActivityForResultSafely(Intent intent, int requestCode) { |
| 1617 | try { |
| 1618 | startActivityForResult(intent, requestCode); |
| 1619 | } catch (ActivityNotFoundException e) { |
| 1620 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 1621 | } catch (SecurityException e) { |
| 1622 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 1623 | Log.e(TAG, "Launcher does not have the permission to launch " + intent + |
| 1624 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
| 1625 | "or use the exported attribute for this activity.", e); |
| 1626 | } |
| 1627 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1628 | |
| 1629 | private void handleFolderClick(FolderInfo folderInfo) { |
| 1630 | if (!folderInfo.opened) { |
| 1631 | // Close any open folder |
| 1632 | closeFolder(); |
| 1633 | // Open the requested folder |
| 1634 | openFolder(folderInfo); |
| 1635 | } else { |
| 1636 | // Find the open folder... |
| 1637 | Folder openFolder = mWorkspace.getFolderForTag(folderInfo); |
| 1638 | int folderScreen; |
| 1639 | if (openFolder != null) { |
| 1640 | folderScreen = mWorkspace.getScreenForView(openFolder); |
| 1641 | // .. and close it |
| 1642 | closeFolder(openFolder); |
| 1643 | if (folderScreen != mWorkspace.getCurrentScreen()) { |
| 1644 | // Close any folder open on the current screen |
| 1645 | closeFolder(); |
| 1646 | // Pull the folder onto this screen |
| 1647 | openFolder(folderInfo); |
| 1648 | } |
| 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1653 | /** |
| 1654 | * Opens the user fodler described by the specified tag. The opening of the folder |
| 1655 | * is animated relative to the specified View. If the View is null, no animation |
| 1656 | * is played. |
| 1657 | * |
| 1658 | * @param folderInfo The FolderInfo describing the folder to open. |
| 1659 | */ |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1660 | public void openFolder(FolderInfo folderInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1661 | Folder openFolder; |
| 1662 | |
| 1663 | if (folderInfo instanceof UserFolderInfo) { |
| 1664 | openFolder = UserFolder.fromXml(this); |
| 1665 | } else if (folderInfo instanceof LiveFolderInfo) { |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 1666 | openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1667 | } else { |
| 1668 | return; |
| 1669 | } |
| 1670 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1671 | openFolder.setDragController(mDragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1672 | openFolder.setLauncher(this); |
| 1673 | |
| 1674 | openFolder.bind(folderInfo); |
| 1675 | folderInfo.opened = true; |
| 1676 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1677 | mWorkspace.addInFullScreen(openFolder, folderInfo.screen); |
| 1678 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1679 | openFolder.onOpen(); |
| 1680 | } |
| 1681 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1682 | public boolean onLongClick(View v) { |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1683 | switch (v.getId()) { |
| 1684 | case R.id.previous_screen: |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1685 | if (!isAllAppsVisible()) { |
| 1686 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1687 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1688 | showPreviews(v); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1689 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1690 | return true; |
| 1691 | case R.id.next_screen: |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1692 | if (!isAllAppsVisible()) { |
| 1693 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1694 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1695 | showPreviews(v); |
| 1696 | } |
| 1697 | return true; |
| 1698 | case R.id.all_apps_button: |
| 1699 | if (!isAllAppsVisible()) { |
| 1700 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1701 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 1702 | showPreviews(v); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1703 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1704 | return true; |
| 1705 | } |
| 1706 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1707 | if (isWorkspaceLocked()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1708 | return false; |
| 1709 | } |
| 1710 | |
| 1711 | if (!(v instanceof CellLayout)) { |
| 1712 | v = (View) v.getParent(); |
| 1713 | } |
| 1714 | |
| 1715 | CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag(); |
| 1716 | |
| 1717 | // This happens when long clicking an item with the dpad/trackball |
| 1718 | if (cellInfo == null) { |
| 1719 | return true; |
| 1720 | } |
| 1721 | |
| 1722 | if (mWorkspace.allowLongPress()) { |
| 1723 | if (cellInfo.cell == null) { |
| 1724 | if (cellInfo.valid) { |
| 1725 | // User long pressed on empty space |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1726 | mWorkspace.setAllowLongPress(false); |
Joe Onorato | f0dde09 | 2010-02-16 18:25:23 -0500 | [diff] [blame] | 1727 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1728 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1729 | showAddDialog(cellInfo); |
| 1730 | } |
| 1731 | } else { |
| 1732 | if (!(cellInfo.cell instanceof Folder)) { |
| 1733 | // User long pressed on an item |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1734 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1735 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1736 | mWorkspace.startDrag(cellInfo); |
| 1737 | } |
| 1738 | } |
| 1739 | } |
| 1740 | return true; |
| 1741 | } |
| 1742 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1743 | @SuppressWarnings({"unchecked"}) |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1744 | private void dismissPreview(final View v) { |
| 1745 | final PopupWindow window = (PopupWindow) v.getTag(); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1746 | if (window != null) { |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1747 | window.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 1748 | public void onDismiss() { |
| 1749 | ViewGroup group = (ViewGroup) v.getTag(R.id.workspace); |
| 1750 | int count = group.getChildCount(); |
| 1751 | for (int i = 0; i < count; i++) { |
| 1752 | ((ImageView) group.getChildAt(i)).setImageDrawable(null); |
| 1753 | } |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1754 | ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon); |
| 1755 | for (Bitmap bitmap : bitmaps) bitmap.recycle(); |
| 1756 | |
| 1757 | v.setTag(R.id.workspace, null); |
| 1758 | v.setTag(R.id.icon, null); |
| 1759 | window.setOnDismissListener(null); |
| 1760 | } |
| 1761 | }); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1762 | window.dismiss(); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1763 | } |
| 1764 | v.setTag(null); |
| 1765 | } |
| 1766 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1767 | private void showPreviews(View anchor) { |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1768 | showPreviews(anchor, 0, mWorkspace.getChildCount()); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1769 | } |
| 1770 | |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1771 | private void showPreviews(final View anchor, int start, int end) { |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1772 | final Resources resources = getResources(); |
| 1773 | final Workspace workspace = mWorkspace; |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1774 | |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1775 | CellLayout cell = ((CellLayout) workspace.getChildAt(start)); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1776 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1777 | float max = workspace.getChildCount(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1778 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1779 | final Rect r = new Rect(); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1780 | resources.getDrawable(R.drawable.preview_background).getPadding(r); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1781 | int extraW = (int) ((r.left + r.right) * max); |
| 1782 | int extraH = r.top + r.bottom; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1783 | |
| 1784 | int aW = cell.getWidth() - extraW; |
| 1785 | float w = aW / max; |
| 1786 | |
| 1787 | int width = cell.getWidth(); |
| 1788 | int height = cell.getHeight(); |
| 1789 | int x = cell.getLeftPadding(); |
| 1790 | int y = cell.getTopPadding(); |
| 1791 | width -= (x + cell.getRightPadding()); |
| 1792 | height -= (y + cell.getBottomPadding()); |
| 1793 | |
| 1794 | float scale = w / width; |
| 1795 | |
| 1796 | int count = end - start; |
| 1797 | |
| 1798 | final float sWidth = width * scale; |
| 1799 | float sHeight = height * scale; |
| 1800 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1801 | LinearLayout preview = new LinearLayout(this); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1802 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1803 | PreviewTouchHandler handler = new PreviewTouchHandler(anchor); |
| 1804 | ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1805 | |
| 1806 | for (int i = start; i < end; i++) { |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1807 | ImageView image = new ImageView(this); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1808 | cell = (CellLayout) workspace.getChildAt(i); |
| 1809 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1810 | final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1811 | Bitmap.Config.ARGB_8888); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1812 | |
| 1813 | final Canvas c = new Canvas(bitmap); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1814 | c.scale(scale, scale); |
| 1815 | c.translate(-cell.getLeftPadding(), -cell.getTopPadding()); |
| 1816 | cell.dispatchDraw(c); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1817 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1818 | image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background)); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1819 | image.setImageBitmap(bitmap); |
| 1820 | image.setTag(i); |
| 1821 | image.setOnClickListener(handler); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1822 | image.setOnFocusChangeListener(handler); |
| 1823 | image.setFocusable(true); |
| 1824 | if (i == mWorkspace.getCurrentScreen()) image.requestFocus(); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1825 | |
| 1826 | preview.addView(image, |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1827 | LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 1828 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1829 | bitmaps.add(bitmap); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1830 | } |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1831 | |
| 1832 | final PopupWindow p = new PopupWindow(this); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1833 | p.setContentView(preview); |
| 1834 | p.setWidth((int) (sWidth * count + extraW)); |
| 1835 | p.setHeight((int) (sHeight + extraH)); |
| 1836 | p.setAnimationStyle(R.style.AnimationPreview); |
| 1837 | p.setOutsideTouchable(true); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1838 | p.setFocusable(true); |
Romain Guy | ff0c2e2 | 2009-11-10 12:09:59 -0800 | [diff] [blame] | 1839 | p.setBackgroundDrawable(new ColorDrawable(0)); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1840 | p.showAsDropDown(anchor, 0, 0); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1841 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1842 | p.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 1843 | public void onDismiss() { |
| 1844 | dismissPreview(anchor); |
| 1845 | } |
| 1846 | }); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1847 | |
| 1848 | anchor.setTag(p); |
| 1849 | anchor.setTag(R.id.workspace, preview); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1850 | anchor.setTag(R.id.icon, bitmaps); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1851 | } |
| 1852 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1853 | class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener { |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1854 | private final View mAnchor; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1855 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1856 | public PreviewTouchHandler(View anchor) { |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1857 | mAnchor = anchor; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | public void onClick(View v) { |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1861 | mWorkspace.snapToScreen((Integer) v.getTag()); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1862 | v.post(this); |
| 1863 | } |
| 1864 | |
| 1865 | public void run() { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1866 | dismissPreview(mAnchor); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | public void onFocusChange(View v, boolean hasFocus) { |
| 1870 | if (hasFocus) { |
Romain Guy | e47f55c | 2009-11-11 19:21:22 -0800 | [diff] [blame] | 1871 | mWorkspace.snapToScreen((Integer) v.getTag()); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1872 | } |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1876 | Workspace getWorkspace() { |
| 1877 | return mWorkspace; |
| 1878 | } |
| 1879 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1880 | @Override |
| 1881 | protected Dialog onCreateDialog(int id) { |
| 1882 | switch (id) { |
| 1883 | case DIALOG_CREATE_SHORTCUT: |
| 1884 | return new CreateShortcut().createDialog(); |
| 1885 | case DIALOG_RENAME_FOLDER: |
| 1886 | return new RenameFolder().createDialog(); |
| 1887 | } |
| 1888 | |
| 1889 | return super.onCreateDialog(id); |
| 1890 | } |
| 1891 | |
| 1892 | @Override |
| 1893 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 1894 | switch (id) { |
| 1895 | case DIALOG_CREATE_SHORTCUT: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1896 | break; |
| 1897 | case DIALOG_RENAME_FOLDER: |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1898 | if (mFolderInfo != null) { |
| 1899 | EditText input = (EditText) dialog.findViewById(R.id.folder_name); |
| 1900 | final CharSequence text = mFolderInfo.title; |
| 1901 | input.setText(text); |
| 1902 | input.setSelection(0, text.length()); |
| 1903 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1904 | break; |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | void showRenameDialog(FolderInfo info) { |
| 1909 | mFolderInfo = info; |
| 1910 | mWaitingForResult = true; |
| 1911 | showDialog(DIALOG_RENAME_FOLDER); |
| 1912 | } |
| 1913 | |
| 1914 | private void showAddDialog(CellLayout.CellInfo cellInfo) { |
| 1915 | mAddItemCellInfo = cellInfo; |
| 1916 | mWaitingForResult = true; |
| 1917 | showDialog(DIALOG_CREATE_SHORTCUT); |
| 1918 | } |
| 1919 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1920 | private void pickShortcut() { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1921 | // Insert extra item to handle picking application |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1922 | Bundle bundle = new Bundle(); |
| 1923 | |
| 1924 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 1925 | shortcutNames.add(getString(R.string.group_applications)); |
| 1926 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
| 1927 | |
| 1928 | ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>(); |
| 1929 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 1930 | R.drawable.ic_launcher_application)); |
| 1931 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 1932 | |
| 1933 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1934 | pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT)); |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1935 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut)); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1936 | pickIntent.putExtras(bundle); |
| 1937 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1938 | startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1941 | private class RenameFolder { |
| 1942 | private EditText mInput; |
| 1943 | |
| 1944 | Dialog createDialog() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1945 | final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null); |
| 1946 | mInput = (EditText) layout.findViewById(R.id.folder_name); |
| 1947 | |
| 1948 | AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 1949 | builder.setIcon(0); |
| 1950 | builder.setTitle(getString(R.string.rename_folder_title)); |
| 1951 | builder.setCancelable(true); |
| 1952 | builder.setOnCancelListener(new Dialog.OnCancelListener() { |
| 1953 | public void onCancel(DialogInterface dialog) { |
| 1954 | cleanup(); |
| 1955 | } |
| 1956 | }); |
| 1957 | builder.setNegativeButton(getString(R.string.cancel_action), |
| 1958 | new Dialog.OnClickListener() { |
| 1959 | public void onClick(DialogInterface dialog, int which) { |
| 1960 | cleanup(); |
| 1961 | } |
| 1962 | } |
| 1963 | ); |
| 1964 | builder.setPositiveButton(getString(R.string.rename_action), |
| 1965 | new Dialog.OnClickListener() { |
| 1966 | public void onClick(DialogInterface dialog, int which) { |
| 1967 | changeFolderName(); |
| 1968 | } |
| 1969 | } |
| 1970 | ); |
| 1971 | builder.setView(layout); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1972 | |
| 1973 | final AlertDialog dialog = builder.create(); |
| 1974 | dialog.setOnShowListener(new DialogInterface.OnShowListener() { |
| 1975 | public void onShow(DialogInterface dialog) { |
Joe Onorato | 7018d8e | 2010-04-13 20:25:47 -0700 | [diff] [blame] | 1976 | mWaitingForResult = true; |
Joe Onorato | d753b42 | 2009-11-08 13:31:11 -0500 | [diff] [blame] | 1977 | mInput.requestFocus(); |
| 1978 | InputMethodManager inputManager = (InputMethodManager) |
| 1979 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 1980 | inputManager.showSoftInput(mInput, 0); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 1981 | } |
| 1982 | }); |
| 1983 | |
| 1984 | return dialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | private void changeFolderName() { |
| 1988 | final String name = mInput.getText().toString(); |
| 1989 | if (!TextUtils.isEmpty(name)) { |
| 1990 | // Make sure we have the right folder info |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1991 | mFolderInfo = mFolders.get(mFolderInfo.id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1992 | mFolderInfo.title = name; |
| 1993 | LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo); |
| 1994 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1995 | if (mWorkspaceLoading) { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 1996 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1997 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1998 | } else { |
| 1999 | final FolderIcon folderIcon = (FolderIcon) |
| 2000 | mWorkspace.getViewForTag(mFolderInfo); |
| 2001 | if (folderIcon != null) { |
| 2002 | folderIcon.setText(name); |
| 2003 | getWorkspace().requestLayout(); |
| 2004 | } else { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2005 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2006 | mWorkspaceLoading = true; |
| 2007 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2008 | } |
| 2009 | } |
| 2010 | } |
| 2011 | cleanup(); |
| 2012 | } |
| 2013 | |
| 2014 | private void cleanup() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2015 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 2016 | mWaitingForResult = false; |
| 2017 | mFolderInfo = null; |
| 2018 | } |
| 2019 | } |
| 2020 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2021 | // Now a part of LauncherModel.Callbacks. Used to reorder loading steps. |
| 2022 | public boolean isAllAppsVisible() { |
| 2023 | return (mAllAppsGrid != null) ? mAllAppsGrid.isVisible() : false; |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2024 | } |
| 2025 | |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2026 | // AllAppsView.Watcher |
| 2027 | public void zoomed(float zoom) { |
| 2028 | if (zoom == 1.0f) { |
| 2029 | mWorkspace.setVisibility(View.GONE); |
| 2030 | } |
| 2031 | } |
| 2032 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 2033 | void showAllApps(boolean animated) { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2034 | hideCustomizationDrawer(); |
| 2035 | |
| 2036 | if (LauncherApplication.isScreenXLarge() && animated) { |
| 2037 | // Not really a zoom -- this just makes the view visible |
| 2038 | mAllAppsGrid.zoom(1.0f, false); |
| 2039 | Animation anim = AnimationUtils.loadAnimation(this, R.anim.all_apps_zoom_in); |
| 2040 | ((View) mAllAppsGrid).startAnimation(anim); |
| 2041 | } else { |
| 2042 | mAllAppsGrid.zoom(1.0f, animated); |
| 2043 | } |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 2044 | |
Romain Guy | c16fea7 | 2010-03-12 17:17:56 -0800 | [diff] [blame] | 2045 | ((View) mAllAppsGrid).setFocusable(true); |
| 2046 | ((View) mAllAppsGrid).requestFocus(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2047 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2048 | // TODO: fade these two too |
| 2049 | mDeleteZone.setVisibility(View.GONE); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2050 | } |
| 2051 | |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2052 | /** |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2053 | * Things to test when changing this code. |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2054 | * - Home from workspace |
| 2055 | * - from center screen |
| 2056 | * - from other screens |
| 2057 | * - Home from all apps |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2058 | * - from center screen |
| 2059 | * - from other screens |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2060 | * - Back from all apps |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2061 | * - from center screen |
| 2062 | * - from other screens |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2063 | * - Launch app from workspace and quit |
| 2064 | * - with back |
| 2065 | * - with home |
| 2066 | * - Launch app from all apps and quit |
| 2067 | * - with back |
| 2068 | * - with home |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2069 | * - Go to a screen that's not the default, then all |
| 2070 | * apps, and launch and app, and go back |
| 2071 | * - with back |
| 2072 | * -with home |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2073 | * - On workspace, long press power and go back |
| 2074 | * - with back |
| 2075 | * - with home |
| 2076 | * - On all apps, long press power and go back |
| 2077 | * - with back |
| 2078 | * - with home |
| 2079 | * - On workspace, power off |
| 2080 | * - On all apps, power off |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2081 | * - Launch an app and turn off the screen while in that app |
| 2082 | * - Go back with home key |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2083 | * - Go back with back key TODO: make this not go to workspace |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2084 | * - From all apps |
| 2085 | * - From workspace |
Joe Onorato | effc4a8 | 2010-04-15 11:48:13 -0700 | [diff] [blame] | 2086 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 2087 | * - From all apps |
| 2088 | * - From the center workspace |
| 2089 | * - From another workspace |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2090 | */ |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 2091 | void closeAllApps(boolean animated) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2092 | if (mAllAppsGrid.isVisible()) { |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2093 | mWorkspace.setVisibility(View.VISIBLE); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2094 | if (LauncherApplication.isScreenXLarge() && animated) { |
| 2095 | Animation anim = AnimationUtils.loadAnimation(this, R.anim.all_apps_zoom_out); |
| 2096 | anim.setAnimationListener(new AnimationListener() { |
| 2097 | public void onAnimationStart(Animation animation) {} |
| 2098 | public void onAnimationRepeat(Animation animation) {} |
| 2099 | public void onAnimationEnd(Animation animation) { |
| 2100 | mAllAppsGrid.zoom(0.0f, false); |
| 2101 | } |
| 2102 | }); |
| 2103 | ((View)mAllAppsGrid).startAnimation(anim); |
| 2104 | } else { |
| 2105 | mAllAppsGrid.zoom(0.0f, animated); |
| 2106 | } |
Daniel Sandler | 388f679 | 2010-03-02 14:08:08 -0500 | [diff] [blame] | 2107 | ((View)mAllAppsGrid).setFocusable(false); |
Joe Onorato | e77c08d | 2009-08-01 00:01:20 -0700 | [diff] [blame] | 2108 | mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus(); |
Joe Onorato | e77c08d | 2009-08-01 00:01:20 -0700 | [diff] [blame] | 2109 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2112 | void lockAllApps() { |
| 2113 | // TODO |
| 2114 | } |
| 2115 | |
| 2116 | void unlockAllApps() { |
| 2117 | // TODO |
| 2118 | } |
| 2119 | |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2120 | private boolean isCustomizationDrawerVisible() { |
| 2121 | return mHomeCustomizationDrawer != null && mHomeCustomizationDrawer.getVisibility() == View.VISIBLE; |
| 2122 | } |
| 2123 | |
| 2124 | private void showCustomizationDrawer() { |
| 2125 | if (isAllAppsVisible()) { |
| 2126 | // TODO: Make a smoother transition here |
| 2127 | closeAllApps(false); |
| 2128 | } |
| 2129 | mHomeCustomizationDrawer.setVisibility(View.VISIBLE); |
| 2130 | mHomeCustomizationDrawer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.home_customization_drawer_slide_up)); |
| 2131 | } |
| 2132 | |
| 2133 | private void hideCustomizationDrawer() { |
| 2134 | if (isCustomizationDrawerVisible()) { |
| 2135 | Animation slideDownAnimation = AnimationUtils.loadAnimation(this, R.anim.home_customization_drawer_slide_down); |
| 2136 | slideDownAnimation.setAnimationListener(new Animation.AnimationListener() { |
| 2137 | public void onAnimationEnd(Animation animation) { |
| 2138 | mHomeCustomizationDrawer.setVisibility(View.GONE); |
| 2139 | } |
| 2140 | public void onAnimationRepeat(Animation animation) {} |
| 2141 | public void onAnimationStart(Animation animation) {} |
| 2142 | }); |
| 2143 | mHomeCustomizationDrawer.startAnimation(slideDownAnimation); |
| 2144 | } |
| 2145 | } |
| 2146 | |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 2147 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2148 | * Displays the shortcut creation dialog and launches, if necessary, the |
| 2149 | * appropriate activity. |
| 2150 | */ |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2151 | private class CreateShortcut implements DialogInterface.OnClickListener, |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2152 | DialogInterface.OnCancelListener, DialogInterface.OnDismissListener, |
| 2153 | DialogInterface.OnShowListener { |
| 2154 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2155 | private AddAdapter mAdapter; |
Romain Guy | 9ffb543 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 2156 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2157 | Dialog createDialog() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2158 | mAdapter = new AddAdapter(Launcher.this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2159 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2160 | final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 2161 | builder.setTitle(getString(R.string.menu_item_add_item)); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2162 | builder.setAdapter(mAdapter, this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2163 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2164 | builder.setInverseBackgroundForced(true); |
| 2165 | |
| 2166 | AlertDialog dialog = builder.create(); |
| 2167 | dialog.setOnCancelListener(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2168 | dialog.setOnDismissListener(this); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2169 | dialog.setOnShowListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2170 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2171 | return dialog; |
| 2172 | } |
| 2173 | |
| 2174 | public void onCancel(DialogInterface dialog) { |
| 2175 | mWaitingForResult = false; |
| 2176 | cleanup(); |
| 2177 | } |
| 2178 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2179 | public void onDismiss(DialogInterface dialog) { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2182 | private void cleanup() { |
Joe Onorato | cc19a53 | 2009-11-19 14:19:17 -0800 | [diff] [blame] | 2183 | try { |
| 2184 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 2185 | } catch (Exception e) { |
| 2186 | // An exception is thrown if the dialog is not visible, which is fine |
| 2187 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2188 | } |
| 2189 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2190 | /** |
| 2191 | * Handle the action clicked in the "Add to home" dialog. |
| 2192 | */ |
| 2193 | public void onClick(DialogInterface dialog, int which) { |
| 2194 | Resources res = getResources(); |
| 2195 | cleanup(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2196 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2197 | switch (which) { |
| 2198 | case AddAdapter.ITEM_SHORTCUT: { |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2199 | pickShortcut(); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2200 | break; |
| 2201 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2202 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2203 | case AddAdapter.ITEM_APPWIDGET: { |
| 2204 | int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2205 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2206 | Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); |
| 2207 | pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2208 | // start the pick activity |
| 2209 | startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); |
| 2210 | break; |
| 2211 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2212 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2213 | case AddAdapter.ITEM_LIVE_FOLDER: { |
| 2214 | // Insert extra item to handle inserting folder |
| 2215 | Bundle bundle = new Bundle(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2216 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2217 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 2218 | shortcutNames.add(res.getString(R.string.group_folder)); |
| 2219 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2220 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2221 | ArrayList<ShortcutIconResource> shortcutIcons = |
| 2222 | new ArrayList<ShortcutIconResource>(); |
| 2223 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 2224 | R.drawable.ic_launcher_folder)); |
| 2225 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 2226 | |
| 2227 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 2228 | pickIntent.putExtra(Intent.EXTRA_INTENT, |
| 2229 | new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER)); |
| 2230 | pickIntent.putExtra(Intent.EXTRA_TITLE, |
| 2231 | getText(R.string.title_select_live_folder)); |
| 2232 | pickIntent.putExtras(bundle); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2233 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2234 | startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER); |
| 2235 | break; |
| 2236 | } |
| 2237 | |
| 2238 | case AddAdapter.ITEM_WALLPAPER: { |
| 2239 | startWallpaper(); |
| 2240 | break; |
| 2241 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2242 | } |
| 2243 | } |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2244 | |
| 2245 | public void onShow(DialogInterface dialog) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2246 | mWaitingForResult = true; |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2247 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | /** |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2251 | * Receives notifications when applications are added/removed. |
| 2252 | */ |
| 2253 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 2254 | @Override |
| 2255 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2256 | closeSystemDialogs(); |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2257 | String reason = intent.getStringExtra("reason"); |
| 2258 | if (!"homekey".equals(reason)) { |
| 2259 | boolean animate = true; |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2260 | if (mPaused || "lock".equals(reason)) { |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2261 | animate = false; |
| 2262 | } |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2263 | closeAllApps(animate); |
| 2264 | } |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2269 | * Receives notifications whenever the appwidgets are reset. |
| 2270 | */ |
| 2271 | private class AppWidgetResetObserver extends ContentObserver { |
| 2272 | public AppWidgetResetObserver() { |
| 2273 | super(new Handler()); |
| 2274 | } |
| 2275 | |
| 2276 | @Override |
| 2277 | public void onChange(boolean selfChange) { |
| 2278 | onAppWidgetReset(); |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2283 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2284 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2285 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 2286 | if (mWorkspace != null) { |
| 2287 | return mWorkspace.getCurrentScreen(); |
| 2288 | } else { |
| 2289 | return SCREEN_COUNT / 2; |
| 2290 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2291 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2292 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2293 | /** |
| 2294 | * Refreshes the shortcuts shown on the workspace. |
| 2295 | * |
| 2296 | * Implementation of the method from LauncherModel.Callbacks. |
| 2297 | */ |
| 2298 | public void startBinding() { |
| 2299 | final Workspace workspace = mWorkspace; |
| 2300 | int count = workspace.getChildCount(); |
| 2301 | for (int i = 0; i < count; i++) { |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 2302 | // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate(). |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2303 | ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); |
| 2304 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2305 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2306 | if (DEBUG_USER_INTERFACE) { |
| 2307 | android.widget.Button finishButton = new android.widget.Button(this); |
| 2308 | finishButton.setText("Finish"); |
| 2309 | workspace.addInScreen(finishButton, 1, 0, 0, 1, 1); |
| 2310 | |
| 2311 | finishButton.setOnClickListener(new android.widget.Button.OnClickListener() { |
| 2312 | public void onClick(View v) { |
| 2313 | finish(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2314 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2315 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2320 | * Bind the items start-end from the list. |
| 2321 | * |
| 2322 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2323 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2324 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { |
| 2325 | |
| 2326 | final Workspace workspace = mWorkspace; |
| 2327 | |
| 2328 | for (int i=start; i<end; i++) { |
| 2329 | final ItemInfo item = shortcuts.get(i); |
| 2330 | mDesktopItems.add(item); |
| 2331 | switch (item.itemType) { |
| 2332 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 2333 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2334 | final View shortcut = createShortcut((ShortcutInfo)item); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2335 | workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, |
| 2336 | false); |
| 2337 | break; |
| 2338 | case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: |
| 2339 | final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
| 2340 | (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()), |
| 2341 | (UserFolderInfo) item); |
| 2342 | workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 2343 | false); |
| 2344 | break; |
| 2345 | case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: |
| 2346 | final FolderIcon newLiveFolder = LiveFolderIcon.fromXml( |
| 2347 | R.layout.live_folder_icon, this, |
| 2348 | (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()), |
| 2349 | (LiveFolderInfo) item); |
| 2350 | workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 2351 | false); |
| 2352 | break; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2353 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2354 | } |
| 2355 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2356 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2357 | } |
| 2358 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2359 | /** |
| 2360 | * Implementation of the method from LauncherModel.Callbacks. |
| 2361 | */ |
Joe Onorato | ad72e17 | 2009-11-06 16:25:04 -0500 | [diff] [blame] | 2362 | public void bindFolders(HashMap<Long, FolderInfo> folders) { |
| 2363 | mFolders.clear(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2364 | mFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2365 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2366 | |
| 2367 | /** |
| 2368 | * Add the views for a widget to the workspace. |
| 2369 | * |
| 2370 | * Implementation of the method from LauncherModel.Callbacks. |
| 2371 | */ |
| 2372 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2373 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 2374 | if (DEBUG_WIDGETS) { |
| 2375 | Log.d(TAG, "bindAppWidget: " + item); |
| 2376 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2377 | final Workspace workspace = mWorkspace; |
| 2378 | |
| 2379 | final int appWidgetId = item.appWidgetId; |
| 2380 | final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2381 | if (DEBUG_WIDGETS) { |
| 2382 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 2383 | } |
| 2384 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2385 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 2386 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2387 | item.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 2388 | item.hostView.setTag(item); |
| 2389 | |
| 2390 | workspace.addInScreen(item.hostView, item.screen, item.cellX, |
| 2391 | item.cellY, item.spanX, item.spanY, false); |
| 2392 | |
| 2393 | workspace.requestLayout(); |
| 2394 | |
| 2395 | mDesktopItems.add(item); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2396 | |
| 2397 | if (DEBUG_WIDGETS) { |
| 2398 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 2399 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 2400 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * Callback saying that there aren't any more items to bind. |
| 2405 | * |
| 2406 | * Implementation of the method from LauncherModel.Callbacks. |
| 2407 | */ |
| 2408 | public void finishBindingItems() { |
| 2409 | if (mSavedState != null) { |
| 2410 | if (!mWorkspace.hasFocus()) { |
| 2411 | mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus(); |
| 2412 | } |
| 2413 | |
| 2414 | final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS); |
| 2415 | if (userFolders != null) { |
| 2416 | for (long folderId : userFolders) { |
| 2417 | final FolderInfo info = mFolders.get(folderId); |
| 2418 | if (info != null) { |
| 2419 | openFolder(info); |
| 2420 | } |
| 2421 | } |
| 2422 | final Folder openFolder = mWorkspace.getOpenFolder(); |
| 2423 | if (openFolder != null) { |
| 2424 | openFolder.requestFocus(); |
| 2425 | } |
| 2426 | } |
| 2427 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2428 | mSavedState = null; |
| 2429 | } |
| 2430 | |
| 2431 | if (mSavedInstanceState != null) { |
| 2432 | super.onRestoreInstanceState(mSavedInstanceState); |
| 2433 | mSavedInstanceState = null; |
| 2434 | } |
| 2435 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2436 | mWorkspaceLoading = false; |
| 2437 | } |
| 2438 | |
| 2439 | /** |
| 2440 | * Add the icons for all apps. |
| 2441 | * |
| 2442 | * Implementation of the method from LauncherModel.Callbacks. |
| 2443 | */ |
| 2444 | public void bindAllApplications(ArrayList<ApplicationInfo> apps) { |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 2445 | mAllAppsGrid.setApps(apps); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | /** |
| 2449 | * A package was installed. |
| 2450 | * |
| 2451 | * Implementation of the method from LauncherModel.Callbacks. |
| 2452 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 2453 | public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2454 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 2455 | mAllAppsGrid.addApps(apps); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | /** |
| 2459 | * A package was updated. |
| 2460 | * |
| 2461 | * Implementation of the method from LauncherModel.Callbacks. |
| 2462 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 2463 | public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2464 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 2465 | mWorkspace.updateShortcuts(apps); |
| 2466 | mAllAppsGrid.updateApps(apps); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | /** |
| 2470 | * A package was uninstalled. |
| 2471 | * |
| 2472 | * Implementation of the method from LauncherModel.Callbacks. |
| 2473 | */ |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2474 | public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2475 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 2476 | if (permanent) { |
| 2477 | mWorkspace.removeItems(apps); |
| 2478 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 2479 | mAllAppsGrid.removeApps(apps); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2480 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2481 | |
| 2482 | /** |
| 2483 | * Prints out out state for debugging. |
| 2484 | */ |
| 2485 | public void dumpState() { |
| 2486 | Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 2487 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 2488 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 2489 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 2490 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 2491 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
| 2492 | Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size()); |
| 2493 | Log.d(TAG, "mFolders.size=" + mFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 2494 | mModel.dumpState(); |
| 2495 | mAllAppsGrid.dumpState(); |
| 2496 | Log.d(TAG, "END launcher2 dump state"); |
| 2497 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2498 | } |