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