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