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