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