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