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