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