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