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