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