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