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