blob: 5c61b0b4af2b30300a11c2cfc5397cdd2dc5d5b8 [file] [log] [blame]
Winson Chung80baf5a2010-08-09 16:03:15 -07001/*
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
17package com.android.launcher2;
18
Michael Jurka72b079e2010-12-10 01:03:53 -080019import com.android.launcher.R;
Winson Chung80baf5a2010-08-09 16:03:15 -070020
Adam Cohen7b9d3a62010-12-07 21:49:34 -080021import org.xmlpull.v1.XmlPullParser;
22
Adam Cohen120980b2010-12-08 11:05:37 -080023import android.animation.Animator;
Patrick Dubroy047379a2010-12-19 22:02:04 -080024import android.animation.AnimatorListenerAdapter;
Adam Cohen120980b2010-12-08 11:05:37 -080025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
27import android.animation.TimeInterpolator;
Adam Cohen7b9d3a62010-12-07 21:49:34 -080028import android.app.WallpaperManager;
Winson Chung80baf5a2010-08-09 16:03:15 -070029import android.appwidget.AppWidgetManager;
30import android.appwidget.AppWidgetProviderInfo;
31import android.content.ComponentName;
32import android.content.Context;
33import android.content.Intent;
Adam Cohen7b9d3a62010-12-07 21:49:34 -080034import android.content.pm.ActivityInfo;
Winson Chung80baf5a2010-08-09 16:03:15 -070035import android.content.pm.PackageManager;
36import android.content.pm.ResolveInfo;
37import android.content.res.Resources;
Winson Chunge3193b92010-09-10 11:44:42 -070038import android.content.res.TypedArray;
Adam Cohen7b9d3a62010-12-07 21:49:34 -080039import android.content.res.XmlResourceParser;
Winson Chung80baf5a2010-08-09 16:03:15 -070040import android.graphics.Bitmap;
Winson Chungcd4bc492010-12-09 18:52:32 -080041import android.graphics.Canvas;
Patrick Dubroy5f445422011-02-18 14:35:21 -080042import android.graphics.Rect;
Winson Chung1908d072011-02-24 18:09:44 -080043import android.graphics.RectF;
Patrick Dubroy5f445422011-02-18 14:35:21 -080044import android.graphics.Bitmap.Config;
Winson Chung80baf5a2010-08-09 16:03:15 -070045import android.graphics.drawable.Drawable;
Winson Chung80baf5a2010-08-09 16:03:15 -070046import android.util.AttributeSet;
47import android.util.Log;
Adam Cohen7b9d3a62010-12-07 21:49:34 -080048import android.util.Slog;
49import android.util.TypedValue;
50import android.util.Xml;
Winson Chungd0d43012010-09-26 17:26:45 -070051import android.view.ActionMode;
Winson Chunge3193b92010-09-10 11:44:42 -070052import android.view.Gravity;
Winson Chung80baf5a2010-08-09 16:03:15 -070053import android.view.LayoutInflater;
Winson Chungd0d43012010-09-26 17:26:45 -070054import android.view.Menu;
55import android.view.MenuItem;
Winson Chung80baf5a2010-08-09 16:03:15 -070056import android.view.View;
Adam Cohen120980b2010-12-08 11:05:37 -080057import android.view.animation.DecelerateInterpolator;
Patrick Dubroy5f445422011-02-18 14:35:21 -080058import android.view.animation.LinearInterpolator;
Winson Chung59e1f9a2010-12-21 11:31:54 -080059import android.widget.Checkable;
Winson Chunge3193b92010-09-10 11:44:42 -070060import android.widget.ImageView;
61import android.widget.LinearLayout;
Michael Jurkad3ef3062010-11-23 16:23:58 -080062import android.widget.TextView;
Winson Chung80baf5a2010-08-09 16:03:15 -070063
Michael Jurka72b079e2010-12-10 01:03:53 -080064import java.util.ArrayList;
65import java.util.Collections;
66import java.util.Comparator;
67import java.util.List;
Winson Chung80baf5a2010-08-09 16:03:15 -070068
Adam Cohen7b9d3a62010-12-07 21:49:34 -080069
Michael Jurka72b079e2010-12-10 01:03:53 -080070public class CustomizePagedView extends PagedViewWithDraggableItems
71 implements View.OnClickListener, DragSource, ActionMode.Callback {
Winson Chung80baf5a2010-08-09 16:03:15 -070072
73 public enum CustomizationType {
74 WidgetCustomization,
Winson Chung80baf5a2010-08-09 16:03:15 -070075 ShortcutCustomization,
Winson Chung5ffd8ea2010-09-23 18:40:29 -070076 WallpaperCustomization,
77 ApplicationCustomization
Winson Chung80baf5a2010-08-09 16:03:15 -070078 }
79
80 private static final String TAG = "CustomizeWorkspace";
Winson Chung80baf5a2010-08-09 16:03:15 -070081
82 private Launcher mLauncher;
83 private DragController mDragController;
84 private PackageManager mPackageManager;
85
86 private CustomizationType mCustomizationType;
87
Winson Chunge3193b92010-09-10 11:44:42 -070088 // 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 Chung1908d072011-02-24 18:09:44 -080094 // 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 Chung45e1d6e2010-11-09 17:19:49 -080098 // The max dimensions for the ImageView we use for displaying a widget
Winson Chunge3193b92010-09-10 11:44:42 -070099 private int mMaxWidgetWidth;
100
Winson Chung45e1d6e2010-11-09 17:19:49 -0800101 // The max number of widget cells to take a "page" of widgets
Winson Chunge3193b92010-09-10 11:44:42 -0700102 private int mMaxWidgetsCellHSpan;
103
Winson Chung45e1d6e2010-11-09 17:19:49 -0800104 // The size of the items on the wallpaper tab
105 private int mWallpaperCellHSpan;
106
Winson Chung78bd53c2010-12-09 13:50:24 -0800107 // The max number of wallpaper cells to take a "page" of wallpaper items
108 private int mMaxWallpaperCellHSpan;
109
Winson Chunge3193b92010-09-10 11:44:42 -0700110 // The raw sources of data for each of the different tabs of the customization page
Winson Chung80baf5a2010-08-09 16:03:15 -0700111 private List<AppWidgetProviderInfo> mWidgetList;
Winson Chung80baf5a2010-08-09 16:03:15 -0700112 private List<ResolveInfo> mShortcutList;
Winson Chunge8878e32010-09-15 20:37:09 -0700113 private List<ResolveInfo> mWallpaperList;
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700114 private List<ApplicationInfo> mApps;
Winson Chung80baf5a2010-08-09 16:03:15 -0700115
Winson Chunge3193b92010-09-10 11:44:42 -0700116 private static final int sMinWidgetCellHSpan = 2;
117 private static final int sMaxWidgetCellHSpan = 4;
118
Michael Jurka3125d9d2010-09-27 11:30:20 -0700119 private int mChoiceModeTitleText;
120
Winson Chunge3193b92010-09-10 11:44:42 -0700121 // The scale factor for widget previews inside the widget drawer
122 private static final float sScaleFactor = 0.75f;
Winson Chung80baf5a2010-08-09 16:03:15 -0700123
124 private final Canvas mCanvas = new Canvas();
125 private final LayoutInflater mInflater;
126
Adam Cohen120980b2010-12-08 11:05:37 -0800127 private final float mTmpFloatPos[] = new float[2];
128 private final float ANIMATION_SCALE = 0.5f;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800129
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 Cohen120980b2010-12-08 11:05:37 -0800136 private TimeInterpolator mQuintEaseOutInterpolator = new DecelerateInterpolator(2.5f);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800137
138 // The Bitmap used to generate the drag view
139 private Bitmap mDragBitmap;
140
141 private int[] mDragViewOrigin = new int[2];
Adam Cohen120980b2010-12-08 11:05:37 -0800142
Winson Chung80baf5a2010-08-09 16:03:15 -0700143 public CustomizePagedView(Context context) {
Winson Chunge3193b92010-09-10 11:44:42 -0700144 this(context, null, 0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700145 }
146
147 public CustomizePagedView(Context context, AttributeSet attrs) {
Winson Chunge3193b92010-09-10 11:44:42 -0700148 this(context, attrs, 0);
149 }
150
151 public CustomizePagedView(Context context, AttributeSet attrs, int defStyle) {
152 super(context, attrs, defStyle);
153
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700154 TypedArray a;
Winson Chung45e1d6e2010-11-09 17:19:49 -0800155 a = context.obtainStyledAttributes(attrs, R.styleable.CustomizePagedView, defStyle, 0);
156 mWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellSpanX, 4);
Winson Chung78bd53c2010-12-09 13:50:24 -0800157 mMaxWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellCountX, 8);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700158 mMaxWidgetsCellHSpan = a.getInt(R.styleable.CustomizePagedView_widgetCellCountX, 8);
159 a.recycle();
160 a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
161 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 7);
162 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700163 a.recycle();
Winson Chung45e1d6e2010-11-09 17:19:49 -0800164
Winson Chung80baf5a2010-08-09 16:03:15 -0700165 mCustomizationType = CustomizationType.WidgetCustomization;
Winson Chunge3193b92010-09-10 11:44:42 -0700166 mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>();
167 mWorkspaceWidgetLayout = new PagedViewCellLayout(context);
Winson Chung80baf5a2010-08-09 16:03:15 -0700168 mInflater = LayoutInflater.from(context);
Winson Chunge3193b92010-09-10 11:44:42 -0700169
Michael Jurka7426c422010-11-11 15:23:47 -0800170 final Resources r = context.getResources();
Michael Jurka72b079e2010-12-10 01:03:53 -0800171 setDragSlopeThreshold(
172 r.getInteger(R.integer.config_customizationDrawerDragSlopeThreshold) / 100.0f);
Winson Chung1908d072011-02-24 18:09:44 -0800173 mMinPageWidth = r.getDimensionPixelSize(R.dimen.customization_drawer_content_min_width);
Michael Jurka7426c422010-11-11 15:23:47 -0800174
Winson Chung80baf5a2010-08-09 16:03:15 -0700175 setVisibility(View.GONE);
176 setSoundEffectsEnabled(false);
Winson Chunge3193b92010-09-10 11:44:42 -0700177 setupWorkspaceLayout();
Winson Chung80baf5a2010-08-09 16:03:15 -0700178 }
179
Winson Chung7da10252010-10-28 16:07:04 -0700180 @Override
181 protected void init() {
182 super.init();
183 mCenterPagesVertically = false;
184 }
185
Winson Chung80baf5a2010-08-09 16:03:15 -0700186 public void setLauncher(Launcher launcher) {
187 Context context = getContext();
188 mLauncher = launcher;
189 mPackageManager = context.getPackageManager();
190 }
191
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700192 /**
193 * Sets the list of applications that launcher has loaded.
194 */
195 public void setApps(ArrayList<ApplicationInfo> list) {
196 mApps = list;
197 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung5f941722010-09-28 16:36:43 -0700198
199 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800200 mPageViewIconCache.retainAllApps(list);
201 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700202 }
203
204 /**
205 * Convenience function to add new items to the set of applications that were previously loaded.
206 * Called by both updateApps() and setApps().
207 */
208 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
209 // we add it in place, in alphabetical order
210 final int count = list.size();
211 for (int i = 0; i < count; ++i) {
212 final ApplicationInfo info = list.get(i);
213 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
214 if (index < 0) {
215 mApps.add(-(index + 1), info);
216 }
217 }
218 }
219
220 /**
221 * Adds new applications to the loaded list, and notifies the paged view to update itself.
222 */
223 public void addApps(ArrayList<ApplicationInfo> list) {
224 addAppsWithoutInvalidate(list);
Winson Chung5f941722010-09-28 16:36:43 -0700225
226 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800227 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700228 }
229
230 /**
231 * Convenience function to remove items to the set of applications that were previously loaded.
232 * Called by both updateApps() and removeApps().
233 */
234 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
235 // loop through all the apps and remove apps that have the same component
236 final int length = list.size();
237 for (int i = 0; i < length; ++i) {
238 final ApplicationInfo info = list.get(i);
239 int removeIndex = findAppByComponent(mApps, info);
240 if (removeIndex > -1) {
241 mApps.remove(removeIndex);
Winson Chung04998342011-01-05 13:54:43 -0800242 mPageViewIconCache.removeOutline(new PagedViewIconCache.Key(info));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700243 }
244 }
245 }
246
247 /**
248 * Removes applications from the loaded list, and notifies the paged view to update itself.
249 */
250 public void removeApps(ArrayList<ApplicationInfo> list) {
251 removeAppsWithoutInvalidate(list);
Winson Chung5f941722010-09-28 16:36:43 -0700252
253 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800254 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700255 }
256
257 /**
258 * Updates a set of applications from the loaded list, and notifies the paged view to update
259 * itself.
260 */
261 public void updateApps(ArrayList<ApplicationInfo> list) {
262 // We remove and re-add the updated applications list because it's properties may have
263 // changed (ie. the title), and this will ensure that the items will be in their proper
264 // place in the list.
265 removeAppsWithoutInvalidate(list);
266 addAppsWithoutInvalidate(list);
Winson Chung5f941722010-09-28 16:36:43 -0700267
268 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800269 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700270 }
271
272 /**
273 * Convenience function to find matching ApplicationInfos for removal.
274 */
275 private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) {
276 ComponentName removeComponent = item.intent.getComponent();
277 final int length = list.size();
278 for (int i = 0; i < length; ++i) {
279 ApplicationInfo info = list.get(i);
280 if (info.intent.getComponent().equals(removeComponent)) {
281 return i;
282 }
283 }
284 return -1;
285 }
286
Winson Chung80baf5a2010-08-09 16:03:15 -0700287 public void update() {
Winson Chung80baf5a2010-08-09 16:03:15 -0700288 // get the list of widgets
289 mWidgetList = AppWidgetManager.getInstance(mLauncher).getInstalledProviders();
290 Collections.sort(mWidgetList, new Comparator<AppWidgetProviderInfo>() {
291 @Override
292 public int compare(AppWidgetProviderInfo object1, AppWidgetProviderInfo object2) {
293 return object1.label.compareTo(object2.label);
294 }
295 });
296
297 Comparator<ResolveInfo> resolveInfoComparator = new Comparator<ResolveInfo>() {
298 @Override
299 public int compare(ResolveInfo object1, ResolveInfo object2) {
300 return object1.loadLabel(mPackageManager).toString().compareTo(
301 object2.loadLabel(mPackageManager).toString());
302 }
303 };
304
Winson Chung80baf5a2010-08-09 16:03:15 -0700305 // get the list of shortcuts
306 Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
307 mShortcutList = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
308 Collections.sort(mShortcutList, resolveInfoComparator);
309
Winson Chunge8878e32010-09-15 20:37:09 -0700310 // get the list of wallpapers
311 Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800312 mWallpaperList = mPackageManager.queryIntentActivities(wallpapersIntent,
313 PackageManager.GET_META_DATA);
Winson Chunge8878e32010-09-15 20:37:09 -0700314 Collections.sort(mWallpaperList, resolveInfoComparator);
315
Winson Chung04998342011-01-05 13:54:43 -0800316 ArrayList<ResolveInfo> retainShortcutList = new ArrayList<ResolveInfo>(mShortcutList);
317 retainShortcutList.addAll(mWallpaperList);
318 mPageViewIconCache.retainAllShortcuts(retainShortcutList);
319 mPageViewIconCache.retainAllAppWidgets(mWidgetList);
Winson Chung80baf5a2010-08-09 16:03:15 -0700320 invalidatePageData();
321 }
322
323 public void setDragController(DragController dragger) {
324 mDragController = dragger;
325 }
326
327 public void setCustomizationFilter(CustomizationType filterType) {
Winson Chung7d1fcbc2011-01-04 10:22:20 -0800328 cancelDragging();
Winson Chung94569f42011-01-17 14:09:17 -0800329 mCustomizationType = filterType;
Winson Chunga12a2502010-12-20 14:41:35 -0800330 if (getChildCount() > 0) {
331 setCurrentPage(0);
332 updateCurrentPageScroll();
333 invalidatePageData();
Winson Chungd0d43012010-09-26 17:26:45 -0700334
Winson Chunga12a2502010-12-20 14:41:35 -0800335 // End the current choice mode so that we don't carry selections across tabs
336 endChoiceMode();
337 }
338 }
339
340 public CustomizationType getCustomizationFilter() {
341 return mCustomizationType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700342 }
343
Patrick Dubroy5f445422011-02-18 14:35:21 -0800344 /**
345 * Similar to resetCheckedGrandchildren, but allows us to specify that it's not animated.
Patrick Dubroy5f445422011-02-18 14:35:21 -0800346 */
347 private void resetCheckedItem(boolean animated) {
Patrick Dubroy6f133422011-02-24 12:16:12 -0800348 final Checkable checkable = getSingleCheckedGrandchild();
349 if (checkable != null) {
350 if (checkable instanceof PagedViewWidget) {
351 ((PagedViewWidget) checkable).setChecked(false, animated);
352 } else {
353 ((PagedViewIcon) checkable).setChecked(false, animated);
354 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800355 }
356 }
357
358 public void onDropCompleted(View target, Object dragInfo, boolean success) {
359 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
360
361 // Create a view, identical to the drag view, that is only used for animating the
362 // item onto the home screen (or back to its original position, if the drop failed).
Patrick Dubroy6f133422011-02-24 12:16:12 -0800363 final int[] pos = mDragController.getDragView().getPosition(null);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800364 final View animView = dragLayer.createDragView(mDragBitmap, pos[0], pos[1]);
365 animView.setVisibility(View.VISIBLE);
366
367 if (success) {
368 resetCheckedItem(true);
369 animateDropOntoScreen(animView, (ItemInfo) dragInfo, DROP_ANIM_DURATION, 0);
370 } else {
371 // Animate the icon/widget back to its original position
372 animateIntoPosition(animView, mDragViewOrigin[0], mDragViewOrigin[1], new Runnable() {
373 public void run() {
374 resetCheckedItem(false);
375 dragLayer.removeView(animView);
376 }
377 });
378 }
Patrick Dubroy7bccb422011-01-20 14:50:55 -0800379 mLauncher.getWorkspace().onDragStopped(success);
Winson Chung400438b2011-01-16 17:53:48 -0800380 mLauncher.unlockScreenOrientation();
Patrick Dubroy5f445422011-02-18 14:35:21 -0800381 mDragBitmap = null;
Winson Chung80baf5a2010-08-09 16:03:15 -0700382 }
383
384 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800385 public void onDragViewVisible() {
386 }
387
Patrick Dubroy5f445422011-02-18 14:35:21 -0800388 /**
389 * Animates the given item onto the center of a home screen, and then scales the item to
390 * look as though it's disappearing onto that screen.
391 */
Adam Cohen120980b2010-12-08 11:05:37 -0800392 private void animateItemOntoScreen(View dragView,
393 final CellLayout layout, final ItemInfo info) {
394 mTmpFloatPos[0] = layout.getWidth() / 2;
395 mTmpFloatPos[1] = layout.getHeight() / 2;
396 mLauncher.getWorkspace().mapPointFromChildToSelf(layout, mTmpFloatPos);
397
Adam Cohen120980b2010-12-08 11:05:37 -0800398 int dragViewWidth = dragView.getMeasuredWidth();
399 int dragViewHeight = dragView.getMeasuredHeight();
400 float heightOffset = 0;
401 float widthOffset = 0;
402
403 if (dragView instanceof ImageView) {
404 Drawable d = ((ImageView) dragView).getDrawable();
405 int width = d.getIntrinsicWidth();
406 int height = d.getIntrinsicHeight();
407
408 if ((1.0 * width / height) >= (1.0f * dragViewWidth) / dragViewHeight) {
409 float f = (dragViewWidth / (width * 1.0f));
410 heightOffset = ANIMATION_SCALE * (dragViewHeight - f * height) / 2;
411 } else {
412 float f = (dragViewHeight / (height * 1.0f));
413 widthOffset = ANIMATION_SCALE * (dragViewWidth - f * width) / 2;
414 }
415 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800416 final float toX = mTmpFloatPos[0] - dragView.getMeasuredWidth() / 2 + widthOffset;
417 final float toY = mTmpFloatPos[1] - dragView.getMeasuredHeight() / 2 + heightOffset;
Adam Cohen120980b2010-12-08 11:05:37 -0800418
Patrick Dubroy5f445422011-02-18 14:35:21 -0800419 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
420 final View dragCopy = dragLayer.createDragView(dragView);
421 dragCopy.setAlpha(1.0f);
Adam Cohen120980b2010-12-08 11:05:37 -0800422
Patrick Dubroy5f445422011-02-18 14:35:21 -0800423 // Translate the item to the center of the appropriate home screen
424 animateIntoPosition(dragCopy, toX, toY, null);
Adam Cohen120980b2010-12-08 11:05:37 -0800425
Patrick Dubroy5f445422011-02-18 14:35:21 -0800426 // The drop-onto-screen animation begins a bit later, but ends at the same time.
427 final int startDelay = TRANSLATE_ANIM_DURATION - DROP_ANIM_DURATION;
428
429 // Scale down the icon and fade out the alpha
430 animateDropOntoScreen(dragCopy, info, DROP_ANIM_DURATION, startDelay);
431 }
Adam Cohen120980b2010-12-08 11:05:37 -0800432
Patrick Dubroy5f445422011-02-18 14:35:21 -0800433 /**
434 * Animation which scales the view down and animates its alpha, making it appear to disappear
435 * onto a home screen.
436 */
437 private void animateDropOntoScreen(
438 final View view, final ItemInfo info, int duration, int delay) {
439 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
440 final CellLayout layout = mLauncher.getWorkspace().getCurrentDropLayout();
441
442 ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
Adam Cohen120980b2010-12-08 11:05:37 -0800443 PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f),
444 PropertyValuesHolder.ofFloat("scaleX", ANIMATION_SCALE),
445 PropertyValuesHolder.ofFloat("scaleY", ANIMATION_SCALE));
Patrick Dubroy5f445422011-02-18 14:35:21 -0800446 anim.setInterpolator(new LinearInterpolator());
447 if (delay > 0) {
448 anim.setStartDelay(delay);
449 }
450 anim.setDuration(duration);
451 anim.addListener(new AnimatorListenerAdapter() {
452 public void onAnimationEnd(Animator animation) {
453 dragLayer.removeView(view);
454 mLauncher.addExternalItemToScreen(info, layout);
Patrick Dubroybbaa75c2011-03-08 18:47:40 -0800455 info.dropPos = null;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800456 }
457 });
458 anim.start();
459 }
Adam Cohen120980b2010-12-08 11:05:37 -0800460
Patrick Dubroy5f445422011-02-18 14:35:21 -0800461 /**
462 * Animates the x,y position of the view, and optionally execute a Runnable on animation end.
463 */
464 private void animateIntoPosition(
465 View view, float toX, float toY, final Runnable endRunnable) {
466 ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
467 PropertyValuesHolder.ofFloat("x", toX),
468 PropertyValuesHolder.ofFloat("y", toY));
469 anim.setInterpolator(mQuintEaseOutInterpolator);
470 anim.setDuration(TRANSLATE_ANIM_DURATION);
471 if (endRunnable != null) {
472 anim.addListener(new AnimatorListenerAdapter() {
473 @Override
474 public void onAnimationEnd(Animator animation) {
475 endRunnable.run();
476 }
477 });
478 }
479 anim.start();
Adam Cohen120980b2010-12-08 11:05:37 -0800480 }
481
Patrick Dubroya669d792010-11-23 14:40:33 -0800482 @Override
Adam Cohen120980b2010-12-08 11:05:37 -0800483 public void onClick(final View v) {
Winson Chunge22a8e92010-11-12 13:40:58 -0800484 // Return early if this is not initiated from a touch
485 if (!v.isInTouchMode()) return;
486 // Return early if we are still animating the pages
Winson Chung4f9e1072010-11-15 15:28:24 -0800487 if (mNextPage != INVALID_PAGE) return;
Winson Chunge8878e32010-09-15 20:37:09 -0700488
Winson Chungd0d43012010-09-26 17:26:45 -0700489 // On certain pages, we allow single tap to mark items as selected so that they can be
490 // dropped onto the mini workspaces
Michael Jurka3125d9d2010-09-27 11:30:20 -0700491 boolean enterChoiceMode = false;
Winson Chungd0d43012010-09-26 17:26:45 -0700492 switch (mCustomizationType) {
493 case WidgetCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700494 mChoiceModeTitleText = R.string.cab_widget_selection_text;
495 enterChoiceMode = true;
496 break;
Winson Chungd0d43012010-09-26 17:26:45 -0700497 case ApplicationCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700498 mChoiceModeTitleText = R.string.cab_app_selection_text;
499 enterChoiceMode = true;
500 break;
Winson Chungd0d43012010-09-26 17:26:45 -0700501 case ShortcutCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700502 mChoiceModeTitleText = R.string.cab_shortcut_selection_text;
503 enterChoiceMode = true;
504 break;
505 default:
506 break;
507 }
Winson Chungd0d43012010-09-26 17:26:45 -0700508
Michael Jurka3125d9d2010-09-27 11:30:20 -0700509 if (enterChoiceMode) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700510 final ItemInfo itemInfo = (ItemInfo) v.getTag();
Winson Chungd0d43012010-09-26 17:26:45 -0700511
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700512 Workspace w = mLauncher.getWorkspace();
513 int currentWorkspaceScreen = mLauncher.getCurrentWorkspaceScreen();
514 final CellLayout cl = (CellLayout)w.getChildAt(currentWorkspaceScreen);
Adam Cohen120980b2010-12-08 11:05:37 -0800515 final View dragView = getDragView(v);
Michael Jurkae17e19c2010-09-28 11:01:39 -0700516
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700517 animateClickFeedback(v, new Runnable() {
518 @Override
519 public void run() {
Patrick Dubroy047379a2010-12-19 22:02:04 -0800520 cl.calculateSpans(itemInfo);
521 if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) {
522 animateItemOntoScreen(dragView, cl, itemInfo);
523 } else {
524 mLauncher.showOutOfSpaceMessage();
525 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700526 }
527 });
Winson Chungd0d43012010-09-26 17:26:45 -0700528 return;
Winson Chungd0d43012010-09-26 17:26:45 -0700529 }
530
531 // Otherwise, we just handle the single click here
Winson Chunge8878e32010-09-15 20:37:09 -0700532 switch (mCustomizationType) {
533 case WallpaperCustomization:
534 // animate some feedback to the long press
Winson Chungd0d43012010-09-26 17:26:45 -0700535 final View clickView = v;
Winson Chunge8878e32010-09-15 20:37:09 -0700536 animateClickFeedback(v, new Runnable() {
537 @Override
538 public void run() {
539 // add the shortcut
Winson Chungd0d43012010-09-26 17:26:45 -0700540 ResolveInfo info = (ResolveInfo) clickView.getTag();
Winson Chung24ab2f12010-09-16 14:10:47 -0700541 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 Chunge8878e32010-09-15 20:37:09 -0700546 }
547 });
Winson Chungd0d43012010-09-26 17:26:45 -0700548 break;
549 default:
550 break;
Winson Chunge8878e32010-09-15 20:37:09 -0700551 }
552 }
553
Winson Chung1908d072011-02-24 18:09:44 -0800554 private Bitmap drawableToBitmap(Drawable d, float scaleX, float scaleY) {
Patrick Dubroy5f445422011-02-18 14:35:21 -0800555 final Rect bounds = d.getBounds();
556 final int w = bounds.width();
557 final int h = bounds.height();
Michael Jurkac4e772e2011-02-10 13:32:01 -0800558 Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Winson Chung1908d072011-02-24 18:09:44 -0800559 renderDrawableToBitmap(d, b, 0, 0, w, h, scaleX, scaleY);
Michael Jurkaaf91de02010-11-23 16:23:58 -0800560 return b;
561 }
562
Adam Cohen120980b2010-12-08 11:05:37 -0800563 private View getDragView(View v) {
564 return (mCustomizationType == CustomizationType.WidgetCustomization) ?
565 v.findViewById(R.id.widget_preview) : v;
566 }
567
Michael Jurka72b079e2010-12-10 01:03:53 -0800568 protected boolean beginDragging(View v) {
Winson Chung304dcde2011-01-07 11:17:23 -0800569 if (!v.isInTouchMode()) return false;
570 if (!super.beginDragging(v)) return false;
571
Winson Chungd0d43012010-09-26 17:26:45 -0700572 // End the current choice mode before we start dragging anything
573 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
574 endChoiceMode();
575 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800576 final Workspace workspace = mLauncher.getWorkspace();
Winson Chung59e1f9a2010-12-21 11:31:54 -0800577 boolean result = false;
Winson Chung400438b2011-01-16 17:53:48 -0800578 mLauncher.lockScreenOrientation();
Winson Chung80baf5a2010-08-09 16:03:15 -0700579 switch (mCustomizationType) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800580 case WidgetCustomization: {
Winson Chung94569f42011-01-17 14:09:17 -0800581 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 Chung1908d072011-02-24 18:09:44 -0800585
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 Dubroy5f445422011-02-18 14:35:21 -0800592 i.getLocationOnScreen(mDragViewOrigin);
Winson Chung94569f42011-01-17 14:09:17 -0800593 PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag();
Michael Jurkaa63c4522010-08-19 13:52:27 -0700594
Patrick Dubroy5f445422011-02-18 14:35:21 -0800595 int[] spanXY = CellLayout.rectToCell(getResources(),
596 createWidgetInfo.minWidth, createWidgetInfo.minHeight, null);
Winson Chung94569f42011-01-17 14:09:17 -0800597 createWidgetInfo.spanX = spanXY[0];
598 createWidgetInfo.spanY = spanXY[1];
Patrick Dubroy5f445422011-02-18 14:35:21 -0800599 workspace.onDragStartedWithItemSpans(spanXY[0], spanXY[1], mDragBitmap);
600 mDragController.startDrag(i, mDragBitmap, this, createWidgetInfo,
601 DragController.DRAG_ACTION_COPY, null);
Winson Chung94569f42011-01-17 14:09:17 -0800602 result = true;
603 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800604 break;
Michael Jurkad3ef3062010-11-23 16:23:58 -0800605 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800606 case ShortcutCustomization:
Michael Jurkad3ef3062010-11-23 16:23:58 -0800607 case ApplicationCustomization: {
Winson Chung94569f42011-01-17 14:09:17 -0800608 if (v instanceof PagedViewIcon) {
Winson Chung94569f42011-01-17 14:09:17 -0800609 // get icon (top compound drawable, index is 1)
610 final TextView tv = (TextView) v;
611 final Drawable icon = tv.getCompoundDrawables()[1];
Winson Chung1908d072011-02-24 18:09:44 -0800612 mDragBitmap = drawableToBitmap(icon, 1.0f, 1.0f);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700613
Patrick Dubroy5f445422011-02-18 14:35:21 -0800614 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 Chung94569f42011-01-17 14:09:17 -0800629 result = true;
630 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800631 break;
Winson Chung80baf5a2010-08-09 16:03:15 -0700632 }
Michael Jurkad3ef3062010-11-23 16:23:58 -0800633 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800634
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 Chung94569f42011-01-17 14:09:17 -0800637 if (result && (v instanceof Checkable)) {
Winson Chung59e1f9a2010-12-21 11:31:54 -0800638 // 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 Chung80baf5a2010-08-09 16:03:15 -0700652 }
653
Winson Chunge3193b92010-09-10 11:44:42 -0700654 /**
655 * Pre-processes the layout of the different widget pages.
656 * @return the number of pages of widgets that we have
657 */
Winson Chung80baf5a2010-08-09 16:03:15 -0700658 private int relayoutWidgets() {
Winson Chunge3193b92010-09-10 11:44:42 -0700659 if (mWidgetList.isEmpty()) return 0;
Winson Chung80baf5a2010-08-09 16:03:15 -0700660
Winson Chunge3193b92010-09-10 11:44:42 -0700661 // create a new page for the first set of widgets
662 ArrayList<AppWidgetProviderInfo> newPage = new ArrayList<AppWidgetProviderInfo>();
Winson Chung80baf5a2010-08-09 16:03:15 -0700663 mWidgetPages.clear();
Winson Chunge3193b92010-09-10 11:44:42 -0700664 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 Chung80baf5a2010-08-09 16:03:15 -0700670 for (int i = 0; i < widgetCount; ++i) {
Winson Chunge3193b92010-09-10 11:44:42 -0700671 final AppWidgetProviderInfo info = mWidgetList.get(i);
Winson Chung80baf5a2010-08-09 16:03:15 -0700672
Winson Chunge3193b92010-09-10 11:44:42 -0700673 // determine the size of the current widget
674 int cellSpanX = Math.max(sMinWidgetCellHSpan, Math.min(sMaxWidgetCellHSpan,
675 mWorkspaceWidgetLayout.estimateCellHSpan(info.minWidth)));
Winson Chung80baf5a2010-08-09 16:03:15 -0700676
Winson Chunge3193b92010-09-10 11:44:42 -0700677 // create a new page if necessary
678 if ((numCellsInRow + cellSpanX) > maxNumCellsPerRow) {
679 numCellsInRow = 0;
680 newPage = new ArrayList<AppWidgetProviderInfo>();
681 mWidgetPages.add(newPage);
Winson Chung80baf5a2010-08-09 16:03:15 -0700682 }
683
Winson Chunge3193b92010-09-10 11:44:42 -0700684 // add the item to the current page
685 newPage.add(info);
686 numCellsInRow += cellSpanX;
Winson Chung80baf5a2010-08-09 16:03:15 -0700687 }
Winson Chunge3193b92010-09-10 11:44:42 -0700688
Winson Chung80baf5a2010-08-09 16:03:15 -0700689 return mWidgetPages.size();
690 }
691
Winson Chunge3193b92010-09-10 11:44:42 -0700692 /**
Winson Chung7da10252010-10-28 16:07:04 -0700693 * Helper function to draw a drawable to the specified canvas with the specified bounds.
694 */
Winson Chung1908d072011-02-24 18:09:44 -0800695 private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
696 float scaleX, float scaleY) {
Winson Chung7da10252010-10-28 16:07:04 -0700697 if (bitmap != null) mCanvas.setBitmap(bitmap);
698 mCanvas.save();
Winson Chung1908d072011-02-24 18:09:44 -0800699 mCanvas.scale(scaleX, scaleY);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800700 final Rect oldBounds = d.copyBounds();
701 d.setBounds(x, y, x + w, y + h);
Winson Chung7da10252010-10-28 16:07:04 -0700702 d.draw(mCanvas);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800703 d.setBounds(oldBounds); // Restore the bounds
Winson Chung7da10252010-10-28 16:07:04 -0700704 mCanvas.restore();
705 }
706
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800707 /*
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 Cohen7b9d3a62010-12-07 21:49:34 -0800715 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 Chung7da10252010-10-28 16:07:04 -0700762 /**
Winson Chung45e1d6e2010-11-09 17:19:49 -0800763 * 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 Chung29d6fea2010-12-01 15:47:31 -0800766 private FastBitmapDrawable getWallpaperPreview(ResolveInfo info) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800767 // 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 Cohen7b9d3a62010-12-07 21:49:34 -0800777
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 Chung1908d072011-02-24 18:09:44 -0800786 renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800787
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800788 // 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 Chung45e1d6e2010-11-09 17:19:49 -0800795
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800796 final int iconSize = minDim / 2;
797 final int offset = iconSize / 4;
Winson Chung1908d072011-02-24 18:09:44 -0800798 renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800799 } catch (Resources.NotFoundException e) {
800 // if we can't find the icon, then just don't draw it
801 }
Winson Chung45e1d6e2010-11-09 17:19:49 -0800802 }
803
Winson Chung29d6fea2010-12-01 15:47:31 -0800804 FastBitmapDrawable drawable = new FastBitmapDrawable(bitmap);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800805 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
806 return drawable;
807 }
808
809 /**
Winson Chunge3193b92010-09-10 11:44:42 -0700810 * 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 Chung45e1d6e2010-11-09 17:19:49 -0800812 * @return the drawable that will be used and sized in the ImageView to represent the widget
Winson Chunge3193b92010-09-10 11:44:42 -0700813 */
Winson Chung29d6fea2010-12-01 15:47:31 -0800814 private FastBitmapDrawable getWidgetPreview(AppWidgetProviderInfo info) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800815 final PackageManager packageManager = mPackageManager;
Winson Chung80baf5a2010-08-09 16:03:15 -0700816 String packageName = info.provider.getPackageName();
817 Drawable drawable = null;
Winson Chung29d6fea2010-12-01 15:47:31 -0800818 FastBitmapDrawable newDrawable = null;
Winson Chung80baf5a2010-08-09 16:03:15 -0700819 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 Chung80baf5a2010-08-09 16:03:15 -0700824 }
825 }
826
827 // If we don't have a preview image, create a default one
Winson Chung7da10252010-10-28 16:07:04 -0700828 final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1);
829 final int maxDim = mWorkspaceWidgetLayout.estimateCellWidth(3);
Winson Chung80baf5a2010-08-09 16:03:15 -0700830 if (drawable == null) {
831 Resources resources = mLauncher.getResources();
832
Winson Chung80baf5a2010-08-09 16:03:15 -0700833 // Create a new bitmap to hold the widget preview
Winson Chunge3193b92010-09-10 11:44:42 -0700834 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 Chung7da10252010-10-28 16:07:04 -0700836 final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
837 final Drawable background = resources.getDrawable(R.drawable.default_widget_preview);
Winson Chung1908d072011-02-24 18:09:44 -0800838 renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700839
Winson Chung45e1d6e2010-11-09 17:19:49 -0800840 // Draw the icon flush left
Winson Chung80baf5a2010-08-09 16:03:15 -0700841 try {
Winson Chung80baf5a2010-08-09 16:03:15 -0700842 Drawable icon = null;
Winson Chunge3193b92010-09-10 11:44:42 -0700843 if (info.icon > 0) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700844 icon = packageManager.getDrawable(packageName, info.icon, null);
Winson Chung5f941722010-09-28 16:36:43 -0700845 }
846 if (icon == null) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700847 icon = resources.getDrawable(R.drawable.ic_launcher_application);
848 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700849
Winson Chunge3193b92010-09-10 11:44:42 -0700850 final int iconSize = minDim / 2;
851 final int offset = iconSize / 4;
Winson Chung1908d072011-02-24 18:09:44 -0800852 renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700853 } catch (Resources.NotFoundException e) {
854 // if we can't find the icon, then just don't draw it
855 }
856
Winson Chung29d6fea2010-12-01 15:47:31 -0800857 newDrawable = new FastBitmapDrawable(bitmap);
Winson Chung7da10252010-10-28 16:07:04 -0700858 } else {
859 // Scale down the preview if necessary
Winson Chung94ba5b12010-11-08 17:17:47 -0800860 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 Chung7da10252010-10-28 16:07:04 -0700867 int width;
868 int height;
Winson Chung94ba5b12010-11-08 17:17:47 -0800869 if (aspect >= 1.0f) {
Winson Chung7da10252010-10-28 16:07:04 -0700870 width = scaledWidth;
Winson Chung94ba5b12010-11-08 17:17:47 -0800871 height = (int) (((float) scaledWidth / imageWidth) * imageHeight);
Winson Chung7da10252010-10-28 16:07:04 -0700872 } else {
873 height = scaledHeight;
Winson Chung94ba5b12010-11-08 17:17:47 -0800874 width = (int) (((float) scaledHeight / imageHeight) * imageWidth);
Winson Chung7da10252010-10-28 16:07:04 -0700875 }
876
877 final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Winson Chung1908d072011-02-24 18:09:44 -0800878 renderDrawableToBitmap(drawable, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung7da10252010-10-28 16:07:04 -0700879
Winson Chung29d6fea2010-12-01 15:47:31 -0800880 newDrawable = new FastBitmapDrawable(bitmap);
Winson Chung80baf5a2010-08-09 16:03:15 -0700881 }
Winson Chung29d6fea2010-12-01 15:47:31 -0800882 newDrawable.setBounds(0, 0, newDrawable.getIntrinsicWidth(),
883 newDrawable.getIntrinsicHeight());
884 return newDrawable;
Winson Chung80baf5a2010-08-09 16:03:15 -0700885 }
886
887 private void setupPage(PagedViewCellLayout layout) {
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700888 layout.setCellCount(mCellCountX, mCellCountY);
889 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight,
890 mPageLayoutPaddingBottom);
Winson Chungef0066b2010-10-21 11:55:00 -0700891 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung80baf5a2010-08-09 16:03:15 -0700892 }
893
Winson Chunge3193b92010-09-10 11:44:42 -0700894 private void setupWorkspaceLayout() {
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700895 mWorkspaceWidgetLayout.setCellCount(mCellCountX, mCellCountY);
Winson Chunge3193b92010-09-10 11:44:42 -0700896 mWorkspaceWidgetLayout.setPadding(20, 10, 20, 0);
897
898 mMaxWidgetWidth = mWorkspaceWidgetLayout.estimateCellWidth(sMaxWidgetCellHSpan);
899 }
900
Winson Chung80baf5a2010-08-09 16:03:15 -0700901 private void syncWidgetPages() {
902 if (mWidgetList == null) return;
903
Winson Chunge3193b92010-09-10 11:44:42 -0700904 // we need to repopulate with the LinearLayout layout for the widget pages
905 removeAllViews();
Winson Chung80baf5a2010-08-09 16:03:15 -0700906 int numPages = relayoutWidgets();
Winson Chunge3193b92010-09-10 11:44:42 -0700907 for (int i = 0; i < numPages; ++i) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800908 LinearLayout layout = new PagedViewExtendedLayout(getContext());
Winson Chunge3193b92010-09-10 11:44:42 -0700909 layout.setGravity(Gravity.CENTER_HORIZONTAL);
Winson Chungef0066b2010-10-21 11:55:00 -0700910 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
911 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chunge3193b92010-09-10 11:44:42 -0700912
Winson Chunge22a8e92010-11-12 13:40:58 -0800913 addView(layout, new LinearLayout.LayoutParams(
914 LinearLayout.LayoutParams.WRAP_CONTENT,
915 LinearLayout.LayoutParams.MATCH_PARENT));
Winson Chung80baf5a2010-08-09 16:03:15 -0700916 }
917 }
918
919 private void syncWidgetPageItems(int page) {
920 // ensure that we have the right number of items on the pages
Winson Chunge3193b92010-09-10 11:44:42 -0700921 LinearLayout layout = (LinearLayout) getChildAt(page);
922 final ArrayList<AppWidgetProviderInfo> list = mWidgetPages.get(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700923 final int count = list.size();
Winson Chung04998342011-01-05 13:54:43 -0800924 final int numPages = getPageCount();
Winson Chung80baf5a2010-08-09 16:03:15 -0700925 layout.removeAllViews();
926 for (int i = 0; i < count; ++i) {
Winson Chung68846fd2010-10-29 11:00:27 -0700927 final AppWidgetProviderInfo info = (AppWidgetProviderInfo) list.get(i);
928 final PendingAddWidgetInfo createItemInfo = new PendingAddWidgetInfo(info, null, null);
Winson Chung29d6fea2010-12-01 15:47:31 -0800929 final int[] cellSpans = CellLayout.rectToCell(getResources(), info.minWidth,
930 info.minHeight, null);
931 final FastBitmapDrawable icon = getWidgetPreview(info);
Winson Chungd0d43012010-09-26 17:26:45 -0700932
Winson Chung29d6fea2010-12-01 15:47:31 -0800933 PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
Winson Chunge3193b92010-09-10 11:44:42 -0700934 R.layout.customize_paged_view_widget, layout, false);
Winson Chung1908d072011-02-24 18:09:44 -0800935
Winson Chung04998342011-01-05 13:54:43 -0800936 l.applyFromAppWidgetProviderInfo(info, icon, mMaxWidgetWidth, cellSpans,
937 mPageViewIconCache, (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -0700938 l.setTag(createItemInfo);
939 l.setOnClickListener(this);
Michael Jurka7426c422010-11-11 15:23:47 -0800940 l.setOnTouchListener(this);
Winson Chunge3193b92010-09-10 11:44:42 -0700941 l.setOnLongClickListener(this);
Winson Chung80baf5a2010-08-09 16:03:15 -0700942
Winson Chunge3193b92010-09-10 11:44:42 -0700943 layout.addView(l);
Winson Chung80baf5a2010-08-09 16:03:15 -0700944 }
945 }
946
Winson Chung45e1d6e2010-11-09 17:19:49 -0800947 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 Chung78bd53c2010-12-09 13:50:24 -0800953 mMaxWallpaperCellHSpan);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800954 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 Chunge22a8e92010-11-12 13:40:58 -0800960 addView(layout, new LinearLayout.LayoutParams(
961 LinearLayout.LayoutParams.WRAP_CONTENT,
962 LinearLayout.LayoutParams.MATCH_PARENT));
Winson Chung45e1d6e2010-11-09 17:19:49 -0800963 }
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 Chung04998342011-01-05 13:54:43 -0800971 final int numPages = getPageCount();
Winson Chung78bd53c2010-12-09 13:50:24 -0800972 final int numItemsPerPage = mMaxWallpaperCellHSpan / mWallpaperCellHSpan;
Winson Chungd28ed492010-11-22 14:34:57 -0800973 final int startIndex = page * numItemsPerPage;
974 final int endIndex = Math.min(count, startIndex + numItemsPerPage);
975 for (int i = startIndex; i < endIndex; ++i) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800976 final ResolveInfo info = mWallpaperList.get(i);
Winson Chung29d6fea2010-12-01 15:47:31 -0800977 final FastBitmapDrawable icon = getWallpaperPreview(info);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800978
Winson Chung29d6fea2010-12-01 15:47:31 -0800979 PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
Winson Chung45e1d6e2010-11-09 17:19:49 -0800980 R.layout.customize_paged_view_wallpaper, layout, false);
Winson Chung04998342011-01-05 13:54:43 -0800981 l.applyFromWallpaperInfo(info, mPackageManager, icon, mMaxWidgetWidth,
982 mPageViewIconCache, (numPages > 1));
Winson Chung45e1d6e2010-11-09 17:19:49 -0800983 l.setTag(info);
984 l.setOnClickListener(this);
985
Winson Chung45e1d6e2010-11-09 17:19:49 -0800986 layout.addView(l);
987 }
988 }
989
Winson Chung80baf5a2010-08-09 16:03:15 -0700990 private void syncListPages(List<ResolveInfo> list) {
Winson Chunge3193b92010-09-10 11:44:42 -0700991 // we need to repopulate with PagedViewCellLayouts
992 removeAllViews();
993
Winson Chung80baf5a2010-08-09 16:03:15 -0700994 // ensure that we have the right number of pages
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700995 int numPages = (int) Math.ceil((float) list.size() / (mCellCountX * mCellCountY));
Winson Chunge3193b92010-09-10 11:44:42 -0700996 for (int i = 0; i < numPages; ++i) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700997 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 Chung04998342011-01-05 13:54:43 -08001005 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 Chung80baf5a2010-08-09 16:03:15 -07001010 // TODO: we can optimize by just re-applying to existing views
Michael Jurka8245a862011-02-01 17:53:59 -08001011 layout.removeAllViewsOnPage();
Winson Chung80baf5a2010-08-09 16:03:15 -07001012 for (int i = startIndex; i < endIndex; ++i) {
1013 ResolveInfo info = list.get(i);
Winson Chungd0d43012010-09-26 17:26:45 -07001014 PendingAddItemInfo createItemInfo = new PendingAddItemInfo();
1015
Winson Chung241c3b42010-08-25 16:53:03 -07001016 PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
1017 R.layout.customize_paged_view_item, layout, false);
Michael Jurkac9a96192010-11-01 11:52:08 -07001018 icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache,
Winson Chung04998342011-01-05 13:54:43 -08001019 ((LauncherApplication) mLauncher.getApplication()).getIconCache(),
1020 (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -07001021 switch (mCustomizationType) {
1022 case WallpaperCustomization:
Winson Chunge8878e32010-09-15 20:37:09 -07001023 icon.setOnClickListener(this);
Winson Chungd0d43012010-09-26 17:26:45 -07001024 break;
Winson Chungd0d43012010-09-26 17:26:45 -07001025 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 Jurka7426c422010-11-11 15:23:47 -08001031 icon.setOnTouchListener(this);
Winson Chungd0d43012010-09-26 17:26:45 -07001032 icon.setOnLongClickListener(this);
1033 break;
1034 default:
1035 break;
Winson Chunge8878e32010-09-15 20:37:09 -07001036 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001037
1038 final int index = i - startIndex;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001039 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 Chung04998342011-01-05 13:54:43 -08001065 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 Chung5ffd8ea2010-09-23 18:40:29 -07001070 // TODO: we can optimize by just re-applying to existing views
Michael Jurka8245a862011-02-01 17:53:59 -08001071 layout.removeAllViewsOnPage();
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001072 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 Chung04998342011-01-05 13:54:43 -08001076 icon.applyFromApplicationInfo(info, mPageViewIconCache, true, (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -07001077 icon.setOnClickListener(this);
Michael Jurka7426c422010-11-11 15:23:47 -08001078 icon.setOnTouchListener(this);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001079 icon.setOnLongClickListener(this);
1080
1081 final int index = i - startIndex;
1082 final int x = index % mCellCountX;
1083 final int y = index / mCellCountX;
Winson Chunge3193b92010-09-10 11:44:42 -07001084 setupPage(layout);
Winson Chung241c3b42010-08-25 16:53:03 -07001085 layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
Winson Chung80baf5a2010-08-09 16:03:15 -07001086 }
1087 }
1088
Winson Chung80baf5a2010-08-09 16:03:15 -07001089 @Override
1090 public void syncPages() {
Winson Chung1908d072011-02-24 18:09:44 -08001091 boolean enforceMinimumPagedWidths = false;
Winson Chunge3193b92010-09-10 11:44:42 -07001092 boolean centerPagedViewCellLayouts = false;
Winson Chung80baf5a2010-08-09 16:03:15 -07001093 switch (mCustomizationType) {
1094 case WidgetCustomization:
1095 syncWidgetPages();
Winson Chung1908d072011-02-24 18:09:44 -08001096 enforceMinimumPagedWidths = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001097 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001098 case ShortcutCustomization:
1099 syncListPages(mShortcutList);
Winson Chunge3193b92010-09-10 11:44:42 -07001100 centerPagedViewCellLayouts = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001101 break;
1102 case WallpaperCustomization:
Winson Chung45e1d6e2010-11-09 17:19:49 -08001103 syncWallpaperPages();
Winson Chung1908d072011-02-24 18:09:44 -08001104 enforceMinimumPagedWidths = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001105 break;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001106 case ApplicationCustomization:
1107 syncAppPages();
1108 centerPagedViewCellLayouts = false;
1109 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001110 default:
1111 removeAllViews();
Winson Chung86f77532010-08-24 11:08:22 -07001112 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -07001113 break;
1114 }
1115
1116 // only try and center the page if there is one page
1117 final int childCount = getChildCount();
Winson Chunge3193b92010-09-10 11:44:42 -07001118 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 Chung80baf5a2010-08-09 16:03:15 -07001127 }
1128 }
1129
Winson Chung1908d072011-02-24 18:09:44 -08001130 // Set a min page width for PagedView layout if we have more than a single page
1131 if (enforceMinimumPagedWidths) {
1132 setMinimumWidthOverride((childCount > 1) ? mMinPageWidth : 0);
1133 }
1134
1135 // Bound the current page index
Winson Chung03929772011-02-23 17:07:10 -08001136 requestLayout();
1137 post(new Runnable() {
1138 @Override
1139 public void run() {
1140 setCurrentPage(Math.max(0, Math.min(childCount - 1, getCurrentPage())));
1141 forceUpdateAdjacentPagesAlpha();
1142 }
1143 });
Winson Chung80baf5a2010-08-09 16:03:15 -07001144 }
1145
1146 @Override
1147 public void syncPageItems(int page) {
1148 switch (mCustomizationType) {
1149 case WidgetCustomization:
1150 syncWidgetPageItems(page);
1151 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001152 case ShortcutCustomization:
1153 syncListPageItems(page, mShortcutList);
1154 break;
1155 case WallpaperCustomization:
Winson Chung45e1d6e2010-11-09 17:19:49 -08001156 syncWallpaperPageItems(page);
Winson Chung80baf5a2010-08-09 16:03:15 -07001157 break;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001158 case ApplicationCustomization:
1159 syncAppPageItems(page);
1160 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001161 }
1162 }
Winson Chunge3193b92010-09-10 11:44:42 -07001163
Winson Chungd0d43012010-09-26 17:26:45 -07001164 @Override
Winson Chunge3193b92010-09-10 11:44:42 -07001165 protected int getAssociatedLowerPageBound(int page) {
1166 return 0;
1167 }
Winson Chungd0d43012010-09-26 17:26:45 -07001168 @Override
Winson Chunge3193b92010-09-10 11:44:42 -07001169 protected int getAssociatedUpperPageBound(int page) {
1170 return getChildCount();
1171 }
Winson Chungd0d43012010-09-26 17:26:45 -07001172
1173 @Override
1174 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -07001175 mode.setTitle(mChoiceModeTitleText);
Winson Chungd0d43012010-09-26 17:26:45 -07001176 return true;
1177 }
1178
1179 @Override
1180 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
1181 return true;
1182 }
1183
1184 @Override
1185 public void onDestroyActionMode(ActionMode mode) {
1186 endChoiceMode();
1187 }
1188
1189 @Override
1190 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
1191 return false;
1192 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001193}