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