Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 18 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 20 | import android.animation.Animator; |
| 21 | import android.animation.AnimatorListenerAdapter; |
| 22 | import android.animation.ValueAnimator; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 23 | import com.android.common.Search; |
| 24 | import com.android.launcher.R; |
| 25 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 26 | import android.animation.ObjectAnimator; |
Patrick Dubroy | 07a0de4 | 2010-08-26 11:48:35 -0700 | [diff] [blame] | 27 | import android.animation.PropertyValuesHolder; |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 28 | import android.animation.AnimatorSet; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 29 | import android.app.Activity; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | import android.app.Dialog; |
| 32 | import android.app.SearchManager; |
| 33 | import android.app.StatusBarManager; |
Dianne Hackborn | 107f839 | 2009-08-05 21:32:16 -0700 | [diff] [blame] | 34 | import android.app.WallpaperManager; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 35 | import android.appwidget.AppWidgetManager; |
| 36 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 38 | import android.content.BroadcastReceiver; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 39 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 40 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.content.Context; |
| 42 | import android.content.DialogInterface; |
| 43 | import android.content.Intent; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 44 | import android.content.Intent.ShortcutIconResource; |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 45 | import android.content.IntentFilter; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 46 | import android.content.pm.ActivityInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 47 | import android.content.pm.PackageManager; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager.NameNotFoundException; |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 49 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 51 | import android.content.res.Resources; |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 52 | import android.content.res.TypedArray; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 53 | import android.database.ContentObserver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | import android.graphics.Bitmap; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 55 | import android.graphics.Canvas; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 56 | import android.graphics.Color; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 57 | import android.graphics.Rect; |
Romain Guy | ff0c2e2 | 2009-11-10 12:09:59 -0800 | [diff] [blame] | 58 | import android.graphics.drawable.ColorDrawable; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 59 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 60 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 61 | import android.os.AsyncTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 62 | import android.os.Bundle; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 63 | import android.os.Handler; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 64 | import android.os.Parcelable; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 65 | import android.os.SystemClock; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 66 | import android.os.SystemProperties; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 67 | import android.provider.LiveFolders; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 68 | import android.provider.Settings; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | import android.text.Selection; |
| 70 | import android.text.SpannableStringBuilder; |
| 71 | import android.text.TextUtils; |
| 72 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 73 | import android.util.Log; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 74 | import android.view.Display; |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 75 | import android.view.HapticFeedbackConstants; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 76 | import android.view.KeyEvent; |
| 77 | import android.view.LayoutInflater; |
| 78 | import android.view.Menu; |
| 79 | import android.view.MenuItem; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 80 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 81 | import android.view.View; |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 82 | import android.view.View.OnLongClickListener; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 83 | import android.view.ViewGroup; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 84 | import android.view.WindowManager; |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 85 | import android.view.animation.AccelerateInterpolator; |
Patrick Dubroy | 7247f63 | 2010-08-04 16:02:59 -0700 | [diff] [blame] | 86 | import android.view.animation.DecelerateInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 87 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 88 | import android.widget.EditText; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 89 | import android.widget.ImageView; |
| 90 | import android.widget.LinearLayout; |
| 91 | import android.widget.PopupWindow; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 92 | import android.widget.RelativeLayout; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 93 | import android.widget.TabHost; |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 94 | import android.widget.TabHost.OnTabChangeListener; |
| 95 | import android.widget.TabHost.TabContentFactory; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 96 | import android.widget.TabWidget; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | import android.widget.TextView; |
| 98 | import android.widget.Toast; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 99 | |
| 100 | import java.io.DataInputStream; |
| 101 | import java.io.DataOutputStream; |
| 102 | import java.io.FileNotFoundException; |
| 103 | import java.io.IOException; |
| 104 | import java.util.ArrayList; |
| 105 | import java.util.HashMap; |
| 106 | import java.util.List; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 107 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 108 | /** |
| 109 | * Default launcher application. |
| 110 | */ |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 111 | public final class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 112 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
| 113 | AllAppsView.Watcher, View.OnTouchListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 114 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 115 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 116 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 117 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 118 | static final boolean DEBUG_WIDGETS = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 119 | static final boolean DEBUG_USER_INTERFACE = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 120 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 121 | private static final int MENU_GROUP_ADD = 1; |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 122 | private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1; |
| 123 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 124 | private static final int MENU_ADD = Menu.FIRST + 1; |
| 125 | private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1; |
| 126 | private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1; |
| 127 | private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1; |
Romain Guy | 94dabf1 | 2009-07-21 10:55:43 -0700 | [diff] [blame] | 128 | private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 129 | |
| 130 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
| 131 | private static final int REQUEST_CREATE_LIVE_FOLDER = 4; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 132 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 133 | private static final int REQUEST_PICK_APPLICATION = 6; |
| 134 | private static final int REQUEST_PICK_SHORTCUT = 7; |
| 135 | private static final int REQUEST_PICK_LIVE_FOLDER = 8; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 136 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 137 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 138 | |
| 139 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 140 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 141 | static final int SCREEN_COUNT = 5; |
| 142 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 143 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 144 | static final int DIALOG_CREATE_SHORTCUT = 1; |
| 145 | static final int DIALOG_RENAME_FOLDER = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 146 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 147 | private static final String PREFERENCES = "launcher.preferences"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 148 | |
| 149 | // Type: int |
| 150 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
| 151 | // Type: boolean |
| 152 | private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder"; |
| 153 | // Type: long |
| 154 | private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder"; |
| 155 | // Type: int |
| 156 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 157 | // Type: int |
| 158 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX"; |
| 159 | // Type: int |
| 160 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 166 | // tags for the customization tabs |
| 167 | private static final String WIDGETS_TAG = "widgets"; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 168 | private static final String APPLICATIONS_TAG = "applications"; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 169 | private static final String FOLDERS_TAG = "folders"; |
| 170 | private static final String SHORTCUTS_TAG = "shortcuts"; |
| 171 | private static final String WALLPAPERS_TAG = "wallpapers"; |
| 172 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 173 | private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; |
| 174 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 175 | /** The different states that Launcher can be in. */ |
| 176 | private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW }; |
| 177 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 178 | static final int APPWIDGET_HOST_ID = 1024; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 179 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 180 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 181 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 182 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 183 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 184 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 185 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 186 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 187 | private LayoutInflater mInflater; |
| 188 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 189 | private DragController mDragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 190 | private Workspace mWorkspace; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 191 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 192 | private AppWidgetManager mAppWidgetManager; |
| 193 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 194 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 195 | private int mAddScreen = -1; |
| 196 | private int mAddIntersectCellX = -1; |
| 197 | private int mAddIntersectCellY = -1; |
| 198 | private int[] mAddDropPosition; |
| 199 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 200 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 201 | private FolderInfo mFolderInfo; |
| 202 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 203 | private DeleteZone mDeleteZone; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 204 | private HandleView mHandleView; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 205 | private AllAppsView mAllAppsGrid; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 206 | private TabHost mHomeCustomizationDrawer; |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 207 | |
| 208 | private PagedView mAllAppsPagedView = null; |
| 209 | private CustomizePagedView mCustomizePagedView = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 210 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 211 | private Bundle mSavedState; |
| 212 | |
| 213 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 214 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 215 | private boolean mWorkspaceLoading = true; |
| 216 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 217 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 218 | private boolean mRestoring; |
| 219 | private boolean mWaitingForResult; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 220 | |
| 221 | private Bundle mSavedInstanceState; |
| 222 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 223 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 224 | private IconCache mIconCache; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 225 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 226 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 227 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 228 | private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 229 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 230 | |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 231 | private ImageView mPreviousView; |
| 232 | private ImageView mNextView; |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 233 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 234 | // Hotseats (quick-launch icons next to AllApps) |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 235 | private String[] mHotseatConfig = null; |
| 236 | private Intent[] mHotseats = null; |
| 237 | private Drawable[] mHotseatIcons = null; |
| 238 | private CharSequence[] mHotseatLabels = null; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 239 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 240 | private Intent mAppMarketIntent = null; |
| 241 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 242 | @Override |
| 243 | protected void onCreate(Bundle savedInstanceState) { |
| 244 | super.onCreate(savedInstanceState); |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 245 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 246 | if (LauncherApplication.isInPlaceRotationEnabled()) { |
| 247 | // hide the status bar (temporary until we get the status bar design figured out) |
| 248 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 249 | this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); |
| 250 | } |
| 251 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 252 | LauncherApplication app = ((LauncherApplication)getApplication()); |
| 253 | mModel = app.setLauncher(this); |
| 254 | mIconCache = app.getIconCache(); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 255 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 256 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 257 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 258 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 259 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 260 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 261 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 262 | if (PROFILE_STARTUP) { |
| 263 | android.os.Debug.startMethodTracing("/sdcard/launcher"); |
| 264 | } |
| 265 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 266 | loadHotseats(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 267 | checkForLocaleChange(); |
| 268 | setWallpaperDimension(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 269 | setContentView(R.layout.launcher); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 270 | mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost); |
| 271 | if (mHomeCustomizationDrawer != null) { |
| 272 | mHomeCustomizationDrawer.setup(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 273 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 274 | // share the same customization workspace across all the tabs |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 275 | mCustomizePagedView = (CustomizePagedView) mInflater.inflate( |
| 276 | R.layout.customization_drawer, mHomeCustomizationDrawer, false); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 277 | TabContentFactory contentFactory = new TabContentFactory() { |
| 278 | public View createTabContent(String tag) { |
| 279 | return mCustomizePagedView; |
| 280 | } |
| 281 | }; |
| 282 | |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 283 | String widgetsLabel = getString(R.string.widgets_tab_label); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 284 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG) |
| 285 | .setIndicator(widgetsLabel).setContent(contentFactory)); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 286 | String applicationsLabel = getString(R.string.applications_tab_label); |
| 287 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG) |
| 288 | .setIndicator(applicationsLabel).setContent(contentFactory)); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 289 | String foldersLabel = getString(R.string.folders_tab_label); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 290 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG) |
| 291 | .setIndicator(foldersLabel).setContent(contentFactory)); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 292 | String wallpapersLabel = getString(R.string.wallpapers_tab_label); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 293 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG) |
| 294 | .setIndicator(wallpapersLabel).setContent(contentFactory)); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 295 | String shortcutsLabel = getString(R.string.shortcuts_tab_label); |
| 296 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG) |
| 297 | .setIndicator(shortcutsLabel).setContent(contentFactory)); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 298 | |
| 299 | // TEMP: just styling the tab widget to be a bit nicer until we get the actual |
| 300 | // new assets |
| 301 | TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget(); |
| 302 | for (int i = 0; i < tabWidget.getChildCount(); ++i) { |
| 303 | RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i); |
| 304 | TextView text = (TextView) tab.getChildAt(1); |
| 305 | text.setTextSize(20.0f); |
| 306 | text.setPadding(20, 0, 20, 0); |
| 307 | text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK); |
| 308 | tab.setBackgroundDrawable(null); |
| 309 | } |
| 310 | |
| 311 | mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() { |
| 312 | public void onTabChanged(String tabId) { |
| 313 | // animate the changing of the tab content by fading pages in and out |
| 314 | final int duration = 150; |
| 315 | final float alpha = mCustomizePagedView.getAlpha(); |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 316 | ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView, |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 317 | "alpha", alpha, 0.0f); |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 318 | alphaAnim.addListener(new AnimatorListenerAdapter() { |
| 319 | public void onAnimationEnd(Animator animation) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 320 | String tag = mHomeCustomizationDrawer.getCurrentTabTag(); |
| 321 | if (tag == WIDGETS_TAG) { |
| 322 | mCustomizePagedView.setCustomizationFilter( |
| 323 | CustomizePagedView.CustomizationType.WidgetCustomization); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 324 | } else if (tag == APPLICATIONS_TAG) { |
| 325 | mCustomizePagedView.setCustomizationFilter( |
| 326 | CustomizePagedView.CustomizationType.ApplicationCustomization); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 327 | } else if (tag == FOLDERS_TAG) { |
| 328 | mCustomizePagedView.setCustomizationFilter( |
| 329 | CustomizePagedView.CustomizationType.FolderCustomization); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 330 | } else if (tag == WALLPAPERS_TAG) { |
| 331 | mCustomizePagedView.setCustomizationFilter( |
| 332 | CustomizePagedView.CustomizationType.WallpaperCustomization); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 333 | } else if (tag == SHORTCUTS_TAG) { |
| 334 | mCustomizePagedView.setCustomizationFilter( |
| 335 | CustomizePagedView.CustomizationType.ShortcutCustomization); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | final float alpha = mCustomizePagedView.getAlpha(); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 339 | ValueAnimator alphaAnim = new ObjectAnimator(duration, |
| 340 | mCustomizePagedView, "alpha", alpha, 1.0f); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 341 | alphaAnim.start(); |
| 342 | } |
| 343 | }); |
| 344 | alphaAnim.start(); |
| 345 | } |
| 346 | }); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 347 | |
| 348 | mHomeCustomizationDrawer.setCurrentTab(0); |
| 349 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 350 | setupViews(); |
| 351 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 352 | registerContentObservers(); |
| 353 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 354 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 355 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 356 | mSavedState = savedInstanceState; |
| 357 | restoreState(mSavedState); |
| 358 | |
| 359 | if (PROFILE_STARTUP) { |
| 360 | android.os.Debug.stopMethodTracing(); |
| 361 | } |
| 362 | |
| 363 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 364 | mModel.startLoader(this, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | // For handling default keys |
| 368 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 369 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 370 | |
| 371 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 372 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 373 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 374 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 375 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 376 | if (sLocaleConfiguration == null) { |
| 377 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 378 | @Override |
| 379 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 380 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 381 | readConfiguration(Launcher.this, localeConfiguration); |
| 382 | return localeConfiguration; |
| 383 | } |
| 384 | |
| 385 | @Override |
| 386 | protected void onPostExecute(LocaleConfiguration result) { |
| 387 | sLocaleConfiguration = result; |
| 388 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 389 | } |
| 390 | }.execute(); |
| 391 | return; |
| 392 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 393 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 394 | final Configuration configuration = getResources().getConfiguration(); |
| 395 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 396 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 397 | final String locale = configuration.locale.toString(); |
| 398 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 399 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 400 | final int mcc = configuration.mcc; |
| 401 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 402 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 403 | final int mnc = configuration.mnc; |
| 404 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 405 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 406 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 407 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 408 | sLocaleConfiguration.locale = locale; |
| 409 | sLocaleConfiguration.mcc = mcc; |
| 410 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 411 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 412 | mIconCache.flush(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 413 | loadHotseats(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 414 | |
| 415 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
| 416 | new Thread("WriteLocaleConfiguration") { |
| 417 | public void run() { |
| 418 | writeConfiguration(Launcher.this, localeConfiguration); |
| 419 | } |
| 420 | }.start(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
| 424 | private static class LocaleConfiguration { |
| 425 | public String locale; |
| 426 | public int mcc = -1; |
| 427 | public int mnc = -1; |
| 428 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 429 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 430 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 431 | DataInputStream in = null; |
| 432 | try { |
| 433 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 434 | configuration.locale = in.readUTF(); |
| 435 | configuration.mcc = in.readInt(); |
| 436 | configuration.mnc = in.readInt(); |
| 437 | } catch (FileNotFoundException e) { |
| 438 | // Ignore |
| 439 | } catch (IOException e) { |
| 440 | // Ignore |
| 441 | } finally { |
| 442 | if (in != null) { |
| 443 | try { |
| 444 | in.close(); |
| 445 | } catch (IOException e) { |
| 446 | // Ignore |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 453 | DataOutputStream out = null; |
| 454 | try { |
| 455 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 456 | out.writeUTF(configuration.locale); |
| 457 | out.writeInt(configuration.mcc); |
| 458 | out.writeInt(configuration.mnc); |
| 459 | out.flush(); |
| 460 | } catch (FileNotFoundException e) { |
| 461 | // Ignore |
| 462 | } catch (IOException e) { |
| 463 | //noinspection ResultOfMethodCallIgnored |
| 464 | context.getFileStreamPath(PREFERENCES).delete(); |
| 465 | } finally { |
| 466 | if (out != null) { |
| 467 | try { |
| 468 | out.close(); |
| 469 | } catch (IOException e) { |
| 470 | // Ignore |
| 471 | } |
| 472 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
| 476 | static int getScreen() { |
| 477 | synchronized (sLock) { |
| 478 | return sScreen; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | static void setScreen(int screen) { |
| 483 | synchronized (sLock) { |
| 484 | sScreen = screen; |
| 485 | } |
| 486 | } |
| 487 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 488 | private void setWallpaperDimension() { |
Dianne Hackborn | 107f839 | 2009-08-05 21:32:16 -0700 | [diff] [blame] | 489 | WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 490 | |
| 491 | Display display = getWindowManager().getDefaultDisplay(); |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 492 | // TODO: Put back when we decide about scrolling the wallpaper |
| 493 | // boolean isPortrait = display.getWidth() < display.getHeight(); |
| 494 | // final int width = isPortrait ? display.getWidth() : display.getHeight(); |
| 495 | // final int height = isPortrait ? display.getHeight() : display.getWidth(); |
| 496 | wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()), |
| 497 | Math.max(display.getWidth(), display.getHeight())); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 500 | // Note: This doesn't do all the client-id magic that BrowserProvider does |
| 501 | // in Browser. (http://b/2425179) |
| 502 | private Uri getDefaultBrowserUri() { |
| 503 | String url = getString(R.string.default_browser_url); |
| 504 | if (url.indexOf("{CID}") != -1) { |
| 505 | url = url.replace("{CID}", "android-google"); |
| 506 | } |
| 507 | return Uri.parse(url); |
| 508 | } |
| 509 | |
| 510 | // Load the Intent templates from arrays.xml to populate the hotseats. For |
| 511 | // each Intent, if it resolves to a single app, use that as the launch |
| 512 | // intent & use that app's label as the contentDescription. Otherwise, |
| 513 | // retain the ResolveActivity so the user can pick an app. |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 514 | private void loadHotseats() { |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 515 | if (mHotseatConfig == null) { |
| 516 | mHotseatConfig = getResources().getStringArray(R.array.hotseats); |
| 517 | if (mHotseatConfig.length > 0) { |
| 518 | mHotseats = new Intent[mHotseatConfig.length]; |
| 519 | mHotseatLabels = new CharSequence[mHotseatConfig.length]; |
| 520 | mHotseatIcons = new Drawable[mHotseatConfig.length]; |
| 521 | } else { |
| 522 | mHotseats = null; |
| 523 | mHotseatIcons = null; |
| 524 | mHotseatLabels = null; |
| 525 | } |
| 526 | |
| 527 | TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons); |
| 528 | for (int i=0; i<mHotseatConfig.length; i++) { |
| 529 | // load icon for this slot; currently unrelated to the actual activity |
| 530 | try { |
| 531 | mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i); |
| 532 | } catch (ArrayIndexOutOfBoundsException ex) { |
| 533 | Log.w(TAG, "Missing hotseat_icons array item #" + i); |
| 534 | mHotseatIcons[i] = null; |
| 535 | } |
| 536 | } |
| 537 | hotseatIconDrawables.recycle(); |
| 538 | } |
| 539 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 540 | PackageManager pm = getPackageManager(); |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 541 | for (int i=0; i<mHotseatConfig.length; i++) { |
| 542 | Intent intent = null; |
| 543 | if (mHotseatConfig[i].equals("*BROWSER*")) { |
| 544 | // magic value meaning "launch user's default web browser" |
| 545 | // replace it with a generic web request so we can see if there is indeed a default |
| 546 | String defaultUri = getString(R.string.default_browser_url); |
| 547 | intent = new Intent( |
| 548 | Intent.ACTION_VIEW, |
| 549 | ((defaultUri != null) |
| 550 | ? Uri.parse(defaultUri) |
| 551 | : getDefaultBrowserUri()) |
| 552 | ).addCategory(Intent.CATEGORY_BROWSABLE); |
| 553 | // note: if the user launches this without a default set, she |
| 554 | // will always be taken to the default URL above; this is |
| 555 | // unavoidable as we must specify a valid URL in order for the |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 556 | // chooser to appear, and once the user selects something, that |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 557 | // URL is unavoidably sent to the chosen app. |
| 558 | } else { |
| 559 | try { |
| 560 | intent = Intent.parseUri(mHotseatConfig[i], 0); |
| 561 | } catch (java.net.URISyntaxException ex) { |
| 562 | Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]); |
| 563 | // bogus; leave intent=null |
| 564 | } |
| 565 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 566 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 567 | if (intent == null) { |
| 568 | mHotseats[i] = null; |
| 569 | mHotseatLabels[i] = getText(R.string.activity_not_found); |
| 570 | continue; |
| 571 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 572 | |
| 573 | if (LOGD) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 574 | Log.d(TAG, "loadHotseats: hotseat " + i |
| 575 | + " initial intent=[" |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 576 | + intent.toUri(Intent.URI_INTENT_SCHEME) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 577 | + "]"); |
| 578 | } |
| 579 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 580 | ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 581 | List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 582 | if (LOGD) { |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 583 | Log.d(TAG, "Best match for intent: " + bestMatch); |
| 584 | Log.d(TAG, "All matches: "); |
| 585 | for (ResolveInfo ri : allMatches) { |
| 586 | Log.d(TAG, " --> " + ri); |
| 587 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 588 | } |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 589 | // did this resolve to a single app, or the resolver? |
| 590 | if (allMatches.size() == 0 || bestMatch == null) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 591 | // can't find any activity to handle this. let's leave the |
| 592 | // intent as-is and let Launcher show a toast when it fails |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 593 | // to launch. |
| 594 | mHotseats[i] = intent; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 595 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 596 | // set accessibility text to "Not installed" |
| 597 | mHotseatLabels[i] = getText(R.string.activity_not_found); |
| 598 | } else { |
| 599 | boolean found = false; |
| 600 | for (ResolveInfo ri : allMatches) { |
| 601 | if (bestMatch.activityInfo.name.equals(ri.activityInfo.name) |
| 602 | && bestMatch.activityInfo.applicationInfo.packageName |
| 603 | .equals(ri.activityInfo.applicationInfo.packageName)) { |
| 604 | found = true; |
| 605 | break; |
| 606 | } |
| 607 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 608 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 609 | if (!found) { |
| 610 | if (LOGD) Log.d(TAG, "Multiple options, no default yet"); |
| 611 | // the bestMatch is probably the ResolveActivity, meaning the |
| 612 | // user has not yet selected a default |
| 613 | // so: we'll keep the original intent for now |
| 614 | mHotseats[i] = intent; |
| 615 | |
| 616 | // set the accessibility text to "Select shortcut" |
| 617 | mHotseatLabels[i] = getText(R.string.title_select_shortcut); |
| 618 | } else { |
| 619 | // we have an app! |
| 620 | // now reconstruct the intent to launch it through the front |
| 621 | // door |
| 622 | ComponentName com = new ComponentName( |
| 623 | bestMatch.activityInfo.applicationInfo.packageName, |
| 624 | bestMatch.activityInfo.name); |
| 625 | mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com); |
| 626 | |
| 627 | // load the app label for accessibility |
| 628 | mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm); |
| 629 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | if (LOGD) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 633 | Log.d(TAG, "loadHotseats: hotseat " + i |
| 634 | + " final intent=[" |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 635 | + ((mHotseats[i] == null) |
| 636 | ? "null" |
| 637 | : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME)) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 638 | + "] label=[" + mHotseatLabels[i] |
| 639 | + "]" |
| 640 | ); |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 645 | @Override |
| 646 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 647 | mWaitingForResult = false; |
| 648 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 649 | // The pattern used here is that a user PICKs a specific application, |
| 650 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 651 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 652 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 653 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 654 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 655 | if (resultCode == RESULT_OK && mAddScreen != -1) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 656 | switch (requestCode) { |
| 657 | case REQUEST_PICK_APPLICATION: |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 658 | completeAddApplication(this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 659 | break; |
| 660 | case REQUEST_PICK_SHORTCUT: |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 661 | processShortcut(data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 662 | break; |
| 663 | case REQUEST_CREATE_SHORTCUT: |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 664 | completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 665 | break; |
| 666 | case REQUEST_PICK_LIVE_FOLDER: |
| 667 | addLiveFolder(data); |
| 668 | break; |
| 669 | case REQUEST_CREATE_LIVE_FOLDER: |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 670 | completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 671 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 672 | case REQUEST_PICK_APPWIDGET: |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 673 | addAppWidgetFromPick(data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 674 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 675 | case REQUEST_CREATE_APPWIDGET: |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 676 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 677 | completeAddAppWidget(appWidgetId, mAddScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 678 | break; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 679 | case REQUEST_PICK_WALLPAPER: |
| 680 | // We just wanted the activity result here so we can clear mWaitingForResult |
| 681 | break; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 682 | } |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 683 | } else if ((requestCode == REQUEST_PICK_APPWIDGET || |
| 684 | requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED && |
| 685 | data != null) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 686 | // Clean up the appWidgetId if we canceled |
| 687 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
| 688 | if (appWidgetId != -1) { |
| 689 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 690 | } |
| 691 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | @Override |
| 695 | protected void onResume() { |
| 696 | super.onResume(); |
| 697 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 698 | mPaused = false; |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 699 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 700 | if (mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 701 | mWorkspaceLoading = true; |
| 702 | mModel.startLoader(this, true); |
| 703 | mRestoring = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 704 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 705 | // When we resume Launcher, a different Activity might be responsible for the app |
| 706 | // market intent, so refresh the icon |
| 707 | updateAppMarketIcon(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 711 | protected void onPause() { |
| 712 | super.onPause(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 713 | // Some launcher layouts don't have a previous and next view |
| 714 | if (mPreviousView != null) { |
| 715 | dismissPreview(mPreviousView); |
Patrick Dubroy | ab962b7 | 2010-07-26 12:10:10 -0700 | [diff] [blame] | 716 | } |
| 717 | if (mNextView != null) { |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 718 | dismissPreview(mNextView); |
| 719 | } |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 720 | mDragController.cancelDrag(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 721 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 722 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 723 | @Override |
| 724 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 725 | // Flag the loader to stop early before switching |
| 726 | mModel.stopLoader(); |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 727 | mAllAppsGrid.surrender(); |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 728 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 729 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 730 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 731 | // We can't hide the IME if it was forced open. So don't bother |
| 732 | /* |
| 733 | @Override |
| 734 | public void onWindowFocusChanged(boolean hasFocus) { |
| 735 | super.onWindowFocusChanged(hasFocus); |
| 736 | |
| 737 | if (hasFocus) { |
| 738 | final InputMethodManager inputManager = (InputMethodManager) |
| 739 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 740 | WindowManager.LayoutParams lp = getWindow().getAttributes(); |
| 741 | inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new |
| 742 | android.os.Handler()) { |
| 743 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 744 | Log.d(TAG, "ResultReceiver got resultCode=" + resultCode); |
| 745 | } |
| 746 | }); |
| 747 | Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged"); |
| 748 | } |
| 749 | } |
| 750 | */ |
| 751 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 752 | private boolean acceptFilter() { |
| 753 | final InputMethodManager inputManager = (InputMethodManager) |
| 754 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 755 | return !inputManager.isFullscreenMode(); |
| 756 | } |
| 757 | |
| 758 | @Override |
| 759 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 760 | boolean handled = super.onKeyDown(keyCode, event); |
| 761 | if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) { |
| 762 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 763 | keyCode, event); |
| 764 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 765 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 766 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 767 | // showSearchDialog() |
| 768 | // If there are multiple keystrokes before the search dialog takes focus, |
| 769 | // onSearchRequested() will be called for every keystroke, |
| 770 | // but it is idempotent, so it's fine. |
| 771 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 775 | // Eat the long press event so the keyboard doesn't come up. |
| 776 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 777 | return true; |
| 778 | } |
| 779 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 780 | return handled; |
| 781 | } |
| 782 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 783 | private String getTypedText() { |
| 784 | return mDefaultKeySsb.toString(); |
| 785 | } |
| 786 | |
| 787 | private void clearTypedText() { |
| 788 | mDefaultKeySsb.clear(); |
| 789 | mDefaultKeySsb.clearSpans(); |
| 790 | Selection.setSelection(mDefaultKeySsb, 0); |
| 791 | } |
| 792 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 793 | /** |
| 794 | * Restores the previous state, if it exists. |
| 795 | * |
| 796 | * @param savedState The previous state. |
| 797 | */ |
| 798 | private void restoreState(Bundle savedState) { |
| 799 | if (savedState == null) { |
| 800 | return; |
| 801 | } |
| 802 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 803 | final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false); |
| 804 | if (allApps) { |
| 805 | showAllApps(false); |
| 806 | } |
| 807 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 808 | final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); |
| 809 | if (currentScreen > -1) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 810 | mWorkspace.setCurrentPage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 814 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 815 | if (addScreen > -1) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 816 | mAddScreen = addScreen; |
| 817 | mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 818 | mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 819 | mRestoring = true; |
| 820 | } |
| 821 | |
| 822 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 823 | if (renameFolder) { |
| 824 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 825 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 826 | mRestoring = true; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * Finds all the views we need and configure them properly. |
| 832 | */ |
| 833 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 834 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 835 | |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 836 | DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 837 | dragLayer.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 838 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 839 | mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 840 | mAllAppsGrid.setLauncher(this); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 841 | mAllAppsGrid.setDragController(dragController); |
Romain Guy | c16fea7 | 2010-03-12 17:17:56 -0800 | [diff] [blame] | 842 | ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 843 | // Manage focusability manually since this thing is always visible (in non-xlarge) |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 844 | ((View) mAllAppsGrid).setFocusable(false); |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 845 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 846 | if (LauncherApplication.isScreenXLarge()) { |
| 847 | // They need to be INVISIBLE initially so that they will be measured in the layout. |
| 848 | // Otherwise the animations are messed up when we show them for the first time. |
| 849 | ((View) mAllAppsGrid).setVisibility(View.INVISIBLE); |
| 850 | mHomeCustomizationDrawer.setVisibility(View.INVISIBLE); |
| 851 | } |
| 852 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 853 | mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); |
| 854 | final Workspace workspace = mWorkspace; |
Joe Onorato | f0dde09 | 2010-02-16 18:25:23 -0500 | [diff] [blame] | 855 | workspace.setHapticFeedbackEnabled(false); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 856 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 857 | DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone); |
| 858 | mDeleteZone = deleteZone; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 859 | |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 860 | View handleView = findViewById(R.id.all_apps_button); |
| 861 | if (handleView != null && handleView instanceof HandleView) { |
| 862 | // we don't use handle view in xlarge mode |
Michael Jurka | 7ef4f75 | 2010-08-03 16:04:26 -0700 | [diff] [blame] | 863 | mHandleView = (HandleView)handleView; |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 864 | mHandleView.setLauncher(this); |
| 865 | mHandleView.setOnClickListener(this); |
| 866 | mHandleView.setOnLongClickListener(this); |
| 867 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 868 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 869 | if (mCustomizePagedView != null) { |
| 870 | mCustomizePagedView.setLauncher(this); |
| 871 | mCustomizePagedView.setDragController(dragController); |
| 872 | mCustomizePagedView.update(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 873 | } else { |
| 874 | ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left); |
| 875 | hotseatLeft.setContentDescription(mHotseatLabels[0]); |
| 876 | hotseatLeft.setImageDrawable(mHotseatIcons[0]); |
| 877 | ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right); |
| 878 | hotseatRight.setContentDescription(mHotseatLabels[1]); |
| 879 | hotseatRight.setImageDrawable(mHotseatIcons[1]); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 880 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 881 | mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen); |
| 882 | mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 883 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 884 | Drawable previous = mPreviousView.getDrawable(); |
| 885 | Drawable next = mNextView.getDrawable(); |
| 886 | mWorkspace.setIndicators(previous, next); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 887 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 888 | mPreviousView.setHapticFeedbackEnabled(false); |
| 889 | mPreviousView.setOnLongClickListener(this); |
| 890 | mNextView.setHapticFeedbackEnabled(false); |
| 891 | mNextView.setOnLongClickListener(this); |
| 892 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 893 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 894 | workspace.setOnLongClickListener(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 895 | workspace.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 896 | workspace.setLauncher(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 897 | |
| 898 | deleteZone.setLauncher(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 899 | deleteZone.setDragController(dragController); |
Michael Jurka | 54f7ac3 | 2010-08-02 13:56:46 -0700 | [diff] [blame] | 900 | int deleteZoneHandleId; |
| 901 | if (LauncherApplication.isScreenXLarge()) { |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 902 | deleteZoneHandleId = R.id.all_apps_button; |
Michael Jurka | 54f7ac3 | 2010-08-02 13:56:46 -0700 | [diff] [blame] | 903 | } else { |
| 904 | deleteZoneHandleId = R.id.all_apps_button_cluster; |
| 905 | } |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 906 | deleteZone.setHandle(findViewById(deleteZoneHandleId)); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 907 | dragController.addDragListener(deleteZone); |
| 908 | |
| 909 | ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button); |
| 910 | if (infoButton != null) { |
| 911 | infoButton.setLauncher(this); |
| 912 | infoButton.setHandle(findViewById(R.id.configure_button)); |
| 913 | infoButton.setDragColor(getResources().getColor(R.color.app_info_filter)); |
| 914 | dragController.addDragListener(infoButton); |
| 915 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 916 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 917 | dragController.setDragScoller(workspace); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 918 | dragController.setScrollView(dragLayer); |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 919 | dragController.setMoveTarget(workspace); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 920 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 921 | // The order here is bottom to top. |
| 922 | dragController.addDropTarget(workspace); |
| 923 | dragController.addDropTarget(deleteZone); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 924 | if (infoButton != null) { |
| 925 | dragController.addDropTarget(infoButton); |
| 926 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 927 | } |
| 928 | |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 929 | @SuppressWarnings({"UnusedDeclaration"}) |
| 930 | public void previousScreen(View v) { |
Joe Onorato | 61597bd | 2009-11-19 12:51:57 -0800 | [diff] [blame] | 931 | if (!isAllAppsVisible()) { |
| 932 | mWorkspace.scrollLeft(); |
| 933 | } |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | @SuppressWarnings({"UnusedDeclaration"}) |
| 937 | public void nextScreen(View v) { |
Joe Onorato | 61597bd | 2009-11-19 12:51:57 -0800 | [diff] [blame] | 938 | if (!isAllAppsVisible()) { |
| 939 | mWorkspace.scrollRight(); |
| 940 | } |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 941 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 942 | |
| 943 | @SuppressWarnings({"UnusedDeclaration"}) |
| 944 | public void launchHotSeat(View v) { |
Daniel Sandler | 3e9454a | 2010-05-24 11:22:41 -0400 | [diff] [blame] | 945 | if (isAllAppsVisible()) return; |
| 946 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 947 | int index = -1; |
| 948 | if (v.getId() == R.id.hotseat_left) { |
| 949 | index = 0; |
| 950 | } else if (v.getId() == R.id.hotseat_right) { |
| 951 | index = 1; |
| 952 | } |
| 953 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 954 | // reload these every tap; you never know when they might change |
| 955 | loadHotseats(); |
| 956 | if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) { |
| 957 | Intent intent = mHotseats[index]; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 958 | startActivitySafely( |
| 959 | mHotseats[index], |
| 960 | "hotseat" |
| 961 | ); |
| 962 | } |
| 963 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 964 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 965 | /** |
| 966 | * Creates a view representing a shortcut. |
| 967 | * |
| 968 | * @param info The data structure describing the shortcut. |
| 969 | * |
| 970 | * @return A View inflated from R.layout.application. |
| 971 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 972 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 973 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 974 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /** |
| 978 | * Creates a view representing a shortcut inflated from the specified resource. |
| 979 | * |
| 980 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 981 | * @param parent The group the shortcut belongs to. |
| 982 | * @param info The data structure describing the shortcut. |
| 983 | * |
| 984 | * @return A View inflated from layoutResId. |
| 985 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 986 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 987 | TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false); |
| 988 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 989 | favorite.setCompoundDrawablesWithIntrinsicBounds(null, |
| 990 | new FastBitmapDrawable(info.getIcon(mIconCache)), |
| 991 | null, null); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 992 | favorite.setText(info.title); |
| 993 | favorite.setTag(info); |
| 994 | favorite.setOnClickListener(this); |
| 995 | |
| 996 | return favorite; |
| 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * Add an application shortcut to the workspace. |
| 1001 | * |
| 1002 | * @param data The intent describing the application. |
| 1003 | * @param cellInfo The position on screen where to create the shortcut. |
| 1004 | */ |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1005 | void completeAddApplication(Context context, Intent data, int screen, |
| 1006 | int intersectCellX, int intersectCellY) { |
| 1007 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1008 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1009 | |
| 1010 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1011 | showOutOfSpaceMessage(); |
| 1012 | return; |
| 1013 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1014 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1015 | final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(), |
| 1016 | data, context); |
| 1017 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1018 | if (info != null) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1019 | info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1020 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1021 | info.container = ItemInfo.NO_ID; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1022 | mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1], |
| 1023 | isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1024 | } else { |
| 1025 | 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] | 1026 | } |
| 1027 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1028 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1029 | /** |
| 1030 | * Add a shortcut to the workspace. |
| 1031 | * |
| 1032 | * @param data The intent describing the shortcut. |
| 1033 | * @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] | 1034 | */ |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1035 | private void completeAddShortcut(Intent data, int screen, |
| 1036 | int intersectCellX, int intersectCellY) { |
| 1037 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1038 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1039 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1040 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1041 | showOutOfSpaceMessage(); |
| 1042 | return; |
| 1043 | } |
| 1044 | |
| 1045 | final ShortcutInfo info = mModel.addShortcut( |
| 1046 | this, data, screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1047 | |
| 1048 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1049 | final View view = createShortcut(info); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1050 | mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1054 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1055 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1056 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1057 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1058 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1059 | * @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] | 1060 | */ |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1061 | private void completeAddAppWidget(int appWidgetId, int screen) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1062 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1063 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1064 | // Calculate the grid spans needed to fit this widget |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1065 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1066 | int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1067 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1068 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1069 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1070 | // if we are placing widgets on a "spring-loaded" screen |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1071 | final int[] cellXY = mTmpAddItemCellCoordinates; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1072 | |
| 1073 | // For now, we don't save the coordinate where we dropped the icon because we're not |
| 1074 | // supporting spring-loaded mini-screens; however, leaving the ability to directly place |
| 1075 | // a widget on the home screen in case we want to add it in the future |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1076 | final int[] touchXY = null; |
| 1077 | //final int[] touchXY = mAddDropPosition; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1078 | boolean findNearestVacantAreaFailed = false; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1079 | boolean foundCellSpan = false; |
| 1080 | if (touchXY != null) { |
| 1081 | // when dragging and dropping, just find the closest free spot |
| 1082 | CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1083 | int[] result = screenLayout.findNearestVacantArea( |
| 1084 | touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1085 | findNearestVacantAreaFailed = (result == null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1086 | foundCellSpan = !findNearestVacantAreaFailed; |
| 1087 | } else { |
| 1088 | if (mAddIntersectCellX != -1 && mAddIntersectCellY != -1) { |
| 1089 | // if we long pressed on an empty cell to bring up a menu, |
| 1090 | // make sure we intersect the empty cell |
| 1091 | foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1], |
| 1092 | mAddIntersectCellX, mAddIntersectCellY); |
| 1093 | } else { |
| 1094 | // if we went through the menu -> add, just find any spot |
| 1095 | foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]); |
| 1096 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1099 | if (!foundCellSpan) { |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1100 | if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1101 | showOutOfSpaceMessage(); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1102 | return; |
| 1103 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1104 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1105 | // Build Launcher-specific widget info and save to database |
| 1106 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1107 | launcherInfo.spanX = spanXY[0]; |
| 1108 | launcherInfo.spanY = spanXY[1]; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1109 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1110 | LauncherModel.addItemToDatabase(this, launcherInfo, |
| 1111 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1112 | screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1113 | |
| 1114 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1115 | mDesktopItems.add(launcherInfo); |
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 | // Perform actual inflation because we're live |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1118 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1119 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1120 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1121 | launcherInfo.hostView.setTag(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1122 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1123 | mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1124 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1125 | } |
| 1126 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1127 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1128 | void showOutOfSpaceMessage() { |
| 1129 | Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show(); |
| 1130 | } |
| 1131 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1132 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
| 1133 | mDesktopItems.remove(launcherInfo); |
| 1134 | launcherInfo.hostView = null; |
| 1135 | } |
| 1136 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1137 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1138 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1139 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1140 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1141 | void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1142 | getWindow().closeAllPanels(); |
| 1143 | |
| 1144 | try { |
| 1145 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 1146 | // Unlock the workspace if the dialog was showing |
| 1147 | } catch (Exception e) { |
| 1148 | // An exception is thrown if the dialog is not visible, which is fine |
| 1149 | } |
| 1150 | |
| 1151 | try { |
| 1152 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 1153 | // Unlock the workspace if the dialog was showing |
| 1154 | } catch (Exception e) { |
| 1155 | // An exception is thrown if the dialog is not visible, which is fine |
| 1156 | } |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1157 | |
| 1158 | // Whatever we were doing is hereby canceled. |
| 1159 | mWaitingForResult = false; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1160 | } |
| 1161 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1162 | @Override |
| 1163 | protected void onNewIntent(Intent intent) { |
| 1164 | super.onNewIntent(intent); |
| 1165 | |
| 1166 | // Close the menu |
| 1167 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1168 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1169 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1170 | |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 1171 | boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1172 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
| 1173 | boolean allAppsVisible = isAllAppsVisible(); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1174 | boolean customizationDrawerVisible = isCustomizationDrawerVisible(); |
| 1175 | |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1176 | // in all these cases, only animate if we're already on home |
| 1177 | if (LauncherApplication.isScreenXLarge()) { |
Michael Jurka | 99229f6 | 2010-09-09 11:49:32 -0700 | [diff] [blame] | 1178 | mWorkspace.unshrink(alreadyOnHome); |
| 1179 | } |
| 1180 | if (!mWorkspace.isDefaultPageShowing()) { |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1181 | // on the phone, we don't animate the change to the workspace if all apps is visible |
Michael Jurka | 99229f6 | 2010-09-09 11:49:32 -0700 | [diff] [blame] | 1182 | mWorkspace.moveToDefaultScreen( |
| 1183 | alreadyOnHome && (LauncherApplication.isScreenXLarge() || !allAppsVisible)); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1184 | } |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 1185 | closeAllApps(alreadyOnHome && allAppsVisible); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 1186 | hideCustomizationDrawer(alreadyOnHome); |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1187 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1188 | final View v = getWindow().peekDecorView(); |
| 1189 | if (v != null && v.getWindowToken() != null) { |
| 1190 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1191 | INPUT_METHOD_SERVICE); |
| 1192 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | @Override |
| 1198 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 1199 | // Do not call super here |
| 1200 | mSavedInstanceState = savedInstanceState; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1201 | |
| 1202 | if (mHomeCustomizationDrawer != null) { |
| 1203 | String cur = savedInstanceState.getString("currentTab"); |
| 1204 | if (cur != null) { |
| 1205 | mHomeCustomizationDrawer.setCurrentTabByTag(cur); |
| 1206 | } |
| 1207 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | @Override |
| 1211 | protected void onSaveInstanceState(Bundle outState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1212 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1213 | |
| 1214 | final ArrayList<Folder> folders = mWorkspace.getOpenFolders(); |
| 1215 | if (folders.size() > 0) { |
| 1216 | final int count = folders.size(); |
| 1217 | long[] ids = new long[count]; |
| 1218 | for (int i = 0; i < count; i++) { |
| 1219 | final FolderInfo info = folders.get(i).getInfo(); |
| 1220 | ids[i] = info.id; |
| 1221 | } |
| 1222 | outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids); |
| 1223 | } else { |
| 1224 | super.onSaveInstanceState(outState); |
| 1225 | } |
| 1226 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1227 | // TODO should not do this if the drawer is currently closing. |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1228 | if (isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1229 | outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1230 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1231 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1232 | if (mAddScreen > -1 && mWaitingForResult) { |
| 1233 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen); |
| 1234 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX); |
| 1235 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | if (mFolderInfo != null && mWaitingForResult) { |
| 1239 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1240 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1241 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1242 | |
| 1243 | if (mHomeCustomizationDrawer != null) { |
| 1244 | String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag(); |
| 1245 | if (currentTabTag != null) { |
| 1246 | outState.putString("currentTab", currentTabTag); |
| 1247 | } |
| 1248 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | @Override |
| 1252 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1253 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1254 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1255 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1256 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1257 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1258 | 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] | 1259 | } |
| 1260 | |
| 1261 | TextKeyListener.getInstance().release(); |
| 1262 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1263 | mModel.stopLoader(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1264 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1265 | unbindDesktopItems(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1266 | |
| 1267 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1268 | |
Patrick Dubroy | ab962b7 | 2010-07-26 12:10:10 -0700 | [diff] [blame] | 1269 | // Some launcher layouts don't have a previous and next view |
| 1270 | if (mPreviousView != null) { |
| 1271 | dismissPreview(mPreviousView); |
| 1272 | } |
| 1273 | if (mNextView != null) { |
| 1274 | dismissPreview(mNextView); |
| 1275 | } |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1276 | |
| 1277 | unregisterReceiver(mCloseSystemDialogsReceiver); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | @Override |
| 1281 | public void startActivityForResult(Intent intent, int requestCode) { |
Romain Guy | 08f9749 | 2009-06-29 14:41:20 -0700 | [diff] [blame] | 1282 | if (requestCode >= 0) mWaitingForResult = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1283 | super.startActivityForResult(intent, requestCode); |
| 1284 | } |
| 1285 | |
| 1286 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1287 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1288 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1289 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1290 | closeAllApps(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1291 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1292 | if (initialQuery == null) { |
| 1293 | // Use any text typed in the launcher as the initial query |
| 1294 | initialQuery = getTypedText(); |
| 1295 | clearTypedText(); |
| 1296 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1297 | if (appSearchData == null) { |
| 1298 | appSearchData = new Bundle(); |
Bjorn Bringert | 3e244cf | 2010-02-10 14:17:35 +0000 | [diff] [blame] | 1299 | appSearchData.putString(Search.SOURCE, "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1300 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1301 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1302 | final SearchManager searchManager = |
| 1303 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1304 | searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1305 | appSearchData, globalSearch); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | @Override |
| 1309 | public boolean onCreateOptionsMenu(Menu menu) { |
Patrick Dubroy | 5905bca | 2010-09-08 22:43:38 -0700 | [diff] [blame] | 1310 | if (isWorkspaceLocked()) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1311 | return false; |
| 1312 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1313 | |
| 1314 | super.onCreateOptionsMenu(menu); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1315 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1316 | menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add) |
| 1317 | .setIcon(android.R.drawable.ic_menu_add) |
| 1318 | .setAlphabeticShortcut('A'); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1319 | 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] | 1320 | .setIcon(android.R.drawable.ic_menu_gallery) |
| 1321 | .setAlphabeticShortcut('W'); |
| 1322 | menu.add(0, MENU_SEARCH, 0, R.string.menu_search) |
| 1323 | .setIcon(android.R.drawable.ic_search_category_default) |
| 1324 | .setAlphabeticShortcut(SearchManager.MENU_KEY); |
| 1325 | menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications) |
| 1326 | .setIcon(com.android.internal.R.drawable.ic_menu_notifications) |
| 1327 | .setAlphabeticShortcut('N'); |
| 1328 | |
| 1329 | final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1330 | settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1331 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1332 | |
| 1333 | menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) |
| 1334 | .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') |
| 1335 | .setIntent(settings); |
| 1336 | |
| 1337 | return true; |
| 1338 | } |
| 1339 | |
| 1340 | @Override |
| 1341 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 1342 | super.onPrepareOptionsMenu(menu); |
| 1343 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1344 | // If all apps is animating, don't show the menu, because we don't know |
| 1345 | // which one to show. |
Patrick Dubroy | ff5f040 | 2010-07-26 15:23:26 -0700 | [diff] [blame] | 1346 | if (mAllAppsGrid.isAnimating()) { |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1347 | return false; |
| 1348 | } |
| 1349 | |
| 1350 | // Only show the add and wallpaper options when we're not in all apps. |
Patrick Dubroy | ff5f040 | 2010-07-26 15:23:26 -0700 | [diff] [blame] | 1351 | boolean visible = !mAllAppsGrid.isVisible(); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1352 | menu.setGroupVisible(MENU_GROUP_ADD, visible); |
| 1353 | menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible); |
| 1354 | |
| 1355 | // Disable add if the workspace is full. |
| 1356 | if (visible) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1357 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage()); |
| 1358 | menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell()); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1359 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1360 | |
| 1361 | return true; |
| 1362 | } |
| 1363 | |
| 1364 | @Override |
| 1365 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1366 | switch (item.getItemId()) { |
| 1367 | case MENU_ADD: |
| 1368 | addItems(); |
| 1369 | return true; |
| 1370 | case MENU_WALLPAPER_SETTINGS: |
| 1371 | startWallpaper(); |
| 1372 | return true; |
| 1373 | case MENU_SEARCH: |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1374 | onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1375 | return true; |
| 1376 | case MENU_NOTIFICATIONS: |
| 1377 | showNotifications(); |
| 1378 | return true; |
| 1379 | } |
| 1380 | |
| 1381 | return super.onOptionsItemSelected(item); |
| 1382 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1383 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1384 | /** |
| 1385 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1386 | * argument for {@link #startSearch} to true. |
| 1387 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1388 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1389 | @Override |
| 1390 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1391 | startSearch(null, false, null, true); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1392 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1395 | public boolean isWorkspaceLocked() { |
| 1396 | return mWorkspaceLoading || mWaitingForResult; |
| 1397 | } |
| 1398 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1399 | private void addItems() { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1400 | if (LauncherApplication.isScreenXLarge()) { |
| 1401 | // Animate the widget chooser up from the bottom of the screen |
| 1402 | if (!isCustomizationDrawerVisible()) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 1403 | showCustomizationDrawer(true); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1404 | } |
| 1405 | } else { |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 1406 | closeAllApps(true); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1407 | showAddDialog(-1, -1); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1408 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1409 | } |
| 1410 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1411 | private void resetAddInfo() { |
| 1412 | mAddScreen = -1; |
| 1413 | mAddIntersectCellX = -1; |
| 1414 | mAddIntersectCellY = -1; |
| 1415 | mAddDropPosition = null; |
| 1416 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1417 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1418 | void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) { |
| 1419 | resetAddInfo(); |
| 1420 | mAddScreen = screen; |
| 1421 | |
| 1422 | // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner |
| 1423 | mAddDropPosition = position; |
| 1424 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1425 | int appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
| 1426 | AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider); |
| 1427 | addAppWidgetImpl(appWidgetId); |
| 1428 | } |
| 1429 | |
| 1430 | void addAppWidgetFromPick(Intent data) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1431 | // TODO: catch bad widget exception when sent |
| 1432 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1433 | // TODO: Is this log message meaningful? |
| 1434 | if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras()); |
| 1435 | addAppWidgetImpl(appWidgetId); |
| 1436 | } |
| 1437 | |
| 1438 | void addAppWidgetImpl(int appWidgetId) { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1439 | AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1440 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1441 | if (appWidget.configure != null) { |
| 1442 | // Launch over to configure widget, if needed |
| 1443 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
| 1444 | intent.setComponent(appWidget.configure); |
| 1445 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
| 1446 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 1447 | startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1448 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1449 | // Otherwise just add it |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1450 | completeAddAppWidget(appWidgetId, mAddScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1451 | } |
| 1452 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1453 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1454 | void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) { |
| 1455 | resetAddInfo(); |
| 1456 | mAddScreen = screen; |
| 1457 | mAddDropPosition = position; |
| 1458 | |
| 1459 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 1460 | createShortcutIntent.setComponent(componentName); |
| 1461 | processShortcut(createShortcutIntent); |
| 1462 | } |
| 1463 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1464 | void processShortcut(Intent intent) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1465 | // Handle case where user selected "Applications" |
| 1466 | String applicationName = getResources().getString(R.string.group_applications); |
| 1467 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1468 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1469 | if (applicationName != null && applicationName.equals(shortcutName)) { |
| 1470 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1471 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1472 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1473 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1474 | pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1475 | startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1476 | } else { |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1477 | startActivityForResult(intent, REQUEST_CREATE_SHORTCUT); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1478 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1479 | } |
| 1480 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 1481 | void processWallpaper(Intent intent) { |
| 1482 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 1483 | } |
| 1484 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1485 | void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) { |
| 1486 | resetAddInfo(); |
| 1487 | mAddScreen = screen; |
| 1488 | mAddDropPosition = position; |
| 1489 | |
| 1490 | Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER); |
| 1491 | createFolderIntent.setComponent(componentName); |
| 1492 | |
| 1493 | addLiveFolder(createFolderIntent); |
| 1494 | } |
| 1495 | |
| 1496 | void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1497 | // Handle case where user selected "Folder" |
Jeffrey Sharkey | c4bbd0a | 2009-03-24 22:47:52 -0700 | [diff] [blame] | 1498 | String folderName = getResources().getString(R.string.group_folder); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1499 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1500 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1501 | if (folderName != null && folderName.equals(shortcutName)) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1502 | addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1503 | } else { |
| 1504 | startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER); |
| 1505 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1506 | } |
| 1507 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1508 | void addFolder(int screen, int intersectCellX, int intersectCellY) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1509 | UserFolderInfo folderInfo = new UserFolderInfo(); |
| 1510 | folderInfo.title = getText(R.string.folder_name); |
| 1511 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1512 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1513 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1514 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1515 | showOutOfSpaceMessage(); |
| 1516 | return; |
| 1517 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1518 | |
| 1519 | // Update the model |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1520 | LauncherModel.addItemToDatabase(this, folderInfo, |
| 1521 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1522 | screen, cellXY[0], cellXY[1], false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1523 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1524 | |
| 1525 | // Create the view |
| 1526 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1527 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1528 | mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1529 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1530 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1531 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1532 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1533 | } |
| 1534 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1535 | private void completeAddLiveFolder(Intent data, int screen, int intersectCellX, int intersectCellY) { |
| 1536 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1537 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1538 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1539 | showOutOfSpaceMessage(); |
| 1540 | return; |
| 1541 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1542 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1543 | final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1544 | |
| 1545 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1546 | final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1547 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1548 | mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | static LiveFolderInfo addLiveFolder(Context context, Intent data, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1553 | int screen, int cellX, int cellY, boolean notify) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1554 | |
| 1555 | Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT); |
| 1556 | String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME); |
| 1557 | |
| 1558 | Drawable icon = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1559 | Intent.ShortcutIconResource iconResource = null; |
| 1560 | |
| 1561 | Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON); |
| 1562 | if (extra != null && extra instanceof Intent.ShortcutIconResource) { |
| 1563 | try { |
| 1564 | iconResource = (Intent.ShortcutIconResource) extra; |
| 1565 | final PackageManager packageManager = context.getPackageManager(); |
| 1566 | Resources resources = packageManager.getResourcesForApplication( |
| 1567 | iconResource.packageName); |
| 1568 | final int id = resources.getIdentifier(iconResource.resourceName, null, null); |
| 1569 | icon = resources.getDrawable(id); |
| 1570 | } catch (Exception e) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1571 | 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] | 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | if (icon == null) { |
| 1576 | icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder); |
| 1577 | } |
| 1578 | |
| 1579 | final LiveFolderInfo info = new LiveFolderInfo(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1580 | info.icon = Utilities.createIconBitmap(icon, context); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1581 | info.title = name; |
| 1582 | info.iconResource = iconResource; |
| 1583 | info.uri = data.getData(); |
| 1584 | info.baseIntent = baseIntent; |
| 1585 | info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, |
| 1586 | LiveFolders.DISPLAY_MODE_GRID); |
| 1587 | |
| 1588 | LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1589 | screen, cellX, cellY, notify); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1590 | sFolders.put(info.id, info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1591 | |
| 1592 | return info; |
| 1593 | } |
| 1594 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1595 | private void showNotifications() { |
| 1596 | final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE); |
| 1597 | if (statusBar != null) { |
| 1598 | statusBar.expand(); |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | private void startWallpaper() { |
Joe Onorato | e616866 | 2009-11-08 13:39:30 -0500 | [diff] [blame] | 1603 | closeAllApps(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1604 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
Dianne Hackborn | 8355ae3 | 2009-09-07 21:47:51 -0700 | [diff] [blame] | 1605 | Intent chooser = Intent.createChooser(pickWallpaper, |
| 1606 | getText(R.string.chooser_wallpaper)); |
Romain Guy | f2826c7 | 2009-11-12 17:39:34 -0800 | [diff] [blame] | 1607 | // NOTE: Adds a configure option to the chooser if the wallpaper supports it |
| 1608 | // Removed in Eclair MR1 |
| 1609 | // WallpaperManager wm = (WallpaperManager) |
| 1610 | // getSystemService(Context.WALLPAPER_SERVICE); |
| 1611 | // WallpaperInfo wi = wm.getWallpaperInfo(); |
| 1612 | // if (wi != null && wi.getSettingsActivity() != null) { |
| 1613 | // LabeledIntent li = new LabeledIntent(getPackageName(), |
| 1614 | // R.string.configure_wallpaper, 0); |
| 1615 | // li.setClassName(wi.getPackageName(), wi.getSettingsActivity()); |
| 1616 | // chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li }); |
| 1617 | // } |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 1618 | startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1619 | } |
| 1620 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1621 | /** |
| 1622 | * Registers various content observers. The current implementation registers |
| 1623 | * only a favorites observer to keep track of the favorites applications. |
| 1624 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1625 | private void registerContentObservers() { |
| 1626 | ContentResolver resolver = getContentResolver(); |
| 1627 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 1628 | true, mWidgetObserver); |
| 1629 | } |
| 1630 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1631 | @Override |
| 1632 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 1633 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 1634 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1635 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1636 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1637 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jason Sams | eb5615d | 2009-11-30 11:50:10 -0800 | [diff] [blame] | 1638 | if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1639 | dumpState(); |
| 1640 | return true; |
| 1641 | } |
| 1642 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1643 | } |
| 1644 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 1645 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1646 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1647 | return true; |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | return super.dispatchKeyEvent(event); |
| 1652 | } |
| 1653 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1654 | @Override |
| 1655 | public void onBackPressed() { |
| 1656 | if (isAllAppsVisible()) { |
| 1657 | closeAllApps(true); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1658 | } else if (isCustomizationDrawerVisible()) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 1659 | hideCustomizationDrawer(true); |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1660 | } else { |
| 1661 | closeFolder(); |
| 1662 | } |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1663 | // Some launcher layouts don't have a previous and next view |
| 1664 | if (mPreviousView != null) { |
| 1665 | dismissPreview(mPreviousView); |
| 1666 | dismissPreview(mNextView); |
| 1667 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1668 | } |
| 1669 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1670 | private void closeFolder() { |
| 1671 | Folder folder = mWorkspace.getOpenFolder(); |
| 1672 | if (folder != null) { |
| 1673 | closeFolder(folder); |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | void closeFolder(Folder folder) { |
| 1678 | folder.getInfo().opened = false; |
| 1679 | ViewGroup parent = (ViewGroup) folder.getParent(); |
| 1680 | if (parent != null) { |
| 1681 | parent.removeView(folder); |
Joe Onorato | b6341e9 | 2009-11-02 10:41:48 -0500 | [diff] [blame] | 1682 | if (folder instanceof DropTarget) { |
| 1683 | // Live folders aren't DropTargets. |
| 1684 | mDragController.removeDropTarget((DropTarget)folder); |
| 1685 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1686 | } |
| 1687 | folder.onClose(); |
| 1688 | } |
| 1689 | |
| 1690 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1691 | * Re-listen when widgets are reset. |
| 1692 | */ |
| 1693 | private void onAppWidgetReset() { |
| 1694 | mAppWidgetHost.startListening(); |
| 1695 | } |
| 1696 | |
| 1697 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1698 | * Go through the and disconnect any of the callbacks in the drawables and the views or we |
| 1699 | * leak the previous Home screen on orientation change. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1700 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1701 | private void unbindDesktopItems() { |
| 1702 | for (ItemInfo item: mDesktopItems) { |
| 1703 | item.unbind(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1704 | } |
| 1705 | } |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1706 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1707 | /** |
| 1708 | * Launches the intent referred by the clicked shortcut. |
| 1709 | * |
| 1710 | * @param v The view representing the clicked shortcut. |
| 1711 | */ |
| 1712 | public void onClick(View v) { |
| 1713 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1714 | if (tag instanceof ShortcutInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1715 | // Open shortcut |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1716 | final Intent intent = ((ShortcutInfo) tag).intent; |
Joe Onorato | 13724ea | 2009-12-02 21:16:35 -0800 | [diff] [blame] | 1717 | int[] pos = new int[2]; |
| 1718 | v.getLocationOnScreen(pos); |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1719 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 1720 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 1721 | startActivitySafely(intent, tag); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1722 | } else if (tag instanceof FolderInfo) { |
| 1723 | handleFolderClick((FolderInfo) tag); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1724 | } else if (v == mHandleView) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 1725 | if (isAllAppsVisible()) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1726 | closeAllApps(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1727 | } else { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1728 | showAllApps(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1729 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1733 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1734 | // this is an intercepted event being forwarded from mWorkspace; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1735 | // clicking anywhere on the workspace causes the drawer to slide down |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 1736 | hideCustomizationDrawer(true); |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1737 | return false; |
| 1738 | } |
| 1739 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1740 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 1741 | * Event handler for the search button |
| 1742 | * |
| 1743 | * @param v The view that was clicked. |
| 1744 | */ |
| 1745 | public void onClickSearchButton(View v) { |
| 1746 | Intent i = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); |
| 1747 | View button = findViewById(R.id.search_button); |
| 1748 | i.setSourceBounds( |
| 1749 | new Rect(button.getLeft(), button.getTop(), button.getRight(), button.getBottom())); |
| 1750 | startActivity(i); |
| 1751 | } |
| 1752 | |
| 1753 | /** |
| 1754 | * Event handler for the "gear" button that appears on the home screen, which |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1755 | * enters home screen customization mode. |
| 1756 | * |
| 1757 | * @param v The view that was clicked. |
| 1758 | */ |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 1759 | public void onClickConfigureButton(View v) { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1760 | addItems(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 1763 | /** |
| 1764 | * Event handler for the "grid" button that appears on the home screen, which |
| 1765 | * enters all apps mode. |
| 1766 | * |
| 1767 | * @param v The view that was clicked. |
| 1768 | */ |
| 1769 | public void onClickAllAppsButton(View v) { |
| 1770 | showAllApps(true); |
| 1771 | } |
| 1772 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 1773 | public void onClickAppMarketButton(View v) { |
| 1774 | if (mAppMarketIntent != null) { |
| 1775 | startActivitySafely(mAppMarketIntent, "app market"); |
| 1776 | } |
| 1777 | } |
| 1778 | |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 1779 | void startApplicationDetailsActivity(ComponentName componentName) { |
| 1780 | String packageName = componentName.getPackageName(); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 1781 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 1782 | Uri.fromParts("package", packageName, null)); |
| 1783 | startActivity(intent); |
| 1784 | } |
| 1785 | |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 1786 | void startApplicationUninstallActivity(ApplicationInfo appInfo) { |
| 1787 | if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) { |
| 1788 | // System applications cannot be installed. For now, show a toast explaining that. |
| 1789 | // We may give them the option of disabling apps this way. |
| 1790 | int messageId = R.string.uninstall_system_app_text; |
| 1791 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
| 1792 | } else { |
| 1793 | String packageName = appInfo.componentName.getPackageName(); |
| 1794 | String className = appInfo.componentName.getClassName(); |
| 1795 | Intent intent = new Intent( |
| 1796 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
| 1797 | startActivity(intent); |
| 1798 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 1801 | void startActivitySafely(Intent intent, Object tag) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1802 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1803 | try { |
| 1804 | startActivity(intent); |
| 1805 | } catch (ActivityNotFoundException e) { |
| 1806 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1807 | 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] | 1808 | } catch (SecurityException e) { |
| 1809 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1810 | 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] | 1811 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 1812 | "or use the exported attribute for this activity. " |
| 1813 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1814 | } |
| 1815 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1816 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 1817 | void startActivityForResultSafely(Intent intent, int requestCode) { |
| 1818 | try { |
| 1819 | startActivityForResult(intent, requestCode); |
| 1820 | } catch (ActivityNotFoundException e) { |
| 1821 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 1822 | } catch (SecurityException e) { |
| 1823 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 1824 | Log.e(TAG, "Launcher does not have the permission to launch " + intent + |
| 1825 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
| 1826 | "or use the exported attribute for this activity.", e); |
| 1827 | } |
| 1828 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1829 | |
| 1830 | private void handleFolderClick(FolderInfo folderInfo) { |
| 1831 | if (!folderInfo.opened) { |
| 1832 | // Close any open folder |
| 1833 | closeFolder(); |
| 1834 | // Open the requested folder |
| 1835 | openFolder(folderInfo); |
| 1836 | } else { |
| 1837 | // Find the open folder... |
| 1838 | Folder openFolder = mWorkspace.getFolderForTag(folderInfo); |
| 1839 | int folderScreen; |
| 1840 | if (openFolder != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1841 | folderScreen = mWorkspace.getPageForView(openFolder); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1842 | // .. and close it |
| 1843 | closeFolder(openFolder); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1844 | if (folderScreen != mWorkspace.getCurrentPage()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1845 | // Close any folder open on the current screen |
| 1846 | closeFolder(); |
| 1847 | // Pull the folder onto this screen |
| 1848 | openFolder(folderInfo); |
| 1849 | } |
| 1850 | } |
| 1851 | } |
| 1852 | } |
| 1853 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1854 | /** |
| 1855 | * Opens the user fodler described by the specified tag. The opening of the folder |
| 1856 | * is animated relative to the specified View. If the View is null, no animation |
| 1857 | * is played. |
| 1858 | * |
| 1859 | * @param folderInfo The FolderInfo describing the folder to open. |
| 1860 | */ |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1861 | public void openFolder(FolderInfo folderInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1862 | Folder openFolder; |
| 1863 | |
| 1864 | if (folderInfo instanceof UserFolderInfo) { |
| 1865 | openFolder = UserFolder.fromXml(this); |
| 1866 | } else if (folderInfo instanceof LiveFolderInfo) { |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 1867 | openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1868 | } else { |
| 1869 | return; |
| 1870 | } |
| 1871 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1872 | openFolder.setDragController(mDragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1873 | openFolder.setLauncher(this); |
| 1874 | |
| 1875 | openFolder.bind(folderInfo); |
| 1876 | folderInfo.opened = true; |
| 1877 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1878 | mWorkspace.addInFullScreen(openFolder, folderInfo.screen); |
| 1879 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1880 | openFolder.onOpen(); |
| 1881 | } |
| 1882 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1883 | public boolean onLongClick(View v) { |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1884 | switch (v.getId()) { |
| 1885 | case R.id.previous_screen: |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1886 | if (!isAllAppsVisible()) { |
| 1887 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1888 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1889 | showPreviews(v); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1890 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1891 | return true; |
| 1892 | case R.id.next_screen: |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1893 | if (!isAllAppsVisible()) { |
| 1894 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1895 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1896 | showPreviews(v); |
| 1897 | } |
| 1898 | return true; |
| 1899 | case R.id.all_apps_button: |
| 1900 | if (!isAllAppsVisible()) { |
| 1901 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1902 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 1903 | showPreviews(v); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1904 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1905 | return true; |
| 1906 | } |
| 1907 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1908 | if (isWorkspaceLocked()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1909 | return false; |
| 1910 | } |
| 1911 | |
| 1912 | if (!(v instanceof CellLayout)) { |
| 1913 | v = (View) v.getParent(); |
| 1914 | } |
| 1915 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1916 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1917 | resetAddInfo(); |
| 1918 | CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1919 | // This happens when long clicking an item with the dpad/trackball |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1920 | if (longClickCellInfo == null || !longClickCellInfo.valid) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1921 | return true; |
| 1922 | } |
| 1923 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1924 | final View itemUnderLongClick = longClickCellInfo.cell; |
| 1925 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1926 | if (mWorkspace.allowLongPress()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1927 | if (itemUnderLongClick == null) { |
| 1928 | // User long pressed on empty space |
| 1929 | mWorkspace.setAllowLongPress(false); |
| 1930 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1931 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 1932 | if (LauncherApplication.isScreenXLarge()) { |
| 1933 | // Animate the widget chooser up from the bottom of the screen |
| 1934 | if (!isCustomizationDrawerVisible()) { |
| 1935 | showCustomizationDrawer(true); |
| 1936 | } |
| 1937 | } else { |
| 1938 | showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1939 | } |
| 1940 | } else { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1941 | if (!(itemUnderLongClick instanceof Folder)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1942 | // User long pressed on an item |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1943 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 1944 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 1945 | mAddIntersectCellX = longClickCellInfo.cellX; |
| 1946 | mAddIntersectCellY = longClickCellInfo.cellY; |
| 1947 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | return true; |
| 1952 | } |
| 1953 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1954 | @SuppressWarnings({"unchecked"}) |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1955 | private void dismissPreview(final View v) { |
| 1956 | final PopupWindow window = (PopupWindow) v.getTag(); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1957 | if (window != null) { |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1958 | window.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 1959 | public void onDismiss() { |
| 1960 | ViewGroup group = (ViewGroup) v.getTag(R.id.workspace); |
| 1961 | int count = group.getChildCount(); |
| 1962 | for (int i = 0; i < count; i++) { |
| 1963 | ((ImageView) group.getChildAt(i)).setImageDrawable(null); |
| 1964 | } |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1965 | ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon); |
| 1966 | for (Bitmap bitmap : bitmaps) bitmap.recycle(); |
| 1967 | |
| 1968 | v.setTag(R.id.workspace, null); |
| 1969 | v.setTag(R.id.icon, null); |
| 1970 | window.setOnDismissListener(null); |
| 1971 | } |
| 1972 | }); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1973 | window.dismiss(); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1974 | } |
| 1975 | v.setTag(null); |
| 1976 | } |
| 1977 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1978 | private void showPreviews(View anchor) { |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1979 | showPreviews(anchor, 0, mWorkspace.getChildCount()); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1980 | } |
| 1981 | |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1982 | private void showPreviews(final View anchor, int start, int end) { |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1983 | final Resources resources = getResources(); |
| 1984 | final Workspace workspace = mWorkspace; |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 1985 | |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1986 | CellLayout cell = ((CellLayout) workspace.getChildAt(start)); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1987 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1988 | float max = workspace.getChildCount(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1989 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 1990 | final Rect r = new Rect(); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 1991 | resources.getDrawable(R.drawable.preview_background).getPadding(r); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 1992 | int extraW = (int) ((r.left + r.right) * max); |
| 1993 | int extraH = r.top + r.bottom; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 1994 | |
| 1995 | int aW = cell.getWidth() - extraW; |
| 1996 | float w = aW / max; |
| 1997 | |
| 1998 | int width = cell.getWidth(); |
| 1999 | int height = cell.getHeight(); |
| 2000 | int x = cell.getLeftPadding(); |
| 2001 | int y = cell.getTopPadding(); |
| 2002 | width -= (x + cell.getRightPadding()); |
| 2003 | height -= (y + cell.getBottomPadding()); |
| 2004 | |
| 2005 | float scale = w / width; |
| 2006 | |
| 2007 | int count = end - start; |
| 2008 | |
| 2009 | final float sWidth = width * scale; |
| 2010 | float sHeight = height * scale; |
| 2011 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2012 | LinearLayout preview = new LinearLayout(this); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2013 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2014 | PreviewTouchHandler handler = new PreviewTouchHandler(anchor); |
| 2015 | ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2016 | |
| 2017 | for (int i = start; i < end; i++) { |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2018 | ImageView image = new ImageView(this); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2019 | cell = (CellLayout) workspace.getChildAt(i); |
| 2020 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2021 | final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2022 | Bitmap.Config.ARGB_8888); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2023 | |
| 2024 | final Canvas c = new Canvas(bitmap); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2025 | c.scale(scale, scale); |
| 2026 | c.translate(-cell.getLeftPadding(), -cell.getTopPadding()); |
| 2027 | cell.dispatchDraw(c); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2028 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2029 | image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background)); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2030 | image.setImageBitmap(bitmap); |
| 2031 | image.setTag(i); |
| 2032 | image.setOnClickListener(handler); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2033 | image.setOnFocusChangeListener(handler); |
| 2034 | image.setFocusable(true); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2035 | if (i == mWorkspace.getCurrentPage()) image.requestFocus(); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2036 | |
| 2037 | preview.addView(image, |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2038 | LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 2039 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2040 | bitmaps.add(bitmap); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2041 | } |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2042 | |
| 2043 | final PopupWindow p = new PopupWindow(this); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2044 | p.setContentView(preview); |
| 2045 | p.setWidth((int) (sWidth * count + extraW)); |
| 2046 | p.setHeight((int) (sHeight + extraH)); |
| 2047 | p.setAnimationStyle(R.style.AnimationPreview); |
| 2048 | p.setOutsideTouchable(true); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2049 | p.setFocusable(true); |
Romain Guy | ff0c2e2 | 2009-11-10 12:09:59 -0800 | [diff] [blame] | 2050 | p.setBackgroundDrawable(new ColorDrawable(0)); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2051 | p.showAsDropDown(anchor, 0, 0); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2052 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2053 | p.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 2054 | public void onDismiss() { |
| 2055 | dismissPreview(anchor); |
| 2056 | } |
| 2057 | }); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2058 | |
| 2059 | anchor.setTag(p); |
| 2060 | anchor.setTag(R.id.workspace, preview); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2061 | anchor.setTag(R.id.icon, bitmaps); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2062 | } |
| 2063 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2064 | class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener { |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2065 | private final View mAnchor; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2066 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2067 | public PreviewTouchHandler(View anchor) { |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2068 | mAnchor = anchor; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | public void onClick(View v) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2072 | mWorkspace.snapToPage((Integer) v.getTag()); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2073 | v.post(this); |
| 2074 | } |
| 2075 | |
| 2076 | public void run() { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2077 | dismissPreview(mAnchor); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | public void onFocusChange(View v, boolean hasFocus) { |
| 2081 | if (hasFocus) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2082 | mWorkspace.snapToPage((Integer) v.getTag()); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2083 | } |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2087 | Workspace getWorkspace() { |
| 2088 | return mWorkspace; |
| 2089 | } |
| 2090 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2091 | @Override |
| 2092 | protected Dialog onCreateDialog(int id) { |
| 2093 | switch (id) { |
| 2094 | case DIALOG_CREATE_SHORTCUT: |
| 2095 | return new CreateShortcut().createDialog(); |
| 2096 | case DIALOG_RENAME_FOLDER: |
| 2097 | return new RenameFolder().createDialog(); |
| 2098 | } |
| 2099 | |
| 2100 | return super.onCreateDialog(id); |
| 2101 | } |
| 2102 | |
| 2103 | @Override |
| 2104 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 2105 | switch (id) { |
| 2106 | case DIALOG_CREATE_SHORTCUT: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2107 | break; |
| 2108 | case DIALOG_RENAME_FOLDER: |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2109 | if (mFolderInfo != null) { |
| 2110 | EditText input = (EditText) dialog.findViewById(R.id.folder_name); |
| 2111 | final CharSequence text = mFolderInfo.title; |
| 2112 | input.setText(text); |
| 2113 | input.setSelection(0, text.length()); |
| 2114 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2115 | break; |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | void showRenameDialog(FolderInfo info) { |
| 2120 | mFolderInfo = info; |
| 2121 | mWaitingForResult = true; |
| 2122 | showDialog(DIALOG_RENAME_FOLDER); |
| 2123 | } |
| 2124 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 2125 | private void showAddDialog(int intersectX, int intersectY) { |
| 2126 | resetAddInfo(); |
| 2127 | mAddIntersectCellX = intersectX; |
| 2128 | mAddIntersectCellY = intersectY; |
| 2129 | mAddScreen = mWorkspace.getCurrentPage(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2130 | mWaitingForResult = true; |
| 2131 | showDialog(DIALOG_CREATE_SHORTCUT); |
| 2132 | } |
| 2133 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2134 | private void pickShortcut() { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2135 | // Insert extra item to handle picking application |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2136 | Bundle bundle = new Bundle(); |
| 2137 | |
| 2138 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 2139 | shortcutNames.add(getString(R.string.group_applications)); |
| 2140 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
| 2141 | |
| 2142 | ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>(); |
| 2143 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 2144 | R.drawable.ic_launcher_application)); |
| 2145 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 2146 | |
| 2147 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 2148 | pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT)); |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2149 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut)); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2150 | pickIntent.putExtras(bundle); |
| 2151 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2152 | startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2155 | private class RenameFolder { |
| 2156 | private EditText mInput; |
| 2157 | |
| 2158 | Dialog createDialog() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2159 | final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null); |
| 2160 | mInput = (EditText) layout.findViewById(R.id.folder_name); |
| 2161 | |
| 2162 | AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 2163 | builder.setIcon(0); |
| 2164 | builder.setTitle(getString(R.string.rename_folder_title)); |
| 2165 | builder.setCancelable(true); |
| 2166 | builder.setOnCancelListener(new Dialog.OnCancelListener() { |
| 2167 | public void onCancel(DialogInterface dialog) { |
| 2168 | cleanup(); |
| 2169 | } |
| 2170 | }); |
| 2171 | builder.setNegativeButton(getString(R.string.cancel_action), |
| 2172 | new Dialog.OnClickListener() { |
| 2173 | public void onClick(DialogInterface dialog, int which) { |
| 2174 | cleanup(); |
| 2175 | } |
| 2176 | } |
| 2177 | ); |
| 2178 | builder.setPositiveButton(getString(R.string.rename_action), |
| 2179 | new Dialog.OnClickListener() { |
| 2180 | public void onClick(DialogInterface dialog, int which) { |
| 2181 | changeFolderName(); |
| 2182 | } |
| 2183 | } |
| 2184 | ); |
| 2185 | builder.setView(layout); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2186 | |
| 2187 | final AlertDialog dialog = builder.create(); |
| 2188 | dialog.setOnShowListener(new DialogInterface.OnShowListener() { |
| 2189 | public void onShow(DialogInterface dialog) { |
Joe Onorato | 7018d8e | 2010-04-13 20:25:47 -0700 | [diff] [blame] | 2190 | mWaitingForResult = true; |
Joe Onorato | d753b42 | 2009-11-08 13:31:11 -0500 | [diff] [blame] | 2191 | mInput.requestFocus(); |
| 2192 | InputMethodManager inputManager = (InputMethodManager) |
| 2193 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 2194 | inputManager.showSoftInput(mInput, 0); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2195 | } |
| 2196 | }); |
| 2197 | |
| 2198 | return dialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | private void changeFolderName() { |
| 2202 | final String name = mInput.getText().toString(); |
| 2203 | if (!TextUtils.isEmpty(name)) { |
| 2204 | // Make sure we have the right folder info |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2205 | mFolderInfo = sFolders.get(mFolderInfo.id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2206 | mFolderInfo.title = name; |
| 2207 | LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo); |
| 2208 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2209 | if (mWorkspaceLoading) { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2210 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2211 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2212 | } else { |
| 2213 | final FolderIcon folderIcon = (FolderIcon) |
| 2214 | mWorkspace.getViewForTag(mFolderInfo); |
| 2215 | if (folderIcon != null) { |
| 2216 | folderIcon.setText(name); |
| 2217 | getWorkspace().requestLayout(); |
| 2218 | } else { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2219 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2220 | mWorkspaceLoading = true; |
| 2221 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | cleanup(); |
| 2226 | } |
| 2227 | |
| 2228 | private void cleanup() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2229 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 2230 | mWaitingForResult = false; |
| 2231 | mFolderInfo = null; |
| 2232 | } |
| 2233 | } |
| 2234 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2235 | // Now a part of LauncherModel.Callbacks. Used to reorder loading steps. |
| 2236 | public boolean isAllAppsVisible() { |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 2237 | return mAllAppsGrid != null && mAllAppsGrid.isVisible(); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2238 | } |
| 2239 | |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2240 | // AllAppsView.Watcher |
| 2241 | public void zoomed(float zoom) { |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 2242 | // In XLarge view, we zoom down the workspace below all apps so it's still visible |
| 2243 | if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) { |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2244 | mWorkspace.setVisibility(View.GONE); |
| 2245 | } |
| 2246 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2247 | |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2248 | private void showToolbarButton(View button) { |
| 2249 | button.setAlpha(1.0f); |
| 2250 | button.setVisibility(View.VISIBLE); |
| 2251 | button.setFocusable(true); |
| 2252 | button.setClickable(true); |
| 2253 | } |
| 2254 | |
| 2255 | private void hideToolbarButton(View button) { |
| 2256 | button.setAlpha(0.0f); |
| 2257 | // We can't set it to GONE, otherwise the RelativeLayout gets screwed up |
| 2258 | button.setVisibility(View.INVISIBLE); |
| 2259 | button.setFocusable(false); |
| 2260 | button.setClickable(false); |
| 2261 | } |
| 2262 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2263 | /** |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2264 | * Helper function for showing or hiding a toolbar button, possibly animated. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2265 | * |
| 2266 | * @param show If true, create an animation to the show the item. Otherwise, hide it. |
| 2267 | * @param view The toolbar button to be animated |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2268 | * @param seq A AnimatorSet that will be used to animate the transition. If null, the |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2269 | * transition will not be animated. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2270 | */ |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2271 | private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2272 | final boolean showing = show; |
| 2273 | final boolean hiding = !show; |
| 2274 | |
| 2275 | final int duration = show ? |
| 2276 | getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) : |
| 2277 | getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime); |
| 2278 | |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2279 | if (seq != null) { |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2280 | Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f); |
| 2281 | anim.addListener(new AnimatorListenerAdapter() { |
| 2282 | public void onAnimationStart(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2283 | if (showing) showToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2284 | } |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2285 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2286 | if (hiding) hideToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2287 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2288 | }); |
| 2289 | seq.play(anim); |
| 2290 | } else { |
| 2291 | if (showing) { |
| 2292 | showToolbarButton(view); |
| 2293 | } else { |
| 2294 | hideToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2295 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2296 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | /** |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2300 | * Show/hide the appropriate toolbar buttons for newState. |
| 2301 | * If showSeq or hideSeq is null, the transition will be done immediately (not animated). |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2302 | * |
| 2303 | * @param newState The state that is being switched to |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2304 | * @param showSeq AnimatorSet in which to put "show" animations, or null. |
| 2305 | * @param hideSeq AnimatorSet in which to put "hide" animations, or null. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2306 | */ |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2307 | private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2308 | final View searchButton = findViewById(R.id.search_button); |
| 2309 | final View allAppsButton = findViewById(R.id.all_apps_button); |
| 2310 | final View marketButton = findViewById(R.id.market_button); |
| 2311 | final View configureButton = findViewById(R.id.configure_button); |
| 2312 | |
| 2313 | switch (newState) { |
| 2314 | case WORKSPACE: |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2315 | hideOrShowToolbarButton(true, searchButton, showSeq); |
| 2316 | hideOrShowToolbarButton(true, allAppsButton, showSeq); |
| 2317 | hideOrShowToolbarButton(true, configureButton, showSeq); |
| 2318 | hideOrShowToolbarButton(false, marketButton, hideSeq); |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2319 | mDeleteZone.setHandle(allAppsButton); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2320 | break; |
| 2321 | case ALL_APPS: |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2322 | hideOrShowToolbarButton(true, configureButton, showSeq); |
| 2323 | hideOrShowToolbarButton(true, marketButton, showSeq); |
| 2324 | hideOrShowToolbarButton(false, searchButton, hideSeq); |
| 2325 | hideOrShowToolbarButton(false, allAppsButton, hideSeq); |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2326 | mDeleteZone.setHandle(marketButton); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2327 | break; |
| 2328 | case CUSTOMIZE: |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2329 | hideOrShowToolbarButton(true, allAppsButton, showSeq); |
| 2330 | hideOrShowToolbarButton(false, searchButton, hideSeq); |
| 2331 | hideOrShowToolbarButton(false, marketButton, hideSeq); |
| 2332 | hideOrShowToolbarButton(false, configureButton, hideSeq); |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2333 | mDeleteZone.setHandle(allAppsButton); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2334 | break; |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | /** |
| 2339 | * Helper method for the cameraZoomIn/cameraZoomOut animations |
| 2340 | * @param view The view being animated |
| 2341 | * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE |
| 2342 | * @param scaleFactor The scale factor used for the zoom |
| 2343 | */ |
| 2344 | private void setPivotsForZoom(View view, State state, float scaleFactor) { |
| 2345 | final int height = view.getHeight(); |
| 2346 | view.setPivotX(view.getWidth() / 2.0f); |
| 2347 | // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin |
| 2348 | // Assumes that the view is normally anchored to either the top or bottom of the screen |
| 2349 | final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset); |
| 2350 | if (state == State.ALL_APPS) { |
| 2351 | view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin); |
| 2352 | } else { |
| 2353 | view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin); |
| 2354 | } |
| 2355 | } |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2356 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2357 | /** |
| 2358 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 2359 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 2360 | * of the screen. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2361 | * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2362 | */ |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2363 | private void cameraZoomOut(State toState, boolean animated) { |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2364 | final Resources res = getResources(); |
| 2365 | final int duration = res.getInteger(R.integer.config_allAppsZoomInTime); |
| 2366 | final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2367 | final boolean toAllApps = (toState == State.ALL_APPS); |
| 2368 | final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2369 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2370 | setPivotsForZoom(toView, toState, scale); |
| 2371 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2372 | if (toState == State.ALL_APPS) { |
| 2373 | mWorkspace.shrinkToBottom(animated); |
| 2374 | } else { |
| 2375 | mWorkspace.shrinkToTop(animated); |
| 2376 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2377 | |
| 2378 | if (animated) { |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2379 | ValueAnimator scaleAnim = new ObjectAnimator(duration, toView, |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2380 | new PropertyValuesHolder<Float>("scaleX", scale, 1.0f), |
| 2381 | new PropertyValuesHolder<Float>("scaleY", scale, 1.0f)); |
| 2382 | scaleAnim.setInterpolator(new DecelerateInterpolator()); |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2383 | scaleAnim.addListener(new AnimatorListenerAdapter() { |
| 2384 | public void onAnimationStart(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2385 | // Prepare the position |
| 2386 | toView.setTranslationX(0.0f); |
| 2387 | toView.setTranslationY(0.0f); |
| 2388 | toView.setVisibility(View.VISIBLE); |
| 2389 | } |
| 2390 | }); |
| 2391 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2392 | AnimatorSet toolbarHideAnim = new AnimatorSet(); |
| 2393 | AnimatorSet toolbarShowAnim = new AnimatorSet(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2394 | hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim); |
| 2395 | |
| 2396 | // toView should appear right at the end of the workspace shrink animation |
| 2397 | final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration; |
| 2398 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2399 | AnimatorSet s = new AnimatorSet(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2400 | s.playTogether(scaleAnim, toolbarHideAnim); |
| 2401 | s.play(scaleAnim).after(startDelay); |
| 2402 | |
| 2403 | // Show the new toolbar buttons just as the main animation is ending |
| 2404 | final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); |
| 2405 | s.play(toolbarShowAnim).after(duration + startDelay - fadeInTime); |
| 2406 | s.start(); |
| 2407 | } else { |
| 2408 | toView.setTranslationX(0.0f); |
| 2409 | toView.setTranslationY(0.0f); |
| 2410 | toView.setScaleX(1.0f); |
| 2411 | toView.setScaleY(1.0f); |
| 2412 | toView.setVisibility(View.VISIBLE); |
| 2413 | hideAndShowToolbarButtons(toState, null, null); |
| 2414 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | /** |
| 2418 | * Zoom the camera back into the workspace, hiding 'fromView'. |
| 2419 | * This is the opposite of cameraZoomOut. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2420 | * @param fromState The current state (must be ALL_APPS or CUSTOMIZE). |
| 2421 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2422 | */ |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2423 | private void cameraZoomIn(State fromState, boolean animated) { |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2424 | Resources res = getResources(); |
| 2425 | int duration = res.getInteger(R.integer.config_allAppsZoomOutTime); |
| 2426 | float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2427 | final View fromView = |
| 2428 | (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer; |
| 2429 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2430 | mCustomizePagedView.endChoiceMode(); |
| 2431 | mAllAppsPagedView.endChoiceMode(); |
| 2432 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2433 | setPivotsForZoom(fromView, fromState, scaleFactor); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2434 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2435 | mWorkspace.unshrink(animated); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2436 | |
| 2437 | if (animated) { |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2438 | AnimatorSet s = new AnimatorSet(); |
| 2439 | ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView, |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2440 | new PropertyValuesHolder<Float>("scaleX", scaleFactor), |
| 2441 | new PropertyValuesHolder<Float>("scaleY", scaleFactor)); |
| 2442 | scaleAnim.setInterpolator(new AccelerateInterpolator()); |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2443 | s.addListener(new AnimatorListenerAdapter() { |
| 2444 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2445 | fromView.setVisibility(View.GONE); |
| 2446 | fromView.setScaleX(1.0f); |
| 2447 | fromView.setScaleY(1.0f); |
| 2448 | } |
| 2449 | }); |
| 2450 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2451 | AnimatorSet toolbarHideAnim = new AnimatorSet(); |
| 2452 | AnimatorSet toolbarShowAnim = new AnimatorSet(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2453 | hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim); |
| 2454 | |
| 2455 | s.playTogether(scaleAnim, toolbarHideAnim); |
| 2456 | |
| 2457 | // Show the new toolbar buttons at the very end of the whole animation |
| 2458 | final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); |
| 2459 | final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime); |
| 2460 | s.play(toolbarShowAnim).after(unshrinkTime - fadeInTime); |
| 2461 | s.start(); |
| 2462 | } else { |
| 2463 | fromView.setVisibility(View.GONE); |
| 2464 | hideAndShowToolbarButtons(State.WORKSPACE, null, null); |
| 2465 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | /** |
| 2469 | * Pan the camera in the vertical plane between 'fromView' and 'toView'. |
| 2470 | * This is the transition used on xlarge screens to go between all apps and |
| 2471 | * the home customization drawer. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2472 | * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE. |
| 2473 | * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE. |
| 2474 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2475 | */ |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2476 | private void cameraPan(State fromState, State toState, boolean animated) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2477 | final Resources res = getResources(); |
| 2478 | final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2479 | final int workspaceHeight = mWorkspace.getHeight(); |
| 2480 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2481 | final boolean fromAllApps = (fromState == State.ALL_APPS); |
| 2482 | final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer; |
| 2483 | final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid; |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2484 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2485 | final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY(); |
| 2486 | final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2; |
| 2487 | final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2; |
| 2488 | final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f; |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2489 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2490 | mCustomizePagedView.endChoiceMode(); |
| 2491 | mAllAppsPagedView.endChoiceMode(); |
| 2492 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2493 | if (toState == State.ALL_APPS) { |
| 2494 | mWorkspace.shrinkToBottom(animated); |
| 2495 | } else { |
| 2496 | mWorkspace.shrinkToTop(animated); |
| 2497 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2498 | |
| 2499 | if (animated) { |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2500 | AnimatorSet s = new AnimatorSet(); |
| 2501 | s.addListener(new AnimatorListenerAdapter() { |
| 2502 | public void onAnimationStart(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2503 | toView.setVisibility(View.VISIBLE); |
| 2504 | toView.setY(toViewStartY); |
| 2505 | } |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2506 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2507 | fromView.setVisibility(View.GONE); |
| 2508 | } |
| 2509 | }); |
| 2510 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2511 | AnimatorSet toolbarHideAnim = new AnimatorSet(); |
| 2512 | AnimatorSet toolbarShowAnim = new AnimatorSet(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2513 | hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim); |
| 2514 | |
| 2515 | s.playTogether( |
| 2516 | toolbarHideAnim, |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2517 | new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY), |
| 2518 | new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY)); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2519 | |
| 2520 | // Show the new toolbar buttons just as the main animation is ending |
| 2521 | final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); |
| 2522 | s.play(toolbarShowAnim).after(duration - fadeInTime); |
| 2523 | s.start(); |
| 2524 | } else { |
| 2525 | fromView.setY(fromViewEndY); |
| 2526 | fromView.setVisibility(View.GONE); |
| 2527 | toView.setY(toViewEndY); |
| 2528 | toView.setVisibility(View.VISIBLE); |
| 2529 | hideAndShowToolbarButtons(toState, null, null); |
| 2530 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | void showAllApps(boolean animated) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 2534 | if (mAllAppsGrid.isVisible()) |
| 2535 | return; |
| 2536 | |
Michael Jurka | 79212d8 | 2010-07-30 16:36:20 -0700 | [diff] [blame] | 2537 | if (LauncherApplication.isScreenXLarge()) { |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2538 | if (isCustomizationDrawerVisible()) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2539 | cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2540 | } else { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2541 | cameraZoomOut(State.ALL_APPS, animated); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2542 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2543 | } else { |
| 2544 | mAllAppsGrid.zoom(1.0f, animated); |
| 2545 | } |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 2546 | |
Romain Guy | c16fea7 | 2010-03-12 17:17:56 -0800 | [diff] [blame] | 2547 | ((View) mAllAppsGrid).setFocusable(true); |
| 2548 | ((View) mAllAppsGrid).requestFocus(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2549 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2550 | // TODO: fade these two too |
| 2551 | mDeleteZone.setVisibility(View.GONE); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2552 | } |
| 2553 | |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2554 | /** |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2555 | * Things to test when changing this code. |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2556 | * - Home from workspace |
| 2557 | * - from center screen |
| 2558 | * - from other screens |
| 2559 | * - Home from all apps |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2560 | * - from center screen |
| 2561 | * - from other screens |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2562 | * - Back from all apps |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2563 | * - from center screen |
| 2564 | * - from other screens |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2565 | * - Launch app from workspace and quit |
| 2566 | * - with back |
| 2567 | * - with home |
| 2568 | * - Launch app from all apps and quit |
| 2569 | * - with back |
| 2570 | * - with home |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2571 | * - Go to a screen that's not the default, then all |
| 2572 | * apps, and launch and app, and go back |
| 2573 | * - with back |
| 2574 | * -with home |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2575 | * - On workspace, long press power and go back |
| 2576 | * - with back |
| 2577 | * - with home |
| 2578 | * - On all apps, long press power and go back |
| 2579 | * - with back |
| 2580 | * - with home |
| 2581 | * - On workspace, power off |
| 2582 | * - On all apps, power off |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2583 | * - Launch an app and turn off the screen while in that app |
| 2584 | * - Go back with home key |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2585 | * - Go back with back key TODO: make this not go to workspace |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2586 | * - From all apps |
| 2587 | * - From workspace |
Joe Onorato | effc4a8 | 2010-04-15 11:48:13 -0700 | [diff] [blame] | 2588 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 2589 | * - From all apps |
| 2590 | * - From the center workspace |
| 2591 | * - From another workspace |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2592 | */ |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 2593 | void closeAllApps(boolean animated) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2594 | if (mAllAppsGrid.isVisible()) { |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2595 | mWorkspace.setVisibility(View.VISIBLE); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2596 | if (LauncherApplication.isScreenXLarge()) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2597 | cameraZoomIn(State.ALL_APPS, animated); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2598 | } else { |
| 2599 | mAllAppsGrid.zoom(0.0f, animated); |
| 2600 | } |
Daniel Sandler | 388f679 | 2010-03-02 14:08:08 -0500 | [diff] [blame] | 2601 | ((View)mAllAppsGrid).setFocusable(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2602 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | e77c08d | 2009-08-01 00:01:20 -0700 | [diff] [blame] | 2603 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2606 | void lockAllApps() { |
| 2607 | // TODO |
| 2608 | } |
| 2609 | |
| 2610 | void unlockAllApps() { |
| 2611 | // TODO |
| 2612 | } |
| 2613 | |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2614 | private boolean isCustomizationDrawerVisible() { |
Michael Jurka | 54f7ac3 | 2010-08-02 13:56:46 -0700 | [diff] [blame] | 2615 | return mHomeCustomizationDrawer != null && |
| 2616 | mHomeCustomizationDrawer.getVisibility() == View.VISIBLE; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2619 | // Show the customization drawer (only exists in x-large configuration) |
| 2620 | private void showCustomizationDrawer(boolean animated) { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2621 | if (isAllAppsVisible()) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2622 | cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2623 | } else { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2624 | cameraZoomOut(State.CUSTOMIZE, animated); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2625 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2628 | // Hide the customization drawer (only exists in x-large configuration) |
| 2629 | void hideCustomizationDrawer(boolean animated) { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2630 | if (isCustomizationDrawerVisible()) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2631 | cameraZoomIn(State.CUSTOMIZE, animated); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2635 | void onWorkspaceClick(CellLayout layout) { |
| 2636 | Object itemInfo = mAllAppsPagedView.getChosenItem(); |
| 2637 | if (itemInfo == null) { |
| 2638 | itemInfo = mCustomizePagedView.getChosenItem(); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 2639 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2640 | |
| 2641 | if (itemInfo == null) { |
| 2642 | // No items are chosen in All Apps or Customize, so just zoom into the workspace |
| 2643 | mWorkspace.unshrink(layout); |
| 2644 | if (isAllAppsVisible()) { |
| 2645 | closeAllApps(true); |
| 2646 | } else if (isCustomizationDrawerVisible()) { |
| 2647 | hideCustomizationDrawer(true); |
| 2648 | } |
| 2649 | } else { |
| 2650 | // Act as if the chosen item was dropped on the given CellLayout |
| 2651 | if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
| 2652 | mAllAppsPagedView.endChoiceMode(); |
| 2653 | mCustomizePagedView.endChoiceMode(); |
| 2654 | } else { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame^] | 2655 | showOutOfSpaceMessage(); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2656 | } |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 2657 | } |
| 2658 | } |
| 2659 | |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 2660 | /** |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2661 | * Sets the app market icon (shown when all apps is visible on x-large screens) |
| 2662 | */ |
| 2663 | private void updateAppMarketIcon() { |
| 2664 | if (LauncherApplication.isScreenXLarge()) { |
| 2665 | // Find the app market activity by resolving an intent. |
| 2666 | // (If multiple app markets are installed, it will return the ResolverActivity.) |
| 2667 | PackageManager packageManager = getPackageManager(); |
| 2668 | Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); |
| 2669 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
| 2670 | if (activityName != null) { |
| 2671 | mAppMarketIntent = intent; |
| 2672 | ImageView marketButton = (ImageView) findViewById(R.id.market_button); |
| 2673 | Drawable toolbarIcon = null; |
| 2674 | try { |
| 2675 | // Look for the toolbar icon specified in the activity meta-data |
| 2676 | Bundle metaData = packageManager.getActivityInfo( |
| 2677 | activityName, PackageManager.GET_META_DATA).metaData; |
| 2678 | if (metaData != null) { |
| 2679 | int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME); |
| 2680 | if (iconResId != 0) { |
| 2681 | Resources res = packageManager.getResourcesForActivity(activityName); |
| 2682 | toolbarIcon = res.getDrawable(iconResId); |
| 2683 | } |
| 2684 | } |
| 2685 | } catch (NameNotFoundException e) { |
| 2686 | // Do nothing |
| 2687 | } |
| 2688 | // If we were unable to find the icon via the meta-data, use a generic one |
| 2689 | if (toolbarIcon == null) { |
| 2690 | marketButton.setImageResource(R.drawable.app_market_generic); |
| 2691 | } else { |
| 2692 | marketButton.setImageDrawable(toolbarIcon); |
| 2693 | } |
| 2694 | } else { |
| 2695 | mAppMarketIntent = null; |
| 2696 | } |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2701 | * Displays the shortcut creation dialog and launches, if necessary, the |
| 2702 | * appropriate activity. |
| 2703 | */ |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2704 | private class CreateShortcut implements DialogInterface.OnClickListener, |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2705 | DialogInterface.OnCancelListener, DialogInterface.OnDismissListener, |
| 2706 | DialogInterface.OnShowListener { |
| 2707 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2708 | private AddAdapter mAdapter; |
Romain Guy | 9ffb543 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 2709 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2710 | Dialog createDialog() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2711 | mAdapter = new AddAdapter(Launcher.this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2712 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2713 | final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 2714 | builder.setTitle(getString(R.string.menu_item_add_item)); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2715 | builder.setAdapter(mAdapter, this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2716 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2717 | builder.setInverseBackgroundForced(true); |
| 2718 | |
| 2719 | AlertDialog dialog = builder.create(); |
| 2720 | dialog.setOnCancelListener(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2721 | dialog.setOnDismissListener(this); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2722 | dialog.setOnShowListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2723 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2724 | return dialog; |
| 2725 | } |
| 2726 | |
| 2727 | public void onCancel(DialogInterface dialog) { |
| 2728 | mWaitingForResult = false; |
| 2729 | cleanup(); |
| 2730 | } |
| 2731 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2732 | public void onDismiss(DialogInterface dialog) { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2735 | private void cleanup() { |
Joe Onorato | cc19a53 | 2009-11-19 14:19:17 -0800 | [diff] [blame] | 2736 | try { |
| 2737 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 2738 | } catch (Exception e) { |
| 2739 | // An exception is thrown if the dialog is not visible, which is fine |
| 2740 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2741 | } |
| 2742 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2743 | /** |
| 2744 | * Handle the action clicked in the "Add to home" dialog. |
| 2745 | */ |
| 2746 | public void onClick(DialogInterface dialog, int which) { |
| 2747 | Resources res = getResources(); |
| 2748 | cleanup(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2749 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2750 | switch (which) { |
| 2751 | case AddAdapter.ITEM_SHORTCUT: { |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2752 | pickShortcut(); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2753 | break; |
| 2754 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2755 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2756 | case AddAdapter.ITEM_APPWIDGET: { |
| 2757 | int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2758 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2759 | Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); |
| 2760 | pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2761 | // start the pick activity |
| 2762 | startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); |
| 2763 | break; |
| 2764 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2765 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2766 | case AddAdapter.ITEM_LIVE_FOLDER: { |
| 2767 | // Insert extra item to handle inserting folder |
| 2768 | Bundle bundle = new Bundle(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2769 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2770 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 2771 | shortcutNames.add(res.getString(R.string.group_folder)); |
| 2772 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2773 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2774 | ArrayList<ShortcutIconResource> shortcutIcons = |
| 2775 | new ArrayList<ShortcutIconResource>(); |
| 2776 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 2777 | R.drawable.ic_launcher_folder)); |
| 2778 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 2779 | |
| 2780 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 2781 | pickIntent.putExtra(Intent.EXTRA_INTENT, |
| 2782 | new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER)); |
| 2783 | pickIntent.putExtra(Intent.EXTRA_TITLE, |
| 2784 | getText(R.string.title_select_live_folder)); |
| 2785 | pickIntent.putExtras(bundle); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 2786 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 2787 | startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER); |
| 2788 | break; |
| 2789 | } |
| 2790 | |
| 2791 | case AddAdapter.ITEM_WALLPAPER: { |
| 2792 | startWallpaper(); |
| 2793 | break; |
| 2794 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2795 | } |
| 2796 | } |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2797 | |
| 2798 | public void onShow(DialogInterface dialog) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2799 | mWaitingForResult = true; |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2800 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | /** |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2804 | * Receives notifications when applications are added/removed. |
| 2805 | */ |
| 2806 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 2807 | @Override |
| 2808 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2809 | closeSystemDialogs(); |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2810 | String reason = intent.getStringExtra("reason"); |
| 2811 | if (!"homekey".equals(reason)) { |
| 2812 | boolean animate = true; |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2813 | if (mPaused || "lock".equals(reason)) { |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2814 | animate = false; |
| 2815 | } |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2816 | closeAllApps(animate); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2817 | hideCustomizationDrawer(animate); |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2818 | } |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2819 | } |
| 2820 | } |
| 2821 | |
| 2822 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2823 | * Receives notifications whenever the appwidgets are reset. |
| 2824 | */ |
| 2825 | private class AppWidgetResetObserver extends ContentObserver { |
| 2826 | public AppWidgetResetObserver() { |
| 2827 | super(new Handler()); |
| 2828 | } |
| 2829 | |
| 2830 | @Override |
| 2831 | public void onChange(boolean selfChange) { |
| 2832 | onAppWidgetReset(); |
| 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2837 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2838 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2839 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 2840 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2841 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 2842 | } else { |
| 2843 | return SCREEN_COUNT / 2; |
| 2844 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2845 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2846 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2847 | void setAllAppsPagedView(PagedView view) { |
| 2848 | mAllAppsPagedView = view; |
| 2849 | } |
| 2850 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2851 | /** |
| 2852 | * Refreshes the shortcuts shown on the workspace. |
| 2853 | * |
| 2854 | * Implementation of the method from LauncherModel.Callbacks. |
| 2855 | */ |
| 2856 | public void startBinding() { |
| 2857 | final Workspace workspace = mWorkspace; |
| 2858 | int count = workspace.getChildCount(); |
| 2859 | for (int i = 0; i < count; i++) { |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 2860 | // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate(). |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2861 | ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); |
| 2862 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2863 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2864 | if (DEBUG_USER_INTERFACE) { |
| 2865 | android.widget.Button finishButton = new android.widget.Button(this); |
| 2866 | finishButton.setText("Finish"); |
| 2867 | workspace.addInScreen(finishButton, 1, 0, 0, 1, 1); |
| 2868 | |
| 2869 | finishButton.setOnClickListener(new android.widget.Button.OnClickListener() { |
| 2870 | public void onClick(View v) { |
| 2871 | finish(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2872 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2873 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2878 | * Bind the items start-end from the list. |
| 2879 | * |
| 2880 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2881 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2882 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { |
| 2883 | |
| 2884 | final Workspace workspace = mWorkspace; |
| 2885 | |
| 2886 | for (int i=start; i<end; i++) { |
| 2887 | final ItemInfo item = shortcuts.get(i); |
| 2888 | mDesktopItems.add(item); |
| 2889 | switch (item.itemType) { |
| 2890 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 2891 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 2892 | final View shortcut = createShortcut((ShortcutInfo)item); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2893 | workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, |
| 2894 | false); |
| 2895 | break; |
| 2896 | case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: |
| 2897 | final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2898 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2899 | (UserFolderInfo) item); |
| 2900 | workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 2901 | false); |
| 2902 | break; |
| 2903 | case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: |
| 2904 | final FolderIcon newLiveFolder = LiveFolderIcon.fromXml( |
| 2905 | R.layout.live_folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2906 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2907 | (LiveFolderInfo) item); |
| 2908 | workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 2909 | false); |
| 2910 | break; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2911 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2912 | } |
| 2913 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2914 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2915 | } |
| 2916 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2917 | /** |
| 2918 | * Implementation of the method from LauncherModel.Callbacks. |
| 2919 | */ |
Joe Onorato | ad72e17 | 2009-11-06 16:25:04 -0500 | [diff] [blame] | 2920 | public void bindFolders(HashMap<Long, FolderInfo> folders) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2921 | sFolders.clear(); |
| 2922 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2923 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2924 | |
| 2925 | /** |
| 2926 | * Add the views for a widget to the workspace. |
| 2927 | * |
| 2928 | * Implementation of the method from LauncherModel.Callbacks. |
| 2929 | */ |
| 2930 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2931 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 2932 | if (DEBUG_WIDGETS) { |
| 2933 | Log.d(TAG, "bindAppWidget: " + item); |
| 2934 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2935 | final Workspace workspace = mWorkspace; |
| 2936 | |
| 2937 | final int appWidgetId = item.appWidgetId; |
| 2938 | final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2939 | if (DEBUG_WIDGETS) { |
| 2940 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 2941 | } |
| 2942 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2943 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 2944 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2945 | item.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 2946 | item.hostView.setTag(item); |
| 2947 | |
| 2948 | workspace.addInScreen(item.hostView, item.screen, item.cellX, |
| 2949 | item.cellY, item.spanX, item.spanY, false); |
| 2950 | |
| 2951 | workspace.requestLayout(); |
| 2952 | |
| 2953 | mDesktopItems.add(item); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2954 | |
| 2955 | if (DEBUG_WIDGETS) { |
| 2956 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 2957 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 2958 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | /** |
| 2962 | * Callback saying that there aren't any more items to bind. |
| 2963 | * |
| 2964 | * Implementation of the method from LauncherModel.Callbacks. |
| 2965 | */ |
| 2966 | public void finishBindingItems() { |
| 2967 | if (mSavedState != null) { |
| 2968 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2969 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS); |
| 2973 | if (userFolders != null) { |
| 2974 | for (long folderId : userFolders) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2975 | final FolderInfo info = sFolders.get(folderId); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2976 | if (info != null) { |
| 2977 | openFolder(info); |
| 2978 | } |
| 2979 | } |
| 2980 | final Folder openFolder = mWorkspace.getOpenFolder(); |
| 2981 | if (openFolder != null) { |
| 2982 | openFolder.requestFocus(); |
| 2983 | } |
| 2984 | } |
| 2985 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2986 | mSavedState = null; |
| 2987 | } |
| 2988 | |
| 2989 | if (mSavedInstanceState != null) { |
| 2990 | super.onRestoreInstanceState(mSavedInstanceState); |
| 2991 | mSavedInstanceState = null; |
| 2992 | } |
| 2993 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2994 | mWorkspaceLoading = false; |
| 2995 | } |
| 2996 | |
| 2997 | /** |
| 2998 | * Add the icons for all apps. |
| 2999 | * |
| 3000 | * Implementation of the method from LauncherModel.Callbacks. |
| 3001 | */ |
| 3002 | public void bindAllApplications(ArrayList<ApplicationInfo> apps) { |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 3003 | mAllAppsGrid.setApps(apps); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 3004 | mCustomizePagedView.setApps(apps); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3005 | updateAppMarketIcon(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | /** |
| 3009 | * A package was installed. |
| 3010 | * |
| 3011 | * Implementation of the method from LauncherModel.Callbacks. |
| 3012 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3013 | public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3014 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 3015 | mAllAppsGrid.addApps(apps); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 3016 | mCustomizePagedView.addApps(apps); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3017 | updateAppMarketIcon(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | /** |
| 3021 | * A package was updated. |
| 3022 | * |
| 3023 | * Implementation of the method from LauncherModel.Callbacks. |
| 3024 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3025 | public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3026 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3027 | mWorkspace.updateShortcuts(apps); |
| 3028 | mAllAppsGrid.updateApps(apps); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 3029 | mCustomizePagedView.updateApps(apps); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3030 | updateAppMarketIcon(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | /** |
| 3034 | * A package was uninstalled. |
| 3035 | * |
| 3036 | * Implementation of the method from LauncherModel.Callbacks. |
| 3037 | */ |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3038 | public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3039 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3040 | if (permanent) { |
| 3041 | mWorkspace.removeItems(apps); |
| 3042 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 3043 | mAllAppsGrid.removeApps(apps); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 3044 | mCustomizePagedView.removeApps(apps); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3045 | updateAppMarketIcon(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3046 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3047 | |
| 3048 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3049 | * A number of packages were updated. |
| 3050 | */ |
| 3051 | public void bindPackagesUpdated() { |
| 3052 | // update the customization drawer contents |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 3053 | if (mCustomizePagedView != null) |
| 3054 | mCustomizePagedView.update(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3058 | * Prints out out state for debugging. |
| 3059 | */ |
| 3060 | public void dumpState() { |
| 3061 | Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 3062 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 3063 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 3064 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 3065 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 3066 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
| 3067 | Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size()); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 3068 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3069 | mModel.dumpState(); |
| 3070 | mAllAppsGrid.dumpState(); |
| 3071 | Log.d(TAG, "END launcher2 dump state"); |
| 3072 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3073 | } |