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