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