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