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