Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher2; |
| 18 | |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 19 | import com.android.launcher.R; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 20 | |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 21 | import org.xmlpull.v1.XmlPullParser; |
| 22 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 23 | import android.animation.Animator; |
Patrick Dubroy | 047379a | 2010-12-19 22:02:04 -0800 | [diff] [blame] | 24 | import android.animation.AnimatorListenerAdapter; |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 25 | import android.animation.ObjectAnimator; |
| 26 | import android.animation.PropertyValuesHolder; |
| 27 | import android.animation.TimeInterpolator; |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 28 | import android.app.WallpaperManager; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 29 | import android.appwidget.AppWidgetManager; |
| 30 | import android.appwidget.AppWidgetProviderInfo; |
| 31 | import android.content.ComponentName; |
| 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
| 36 | import android.content.pm.ResolveInfo; |
| 37 | import android.content.res.Resources; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 38 | import android.content.res.TypedArray; |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 39 | import android.content.res.XmlResourceParser; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 40 | import android.graphics.Bitmap; |
Winson Chung | cd4bc49 | 2010-12-09 18:52:32 -0800 | [diff] [blame] | 41 | import android.graphics.Canvas; |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 42 | import android.graphics.Rect; |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 43 | import android.graphics.RectF; |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 44 | import android.graphics.Bitmap.Config; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 45 | import android.graphics.drawable.Drawable; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 46 | import android.util.AttributeSet; |
| 47 | import android.util.Log; |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 48 | import android.util.Slog; |
| 49 | import android.util.TypedValue; |
| 50 | import android.util.Xml; |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 51 | import android.view.ActionMode; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 52 | import android.view.Gravity; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 53 | import android.view.LayoutInflater; |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 54 | import android.view.Menu; |
| 55 | import android.view.MenuItem; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 56 | import android.view.View; |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 57 | import android.view.animation.DecelerateInterpolator; |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 58 | import android.view.animation.LinearInterpolator; |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 59 | import android.widget.Checkable; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 60 | import android.widget.ImageView; |
| 61 | import android.widget.LinearLayout; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 62 | import android.widget.TextView; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 63 | |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 64 | import java.util.ArrayList; |
| 65 | import java.util.Collections; |
| 66 | import java.util.Comparator; |
| 67 | import java.util.List; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 68 | |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 69 | |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 70 | public class CustomizePagedView extends PagedViewWithDraggableItems |
| 71 | implements View.OnClickListener, DragSource, ActionMode.Callback { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 72 | |
| 73 | public enum CustomizationType { |
| 74 | WidgetCustomization, |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 75 | ShortcutCustomization, |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 76 | WallpaperCustomization, |
| 77 | ApplicationCustomization |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | private static final String TAG = "CustomizeWorkspace"; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 81 | |
| 82 | private Launcher mLauncher; |
| 83 | private DragController mDragController; |
| 84 | private PackageManager mPackageManager; |
| 85 | |
| 86 | private CustomizationType mCustomizationType; |
| 87 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 88 | // The layout used to emulate the workspace in resolve the cell dimensions of a widget |
| 89 | private PagedViewCellLayout mWorkspaceWidgetLayout; |
| 90 | |
| 91 | // The mapping between the pages and the widgets that will be laid out on them |
| 92 | private ArrayList<ArrayList<AppWidgetProviderInfo>> mWidgetPages; |
| 93 | |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 94 | // This is used if we want to set a min width on pages so that things inside them left align to |
| 95 | // a fixed size |
| 96 | private int mMinPageWidth; |
| 97 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 98 | // The max dimensions for the ImageView we use for displaying a widget |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 99 | private int mMaxWidgetWidth; |
| 100 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 101 | // The max number of widget cells to take a "page" of widgets |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 102 | private int mMaxWidgetsCellHSpan; |
| 103 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 104 | // The size of the items on the wallpaper tab |
| 105 | private int mWallpaperCellHSpan; |
| 106 | |
Winson Chung | 78bd53c | 2010-12-09 13:50:24 -0800 | [diff] [blame] | 107 | // The max number of wallpaper cells to take a "page" of wallpaper items |
| 108 | private int mMaxWallpaperCellHSpan; |
| 109 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 110 | // The raw sources of data for each of the different tabs of the customization page |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 111 | private List<AppWidgetProviderInfo> mWidgetList; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 112 | private List<ResolveInfo> mShortcutList; |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 113 | private List<ResolveInfo> mWallpaperList; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 114 | private List<ApplicationInfo> mApps; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 115 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 116 | private static final int sMinWidgetCellHSpan = 2; |
| 117 | private static final int sMaxWidgetCellHSpan = 4; |
| 118 | |
Michael Jurka | 3125d9d | 2010-09-27 11:30:20 -0700 | [diff] [blame] | 119 | private int mChoiceModeTitleText; |
| 120 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 121 | // The scale factor for widget previews inside the widget drawer |
| 122 | private static final float sScaleFactor = 0.75f; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 123 | |
| 124 | private final Canvas mCanvas = new Canvas(); |
| 125 | private final LayoutInflater mInflater; |
| 126 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 127 | private final float mTmpFloatPos[] = new float[2]; |
| 128 | private final float ANIMATION_SCALE = 0.5f; |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 129 | |
| 130 | // The duration of the translation animation that occurs during you drag and drop |
| 131 | private final int TRANSLATE_ANIM_DURATION = 400; |
| 132 | |
| 133 | // The duration of the scale & alpha animation that occurs during drag and drop |
| 134 | private final int DROP_ANIM_DURATION = 200; |
| 135 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 136 | private TimeInterpolator mQuintEaseOutInterpolator = new DecelerateInterpolator(2.5f); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 137 | |
| 138 | // The Bitmap used to generate the drag view |
| 139 | private Bitmap mDragBitmap; |
| 140 | |
| 141 | private int[] mDragViewOrigin = new int[2]; |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 142 | |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 143 | private int mPageContentWidth; |
| 144 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 145 | public CustomizePagedView(Context context) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 146 | this(context, null, 0); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | public CustomizePagedView(Context context, AttributeSet attrs) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 150 | this(context, attrs, 0); |
| 151 | } |
| 152 | |
| 153 | public CustomizePagedView(Context context, AttributeSet attrs, int defStyle) { |
| 154 | super(context, attrs, defStyle); |
| 155 | |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 156 | TypedArray a; |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 157 | a = context.obtainStyledAttributes(attrs, R.styleable.CustomizePagedView, defStyle, 0); |
| 158 | mWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellSpanX, 4); |
Winson Chung | 78bd53c | 2010-12-09 13:50:24 -0800 | [diff] [blame] | 159 | mMaxWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellCountX, 8); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 160 | mMaxWidgetsCellHSpan = a.getInt(R.styleable.CustomizePagedView_widgetCellCountX, 8); |
| 161 | a.recycle(); |
| 162 | a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); |
| 163 | mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 7); |
| 164 | mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 165 | a.recycle(); |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 166 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 167 | mCustomizationType = CustomizationType.WidgetCustomization; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 168 | mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>(); |
| 169 | mWorkspaceWidgetLayout = new PagedViewCellLayout(context); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 170 | mInflater = LayoutInflater.from(context); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 171 | |
Michael Jurka | 7426c42 | 2010-11-11 15:23:47 -0800 | [diff] [blame] | 172 | final Resources r = context.getResources(); |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 173 | setDragSlopeThreshold( |
| 174 | r.getInteger(R.integer.config_customizationDrawerDragSlopeThreshold) / 100.0f); |
Michael Jurka | 7426c42 | 2010-11-11 15:23:47 -0800 | [diff] [blame] | 175 | |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 176 | // Create a dummy page and set it up to find out the content width (used by our parent) |
| 177 | PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); |
| 178 | setupPage(layout); |
| 179 | mPageContentWidth = layout.getContentWidth(); |
Michael Jurka | 0413dfa | 2011-04-05 16:52:32 -0700 | [diff] [blame] | 180 | mMinPageWidth = layout.getWidthBeforeFirstLayout(); |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 181 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 182 | setVisibility(View.GONE); |
| 183 | setSoundEffectsEnabled(false); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 184 | setupWorkspaceLayout(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 187 | @Override |
| 188 | protected void init() { |
| 189 | super.init(); |
| 190 | mCenterPagesVertically = false; |
| 191 | } |
| 192 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 193 | public void setLauncher(Launcher launcher) { |
| 194 | Context context = getContext(); |
| 195 | mLauncher = launcher; |
| 196 | mPackageManager = context.getPackageManager(); |
| 197 | } |
| 198 | |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 199 | /** |
| 200 | * Sets the list of applications that launcher has loaded. |
| 201 | */ |
| 202 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 203 | mApps = list; |
| 204 | Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 205 | |
| 206 | // Update the widgets/shortcuts to reflect changes in the set of available apps |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 207 | mPageViewIconCache.retainAllApps(list); |
| 208 | invalidatePageData(); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Convenience function to add new items to the set of applications that were previously loaded. |
| 213 | * Called by both updateApps() and setApps(). |
| 214 | */ |
| 215 | private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
| 216 | // we add it in place, in alphabetical order |
| 217 | final int count = list.size(); |
| 218 | for (int i = 0; i < count; ++i) { |
| 219 | final ApplicationInfo info = list.get(i); |
| 220 | final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR); |
| 221 | if (index < 0) { |
| 222 | mApps.add(-(index + 1), info); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Adds new applications to the loaded list, and notifies the paged view to update itself. |
| 229 | */ |
| 230 | public void addApps(ArrayList<ApplicationInfo> list) { |
| 231 | addAppsWithoutInvalidate(list); |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 232 | |
| 233 | // Update the widgets/shortcuts to reflect changes in the set of available apps |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 234 | invalidatePageData(); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Convenience function to remove items to the set of applications that were previously loaded. |
| 239 | * Called by both updateApps() and removeApps(). |
| 240 | */ |
| 241 | private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
| 242 | // loop through all the apps and remove apps that have the same component |
| 243 | final int length = list.size(); |
| 244 | for (int i = 0; i < length; ++i) { |
| 245 | final ApplicationInfo info = list.get(i); |
| 246 | int removeIndex = findAppByComponent(mApps, info); |
| 247 | if (removeIndex > -1) { |
| 248 | mApps.remove(removeIndex); |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 249 | mPageViewIconCache.removeOutline(new PagedViewIconCache.Key(info)); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Removes applications from the loaded list, and notifies the paged view to update itself. |
| 256 | */ |
| 257 | public void removeApps(ArrayList<ApplicationInfo> list) { |
| 258 | removeAppsWithoutInvalidate(list); |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 259 | |
| 260 | // Update the widgets/shortcuts to reflect changes in the set of available apps |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 261 | invalidatePageData(); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Updates a set of applications from the loaded list, and notifies the paged view to update |
| 266 | * itself. |
| 267 | */ |
| 268 | public void updateApps(ArrayList<ApplicationInfo> list) { |
| 269 | // We remove and re-add the updated applications list because it's properties may have |
| 270 | // changed (ie. the title), and this will ensure that the items will be in their proper |
| 271 | // place in the list. |
| 272 | removeAppsWithoutInvalidate(list); |
| 273 | addAppsWithoutInvalidate(list); |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 274 | |
| 275 | // Update the widgets/shortcuts to reflect changes in the set of available apps |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 276 | invalidatePageData(); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Convenience function to find matching ApplicationInfos for removal. |
| 281 | */ |
| 282 | private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) { |
| 283 | ComponentName removeComponent = item.intent.getComponent(); |
| 284 | final int length = list.size(); |
| 285 | for (int i = 0; i < length; ++i) { |
| 286 | ApplicationInfo info = list.get(i); |
| 287 | if (info.intent.getComponent().equals(removeComponent)) { |
| 288 | return i; |
| 289 | } |
| 290 | } |
| 291 | return -1; |
| 292 | } |
| 293 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 294 | public void update() { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 295 | // get the list of widgets |
| 296 | mWidgetList = AppWidgetManager.getInstance(mLauncher).getInstalledProviders(); |
| 297 | Collections.sort(mWidgetList, new Comparator<AppWidgetProviderInfo>() { |
| 298 | @Override |
| 299 | public int compare(AppWidgetProviderInfo object1, AppWidgetProviderInfo object2) { |
| 300 | return object1.label.compareTo(object2.label); |
| 301 | } |
| 302 | }); |
| 303 | |
Winson Chung | 4dbea79 | 2011-05-05 14:21:32 -0700 | [diff] [blame^] | 304 | LauncherModel.ShortcutNameComparator resolveInfoComparator = |
| 305 | new LauncherModel.ShortcutNameComparator(mPackageManager); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 306 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 307 | // get the list of shortcuts |
| 308 | Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 309 | mShortcutList = mPackageManager.queryIntentActivities(shortcutsIntent, 0); |
| 310 | Collections.sort(mShortcutList, resolveInfoComparator); |
| 311 | |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 312 | // get the list of wallpapers |
| 313 | Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER); |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 314 | mWallpaperList = mPackageManager.queryIntentActivities(wallpapersIntent, |
| 315 | PackageManager.GET_META_DATA); |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 316 | Collections.sort(mWallpaperList, resolveInfoComparator); |
| 317 | |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 318 | ArrayList<ResolveInfo> retainShortcutList = new ArrayList<ResolveInfo>(mShortcutList); |
| 319 | retainShortcutList.addAll(mWallpaperList); |
| 320 | mPageViewIconCache.retainAllShortcuts(retainShortcutList); |
| 321 | mPageViewIconCache.retainAllAppWidgets(mWidgetList); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 322 | invalidatePageData(); |
| 323 | } |
| 324 | |
| 325 | public void setDragController(DragController dragger) { |
| 326 | mDragController = dragger; |
| 327 | } |
| 328 | |
| 329 | public void setCustomizationFilter(CustomizationType filterType) { |
Winson Chung | 7d1fcbc | 2011-01-04 10:22:20 -0800 | [diff] [blame] | 330 | cancelDragging(); |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 331 | mCustomizationType = filterType; |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 332 | if (getChildCount() > 0) { |
| 333 | setCurrentPage(0); |
| 334 | updateCurrentPageScroll(); |
| 335 | invalidatePageData(); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 336 | |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 337 | // End the current choice mode so that we don't carry selections across tabs |
| 338 | endChoiceMode(); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | public CustomizationType getCustomizationFilter() { |
| 343 | return mCustomizationType; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 346 | /** |
| 347 | * Similar to resetCheckedGrandchildren, but allows us to specify that it's not animated. |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 348 | */ |
| 349 | private void resetCheckedItem(boolean animated) { |
Patrick Dubroy | 6f13342 | 2011-02-24 12:16:12 -0800 | [diff] [blame] | 350 | final Checkable checkable = getSingleCheckedGrandchild(); |
| 351 | if (checkable != null) { |
| 352 | if (checkable instanceof PagedViewWidget) { |
| 353 | ((PagedViewWidget) checkable).setChecked(false, animated); |
| 354 | } else { |
| 355 | ((PagedViewIcon) checkable).setChecked(false, animated); |
| 356 | } |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
| 360 | public void onDropCompleted(View target, Object dragInfo, boolean success) { |
| 361 | final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer); |
| 362 | |
| 363 | // Create a view, identical to the drag view, that is only used for animating the |
| 364 | // item onto the home screen (or back to its original position, if the drop failed). |
Patrick Dubroy | 6f13342 | 2011-02-24 12:16:12 -0800 | [diff] [blame] | 365 | final int[] pos = mDragController.getDragView().getPosition(null); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 366 | final View animView = dragLayer.createDragView(mDragBitmap, pos[0], pos[1]); |
| 367 | animView.setVisibility(View.VISIBLE); |
| 368 | |
| 369 | if (success) { |
| 370 | resetCheckedItem(true); |
| 371 | animateDropOntoScreen(animView, (ItemInfo) dragInfo, DROP_ANIM_DURATION, 0); |
| 372 | } else { |
| 373 | // Animate the icon/widget back to its original position |
| 374 | animateIntoPosition(animView, mDragViewOrigin[0], mDragViewOrigin[1], new Runnable() { |
| 375 | public void run() { |
| 376 | resetCheckedItem(false); |
| 377 | dragLayer.removeView(animView); |
| 378 | } |
| 379 | }); |
| 380 | } |
Patrick Dubroy | 7bccb42 | 2011-01-20 14:50:55 -0800 | [diff] [blame] | 381 | mLauncher.getWorkspace().onDragStopped(success); |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 382 | mLauncher.unlockScreenOrientation(); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 383 | mDragBitmap = null; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | @Override |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 387 | public void onDragViewVisible() { |
| 388 | } |
| 389 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 390 | /** |
| 391 | * Animates the given item onto the center of a home screen, and then scales the item to |
| 392 | * look as though it's disappearing onto that screen. |
| 393 | */ |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 394 | private void animateItemOntoScreen(View dragView, |
| 395 | final CellLayout layout, final ItemInfo info) { |
| 396 | mTmpFloatPos[0] = layout.getWidth() / 2; |
| 397 | mTmpFloatPos[1] = layout.getHeight() / 2; |
| 398 | mLauncher.getWorkspace().mapPointFromChildToSelf(layout, mTmpFloatPos); |
| 399 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 400 | int dragViewWidth = dragView.getMeasuredWidth(); |
| 401 | int dragViewHeight = dragView.getMeasuredHeight(); |
| 402 | float heightOffset = 0; |
| 403 | float widthOffset = 0; |
| 404 | |
| 405 | if (dragView instanceof ImageView) { |
| 406 | Drawable d = ((ImageView) dragView).getDrawable(); |
| 407 | int width = d.getIntrinsicWidth(); |
| 408 | int height = d.getIntrinsicHeight(); |
| 409 | |
| 410 | if ((1.0 * width / height) >= (1.0f * dragViewWidth) / dragViewHeight) { |
| 411 | float f = (dragViewWidth / (width * 1.0f)); |
| 412 | heightOffset = ANIMATION_SCALE * (dragViewHeight - f * height) / 2; |
| 413 | } else { |
| 414 | float f = (dragViewHeight / (height * 1.0f)); |
| 415 | widthOffset = ANIMATION_SCALE * (dragViewWidth - f * width) / 2; |
| 416 | } |
| 417 | } |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 418 | final float toX = mTmpFloatPos[0] - dragView.getMeasuredWidth() / 2 + widthOffset; |
| 419 | final float toY = mTmpFloatPos[1] - dragView.getMeasuredHeight() / 2 + heightOffset; |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 420 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 421 | final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer); |
| 422 | final View dragCopy = dragLayer.createDragView(dragView); |
| 423 | dragCopy.setAlpha(1.0f); |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 424 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 425 | // Translate the item to the center of the appropriate home screen |
| 426 | animateIntoPosition(dragCopy, toX, toY, null); |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 427 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 428 | // The drop-onto-screen animation begins a bit later, but ends at the same time. |
| 429 | final int startDelay = TRANSLATE_ANIM_DURATION - DROP_ANIM_DURATION; |
| 430 | |
| 431 | // Scale down the icon and fade out the alpha |
| 432 | animateDropOntoScreen(dragCopy, info, DROP_ANIM_DURATION, startDelay); |
| 433 | } |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 434 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 435 | /** |
| 436 | * Animation which scales the view down and animates its alpha, making it appear to disappear |
| 437 | * onto a home screen. |
| 438 | */ |
| 439 | private void animateDropOntoScreen( |
| 440 | final View view, final ItemInfo info, int duration, int delay) { |
| 441 | final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer); |
| 442 | final CellLayout layout = mLauncher.getWorkspace().getCurrentDropLayout(); |
| 443 | |
| 444 | ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view, |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 445 | PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f), |
| 446 | PropertyValuesHolder.ofFloat("scaleX", ANIMATION_SCALE), |
| 447 | PropertyValuesHolder.ofFloat("scaleY", ANIMATION_SCALE)); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 448 | anim.setInterpolator(new LinearInterpolator()); |
| 449 | if (delay > 0) { |
| 450 | anim.setStartDelay(delay); |
| 451 | } |
| 452 | anim.setDuration(duration); |
| 453 | anim.addListener(new AnimatorListenerAdapter() { |
| 454 | public void onAnimationEnd(Animator animation) { |
| 455 | dragLayer.removeView(view); |
| 456 | mLauncher.addExternalItemToScreen(info, layout); |
Patrick Dubroy | bbaa75c | 2011-03-08 18:47:40 -0800 | [diff] [blame] | 457 | info.dropPos = null; |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 458 | } |
| 459 | }); |
| 460 | anim.start(); |
| 461 | } |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 462 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 463 | /** |
| 464 | * Animates the x,y position of the view, and optionally execute a Runnable on animation end. |
| 465 | */ |
| 466 | private void animateIntoPosition( |
| 467 | View view, float toX, float toY, final Runnable endRunnable) { |
| 468 | ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view, |
| 469 | PropertyValuesHolder.ofFloat("x", toX), |
| 470 | PropertyValuesHolder.ofFloat("y", toY)); |
| 471 | anim.setInterpolator(mQuintEaseOutInterpolator); |
| 472 | anim.setDuration(TRANSLATE_ANIM_DURATION); |
| 473 | if (endRunnable != null) { |
| 474 | anim.addListener(new AnimatorListenerAdapter() { |
| 475 | @Override |
| 476 | public void onAnimationEnd(Animator animation) { |
| 477 | endRunnable.run(); |
| 478 | } |
| 479 | }); |
| 480 | } |
| 481 | anim.start(); |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 482 | } |
| 483 | |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 484 | @Override |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 485 | public void onClick(final View v) { |
Winson Chung | e22a8e9 | 2010-11-12 13:40:58 -0800 | [diff] [blame] | 486 | // Return early if we are still animating the pages |
Winson Chung | 4f9e107 | 2010-11-15 15:28:24 -0800 | [diff] [blame] | 487 | if (mNextPage != INVALID_PAGE) return; |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 488 | |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 489 | // On certain pages, we allow single tap to mark items as selected so that they can be |
| 490 | // dropped onto the mini workspaces |
Michael Jurka | 3125d9d | 2010-09-27 11:30:20 -0700 | [diff] [blame] | 491 | boolean enterChoiceMode = false; |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 492 | switch (mCustomizationType) { |
| 493 | case WidgetCustomization: |
Michael Jurka | 3125d9d | 2010-09-27 11:30:20 -0700 | [diff] [blame] | 494 | mChoiceModeTitleText = R.string.cab_widget_selection_text; |
| 495 | enterChoiceMode = true; |
| 496 | break; |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 497 | case ApplicationCustomization: |
Michael Jurka | 3125d9d | 2010-09-27 11:30:20 -0700 | [diff] [blame] | 498 | mChoiceModeTitleText = R.string.cab_app_selection_text; |
| 499 | enterChoiceMode = true; |
| 500 | break; |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 501 | case ShortcutCustomization: |
Michael Jurka | 3125d9d | 2010-09-27 11:30:20 -0700 | [diff] [blame] | 502 | mChoiceModeTitleText = R.string.cab_shortcut_selection_text; |
| 503 | enterChoiceMode = true; |
| 504 | break; |
| 505 | default: |
| 506 | break; |
| 507 | } |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 508 | |
Michael Jurka | 3125d9d | 2010-09-27 11:30:20 -0700 | [diff] [blame] | 509 | if (enterChoiceMode) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 510 | final ItemInfo itemInfo = (ItemInfo) v.getTag(); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 511 | |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 512 | Workspace w = mLauncher.getWorkspace(); |
| 513 | int currentWorkspaceScreen = mLauncher.getCurrentWorkspaceScreen(); |
| 514 | final CellLayout cl = (CellLayout)w.getChildAt(currentWorkspaceScreen); |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 515 | final View dragView = getDragView(v); |
Michael Jurka | e17e19c | 2010-09-28 11:01:39 -0700 | [diff] [blame] | 516 | |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 517 | animateClickFeedback(v, new Runnable() { |
| 518 | @Override |
| 519 | public void run() { |
Patrick Dubroy | 047379a | 2010-12-19 22:02:04 -0800 | [diff] [blame] | 520 | cl.calculateSpans(itemInfo); |
| 521 | if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) { |
| 522 | animateItemOntoScreen(dragView, cl, itemInfo); |
| 523 | } else { |
| 524 | mLauncher.showOutOfSpaceMessage(); |
| 525 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 526 | } |
| 527 | }); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 528 | return; |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | // Otherwise, we just handle the single click here |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 532 | switch (mCustomizationType) { |
| 533 | case WallpaperCustomization: |
| 534 | // animate some feedback to the long press |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 535 | final View clickView = v; |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 536 | animateClickFeedback(v, new Runnable() { |
| 537 | @Override |
| 538 | public void run() { |
| 539 | // add the shortcut |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 540 | ResolveInfo info = (ResolveInfo) clickView.getTag(); |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 541 | Intent createWallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 542 | ComponentName name = new ComponentName(info.activityInfo.packageName, |
| 543 | info.activityInfo.name); |
| 544 | createWallpapersIntent.setComponent(name); |
| 545 | mLauncher.processWallpaper(createWallpapersIntent); |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 546 | } |
| 547 | }); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 548 | break; |
| 549 | default: |
| 550 | break; |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 554 | private Bitmap drawableToBitmap(Drawable d, float scaleX, float scaleY) { |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 555 | final Rect bounds = d.getBounds(); |
| 556 | final int w = bounds.width(); |
| 557 | final int h = bounds.height(); |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 558 | Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 559 | renderDrawableToBitmap(d, b, 0, 0, w, h, scaleX, scaleY); |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 560 | return b; |
| 561 | } |
| 562 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 563 | private View getDragView(View v) { |
| 564 | return (mCustomizationType == CustomizationType.WidgetCustomization) ? |
| 565 | v.findViewById(R.id.widget_preview) : v; |
| 566 | } |
| 567 | |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 568 | protected boolean beginDragging(View v) { |
Winson Chung | 304dcde | 2011-01-07 11:17:23 -0800 | [diff] [blame] | 569 | if (!v.isInTouchMode()) return false; |
| 570 | if (!super.beginDragging(v)) return false; |
| 571 | |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 572 | // End the current choice mode before we start dragging anything |
| 573 | if (isChoiceMode(CHOICE_MODE_SINGLE)) { |
| 574 | endChoiceMode(); |
| 575 | } |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 576 | final Workspace workspace = mLauncher.getWorkspace(); |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 577 | boolean result = false; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 578 | mLauncher.lockScreenOrientation(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 579 | switch (mCustomizationType) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 580 | case WidgetCustomization: { |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 581 | if (v instanceof PagedViewWidget) { |
| 582 | // Get the widget preview as the drag representation |
| 583 | final LinearLayout l = (LinearLayout) v; |
| 584 | final ImageView i = (ImageView) l.findViewById(R.id.widget_preview); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 585 | |
| 586 | // Calculate how much to scale the drag preview |
| 587 | RectF tmpScaleRect = new RectF(0,0,1,1); |
| 588 | i.getImageMatrix().mapRect(tmpScaleRect); |
| 589 | |
| 590 | mDragBitmap = drawableToBitmap(i.getDrawable(), tmpScaleRect.right, |
| 591 | tmpScaleRect.bottom); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 592 | i.getLocationOnScreen(mDragViewOrigin); |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 593 | PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag(); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 594 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 595 | int[] spanXY = CellLayout.rectToCell(getResources(), |
| 596 | createWidgetInfo.minWidth, createWidgetInfo.minHeight, null); |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 597 | createWidgetInfo.spanX = spanXY[0]; |
| 598 | createWidgetInfo.spanY = spanXY[1]; |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 599 | workspace.onDragStartedWithItemSpans(spanXY[0], spanXY[1], mDragBitmap); |
| 600 | mDragController.startDrag(i, mDragBitmap, this, createWidgetInfo, |
| 601 | DragController.DRAG_ACTION_COPY, null); |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 602 | result = true; |
| 603 | } |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 604 | break; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 605 | } |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 606 | case ShortcutCustomization: |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 607 | case ApplicationCustomization: { |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 608 | if (v instanceof PagedViewIcon) { |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 609 | // get icon (top compound drawable, index is 1) |
| 610 | final TextView tv = (TextView) v; |
| 611 | final Drawable icon = tv.getCompoundDrawables()[1]; |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 612 | mDragBitmap = drawableToBitmap(icon, 1.0f, 1.0f); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 613 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 614 | Object dragInfo = v.getTag(); |
| 615 | if (mCustomizationType == CustomizationType.ApplicationCustomization) { |
| 616 | // TODO: Not sure why we have to copy this |
| 617 | dragInfo = new ApplicationInfo((ApplicationInfo) dragInfo); |
| 618 | } |
| 619 | workspace.onDragStartedWithItemSpans(1, 1, mDragBitmap); |
| 620 | |
| 621 | // Calculate where to place the drag view in order to align the icon pixels with |
| 622 | // the original view. |
| 623 | v.getLocationOnScreen(mDragViewOrigin); |
| 624 | mDragViewOrigin[0] += (v.getWidth() - icon.getIntrinsicWidth()) / 2; |
| 625 | mDragViewOrigin[1] += v.getPaddingTop(); |
| 626 | |
| 627 | mDragController.startDrag(mDragBitmap, mDragViewOrigin[0], mDragViewOrigin[1], |
| 628 | this, dragInfo, DragController.DRAG_ACTION_COPY); |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 629 | result = true; |
| 630 | } |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 631 | break; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 632 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 633 | } |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 634 | |
| 635 | // We toggle the checked state _after_ we create the view for the drag in case toggling the |
| 636 | // checked state changes the view's look |
Winson Chung | 94569f4 | 2011-01-17 14:09:17 -0800 | [diff] [blame] | 637 | if (result && (v instanceof Checkable)) { |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 638 | // In preparation for drag, we always reset the checked grand children regardless of |
| 639 | // what choice mode we are in |
| 640 | resetCheckedGrandchildren(); |
| 641 | |
| 642 | // Toggle the selection on the dragged app |
| 643 | Checkable checkable = (Checkable) v; |
| 644 | |
| 645 | // Note: we toggle the checkable state to actually cause an alpha fade for the duration |
| 646 | // of the drag of the item. (The fade-in will occur when all checked states are |
| 647 | // disabled when dragging ends) |
| 648 | checkable.toggle(); |
| 649 | } |
| 650 | |
| 651 | return result; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 654 | /** |
| 655 | * Pre-processes the layout of the different widget pages. |
| 656 | * @return the number of pages of widgets that we have |
| 657 | */ |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 658 | private int relayoutWidgets() { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 659 | if (mWidgetList.isEmpty()) return 0; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 660 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 661 | // create a new page for the first set of widgets |
| 662 | ArrayList<AppWidgetProviderInfo> newPage = new ArrayList<AppWidgetProviderInfo>(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 663 | mWidgetPages.clear(); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 664 | mWidgetPages.add(newPage); |
| 665 | |
| 666 | // do this until we have no more widgets to lay out |
| 667 | final int maxNumCellsPerRow = mMaxWidgetsCellHSpan; |
| 668 | final int widgetCount = mWidgetList.size(); |
| 669 | int numCellsInRow = 0; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 670 | for (int i = 0; i < widgetCount; ++i) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 671 | final AppWidgetProviderInfo info = mWidgetList.get(i); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 672 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 673 | // determine the size of the current widget |
| 674 | int cellSpanX = Math.max(sMinWidgetCellHSpan, Math.min(sMaxWidgetCellHSpan, |
| 675 | mWorkspaceWidgetLayout.estimateCellHSpan(info.minWidth))); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 676 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 677 | // create a new page if necessary |
| 678 | if ((numCellsInRow + cellSpanX) > maxNumCellsPerRow) { |
| 679 | numCellsInRow = 0; |
| 680 | newPage = new ArrayList<AppWidgetProviderInfo>(); |
| 681 | mWidgetPages.add(newPage); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 684 | // add the item to the current page |
| 685 | newPage.add(info); |
| 686 | numCellsInRow += cellSpanX; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 687 | } |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 688 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 689 | return mWidgetPages.size(); |
| 690 | } |
| 691 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 692 | /** |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 693 | * Helper function to draw a drawable to the specified canvas with the specified bounds. |
| 694 | */ |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 695 | private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h, |
| 696 | float scaleX, float scaleY) { |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 697 | if (bitmap != null) mCanvas.setBitmap(bitmap); |
| 698 | mCanvas.save(); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 699 | mCanvas.scale(scaleX, scaleY); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 700 | final Rect oldBounds = d.copyBounds(); |
| 701 | d.setBounds(x, y, x + w, y + h); |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 702 | d.draw(mCanvas); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 703 | d.setBounds(oldBounds); // Restore the bounds |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 704 | mCanvas.restore(); |
| 705 | } |
| 706 | |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 707 | /* |
| 708 | * This method fetches an xml file specified in the manifest identified by |
| 709 | * WallpaperManager.WALLPAPER_PREVIEW_META_DATA). The xml file specifies |
| 710 | * an image which will be used as the wallpaper preview for an activity |
| 711 | * which responds to ACTION_SET_WALLPAPER. This image is returned and used |
| 712 | * in the customize drawer. |
| 713 | */ |
| 714 | private Drawable parseWallpaperPreviewXml(ComponentName component, ResolveInfo ri) { |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 715 | ActivityInfo activityInfo = ri.activityInfo; |
| 716 | XmlResourceParser parser = null; |
| 717 | try { |
| 718 | parser = activityInfo.loadXmlMetaData(mPackageManager, |
| 719 | WallpaperManager.WALLPAPER_PREVIEW_META_DATA); |
| 720 | if (parser == null) { |
| 721 | Slog.w(TAG, "No " + WallpaperManager.WALLPAPER_PREVIEW_META_DATA + " meta-data for " |
| 722 | + "wallpaper provider '" + component + '\''); |
| 723 | return null; |
| 724 | } |
| 725 | |
| 726 | AttributeSet attrs = Xml.asAttributeSet(parser); |
| 727 | |
| 728 | int type; |
| 729 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 730 | && type != XmlPullParser.START_TAG) { |
| 731 | // drain whitespace, comments, etc. |
| 732 | } |
| 733 | |
| 734 | String nodeName = parser.getName(); |
| 735 | if (!"wallpaper-preview".equals(nodeName)) { |
| 736 | Slog.w(TAG, "Meta-data does not start with wallpaper-preview tag for " |
| 737 | + "wallpaper provider '" + component + '\''); |
| 738 | return null; |
| 739 | } |
| 740 | |
| 741 | // If metaData was null, we would have returned earlier when getting |
| 742 | // the parser No need to do the check here |
| 743 | Resources res = mPackageManager.getResourcesForApplication( |
| 744 | activityInfo.applicationInfo); |
| 745 | |
| 746 | TypedArray sa = res.obtainAttributes(attrs, |
| 747 | com.android.internal.R.styleable.WallpaperPreviewInfo); |
| 748 | |
| 749 | TypedValue value = sa.peekValue( |
| 750 | com.android.internal.R.styleable.WallpaperPreviewInfo_staticWallpaperPreview); |
| 751 | if (value == null) return null; |
| 752 | |
| 753 | return res.getDrawable(value.resourceId); |
| 754 | } catch (Exception e) { |
| 755 | Slog.w(TAG, "XML parsing failed for wallpaper provider '" + component + '\'', e); |
| 756 | return null; |
| 757 | } finally { |
| 758 | if (parser != null) parser.close(); |
| 759 | } |
| 760 | } |
| 761 | |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 762 | /** |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 763 | * This method will extract the preview image specified by the wallpaper source provider (if it |
| 764 | * exists) otherwise, it will try to generate a default image preview. |
| 765 | */ |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 766 | private FastBitmapDrawable getWallpaperPreview(ResolveInfo info) { |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 767 | // To be implemented later: resolving the up-to-date wallpaper thumbnail |
| 768 | |
| 769 | final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1); |
| 770 | final int dim = mWorkspaceWidgetLayout.estimateCellWidth(mWallpaperCellHSpan); |
| 771 | Resources resources = mLauncher.getResources(); |
| 772 | |
| 773 | // Create a new bitmap to hold the widget preview |
| 774 | int width = (int) (dim * sScaleFactor); |
| 775 | int height = (int) (dim * sScaleFactor); |
| 776 | final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 777 | |
| 778 | Drawable background = parseWallpaperPreviewXml( |
| 779 | new ComponentName(info.activityInfo.packageName, info.activityInfo.name), info); |
| 780 | boolean foundCustomDrawable = background != null; |
| 781 | |
| 782 | if (!foundCustomDrawable) { |
| 783 | background = resources.getDrawable(R.drawable.default_widget_preview); |
| 784 | } |
| 785 | |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 786 | renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f); |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 787 | |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 788 | // If we don't have a custom icon, we use the app icon on the default background |
| 789 | if (!foundCustomDrawable) { |
| 790 | try { |
| 791 | final IconCache iconCache = |
| 792 | ((LauncherApplication) mLauncher.getApplication()).getIconCache(); |
| 793 | Drawable icon = new FastBitmapDrawable(Utilities.createIconBitmap( |
| 794 | iconCache.getFullResIcon(info, mPackageManager), mContext)); |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 795 | |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 796 | final int iconSize = minDim / 2; |
| 797 | final int offset = iconSize / 4; |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 798 | renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f); |
Adam Cohen | 7b9d3a6 | 2010-12-07 21:49:34 -0800 | [diff] [blame] | 799 | } catch (Resources.NotFoundException e) { |
| 800 | // if we can't find the icon, then just don't draw it |
| 801 | } |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 802 | } |
| 803 | |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 804 | FastBitmapDrawable drawable = new FastBitmapDrawable(bitmap); |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 805 | drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); |
| 806 | return drawable; |
| 807 | } |
| 808 | |
| 809 | /** |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 810 | * This method will extract the preview image specified by the widget developer (if it exists), |
| 811 | * otherwise, it will try to generate a default image preview with the widget's package icon. |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 812 | * @return the drawable that will be used and sized in the ImageView to represent the widget |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 813 | */ |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 814 | private FastBitmapDrawable getWidgetPreview(AppWidgetProviderInfo info) { |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 815 | final PackageManager packageManager = mPackageManager; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 816 | String packageName = info.provider.getPackageName(); |
| 817 | Drawable drawable = null; |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 818 | FastBitmapDrawable newDrawable = null; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 819 | if (info.previewImage != 0) { |
| 820 | drawable = packageManager.getDrawable(packageName, info.previewImage, null); |
| 821 | if (drawable == null) { |
| 822 | Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) |
| 823 | + " for provider: " + info.provider); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | |
| 827 | // If we don't have a preview image, create a default one |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 828 | final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1); |
| 829 | final int maxDim = mWorkspaceWidgetLayout.estimateCellWidth(3); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 830 | if (drawable == null) { |
| 831 | Resources resources = mLauncher.getResources(); |
| 832 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 833 | // Create a new bitmap to hold the widget preview |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 834 | int width = (int) (Math.max(minDim, Math.min(maxDim, info.minWidth)) * sScaleFactor); |
| 835 | int height = (int) (Math.max(minDim, Math.min(maxDim, info.minHeight)) * sScaleFactor); |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 836 | final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); |
| 837 | final Drawable background = resources.getDrawable(R.drawable.default_widget_preview); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 838 | renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 839 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 840 | // Draw the icon flush left |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 841 | try { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 842 | Drawable icon = null; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 843 | if (info.icon > 0) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 844 | icon = packageManager.getDrawable(packageName, info.icon, null); |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 845 | } |
| 846 | if (icon == null) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 847 | icon = resources.getDrawable(R.drawable.ic_launcher_application); |
| 848 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 849 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 850 | final int iconSize = minDim / 2; |
| 851 | final int offset = iconSize / 4; |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 852 | renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 853 | } catch (Resources.NotFoundException e) { |
| 854 | // if we can't find the icon, then just don't draw it |
| 855 | } |
| 856 | |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 857 | newDrawable = new FastBitmapDrawable(bitmap); |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 858 | } else { |
| 859 | // Scale down the preview if necessary |
Winson Chung | 94ba5b1 | 2010-11-08 17:17:47 -0800 | [diff] [blame] | 860 | final float imageWidth = drawable.getIntrinsicWidth(); |
| 861 | final float imageHeight = drawable.getIntrinsicHeight(); |
| 862 | final float aspect = (float) imageWidth / imageHeight; |
| 863 | final int scaledWidth = |
| 864 | (int) (Math.max(minDim, Math.min(maxDim, imageWidth)) * sScaleFactor); |
| 865 | final int scaledHeight = |
| 866 | (int) (Math.max(minDim, Math.min(maxDim, imageHeight)) * sScaleFactor); |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 867 | int width; |
| 868 | int height; |
Winson Chung | 94ba5b1 | 2010-11-08 17:17:47 -0800 | [diff] [blame] | 869 | if (aspect >= 1.0f) { |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 870 | width = scaledWidth; |
Winson Chung | 94ba5b1 | 2010-11-08 17:17:47 -0800 | [diff] [blame] | 871 | height = (int) (((float) scaledWidth / imageWidth) * imageHeight); |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 872 | } else { |
| 873 | height = scaledHeight; |
Winson Chung | 94ba5b1 | 2010-11-08 17:17:47 -0800 | [diff] [blame] | 874 | width = (int) (((float) scaledHeight / imageHeight) * imageWidth); |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 878 | renderDrawableToBitmap(drawable, bitmap, 0, 0, width, height, 1.0f, 1.0f); |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 879 | |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 880 | newDrawable = new FastBitmapDrawable(bitmap); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 881 | } |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 882 | newDrawable.setBounds(0, 0, newDrawable.getIntrinsicWidth(), |
| 883 | newDrawable.getIntrinsicHeight()); |
| 884 | return newDrawable; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | private void setupPage(PagedViewCellLayout layout) { |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 888 | layout.setCellCount(mCellCountX, mCellCountY); |
| 889 | layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight, |
| 890 | mPageLayoutPaddingBottom); |
Winson Chung | ef0066b | 2010-10-21 11:55:00 -0700 | [diff] [blame] | 891 | layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 894 | private void setupWorkspaceLayout() { |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 895 | mWorkspaceWidgetLayout.setCellCount(mCellCountX, mCellCountY); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 896 | mWorkspaceWidgetLayout.setPadding(20, 10, 20, 0); |
| 897 | |
| 898 | mMaxWidgetWidth = mWorkspaceWidgetLayout.estimateCellWidth(sMaxWidgetCellHSpan); |
| 899 | } |
| 900 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 901 | private void syncWidgetPages() { |
| 902 | if (mWidgetList == null) return; |
| 903 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 904 | // we need to repopulate with the LinearLayout layout for the widget pages |
| 905 | removeAllViews(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 906 | int numPages = relayoutWidgets(); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 907 | for (int i = 0; i < numPages; ++i) { |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 908 | LinearLayout layout = new PagedViewExtendedLayout(getContext()); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 909 | layout.setGravity(Gravity.CENTER_HORIZONTAL); |
Winson Chung | ef0066b | 2010-10-21 11:55:00 -0700 | [diff] [blame] | 910 | layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, |
| 911 | mPageLayoutPaddingRight, mPageLayoutPaddingBottom); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 912 | |
Winson Chung | e22a8e9 | 2010-11-12 13:40:58 -0800 | [diff] [blame] | 913 | addView(layout, new LinearLayout.LayoutParams( |
| 914 | LinearLayout.LayoutParams.WRAP_CONTENT, |
| 915 | LinearLayout.LayoutParams.MATCH_PARENT)); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
| 919 | private void syncWidgetPageItems(int page) { |
| 920 | // ensure that we have the right number of items on the pages |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 921 | LinearLayout layout = (LinearLayout) getChildAt(page); |
| 922 | final ArrayList<AppWidgetProviderInfo> list = mWidgetPages.get(page); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 923 | final int count = list.size(); |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 924 | final int numPages = getPageCount(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 925 | layout.removeAllViews(); |
| 926 | for (int i = 0; i < count; ++i) { |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 927 | final AppWidgetProviderInfo info = (AppWidgetProviderInfo) list.get(i); |
| 928 | final PendingAddWidgetInfo createItemInfo = new PendingAddWidgetInfo(info, null, null); |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 929 | final int[] cellSpans = CellLayout.rectToCell(getResources(), info.minWidth, |
| 930 | info.minHeight, null); |
| 931 | final FastBitmapDrawable icon = getWidgetPreview(info); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 932 | |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 933 | PagedViewWidget l = (PagedViewWidget) mInflater.inflate( |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 934 | R.layout.customize_paged_view_widget, layout, false); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 935 | |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 936 | l.applyFromAppWidgetProviderInfo(info, icon, mMaxWidgetWidth, cellSpans, |
| 937 | mPageViewIconCache, (numPages > 1)); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 938 | l.setTag(createItemInfo); |
| 939 | l.setOnClickListener(this); |
Michael Jurka | 7426c42 | 2010-11-11 15:23:47 -0800 | [diff] [blame] | 940 | l.setOnTouchListener(this); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 941 | l.setOnLongClickListener(this); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 942 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 943 | layout.addView(l); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 947 | private void syncWallpaperPages() { |
| 948 | if (mWallpaperList == null) return; |
| 949 | |
| 950 | // We need to repopulate the LinearLayout for the wallpaper pages |
| 951 | removeAllViews(); |
| 952 | int numPages = (int) Math.ceil((float) (mWallpaperList.size() * mWallpaperCellHSpan) / |
Winson Chung | 78bd53c | 2010-12-09 13:50:24 -0800 | [diff] [blame] | 953 | mMaxWallpaperCellHSpan); |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 954 | for (int i = 0; i < numPages; ++i) { |
| 955 | LinearLayout layout = new PagedViewExtendedLayout(getContext()); |
| 956 | layout.setGravity(Gravity.CENTER_HORIZONTAL); |
| 957 | layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, |
| 958 | mPageLayoutPaddingRight, mPageLayoutPaddingBottom); |
| 959 | |
Winson Chung | e22a8e9 | 2010-11-12 13:40:58 -0800 | [diff] [blame] | 960 | addView(layout, new LinearLayout.LayoutParams( |
| 961 | LinearLayout.LayoutParams.WRAP_CONTENT, |
| 962 | LinearLayout.LayoutParams.MATCH_PARENT)); |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
| 966 | private void syncWallpaperPageItems(int page) { |
| 967 | // Load the items on to the pages |
| 968 | LinearLayout layout = (LinearLayout) getChildAt(page); |
| 969 | layout.removeAllViews(); |
| 970 | final int count = mWallpaperList.size(); |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 971 | final int numPages = getPageCount(); |
Winson Chung | 78bd53c | 2010-12-09 13:50:24 -0800 | [diff] [blame] | 972 | final int numItemsPerPage = mMaxWallpaperCellHSpan / mWallpaperCellHSpan; |
Winson Chung | d28ed49 | 2010-11-22 14:34:57 -0800 | [diff] [blame] | 973 | final int startIndex = page * numItemsPerPage; |
| 974 | final int endIndex = Math.min(count, startIndex + numItemsPerPage); |
| 975 | for (int i = startIndex; i < endIndex; ++i) { |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 976 | final ResolveInfo info = mWallpaperList.get(i); |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 977 | final FastBitmapDrawable icon = getWallpaperPreview(info); |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 978 | |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 979 | PagedViewWidget l = (PagedViewWidget) mInflater.inflate( |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 980 | R.layout.customize_paged_view_wallpaper, layout, false); |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 981 | l.applyFromWallpaperInfo(info, mPackageManager, icon, mMaxWidgetWidth, |
| 982 | mPageViewIconCache, (numPages > 1)); |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 983 | l.setTag(info); |
| 984 | l.setOnClickListener(this); |
| 985 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 986 | layout.addView(l); |
| 987 | } |
| 988 | } |
| 989 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 990 | private void syncListPages(List<ResolveInfo> list) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 991 | // we need to repopulate with PagedViewCellLayouts |
| 992 | removeAllViews(); |
| 993 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 994 | // ensure that we have the right number of pages |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 995 | int numPages = (int) Math.ceil((float) list.size() / (mCellCountX * mCellCountY)); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 996 | for (int i = 0; i < numPages; ++i) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 997 | PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); |
| 998 | setupPage(layout); |
| 999 | addView(layout); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | private void syncListPageItems(int page, List<ResolveInfo> list) { |
| 1004 | // ensure that we have the right number of items on the pages |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 1005 | final int numPages = getPageCount(); |
| 1006 | final int numCells = mCellCountX * mCellCountY; |
| 1007 | final int startIndex = page * numCells; |
| 1008 | final int endIndex = Math.min(startIndex + numCells, list.size()); |
| 1009 | final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1010 | // TODO: we can optimize by just re-applying to existing views |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 1011 | layout.removeAllViewsOnPage(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1012 | for (int i = startIndex; i < endIndex; ++i) { |
| 1013 | ResolveInfo info = list.get(i); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1014 | PendingAddItemInfo createItemInfo = new PendingAddItemInfo(); |
| 1015 | |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 1016 | PagedViewIcon icon = (PagedViewIcon) mInflater.inflate( |
| 1017 | R.layout.customize_paged_view_item, layout, false); |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 1018 | icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache, |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 1019 | ((LauncherApplication) mLauncher.getApplication()).getIconCache(), |
| 1020 | (numPages > 1)); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1021 | switch (mCustomizationType) { |
| 1022 | case WallpaperCustomization: |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 1023 | icon.setOnClickListener(this); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1024 | break; |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1025 | case ShortcutCustomization: |
| 1026 | createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; |
| 1027 | createItemInfo.componentName = new ComponentName(info.activityInfo.packageName, |
| 1028 | info.activityInfo.name); |
| 1029 | icon.setTag(createItemInfo); |
| 1030 | icon.setOnClickListener(this); |
Michael Jurka | 7426c42 | 2010-11-11 15:23:47 -0800 | [diff] [blame] | 1031 | icon.setOnTouchListener(this); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1032 | icon.setOnLongClickListener(this); |
| 1033 | break; |
| 1034 | default: |
| 1035 | break; |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 1036 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1037 | |
| 1038 | final int index = i - startIndex; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 1039 | final int x = index % mCellCountX; |
| 1040 | final int y = index / mCellCountX; |
| 1041 | setupPage(layout); |
| 1042 | layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1)); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | private void syncAppPages() { |
| 1047 | if (mApps == null) return; |
| 1048 | |
| 1049 | // We need to repopulate with PagedViewCellLayouts |
| 1050 | removeAllViews(); |
| 1051 | |
| 1052 | // Ensure that we have the right number of pages |
| 1053 | int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); |
| 1054 | for (int i = 0; i < numPages; ++i) { |
| 1055 | PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); |
| 1056 | setupPage(layout); |
| 1057 | addView(layout); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | private void syncAppPageItems(int page) { |
| 1062 | if (mApps == null) return; |
| 1063 | |
| 1064 | // ensure that we have the right number of items on the pages |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 1065 | final int numPages = getPageCount(); |
| 1066 | final int numCells = mCellCountX * mCellCountY; |
| 1067 | final int startIndex = page * numCells; |
| 1068 | final int endIndex = Math.min(startIndex + numCells, mApps.size()); |
| 1069 | final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 1070 | // TODO: we can optimize by just re-applying to existing views |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 1071 | layout.removeAllViewsOnPage(); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 1072 | for (int i = startIndex; i < endIndex; ++i) { |
| 1073 | final ApplicationInfo info = mApps.get(i); |
| 1074 | PagedViewIcon icon = (PagedViewIcon) mInflater.inflate( |
| 1075 | R.layout.all_apps_paged_view_application, layout, false); |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 1076 | icon.applyFromApplicationInfo(info, mPageViewIconCache, true, (numPages > 1)); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1077 | icon.setOnClickListener(this); |
Michael Jurka | 7426c42 | 2010-11-11 15:23:47 -0800 | [diff] [blame] | 1078 | icon.setOnTouchListener(this); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 1079 | icon.setOnLongClickListener(this); |
| 1080 | |
| 1081 | final int index = i - startIndex; |
| 1082 | final int x = index % mCellCountX; |
| 1083 | final int y = index / mCellCountX; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1084 | setupPage(layout); |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 1085 | layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1)); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1089 | @Override |
| 1090 | public void syncPages() { |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 1091 | boolean enforceMinimumPagedWidths = false; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1092 | boolean centerPagedViewCellLayouts = false; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1093 | switch (mCustomizationType) { |
| 1094 | case WidgetCustomization: |
| 1095 | syncWidgetPages(); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 1096 | enforceMinimumPagedWidths = true; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1097 | break; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1098 | case ShortcutCustomization: |
| 1099 | syncListPages(mShortcutList); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1100 | centerPagedViewCellLayouts = true; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1101 | break; |
| 1102 | case WallpaperCustomization: |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 1103 | syncWallpaperPages(); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 1104 | enforceMinimumPagedWidths = true; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1105 | break; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 1106 | case ApplicationCustomization: |
| 1107 | syncAppPages(); |
| 1108 | centerPagedViewCellLayouts = false; |
| 1109 | break; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1110 | default: |
| 1111 | removeAllViews(); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1112 | setCurrentPage(0); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1113 | break; |
| 1114 | } |
| 1115 | |
| 1116 | // only try and center the page if there is one page |
| 1117 | final int childCount = getChildCount(); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1118 | if (centerPagedViewCellLayouts) { |
| 1119 | if (childCount == 1) { |
| 1120 | PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(0); |
| 1121 | layout.enableCenteredContent(true); |
| 1122 | } else { |
| 1123 | for (int i = 0; i < childCount; ++i) { |
| 1124 | PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i); |
| 1125 | layout.enableCenteredContent(false); |
| 1126 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 1130 | // Set a min page width for PagedView layout if we have more than a single page |
Winson Chung | 34b23d5 | 2011-03-18 11:29:34 -0700 | [diff] [blame] | 1131 | if (enforceMinimumPagedWidths && childCount > 1) { |
| 1132 | setMinimumWidthOverride(mMinPageWidth); |
| 1133 | } else { |
| 1134 | resetMinimumWidthOverride(); |
Winson Chung | 1908d07 | 2011-02-24 18:09:44 -0800 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | // Bound the current page index |
Winson Chung | 0392977 | 2011-02-23 17:07:10 -0800 | [diff] [blame] | 1138 | requestLayout(); |
| 1139 | post(new Runnable() { |
| 1140 | @Override |
| 1141 | public void run() { |
| 1142 | setCurrentPage(Math.max(0, Math.min(childCount - 1, getCurrentPage()))); |
| 1143 | forceUpdateAdjacentPagesAlpha(); |
| 1144 | } |
| 1145 | }); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | @Override |
| 1149 | public void syncPageItems(int page) { |
| 1150 | switch (mCustomizationType) { |
| 1151 | case WidgetCustomization: |
| 1152 | syncWidgetPageItems(page); |
| 1153 | break; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1154 | case ShortcutCustomization: |
| 1155 | syncListPageItems(page, mShortcutList); |
| 1156 | break; |
| 1157 | case WallpaperCustomization: |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 1158 | syncWallpaperPageItems(page); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1159 | break; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 1160 | case ApplicationCustomization: |
| 1161 | syncAppPageItems(page); |
| 1162 | break; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1163 | } |
| 1164 | } |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1165 | |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 1166 | int getPageContentWidth() { |
| 1167 | return mPageContentWidth; |
| 1168 | } |
| 1169 | |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1170 | @Override |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1171 | protected int getAssociatedLowerPageBound(int page) { |
| 1172 | return 0; |
| 1173 | } |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1174 | @Override |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1175 | protected int getAssociatedUpperPageBound(int page) { |
| 1176 | return getChildCount(); |
| 1177 | } |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1178 | |
| 1179 | @Override |
| 1180 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
Michael Jurka | 3125d9d | 2010-09-27 11:30:20 -0700 | [diff] [blame] | 1181 | mode.setTitle(mChoiceModeTitleText); |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1182 | return true; |
| 1183 | } |
| 1184 | |
| 1185 | @Override |
| 1186 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 1187 | return true; |
| 1188 | } |
| 1189 | |
| 1190 | @Override |
| 1191 | public void onDestroyActionMode(ActionMode mode) { |
| 1192 | endChoiceMode(); |
| 1193 | } |
| 1194 | |
| 1195 | @Override |
| 1196 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 1197 | return false; |
| 1198 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1199 | } |