blob: 7bcfaadb24071f97c53f5eec418844be768e82e2 [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
Michael Jurka7ef959b2011-02-23 11:48:32 -0800143 private int mPageContentWidth;
144
Winson Chung80baf5a2010-08-09 16:03:15 -0700145 public CustomizePagedView(Context context) {
Winson Chunge3193b92010-09-10 11:44:42 -0700146 this(context, null, 0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700147 }
148
149 public CustomizePagedView(Context context, AttributeSet attrs) {
Winson Chunge3193b92010-09-10 11:44:42 -0700150 this(context, attrs, 0);
151 }
152
153 public CustomizePagedView(Context context, AttributeSet attrs, int defStyle) {
154 super(context, attrs, defStyle);
155
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700156 TypedArray a;
Winson Chung45e1d6e2010-11-09 17:19:49 -0800157 a = context.obtainStyledAttributes(attrs, R.styleable.CustomizePagedView, defStyle, 0);
158 mWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellSpanX, 4);
Winson Chung78bd53c2010-12-09 13:50:24 -0800159 mMaxWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellCountX, 8);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700160 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 Chung5ffd8ea2010-09-23 18:40:29 -0700165 a.recycle();
Winson Chung45e1d6e2010-11-09 17:19:49 -0800166
Winson Chung80baf5a2010-08-09 16:03:15 -0700167 mCustomizationType = CustomizationType.WidgetCustomization;
Winson Chunge3193b92010-09-10 11:44:42 -0700168 mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>();
169 mWorkspaceWidgetLayout = new PagedViewCellLayout(context);
Winson Chung80baf5a2010-08-09 16:03:15 -0700170 mInflater = LayoutInflater.from(context);
Winson Chunge3193b92010-09-10 11:44:42 -0700171
Michael Jurka7426c422010-11-11 15:23:47 -0800172 final Resources r = context.getResources();
Michael Jurka72b079e2010-12-10 01:03:53 -0800173 setDragSlopeThreshold(
174 r.getInteger(R.integer.config_customizationDrawerDragSlopeThreshold) / 100.0f);
Michael Jurka7426c422010-11-11 15:23:47 -0800175
Michael Jurka7ef959b2011-02-23 11:48:32 -0800176 // 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 Jurka0413dfa2011-04-05 16:52:32 -0700180 mMinPageWidth = layout.getWidthBeforeFirstLayout();
Michael Jurka7ef959b2011-02-23 11:48:32 -0800181
Winson Chung80baf5a2010-08-09 16:03:15 -0700182 setVisibility(View.GONE);
183 setSoundEffectsEnabled(false);
Winson Chunge3193b92010-09-10 11:44:42 -0700184 setupWorkspaceLayout();
Winson Chung80baf5a2010-08-09 16:03:15 -0700185 }
186
Winson Chung7da10252010-10-28 16:07:04 -0700187 @Override
188 protected void init() {
189 super.init();
190 mCenterPagesVertically = false;
191 }
192
Winson Chung80baf5a2010-08-09 16:03:15 -0700193 public void setLauncher(Launcher launcher) {
194 Context context = getContext();
195 mLauncher = launcher;
196 mPackageManager = context.getPackageManager();
197 }
198
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700199 /**
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 Chung5f941722010-09-28 16:36:43 -0700205
206 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800207 mPageViewIconCache.retainAllApps(list);
208 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700209 }
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 Chung5f941722010-09-28 16:36:43 -0700232
233 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800234 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700235 }
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 Chung04998342011-01-05 13:54:43 -0800249 mPageViewIconCache.removeOutline(new PagedViewIconCache.Key(info));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700250 }
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 Chung5f941722010-09-28 16:36:43 -0700259
260 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800261 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700262 }
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 Chung5f941722010-09-28 16:36:43 -0700274
275 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800276 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700277 }
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 Chung80baf5a2010-08-09 16:03:15 -0700294 public void update() {
Winson Chung80baf5a2010-08-09 16:03:15 -0700295 // 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
304 Comparator<ResolveInfo> resolveInfoComparator = new Comparator<ResolveInfo>() {
305 @Override
306 public int compare(ResolveInfo object1, ResolveInfo object2) {
307 return object1.loadLabel(mPackageManager).toString().compareTo(
308 object2.loadLabel(mPackageManager).toString());
309 }
310 };
311
Winson Chung80baf5a2010-08-09 16:03:15 -0700312 // get the list of shortcuts
313 Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
314 mShortcutList = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
315 Collections.sort(mShortcutList, resolveInfoComparator);
316
Winson Chunge8878e32010-09-15 20:37:09 -0700317 // get the list of wallpapers
318 Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800319 mWallpaperList = mPackageManager.queryIntentActivities(wallpapersIntent,
320 PackageManager.GET_META_DATA);
Winson Chunge8878e32010-09-15 20:37:09 -0700321 Collections.sort(mWallpaperList, resolveInfoComparator);
322
Winson Chung04998342011-01-05 13:54:43 -0800323 ArrayList<ResolveInfo> retainShortcutList = new ArrayList<ResolveInfo>(mShortcutList);
324 retainShortcutList.addAll(mWallpaperList);
325 mPageViewIconCache.retainAllShortcuts(retainShortcutList);
326 mPageViewIconCache.retainAllAppWidgets(mWidgetList);
Winson Chung80baf5a2010-08-09 16:03:15 -0700327 invalidatePageData();
328 }
329
330 public void setDragController(DragController dragger) {
331 mDragController = dragger;
332 }
333
334 public void setCustomizationFilter(CustomizationType filterType) {
Winson Chung7d1fcbc2011-01-04 10:22:20 -0800335 cancelDragging();
Winson Chung94569f42011-01-17 14:09:17 -0800336 mCustomizationType = filterType;
Winson Chunga12a2502010-12-20 14:41:35 -0800337 if (getChildCount() > 0) {
338 setCurrentPage(0);
339 updateCurrentPageScroll();
340 invalidatePageData();
Winson Chungd0d43012010-09-26 17:26:45 -0700341
Winson Chunga12a2502010-12-20 14:41:35 -0800342 // End the current choice mode so that we don't carry selections across tabs
343 endChoiceMode();
344 }
345 }
346
347 public CustomizationType getCustomizationFilter() {
348 return mCustomizationType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700349 }
350
Patrick Dubroy5f445422011-02-18 14:35:21 -0800351 /**
352 * Similar to resetCheckedGrandchildren, but allows us to specify that it's not animated.
Patrick Dubroy5f445422011-02-18 14:35:21 -0800353 */
354 private void resetCheckedItem(boolean animated) {
Patrick Dubroy6f133422011-02-24 12:16:12 -0800355 final Checkable checkable = getSingleCheckedGrandchild();
356 if (checkable != null) {
357 if (checkable instanceof PagedViewWidget) {
358 ((PagedViewWidget) checkable).setChecked(false, animated);
359 } else {
360 ((PagedViewIcon) checkable).setChecked(false, animated);
361 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800362 }
363 }
364
365 public void onDropCompleted(View target, Object dragInfo, boolean success) {
366 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
367
368 // Create a view, identical to the drag view, that is only used for animating the
369 // item onto the home screen (or back to its original position, if the drop failed).
Patrick Dubroy6f133422011-02-24 12:16:12 -0800370 final int[] pos = mDragController.getDragView().getPosition(null);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800371 final View animView = dragLayer.createDragView(mDragBitmap, pos[0], pos[1]);
372 animView.setVisibility(View.VISIBLE);
373
374 if (success) {
375 resetCheckedItem(true);
376 animateDropOntoScreen(animView, (ItemInfo) dragInfo, DROP_ANIM_DURATION, 0);
377 } else {
378 // Animate the icon/widget back to its original position
379 animateIntoPosition(animView, mDragViewOrigin[0], mDragViewOrigin[1], new Runnable() {
380 public void run() {
381 resetCheckedItem(false);
382 dragLayer.removeView(animView);
383 }
384 });
385 }
Patrick Dubroy7bccb422011-01-20 14:50:55 -0800386 mLauncher.getWorkspace().onDragStopped(success);
Winson Chung400438b2011-01-16 17:53:48 -0800387 mLauncher.unlockScreenOrientation();
Patrick Dubroy5f445422011-02-18 14:35:21 -0800388 mDragBitmap = null;
Winson Chung80baf5a2010-08-09 16:03:15 -0700389 }
390
391 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800392 public void onDragViewVisible() {
393 }
394
Patrick Dubroy5f445422011-02-18 14:35:21 -0800395 /**
396 * Animates the given item onto the center of a home screen, and then scales the item to
397 * look as though it's disappearing onto that screen.
398 */
Adam Cohen120980b2010-12-08 11:05:37 -0800399 private void animateItemOntoScreen(View dragView,
400 final CellLayout layout, final ItemInfo info) {
401 mTmpFloatPos[0] = layout.getWidth() / 2;
402 mTmpFloatPos[1] = layout.getHeight() / 2;
403 mLauncher.getWorkspace().mapPointFromChildToSelf(layout, mTmpFloatPos);
404
Adam Cohen120980b2010-12-08 11:05:37 -0800405 int dragViewWidth = dragView.getMeasuredWidth();
406 int dragViewHeight = dragView.getMeasuredHeight();
407 float heightOffset = 0;
408 float widthOffset = 0;
409
410 if (dragView instanceof ImageView) {
411 Drawable d = ((ImageView) dragView).getDrawable();
412 int width = d.getIntrinsicWidth();
413 int height = d.getIntrinsicHeight();
414
415 if ((1.0 * width / height) >= (1.0f * dragViewWidth) / dragViewHeight) {
416 float f = (dragViewWidth / (width * 1.0f));
417 heightOffset = ANIMATION_SCALE * (dragViewHeight - f * height) / 2;
418 } else {
419 float f = (dragViewHeight / (height * 1.0f));
420 widthOffset = ANIMATION_SCALE * (dragViewWidth - f * width) / 2;
421 }
422 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800423 final float toX = mTmpFloatPos[0] - dragView.getMeasuredWidth() / 2 + widthOffset;
424 final float toY = mTmpFloatPos[1] - dragView.getMeasuredHeight() / 2 + heightOffset;
Adam Cohen120980b2010-12-08 11:05:37 -0800425
Patrick Dubroy5f445422011-02-18 14:35:21 -0800426 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
427 final View dragCopy = dragLayer.createDragView(dragView);
428 dragCopy.setAlpha(1.0f);
Adam Cohen120980b2010-12-08 11:05:37 -0800429
Patrick Dubroy5f445422011-02-18 14:35:21 -0800430 // Translate the item to the center of the appropriate home screen
431 animateIntoPosition(dragCopy, toX, toY, null);
Adam Cohen120980b2010-12-08 11:05:37 -0800432
Patrick Dubroy5f445422011-02-18 14:35:21 -0800433 // The drop-onto-screen animation begins a bit later, but ends at the same time.
434 final int startDelay = TRANSLATE_ANIM_DURATION - DROP_ANIM_DURATION;
435
436 // Scale down the icon and fade out the alpha
437 animateDropOntoScreen(dragCopy, info, DROP_ANIM_DURATION, startDelay);
438 }
Adam Cohen120980b2010-12-08 11:05:37 -0800439
Patrick Dubroy5f445422011-02-18 14:35:21 -0800440 /**
441 * Animation which scales the view down and animates its alpha, making it appear to disappear
442 * onto a home screen.
443 */
444 private void animateDropOntoScreen(
445 final View view, final ItemInfo info, int duration, int delay) {
446 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
447 final CellLayout layout = mLauncher.getWorkspace().getCurrentDropLayout();
448
449 ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
Adam Cohen120980b2010-12-08 11:05:37 -0800450 PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f),
451 PropertyValuesHolder.ofFloat("scaleX", ANIMATION_SCALE),
452 PropertyValuesHolder.ofFloat("scaleY", ANIMATION_SCALE));
Patrick Dubroy5f445422011-02-18 14:35:21 -0800453 anim.setInterpolator(new LinearInterpolator());
454 if (delay > 0) {
455 anim.setStartDelay(delay);
456 }
457 anim.setDuration(duration);
458 anim.addListener(new AnimatorListenerAdapter() {
459 public void onAnimationEnd(Animator animation) {
460 dragLayer.removeView(view);
461 mLauncher.addExternalItemToScreen(info, layout);
Patrick Dubroybbaa75c2011-03-08 18:47:40 -0800462 info.dropPos = null;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800463 }
464 });
465 anim.start();
466 }
Adam Cohen120980b2010-12-08 11:05:37 -0800467
Patrick Dubroy5f445422011-02-18 14:35:21 -0800468 /**
469 * Animates the x,y position of the view, and optionally execute a Runnable on animation end.
470 */
471 private void animateIntoPosition(
472 View view, float toX, float toY, final Runnable endRunnable) {
473 ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
474 PropertyValuesHolder.ofFloat("x", toX),
475 PropertyValuesHolder.ofFloat("y", toY));
476 anim.setInterpolator(mQuintEaseOutInterpolator);
477 anim.setDuration(TRANSLATE_ANIM_DURATION);
478 if (endRunnable != null) {
479 anim.addListener(new AnimatorListenerAdapter() {
480 @Override
481 public void onAnimationEnd(Animator animation) {
482 endRunnable.run();
483 }
484 });
485 }
486 anim.start();
Adam Cohen120980b2010-12-08 11:05:37 -0800487 }
488
Patrick Dubroya669d792010-11-23 14:40:33 -0800489 @Override
Adam Cohen120980b2010-12-08 11:05:37 -0800490 public void onClick(final View v) {
Winson Chunge22a8e92010-11-12 13:40:58 -0800491 // Return early if we are still animating the pages
Winson Chung4f9e1072010-11-15 15:28:24 -0800492 if (mNextPage != INVALID_PAGE) return;
Winson Chunge8878e32010-09-15 20:37:09 -0700493
Winson Chungd0d43012010-09-26 17:26:45 -0700494 // On certain pages, we allow single tap to mark items as selected so that they can be
495 // dropped onto the mini workspaces
Michael Jurka3125d9d2010-09-27 11:30:20 -0700496 boolean enterChoiceMode = false;
Winson Chungd0d43012010-09-26 17:26:45 -0700497 switch (mCustomizationType) {
498 case WidgetCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700499 mChoiceModeTitleText = R.string.cab_widget_selection_text;
500 enterChoiceMode = true;
501 break;
Winson Chungd0d43012010-09-26 17:26:45 -0700502 case ApplicationCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700503 mChoiceModeTitleText = R.string.cab_app_selection_text;
504 enterChoiceMode = true;
505 break;
Winson Chungd0d43012010-09-26 17:26:45 -0700506 case ShortcutCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700507 mChoiceModeTitleText = R.string.cab_shortcut_selection_text;
508 enterChoiceMode = true;
509 break;
510 default:
511 break;
512 }
Winson Chungd0d43012010-09-26 17:26:45 -0700513
Michael Jurka3125d9d2010-09-27 11:30:20 -0700514 if (enterChoiceMode) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700515 final ItemInfo itemInfo = (ItemInfo) v.getTag();
Winson Chungd0d43012010-09-26 17:26:45 -0700516
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700517 Workspace w = mLauncher.getWorkspace();
518 int currentWorkspaceScreen = mLauncher.getCurrentWorkspaceScreen();
519 final CellLayout cl = (CellLayout)w.getChildAt(currentWorkspaceScreen);
Adam Cohen120980b2010-12-08 11:05:37 -0800520 final View dragView = getDragView(v);
Michael Jurkae17e19c2010-09-28 11:01:39 -0700521
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700522 animateClickFeedback(v, new Runnable() {
523 @Override
524 public void run() {
Patrick Dubroy047379a2010-12-19 22:02:04 -0800525 cl.calculateSpans(itemInfo);
526 if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) {
527 animateItemOntoScreen(dragView, cl, itemInfo);
528 } else {
529 mLauncher.showOutOfSpaceMessage();
530 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700531 }
532 });
Winson Chungd0d43012010-09-26 17:26:45 -0700533 return;
Winson Chungd0d43012010-09-26 17:26:45 -0700534 }
535
536 // Otherwise, we just handle the single click here
Winson Chunge8878e32010-09-15 20:37:09 -0700537 switch (mCustomizationType) {
538 case WallpaperCustomization:
539 // animate some feedback to the long press
Winson Chungd0d43012010-09-26 17:26:45 -0700540 final View clickView = v;
Winson Chunge8878e32010-09-15 20:37:09 -0700541 animateClickFeedback(v, new Runnable() {
542 @Override
543 public void run() {
544 // add the shortcut
Winson Chungd0d43012010-09-26 17:26:45 -0700545 ResolveInfo info = (ResolveInfo) clickView.getTag();
Winson Chung24ab2f12010-09-16 14:10:47 -0700546 Intent createWallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
547 ComponentName name = new ComponentName(info.activityInfo.packageName,
548 info.activityInfo.name);
549 createWallpapersIntent.setComponent(name);
550 mLauncher.processWallpaper(createWallpapersIntent);
Winson Chunge8878e32010-09-15 20:37:09 -0700551 }
552 });
Winson Chungd0d43012010-09-26 17:26:45 -0700553 break;
554 default:
555 break;
Winson Chunge8878e32010-09-15 20:37:09 -0700556 }
557 }
558
Winson Chung1908d072011-02-24 18:09:44 -0800559 private Bitmap drawableToBitmap(Drawable d, float scaleX, float scaleY) {
Patrick Dubroy5f445422011-02-18 14:35:21 -0800560 final Rect bounds = d.getBounds();
561 final int w = bounds.width();
562 final int h = bounds.height();
Michael Jurkac4e772e2011-02-10 13:32:01 -0800563 Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Winson Chung1908d072011-02-24 18:09:44 -0800564 renderDrawableToBitmap(d, b, 0, 0, w, h, scaleX, scaleY);
Michael Jurkaaf91de02010-11-23 16:23:58 -0800565 return b;
566 }
567
Adam Cohen120980b2010-12-08 11:05:37 -0800568 private View getDragView(View v) {
569 return (mCustomizationType == CustomizationType.WidgetCustomization) ?
570 v.findViewById(R.id.widget_preview) : v;
571 }
572
Michael Jurka72b079e2010-12-10 01:03:53 -0800573 protected boolean beginDragging(View v) {
Winson Chung304dcde2011-01-07 11:17:23 -0800574 if (!v.isInTouchMode()) return false;
575 if (!super.beginDragging(v)) return false;
576
Winson Chungd0d43012010-09-26 17:26:45 -0700577 // End the current choice mode before we start dragging anything
578 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
579 endChoiceMode();
580 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800581 final Workspace workspace = mLauncher.getWorkspace();
Winson Chung59e1f9a2010-12-21 11:31:54 -0800582 boolean result = false;
Winson Chung400438b2011-01-16 17:53:48 -0800583 mLauncher.lockScreenOrientation();
Winson Chung80baf5a2010-08-09 16:03:15 -0700584 switch (mCustomizationType) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800585 case WidgetCustomization: {
Winson Chung94569f42011-01-17 14:09:17 -0800586 if (v instanceof PagedViewWidget) {
587 // Get the widget preview as the drag representation
588 final LinearLayout l = (LinearLayout) v;
589 final ImageView i = (ImageView) l.findViewById(R.id.widget_preview);
Winson Chung1908d072011-02-24 18:09:44 -0800590
591 // Calculate how much to scale the drag preview
592 RectF tmpScaleRect = new RectF(0,0,1,1);
593 i.getImageMatrix().mapRect(tmpScaleRect);
594
595 mDragBitmap = drawableToBitmap(i.getDrawable(), tmpScaleRect.right,
596 tmpScaleRect.bottom);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800597 i.getLocationOnScreen(mDragViewOrigin);
Winson Chung94569f42011-01-17 14:09:17 -0800598 PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag();
Michael Jurkaa63c4522010-08-19 13:52:27 -0700599
Patrick Dubroy5f445422011-02-18 14:35:21 -0800600 int[] spanXY = CellLayout.rectToCell(getResources(),
601 createWidgetInfo.minWidth, createWidgetInfo.minHeight, null);
Winson Chung94569f42011-01-17 14:09:17 -0800602 createWidgetInfo.spanX = spanXY[0];
603 createWidgetInfo.spanY = spanXY[1];
Patrick Dubroy5f445422011-02-18 14:35:21 -0800604 workspace.onDragStartedWithItemSpans(spanXY[0], spanXY[1], mDragBitmap);
605 mDragController.startDrag(i, mDragBitmap, this, createWidgetInfo,
606 DragController.DRAG_ACTION_COPY, null);
Winson Chung94569f42011-01-17 14:09:17 -0800607 result = true;
608 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800609 break;
Michael Jurkad3ef3062010-11-23 16:23:58 -0800610 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800611 case ShortcutCustomization:
Michael Jurkad3ef3062010-11-23 16:23:58 -0800612 case ApplicationCustomization: {
Winson Chung94569f42011-01-17 14:09:17 -0800613 if (v instanceof PagedViewIcon) {
Winson Chung94569f42011-01-17 14:09:17 -0800614 // get icon (top compound drawable, index is 1)
615 final TextView tv = (TextView) v;
616 final Drawable icon = tv.getCompoundDrawables()[1];
Winson Chung1908d072011-02-24 18:09:44 -0800617 mDragBitmap = drawableToBitmap(icon, 1.0f, 1.0f);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700618
Patrick Dubroy5f445422011-02-18 14:35:21 -0800619 Object dragInfo = v.getTag();
620 if (mCustomizationType == CustomizationType.ApplicationCustomization) {
621 // TODO: Not sure why we have to copy this
622 dragInfo = new ApplicationInfo((ApplicationInfo) dragInfo);
623 }
624 workspace.onDragStartedWithItemSpans(1, 1, mDragBitmap);
625
626 // Calculate where to place the drag view in order to align the icon pixels with
627 // the original view.
628 v.getLocationOnScreen(mDragViewOrigin);
629 mDragViewOrigin[0] += (v.getWidth() - icon.getIntrinsicWidth()) / 2;
630 mDragViewOrigin[1] += v.getPaddingTop();
631
632 mDragController.startDrag(mDragBitmap, mDragViewOrigin[0], mDragViewOrigin[1],
633 this, dragInfo, DragController.DRAG_ACTION_COPY);
Winson Chung94569f42011-01-17 14:09:17 -0800634 result = true;
635 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800636 break;
Winson Chung80baf5a2010-08-09 16:03:15 -0700637 }
Michael Jurkad3ef3062010-11-23 16:23:58 -0800638 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800639
640 // We toggle the checked state _after_ we create the view for the drag in case toggling the
641 // checked state changes the view's look
Winson Chung94569f42011-01-17 14:09:17 -0800642 if (result && (v instanceof Checkable)) {
Winson Chung59e1f9a2010-12-21 11:31:54 -0800643 // In preparation for drag, we always reset the checked grand children regardless of
644 // what choice mode we are in
645 resetCheckedGrandchildren();
646
647 // Toggle the selection on the dragged app
648 Checkable checkable = (Checkable) v;
649
650 // Note: we toggle the checkable state to actually cause an alpha fade for the duration
651 // of the drag of the item. (The fade-in will occur when all checked states are
652 // disabled when dragging ends)
653 checkable.toggle();
654 }
655
656 return result;
Winson Chung80baf5a2010-08-09 16:03:15 -0700657 }
658
Winson Chunge3193b92010-09-10 11:44:42 -0700659 /**
660 * Pre-processes the layout of the different widget pages.
661 * @return the number of pages of widgets that we have
662 */
Winson Chung80baf5a2010-08-09 16:03:15 -0700663 private int relayoutWidgets() {
Winson Chunge3193b92010-09-10 11:44:42 -0700664 if (mWidgetList.isEmpty()) return 0;
Winson Chung80baf5a2010-08-09 16:03:15 -0700665
Winson Chunge3193b92010-09-10 11:44:42 -0700666 // create a new page for the first set of widgets
667 ArrayList<AppWidgetProviderInfo> newPage = new ArrayList<AppWidgetProviderInfo>();
Winson Chung80baf5a2010-08-09 16:03:15 -0700668 mWidgetPages.clear();
Winson Chunge3193b92010-09-10 11:44:42 -0700669 mWidgetPages.add(newPage);
670
671 // do this until we have no more widgets to lay out
672 final int maxNumCellsPerRow = mMaxWidgetsCellHSpan;
673 final int widgetCount = mWidgetList.size();
674 int numCellsInRow = 0;
Winson Chung80baf5a2010-08-09 16:03:15 -0700675 for (int i = 0; i < widgetCount; ++i) {
Winson Chunge3193b92010-09-10 11:44:42 -0700676 final AppWidgetProviderInfo info = mWidgetList.get(i);
Winson Chung80baf5a2010-08-09 16:03:15 -0700677
Winson Chunge3193b92010-09-10 11:44:42 -0700678 // determine the size of the current widget
679 int cellSpanX = Math.max(sMinWidgetCellHSpan, Math.min(sMaxWidgetCellHSpan,
680 mWorkspaceWidgetLayout.estimateCellHSpan(info.minWidth)));
Winson Chung80baf5a2010-08-09 16:03:15 -0700681
Winson Chunge3193b92010-09-10 11:44:42 -0700682 // create a new page if necessary
683 if ((numCellsInRow + cellSpanX) > maxNumCellsPerRow) {
684 numCellsInRow = 0;
685 newPage = new ArrayList<AppWidgetProviderInfo>();
686 mWidgetPages.add(newPage);
Winson Chung80baf5a2010-08-09 16:03:15 -0700687 }
688
Winson Chunge3193b92010-09-10 11:44:42 -0700689 // add the item to the current page
690 newPage.add(info);
691 numCellsInRow += cellSpanX;
Winson Chung80baf5a2010-08-09 16:03:15 -0700692 }
Winson Chunge3193b92010-09-10 11:44:42 -0700693
Winson Chung80baf5a2010-08-09 16:03:15 -0700694 return mWidgetPages.size();
695 }
696
Winson Chunge3193b92010-09-10 11:44:42 -0700697 /**
Winson Chung7da10252010-10-28 16:07:04 -0700698 * Helper function to draw a drawable to the specified canvas with the specified bounds.
699 */
Winson Chung1908d072011-02-24 18:09:44 -0800700 private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
701 float scaleX, float scaleY) {
Winson Chung7da10252010-10-28 16:07:04 -0700702 if (bitmap != null) mCanvas.setBitmap(bitmap);
703 mCanvas.save();
Winson Chung1908d072011-02-24 18:09:44 -0800704 mCanvas.scale(scaleX, scaleY);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800705 final Rect oldBounds = d.copyBounds();
706 d.setBounds(x, y, x + w, y + h);
Winson Chung7da10252010-10-28 16:07:04 -0700707 d.draw(mCanvas);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800708 d.setBounds(oldBounds); // Restore the bounds
Winson Chung7da10252010-10-28 16:07:04 -0700709 mCanvas.restore();
710 }
711
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800712 /*
713 * This method fetches an xml file specified in the manifest identified by
714 * WallpaperManager.WALLPAPER_PREVIEW_META_DATA). The xml file specifies
715 * an image which will be used as the wallpaper preview for an activity
716 * which responds to ACTION_SET_WALLPAPER. This image is returned and used
717 * in the customize drawer.
718 */
719 private Drawable parseWallpaperPreviewXml(ComponentName component, ResolveInfo ri) {
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800720 ActivityInfo activityInfo = ri.activityInfo;
721 XmlResourceParser parser = null;
722 try {
723 parser = activityInfo.loadXmlMetaData(mPackageManager,
724 WallpaperManager.WALLPAPER_PREVIEW_META_DATA);
725 if (parser == null) {
726 Slog.w(TAG, "No " + WallpaperManager.WALLPAPER_PREVIEW_META_DATA + " meta-data for "
727 + "wallpaper provider '" + component + '\'');
728 return null;
729 }
730
731 AttributeSet attrs = Xml.asAttributeSet(parser);
732
733 int type;
734 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
735 && type != XmlPullParser.START_TAG) {
736 // drain whitespace, comments, etc.
737 }
738
739 String nodeName = parser.getName();
740 if (!"wallpaper-preview".equals(nodeName)) {
741 Slog.w(TAG, "Meta-data does not start with wallpaper-preview tag for "
742 + "wallpaper provider '" + component + '\'');
743 return null;
744 }
745
746 // If metaData was null, we would have returned earlier when getting
747 // the parser No need to do the check here
748 Resources res = mPackageManager.getResourcesForApplication(
749 activityInfo.applicationInfo);
750
751 TypedArray sa = res.obtainAttributes(attrs,
752 com.android.internal.R.styleable.WallpaperPreviewInfo);
753
754 TypedValue value = sa.peekValue(
755 com.android.internal.R.styleable.WallpaperPreviewInfo_staticWallpaperPreview);
756 if (value == null) return null;
757
758 return res.getDrawable(value.resourceId);
759 } catch (Exception e) {
760 Slog.w(TAG, "XML parsing failed for wallpaper provider '" + component + '\'', e);
761 return null;
762 } finally {
763 if (parser != null) parser.close();
764 }
765 }
766
Winson Chung7da10252010-10-28 16:07:04 -0700767 /**
Winson Chung45e1d6e2010-11-09 17:19:49 -0800768 * This method will extract the preview image specified by the wallpaper source provider (if it
769 * exists) otherwise, it will try to generate a default image preview.
770 */
Winson Chung29d6fea2010-12-01 15:47:31 -0800771 private FastBitmapDrawable getWallpaperPreview(ResolveInfo info) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800772 // To be implemented later: resolving the up-to-date wallpaper thumbnail
773
774 final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1);
775 final int dim = mWorkspaceWidgetLayout.estimateCellWidth(mWallpaperCellHSpan);
776 Resources resources = mLauncher.getResources();
777
778 // Create a new bitmap to hold the widget preview
779 int width = (int) (dim * sScaleFactor);
780 int height = (int) (dim * sScaleFactor);
781 final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800782
783 Drawable background = parseWallpaperPreviewXml(
784 new ComponentName(info.activityInfo.packageName, info.activityInfo.name), info);
785 boolean foundCustomDrawable = background != null;
786
787 if (!foundCustomDrawable) {
788 background = resources.getDrawable(R.drawable.default_widget_preview);
789 }
790
Winson Chung1908d072011-02-24 18:09:44 -0800791 renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800792
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800793 // If we don't have a custom icon, we use the app icon on the default background
794 if (!foundCustomDrawable) {
795 try {
796 final IconCache iconCache =
797 ((LauncherApplication) mLauncher.getApplication()).getIconCache();
798 Drawable icon = new FastBitmapDrawable(Utilities.createIconBitmap(
799 iconCache.getFullResIcon(info, mPackageManager), mContext));
Winson Chung45e1d6e2010-11-09 17:19:49 -0800800
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800801 final int iconSize = minDim / 2;
802 final int offset = iconSize / 4;
Winson Chung1908d072011-02-24 18:09:44 -0800803 renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800804 } catch (Resources.NotFoundException e) {
805 // if we can't find the icon, then just don't draw it
806 }
Winson Chung45e1d6e2010-11-09 17:19:49 -0800807 }
808
Winson Chung29d6fea2010-12-01 15:47:31 -0800809 FastBitmapDrawable drawable = new FastBitmapDrawable(bitmap);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800810 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
811 return drawable;
812 }
813
814 /**
Winson Chunge3193b92010-09-10 11:44:42 -0700815 * This method will extract the preview image specified by the widget developer (if it exists),
816 * otherwise, it will try to generate a default image preview with the widget's package icon.
Winson Chung45e1d6e2010-11-09 17:19:49 -0800817 * @return the drawable that will be used and sized in the ImageView to represent the widget
Winson Chunge3193b92010-09-10 11:44:42 -0700818 */
Winson Chung29d6fea2010-12-01 15:47:31 -0800819 private FastBitmapDrawable getWidgetPreview(AppWidgetProviderInfo info) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800820 final PackageManager packageManager = mPackageManager;
Winson Chung80baf5a2010-08-09 16:03:15 -0700821 String packageName = info.provider.getPackageName();
822 Drawable drawable = null;
Winson Chung29d6fea2010-12-01 15:47:31 -0800823 FastBitmapDrawable newDrawable = null;
Winson Chung80baf5a2010-08-09 16:03:15 -0700824 if (info.previewImage != 0) {
825 drawable = packageManager.getDrawable(packageName, info.previewImage, null);
826 if (drawable == null) {
827 Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon)
828 + " for provider: " + info.provider);
Winson Chung80baf5a2010-08-09 16:03:15 -0700829 }
830 }
831
832 // If we don't have a preview image, create a default one
Winson Chung7da10252010-10-28 16:07:04 -0700833 final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1);
834 final int maxDim = mWorkspaceWidgetLayout.estimateCellWidth(3);
Winson Chung80baf5a2010-08-09 16:03:15 -0700835 if (drawable == null) {
836 Resources resources = mLauncher.getResources();
837
Winson Chung80baf5a2010-08-09 16:03:15 -0700838 // Create a new bitmap to hold the widget preview
Winson Chunge3193b92010-09-10 11:44:42 -0700839 int width = (int) (Math.max(minDim, Math.min(maxDim, info.minWidth)) * sScaleFactor);
840 int height = (int) (Math.max(minDim, Math.min(maxDim, info.minHeight)) * sScaleFactor);
Winson Chung7da10252010-10-28 16:07:04 -0700841 final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
842 final Drawable background = resources.getDrawable(R.drawable.default_widget_preview);
Winson Chung1908d072011-02-24 18:09:44 -0800843 renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700844
Winson Chung45e1d6e2010-11-09 17:19:49 -0800845 // Draw the icon flush left
Winson Chung80baf5a2010-08-09 16:03:15 -0700846 try {
Winson Chung80baf5a2010-08-09 16:03:15 -0700847 Drawable icon = null;
Winson Chunge3193b92010-09-10 11:44:42 -0700848 if (info.icon > 0) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700849 icon = packageManager.getDrawable(packageName, info.icon, null);
Winson Chung5f941722010-09-28 16:36:43 -0700850 }
851 if (icon == null) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700852 icon = resources.getDrawable(R.drawable.ic_launcher_application);
853 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700854
Winson Chunge3193b92010-09-10 11:44:42 -0700855 final int iconSize = minDim / 2;
856 final int offset = iconSize / 4;
Winson Chung1908d072011-02-24 18:09:44 -0800857 renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700858 } catch (Resources.NotFoundException e) {
859 // if we can't find the icon, then just don't draw it
860 }
861
Winson Chung29d6fea2010-12-01 15:47:31 -0800862 newDrawable = new FastBitmapDrawable(bitmap);
Winson Chung7da10252010-10-28 16:07:04 -0700863 } else {
864 // Scale down the preview if necessary
Winson Chung94ba5b12010-11-08 17:17:47 -0800865 final float imageWidth = drawable.getIntrinsicWidth();
866 final float imageHeight = drawable.getIntrinsicHeight();
867 final float aspect = (float) imageWidth / imageHeight;
868 final int scaledWidth =
869 (int) (Math.max(minDim, Math.min(maxDim, imageWidth)) * sScaleFactor);
870 final int scaledHeight =
871 (int) (Math.max(minDim, Math.min(maxDim, imageHeight)) * sScaleFactor);
Winson Chung7da10252010-10-28 16:07:04 -0700872 int width;
873 int height;
Winson Chung94ba5b12010-11-08 17:17:47 -0800874 if (aspect >= 1.0f) {
Winson Chung7da10252010-10-28 16:07:04 -0700875 width = scaledWidth;
Winson Chung94ba5b12010-11-08 17:17:47 -0800876 height = (int) (((float) scaledWidth / imageWidth) * imageHeight);
Winson Chung7da10252010-10-28 16:07:04 -0700877 } else {
878 height = scaledHeight;
Winson Chung94ba5b12010-11-08 17:17:47 -0800879 width = (int) (((float) scaledHeight / imageHeight) * imageWidth);
Winson Chung7da10252010-10-28 16:07:04 -0700880 }
881
882 final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Winson Chung1908d072011-02-24 18:09:44 -0800883 renderDrawableToBitmap(drawable, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung7da10252010-10-28 16:07:04 -0700884
Winson Chung29d6fea2010-12-01 15:47:31 -0800885 newDrawable = new FastBitmapDrawable(bitmap);
Winson Chung80baf5a2010-08-09 16:03:15 -0700886 }
Winson Chung29d6fea2010-12-01 15:47:31 -0800887 newDrawable.setBounds(0, 0, newDrawable.getIntrinsicWidth(),
888 newDrawable.getIntrinsicHeight());
889 return newDrawable;
Winson Chung80baf5a2010-08-09 16:03:15 -0700890 }
891
892 private void setupPage(PagedViewCellLayout layout) {
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700893 layout.setCellCount(mCellCountX, mCellCountY);
894 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight,
895 mPageLayoutPaddingBottom);
Winson Chungef0066b2010-10-21 11:55:00 -0700896 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung80baf5a2010-08-09 16:03:15 -0700897 }
898
Winson Chunge3193b92010-09-10 11:44:42 -0700899 private void setupWorkspaceLayout() {
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700900 mWorkspaceWidgetLayout.setCellCount(mCellCountX, mCellCountY);
Winson Chunge3193b92010-09-10 11:44:42 -0700901 mWorkspaceWidgetLayout.setPadding(20, 10, 20, 0);
902
903 mMaxWidgetWidth = mWorkspaceWidgetLayout.estimateCellWidth(sMaxWidgetCellHSpan);
904 }
905
Winson Chung80baf5a2010-08-09 16:03:15 -0700906 private void syncWidgetPages() {
907 if (mWidgetList == null) return;
908
Winson Chunge3193b92010-09-10 11:44:42 -0700909 // we need to repopulate with the LinearLayout layout for the widget pages
910 removeAllViews();
Winson Chung80baf5a2010-08-09 16:03:15 -0700911 int numPages = relayoutWidgets();
Winson Chunge3193b92010-09-10 11:44:42 -0700912 for (int i = 0; i < numPages; ++i) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800913 LinearLayout layout = new PagedViewExtendedLayout(getContext());
Winson Chunge3193b92010-09-10 11:44:42 -0700914 layout.setGravity(Gravity.CENTER_HORIZONTAL);
Winson Chungef0066b2010-10-21 11:55:00 -0700915 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
916 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chunge3193b92010-09-10 11:44:42 -0700917
Winson Chunge22a8e92010-11-12 13:40:58 -0800918 addView(layout, new LinearLayout.LayoutParams(
919 LinearLayout.LayoutParams.WRAP_CONTENT,
920 LinearLayout.LayoutParams.MATCH_PARENT));
Winson Chung80baf5a2010-08-09 16:03:15 -0700921 }
922 }
923
924 private void syncWidgetPageItems(int page) {
925 // ensure that we have the right number of items on the pages
Winson Chunge3193b92010-09-10 11:44:42 -0700926 LinearLayout layout = (LinearLayout) getChildAt(page);
927 final ArrayList<AppWidgetProviderInfo> list = mWidgetPages.get(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700928 final int count = list.size();
Winson Chung04998342011-01-05 13:54:43 -0800929 final int numPages = getPageCount();
Winson Chung80baf5a2010-08-09 16:03:15 -0700930 layout.removeAllViews();
931 for (int i = 0; i < count; ++i) {
Winson Chung68846fd2010-10-29 11:00:27 -0700932 final AppWidgetProviderInfo info = (AppWidgetProviderInfo) list.get(i);
933 final PendingAddWidgetInfo createItemInfo = new PendingAddWidgetInfo(info, null, null);
Winson Chung29d6fea2010-12-01 15:47:31 -0800934 final int[] cellSpans = CellLayout.rectToCell(getResources(), info.minWidth,
935 info.minHeight, null);
936 final FastBitmapDrawable icon = getWidgetPreview(info);
Winson Chungd0d43012010-09-26 17:26:45 -0700937
Winson Chung29d6fea2010-12-01 15:47:31 -0800938 PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
Winson Chunge3193b92010-09-10 11:44:42 -0700939 R.layout.customize_paged_view_widget, layout, false);
Winson Chung1908d072011-02-24 18:09:44 -0800940
Winson Chung04998342011-01-05 13:54:43 -0800941 l.applyFromAppWidgetProviderInfo(info, icon, mMaxWidgetWidth, cellSpans,
942 mPageViewIconCache, (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -0700943 l.setTag(createItemInfo);
944 l.setOnClickListener(this);
Michael Jurka7426c422010-11-11 15:23:47 -0800945 l.setOnTouchListener(this);
Winson Chunge3193b92010-09-10 11:44:42 -0700946 l.setOnLongClickListener(this);
Winson Chung80baf5a2010-08-09 16:03:15 -0700947
Winson Chunge3193b92010-09-10 11:44:42 -0700948 layout.addView(l);
Winson Chung80baf5a2010-08-09 16:03:15 -0700949 }
950 }
951
Winson Chung45e1d6e2010-11-09 17:19:49 -0800952 private void syncWallpaperPages() {
953 if (mWallpaperList == null) return;
954
955 // We need to repopulate the LinearLayout for the wallpaper pages
956 removeAllViews();
957 int numPages = (int) Math.ceil((float) (mWallpaperList.size() * mWallpaperCellHSpan) /
Winson Chung78bd53c2010-12-09 13:50:24 -0800958 mMaxWallpaperCellHSpan);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800959 for (int i = 0; i < numPages; ++i) {
960 LinearLayout layout = new PagedViewExtendedLayout(getContext());
961 layout.setGravity(Gravity.CENTER_HORIZONTAL);
962 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
963 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
964
Winson Chunge22a8e92010-11-12 13:40:58 -0800965 addView(layout, new LinearLayout.LayoutParams(
966 LinearLayout.LayoutParams.WRAP_CONTENT,
967 LinearLayout.LayoutParams.MATCH_PARENT));
Winson Chung45e1d6e2010-11-09 17:19:49 -0800968 }
969 }
970
971 private void syncWallpaperPageItems(int page) {
972 // Load the items on to the pages
973 LinearLayout layout = (LinearLayout) getChildAt(page);
974 layout.removeAllViews();
975 final int count = mWallpaperList.size();
Winson Chung04998342011-01-05 13:54:43 -0800976 final int numPages = getPageCount();
Winson Chung78bd53c2010-12-09 13:50:24 -0800977 final int numItemsPerPage = mMaxWallpaperCellHSpan / mWallpaperCellHSpan;
Winson Chungd28ed492010-11-22 14:34:57 -0800978 final int startIndex = page * numItemsPerPage;
979 final int endIndex = Math.min(count, startIndex + numItemsPerPage);
980 for (int i = startIndex; i < endIndex; ++i) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800981 final ResolveInfo info = mWallpaperList.get(i);
Winson Chung29d6fea2010-12-01 15:47:31 -0800982 final FastBitmapDrawable icon = getWallpaperPreview(info);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800983
Winson Chung29d6fea2010-12-01 15:47:31 -0800984 PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
Winson Chung45e1d6e2010-11-09 17:19:49 -0800985 R.layout.customize_paged_view_wallpaper, layout, false);
Winson Chung04998342011-01-05 13:54:43 -0800986 l.applyFromWallpaperInfo(info, mPackageManager, icon, mMaxWidgetWidth,
987 mPageViewIconCache, (numPages > 1));
Winson Chung45e1d6e2010-11-09 17:19:49 -0800988 l.setTag(info);
989 l.setOnClickListener(this);
990
Winson Chung45e1d6e2010-11-09 17:19:49 -0800991 layout.addView(l);
992 }
993 }
994
Winson Chung80baf5a2010-08-09 16:03:15 -0700995 private void syncListPages(List<ResolveInfo> list) {
Winson Chunge3193b92010-09-10 11:44:42 -0700996 // we need to repopulate with PagedViewCellLayouts
997 removeAllViews();
998
Winson Chung80baf5a2010-08-09 16:03:15 -0700999 // ensure that we have the right number of pages
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001000 int numPages = (int) Math.ceil((float) list.size() / (mCellCountX * mCellCountY));
Winson Chunge3193b92010-09-10 11:44:42 -07001001 for (int i = 0; i < numPages; ++i) {
Winson Chung80baf5a2010-08-09 16:03:15 -07001002 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
1003 setupPage(layout);
1004 addView(layout);
1005 }
1006 }
1007
1008 private void syncListPageItems(int page, List<ResolveInfo> list) {
1009 // ensure that we have the right number of items on the pages
Winson Chung04998342011-01-05 13:54:43 -08001010 final int numPages = getPageCount();
1011 final int numCells = mCellCountX * mCellCountY;
1012 final int startIndex = page * numCells;
1013 final int endIndex = Math.min(startIndex + numCells, list.size());
1014 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -07001015 // TODO: we can optimize by just re-applying to existing views
Michael Jurka8245a862011-02-01 17:53:59 -08001016 layout.removeAllViewsOnPage();
Winson Chung80baf5a2010-08-09 16:03:15 -07001017 for (int i = startIndex; i < endIndex; ++i) {
1018 ResolveInfo info = list.get(i);
Winson Chungd0d43012010-09-26 17:26:45 -07001019 PendingAddItemInfo createItemInfo = new PendingAddItemInfo();
1020
Winson Chung241c3b42010-08-25 16:53:03 -07001021 PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
1022 R.layout.customize_paged_view_item, layout, false);
Michael Jurkac9a96192010-11-01 11:52:08 -07001023 icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache,
Winson Chung04998342011-01-05 13:54:43 -08001024 ((LauncherApplication) mLauncher.getApplication()).getIconCache(),
1025 (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -07001026 switch (mCustomizationType) {
1027 case WallpaperCustomization:
Winson Chunge8878e32010-09-15 20:37:09 -07001028 icon.setOnClickListener(this);
Winson Chungd0d43012010-09-26 17:26:45 -07001029 break;
Winson Chungd0d43012010-09-26 17:26:45 -07001030 case ShortcutCustomization:
1031 createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
1032 createItemInfo.componentName = new ComponentName(info.activityInfo.packageName,
1033 info.activityInfo.name);
1034 icon.setTag(createItemInfo);
1035 icon.setOnClickListener(this);
Michael Jurka7426c422010-11-11 15:23:47 -08001036 icon.setOnTouchListener(this);
Winson Chungd0d43012010-09-26 17:26:45 -07001037 icon.setOnLongClickListener(this);
1038 break;
1039 default:
1040 break;
Winson Chunge8878e32010-09-15 20:37:09 -07001041 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001042
1043 final int index = i - startIndex;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001044 final int x = index % mCellCountX;
1045 final int y = index / mCellCountX;
1046 setupPage(layout);
1047 layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
1048 }
1049 }
1050
1051 private void syncAppPages() {
1052 if (mApps == null) return;
1053
1054 // We need to repopulate with PagedViewCellLayouts
1055 removeAllViews();
1056
1057 // Ensure that we have the right number of pages
1058 int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
1059 for (int i = 0; i < numPages; ++i) {
1060 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
1061 setupPage(layout);
1062 addView(layout);
1063 }
1064 }
1065
1066 private void syncAppPageItems(int page) {
1067 if (mApps == null) return;
1068
1069 // ensure that we have the right number of items on the pages
Winson Chung04998342011-01-05 13:54:43 -08001070 final int numPages = getPageCount();
1071 final int numCells = mCellCountX * mCellCountY;
1072 final int startIndex = page * numCells;
1073 final int endIndex = Math.min(startIndex + numCells, mApps.size());
1074 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001075 // TODO: we can optimize by just re-applying to existing views
Michael Jurka8245a862011-02-01 17:53:59 -08001076 layout.removeAllViewsOnPage();
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001077 for (int i = startIndex; i < endIndex; ++i) {
1078 final ApplicationInfo info = mApps.get(i);
1079 PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
1080 R.layout.all_apps_paged_view_application, layout, false);
Michael Jurkab9b8ce92011-05-05 15:05:07 -07001081 icon.applyFromApplicationInfo(
1082 info, mPageViewIconCache, true, isHardwareAccelerated() && (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -07001083 icon.setOnClickListener(this);
Michael Jurka7426c422010-11-11 15:23:47 -08001084 icon.setOnTouchListener(this);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001085 icon.setOnLongClickListener(this);
1086
1087 final int index = i - startIndex;
1088 final int x = index % mCellCountX;
1089 final int y = index / mCellCountX;
Winson Chunge3193b92010-09-10 11:44:42 -07001090 setupPage(layout);
Winson Chung241c3b42010-08-25 16:53:03 -07001091 layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
Winson Chung80baf5a2010-08-09 16:03:15 -07001092 }
1093 }
1094
Winson Chung80baf5a2010-08-09 16:03:15 -07001095 @Override
1096 public void syncPages() {
Winson Chung1908d072011-02-24 18:09:44 -08001097 boolean enforceMinimumPagedWidths = false;
Winson Chunge3193b92010-09-10 11:44:42 -07001098 boolean centerPagedViewCellLayouts = false;
Winson Chung80baf5a2010-08-09 16:03:15 -07001099 switch (mCustomizationType) {
1100 case WidgetCustomization:
1101 syncWidgetPages();
Winson Chung1908d072011-02-24 18:09:44 -08001102 enforceMinimumPagedWidths = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001103 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001104 case ShortcutCustomization:
1105 syncListPages(mShortcutList);
Winson Chunge3193b92010-09-10 11:44:42 -07001106 centerPagedViewCellLayouts = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001107 break;
1108 case WallpaperCustomization:
Winson Chung45e1d6e2010-11-09 17:19:49 -08001109 syncWallpaperPages();
Winson Chung1908d072011-02-24 18:09:44 -08001110 enforceMinimumPagedWidths = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001111 break;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001112 case ApplicationCustomization:
1113 syncAppPages();
1114 centerPagedViewCellLayouts = false;
1115 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001116 default:
1117 removeAllViews();
Winson Chung86f77532010-08-24 11:08:22 -07001118 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -07001119 break;
1120 }
1121
1122 // only try and center the page if there is one page
1123 final int childCount = getChildCount();
Winson Chunge3193b92010-09-10 11:44:42 -07001124 if (centerPagedViewCellLayouts) {
1125 if (childCount == 1) {
1126 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(0);
1127 layout.enableCenteredContent(true);
1128 } else {
1129 for (int i = 0; i < childCount; ++i) {
1130 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
1131 layout.enableCenteredContent(false);
1132 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001133 }
1134 }
1135
Winson Chung1908d072011-02-24 18:09:44 -08001136 // Set a min page width for PagedView layout if we have more than a single page
Winson Chung34b23d52011-03-18 11:29:34 -07001137 if (enforceMinimumPagedWidths && childCount > 1) {
1138 setMinimumWidthOverride(mMinPageWidth);
1139 } else {
1140 resetMinimumWidthOverride();
Winson Chung1908d072011-02-24 18:09:44 -08001141 }
1142
1143 // Bound the current page index
Winson Chung03929772011-02-23 17:07:10 -08001144 requestLayout();
1145 post(new Runnable() {
1146 @Override
1147 public void run() {
1148 setCurrentPage(Math.max(0, Math.min(childCount - 1, getCurrentPage())));
1149 forceUpdateAdjacentPagesAlpha();
1150 }
1151 });
Winson Chung80baf5a2010-08-09 16:03:15 -07001152 }
1153
1154 @Override
1155 public void syncPageItems(int page) {
1156 switch (mCustomizationType) {
1157 case WidgetCustomization:
1158 syncWidgetPageItems(page);
1159 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001160 case ShortcutCustomization:
1161 syncListPageItems(page, mShortcutList);
1162 break;
1163 case WallpaperCustomization:
Winson Chung45e1d6e2010-11-09 17:19:49 -08001164 syncWallpaperPageItems(page);
Winson Chung80baf5a2010-08-09 16:03:15 -07001165 break;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001166 case ApplicationCustomization:
1167 syncAppPageItems(page);
1168 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001169 }
1170 }
Winson Chunge3193b92010-09-10 11:44:42 -07001171
Michael Jurka7ef959b2011-02-23 11:48:32 -08001172 int getPageContentWidth() {
1173 return mPageContentWidth;
1174 }
1175
Winson Chungd0d43012010-09-26 17:26:45 -07001176 @Override
Winson Chunge3193b92010-09-10 11:44:42 -07001177 protected int getAssociatedLowerPageBound(int page) {
1178 return 0;
1179 }
Winson Chungd0d43012010-09-26 17:26:45 -07001180 @Override
Winson Chunge3193b92010-09-10 11:44:42 -07001181 protected int getAssociatedUpperPageBound(int page) {
1182 return getChildCount();
1183 }
Winson Chungd0d43012010-09-26 17:26:45 -07001184
1185 @Override
1186 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -07001187 mode.setTitle(mChoiceModeTitleText);
Winson Chungd0d43012010-09-26 17:26:45 -07001188 return true;
1189 }
1190
1191 @Override
1192 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
1193 return true;
1194 }
1195
1196 @Override
1197 public void onDestroyActionMode(ActionMode mode) {
1198 endChoiceMode();
1199 }
1200
1201 @Override
1202 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
1203 return false;
1204 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001205}