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