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