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