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