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