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