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