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