blob: c942b0cf97633dff30d72814b22eaee60e8bb5ab [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
Winson Chung4dbea792011-05-05 14:21:32 -0700304 LauncherModel.ShortcutNameComparator resolveInfoComparator =
305 new LauncherModel.ShortcutNameComparator(mPackageManager);
Winson Chung80baf5a2010-08-09 16:03:15 -0700306
Winson Chung80baf5a2010-08-09 16:03:15 -0700307 // get the list of shortcuts
308 Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
309 mShortcutList = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
310 Collections.sort(mShortcutList, resolveInfoComparator);
311
Winson Chunge8878e32010-09-15 20:37:09 -0700312 // get the list of wallpapers
313 Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800314 mWallpaperList = mPackageManager.queryIntentActivities(wallpapersIntent,
315 PackageManager.GET_META_DATA);
Winson Chunge8878e32010-09-15 20:37:09 -0700316 Collections.sort(mWallpaperList, resolveInfoComparator);
317
Winson Chung04998342011-01-05 13:54:43 -0800318 ArrayList<ResolveInfo> retainShortcutList = new ArrayList<ResolveInfo>(mShortcutList);
319 retainShortcutList.addAll(mWallpaperList);
320 mPageViewIconCache.retainAllShortcuts(retainShortcutList);
321 mPageViewIconCache.retainAllAppWidgets(mWidgetList);
Winson Chung80baf5a2010-08-09 16:03:15 -0700322 invalidatePageData();
323 }
324
325 public void setDragController(DragController dragger) {
326 mDragController = dragger;
327 }
328
329 public void setCustomizationFilter(CustomizationType filterType) {
Winson Chung7d1fcbc2011-01-04 10:22:20 -0800330 cancelDragging();
Winson Chung94569f42011-01-17 14:09:17 -0800331 mCustomizationType = filterType;
Winson Chunga12a2502010-12-20 14:41:35 -0800332 if (getChildCount() > 0) {
333 setCurrentPage(0);
334 updateCurrentPageScroll();
335 invalidatePageData();
Winson Chungd0d43012010-09-26 17:26:45 -0700336
Winson Chunga12a2502010-12-20 14:41:35 -0800337 // End the current choice mode so that we don't carry selections across tabs
338 endChoiceMode();
339 }
340 }
341
342 public CustomizationType getCustomizationFilter() {
343 return mCustomizationType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700344 }
345
Patrick Dubroy5f445422011-02-18 14:35:21 -0800346 /**
347 * Similar to resetCheckedGrandchildren, but allows us to specify that it's not animated.
Patrick Dubroy5f445422011-02-18 14:35:21 -0800348 */
349 private void resetCheckedItem(boolean animated) {
Patrick Dubroy6f133422011-02-24 12:16:12 -0800350 final Checkable checkable = getSingleCheckedGrandchild();
351 if (checkable != null) {
352 if (checkable instanceof PagedViewWidget) {
353 ((PagedViewWidget) checkable).setChecked(false, animated);
354 } else {
355 ((PagedViewIcon) checkable).setChecked(false, animated);
356 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800357 }
358 }
359
360 public void onDropCompleted(View target, Object dragInfo, boolean success) {
361 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
362
363 // Create a view, identical to the drag view, that is only used for animating the
364 // item onto the home screen (or back to its original position, if the drop failed).
Patrick Dubroy6f133422011-02-24 12:16:12 -0800365 final int[] pos = mDragController.getDragView().getPosition(null);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800366 final View animView = dragLayer.createDragView(mDragBitmap, pos[0], pos[1]);
367 animView.setVisibility(View.VISIBLE);
368
369 if (success) {
370 resetCheckedItem(true);
371 animateDropOntoScreen(animView, (ItemInfo) dragInfo, DROP_ANIM_DURATION, 0);
372 } else {
373 // Animate the icon/widget back to its original position
374 animateIntoPosition(animView, mDragViewOrigin[0], mDragViewOrigin[1], new Runnable() {
375 public void run() {
376 resetCheckedItem(false);
377 dragLayer.removeView(animView);
378 }
379 });
380 }
Patrick Dubroy7bccb422011-01-20 14:50:55 -0800381 mLauncher.getWorkspace().onDragStopped(success);
Winson Chung400438b2011-01-16 17:53:48 -0800382 mLauncher.unlockScreenOrientation();
Patrick Dubroy5f445422011-02-18 14:35:21 -0800383 mDragBitmap = null;
Winson Chung80baf5a2010-08-09 16:03:15 -0700384 }
385
386 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800387 public void onDragViewVisible() {
388 }
389
Patrick Dubroy5f445422011-02-18 14:35:21 -0800390 /**
391 * Animates the given item onto the center of a home screen, and then scales the item to
392 * look as though it's disappearing onto that screen.
393 */
Adam Cohen120980b2010-12-08 11:05:37 -0800394 private void animateItemOntoScreen(View dragView,
395 final CellLayout layout, final ItemInfo info) {
396 mTmpFloatPos[0] = layout.getWidth() / 2;
397 mTmpFloatPos[1] = layout.getHeight() / 2;
398 mLauncher.getWorkspace().mapPointFromChildToSelf(layout, mTmpFloatPos);
399
Adam Cohen120980b2010-12-08 11:05:37 -0800400 int dragViewWidth = dragView.getMeasuredWidth();
401 int dragViewHeight = dragView.getMeasuredHeight();
402 float heightOffset = 0;
403 float widthOffset = 0;
404
405 if (dragView instanceof ImageView) {
406 Drawable d = ((ImageView) dragView).getDrawable();
407 int width = d.getIntrinsicWidth();
408 int height = d.getIntrinsicHeight();
409
410 if ((1.0 * width / height) >= (1.0f * dragViewWidth) / dragViewHeight) {
411 float f = (dragViewWidth / (width * 1.0f));
412 heightOffset = ANIMATION_SCALE * (dragViewHeight - f * height) / 2;
413 } else {
414 float f = (dragViewHeight / (height * 1.0f));
415 widthOffset = ANIMATION_SCALE * (dragViewWidth - f * width) / 2;
416 }
417 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800418 final float toX = mTmpFloatPos[0] - dragView.getMeasuredWidth() / 2 + widthOffset;
419 final float toY = mTmpFloatPos[1] - dragView.getMeasuredHeight() / 2 + heightOffset;
Adam Cohen120980b2010-12-08 11:05:37 -0800420
Patrick Dubroy5f445422011-02-18 14:35:21 -0800421 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
422 final View dragCopy = dragLayer.createDragView(dragView);
423 dragCopy.setAlpha(1.0f);
Adam Cohen120980b2010-12-08 11:05:37 -0800424
Patrick Dubroy5f445422011-02-18 14:35:21 -0800425 // Translate the item to the center of the appropriate home screen
426 animateIntoPosition(dragCopy, toX, toY, null);
Adam Cohen120980b2010-12-08 11:05:37 -0800427
Patrick Dubroy5f445422011-02-18 14:35:21 -0800428 // The drop-onto-screen animation begins a bit later, but ends at the same time.
429 final int startDelay = TRANSLATE_ANIM_DURATION - DROP_ANIM_DURATION;
430
431 // Scale down the icon and fade out the alpha
432 animateDropOntoScreen(dragCopy, info, DROP_ANIM_DURATION, startDelay);
433 }
Adam Cohen120980b2010-12-08 11:05:37 -0800434
Patrick Dubroy5f445422011-02-18 14:35:21 -0800435 /**
436 * Animation which scales the view down and animates its alpha, making it appear to disappear
437 * onto a home screen.
438 */
439 private void animateDropOntoScreen(
440 final View view, final ItemInfo info, int duration, int delay) {
441 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
442 final CellLayout layout = mLauncher.getWorkspace().getCurrentDropLayout();
443
444 ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
Adam Cohen120980b2010-12-08 11:05:37 -0800445 PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f),
446 PropertyValuesHolder.ofFloat("scaleX", ANIMATION_SCALE),
447 PropertyValuesHolder.ofFloat("scaleY", ANIMATION_SCALE));
Patrick Dubroy5f445422011-02-18 14:35:21 -0800448 anim.setInterpolator(new LinearInterpolator());
449 if (delay > 0) {
450 anim.setStartDelay(delay);
451 }
452 anim.setDuration(duration);
453 anim.addListener(new AnimatorListenerAdapter() {
454 public void onAnimationEnd(Animator animation) {
455 dragLayer.removeView(view);
456 mLauncher.addExternalItemToScreen(info, layout);
Patrick Dubroybbaa75c2011-03-08 18:47:40 -0800457 info.dropPos = null;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800458 }
459 });
460 anim.start();
461 }
Adam Cohen120980b2010-12-08 11:05:37 -0800462
Patrick Dubroy5f445422011-02-18 14:35:21 -0800463 /**
464 * Animates the x,y position of the view, and optionally execute a Runnable on animation end.
465 */
466 private void animateIntoPosition(
467 View view, float toX, float toY, final Runnable endRunnable) {
468 ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
469 PropertyValuesHolder.ofFloat("x", toX),
470 PropertyValuesHolder.ofFloat("y", toY));
471 anim.setInterpolator(mQuintEaseOutInterpolator);
472 anim.setDuration(TRANSLATE_ANIM_DURATION);
473 if (endRunnable != null) {
474 anim.addListener(new AnimatorListenerAdapter() {
475 @Override
476 public void onAnimationEnd(Animator animation) {
477 endRunnable.run();
478 }
479 });
480 }
481 anim.start();
Adam Cohen120980b2010-12-08 11:05:37 -0800482 }
483
Patrick Dubroya669d792010-11-23 14:40:33 -0800484 @Override
Adam Cohen120980b2010-12-08 11:05:37 -0800485 public void onClick(final View v) {
Winson Chunge22a8e92010-11-12 13:40:58 -0800486 // 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
Winson Chung34b23d52011-03-18 11:29:34 -07001131 if (enforceMinimumPagedWidths && childCount > 1) {
1132 setMinimumWidthOverride(mMinPageWidth);
1133 } else {
1134 resetMinimumWidthOverride();
Winson Chung1908d072011-02-24 18:09:44 -08001135 }
1136
1137 // Bound the current page index
Winson Chung03929772011-02-23 17:07:10 -08001138 requestLayout();
1139 post(new Runnable() {
1140 @Override
1141 public void run() {
1142 setCurrentPage(Math.max(0, Math.min(childCount - 1, getCurrentPage())));
1143 forceUpdateAdjacentPagesAlpha();
1144 }
1145 });
Winson Chung80baf5a2010-08-09 16:03:15 -07001146 }
1147
1148 @Override
1149 public void syncPageItems(int page) {
1150 switch (mCustomizationType) {
1151 case WidgetCustomization:
1152 syncWidgetPageItems(page);
1153 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001154 case ShortcutCustomization:
1155 syncListPageItems(page, mShortcutList);
1156 break;
1157 case WallpaperCustomization:
Winson Chung45e1d6e2010-11-09 17:19:49 -08001158 syncWallpaperPageItems(page);
Winson Chung80baf5a2010-08-09 16:03:15 -07001159 break;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001160 case ApplicationCustomization:
1161 syncAppPageItems(page);
1162 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001163 }
1164 }
Winson Chunge3193b92010-09-10 11:44:42 -07001165
Michael Jurka7ef959b2011-02-23 11:48:32 -08001166 int getPageContentWidth() {
1167 return mPageContentWidth;
1168 }
1169
Winson Chungd0d43012010-09-26 17:26:45 -07001170 @Override
Winson Chunge3193b92010-09-10 11:44:42 -07001171 protected int getAssociatedLowerPageBound(int page) {
1172 return 0;
1173 }
Winson Chungd0d43012010-09-26 17:26:45 -07001174 @Override
Winson Chunge3193b92010-09-10 11:44:42 -07001175 protected int getAssociatedUpperPageBound(int page) {
1176 return getChildCount();
1177 }
Winson Chungd0d43012010-09-26 17:26:45 -07001178
1179 @Override
1180 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -07001181 mode.setTitle(mChoiceModeTitleText);
Winson Chungd0d43012010-09-26 17:26:45 -07001182 return true;
1183 }
1184
1185 @Override
1186 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
1187 return true;
1188 }
1189
1190 @Override
1191 public void onDestroyActionMode(ActionMode mode) {
1192 endChoiceMode();
1193 }
1194
1195 @Override
1196 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
1197 return false;
1198 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001199}