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