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