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