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 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 20 | import java.io.DataInputStream; |
| 21 | import java.io.DataOutputStream; |
| 22 | import java.io.FileNotFoundException; |
| 23 | import java.io.IOException; |
| 24 | import java.util.ArrayList; |
| 25 | import java.util.HashMap; |
| 26 | import java.util.List; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 27 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 28 | import android.animation.Animator; |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 29 | import android.animation.AnimatorListenerAdapter; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 30 | import android.animation.AnimatorSet; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 31 | import android.animation.ObjectAnimator; |
| 32 | import android.animation.PropertyValuesHolder; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 33 | import android.animation.ValueAnimator; |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 34 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 35 | import android.app.Activity; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | import android.app.Dialog; |
| 38 | import android.app.SearchManager; |
| 39 | import android.app.StatusBarManager; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 40 | import android.appwidget.AppWidgetManager; |
| 41 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 43 | import android.content.BroadcastReceiver; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 44 | import android.content.ClipData; |
| 45 | import android.content.ClipDescription; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 46 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 47 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | import android.content.Context; |
| 49 | import android.content.DialogInterface; |
| 50 | import android.content.Intent; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 51 | import android.content.IntentFilter; |
Adam Cohen | 860f4c5 | 2011-01-27 20:16:13 -0800 | [diff] [blame] | 52 | import android.content.Intent.ShortcutIconResource; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 53 | import android.content.pm.ActivityInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | import android.content.pm.PackageManager; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 55 | import android.content.pm.ResolveInfo; |
Adam Cohen | 860f4c5 | 2011-01-27 20:16:13 -0800 | [diff] [blame] | 56 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 58 | import android.content.res.Resources; |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 59 | import android.content.res.TypedArray; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 60 | import android.database.ContentObserver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 61 | import android.graphics.Bitmap; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 62 | import android.graphics.Canvas; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 63 | import android.graphics.Rect; |
Romain Guy | ff0c2e2 | 2009-11-10 12:09:59 -0800 | [diff] [blame] | 64 | import android.graphics.drawable.ColorDrawable; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 65 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 66 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 67 | import android.os.AsyncTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 68 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 69 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 70 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 71 | import android.os.Message; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 72 | import android.os.SystemClock; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 73 | import android.os.SystemProperties; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 74 | import android.provider.Settings; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 75 | import android.speech.RecognizerIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 76 | import android.text.Selection; |
| 77 | import android.text.SpannableStringBuilder; |
| 78 | import android.text.TextUtils; |
| 79 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 80 | import android.util.Log; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 81 | import android.view.Display; |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 82 | import android.view.HapticFeedbackConstants; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 83 | import android.view.KeyEvent; |
| 84 | import android.view.LayoutInflater; |
| 85 | import android.view.Menu; |
| 86 | import android.view.MenuItem; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 87 | import android.view.MotionEvent; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 88 | import android.view.Surface; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 89 | import android.view.View; |
| 90 | import android.view.ViewGroup; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 91 | import android.view.WindowManager; |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 92 | import android.view.View.OnClickListener; |
Adam Cohen | 860f4c5 | 2011-01-27 20:16:13 -0800 | [diff] [blame] | 93 | import android.view.View.OnLongClickListener; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 94 | import android.view.accessibility.AccessibilityEvent; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 95 | import android.view.animation.DecelerateInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 96 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 97 | import android.widget.Advanceable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 98 | import android.widget.EditText; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 99 | import android.widget.ImageView; |
| 100 | import android.widget.LinearLayout; |
| 101 | import android.widget.PopupWindow; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 102 | import android.widget.TabHost; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 103 | import android.widget.TextView; |
| 104 | import android.widget.Toast; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 105 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 106 | import com.android.common.Search; |
| 107 | import com.android.launcher.R; |
| 108 | import com.android.launcher2.Workspace.ShrinkState; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 109 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | /** |
| 111 | * Default launcher application. |
| 112 | */ |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 113 | public final class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 114 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
| 115 | AllAppsView.Watcher, View.OnTouchListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 116 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 117 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 118 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 119 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 120 | static final boolean DEBUG_WIDGETS = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 121 | static final boolean DEBUG_USER_INTERFACE = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 122 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 123 | private static final int MENU_GROUP_ADD = 1; |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 124 | private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1; |
| 125 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 126 | private static final int MENU_ADD = Menu.FIRST + 1; |
Winson Chung | 7ad0141 | 2010-09-27 11:33:03 -0700 | [diff] [blame] | 127 | private static final int MENU_MANAGE_APPS = MENU_ADD + 1; |
| 128 | private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 129 | private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1; |
| 130 | private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1; |
Romain Guy | 94dabf1 | 2009-07-21 10:55:43 -0700 | [diff] [blame] | 131 | private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 132 | |
| 133 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 134 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 135 | private static final int REQUEST_PICK_APPLICATION = 6; |
| 136 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 137 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 138 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 139 | |
| 140 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 141 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 142 | static final int SCREEN_COUNT = 5; |
| 143 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 144 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 145 | static final int DIALOG_CREATE_SHORTCUT = 1; |
| 146 | static final int DIALOG_RENAME_FOLDER = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 147 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 148 | private static final String PREFERENCES = "launcher.preferences"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 149 | |
| 150 | // Type: int |
| 151 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 152 | // Type: int |
| 153 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 154 | // Type: long |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 155 | private static final String RUNTIME_STATE_FOLDERS = "launcher.folder"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 156 | // Type: int |
| 157 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 158 | // Type: int |
| 159 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX"; |
| 160 | // Type: int |
| 161 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 162 | // Type: boolean |
| 163 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 164 | // Type: long |
| 165 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; |
| 166 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 167 | private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; |
| 168 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 169 | /** The different states that Launcher can be in. */ |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 170 | private enum State { WORKSPACE, APPS_CUSTOMIZE, ALL_APPS, CUSTOMIZE, |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 171 | CUSTOMIZE_SPRING_LOADED, ALL_APPS_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 172 | private State mState = State.WORKSPACE; |
| 173 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 174 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 175 | static final int APPWIDGET_HOST_ID = 1024; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 176 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 177 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 178 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 179 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 180 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 181 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 182 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 183 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 184 | private LayoutInflater mInflater; |
| 185 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 186 | private DragController mDragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 187 | private Workspace mWorkspace; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 188 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 189 | private AppWidgetManager mAppWidgetManager; |
| 190 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 191 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 192 | private int mAddScreen = -1; |
| 193 | private int mAddIntersectCellX = -1; |
| 194 | private int mAddIntersectCellY = -1; |
| 195 | private int[] mAddDropPosition; |
| 196 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 197 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 198 | private FolderInfo mFolderInfo; |
| 199 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 200 | private DeleteZone mDeleteZone; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 201 | private HandleView mHandleView; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 202 | private AllAppsView mAllAppsGrid; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 203 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 204 | private AppsCustomizePagedView mAppsCustomizeContent; |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 205 | private CustomizeTrayTabHost mHomeCustomizationDrawer; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 206 | private boolean mAutoAdvanceRunning = false; |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 207 | |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 208 | private ViewGroup mButtonCluster; |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 209 | private View mAllAppsButton; |
| 210 | private View mDivider; |
| 211 | private View mConfigureButton; |
| 212 | |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 213 | private AllAppsPagedView mAllAppsPagedView = null; |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 214 | private CustomizePagedView mCustomizePagedView = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 215 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 216 | private Bundle mSavedState; |
| 217 | |
| 218 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 219 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 220 | private boolean mWorkspaceLoading = true; |
| 221 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 222 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 223 | private boolean mRestoring; |
| 224 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 225 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 226 | |
| 227 | private Bundle mSavedInstanceState; |
| 228 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 229 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 230 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 231 | private boolean mUserPresent = true; |
| 232 | private boolean mVisible = false; |
| 233 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 234 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 235 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 236 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 237 | private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 238 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 239 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 240 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 241 | // The "signpost" images along the bottom of the screen (only in some layouts) |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 242 | private ImageView mPreviousView; |
| 243 | private ImageView mNextView; |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 244 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 245 | // Hotseats (quick-launch icons next to AllApps) |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 246 | private String[] mHotseatConfig = null; |
| 247 | private Intent[] mHotseats = null; |
| 248 | private Drawable[] mHotseatIcons = null; |
| 249 | private CharSequence[] mHotseatLabels = null; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 250 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 251 | private Intent mAppMarketIntent = null; |
| 252 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 253 | // Related to the auto-advancing of widgets |
| 254 | private final int ADVANCE_MSG = 1; |
| 255 | private final int mAdvanceInterval = 20000; |
| 256 | private final int mAdvanceStagger = 250; |
| 257 | private long mAutoAdvanceSentTime; |
| 258 | private long mAutoAdvanceTimeLeft = -1; |
| 259 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 260 | new HashMap<View, AppWidgetProviderInfo>(); |
| 261 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 262 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 263 | // match the sensor state. |
| 264 | private final int mRestoreScreenOrientationDelay = 500; |
| 265 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 266 | // External icons saved in case of resource changes, orientation, etc. |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 267 | private static Drawable.ConstantState sGlobalSearchIcon; |
| 268 | private static Drawable.ConstantState sVoiceSearchIcon; |
| 269 | private static Drawable.ConstantState sAppMarketIcon; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 270 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 271 | private DragLayer mDragLayer; |
| 272 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 273 | private BubbleTextView mWaitingForResume; |
| 274 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 275 | private static ArrayList<PendingAddArguments> sPendingAddList |
| 276 | = new ArrayList<PendingAddArguments>(); |
| 277 | |
| 278 | private static class PendingAddArguments { |
| 279 | int requestCode; |
| 280 | Intent intent; |
| 281 | int screen; |
| 282 | int cellX; |
| 283 | int cellY; |
| 284 | } |
| 285 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 286 | @Override |
| 287 | protected void onCreate(Bundle savedInstanceState) { |
| 288 | super.onCreate(savedInstanceState); |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 289 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 290 | if (LauncherApplication.isInPlaceRotationEnabled()) { |
| 291 | // hide the status bar (temporary until we get the status bar design figured out) |
| 292 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 293 | this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); |
| 294 | } |
| 295 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 296 | LauncherApplication app = ((LauncherApplication)getApplication()); |
| 297 | mModel = app.setLauncher(this); |
| 298 | mIconCache = app.getIconCache(); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 299 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 300 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 301 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 302 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 303 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 304 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 305 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 306 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 307 | android.os.Debug.startMethodTracing( |
| 308 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 311 | loadHotseats(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 312 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 313 | setContentView(R.layout.launcher); |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 314 | mHomeCustomizationDrawer = (CustomizeTrayTabHost) findViewById(R.id.customization_drawer); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 315 | if (mHomeCustomizationDrawer != null) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 316 | // share the same customization workspace across all the tabs |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 317 | mCustomizePagedView = (CustomizePagedView) findViewById( |
| 318 | R.id.customization_drawer_tab_contents); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 319 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 320 | setupViews(); |
| 321 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 322 | registerContentObservers(); |
| 323 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 324 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 326 | mSavedState = savedInstanceState; |
| 327 | restoreState(mSavedState); |
| 328 | |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 329 | // Update customization drawer _after_ restoring the states |
tedbo | 2b0857a | 2010-12-22 18:36:24 -0800 | [diff] [blame] | 330 | if (mCustomizePagedView != null) { |
| 331 | mCustomizePagedView.update(); |
| 332 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 333 | if (mAppsCustomizeContent != null) { |
| 334 | mAppsCustomizeContent.onPackagesUpdated(); |
| 335 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 336 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 337 | if (PROFILE_STARTUP) { |
| 338 | android.os.Debug.stopMethodTracing(); |
| 339 | } |
| 340 | |
| 341 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 342 | mModel.startLoader(this, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | // For handling default keys |
| 346 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 347 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 348 | |
| 349 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 350 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 351 | |
| 352 | // If we have a saved version of these external icons, we load them up immediately |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 353 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | c6d2000 | 2011-03-02 11:57:29 -0800 | [diff] [blame] | 354 | if (sGlobalSearchIcon == null || sVoiceSearchIcon == null || sAppMarketIcon == null) { |
| 355 | updateIconsAffectedByPackageManagerChanges(); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 356 | } |
Michael Jurka | 1c3f8ec | 2011-03-07 16:41:21 -0800 | [diff] [blame] | 357 | if (sGlobalSearchIcon != null) { |
| 358 | updateGlobalSearchIcon(sGlobalSearchIcon); |
| 359 | } |
| 360 | if (sVoiceSearchIcon != null) { |
| 361 | updateVoiceSearchIcon(sVoiceSearchIcon); |
| 362 | } |
| 363 | if (sAppMarketIcon != null) { |
| 364 | updateAppMarketIcon(sAppMarketIcon); |
| 365 | } |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 366 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 367 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 368 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 369 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 370 | if (sLocaleConfiguration == null) { |
| 371 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 372 | @Override |
| 373 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 374 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 375 | readConfiguration(Launcher.this, localeConfiguration); |
| 376 | return localeConfiguration; |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | protected void onPostExecute(LocaleConfiguration result) { |
| 381 | sLocaleConfiguration = result; |
| 382 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 383 | } |
| 384 | }.execute(); |
| 385 | return; |
| 386 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 387 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 388 | final Configuration configuration = getResources().getConfiguration(); |
| 389 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 390 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 391 | final String locale = configuration.locale.toString(); |
| 392 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 393 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 394 | final int mcc = configuration.mcc; |
| 395 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 396 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 397 | final int mnc = configuration.mnc; |
| 398 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 399 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 400 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 401 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 402 | sLocaleConfiguration.locale = locale; |
| 403 | sLocaleConfiguration.mcc = mcc; |
| 404 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 405 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 406 | mIconCache.flush(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 407 | loadHotseats(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 408 | |
| 409 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
| 410 | new Thread("WriteLocaleConfiguration") { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 411 | @Override |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 412 | public void run() { |
| 413 | writeConfiguration(Launcher.this, localeConfiguration); |
| 414 | } |
| 415 | }.start(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | private static class LocaleConfiguration { |
| 420 | public String locale; |
| 421 | public int mcc = -1; |
| 422 | public int mnc = -1; |
| 423 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 424 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 425 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 426 | DataInputStream in = null; |
| 427 | try { |
| 428 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 429 | configuration.locale = in.readUTF(); |
| 430 | configuration.mcc = in.readInt(); |
| 431 | configuration.mnc = in.readInt(); |
| 432 | } catch (FileNotFoundException e) { |
| 433 | // Ignore |
| 434 | } catch (IOException e) { |
| 435 | // Ignore |
| 436 | } finally { |
| 437 | if (in != null) { |
| 438 | try { |
| 439 | in.close(); |
| 440 | } catch (IOException e) { |
| 441 | // Ignore |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 448 | DataOutputStream out = null; |
| 449 | try { |
| 450 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 451 | out.writeUTF(configuration.locale); |
| 452 | out.writeInt(configuration.mcc); |
| 453 | out.writeInt(configuration.mnc); |
| 454 | out.flush(); |
| 455 | } catch (FileNotFoundException e) { |
| 456 | // Ignore |
| 457 | } catch (IOException e) { |
| 458 | //noinspection ResultOfMethodCallIgnored |
| 459 | context.getFileStreamPath(PREFERENCES).delete(); |
| 460 | } finally { |
| 461 | if (out != null) { |
| 462 | try { |
| 463 | out.close(); |
| 464 | } catch (IOException e) { |
| 465 | // Ignore |
| 466 | } |
| 467 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
| 471 | static int getScreen() { |
| 472 | synchronized (sLock) { |
| 473 | return sScreen; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | static void setScreen(int screen) { |
| 478 | synchronized (sLock) { |
| 479 | sScreen = screen; |
| 480 | } |
| 481 | } |
| 482 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 483 | // Note: This doesn't do all the client-id magic that BrowserProvider does |
| 484 | // in Browser. (http://b/2425179) |
| 485 | private Uri getDefaultBrowserUri() { |
| 486 | String url = getString(R.string.default_browser_url); |
| 487 | if (url.indexOf("{CID}") != -1) { |
| 488 | url = url.replace("{CID}", "android-google"); |
| 489 | } |
| 490 | return Uri.parse(url); |
| 491 | } |
| 492 | |
| 493 | // Load the Intent templates from arrays.xml to populate the hotseats. For |
| 494 | // each Intent, if it resolves to a single app, use that as the launch |
| 495 | // intent & use that app's label as the contentDescription. Otherwise, |
| 496 | // retain the ResolveActivity so the user can pick an app. |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 497 | private void loadHotseats() { |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 498 | if (mHotseatConfig == null) { |
| 499 | mHotseatConfig = getResources().getStringArray(R.array.hotseats); |
| 500 | if (mHotseatConfig.length > 0) { |
| 501 | mHotseats = new Intent[mHotseatConfig.length]; |
| 502 | mHotseatLabels = new CharSequence[mHotseatConfig.length]; |
| 503 | mHotseatIcons = new Drawable[mHotseatConfig.length]; |
| 504 | } else { |
| 505 | mHotseats = null; |
| 506 | mHotseatIcons = null; |
| 507 | mHotseatLabels = null; |
| 508 | } |
| 509 | |
| 510 | TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons); |
| 511 | for (int i=0; i<mHotseatConfig.length; i++) { |
| 512 | // load icon for this slot; currently unrelated to the actual activity |
| 513 | try { |
| 514 | mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i); |
| 515 | } catch (ArrayIndexOutOfBoundsException ex) { |
| 516 | Log.w(TAG, "Missing hotseat_icons array item #" + i); |
| 517 | mHotseatIcons[i] = null; |
| 518 | } |
| 519 | } |
| 520 | hotseatIconDrawables.recycle(); |
| 521 | } |
| 522 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 523 | PackageManager pm = getPackageManager(); |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 524 | for (int i=0; i<mHotseatConfig.length; i++) { |
| 525 | Intent intent = null; |
| 526 | if (mHotseatConfig[i].equals("*BROWSER*")) { |
| 527 | // magic value meaning "launch user's default web browser" |
| 528 | // replace it with a generic web request so we can see if there is indeed a default |
| 529 | String defaultUri = getString(R.string.default_browser_url); |
| 530 | intent = new Intent( |
| 531 | Intent.ACTION_VIEW, |
| 532 | ((defaultUri != null) |
| 533 | ? Uri.parse(defaultUri) |
| 534 | : getDefaultBrowserUri()) |
| 535 | ).addCategory(Intent.CATEGORY_BROWSABLE); |
| 536 | // note: if the user launches this without a default set, she |
| 537 | // will always be taken to the default URL above; this is |
| 538 | // unavoidable as we must specify a valid URL in order for the |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 539 | // chooser to appear, and once the user selects something, that |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 540 | // URL is unavoidably sent to the chosen app. |
| 541 | } else { |
| 542 | try { |
| 543 | intent = Intent.parseUri(mHotseatConfig[i], 0); |
| 544 | } catch (java.net.URISyntaxException ex) { |
| 545 | Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]); |
| 546 | // bogus; leave intent=null |
| 547 | } |
| 548 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 549 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 550 | if (intent == null) { |
| 551 | mHotseats[i] = null; |
| 552 | mHotseatLabels[i] = getText(R.string.activity_not_found); |
| 553 | continue; |
| 554 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 555 | |
| 556 | if (LOGD) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 557 | Log.d(TAG, "loadHotseats: hotseat " + i |
| 558 | + " initial intent=[" |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 559 | + intent.toUri(Intent.URI_INTENT_SCHEME) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 560 | + "]"); |
| 561 | } |
| 562 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 563 | ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 564 | List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 565 | if (LOGD) { |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 566 | Log.d(TAG, "Best match for intent: " + bestMatch); |
| 567 | Log.d(TAG, "All matches: "); |
| 568 | for (ResolveInfo ri : allMatches) { |
| 569 | Log.d(TAG, " --> " + ri); |
| 570 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 571 | } |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 572 | // did this resolve to a single app, or the resolver? |
| 573 | if (allMatches.size() == 0 || bestMatch == null) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 574 | // can't find any activity to handle this. let's leave the |
| 575 | // intent as-is and let Launcher show a toast when it fails |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 576 | // to launch. |
| 577 | mHotseats[i] = intent; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 578 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 579 | // set accessibility text to "Not installed" |
| 580 | mHotseatLabels[i] = getText(R.string.activity_not_found); |
| 581 | } else { |
| 582 | boolean found = false; |
| 583 | for (ResolveInfo ri : allMatches) { |
| 584 | if (bestMatch.activityInfo.name.equals(ri.activityInfo.name) |
| 585 | && bestMatch.activityInfo.applicationInfo.packageName |
| 586 | .equals(ri.activityInfo.applicationInfo.packageName)) { |
| 587 | found = true; |
| 588 | break; |
| 589 | } |
| 590 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 591 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 592 | if (!found) { |
| 593 | if (LOGD) Log.d(TAG, "Multiple options, no default yet"); |
| 594 | // the bestMatch is probably the ResolveActivity, meaning the |
| 595 | // user has not yet selected a default |
| 596 | // so: we'll keep the original intent for now |
| 597 | mHotseats[i] = intent; |
| 598 | |
| 599 | // set the accessibility text to "Select shortcut" |
| 600 | mHotseatLabels[i] = getText(R.string.title_select_shortcut); |
| 601 | } else { |
| 602 | // we have an app! |
| 603 | // now reconstruct the intent to launch it through the front |
| 604 | // door |
| 605 | ComponentName com = new ComponentName( |
| 606 | bestMatch.activityInfo.applicationInfo.packageName, |
| 607 | bestMatch.activityInfo.name); |
| 608 | mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com); |
| 609 | |
| 610 | // load the app label for accessibility |
| 611 | mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm); |
| 612 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | if (LOGD) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 616 | Log.d(TAG, "loadHotseats: hotseat " + i |
| 617 | + " final intent=[" |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 618 | + ((mHotseats[i] == null) |
| 619 | ? "null" |
| 620 | : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME)) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 621 | + "] label=[" + mHotseatLabels[i] |
| 622 | + "]" |
| 623 | ); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 628 | private void completeAdd(PendingAddArguments args) { |
| 629 | switch (args.requestCode) { |
| 630 | case REQUEST_PICK_APPLICATION: |
| 631 | completeAddApplication(args.intent, args.screen, args.cellX, args.cellY); |
| 632 | break; |
| 633 | case REQUEST_PICK_SHORTCUT: |
| 634 | processShortcut(args.intent); |
| 635 | break; |
| 636 | case REQUEST_CREATE_SHORTCUT: |
| 637 | completeAddShortcut(args.intent, args.screen, args.cellX, args.cellY); |
| 638 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 639 | case REQUEST_PICK_APPWIDGET: |
| 640 | addAppWidgetFromPick(args.intent); |
| 641 | break; |
| 642 | case REQUEST_CREATE_APPWIDGET: |
| 643 | int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
| 644 | completeAddAppWidget(appWidgetId, args.screen); |
| 645 | break; |
| 646 | case REQUEST_PICK_WALLPAPER: |
| 647 | // We just wanted the activity result here so we can clear mWaitingForResult |
| 648 | break; |
| 649 | } |
| 650 | } |
| 651 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 652 | @Override |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 653 | protected void onActivityResult(final int requestCode, int resultCode, final Intent data) { |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 654 | mWaitingForResult = false; |
| 655 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 656 | // The pattern used here is that a user PICKs a specific application, |
| 657 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 658 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 659 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 660 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 661 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 662 | if (resultCode == RESULT_OK && mAddScreen != -1) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 663 | final PendingAddArguments args = new PendingAddArguments(); |
| 664 | args.requestCode = requestCode; |
| 665 | args.intent = data; |
| 666 | args.screen = mAddScreen; |
| 667 | args.cellX = mAddIntersectCellX; |
| 668 | args.cellY = mAddIntersectCellY; |
| 669 | |
| 670 | // If the loader is still running, defer the add until it is done. |
| 671 | if (isWorkspaceLocked()) { |
| 672 | sPendingAddList.add(args); |
| 673 | } else { |
| 674 | completeAdd(args); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 675 | } |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 676 | } else if ((requestCode == REQUEST_PICK_APPWIDGET || |
| 677 | requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED && |
| 678 | data != null) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 679 | // Clean up the appWidgetId if we canceled |
| 680 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
| 681 | if (appWidgetId != -1) { |
| 682 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 683 | } |
| 684 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | @Override |
| 688 | protected void onResume() { |
| 689 | super.onResume(); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 690 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 691 | if (mRestoring || mOnResumeNeedsLoad) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 692 | mWorkspaceLoading = true; |
| 693 | mModel.startLoader(this, true); |
| 694 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 695 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 696 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 697 | if (mWaitingForResume != null) { |
| 698 | mWaitingForResume.setStayPressed(false); |
| 699 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 700 | // When we resume Launcher, a different Activity might be responsible for the app |
| 701 | // market intent, so refresh the icon |
| 702 | updateAppMarketIcon(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 706 | protected void onPause() { |
| 707 | super.onPause(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 708 | // Some launcher layouts don't have a previous and next view |
| 709 | if (mPreviousView != null) { |
| 710 | dismissPreview(mPreviousView); |
Patrick Dubroy | ab962b7 | 2010-07-26 12:10:10 -0700 | [diff] [blame] | 711 | } |
| 712 | if (mNextView != null) { |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 713 | dismissPreview(mNextView); |
| 714 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 715 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 716 | mDragController.cancelDrag(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 717 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 718 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 719 | @Override |
| 720 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 721 | // Flag the loader to stop early before switching |
| 722 | mModel.stopLoader(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 723 | if (mAllAppsGrid != null) { |
| 724 | mAllAppsGrid.surrender(); |
| 725 | } |
| 726 | if (mAppsCustomizeContent != null) { |
| 727 | mAppsCustomizeContent.surrender(); |
| 728 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 729 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 730 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 731 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 732 | // We can't hide the IME if it was forced open. So don't bother |
| 733 | /* |
| 734 | @Override |
| 735 | public void onWindowFocusChanged(boolean hasFocus) { |
| 736 | super.onWindowFocusChanged(hasFocus); |
| 737 | |
| 738 | if (hasFocus) { |
| 739 | final InputMethodManager inputManager = (InputMethodManager) |
| 740 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 741 | WindowManager.LayoutParams lp = getWindow().getAttributes(); |
| 742 | inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new |
| 743 | android.os.Handler()) { |
| 744 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 745 | Log.d(TAG, "ResultReceiver got resultCode=" + resultCode); |
| 746 | } |
| 747 | }); |
| 748 | Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged"); |
| 749 | } |
| 750 | } |
| 751 | */ |
| 752 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 753 | private boolean acceptFilter() { |
| 754 | final InputMethodManager inputManager = (InputMethodManager) |
| 755 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 756 | return !inputManager.isFullscreenMode(); |
| 757 | } |
| 758 | |
| 759 | @Override |
| 760 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 761 | final int uniChar = event.getUnicodeChar(); |
| 762 | final boolean handled = super.onKeyDown(keyCode, event); |
| 763 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 764 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 765 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 766 | keyCode, event); |
| 767 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 768 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 769 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 770 | // showSearchDialog() |
| 771 | // If there are multiple keystrokes before the search dialog takes focus, |
| 772 | // onSearchRequested() will be called for every keystroke, |
| 773 | // but it is idempotent, so it's fine. |
| 774 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 778 | // Eat the long press event so the keyboard doesn't come up. |
| 779 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 780 | return true; |
| 781 | } |
| 782 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 783 | return handled; |
| 784 | } |
| 785 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 786 | private String getTypedText() { |
| 787 | return mDefaultKeySsb.toString(); |
| 788 | } |
| 789 | |
| 790 | private void clearTypedText() { |
| 791 | mDefaultKeySsb.clear(); |
| 792 | mDefaultKeySsb.clearSpans(); |
| 793 | Selection.setSelection(mDefaultKeySsb, 0); |
| 794 | } |
| 795 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 796 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 797 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 798 | * State |
| 799 | */ |
| 800 | private static State intToState(int stateOrdinal) { |
| 801 | State state = State.WORKSPACE; |
| 802 | final State[] stateValues = State.values(); |
| 803 | for (int i = 0; i < stateValues.length; i++) { |
| 804 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 805 | state = stateValues[i]; |
| 806 | break; |
| 807 | } |
| 808 | } |
| 809 | return state; |
| 810 | } |
| 811 | |
| 812 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 813 | * Restores the previous state, if it exists. |
| 814 | * |
| 815 | * @param savedState The previous state. |
| 816 | */ |
| 817 | private void restoreState(Bundle savedState) { |
| 818 | if (savedState == null) { |
| 819 | return; |
| 820 | } |
| 821 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 822 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
| 823 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 824 | if (state == State.ALL_APPS || state == State.APPS_CUSTOMIZE) { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 825 | showAllApps(false); |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 826 | } else if (state == State.CUSTOMIZE) { |
| 827 | showCustomizationDrawer(false); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 828 | } |
| 829 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 830 | final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); |
| 831 | if (currentScreen > -1) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 832 | mWorkspace.setCurrentPage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 836 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 837 | if (addScreen > -1) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 838 | mAddScreen = addScreen; |
| 839 | mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 840 | mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 841 | mRestoring = true; |
| 842 | } |
| 843 | |
| 844 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 845 | if (renameFolder) { |
| 846 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 847 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 848 | mRestoring = true; |
| 849 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 850 | |
| 851 | // Restore the current AllApps drawer tab |
| 852 | if (mAllAppsGrid != null && mAllAppsGrid instanceof AllAppsTabbed) { |
| 853 | String curTab = savedState.getString("allapps_currentTab"); |
| 854 | if (curTab != null) { |
| 855 | AllAppsTabbed tabhost = (AllAppsTabbed) mAllAppsGrid; |
| 856 | tabhost.setCurrentTabByTag(curTab); |
| 857 | } |
| 858 | int curPage = savedState.getInt("allapps_currentPage", -1); |
| 859 | if (curPage > -1) { |
| 860 | mAllAppsPagedView.setRestorePage(curPage); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | // Restore the current customization drawer tab |
| 865 | if (mHomeCustomizationDrawer != null) { |
| 866 | String curTab = savedState.getString("customize_currentTab"); |
| 867 | if (curTab != null) { |
| 868 | // We set this directly so that there is no delay before the tab is set |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 869 | mCustomizePagedView.setCustomizationFilter( |
| 870 | mHomeCustomizationDrawer.getCustomizeFilterForTabTag(curTab)); |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 871 | mHomeCustomizationDrawer.setCurrentTabByTag(curTab); |
| 872 | } |
| 873 | |
| 874 | // Note: currently we do not restore the page for the customization tray because unlike |
| 875 | // AllApps, the page content can change drastically |
| 876 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 877 | |
| 878 | // Restore the AppsCustomize tab |
| 879 | if (mAppsCustomizeTabHost != null) { |
| 880 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 881 | if (curTab != null) { |
| 882 | // We set this directly so that there is no delay before the tab is set |
| 883 | mAppsCustomizeContent.setContentType( |
| 884 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
| 885 | mAppsCustomizeTabHost.setCurrentTabByTag(curTab); |
| 886 | } |
| 887 | |
| 888 | // Note: currently we do not restore the page for the AppsCustomize pane because the |
| 889 | // change in layout can drastically affect the saved page index |
| 890 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | /** |
| 894 | * Finds all the views we need and configure them properly. |
| 895 | */ |
| 896 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 897 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 898 | |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 899 | DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 900 | dragLayer.setDragController(dragController); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 901 | dragLayer.setLauncher(this); |
| 902 | mDragLayer = dragLayer; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 903 | |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 904 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 905 | mAllAppsGrid = (AllAppsView) dragLayer.findViewById(R.id.all_apps_view); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 906 | mAllAppsGrid.setup(this, dragController); |
| 907 | // We don't want a hole punched in our window. |
| 908 | ((View) mAllAppsGrid).setWillNotDraw(false); |
| 909 | } else { |
| 910 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) |
| 911 | findViewById(R.id.apps_customize_pane); |
| 912 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 913 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 914 | mAppsCustomizeContent.setup(this, dragController); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 915 | } |
| 916 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 917 | mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 918 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 919 | final Workspace workspace = mWorkspace; |
Joe Onorato | f0dde09 | 2010-02-16 18:25:23 -0500 | [diff] [blame] | 920 | workspace.setHapticFeedbackEnabled(false); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 921 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 922 | DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone); |
| 923 | mDeleteZone = deleteZone; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 924 | |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 925 | View handleView = findViewById(R.id.all_apps_button); |
| 926 | if (handleView != null && handleView instanceof HandleView) { |
| 927 | // we don't use handle view in xlarge mode |
Michael Jurka | 7ef4f75 | 2010-08-03 16:04:26 -0700 | [diff] [blame] | 928 | mHandleView = (HandleView)handleView; |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 929 | mHandleView.setLauncher(this); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 930 | mHandleView.setOnLongClickListener(this); |
| 931 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 932 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 933 | if (mCustomizePagedView != null) { |
| 934 | mCustomizePagedView.setLauncher(this); |
| 935 | mCustomizePagedView.setDragController(dragController); |
Patrick Dubroy | 4a5ad09 | 2011-05-23 16:15:09 -0700 | [diff] [blame] | 936 | mCustomizePagedView.setAllAppsPagedView(mAllAppsPagedView); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 937 | } else { |
| 938 | ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left); |
| 939 | hotseatLeft.setContentDescription(mHotseatLabels[0]); |
| 940 | hotseatLeft.setImageDrawable(mHotseatIcons[0]); |
| 941 | ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right); |
| 942 | hotseatRight.setContentDescription(mHotseatLabels[1]); |
| 943 | hotseatRight.setImageDrawable(mHotseatIcons[1]); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 944 | |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 945 | View.OnKeyListener listener = new IndicatorKeyEventListener(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 946 | mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen); |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 947 | mPreviousView.setOnKeyListener(listener); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 948 | mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen); |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 949 | mNextView.setOnKeyListener(listener); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 950 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 951 | Drawable previous = mPreviousView.getDrawable(); |
| 952 | Drawable next = mNextView.getDrawable(); |
| 953 | mWorkspace.setIndicators(previous, next); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 954 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 955 | mPreviousView.setHapticFeedbackEnabled(false); |
| 956 | mPreviousView.setOnLongClickListener(this); |
| 957 | mNextView.setHapticFeedbackEnabled(false); |
| 958 | mNextView.setOnLongClickListener(this); |
| 959 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 960 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 961 | workspace.setOnLongClickListener(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 962 | workspace.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 963 | workspace.setLauncher(this); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 964 | workspace.setWallpaperDimension(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 965 | |
| 966 | deleteZone.setLauncher(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 967 | deleteZone.setDragController(dragController); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 968 | |
| 969 | final View allAppsButton = findViewById(R.id.all_apps_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 970 | final View divider = findViewById(R.id.all_apps_divider); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 971 | final View configureButton = findViewById(R.id.configure_button); |
| 972 | |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 973 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 26cbf3a | 2011-01-06 16:25:55 -0800 | [diff] [blame] | 974 | deleteZone.setOverlappingViews(new View[] { allAppsButton, divider, configureButton }); |
Michael Jurka | 54f7ac3 | 2010-08-02 13:56:46 -0700 | [diff] [blame] | 975 | } else { |
Winson Chung | 26cbf3a | 2011-01-06 16:25:55 -0800 | [diff] [blame] | 976 | deleteZone.setOverlappingView(findViewById(R.id.all_apps_button_cluster)); |
Michael Jurka | 54f7ac3 | 2010-08-02 13:56:46 -0700 | [diff] [blame] | 977 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 978 | dragController.addDragListener(deleteZone); |
| 979 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 980 | DeleteZone allAppsDeleteZone = (DeleteZone) findViewById(R.id.all_apps_delete_zone); |
| 981 | if (allAppsDeleteZone != null) { |
| 982 | allAppsDeleteZone.setLauncher(this); |
| 983 | allAppsDeleteZone.setDragController(dragController); |
| 984 | allAppsDeleteZone.setDragAndDropEnabled(false); |
| 985 | dragController.addDragListener(allAppsDeleteZone); |
| 986 | dragController.addDropTarget(allAppsDeleteZone); |
| 987 | } |
| 988 | |
| 989 | ApplicationInfoDropTarget allAppsInfoTarget = (ApplicationInfoDropTarget) |
| 990 | findViewById(R.id.all_apps_info_target); |
| 991 | if (allAppsInfoTarget != null) { |
| 992 | allAppsInfoTarget.setLauncher(this); |
| 993 | dragController.addDragListener(allAppsInfoTarget); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 994 | allAppsInfoTarget.setDragAndDropEnabled(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 995 | } |
| 996 | View marketButton = findViewById(R.id.market_button); |
| 997 | if (marketButton != null) { |
| 998 | if (allAppsInfoTarget != null) { |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 999 | allAppsInfoTarget.setOverlappingView(marketButton); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 1000 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1001 | marketButton.setOnClickListener(new OnClickListener() { |
| 1002 | public void onClick(View v) { |
| 1003 | onClickAppMarketButton(v); |
| 1004 | } |
| 1005 | }); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1008 | dragController.setDragScoller(workspace); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1009 | dragController.setScrollView(dragLayer); |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 1010 | dragController.setMoveTarget(workspace); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1011 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1012 | // The order here is bottom to top. |
| 1013 | dragController.addDropTarget(workspace); |
| 1014 | dragController.addDropTarget(deleteZone); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 1015 | if (allAppsInfoTarget != null) { |
| 1016 | dragController.addDropTarget(allAppsInfoTarget); |
| 1017 | } |
| 1018 | if (allAppsDeleteZone != null) { |
| 1019 | dragController.addDropTarget(allAppsDeleteZone); |
| 1020 | } |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1021 | mButtonCluster = (ViewGroup) findViewById(R.id.all_apps_button_cluster); |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 1022 | View.OnKeyListener listener = null; |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 1023 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 1024 | // For tablets, AllApps lives in the button bar at the top |
| 1025 | listener = new ButtonBarKeyEventListener(); |
| 1026 | } else { |
| 1027 | // For phones, AppsCustomize lives in the "dock" at the bottom |
| 1028 | listener = new DockKeyEventListener(); |
| 1029 | } |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1030 | int buttonCount = mButtonCluster.getChildCount(); |
| 1031 | for (int i = 0; i < buttonCount; ++i) { |
| 1032 | mButtonCluster.getChildAt(i).setOnKeyListener(listener); |
| 1033 | } |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 1034 | |
| 1035 | mAllAppsButton = findViewById(R.id.all_apps_button); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1036 | mDivider = findViewById(R.id.all_apps_divider); |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 1037 | mConfigureButton = findViewById(R.id.configure_button); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1038 | |
| 1039 | // We had previously set these click handlers in XML, but the first time we launched |
| 1040 | // Configure or All Apps we had an extra 50ms of delay while the java reflection methods |
| 1041 | // found the right handler. Setting the handlers directly here eliminates that cost. |
| 1042 | if (mConfigureButton != null) { |
| 1043 | mConfigureButton.setOnClickListener(new OnClickListener() { |
| 1044 | public void onClick(View v) { |
| 1045 | onClickConfigureButton(v); |
| 1046 | } |
| 1047 | }); |
| 1048 | } |
| 1049 | if (mDivider != null) { |
| 1050 | mDivider.setOnClickListener(new OnClickListener() { |
| 1051 | public void onClick(View v) { |
| 1052 | onClickAllAppsButton(v); |
| 1053 | } |
| 1054 | }); |
| 1055 | } |
| 1056 | if (mAllAppsButton != null) { |
| 1057 | mAllAppsButton.setOnClickListener(new OnClickListener() { |
| 1058 | public void onClick(View v) { |
| 1059 | onClickAllAppsButton(v); |
| 1060 | } |
| 1061 | }); |
| 1062 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 1065 | @SuppressWarnings({"UnusedDeclaration"}) |
| 1066 | public void previousScreen(View v) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1067 | if (mState != State.ALL_APPS && mState != State.APPS_CUSTOMIZE) { |
Joe Onorato | 61597bd | 2009-11-19 12:51:57 -0800 | [diff] [blame] | 1068 | mWorkspace.scrollLeft(); |
| 1069 | } |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | @SuppressWarnings({"UnusedDeclaration"}) |
| 1073 | public void nextScreen(View v) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1074 | if (mState != State.ALL_APPS && mState != State.APPS_CUSTOMIZE) { |
Joe Onorato | 61597bd | 2009-11-19 12:51:57 -0800 | [diff] [blame] | 1075 | mWorkspace.scrollRight(); |
| 1076 | } |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 1077 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1078 | |
| 1079 | @SuppressWarnings({"UnusedDeclaration"}) |
| 1080 | public void launchHotSeat(View v) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1081 | if (mState == State.ALL_APPS) return; |
Daniel Sandler | 3e9454a | 2010-05-24 11:22:41 -0400 | [diff] [blame] | 1082 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1083 | int index = -1; |
| 1084 | if (v.getId() == R.id.hotseat_left) { |
| 1085 | index = 0; |
| 1086 | } else if (v.getId() == R.id.hotseat_right) { |
| 1087 | index = 1; |
| 1088 | } |
| 1089 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 1090 | // reload these every tap; you never know when they might change |
| 1091 | loadHotseats(); |
| 1092 | if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) { |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1093 | startActivitySafely( |
| 1094 | mHotseats[index], |
| 1095 | "hotseat" |
| 1096 | ); |
| 1097 | } |
| 1098 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1099 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1100 | /** |
| 1101 | * Creates a view representing a shortcut. |
| 1102 | * |
| 1103 | * @param info The data structure describing the shortcut. |
| 1104 | * |
| 1105 | * @return A View inflated from R.layout.application. |
| 1106 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1107 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1108 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1109 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | /** |
| 1113 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1114 | * |
| 1115 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1116 | * @param parent The group the shortcut belongs to. |
| 1117 | * @param info The data structure describing the shortcut. |
| 1118 | * |
| 1119 | * @return A View inflated from layoutResId. |
| 1120 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1121 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1122 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
| 1123 | favorite.applyFromShortcutInfo(info, mIconCache); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1124 | favorite.setOnClickListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1125 | return favorite; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * Add an application shortcut to the workspace. |
| 1130 | * |
| 1131 | * @param data The intent describing the application. |
| 1132 | * @param cellInfo The position on screen where to create the shortcut. |
| 1133 | */ |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 1134 | void completeAddApplication(Intent data, int screen, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1135 | int intersectCellX, int intersectCellY) { |
| 1136 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1137 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1138 | |
| 1139 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1140 | showOutOfSpaceMessage(); |
| 1141 | return; |
| 1142 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1143 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 1144 | final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1145 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1146 | if (info != null) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1147 | info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1148 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1149 | info.container = ItemInfo.NO_ID; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1150 | mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1], |
| 1151 | isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1152 | } else { |
| 1153 | 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] | 1154 | } |
| 1155 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1156 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1157 | /** |
| 1158 | * Add a shortcut to the workspace. |
| 1159 | * |
| 1160 | * @param data The intent describing the shortcut. |
| 1161 | * @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] | 1162 | */ |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1163 | private void completeAddShortcut(Intent data, int screen, |
| 1164 | int intersectCellX, int intersectCellY) { |
| 1165 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1166 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1167 | |
Patrick Dubroy | 8b1fe77 | 2011-01-25 05:32:24 -0800 | [diff] [blame] | 1168 | int[] touchXY = mAddDropPosition; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1169 | boolean foundCellSpan = false; |
| 1170 | if (touchXY != null) { |
| 1171 | // when dragging and dropping, just find the closest free spot |
| 1172 | CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1173 | int[] result = screenLayout.findNearestVacantArea( |
| 1174 | touchXY[0], touchXY[1], 1, 1, cellXY); |
| 1175 | foundCellSpan = (result != null); |
| 1176 | } else { |
| 1177 | foundCellSpan = layout.findCellForSpanThatIntersects( |
| 1178 | cellXY, 1, 1, intersectCellX, intersectCellY); |
| 1179 | } |
| 1180 | |
| 1181 | if (!foundCellSpan) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1182 | showOutOfSpaceMessage(); |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | final ShortcutInfo info = mModel.addShortcut( |
| 1187 | this, data, screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1188 | |
| 1189 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1190 | final View view = createShortcut(info); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1191 | mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1195 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1196 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1197 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1198 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1199 | * @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] | 1200 | */ |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1201 | private void completeAddAppWidget(final int appWidgetId, int screen) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1202 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1203 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1204 | // Calculate the grid spans needed to fit this widget |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1205 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1206 | int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1207 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1208 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1209 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1210 | // if we are placing widgets on a "spring-loaded" screen |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1211 | final int[] cellXY = mTmpAddItemCellCoordinates; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1212 | |
Patrick Dubroy | 8b1fe77 | 2011-01-25 05:32:24 -0800 | [diff] [blame] | 1213 | int[] touchXY = mAddDropPosition; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1214 | boolean foundCellSpan = false; |
| 1215 | if (touchXY != null) { |
| 1216 | // when dragging and dropping, just find the closest free spot |
| 1217 | CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1218 | int[] result = screenLayout.findNearestVacantArea( |
| 1219 | touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1220 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1221 | } else { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1222 | // if we long pressed on an empty cell to bring up a menu, |
| 1223 | // make sure we intersect the empty cell |
| 1224 | // if mAddIntersectCellX/Y are -1 (e.g. we used menu -> add) then |
| 1225 | // findCellForSpanThatIntersects will just ignore them |
| 1226 | foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1], |
| 1227 | mAddIntersectCellX, mAddIntersectCellY); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1230 | if (!foundCellSpan) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1231 | if (appWidgetId != -1) { |
| 1232 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 1233 | // to the caller... |
| 1234 | final LauncherAppWidgetHost appWidgetHost = mAppWidgetHost; |
| 1235 | new Thread("deleteAppWidgetId") { |
| 1236 | public void run() { |
| 1237 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 1238 | } |
| 1239 | }.start(); |
| 1240 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1241 | showOutOfSpaceMessage(); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1242 | return; |
| 1243 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1244 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1245 | // Build Launcher-specific widget info and save to database |
| 1246 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1247 | launcherInfo.spanX = spanXY[0]; |
| 1248 | launcherInfo.spanY = spanXY[1]; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1249 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1250 | LauncherModel.addItemToDatabase(this, launcherInfo, |
| 1251 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1252 | screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1253 | |
| 1254 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1255 | mDesktopItems.add(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1256 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1257 | // Perform actual inflation because we're live |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1258 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1259 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1260 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1261 | launcherInfo.hostView.setTag(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1262 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1263 | mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1264 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1265 | |
| 1266 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1267 | } |
| 1268 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1269 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1270 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1271 | @Override |
| 1272 | public void onReceive(Context context, Intent intent) { |
| 1273 | final String action = intent.getAction(); |
| 1274 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1275 | mUserPresent = false; |
| 1276 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1277 | |
| 1278 | // Reset AllApps to it's initial state |
| 1279 | if (mAllAppsGrid != null) { |
| 1280 | mAllAppsGrid.reset(); |
| 1281 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1282 | if (mAppsCustomizeContent != null) { |
| 1283 | mAppsCustomizeContent.reset(); |
| 1284 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1285 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1286 | mUserPresent = true; |
| 1287 | updateRunning(); |
| 1288 | } |
| 1289 | } |
| 1290 | }; |
| 1291 | |
| 1292 | @Override |
| 1293 | public void onAttachedToWindow() { |
| 1294 | super.onAttachedToWindow(); |
| 1295 | |
| 1296 | // Listen for broadcasts related to user-presence |
| 1297 | final IntentFilter filter = new IntentFilter(); |
| 1298 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1299 | filter.addAction(Intent.ACTION_USER_PRESENT); |
| 1300 | registerReceiver(mReceiver, filter); |
| 1301 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1302 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1303 | mVisible = true; |
| 1304 | } |
| 1305 | |
| 1306 | @Override |
| 1307 | public void onDetachedFromWindow() { |
| 1308 | super.onDetachedFromWindow(); |
| 1309 | mVisible = false; |
| 1310 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1311 | if (mAttached) { |
| 1312 | unregisterReceiver(mReceiver); |
| 1313 | mAttached = false; |
| 1314 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1315 | updateRunning(); |
| 1316 | } |
| 1317 | |
| 1318 | public void onWindowVisibilityChanged(int visibility) { |
| 1319 | mVisible = visibility == View.VISIBLE; |
| 1320 | updateRunning(); |
| 1321 | } |
| 1322 | |
| 1323 | private void sendAdvanceMessage(long delay) { |
| 1324 | mHandler.removeMessages(ADVANCE_MSG); |
| 1325 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1326 | mHandler.sendMessageDelayed(msg, delay); |
| 1327 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1328 | } |
| 1329 | |
| 1330 | private void updateRunning() { |
| 1331 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1332 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1333 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1334 | if (autoAdvanceRunning) { |
| 1335 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1336 | sendAdvanceMessage(delay); |
| 1337 | } else { |
| 1338 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1339 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1340 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1341 | } |
| 1342 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1343 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | private final Handler mHandler = new Handler() { |
| 1349 | @Override |
| 1350 | public void handleMessage(Message msg) { |
| 1351 | if (msg.what == ADVANCE_MSG) { |
| 1352 | int i = 0; |
| 1353 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1354 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1355 | final int delay = mAdvanceStagger * i; |
| 1356 | if (v instanceof Advanceable) { |
| 1357 | postDelayed(new Runnable() { |
| 1358 | public void run() { |
| 1359 | ((Advanceable) v).advance(); |
| 1360 | } |
| 1361 | }, delay); |
| 1362 | } |
| 1363 | i++; |
| 1364 | } |
| 1365 | sendAdvanceMessage(mAdvanceInterval); |
| 1366 | } |
| 1367 | } |
| 1368 | }; |
| 1369 | |
| 1370 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1371 | if (appWidgetInfo.autoAdvanceViewId == -1) return; |
| 1372 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1373 | if (v instanceof Advanceable) { |
| 1374 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1375 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1376 | updateRunning(); |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | void removeWidgetToAutoAdvance(View hostView) { |
| 1381 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1382 | mWidgetsToAdvance.remove(hostView); |
| 1383 | updateRunning(); |
| 1384 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1387 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
| 1388 | mDesktopItems.remove(launcherInfo); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1389 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1390 | launcherInfo.hostView = null; |
| 1391 | } |
| 1392 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1393 | void showOutOfSpaceMessage() { |
| 1394 | Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show(); |
| 1395 | } |
| 1396 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1397 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1398 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1399 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1400 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1401 | public LauncherModel getModel() { |
| 1402 | return mModel; |
| 1403 | } |
| 1404 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1405 | void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1406 | getWindow().closeAllPanels(); |
| 1407 | |
| 1408 | try { |
| 1409 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 1410 | // Unlock the workspace if the dialog was showing |
| 1411 | } catch (Exception e) { |
| 1412 | // An exception is thrown if the dialog is not visible, which is fine |
| 1413 | } |
| 1414 | |
| 1415 | try { |
| 1416 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 1417 | // Unlock the workspace if the dialog was showing |
| 1418 | } catch (Exception e) { |
| 1419 | // An exception is thrown if the dialog is not visible, which is fine |
| 1420 | } |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1421 | |
| 1422 | // Whatever we were doing is hereby canceled. |
| 1423 | mWaitingForResult = false; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1424 | } |
| 1425 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1426 | @Override |
| 1427 | protected void onNewIntent(Intent intent) { |
| 1428 | super.onNewIntent(intent); |
| 1429 | |
| 1430 | // Close the menu |
| 1431 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1432 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1433 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1434 | |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 1435 | boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1436 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1437 | |
Patrick Dubroy | 6ec2e18 | 2011-02-23 13:31:16 -0800 | [diff] [blame] | 1438 | // In all these cases, only animate if we're already on home |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1439 | mWorkspace.unshrink(alreadyOnHome); |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1440 | mWorkspace.exitWidgetResizeMode(); |
Patrick Dubroy | a0aa012 | 2011-02-24 11:42:23 -0800 | [diff] [blame] | 1441 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()) { |
Patrick Dubroy | 6ec2e18 | 2011-02-23 13:31:16 -0800 | [diff] [blame] | 1442 | mWorkspace.moveToDefaultScreen(true); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1443 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1444 | showWorkspace(alreadyOnHome); |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1445 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1446 | final View v = getWindow().peekDecorView(); |
| 1447 | if (v != null && v.getWindowToken() != null) { |
| 1448 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1449 | INPUT_METHOD_SERVICE); |
| 1450 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1451 | } |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1452 | |
| 1453 | // Reset AllApps to it's initial state |
| 1454 | if (mAllAppsGrid != null) { |
| 1455 | mAllAppsGrid.reset(); |
| 1456 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1457 | if (mAppsCustomizeContent != null) { |
| 1458 | mAppsCustomizeContent.reset(); |
| 1459 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | @Override |
| 1464 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 1465 | // Do not call super here |
| 1466 | mSavedInstanceState = savedInstanceState; |
| 1467 | } |
| 1468 | |
| 1469 | @Override |
| 1470 | protected void onSaveInstanceState(Bundle outState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1471 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1472 | |
| 1473 | final ArrayList<Folder> folders = mWorkspace.getOpenFolders(); |
| 1474 | if (folders.size() > 0) { |
| 1475 | final int count = folders.size(); |
| 1476 | long[] ids = new long[count]; |
| 1477 | for (int i = 0; i < count; i++) { |
| 1478 | final FolderInfo info = folders.get(i).getInfo(); |
| 1479 | ids[i] = info.id; |
| 1480 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 1481 | outState.putLongArray(RUNTIME_STATE_FOLDERS, ids); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1482 | } else { |
| 1483 | super.onSaveInstanceState(outState); |
| 1484 | } |
| 1485 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1486 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1487 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1488 | if (mAddScreen > -1 && mWaitingForResult) { |
| 1489 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen); |
| 1490 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX); |
| 1491 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | if (mFolderInfo != null && mWaitingForResult) { |
| 1495 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1496 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1497 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1498 | |
Winson Chung | 43b119d | 2010-12-06 16:45:05 -0800 | [diff] [blame] | 1499 | // Save the current AllApps drawer tab |
| 1500 | if (mAllAppsGrid != null && mAllAppsGrid instanceof AllAppsTabbed) { |
| 1501 | AllAppsTabbed tabhost = (AllAppsTabbed) mAllAppsGrid; |
| 1502 | String currentTabTag = tabhost.getCurrentTabTag(); |
| 1503 | if (currentTabTag != null) { |
| 1504 | outState.putString("allapps_currentTab", currentTabTag); |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 1505 | outState.putInt("allapps_currentPage", mAllAppsPagedView.getCurrentPage()); |
Winson Chung | 43b119d | 2010-12-06 16:45:05 -0800 | [diff] [blame] | 1506 | } |
| 1507 | } |
Winson Chung | 43b119d | 2010-12-06 16:45:05 -0800 | [diff] [blame] | 1508 | // Save the current customization drawer tab |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1509 | if (mHomeCustomizationDrawer != null) { |
| 1510 | String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag(); |
| 1511 | if (currentTabTag != null) { |
Winson Chung | 43b119d | 2010-12-06 16:45:05 -0800 | [diff] [blame] | 1512 | outState.putString("customize_currentTab", currentTabTag); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1513 | } |
| 1514 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1515 | // Save the current AppsCustomize tab |
| 1516 | if (mAppsCustomizeTabHost != null) { |
| 1517 | String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag(); |
| 1518 | if (currentTabTag != null) { |
| 1519 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 1520 | } |
| 1521 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | @Override |
| 1525 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1526 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1527 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1528 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1529 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1530 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1531 | 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] | 1532 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1533 | mAppWidgetHost = null; |
| 1534 | |
| 1535 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1536 | |
| 1537 | TextKeyListener.getInstance().release(); |
| 1538 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1539 | mModel.stopLoader(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1540 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1541 | unbindDesktopItems(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1542 | |
| 1543 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1544 | |
Patrick Dubroy | ab962b7 | 2010-07-26 12:10:10 -0700 | [diff] [blame] | 1545 | // Some launcher layouts don't have a previous and next view |
| 1546 | if (mPreviousView != null) { |
| 1547 | dismissPreview(mPreviousView); |
| 1548 | } |
| 1549 | if (mNextView != null) { |
| 1550 | dismissPreview(mNextView); |
| 1551 | } |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1552 | |
| 1553 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1554 | |
| 1555 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
| 1556 | mWorkspace.removeAllViews(); |
| 1557 | mWorkspace = null; |
| 1558 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 1559 | |
| 1560 | ValueAnimator.clearAllAnimations(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1561 | } |
| 1562 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1563 | public DragController getDragController() { |
| 1564 | return mDragController; |
| 1565 | } |
| 1566 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1567 | @Override |
| 1568 | public void startActivityForResult(Intent intent, int requestCode) { |
Romain Guy | 08f9749 | 2009-06-29 14:41:20 -0700 | [diff] [blame] | 1569 | if (requestCode >= 0) mWaitingForResult = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1570 | super.startActivityForResult(intent, requestCode); |
| 1571 | } |
| 1572 | |
| 1573 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1574 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1575 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1576 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1577 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1578 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1579 | if (initialQuery == null) { |
| 1580 | // Use any text typed in the launcher as the initial query |
| 1581 | initialQuery = getTypedText(); |
| 1582 | clearTypedText(); |
| 1583 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1584 | if (appSearchData == null) { |
| 1585 | appSearchData = new Bundle(); |
Bjorn Bringert | 3e244cf | 2010-02-10 14:17:35 +0000 | [diff] [blame] | 1586 | appSearchData.putString(Search.SOURCE, "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1587 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1588 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1589 | final SearchManager searchManager = |
| 1590 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1591 | searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1592 | appSearchData, globalSearch); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | @Override |
| 1596 | public boolean onCreateOptionsMenu(Menu menu) { |
Patrick Dubroy | 5905bca | 2010-09-08 22:43:38 -0700 | [diff] [blame] | 1597 | if (isWorkspaceLocked()) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1598 | return false; |
| 1599 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1600 | |
| 1601 | super.onCreateOptionsMenu(menu); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1602 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1603 | menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add) |
| 1604 | .setIcon(android.R.drawable.ic_menu_add) |
| 1605 | .setAlphabeticShortcut('A'); |
Winson Chung | 7ad0141 | 2010-09-27 11:33:03 -0700 | [diff] [blame] | 1606 | menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps) |
| 1607 | .setIcon(android.R.drawable.ic_menu_manage) |
| 1608 | .setAlphabeticShortcut('M'); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1609 | menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1610 | .setIcon(android.R.drawable.ic_menu_gallery) |
| 1611 | .setAlphabeticShortcut('W'); |
| 1612 | menu.add(0, MENU_SEARCH, 0, R.string.menu_search) |
| 1613 | .setIcon(android.R.drawable.ic_search_category_default) |
| 1614 | .setAlphabeticShortcut(SearchManager.MENU_KEY); |
| 1615 | menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications) |
| 1616 | .setIcon(com.android.internal.R.drawable.ic_menu_notifications) |
| 1617 | .setAlphabeticShortcut('N'); |
| 1618 | |
| 1619 | final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1620 | settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1621 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1622 | |
| 1623 | menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) |
| 1624 | .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') |
| 1625 | .setIntent(settings); |
| 1626 | |
| 1627 | return true; |
| 1628 | } |
| 1629 | |
| 1630 | @Override |
| 1631 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 1632 | super.onPrepareOptionsMenu(menu); |
| 1633 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1634 | if (mAllAppsGrid != null) { |
| 1635 | // If all apps is animating, don't show the menu, because we don't know |
| 1636 | // which one to show. |
| 1637 | if (mAllAppsGrid.isAnimating()) { |
| 1638 | return false; |
| 1639 | } |
| 1640 | |
| 1641 | // Only show the add and wallpaper options when we're not in all apps. |
| 1642 | boolean visible = !mAllAppsGrid.isVisible(); |
| 1643 | menu.setGroupVisible(MENU_GROUP_ADD, visible); |
| 1644 | menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible); |
| 1645 | |
| 1646 | // Disable add if the workspace is full. |
| 1647 | if (visible) { |
| 1648 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage()); |
| 1649 | menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell()); |
| 1650 | } |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1651 | } |
| 1652 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1653 | // TODO-APPS_CUSTOMIZE: Remove this for the phone UI at some point, along with all the menu |
| 1654 | // related code? |
| 1655 | if (mAppsCustomizeContent != null && mAppsCustomizeContent.isAnimating()) return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1656 | |
| 1657 | return true; |
| 1658 | } |
| 1659 | |
| 1660 | @Override |
| 1661 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1662 | switch (item.getItemId()) { |
| 1663 | case MENU_ADD: |
| 1664 | addItems(); |
| 1665 | return true; |
Winson Chung | 7ad0141 | 2010-09-27 11:33:03 -0700 | [diff] [blame] | 1666 | case MENU_MANAGE_APPS: |
| 1667 | manageApps(); |
| 1668 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1669 | case MENU_WALLPAPER_SETTINGS: |
| 1670 | startWallpaper(); |
| 1671 | return true; |
| 1672 | case MENU_SEARCH: |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1673 | onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1674 | return true; |
| 1675 | case MENU_NOTIFICATIONS: |
| 1676 | showNotifications(); |
| 1677 | return true; |
| 1678 | } |
| 1679 | |
| 1680 | return super.onOptionsItemSelected(item); |
| 1681 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1682 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1683 | /** |
| 1684 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1685 | * argument for {@link #startSearch} to true. |
| 1686 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1687 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1688 | @Override |
| 1689 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1690 | startSearch(null, false, null, true); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1691 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1692 | } |
| 1693 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1694 | public boolean isWorkspaceLocked() { |
| 1695 | return mWorkspaceLoading || mWaitingForResult; |
| 1696 | } |
| 1697 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1698 | // Is the workspace preview (brought up by long-pressing on a signpost icon) visible? |
| 1699 | private boolean isPreviewVisible() { |
| 1700 | return (mPreviousView != null && mPreviousView.getTag() != null) || |
| 1701 | (mNextView != null && mNextView.getTag() != null); |
| 1702 | } |
| 1703 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1704 | private void addItems() { |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 1705 | if (LauncherApplication.isScreenLarge()) { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1706 | // Animate the widget chooser up from the bottom of the screen |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1707 | if (mState != State.CUSTOMIZE) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 1708 | showCustomizationDrawer(true); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1709 | } |
| 1710 | } else { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1711 | showWorkspace(true); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1712 | showAddDialog(-1, -1); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1713 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1714 | } |
| 1715 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1716 | private void resetAddInfo() { |
| 1717 | mAddScreen = -1; |
| 1718 | mAddIntersectCellX = -1; |
| 1719 | mAddIntersectCellY = -1; |
| 1720 | mAddDropPosition = null; |
| 1721 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1722 | |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1723 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, int screen, int[] position) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1724 | resetAddInfo(); |
| 1725 | mAddScreen = screen; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1726 | mAddDropPosition = position; |
| 1727 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1728 | int appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1729 | AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName); |
| 1730 | addAppWidgetImpl(appWidgetId, info); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Winson Chung | 7ad0141 | 2010-09-27 11:33:03 -0700 | [diff] [blame] | 1733 | private void manageApps() { |
| 1734 | startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS)); |
| 1735 | } |
| 1736 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1737 | void addAppWidgetFromPick(Intent data) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1738 | // TODO: catch bad widget exception when sent |
| 1739 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1740 | // TODO: Is this log message meaningful? |
| 1741 | if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras()); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1742 | addAppWidgetImpl(appWidgetId, null); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1745 | void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1746 | AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1747 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1748 | if (appWidget.configure != null) { |
| 1749 | // Launch over to configure widget, if needed |
| 1750 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
| 1751 | intent.setComponent(appWidget.configure); |
| 1752 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1753 | if (info != null) { |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 1754 | if (info.mimeType != null && !info.mimeType.isEmpty()) { |
| 1755 | intent.putExtra( |
| 1756 | InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, |
| 1757 | info.mimeType); |
| 1758 | |
| 1759 | final String mimeType = info.mimeType; |
| 1760 | final ClipData clipData = (ClipData) info.configurationData; |
| 1761 | final ClipDescription clipDesc = clipData.getDescription(); |
| 1762 | for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) { |
| 1763 | if (clipDesc.getMimeType(i).equals(mimeType)) { |
Dianne Hackborn | 0d5aad7 | 2011-01-17 15:28:58 -0800 | [diff] [blame] | 1764 | final ClipData.Item item = clipData.getItemAt(i); |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 1765 | final CharSequence stringData = item.getText(); |
| 1766 | final Uri uriData = item.getUri(); |
| 1767 | final Intent intentData = item.getIntent(); |
| 1768 | final String key = |
| 1769 | InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA; |
| 1770 | if (uriData != null) { |
| 1771 | intent.putExtra(key, uriData); |
| 1772 | } else if (intentData != null) { |
| 1773 | intent.putExtra(key, intentData); |
| 1774 | } else if (stringData != null) { |
| 1775 | intent.putExtra(key, stringData); |
| 1776 | } |
| 1777 | break; |
| 1778 | } |
| 1779 | } |
| 1780 | } |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1781 | } |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1782 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 1783 | startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1784 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1785 | // Otherwise just add it |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1786 | completeAddAppWidget(appWidgetId, mAddScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1787 | } |
| 1788 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1789 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1790 | void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) { |
| 1791 | resetAddInfo(); |
| 1792 | mAddScreen = screen; |
| 1793 | mAddDropPosition = position; |
| 1794 | |
| 1795 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 1796 | createShortcutIntent.setComponent(componentName); |
| 1797 | processShortcut(createShortcutIntent); |
| 1798 | } |
| 1799 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1800 | void processShortcut(Intent intent) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1801 | // Handle case where user selected "Applications" |
| 1802 | String applicationName = getResources().getString(R.string.group_applications); |
| 1803 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1804 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1805 | if (applicationName != null && applicationName.equals(shortcutName)) { |
| 1806 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1807 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1808 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1809 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1810 | pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); |
Winson Chung | 58f2088 | 2010-10-01 13:44:56 -0700 | [diff] [blame] | 1811 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application)); |
Joe Onorato | 4a79a04 | 2010-09-24 16:17:21 -0700 | [diff] [blame] | 1812 | startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1813 | } else { |
Joe Onorato | 4a79a04 | 2010-09-24 16:17:21 -0700 | [diff] [blame] | 1814 | startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1815 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1816 | } |
| 1817 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 1818 | void processWallpaper(Intent intent) { |
| 1819 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 1820 | } |
| 1821 | |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1822 | FolderIcon addFolder(int screen, int intersectCellX, int intersectCellY) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 1823 | FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1824 | folderInfo.title = getText(R.string.folder_name); |
| 1825 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1826 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1827 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1828 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1829 | showOutOfSpaceMessage(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1830 | return null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1831 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1832 | |
| 1833 | // Update the model |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1834 | LauncherModel.addItemToDatabase(this, folderInfo, |
| 1835 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1836 | screen, cellXY[0], cellXY[1], false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1837 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1838 | |
| 1839 | // Create the view |
| 1840 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 1841 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), |
| 1842 | folderInfo, mIconCache); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1843 | mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked()); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1844 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1845 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1846 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1847 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1848 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1849 | } |
| 1850 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1851 | private void showNotifications() { |
| 1852 | final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE); |
| 1853 | if (statusBar != null) { |
| 1854 | statusBar.expand(); |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | private void startWallpaper() { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1859 | showWorkspace(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1860 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
Dianne Hackborn | 8355ae3 | 2009-09-07 21:47:51 -0700 | [diff] [blame] | 1861 | Intent chooser = Intent.createChooser(pickWallpaper, |
| 1862 | getText(R.string.chooser_wallpaper)); |
Romain Guy | f2826c7 | 2009-11-12 17:39:34 -0800 | [diff] [blame] | 1863 | // NOTE: Adds a configure option to the chooser if the wallpaper supports it |
| 1864 | // Removed in Eclair MR1 |
| 1865 | // WallpaperManager wm = (WallpaperManager) |
| 1866 | // getSystemService(Context.WALLPAPER_SERVICE); |
| 1867 | // WallpaperInfo wi = wm.getWallpaperInfo(); |
| 1868 | // if (wi != null && wi.getSettingsActivity() != null) { |
| 1869 | // LabeledIntent li = new LabeledIntent(getPackageName(), |
| 1870 | // R.string.configure_wallpaper, 0); |
| 1871 | // li.setClassName(wi.getPackageName(), wi.getSettingsActivity()); |
| 1872 | // chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li }); |
| 1873 | // } |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 1874 | startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1875 | } |
| 1876 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1877 | /** |
| 1878 | * Registers various content observers. The current implementation registers |
| 1879 | * only a favorites observer to keep track of the favorites applications. |
| 1880 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1881 | private void registerContentObservers() { |
| 1882 | ContentResolver resolver = getContentResolver(); |
| 1883 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 1884 | true, mWidgetObserver); |
| 1885 | } |
| 1886 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1887 | @Override |
| 1888 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 1889 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 1890 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1891 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1892 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1893 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jason Sams | eb5615d | 2009-11-30 11:50:10 -0800 | [diff] [blame] | 1894 | if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1895 | dumpState(); |
| 1896 | return true; |
| 1897 | } |
| 1898 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1899 | } |
| 1900 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 1901 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1902 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1903 | return true; |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | return super.dispatchKeyEvent(event); |
| 1908 | } |
| 1909 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1910 | @Override |
| 1911 | public void onBackPressed() { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1912 | if (mState == State.ALL_APPS || mState == State.CUSTOMIZE || mState == State.APPS_CUSTOMIZE) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1913 | showWorkspace(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1914 | } else if (mWorkspace.getOpenFolder() != null) { |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1915 | closeFolder(); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1916 | } else if (isPreviewVisible()) { |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1917 | dismissPreview(mPreviousView); |
| 1918 | dismissPreview(mNextView); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1919 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1920 | mWorkspace.exitWidgetResizeMode(); |
| 1921 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1922 | // Back button is a no-op here, but give at least some feedback for the button press |
| 1923 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1924 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1925 | } |
| 1926 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1927 | public void closeFolder() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1928 | Folder folder = mWorkspace.getOpenFolder(); |
| 1929 | if (folder != null) { |
| 1930 | closeFolder(folder); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1931 | mDragLayer.setCurrentFolder(null); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | void closeFolder(Folder folder) { |
| 1936 | folder.getInfo().opened = false; |
Adam Cohen | 7f4eabe | 2011-04-21 16:19:16 -0700 | [diff] [blame] | 1937 | |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 1938 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1939 | if (parent != null) { |
Michael Jurka | f3ca3ab | 2010-10-20 17:08:24 -0700 | [diff] [blame] | 1940 | CellLayout cl = (CellLayout) parent; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1941 | FolderIcon fi = (FolderIcon) cl.getChildAt(folder.mInfo.cellX, folder.mInfo.cellY); |
| 1942 | shrinkAndFadeInFolderIcon(fi); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 1943 | mDragController.removeDropTarget((DropTarget)folder); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1944 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 1945 | |
| 1946 | folder.animateClosed(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1947 | folder.onClose(); |
| 1948 | } |
| 1949 | |
| 1950 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1951 | * Re-listen when widgets are reset. |
| 1952 | */ |
| 1953 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 1954 | if (mAppWidgetHost != null) { |
| 1955 | mAppWidgetHost.startListening(); |
| 1956 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1960 | * Go through the and disconnect any of the callbacks in the drawables and the views or we |
| 1961 | * leak the previous Home screen on orientation change. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1962 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1963 | private void unbindDesktopItems() { |
| 1964 | for (ItemInfo item: mDesktopItems) { |
| 1965 | item.unbind(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1966 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1967 | mDesktopItems.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1968 | } |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1969 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1970 | /** |
| 1971 | * Launches the intent referred by the clicked shortcut. |
| 1972 | * |
| 1973 | * @param v The view representing the clicked shortcut. |
| 1974 | */ |
| 1975 | public void onClick(View v) { |
| 1976 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1977 | if (tag instanceof ShortcutInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1978 | // Open shortcut |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1979 | final Intent intent = ((ShortcutInfo) tag).intent; |
Joe Onorato | 13724ea | 2009-12-02 21:16:35 -0800 | [diff] [blame] | 1980 | int[] pos = new int[2]; |
| 1981 | v.getLocationOnScreen(pos); |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1982 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 1983 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1984 | boolean success = startActivitySafely(intent, tag); |
| 1985 | |
| 1986 | if (success && v instanceof BubbleTextView) { |
| 1987 | mWaitingForResume = (BubbleTextView) v; |
| 1988 | mWaitingForResume.setStayPressed(true); |
| 1989 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1990 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1991 | if (v instanceof FolderIcon) { |
| 1992 | FolderIcon fi = (FolderIcon) v; |
| 1993 | handleFolderClick(fi); |
| 1994 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1995 | } else if (v == mHandleView) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1996 | if (mState == State.ALL_APPS) { |
| 1997 | showWorkspace(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1998 | } else { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1999 | showAllApps(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 2000 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2001 | } |
| 2002 | } |
| 2003 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2004 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 2005 | // this is an intercepted event being forwarded from mWorkspace; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2006 | // clicking anywhere on the workspace causes the customization drawer to slide down |
| 2007 | showWorkspace(true); |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2008 | return false; |
| 2009 | } |
| 2010 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2011 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2012 | * Event handler for the search button |
| 2013 | * |
| 2014 | * @param v The view that was clicked. |
| 2015 | */ |
| 2016 | public void onClickSearchButton(View v) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2017 | startSearch(null, false, null, true); |
Amith Yamasani | 1f878a1 | 2010-11-22 14:58:22 -0800 | [diff] [blame] | 2018 | // Use a custom animation for launching search |
| 2019 | overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2023 | * Event handler for the voice button |
| 2024 | * |
| 2025 | * @param v The view that was clicked. |
| 2026 | */ |
| 2027 | public void onClickVoiceButton(View v) { |
| 2028 | startVoiceSearch(); |
| 2029 | } |
| 2030 | |
| 2031 | private void startVoiceSearch() { |
| 2032 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2033 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2034 | startActivity(intent); |
| 2035 | } |
| 2036 | |
| 2037 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2038 | * Event handler for the "gear" button that appears on the home screen, which |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2039 | * enters home screen customization mode. |
| 2040 | * |
| 2041 | * @param v The view that was clicked. |
| 2042 | */ |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2043 | public void onClickConfigureButton(View v) { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2044 | addItems(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2047 | /** |
| 2048 | * Event handler for the "grid" button that appears on the home screen, which |
| 2049 | * enters all apps mode. |
| 2050 | * |
| 2051 | * @param v The view that was clicked. |
| 2052 | */ |
| 2053 | public void onClickAllAppsButton(View v) { |
| 2054 | showAllApps(true); |
| 2055 | } |
| 2056 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2057 | public void onClickAppMarketButton(View v) { |
| 2058 | if (mAppMarketIntent != null) { |
| 2059 | startActivitySafely(mAppMarketIntent, "app market"); |
| 2060 | } |
| 2061 | } |
| 2062 | |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2063 | void startApplicationDetailsActivity(ComponentName componentName) { |
| 2064 | String packageName = componentName.getPackageName(); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2065 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 2066 | Uri.fromParts("package", packageName, null)); |
| 2067 | startActivity(intent); |
| 2068 | } |
| 2069 | |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2070 | void startApplicationUninstallActivity(ApplicationInfo appInfo) { |
| 2071 | if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) { |
| 2072 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2073 | // We may give them the option of disabling apps this way. |
| 2074 | int messageId = R.string.uninstall_system_app_text; |
| 2075 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
| 2076 | } else { |
| 2077 | String packageName = appInfo.componentName.getPackageName(); |
| 2078 | String className = appInfo.componentName.getClassName(); |
| 2079 | Intent intent = new Intent( |
| 2080 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
| 2081 | startActivity(intent); |
| 2082 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2085 | boolean startActivitySafely(Intent intent, Object tag) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2086 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2087 | try { |
| 2088 | startActivity(intent); |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2089 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2090 | } catch (ActivityNotFoundException e) { |
| 2091 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 2092 | 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] | 2093 | } catch (SecurityException e) { |
| 2094 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2095 | 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] | 2096 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2097 | "or use the exported attribute for this activity. " |
| 2098 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2099 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 2100 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2101 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2102 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 2103 | void startActivityForResultSafely(Intent intent, int requestCode) { |
| 2104 | try { |
| 2105 | startActivityForResult(intent, requestCode); |
| 2106 | } catch (ActivityNotFoundException e) { |
| 2107 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2108 | } catch (SecurityException e) { |
| 2109 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2110 | Log.e(TAG, "Launcher does not have the permission to launch " + intent + |
| 2111 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
| 2112 | "or use the exported attribute for this activity.", e); |
| 2113 | } |
| 2114 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2115 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2116 | private void handleFolderClick(FolderIcon folderIcon) { |
| 2117 | final FolderInfo info = folderIcon.mInfo; |
| 2118 | if (!info.opened) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2119 | // Close any open folder |
| 2120 | closeFolder(); |
| 2121 | // Open the requested folder |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2122 | openFolder(folderIcon); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2123 | } else { |
| 2124 | // Find the open folder... |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2125 | Folder openFolder = mWorkspace.getFolderForTag(info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2126 | int folderScreen; |
| 2127 | if (openFolder != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2128 | folderScreen = mWorkspace.getPageForView(openFolder); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2129 | // .. and close it |
| 2130 | closeFolder(openFolder); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2131 | if (folderScreen != mWorkspace.getCurrentPage()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2132 | // Close any folder open on the current screen |
| 2133 | closeFolder(); |
| 2134 | // Pull the folder onto this screen |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2135 | openFolder(folderIcon); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | } |
| 2140 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2141 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
| 2142 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 2143 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 2144 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 2145 | |
| 2146 | ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY); |
| 2147 | oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); |
| 2148 | oa.start(); |
| 2149 | } |
| 2150 | |
| 2151 | private void shrinkAndFadeInFolderIcon(FolderIcon fi) { |
| 2152 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 2153 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 2154 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 2155 | |
| 2156 | ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY); |
| 2157 | oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); |
| 2158 | oa.start(); |
| 2159 | } |
| 2160 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2161 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 2162 | * 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] | 2163 | * is animated relative to the specified View. If the View is null, no animation |
| 2164 | * is played. |
| 2165 | * |
| 2166 | * @param folderInfo The FolderInfo describing the folder to open. |
| 2167 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2168 | public void openFolder(FolderIcon folderIcon) { |
| 2169 | Folder folder = folderIcon.mFolder; |
| 2170 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2171 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2172 | growAndFadeOutFolderIcon(folderIcon); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2173 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2174 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2175 | mWorkspace.addInFullScreen(folder, info.screen); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 2176 | mDragLayer.setCurrentFolder(folder); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2177 | folder.animateOpen(); |
| 2178 | folder.onOpen(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2179 | } |
| 2180 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2181 | public boolean onLongClick(View v) { |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 2182 | if (mState != State.WORKSPACE) { |
| 2183 | return false; |
| 2184 | } |
| 2185 | |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2186 | switch (v.getId()) { |
| 2187 | case R.id.previous_screen: |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2188 | if (mState != State.ALL_APPS && mState != State.APPS_CUSTOMIZE) { |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2189 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2190 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2191 | showPreviews(v); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2192 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2193 | return true; |
| 2194 | case R.id.next_screen: |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2195 | if (mState != State.ALL_APPS && mState != State.APPS_CUSTOMIZE) { |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2196 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2197 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2198 | showPreviews(v); |
| 2199 | } |
| 2200 | return true; |
| 2201 | case R.id.all_apps_button: |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2202 | if (mState != State.ALL_APPS && mState != State.APPS_CUSTOMIZE) { |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2203 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2204 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 2205 | showPreviews(v); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2206 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2207 | return true; |
| 2208 | } |
| 2209 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2210 | if (isWorkspaceLocked()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2211 | return false; |
| 2212 | } |
| 2213 | |
| 2214 | if (!(v instanceof CellLayout)) { |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 2215 | v = (View) v.getParent().getParent(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2216 | } |
| 2217 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2218 | resetAddInfo(); |
| 2219 | CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2220 | // This happens when long clicking an item with the dpad/trackball |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2221 | if (longClickCellInfo == null || !longClickCellInfo.valid) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2222 | return true; |
| 2223 | } |
| 2224 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2225 | final View itemUnderLongClick = longClickCellInfo.cell; |
| 2226 | |
Winson Chung | 304dcde | 2011-01-07 11:17:23 -0800 | [diff] [blame] | 2227 | if (mWorkspace.allowLongPress() && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2228 | if (itemUnderLongClick == null) { |
| 2229 | // User long pressed on empty space |
| 2230 | mWorkspace.setAllowLongPress(false); |
| 2231 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2232 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame^] | 2233 | addItems(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2234 | } else { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2235 | if (!(itemUnderLongClick instanceof Folder)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2236 | // User long pressed on an item |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2237 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2238 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2239 | mAddIntersectCellX = longClickCellInfo.cellX; |
| 2240 | mAddIntersectCellY = longClickCellInfo.cellY; |
| 2241 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2242 | } |
| 2243 | } |
| 2244 | } |
| 2245 | return true; |
| 2246 | } |
| 2247 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2248 | @SuppressWarnings({"unchecked"}) |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2249 | private void dismissPreview(final View v) { |
| 2250 | final PopupWindow window = (PopupWindow) v.getTag(); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2251 | if (window != null) { |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2252 | window.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 2253 | public void onDismiss() { |
| 2254 | ViewGroup group = (ViewGroup) v.getTag(R.id.workspace); |
| 2255 | int count = group.getChildCount(); |
| 2256 | for (int i = 0; i < count; i++) { |
| 2257 | ((ImageView) group.getChildAt(i)).setImageDrawable(null); |
| 2258 | } |
Michael Jurka | 25913ca | 2011-05-04 17:45:33 -0700 | [diff] [blame] | 2259 | ArrayList<Bitmap> bitmaps = |
| 2260 | (ArrayList<Bitmap>) v.getTag(R.id.all_apps_button_cluster); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2261 | for (Bitmap bitmap : bitmaps) bitmap.recycle(); |
| 2262 | |
| 2263 | v.setTag(R.id.workspace, null); |
Michael Jurka | 25913ca | 2011-05-04 17:45:33 -0700 | [diff] [blame] | 2264 | v.setTag(R.id.all_apps_button_cluster, null); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2265 | window.setOnDismissListener(null); |
| 2266 | } |
| 2267 | }); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2268 | window.dismiss(); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2269 | } |
| 2270 | v.setTag(null); |
| 2271 | } |
| 2272 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2273 | private void showPreviews(View anchor) { |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2274 | showPreviews(anchor, 0, mWorkspace.getChildCount()); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2275 | } |
| 2276 | |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2277 | private void showPreviews(final View anchor, int start, int end) { |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2278 | final Resources resources = getResources(); |
| 2279 | final Workspace workspace = mWorkspace; |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2280 | |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2281 | CellLayout cell = ((CellLayout) workspace.getChildAt(start)); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2282 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2283 | float max = workspace.getChildCount(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2284 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2285 | final Rect r = new Rect(); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2286 | resources.getDrawable(R.drawable.preview_background).getPadding(r); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2287 | int extraW = (int) ((r.left + r.right) * max); |
| 2288 | int extraH = r.top + r.bottom; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2289 | |
| 2290 | int aW = cell.getWidth() - extraW; |
| 2291 | float w = aW / max; |
| 2292 | |
| 2293 | int width = cell.getWidth(); |
| 2294 | int height = cell.getHeight(); |
| 2295 | int x = cell.getLeftPadding(); |
| 2296 | int y = cell.getTopPadding(); |
| 2297 | width -= (x + cell.getRightPadding()); |
| 2298 | height -= (y + cell.getBottomPadding()); |
| 2299 | |
| 2300 | float scale = w / width; |
| 2301 | |
| 2302 | int count = end - start; |
| 2303 | |
| 2304 | final float sWidth = width * scale; |
| 2305 | float sHeight = height * scale; |
| 2306 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2307 | LinearLayout preview = new LinearLayout(this); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2308 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2309 | PreviewTouchHandler handler = new PreviewTouchHandler(anchor); |
| 2310 | ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2311 | |
| 2312 | for (int i = start; i < end; i++) { |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2313 | ImageView image = new ImageView(this); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2314 | cell = (CellLayout) workspace.getChildAt(i); |
| 2315 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2316 | final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2317 | Bitmap.Config.ARGB_8888); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2318 | |
| 2319 | final Canvas c = new Canvas(bitmap); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2320 | c.scale(scale, scale); |
| 2321 | c.translate(-cell.getLeftPadding(), -cell.getTopPadding()); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 2322 | cell.drawChildren(c); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2323 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2324 | image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background)); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2325 | image.setImageBitmap(bitmap); |
| 2326 | image.setTag(i); |
| 2327 | image.setOnClickListener(handler); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2328 | image.setOnFocusChangeListener(handler); |
| 2329 | image.setFocusable(true); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2330 | if (i == mWorkspace.getCurrentPage()) image.requestFocus(); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2331 | |
| 2332 | preview.addView(image, |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2333 | LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 2334 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2335 | bitmaps.add(bitmap); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2336 | } |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2337 | |
| 2338 | final PopupWindow p = new PopupWindow(this); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2339 | p.setContentView(preview); |
| 2340 | p.setWidth((int) (sWidth * count + extraW)); |
| 2341 | p.setHeight((int) (sHeight + extraH)); |
| 2342 | p.setAnimationStyle(R.style.AnimationPreview); |
| 2343 | p.setOutsideTouchable(true); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2344 | p.setFocusable(true); |
Romain Guy | ff0c2e2 | 2009-11-10 12:09:59 -0800 | [diff] [blame] | 2345 | p.setBackgroundDrawable(new ColorDrawable(0)); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2346 | p.showAsDropDown(anchor, 0, 0); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2347 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2348 | p.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 2349 | public void onDismiss() { |
| 2350 | dismissPreview(anchor); |
| 2351 | } |
| 2352 | }); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2353 | |
| 2354 | anchor.setTag(p); |
| 2355 | anchor.setTag(R.id.workspace, preview); |
Michael Jurka | 25913ca | 2011-05-04 17:45:33 -0700 | [diff] [blame] | 2356 | anchor.setTag(R.id.all_apps_button_cluster, bitmaps); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2357 | } |
| 2358 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2359 | class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener { |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2360 | private final View mAnchor; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2361 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2362 | public PreviewTouchHandler(View anchor) { |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2363 | mAnchor = anchor; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | public void onClick(View v) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2367 | mWorkspace.snapToPage((Integer) v.getTag()); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2368 | v.post(this); |
| 2369 | } |
| 2370 | |
| 2371 | public void run() { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2372 | dismissPreview(mAnchor); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | public void onFocusChange(View v, boolean hasFocus) { |
| 2376 | if (hasFocus) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2377 | mWorkspace.snapToPage((Integer) v.getTag()); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2378 | } |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2379 | } |
| 2380 | } |
| 2381 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2382 | Workspace getWorkspace() { |
| 2383 | return mWorkspace; |
| 2384 | } |
| 2385 | |
Michael Jurka | 3c38d56 | 2011-02-18 19:22:12 -0800 | [diff] [blame] | 2386 | TabHost getCustomizationDrawer() { |
| 2387 | return mHomeCustomizationDrawer; |
| 2388 | } |
| 2389 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2390 | @Override |
| 2391 | protected Dialog onCreateDialog(int id) { |
| 2392 | switch (id) { |
| 2393 | case DIALOG_CREATE_SHORTCUT: |
| 2394 | return new CreateShortcut().createDialog(); |
| 2395 | case DIALOG_RENAME_FOLDER: |
| 2396 | return new RenameFolder().createDialog(); |
| 2397 | } |
| 2398 | |
| 2399 | return super.onCreateDialog(id); |
| 2400 | } |
| 2401 | |
| 2402 | @Override |
| 2403 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 2404 | switch (id) { |
| 2405 | case DIALOG_CREATE_SHORTCUT: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2406 | break; |
| 2407 | case DIALOG_RENAME_FOLDER: |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2408 | if (mFolderInfo != null) { |
| 2409 | EditText input = (EditText) dialog.findViewById(R.id.folder_name); |
| 2410 | final CharSequence text = mFolderInfo.title; |
| 2411 | input.setText(text); |
| 2412 | input.setSelection(0, text.length()); |
| 2413 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2414 | break; |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | void showRenameDialog(FolderInfo info) { |
| 2419 | mFolderInfo = info; |
| 2420 | mWaitingForResult = true; |
| 2421 | showDialog(DIALOG_RENAME_FOLDER); |
| 2422 | } |
| 2423 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2424 | private void showAddDialog(int intersectX, int intersectY) { |
| 2425 | resetAddInfo(); |
| 2426 | mAddIntersectCellX = intersectX; |
| 2427 | mAddIntersectCellY = intersectY; |
| 2428 | mAddScreen = mWorkspace.getCurrentPage(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2429 | mWaitingForResult = true; |
| 2430 | showDialog(DIALOG_CREATE_SHORTCUT); |
| 2431 | } |
| 2432 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2433 | private void pickShortcut() { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2434 | // Insert extra item to handle picking application |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2435 | Bundle bundle = new Bundle(); |
| 2436 | |
| 2437 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 2438 | shortcutNames.add(getString(R.string.group_applications)); |
| 2439 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
| 2440 | |
| 2441 | ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>(); |
| 2442 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 2443 | R.drawable.ic_launcher_application)); |
| 2444 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 2445 | |
| 2446 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 2447 | pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT)); |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2448 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut)); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2449 | pickIntent.putExtras(bundle); |
| 2450 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2451 | startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2452 | } |
| 2453 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2454 | private class RenameFolder { |
| 2455 | private EditText mInput; |
| 2456 | |
| 2457 | Dialog createDialog() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2458 | final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null); |
| 2459 | mInput = (EditText) layout.findViewById(R.id.folder_name); |
| 2460 | |
| 2461 | AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 2462 | builder.setIcon(0); |
| 2463 | builder.setTitle(getString(R.string.rename_folder_title)); |
| 2464 | builder.setCancelable(true); |
| 2465 | builder.setOnCancelListener(new Dialog.OnCancelListener() { |
| 2466 | public void onCancel(DialogInterface dialog) { |
| 2467 | cleanup(); |
| 2468 | } |
| 2469 | }); |
| 2470 | builder.setNegativeButton(getString(R.string.cancel_action), |
| 2471 | new Dialog.OnClickListener() { |
| 2472 | public void onClick(DialogInterface dialog, int which) { |
| 2473 | cleanup(); |
| 2474 | } |
| 2475 | } |
| 2476 | ); |
| 2477 | builder.setPositiveButton(getString(R.string.rename_action), |
| 2478 | new Dialog.OnClickListener() { |
| 2479 | public void onClick(DialogInterface dialog, int which) { |
| 2480 | changeFolderName(); |
| 2481 | } |
| 2482 | } |
| 2483 | ); |
| 2484 | builder.setView(layout); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2485 | |
| 2486 | final AlertDialog dialog = builder.create(); |
| 2487 | dialog.setOnShowListener(new DialogInterface.OnShowListener() { |
| 2488 | public void onShow(DialogInterface dialog) { |
Joe Onorato | 7018d8e | 2010-04-13 20:25:47 -0700 | [diff] [blame] | 2489 | mWaitingForResult = true; |
Joe Onorato | d753b42 | 2009-11-08 13:31:11 -0500 | [diff] [blame] | 2490 | mInput.requestFocus(); |
| 2491 | InputMethodManager inputManager = (InputMethodManager) |
| 2492 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 2493 | inputManager.showSoftInput(mInput, 0); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2494 | } |
| 2495 | }); |
| 2496 | |
| 2497 | return dialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | private void changeFolderName() { |
| 2501 | final String name = mInput.getText().toString(); |
| 2502 | if (!TextUtils.isEmpty(name)) { |
| 2503 | // Make sure we have the right folder info |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2504 | mFolderInfo = sFolders.get(mFolderInfo.id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2505 | mFolderInfo.title = name; |
| 2506 | LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo); |
| 2507 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2508 | if (mWorkspaceLoading) { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2509 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2510 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2511 | } else { |
| 2512 | final FolderIcon folderIcon = (FolderIcon) |
| 2513 | mWorkspace.getViewForTag(mFolderInfo); |
| 2514 | if (folderIcon != null) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2515 | // TODO: At some point we'll probably want some version of setting |
| 2516 | // the text for a folder icon. |
| 2517 | //folderIcon.setText(name); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2518 | getWorkspace().requestLayout(); |
| 2519 | } else { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2520 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2521 | mWorkspaceLoading = true; |
| 2522 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2523 | } |
| 2524 | } |
| 2525 | } |
| 2526 | cleanup(); |
| 2527 | } |
| 2528 | |
| 2529 | private void cleanup() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2530 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 2531 | mWaitingForResult = false; |
| 2532 | mFolderInfo = null; |
| 2533 | } |
| 2534 | } |
| 2535 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2536 | // Now a part of LauncherModel.Callbacks. Used to reorder loading steps. |
| 2537 | public boolean isAllAppsVisible() { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2538 | return (mState == State.ALL_APPS) || (mState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2539 | } |
| 2540 | |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2541 | // AllAppsView.Watcher |
| 2542 | public void zoomed(float zoom) { |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 2543 | // In XLarge view, we zoom down the workspace below all apps so it's still visible |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2544 | if (zoom == 1.0f && !LauncherApplication.isScreenLarge()) { |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2545 | mWorkspace.setVisibility(View.GONE); |
| 2546 | } |
| 2547 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2548 | |
Michael Jurka | afca953 | 2011-02-16 14:50:35 -0800 | [diff] [blame] | 2549 | private void showAndEnableToolbarButton(View button) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2550 | button.setVisibility(View.VISIBLE); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | private void hideToolbarButton(View button) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2554 | // We can't set it to GONE, otherwise the RelativeLayout gets screwed up |
| 2555 | button.setVisibility(View.INVISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2556 | button.setAlpha(0.0f); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2559 | /** |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2560 | * Helper function for showing or hiding a toolbar button, possibly animated. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2561 | * |
| 2562 | * @param show If true, create an animation to the show the item. Otherwise, hide it. |
| 2563 | * @param view The toolbar button to be animated |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2564 | * @param seq A AnimatorSet that will be used to animate the transition. If null, the |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2565 | * transition will not be animated. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2566 | */ |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2567 | private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2568 | final boolean showing = show; |
| 2569 | final boolean hiding = !show; |
| 2570 | |
| 2571 | final int duration = show ? |
| 2572 | getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) : |
| 2573 | getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime); |
| 2574 | |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2575 | if (seq != null) { |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 2576 | ValueAnimator anim = ValueAnimator.ofFloat(view.getAlpha(), show ? 1.0f : 0.0f); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 2577 | anim.setDuration(duration); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 2578 | anim.addUpdateListener(new AnimatorUpdateListener() { |
| 2579 | public void onAnimationUpdate(ValueAnimator animation) { |
| 2580 | view.setAlpha((Float) animation.getAnimatedValue()); |
| 2581 | } |
| 2582 | }); |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2583 | anim.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2584 | @Override |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2585 | public void onAnimationStart(Animator animation) { |
Michael Jurka | afca953 | 2011-02-16 14:50:35 -0800 | [diff] [blame] | 2586 | if (showing) showAndEnableToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2587 | } |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2588 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2589 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2590 | if (hiding) hideToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2591 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2592 | }); |
| 2593 | seq.play(anim); |
| 2594 | } else { |
| 2595 | if (showing) { |
Michael Jurka | afca953 | 2011-02-16 14:50:35 -0800 | [diff] [blame] | 2596 | showAndEnableToolbarButton(view); |
Michael Jurka | ea57348 | 2011-02-03 19:48:18 -0800 | [diff] [blame] | 2597 | view.setAlpha(1f); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2598 | } else { |
| 2599 | hideToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2600 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2601 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | /** |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2605 | * Show/hide the appropriate toolbar buttons for newState. |
| 2606 | * If showSeq or hideSeq is null, the transition will be done immediately (not animated). |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2607 | * |
| 2608 | * @param newState The state that is being switched to |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2609 | * @param showSeq AnimatorSet in which to put "show" animations, or null. |
| 2610 | * @param hideSeq AnimatorSet in which to put "hide" animations, or null. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2611 | */ |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2612 | private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2613 | switch (newState) { |
| 2614 | case WORKSPACE: |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 2615 | hideOrShowToolbarButton(true, mButtonCluster, showSeq); |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 2616 | mDeleteZone.setDragAndDropEnabled(true); |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2617 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2618 | mDeleteZone.setText(getResources().getString(R.string.delete_zone_label_workspace)); |
| 2619 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2620 | break; |
| 2621 | case ALL_APPS: |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2622 | case APPS_CUSTOMIZE: |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 2623 | hideOrShowToolbarButton(false, mButtonCluster, hideSeq); |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 2624 | mDeleteZone.setDragAndDropEnabled(false); |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2625 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2626 | mDeleteZone.setText(getResources().getString(R.string.delete_zone_label_all_apps)); |
| 2627 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2628 | break; |
| 2629 | case CUSTOMIZE: |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 2630 | hideOrShowToolbarButton(false, mButtonCluster, hideSeq); |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 2631 | mDeleteZone.setDragAndDropEnabled(false); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2632 | break; |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | /** |
| 2637 | * Helper method for the cameraZoomIn/cameraZoomOut animations |
| 2638 | * @param view The view being animated |
| 2639 | * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE |
| 2640 | * @param scaleFactor The scale factor used for the zoom |
| 2641 | */ |
| 2642 | private void setPivotsForZoom(View view, State state, float scaleFactor) { |
| 2643 | final int height = view.getHeight(); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2644 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2645 | view.setPivotX(view.getWidth() / 2.0f); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2646 | // Set pivotY so that at the starting zoom factor, the view is partially |
| 2647 | // visible. Modifying initialHeightFactor changes how much of the view is |
| 2648 | // initially showing, and hence the perceived angle from which the view enters. |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2649 | if (state == State.ALL_APPS || state == State.APPS_CUSTOMIZE) { |
Michael Jurka | ea57348 | 2011-02-03 19:48:18 -0800 | [diff] [blame] | 2650 | final float initialHeightFactor = 0.175f; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2651 | view.setPivotY((1 - initialHeightFactor) * height); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2652 | } else { |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2653 | final float initialHeightFactor = 0.2f; |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2654 | view.setPivotY(-initialHeightFactor * height); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2655 | } |
| 2656 | } |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2657 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2658 | /** |
| 2659 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 2660 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 2661 | * of the screen. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2662 | * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2663 | */ |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 2664 | private void cameraZoomOut(State toState, boolean animated, boolean springLoaded) { |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2665 | final Resources res = getResources(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2666 | final boolean toAllApps = (toState == State.ALL_APPS) |
| 2667 | || (toState == State.APPS_CUSTOMIZE); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2668 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2669 | final int duration = (toAllApps ? |
| 2670 | res.getInteger(R.integer.config_appsCustomizeZoomInTime) : |
| 2671 | res.getInteger(R.integer.config_customizeZoomInTime)); |
| 2672 | final int fadeDuration = (toAllApps ? |
| 2673 | res.getInteger(R.integer.config_appsCustomizeFadeInTime) : |
| 2674 | res.getInteger(R.integer.config_customizeFadeInTime)); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2675 | |
| 2676 | final float scale = toAllApps ? |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2677 | (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor) : |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2678 | (float) res.getInteger(R.integer.config_customizeZoomScaleFactor); |
| 2679 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2680 | View tmpView; |
| 2681 | if (toAllApps) { |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2682 | tmpView = (LauncherApplication.isScreenLarge()) |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2683 | ? (View) mAllAppsGrid : mAppsCustomizeTabHost; |
| 2684 | } else { |
| 2685 | tmpView = mHomeCustomizationDrawer; |
| 2686 | } |
| 2687 | final View toView = tmpView; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2688 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2689 | setPivotsForZoom(toView, toState, scale); |
| 2690 | |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2691 | if (toAllApps) { |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 2692 | if (!springLoaded) { |
| 2693 | mWorkspace.shrink(ShrinkState.BOTTOM_HIDDEN, animated); |
| 2694 | |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2695 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2696 | // Everytime we launch into AllApps, we reset the successful drop flag which |
| 2697 | // controls when it should hide/show the mini workspaces |
| 2698 | mAllAppsPagedView.resetSuccessfulDropFlag(); |
| 2699 | } |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 2700 | } else { |
| 2701 | mWorkspace.shrink(ShrinkState.BOTTOM_VISIBLE, animated); |
| 2702 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2703 | } else { |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2704 | mWorkspace.shrink(ShrinkState.TOP, animated); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2705 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2706 | |
| 2707 | if (animated) { |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2708 | final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration); |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 2709 | scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator()); |
Michael Jurka | c2e26a0 | 2011-03-24 15:20:26 -0700 | [diff] [blame] | 2710 | scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 2711 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 2712 | ((View) toView.getParent()).fastInvalidate(); |
Michael Jurka | 11148e5 | 2011-02-03 18:20:25 -0800 | [diff] [blame] | 2713 | toView.setFastScaleX(a * scale + b * 1f); |
| 2714 | toView.setFastScaleY(a * scale + b * 1f); |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 2715 | } |
| 2716 | }); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2717 | |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2718 | if (toAllApps) { |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 2719 | toView.setVisibility(View.VISIBLE); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 2720 | toView.setFastAlpha(0f); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 2721 | ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration); |
Michael Jurka | ea57348 | 2011-02-03 19:48:18 -0800 | [diff] [blame] | 2722 | alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); |
Michael Jurka | c2e26a0 | 2011-03-24 15:20:26 -0700 | [diff] [blame] | 2723 | alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 2724 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 2725 | // don't need to invalidate because we do so above |
| 2726 | toView.setFastAlpha(a * 0f + b * 1f); |
| 2727 | } |
| 2728 | }); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2729 | alphaAnim.start(); |
| 2730 | } |
| 2731 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2732 | if (toView instanceof LauncherTransitionable) { |
| 2733 | ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim); |
Michael Jurka | bfadaad | 2011-01-31 21:35:39 -0800 | [diff] [blame] | 2734 | } |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2735 | scaleAnim.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2736 | @Override |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2737 | public void onAnimationStart(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2738 | // Prepare the position |
| 2739 | toView.setTranslationX(0.0f); |
| 2740 | toView.setTranslationY(0.0f); |
| 2741 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2742 | toView.bringToFront(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2743 | if (!toAllApps) { |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 2744 | toView.setFastAlpha(1.0f); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2745 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2746 | } |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2747 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2748 | public void onAnimationEnd(Animator animation) { |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2749 | // If we don't set the final scale values here, if this animation is cancelled |
| 2750 | // it will have the wrong scale value and subsequent cameraPan animations will |
| 2751 | // not fix that |
| 2752 | toView.setScaleX(1.0f); |
| 2753 | toView.setScaleY(1.0f); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2754 | if (toView instanceof LauncherTransitionable) { |
| 2755 | ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 2756 | } |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2757 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2758 | }); |
| 2759 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2760 | AnimatorSet toolbarHideAnim = new AnimatorSet(); |
| 2761 | AnimatorSet toolbarShowAnim = new AnimatorSet(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2762 | hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim); |
| 2763 | |
| 2764 | // toView should appear right at the end of the workspace shrink animation |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2765 | final int startDelay = 0; |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2766 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2767 | if (mStateAnimation != null) mStateAnimation.cancel(); |
| 2768 | mStateAnimation = new AnimatorSet(); |
| 2769 | mStateAnimation.playTogether(scaleAnim, toolbarHideAnim); |
| 2770 | mStateAnimation.play(scaleAnim).after(startDelay); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2771 | |
| 2772 | // Show the new toolbar buttons just as the main animation is ending |
| 2773 | final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2774 | mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime); |
| 2775 | mStateAnimation.start(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2776 | } else { |
| 2777 | toView.setTranslationX(0.0f); |
| 2778 | toView.setTranslationY(0.0f); |
| 2779 | toView.setScaleX(1.0f); |
| 2780 | toView.setScaleY(1.0f); |
| 2781 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2782 | toView.bringToFront(); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2783 | if (toView instanceof LauncherTransitionable) { |
| 2784 | ((LauncherTransitionable) toView).onLauncherTransitionStart(null); |
| 2785 | ((LauncherTransitionable) toView).onLauncherTransitionEnd(null); |
| 2786 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2787 | hideAndShowToolbarButtons(toState, null, null); |
| 2788 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | /** |
| 2792 | * Zoom the camera back into the workspace, hiding 'fromView'. |
| 2793 | * This is the opposite of cameraZoomOut. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2794 | * @param fromState The current state (must be ALL_APPS or CUSTOMIZE). |
| 2795 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2796 | */ |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2797 | private void cameraZoomIn(State fromState, boolean animated, boolean springLoaded) { |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2798 | Resources res = getResources(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2799 | final boolean fromAllApps = (fromState == State.ALL_APPS) |
| 2800 | || (fromState == State.APPS_CUSTOMIZE); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2801 | |
| 2802 | int duration = fromAllApps ? |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2803 | res.getInteger(R.integer.config_appsCustomizeZoomOutTime) : |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2804 | res.getInteger(R.integer.config_customizeZoomOutTime); |
| 2805 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 2806 | final float scaleFactor = fromAllApps ? |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2807 | (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor) : |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2808 | (float) res.getInteger(R.integer.config_customizeZoomScaleFactor); |
| 2809 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2810 | View tmpView; |
| 2811 | if (fromAllApps) { |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2812 | tmpView = (LauncherApplication.isScreenLarge()) |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2813 | ? (View) mAllAppsGrid : mAppsCustomizeTabHost; |
| 2814 | } else { |
| 2815 | tmpView = mHomeCustomizationDrawer; |
| 2816 | } |
| 2817 | final View fromView = tmpView; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2818 | |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2819 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2820 | mCustomizePagedView.endChoiceMode(); |
| 2821 | mAllAppsPagedView.endChoiceMode(); |
| 2822 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2823 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2824 | setPivotsForZoom(fromView, fromState, scaleFactor); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2825 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2826 | if (!springLoaded) { |
| 2827 | mWorkspace.unshrink(animated); |
| 2828 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2829 | if (animated) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2830 | if (mStateAnimation != null) mStateAnimation.cancel(); |
| 2831 | mStateAnimation = new AnimatorSet(); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2832 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 2833 | final float oldScaleX = fromView.getScaleX(); |
| 2834 | final float oldScaleY = fromView.getScaleY(); |
| 2835 | |
| 2836 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration); |
| 2837 | scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator()); |
Michael Jurka | c2e26a0 | 2011-03-24 15:20:26 -0700 | [diff] [blame] | 2838 | scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 2839 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 2840 | ((View)fromView.getParent()).fastInvalidate(); |
| 2841 | fromView.setFastScaleX(a * oldScaleX + b * scaleFactor); |
| 2842 | fromView.setFastScaleY(a * oldScaleY + b * scaleFactor); |
| 2843 | } |
| 2844 | }); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2845 | final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2846 | alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime)); |
Michael Jurka | ea57348 | 2011-02-03 19:48:18 -0800 | [diff] [blame] | 2847 | alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); |
Michael Jurka | c2e26a0 | 2011-03-24 15:20:26 -0700 | [diff] [blame] | 2848 | alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 2849 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 2850 | // don't need to invalidate because we do so above |
| 2851 | fromView.setFastAlpha(a * 1f + b * 0f); |
| 2852 | } |
| 2853 | }); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2854 | if (fromView instanceof LauncherTransitionable) { |
| 2855 | ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 2856 | } |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2857 | alphaAnim.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2858 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2859 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2860 | fromView.setVisibility(View.GONE); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2861 | if (fromView instanceof LauncherTransitionable) { |
| 2862 | ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 2863 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2864 | } |
| 2865 | }); |
| 2866 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2867 | AnimatorSet toolbarHideAnim = new AnimatorSet(); |
| 2868 | AnimatorSet toolbarShowAnim = new AnimatorSet(); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2869 | if (!springLoaded) { |
| 2870 | hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim); |
| 2871 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2872 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2873 | mStateAnimation.playTogether(scaleAnim, toolbarHideAnim, alphaAnim); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2874 | |
| 2875 | // Show the new toolbar buttons at the very end of the whole animation |
| 2876 | final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); |
| 2877 | final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime); |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2878 | mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime); |
| 2879 | mStateAnimation.start(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2880 | } else { |
| 2881 | fromView.setVisibility(View.GONE); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2882 | if (fromView instanceof LauncherTransitionable) { |
| 2883 | ((LauncherTransitionable) fromView).onLauncherTransitionStart(null); |
| 2884 | ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null); |
| 2885 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2886 | if (!springLoaded) { |
| 2887 | hideAndShowToolbarButtons(State.WORKSPACE, null, null); |
| 2888 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2889 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2890 | } |
| 2891 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2892 | void showWorkspace(boolean animated) { |
| 2893 | showWorkspace(animated, null); |
| 2894 | } |
| 2895 | |
| 2896 | void showWorkspace(boolean animated, CellLayout layout) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2897 | if (layout != null) { |
| 2898 | // always animated, but that's ok since we never specify a layout and |
| 2899 | // want no animation |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2900 | mWorkspace.unshrink(layout); |
| 2901 | } else { |
| 2902 | mWorkspace.unshrink(animated); |
| 2903 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2904 | if (mState == State.ALL_APPS || mState == State.APPS_CUSTOMIZE) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2905 | closeAllApps(animated); |
| 2906 | } else if (mState == State.CUSTOMIZE) { |
| 2907 | hideCustomizationDrawer(animated); |
| 2908 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 2909 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2910 | // Change the state *after* we've called all the transition code |
| 2911 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 2912 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 2913 | // Resume the auto-advance of widgets |
| 2914 | mUserPresent = true; |
| 2915 | updateRunning(); |
| 2916 | |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 2917 | // send an accessibility event to announce the context change |
| 2918 | getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2919 | } |
| 2920 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2921 | void enterSpringLoadedDragMode(CellLayout layout) { |
| 2922 | mWorkspace.enterSpringLoadedDragMode(layout); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2923 | if (mState == State.ALL_APPS || mState == State.APPS_CUSTOMIZE) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2924 | mState = State.ALL_APPS_SPRING_LOADED; |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2925 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2926 | cameraZoomIn(State.ALL_APPS, true, true); |
| 2927 | } else { |
| 2928 | cameraZoomIn(State.APPS_CUSTOMIZE, true, true); |
| 2929 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2930 | } else if (mState == State.CUSTOMIZE) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2931 | mState = State.CUSTOMIZE_SPRING_LOADED; |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 2932 | cameraZoomIn(State.CUSTOMIZE, true, true); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2933 | }/* else { |
| 2934 | // we're already in spring loaded mode; don't do anything |
| 2935 | }*/ |
| 2936 | } |
| 2937 | |
| 2938 | void exitSpringLoadedDragMode() { |
| 2939 | if (mState == State.ALL_APPS_SPRING_LOADED) { |
| 2940 | mWorkspace.exitSpringLoadedDragMode(Workspace.ShrinkState.BOTTOM_VISIBLE); |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2941 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2942 | cameraZoomOut(State.ALL_APPS, true, true); |
| 2943 | mState = State.ALL_APPS; |
| 2944 | } else { |
| 2945 | cameraZoomOut(State.APPS_CUSTOMIZE, true, true); |
| 2946 | mState = State.APPS_CUSTOMIZE; |
| 2947 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2948 | } else if (mState == State.CUSTOMIZE_SPRING_LOADED) { |
| 2949 | mWorkspace.exitSpringLoadedDragMode(Workspace.ShrinkState.TOP); |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 2950 | cameraZoomOut(State.CUSTOMIZE, true, true); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2951 | mState = State.CUSTOMIZE; |
| 2952 | }/* else { |
| 2953 | // we're not in spring loaded mode; don't do anything |
| 2954 | }*/ |
| 2955 | } |
| 2956 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2957 | void showAllApps(boolean animated) { |
| 2958 | if (mState != State.WORKSPACE) return; |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 2959 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2960 | cameraZoomOut(State.ALL_APPS, animated, false); |
| 2961 | ((View) mAllAppsGrid).requestFocus(); |
| 2962 | |
| 2963 | // TODO: fade these two too |
| 2964 | mDeleteZone.setVisibility(View.GONE); |
| 2965 | |
| 2966 | // Change the state *after* we've called all the transition code |
| 2967 | mState = State.ALL_APPS; |
| 2968 | } else { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2969 | cameraZoomOut(State.APPS_CUSTOMIZE, animated, false); |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame^] | 2970 | mAppsCustomizeTabHost.requestFocus(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2971 | |
| 2972 | // Change the state *after* we've called all the transition code |
| 2973 | mState = State.APPS_CUSTOMIZE; |
| 2974 | } |
| 2975 | |
| 2976 | // Pause the auto-advance of widgets until we are out of AllApps |
| 2977 | mUserPresent = false; |
| 2978 | updateRunning(); |
| 2979 | |
| 2980 | // Send an accessibility event to announce the context change |
| 2981 | getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
| 2982 | } |
| 2983 | |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2984 | /** |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2985 | * Things to test when changing this code. |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2986 | * - Home from workspace |
| 2987 | * - from center screen |
| 2988 | * - from other screens |
| 2989 | * - Home from all apps |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2990 | * - from center screen |
| 2991 | * - from other screens |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2992 | * - Back from all apps |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2993 | * - from center screen |
| 2994 | * - from other screens |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2995 | * - Launch app from workspace and quit |
| 2996 | * - with back |
| 2997 | * - with home |
| 2998 | * - Launch app from all apps and quit |
| 2999 | * - with back |
| 3000 | * - with home |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 3001 | * - Go to a screen that's not the default, then all |
| 3002 | * apps, and launch and app, and go back |
| 3003 | * - with back |
| 3004 | * -with home |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 3005 | * - On workspace, long press power and go back |
| 3006 | * - with back |
| 3007 | * - with home |
| 3008 | * - On all apps, long press power and go back |
| 3009 | * - with back |
| 3010 | * - with home |
| 3011 | * - On workspace, power off |
| 3012 | * - On all apps, power off |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 3013 | * - Launch an app and turn off the screen while in that app |
| 3014 | * - Go back with home key |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 3015 | * - Go back with back key TODO: make this not go to workspace |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 3016 | * - From all apps |
| 3017 | * - From workspace |
Joe Onorato | effc4a8 | 2010-04-15 11:48:13 -0700 | [diff] [blame] | 3018 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 3019 | * - From all apps |
| 3020 | * - From the center workspace |
| 3021 | * - From another workspace |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 3022 | */ |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 3023 | void closeAllApps(boolean animated) { |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 3024 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3025 | if (mState == State.ALL_APPS || mState == State.ALL_APPS_SPRING_LOADED) { |
| 3026 | mWorkspace.setVisibility(View.VISIBLE); |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 3027 | cameraZoomIn(State.ALL_APPS, animated, false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3028 | |
| 3029 | // Set focus to the AllApps button |
| 3030 | findViewById(R.id.all_apps_button).requestFocus(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3031 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3032 | } else { |
| 3033 | if (mState == State.APPS_CUSTOMIZE || mState == State.ALL_APPS_SPRING_LOADED) { |
| 3034 | mWorkspace.setVisibility(View.VISIBLE); |
| 3035 | cameraZoomIn(State.APPS_CUSTOMIZE, animated, false); |
| 3036 | |
| 3037 | // Set focus to the AllApps button |
| 3038 | findViewById(R.id.all_apps_button).requestFocus(); |
| 3039 | } |
Joe Onorato | e77c08d | 2009-08-01 00:01:20 -0700 | [diff] [blame] | 3040 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 3043 | void lockAllApps() { |
| 3044 | // TODO |
| 3045 | } |
| 3046 | |
| 3047 | void unlockAllApps() { |
| 3048 | // TODO |
| 3049 | } |
| 3050 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3051 | // Show the customization drawer (only exists in x-large configuration) |
| 3052 | private void showCustomizationDrawer(boolean animated) { |
Michael Jurka | afca953 | 2011-02-16 14:50:35 -0800 | [diff] [blame] | 3053 | if (mState != State.WORKSPACE) { |
| 3054 | return; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3055 | } |
Michael Jurka | afca953 | 2011-02-16 14:50:35 -0800 | [diff] [blame] | 3056 | |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 3057 | cameraZoomOut(State.CUSTOMIZE, animated, false); |
Michael Jurka | afca953 | 2011-02-16 14:50:35 -0800 | [diff] [blame] | 3058 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3059 | // Change the state *after* we've called all the transition code |
| 3060 | mState = State.CUSTOMIZE; |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 3061 | |
| 3062 | // Pause the auto-advance of widgets until we are out of Customization drawer |
| 3063 | mUserPresent = false; |
| 3064 | updateRunning(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 3067 | // Hide the customization drawer (only exists in x-large configuration) |
| 3068 | void hideCustomizationDrawer(boolean animated) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3069 | if (mState == State.CUSTOMIZE || mState == State.CUSTOMIZE_SPRING_LOADED) { |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 3070 | cameraZoomIn(State.CUSTOMIZE, animated, false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3071 | |
| 3072 | // Set focus to the customize button |
| 3073 | findViewById(R.id.configure_button).requestFocus(); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3077 | /** |
| 3078 | * Add an item from all apps or customize onto the given workspace screen. |
| 3079 | * If layout is null, add to the current screen. |
| 3080 | */ |
| 3081 | void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3082 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
| 3083 | showOutOfSpaceMessage(); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3084 | } else { |
| 3085 | layout.animateDrop(); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 3086 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3087 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3088 | |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 3089 | void onWorkspaceClick(CellLayout layout) { |
| 3090 | showWorkspace(true, layout); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 3091 | } |
| 3092 | |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3093 | private Drawable getExternalPackageToolbarIcon(ComponentName activityName) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3094 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3095 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3096 | // Look for the toolbar icon specified in the activity meta-data |
| 3097 | Bundle metaData = packageManager.getActivityInfo( |
| 3098 | activityName, PackageManager.GET_META_DATA).metaData; |
| 3099 | if (metaData != null) { |
| 3100 | int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME); |
| 3101 | if (iconResId != 0) { |
| 3102 | Resources res = packageManager.getResourcesForActivity(activityName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3103 | return res.getDrawable(iconResId); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | } catch (NameNotFoundException e) { |
| 3107 | // Do nothing |
| 3108 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3109 | return null; |
| 3110 | } |
| 3111 | |
| 3112 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3113 | private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( |
| 3114 | int buttonId, ComponentName activityName, int fallbackDrawableId) { |
| 3115 | TextView button = (TextView) findViewById(buttonId); |
| 3116 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName); |
| 3117 | |
| 3118 | // If we were unable to find the icon via the meta-data, use a generic one |
| 3119 | if (toolbarIcon == null) { |
| 3120 | button.setCompoundDrawablesWithIntrinsicBounds(fallbackDrawableId, 0, 0, 0); |
| 3121 | return null; |
| 3122 | } else { |
| 3123 | button.setCompoundDrawablesWithIntrinsicBounds(toolbarIcon, null, null, null); |
| 3124 | return toolbarIcon.getConstantState(); |
| 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 3129 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
| 3130 | int buttonId, ComponentName activityName, int fallbackDrawableId) { |
| 3131 | ImageView button = (ImageView) findViewById(buttonId); |
| 3132 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName); |
| 3133 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3134 | // If we were unable to find the icon via the meta-data, use a generic one |
| 3135 | if (toolbarIcon == null) { |
| 3136 | button.setImageResource(fallbackDrawableId); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3137 | return null; |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3138 | } else { |
| 3139 | button.setImageDrawable(toolbarIcon); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3140 | return toolbarIcon.getConstantState(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3141 | } |
| 3142 | } |
| 3143 | |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3144 | private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
| 3145 | TextView button = (TextView) findViewById(buttonId); |
| 3146 | button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null); |
| 3147 | } |
| 3148 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3149 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3150 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3151 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3152 | } |
| 3153 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3154 | private void updateGlobalSearchIcon() { |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 3155 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3156 | final View searchButton = findViewById(R.id.search_button); |
| 3157 | final View searchDivider = findViewById(R.id.search_divider); |
| 3158 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3159 | final SearchManager searchManager = |
| 3160 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3161 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3162 | if (activityName != null) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3163 | sGlobalSearchIcon = updateButtonWithIconFromExternalActivity( |
Michael Jurka | 789744f | 2011-01-25 18:41:55 -0800 | [diff] [blame] | 3164 | R.id.search_button, activityName, R.drawable.ic_generic_search); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3165 | searchButton.setVisibility(View.VISIBLE); |
| 3166 | searchDivider.setVisibility(View.VISIBLE); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3167 | } else { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3168 | searchButton.setVisibility(View.GONE); |
| 3169 | searchDivider.setVisibility(View.GONE); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3170 | } |
| 3171 | } |
| 3172 | } |
| 3173 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3174 | private void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3175 | updateButtonWithDrawable(R.id.search_button, d); |
| 3176 | } |
| 3177 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3178 | private void updateVoiceSearchIcon() { |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 3179 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3180 | final View searchDivider = findViewById(R.id.search_divider); |
| 3181 | final View voiceButton = findViewById(R.id.voice_button); |
| 3182 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3183 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3184 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
| 3185 | if (activityName != null) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3186 | sVoiceSearchIcon = updateButtonWithIconFromExternalActivity( |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3187 | R.id.voice_button, activityName, R.drawable.ic_voice_search); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3188 | searchDivider.setVisibility(View.VISIBLE); |
| 3189 | voiceButton.setVisibility(View.VISIBLE); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3190 | } else { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 3191 | searchDivider.setVisibility(View.GONE); |
| 3192 | voiceButton.setVisibility(View.GONE); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3193 | } |
| 3194 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3195 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3196 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3197 | private void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3198 | updateButtonWithDrawable(R.id.voice_button, d); |
| 3199 | } |
| 3200 | |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3201 | /** |
| 3202 | * Sets the app market icon (shown when all apps is visible on x-large screens) |
| 3203 | */ |
| 3204 | private void updateAppMarketIcon() { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3205 | final View marketButton = findViewById(R.id.market_button); |
| 3206 | Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); |
| 3207 | // Find the app market activity by resolving an intent. |
| 3208 | // (If multiple app markets are installed, it will return the ResolverActivity.) |
| 3209 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
Winson Chung | 4c5ac59 | 2011-05-23 14:38:58 -0700 | [diff] [blame] | 3210 | if (activityName != null && LauncherApplication.isScreenLarge()) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3211 | mAppMarketIntent = intent; |
| 3212 | sAppMarketIcon = updateTextButtonWithIconFromExternalActivity( |
| 3213 | R.id.market_button, activityName, R.drawable.app_market_generic); |
| 3214 | marketButton.setVisibility(View.VISIBLE); |
| 3215 | } else { |
| 3216 | // We should hide and disable the view so that we don't try and restore the visibility |
| 3217 | // of it when we swap between drag & normal states from IconDropTarget subclasses. |
| 3218 | marketButton.setVisibility(View.GONE); |
| 3219 | marketButton.setEnabled(false); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3220 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3223 | private void updateAppMarketIcon(Drawable.ConstantState d) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 3224 | updateTextButtonWithDrawable(R.id.market_button, d); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3225 | } |
| 3226 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3227 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3228 | * Displays the shortcut creation dialog and launches, if necessary, the |
| 3229 | * appropriate activity. |
| 3230 | */ |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3231 | private class CreateShortcut implements DialogInterface.OnClickListener, |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 3232 | DialogInterface.OnCancelListener, DialogInterface.OnDismissListener, |
| 3233 | DialogInterface.OnShowListener { |
| 3234 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3235 | private AddAdapter mAdapter; |
Romain Guy | 9ffb543 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 3236 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3237 | Dialog createDialog() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3238 | mAdapter = new AddAdapter(Launcher.this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3239 | |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame^] | 3240 | final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this, |
| 3241 | AlertDialog.THEME_HOLO_DARK); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3242 | builder.setTitle(getString(R.string.menu_item_add_item)); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3243 | builder.setAdapter(mAdapter, this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3244 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3245 | AlertDialog dialog = builder.create(); |
| 3246 | dialog.setOnCancelListener(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3247 | dialog.setOnDismissListener(this); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 3248 | dialog.setOnShowListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3249 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3250 | return dialog; |
| 3251 | } |
| 3252 | |
| 3253 | public void onCancel(DialogInterface dialog) { |
| 3254 | mWaitingForResult = false; |
| 3255 | cleanup(); |
| 3256 | } |
| 3257 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3258 | public void onDismiss(DialogInterface dialog) { |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame^] | 3259 | mWaitingForResult = false; |
| 3260 | cleanup(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3261 | } |
| 3262 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3263 | private void cleanup() { |
Joe Onorato | cc19a53 | 2009-11-19 14:19:17 -0800 | [diff] [blame] | 3264 | try { |
| 3265 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 3266 | } catch (Exception e) { |
| 3267 | // An exception is thrown if the dialog is not visible, which is fine |
| 3268 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3269 | } |
| 3270 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3271 | /** |
| 3272 | * Handle the action clicked in the "Add to home" dialog. |
| 3273 | */ |
| 3274 | public void onClick(DialogInterface dialog, int which) { |
| 3275 | Resources res = getResources(); |
| 3276 | cleanup(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3277 | |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame^] | 3278 | AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which); |
| 3279 | switch (item.actionTag) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3280 | case AddAdapter.ITEM_SHORTCUT: { |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 3281 | pickShortcut(); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3282 | break; |
| 3283 | } |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame^] | 3284 | case AddAdapter.ITEM_APPLICATION: { |
| 3285 | if (mAppsCustomizeTabHost != null) { |
| 3286 | mAppsCustomizeTabHost.selectAppsTab(); |
| 3287 | } |
| 3288 | showAllApps(true); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3289 | break; |
| 3290 | } |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame^] | 3291 | case AddAdapter.ITEM_APPWIDGET: { |
| 3292 | if (mAppsCustomizeTabHost != null) { |
| 3293 | mAppsCustomizeTabHost.selectWidgetsTab(); |
| 3294 | } |
| 3295 | showAllApps(true); |
| 3296 | break; |
| 3297 | } |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3298 | case AddAdapter.ITEM_WALLPAPER: { |
| 3299 | startWallpaper(); |
| 3300 | break; |
| 3301 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3302 | } |
| 3303 | } |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 3304 | |
| 3305 | public void onShow(DialogInterface dialog) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3306 | mWaitingForResult = true; |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 3307 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | /** |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3311 | * Receives notifications when applications are added/removed. |
| 3312 | */ |
| 3313 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 3314 | @Override |
| 3315 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3316 | closeSystemDialogs(); |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 3317 | String reason = intent.getStringExtra("reason"); |
| 3318 | if (!"homekey".equals(reason)) { |
| 3319 | boolean animate = true; |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 3320 | if (mPaused || "lock".equals(reason)) { |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 3321 | animate = false; |
| 3322 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3323 | showWorkspace(animate); |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 3324 | } |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 3329 | * Receives notifications whenever the appwidgets are reset. |
| 3330 | */ |
| 3331 | private class AppWidgetResetObserver extends ContentObserver { |
| 3332 | public AppWidgetResetObserver() { |
| 3333 | super(new Handler()); |
| 3334 | } |
| 3335 | |
| 3336 | @Override |
| 3337 | public void onChange(boolean selfChange) { |
| 3338 | onAppWidgetReset(); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3343 | * If the activity is currently paused, signal that we need to re-run the loader |
| 3344 | * in onResume. |
| 3345 | * |
| 3346 | * This needs to be called from incoming places where resources might have been loaded |
| 3347 | * while we are paused. That is becaues the Configuration might be wrong |
| 3348 | * when we're not running, and if it comes back to what it was when we |
| 3349 | * were paused, we are not restarted. |
| 3350 | * |
| 3351 | * Implementation of the method from LauncherModel.Callbacks. |
| 3352 | * |
| 3353 | * @return true if we are currently paused. The caller might be able to |
| 3354 | * skip some work in that case since we will come back again. |
| 3355 | */ |
| 3356 | public boolean setLoadOnResume() { |
| 3357 | if (mPaused) { |
| 3358 | Log.i(TAG, "setLoadOnResume"); |
| 3359 | mOnResumeNeedsLoad = true; |
| 3360 | return true; |
| 3361 | } else { |
| 3362 | return false; |
| 3363 | } |
| 3364 | } |
| 3365 | |
| 3366 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3367 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3368 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3369 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3370 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3371 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3372 | } else { |
| 3373 | return SCREEN_COUNT / 2; |
| 3374 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3375 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3376 | |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 3377 | void setAllAppsPagedView(AllAppsPagedView view) { |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3378 | mAllAppsPagedView = view; |
| 3379 | } |
| 3380 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3381 | /** |
| 3382 | * Refreshes the shortcuts shown on the workspace. |
| 3383 | * |
| 3384 | * Implementation of the method from LauncherModel.Callbacks. |
| 3385 | */ |
| 3386 | public void startBinding() { |
| 3387 | final Workspace workspace = mWorkspace; |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3388 | |
| 3389 | mWorkspace.clearDropTargets(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3390 | int count = workspace.getChildCount(); |
| 3391 | for (int i = 0; i < count; i++) { |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 3392 | // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate(). |
Winson Chung | 7a25a9e | 2011-01-30 13:33:56 -0800 | [diff] [blame] | 3393 | final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i); |
| 3394 | layoutParent.removeAllViewsInLayout(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3395 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3396 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3397 | if (DEBUG_USER_INTERFACE) { |
| 3398 | android.widget.Button finishButton = new android.widget.Button(this); |
| 3399 | finishButton.setText("Finish"); |
| 3400 | workspace.addInScreen(finishButton, 1, 0, 0, 1, 1); |
| 3401 | |
| 3402 | finishButton.setOnClickListener(new android.widget.Button.OnClickListener() { |
| 3403 | public void onClick(View v) { |
| 3404 | finish(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3405 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3406 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3407 | } |
Adam Cohen | f5d77c9 | 2011-02-03 12:55:38 -0800 | [diff] [blame] | 3408 | |
| 3409 | // This wasn't being called before which resulted in a leak of AppWidgetHostViews (through |
| 3410 | // mDesktopItems -> AppWidgetInfo -> hostView). |
| 3411 | unbindDesktopItems(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3415 | * Bind the items start-end from the list. |
| 3416 | * |
| 3417 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3418 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3419 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { |
| 3420 | |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3421 | setLoadOnResume(); |
| 3422 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3423 | final Workspace workspace = mWorkspace; |
| 3424 | |
| 3425 | for (int i=start; i<end; i++) { |
| 3426 | final ItemInfo item = shortcuts.get(i); |
| 3427 | mDesktopItems.add(item); |
| 3428 | switch (item.itemType) { |
| 3429 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 3430 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3431 | final View shortcut = createShortcut((ShortcutInfo)item); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3432 | workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, |
| 3433 | false); |
| 3434 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3435 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3436 | final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3437 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3438 | (FolderInfo) item, mIconCache); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3439 | workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 3440 | false); |
| 3441 | break; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3442 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3443 | } |
| 3444 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3445 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3446 | } |
| 3447 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3448 | /** |
| 3449 | * Implementation of the method from LauncherModel.Callbacks. |
| 3450 | */ |
Joe Onorato | ad72e17 | 2009-11-06 16:25:04 -0500 | [diff] [blame] | 3451 | public void bindFolders(HashMap<Long, FolderInfo> folders) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3452 | setLoadOnResume(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 3453 | sFolders.clear(); |
| 3454 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3455 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3456 | |
| 3457 | /** |
| 3458 | * Add the views for a widget to the workspace. |
| 3459 | * |
| 3460 | * Implementation of the method from LauncherModel.Callbacks. |
| 3461 | */ |
| 3462 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3463 | setLoadOnResume(); |
| 3464 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3465 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 3466 | if (DEBUG_WIDGETS) { |
| 3467 | Log.d(TAG, "bindAppWidget: " + item); |
| 3468 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3469 | final Workspace workspace = mWorkspace; |
| 3470 | |
| 3471 | final int appWidgetId = item.appWidgetId; |
| 3472 | final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3473 | if (DEBUG_WIDGETS) { |
| 3474 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 3475 | } |
| 3476 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3477 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 3478 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3479 | item.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 3480 | item.hostView.setTag(item); |
| 3481 | |
| 3482 | workspace.addInScreen(item.hostView, item.screen, item.cellX, |
| 3483 | item.cellY, item.spanX, item.spanY, false); |
| 3484 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 3485 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 3486 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3487 | workspace.requestLayout(); |
| 3488 | |
| 3489 | mDesktopItems.add(item); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3490 | |
| 3491 | if (DEBUG_WIDGETS) { |
| 3492 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 3493 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 3494 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | /** |
| 3498 | * Callback saying that there aren't any more items to bind. |
| 3499 | * |
| 3500 | * Implementation of the method from LauncherModel.Callbacks. |
| 3501 | */ |
| 3502 | public void finishBindingItems() { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3503 | setLoadOnResume(); |
| 3504 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3505 | if (mSavedState != null) { |
| 3506 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3507 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3508 | } |
| 3509 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3510 | final long[] folders = mSavedState.getLongArray(RUNTIME_STATE_FOLDERS); |
| 3511 | if (folders != null) { |
| 3512 | for (long folderId : folders) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 3513 | final FolderInfo info = sFolders.get(folderId); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3514 | final FolderIcon folderIcon = (FolderIcon) |
| 3515 | mWorkspace.getViewForTag(info); |
| 3516 | if (folderIcon != null) { |
| 3517 | openFolder(folderIcon); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3518 | } |
| 3519 | } |
| 3520 | final Folder openFolder = mWorkspace.getOpenFolder(); |
| 3521 | if (openFolder != null) { |
| 3522 | openFolder.requestFocus(); |
| 3523 | } |
| 3524 | } |
| 3525 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3526 | mSavedState = null; |
| 3527 | } |
| 3528 | |
| 3529 | if (mSavedInstanceState != null) { |
| 3530 | super.onRestoreInstanceState(mSavedInstanceState); |
| 3531 | mSavedInstanceState = null; |
| 3532 | } |
| 3533 | |
Winson Chung | 32bb5e5 | 2011-01-31 14:51:56 -0800 | [diff] [blame] | 3534 | // Workaround a bug that occurs when rotating the device while the customization mode is |
| 3535 | // open, we trigger a new layout on all the CellLayout children. |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 3536 | if (LauncherApplication.isScreenLarge() && (mState == State.CUSTOMIZE)) { |
Winson Chung | 32bb5e5 | 2011-01-31 14:51:56 -0800 | [diff] [blame] | 3537 | final int childCount = mWorkspace.getChildCount(); |
| 3538 | for (int i = 0; i < childCount; ++i) { |
| 3539 | mWorkspace.getChildAt(i).requestLayout(); |
| 3540 | } |
| 3541 | } |
| 3542 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3543 | mWorkspaceLoading = false; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 3544 | |
| 3545 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 3546 | // widget configuration forced an orientation change), process them now. |
| 3547 | for (int i = 0; i < sPendingAddList.size(); i++) { |
| 3548 | completeAdd(sPendingAddList.get(i)); |
| 3549 | } |
| 3550 | sPendingAddList.clear(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3554 | * Updates the icons on the launcher that are affected by changes to the package list |
| 3555 | * on the device. |
| 3556 | */ |
| 3557 | private void updateIconsAffectedByPackageManagerChanges() { |
| 3558 | updateAppMarketIcon(); |
| 3559 | updateGlobalSearchIcon(); |
| 3560 | updateVoiceSearchIcon(); |
| 3561 | } |
| 3562 | |
| 3563 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3564 | * Add the icons for all apps. |
| 3565 | * |
| 3566 | * Implementation of the method from LauncherModel.Callbacks. |
| 3567 | */ |
| 3568 | public void bindAllApplications(ArrayList<ApplicationInfo> apps) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3569 | if (mAllAppsGrid != null) { |
| 3570 | mAllAppsGrid.setApps(apps); |
| 3571 | } |
| 3572 | if (mAppsCustomizeContent != null) { |
| 3573 | mAppsCustomizeContent.setApps(apps); |
| 3574 | } |
Andrew Stadler | 959f603 | 2010-09-27 11:42:53 -0700 | [diff] [blame] | 3575 | if (mCustomizePagedView != null) { |
| 3576 | mCustomizePagedView.setApps(apps); |
| 3577 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3578 | updateIconsAffectedByPackageManagerChanges(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | /** |
| 3582 | * A package was installed. |
| 3583 | * |
| 3584 | * Implementation of the method from LauncherModel.Callbacks. |
| 3585 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3586 | public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3587 | setLoadOnResume(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3588 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3589 | if (mAllAppsGrid != null) { |
| 3590 | mAllAppsGrid.addApps(apps); |
| 3591 | } |
| 3592 | if (mAppsCustomizeContent != null) { |
| 3593 | mAppsCustomizeContent.addApps(apps); |
| 3594 | } |
Andrew Stadler | 959f603 | 2010-09-27 11:42:53 -0700 | [diff] [blame] | 3595 | if (mCustomizePagedView != null) { |
| 3596 | mCustomizePagedView.addApps(apps); |
| 3597 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3598 | updateIconsAffectedByPackageManagerChanges(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | /** |
| 3602 | * A package was updated. |
| 3603 | * |
| 3604 | * Implementation of the method from LauncherModel.Callbacks. |
| 3605 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3606 | public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3607 | setLoadOnResume(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3608 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 3609 | if (mWorkspace != null) { |
| 3610 | mWorkspace.updateShortcuts(apps); |
| 3611 | } |
| 3612 | if (mAllAppsGrid != null) { |
| 3613 | mAllAppsGrid.updateApps(apps); |
| 3614 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3615 | if (mAppsCustomizeContent != null) { |
| 3616 | mAppsCustomizeContent.updateApps(apps); |
| 3617 | } |
Andrew Stadler | 959f603 | 2010-09-27 11:42:53 -0700 | [diff] [blame] | 3618 | if (mCustomizePagedView != null) { |
| 3619 | mCustomizePagedView.updateApps(apps); |
| 3620 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3621 | updateIconsAffectedByPackageManagerChanges(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | /** |
| 3625 | * A package was uninstalled. |
| 3626 | * |
| 3627 | * Implementation of the method from LauncherModel.Callbacks. |
| 3628 | */ |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3629 | public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3630 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3631 | if (permanent) { |
| 3632 | mWorkspace.removeItems(apps); |
| 3633 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3634 | if (mAllAppsGrid != null) { |
| 3635 | mAllAppsGrid.removeApps(apps); |
| 3636 | } |
| 3637 | if (mAppsCustomizeContent != null) { |
| 3638 | mAppsCustomizeContent.removeApps(apps); |
| 3639 | } |
Andrew Stadler | 959f603 | 2010-09-27 11:42:53 -0700 | [diff] [blame] | 3640 | if (mCustomizePagedView != null) { |
| 3641 | mCustomizePagedView.removeApps(apps); |
| 3642 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3643 | updateIconsAffectedByPackageManagerChanges(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3644 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3645 | |
| 3646 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3647 | * A number of packages were updated. |
| 3648 | */ |
| 3649 | public void bindPackagesUpdated() { |
| 3650 | // update the customization drawer contents |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 3651 | if (mCustomizePagedView != null) { |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 3652 | mCustomizePagedView.update(); |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 3653 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3654 | if (mAppsCustomizeContent != null) { |
| 3655 | mAppsCustomizeContent.onPackagesUpdated(); |
| 3656 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 3659 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 3660 | final Display d = getWindowManager().getDefaultDisplay(); |
| 3661 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 3662 | switch (d.getRotation()) { |
| 3663 | case Surface.ROTATION_0: |
| 3664 | case Surface.ROTATION_180: |
| 3665 | // We are currently in the same basic orientation as the natural orientation |
| 3666 | naturalOri = configOri; |
| 3667 | break; |
| 3668 | case Surface.ROTATION_90: |
| 3669 | case Surface.ROTATION_270: |
| 3670 | // We are currently in the other basic orientation to the natural orientation |
| 3671 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 3672 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 3673 | break; |
| 3674 | } |
| 3675 | |
| 3676 | int[] oriMap = { |
| 3677 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 3678 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 3679 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 3680 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 3681 | }; |
| 3682 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 3683 | // is landscape. |
| 3684 | int indexOffset = 0; |
| 3685 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 3686 | indexOffset = 1; |
| 3687 | } |
| 3688 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 3689 | } |
| 3690 | public void lockScreenOrientation() { |
| 3691 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 3692 | .getConfiguration().orientation)); |
| 3693 | } |
| 3694 | public void unlockScreenOrientation() { |
| 3695 | mHandler.postDelayed(new Runnable() { |
| 3696 | public void run() { |
| 3697 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 3698 | } |
| 3699 | }, mRestoreScreenOrientationDelay); |
| 3700 | } |
| 3701 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3702 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3703 | * Prints out out state for debugging. |
| 3704 | */ |
| 3705 | public void dumpState() { |
| 3706 | Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 3707 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 3708 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 3709 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 3710 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 3711 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
| 3712 | Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size()); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 3713 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3714 | mModel.dumpState(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3715 | if (mAllAppsGrid != null) { |
| 3716 | mAllAppsGrid.dumpState(); |
| 3717 | } |
| 3718 | if (mAppsCustomizeContent != null) { |
| 3719 | mAppsCustomizeContent.dumpState(); |
| 3720 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3721 | Log.d(TAG, "END launcher2 dump state"); |
| 3722 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3723 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 3724 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3725 | interface LauncherTransitionable { |
| 3726 | void onLauncherTransitionStart(Animator animation); |
| 3727 | void onLauncherTransitionEnd(Animator animation); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 3728 | } |