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