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