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