blob: e80eda3a76ef1fd13dd52cab5d3be43119146a0d [file] [log] [blame]
Winson Chung80baf5a2010-08-09 16:03:15 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher2;
18
Michael Jurka72b079e2010-12-10 01:03:53 -080019import com.android.launcher.R;
Winson Chung80baf5a2010-08-09 16:03:15 -070020
Adam Cohen7b9d3a62010-12-07 21:49:34 -080021import org.xmlpull.v1.XmlPullParser;
22
Adam Cohen120980b2010-12-08 11:05:37 -080023import android.animation.Animator;
Patrick Dubroy047379a2010-12-19 22:02:04 -080024import android.animation.AnimatorListenerAdapter;
Adam Cohen120980b2010-12-08 11:05:37 -080025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
27import android.animation.TimeInterpolator;
Adam Cohen7b9d3a62010-12-07 21:49:34 -080028import android.app.WallpaperManager;
Winson Chung80baf5a2010-08-09 16:03:15 -070029import android.appwidget.AppWidgetManager;
30import android.appwidget.AppWidgetProviderInfo;
31import android.content.ComponentName;
32import android.content.Context;
33import android.content.Intent;
Adam Cohen7b9d3a62010-12-07 21:49:34 -080034import android.content.pm.ActivityInfo;
Winson Chung80baf5a2010-08-09 16:03:15 -070035import android.content.pm.PackageManager;
36import android.content.pm.ResolveInfo;
37import android.content.res.Resources;
Winson Chunge3193b92010-09-10 11:44:42 -070038import android.content.res.TypedArray;
Adam Cohen7b9d3a62010-12-07 21:49:34 -080039import android.content.res.XmlResourceParser;
Winson Chung80baf5a2010-08-09 16:03:15 -070040import android.graphics.Bitmap;
Winson Chungcd4bc492010-12-09 18:52:32 -080041import android.graphics.Canvas;
Patrick Dubroy5f445422011-02-18 14:35:21 -080042import android.graphics.Rect;
Winson Chung1908d072011-02-24 18:09:44 -080043import android.graphics.RectF;
Patrick Dubroy5f445422011-02-18 14:35:21 -080044import android.graphics.Bitmap.Config;
Winson Chung80baf5a2010-08-09 16:03:15 -070045import android.graphics.drawable.Drawable;
Winson Chung80baf5a2010-08-09 16:03:15 -070046import android.util.AttributeSet;
47import android.util.Log;
Adam Cohen7b9d3a62010-12-07 21:49:34 -080048import android.util.Slog;
49import android.util.TypedValue;
50import android.util.Xml;
Winson Chungd0d43012010-09-26 17:26:45 -070051import android.view.ActionMode;
Winson Chunge3193b92010-09-10 11:44:42 -070052import android.view.Gravity;
Winson Chung80baf5a2010-08-09 16:03:15 -070053import android.view.LayoutInflater;
Winson Chungd0d43012010-09-26 17:26:45 -070054import android.view.Menu;
55import android.view.MenuItem;
Winson Chung80baf5a2010-08-09 16:03:15 -070056import android.view.View;
Adam Cohen120980b2010-12-08 11:05:37 -080057import android.view.animation.DecelerateInterpolator;
Patrick Dubroy5f445422011-02-18 14:35:21 -080058import android.view.animation.LinearInterpolator;
Winson Chung59e1f9a2010-12-21 11:31:54 -080059import android.widget.Checkable;
Winson Chunge3193b92010-09-10 11:44:42 -070060import android.widget.ImageView;
61import android.widget.LinearLayout;
Michael Jurkad3ef3062010-11-23 16:23:58 -080062import android.widget.TextView;
Winson Chung80baf5a2010-08-09 16:03:15 -070063
Michael Jurka72b079e2010-12-10 01:03:53 -080064import java.util.ArrayList;
65import java.util.Collections;
66import java.util.Comparator;
67import java.util.List;
Winson Chung80baf5a2010-08-09 16:03:15 -070068
Adam Cohen7b9d3a62010-12-07 21:49:34 -080069
Michael Jurka72b079e2010-12-10 01:03:53 -080070public class CustomizePagedView extends PagedViewWithDraggableItems
71 implements View.OnClickListener, DragSource, ActionMode.Callback {
Winson Chung80baf5a2010-08-09 16:03:15 -070072
73 public enum CustomizationType {
74 WidgetCustomization,
Winson Chung80baf5a2010-08-09 16:03:15 -070075 ShortcutCustomization,
Winson Chung5ffd8ea2010-09-23 18:40:29 -070076 WallpaperCustomization,
77 ApplicationCustomization
Winson Chung80baf5a2010-08-09 16:03:15 -070078 }
79
80 private static final String TAG = "CustomizeWorkspace";
Winson Chung80baf5a2010-08-09 16:03:15 -070081
82 private Launcher mLauncher;
83 private DragController mDragController;
84 private PackageManager mPackageManager;
85
86 private CustomizationType mCustomizationType;
87
Winson Chunge3193b92010-09-10 11:44:42 -070088 // The layout used to emulate the workspace in resolve the cell dimensions of a widget
89 private PagedViewCellLayout mWorkspaceWidgetLayout;
90
91 // The mapping between the pages and the widgets that will be laid out on them
92 private ArrayList<ArrayList<AppWidgetProviderInfo>> mWidgetPages;
93
Winson Chung1908d072011-02-24 18:09:44 -080094 // This is used if we want to set a min width on pages so that things inside them left align to
95 // a fixed size
96 private int mMinPageWidth;
97
Winson Chung45e1d6e2010-11-09 17:19:49 -080098 // The max dimensions for the ImageView we use for displaying a widget
Winson Chunge3193b92010-09-10 11:44:42 -070099 private int mMaxWidgetWidth;
100
Winson Chung45e1d6e2010-11-09 17:19:49 -0800101 // The max number of widget cells to take a "page" of widgets
Winson Chunge3193b92010-09-10 11:44:42 -0700102 private int mMaxWidgetsCellHSpan;
103
Winson Chung45e1d6e2010-11-09 17:19:49 -0800104 // The size of the items on the wallpaper tab
105 private int mWallpaperCellHSpan;
106
Winson Chung78bd53c2010-12-09 13:50:24 -0800107 // The max number of wallpaper cells to take a "page" of wallpaper items
108 private int mMaxWallpaperCellHSpan;
109
Winson Chunge3193b92010-09-10 11:44:42 -0700110 // The raw sources of data for each of the different tabs of the customization page
Winson Chung80baf5a2010-08-09 16:03:15 -0700111 private List<AppWidgetProviderInfo> mWidgetList;
Winson Chung80baf5a2010-08-09 16:03:15 -0700112 private List<ResolveInfo> mShortcutList;
Winson Chunge8878e32010-09-15 20:37:09 -0700113 private List<ResolveInfo> mWallpaperList;
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700114 private List<ApplicationInfo> mApps;
Winson Chung80baf5a2010-08-09 16:03:15 -0700115
Winson Chunge3193b92010-09-10 11:44:42 -0700116 private static final int sMinWidgetCellHSpan = 2;
117 private static final int sMaxWidgetCellHSpan = 4;
118
Michael Jurka3125d9d2010-09-27 11:30:20 -0700119 private int mChoiceModeTitleText;
120
Winson Chunge3193b92010-09-10 11:44:42 -0700121 // The scale factor for widget previews inside the widget drawer
122 private static final float sScaleFactor = 0.75f;
Winson Chung80baf5a2010-08-09 16:03:15 -0700123
124 private final Canvas mCanvas = new Canvas();
125 private final LayoutInflater mInflater;
126
Adam Cohen120980b2010-12-08 11:05:37 -0800127 private final float mTmpFloatPos[] = new float[2];
128 private final float ANIMATION_SCALE = 0.5f;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800129
130 // The duration of the translation animation that occurs during you drag and drop
131 private final int TRANSLATE_ANIM_DURATION = 400;
132
133 // The duration of the scale & alpha animation that occurs during drag and drop
134 private final int DROP_ANIM_DURATION = 200;
135
Adam Cohen120980b2010-12-08 11:05:37 -0800136 private TimeInterpolator mQuintEaseOutInterpolator = new DecelerateInterpolator(2.5f);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800137
138 // The Bitmap used to generate the drag view
139 private Bitmap mDragBitmap;
140
141 private int[] mDragViewOrigin = new int[2];
Adam Cohen120980b2010-12-08 11:05:37 -0800142
Winson Chung80baf5a2010-08-09 16:03:15 -0700143 public CustomizePagedView(Context context) {
Winson Chunge3193b92010-09-10 11:44:42 -0700144 this(context, null, 0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700145 }
146
147 public CustomizePagedView(Context context, AttributeSet attrs) {
Winson Chunge3193b92010-09-10 11:44:42 -0700148 this(context, attrs, 0);
149 }
150
151 public CustomizePagedView(Context context, AttributeSet attrs, int defStyle) {
152 super(context, attrs, defStyle);
153
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700154 TypedArray a;
Winson Chung45e1d6e2010-11-09 17:19:49 -0800155 a = context.obtainStyledAttributes(attrs, R.styleable.CustomizePagedView, defStyle, 0);
156 mWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellSpanX, 4);
Winson Chung78bd53c2010-12-09 13:50:24 -0800157 mMaxWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellCountX, 8);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700158 mMaxWidgetsCellHSpan = a.getInt(R.styleable.CustomizePagedView_widgetCellCountX, 8);
159 a.recycle();
160 a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
161 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 7);
162 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700163 a.recycle();
Winson Chung45e1d6e2010-11-09 17:19:49 -0800164
Winson Chung80baf5a2010-08-09 16:03:15 -0700165 mCustomizationType = CustomizationType.WidgetCustomization;
Winson Chunge3193b92010-09-10 11:44:42 -0700166 mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>();
167 mWorkspaceWidgetLayout = new PagedViewCellLayout(context);
Winson Chung80baf5a2010-08-09 16:03:15 -0700168 mInflater = LayoutInflater.from(context);
Winson Chunge3193b92010-09-10 11:44:42 -0700169
Michael Jurka7426c422010-11-11 15:23:47 -0800170 final Resources r = context.getResources();
Michael Jurka72b079e2010-12-10 01:03:53 -0800171 setDragSlopeThreshold(
172 r.getInteger(R.integer.config_customizationDrawerDragSlopeThreshold) / 100.0f);
Winson Chung1908d072011-02-24 18:09:44 -0800173 mMinPageWidth = r.getDimensionPixelSize(R.dimen.customization_drawer_content_min_width);
Michael Jurka7426c422010-11-11 15:23:47 -0800174
Winson Chung80baf5a2010-08-09 16:03:15 -0700175 setVisibility(View.GONE);
176 setSoundEffectsEnabled(false);
Winson Chunge3193b92010-09-10 11:44:42 -0700177 setupWorkspaceLayout();
Winson Chung80baf5a2010-08-09 16:03:15 -0700178 }
179
Winson Chung7da10252010-10-28 16:07:04 -0700180 @Override
181 protected void init() {
182 super.init();
183 mCenterPagesVertically = false;
184 }
185
Winson Chung80baf5a2010-08-09 16:03:15 -0700186 public void setLauncher(Launcher launcher) {
187 Context context = getContext();
188 mLauncher = launcher;
189 mPackageManager = context.getPackageManager();
190 }
191
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700192 /**
193 * Sets the list of applications that launcher has loaded.
194 */
195 public void setApps(ArrayList<ApplicationInfo> list) {
196 mApps = list;
197 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung5f941722010-09-28 16:36:43 -0700198
199 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800200 mPageViewIconCache.retainAllApps(list);
201 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700202 }
203
204 /**
205 * Convenience function to add new items to the set of applications that were previously loaded.
206 * Called by both updateApps() and setApps().
207 */
208 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
209 // we add it in place, in alphabetical order
210 final int count = list.size();
211 for (int i = 0; i < count; ++i) {
212 final ApplicationInfo info = list.get(i);
213 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
214 if (index < 0) {
215 mApps.add(-(index + 1), info);
216 }
217 }
218 }
219
220 /**
221 * Adds new applications to the loaded list, and notifies the paged view to update itself.
222 */
223 public void addApps(ArrayList<ApplicationInfo> list) {
224 addAppsWithoutInvalidate(list);
Winson Chung5f941722010-09-28 16:36:43 -0700225
226 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800227 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700228 }
229
230 /**
231 * Convenience function to remove items to the set of applications that were previously loaded.
232 * Called by both updateApps() and removeApps().
233 */
234 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
235 // loop through all the apps and remove apps that have the same component
236 final int length = list.size();
237 for (int i = 0; i < length; ++i) {
238 final ApplicationInfo info = list.get(i);
239 int removeIndex = findAppByComponent(mApps, info);
240 if (removeIndex > -1) {
241 mApps.remove(removeIndex);
Winson Chung04998342011-01-05 13:54:43 -0800242 mPageViewIconCache.removeOutline(new PagedViewIconCache.Key(info));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700243 }
244 }
245 }
246
247 /**
248 * Removes applications from the loaded list, and notifies the paged view to update itself.
249 */
250 public void removeApps(ArrayList<ApplicationInfo> list) {
251 removeAppsWithoutInvalidate(list);
Winson Chung5f941722010-09-28 16:36:43 -0700252
253 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800254 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700255 }
256
257 /**
258 * Updates a set of applications from the loaded list, and notifies the paged view to update
259 * itself.
260 */
261 public void updateApps(ArrayList<ApplicationInfo> list) {
262 // We remove and re-add the updated applications list because it's properties may have
263 // changed (ie. the title), and this will ensure that the items will be in their proper
264 // place in the list.
265 removeAppsWithoutInvalidate(list);
266 addAppsWithoutInvalidate(list);
Winson Chung5f941722010-09-28 16:36:43 -0700267
268 // Update the widgets/shortcuts to reflect changes in the set of available apps
Winson Chung04998342011-01-05 13:54:43 -0800269 invalidatePageData();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700270 }
271
272 /**
273 * Convenience function to find matching ApplicationInfos for removal.
274 */
275 private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) {
276 ComponentName removeComponent = item.intent.getComponent();
277 final int length = list.size();
278 for (int i = 0; i < length; ++i) {
279 ApplicationInfo info = list.get(i);
280 if (info.intent.getComponent().equals(removeComponent)) {
281 return i;
282 }
283 }
284 return -1;
285 }
286
Winson Chung80baf5a2010-08-09 16:03:15 -0700287 public void update() {
Winson Chung80baf5a2010-08-09 16:03:15 -0700288 // get the list of widgets
289 mWidgetList = AppWidgetManager.getInstance(mLauncher).getInstalledProviders();
290 Collections.sort(mWidgetList, new Comparator<AppWidgetProviderInfo>() {
291 @Override
292 public int compare(AppWidgetProviderInfo object1, AppWidgetProviderInfo object2) {
293 return object1.label.compareTo(object2.label);
294 }
295 });
296
297 Comparator<ResolveInfo> resolveInfoComparator = new Comparator<ResolveInfo>() {
298 @Override
299 public int compare(ResolveInfo object1, ResolveInfo object2) {
300 return object1.loadLabel(mPackageManager).toString().compareTo(
301 object2.loadLabel(mPackageManager).toString());
302 }
303 };
304
Winson Chung80baf5a2010-08-09 16:03:15 -0700305 // get the list of shortcuts
306 Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
307 mShortcutList = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
308 Collections.sort(mShortcutList, resolveInfoComparator);
309
Winson Chunge8878e32010-09-15 20:37:09 -0700310 // get the list of wallpapers
311 Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800312 mWallpaperList = mPackageManager.queryIntentActivities(wallpapersIntent,
313 PackageManager.GET_META_DATA);
Winson Chunge8878e32010-09-15 20:37:09 -0700314 Collections.sort(mWallpaperList, resolveInfoComparator);
315
Winson Chung04998342011-01-05 13:54:43 -0800316 ArrayList<ResolveInfo> retainShortcutList = new ArrayList<ResolveInfo>(mShortcutList);
317 retainShortcutList.addAll(mWallpaperList);
318 mPageViewIconCache.retainAllShortcuts(retainShortcutList);
319 mPageViewIconCache.retainAllAppWidgets(mWidgetList);
Winson Chung80baf5a2010-08-09 16:03:15 -0700320 invalidatePageData();
321 }
322
323 public void setDragController(DragController dragger) {
324 mDragController = dragger;
325 }
326
327 public void setCustomizationFilter(CustomizationType filterType) {
Winson Chung7d1fcbc2011-01-04 10:22:20 -0800328 cancelDragging();
Winson Chung94569f42011-01-17 14:09:17 -0800329 mCustomizationType = filterType;
Winson Chunga12a2502010-12-20 14:41:35 -0800330 if (getChildCount() > 0) {
331 setCurrentPage(0);
332 updateCurrentPageScroll();
333 invalidatePageData();
Winson Chungd0d43012010-09-26 17:26:45 -0700334
Winson Chunga12a2502010-12-20 14:41:35 -0800335 // End the current choice mode so that we don't carry selections across tabs
336 endChoiceMode();
337 }
338 }
339
340 public CustomizationType getCustomizationFilter() {
341 return mCustomizationType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700342 }
343
Patrick Dubroy5f445422011-02-18 14:35:21 -0800344 /**
345 * Similar to resetCheckedGrandchildren, but allows us to specify that it's not animated.
Patrick Dubroy5f445422011-02-18 14:35:21 -0800346 */
347 private void resetCheckedItem(boolean animated) {
Patrick Dubroy6f133422011-02-24 12:16:12 -0800348 final Checkable checkable = getSingleCheckedGrandchild();
349 if (checkable != null) {
350 if (checkable instanceof PagedViewWidget) {
351 ((PagedViewWidget) checkable).setChecked(false, animated);
352 } else {
353 ((PagedViewIcon) checkable).setChecked(false, animated);
354 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800355 }
356 }
357
358 public void onDropCompleted(View target, Object dragInfo, boolean success) {
359 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
360
361 // Create a view, identical to the drag view, that is only used for animating the
362 // item onto the home screen (or back to its original position, if the drop failed).
Patrick Dubroy6f133422011-02-24 12:16:12 -0800363 final int[] pos = mDragController.getDragView().getPosition(null);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800364 final View animView = dragLayer.createDragView(mDragBitmap, pos[0], pos[1]);
365 animView.setVisibility(View.VISIBLE);
366
367 if (success) {
368 resetCheckedItem(true);
369 animateDropOntoScreen(animView, (ItemInfo) dragInfo, DROP_ANIM_DURATION, 0);
370 } else {
371 // Animate the icon/widget back to its original position
372 animateIntoPosition(animView, mDragViewOrigin[0], mDragViewOrigin[1], new Runnable() {
373 public void run() {
374 resetCheckedItem(false);
375 dragLayer.removeView(animView);
376 }
377 });
378 }
Patrick Dubroy7bccb422011-01-20 14:50:55 -0800379 mLauncher.getWorkspace().onDragStopped(success);
Winson Chung400438b2011-01-16 17:53:48 -0800380 mLauncher.unlockScreenOrientation();
Patrick Dubroy5f445422011-02-18 14:35:21 -0800381 mDragBitmap = null;
Winson Chung80baf5a2010-08-09 16:03:15 -0700382 }
383
384 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800385 public void onDragViewVisible() {
386 }
387
Patrick Dubroy5f445422011-02-18 14:35:21 -0800388 /**
389 * Animates the given item onto the center of a home screen, and then scales the item to
390 * look as though it's disappearing onto that screen.
391 */
Adam Cohen120980b2010-12-08 11:05:37 -0800392 private void animateItemOntoScreen(View dragView,
393 final CellLayout layout, final ItemInfo info) {
394 mTmpFloatPos[0] = layout.getWidth() / 2;
395 mTmpFloatPos[1] = layout.getHeight() / 2;
396 mLauncher.getWorkspace().mapPointFromChildToSelf(layout, mTmpFloatPos);
397
Adam Cohen120980b2010-12-08 11:05:37 -0800398 int dragViewWidth = dragView.getMeasuredWidth();
399 int dragViewHeight = dragView.getMeasuredHeight();
400 float heightOffset = 0;
401 float widthOffset = 0;
402
403 if (dragView instanceof ImageView) {
404 Drawable d = ((ImageView) dragView).getDrawable();
405 int width = d.getIntrinsicWidth();
406 int height = d.getIntrinsicHeight();
407
408 if ((1.0 * width / height) >= (1.0f * dragViewWidth) / dragViewHeight) {
409 float f = (dragViewWidth / (width * 1.0f));
410 heightOffset = ANIMATION_SCALE * (dragViewHeight - f * height) / 2;
411 } else {
412 float f = (dragViewHeight / (height * 1.0f));
413 widthOffset = ANIMATION_SCALE * (dragViewWidth - f * width) / 2;
414 }
415 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800416 final float toX = mTmpFloatPos[0] - dragView.getMeasuredWidth() / 2 + widthOffset;
417 final float toY = mTmpFloatPos[1] - dragView.getMeasuredHeight() / 2 + heightOffset;
Adam Cohen120980b2010-12-08 11:05:37 -0800418
Patrick Dubroy5f445422011-02-18 14:35:21 -0800419 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
420 final View dragCopy = dragLayer.createDragView(dragView);
421 dragCopy.setAlpha(1.0f);
Adam Cohen120980b2010-12-08 11:05:37 -0800422
Patrick Dubroy5f445422011-02-18 14:35:21 -0800423 // Translate the item to the center of the appropriate home screen
424 animateIntoPosition(dragCopy, toX, toY, null);
Adam Cohen120980b2010-12-08 11:05:37 -0800425
Patrick Dubroy5f445422011-02-18 14:35:21 -0800426 // The drop-onto-screen animation begins a bit later, but ends at the same time.
427 final int startDelay = TRANSLATE_ANIM_DURATION - DROP_ANIM_DURATION;
428
429 // Scale down the icon and fade out the alpha
430 animateDropOntoScreen(dragCopy, info, DROP_ANIM_DURATION, startDelay);
431 }
Adam Cohen120980b2010-12-08 11:05:37 -0800432
Patrick Dubroy5f445422011-02-18 14:35:21 -0800433 /**
434 * Animation which scales the view down and animates its alpha, making it appear to disappear
435 * onto a home screen.
436 */
437 private void animateDropOntoScreen(
438 final View view, final ItemInfo info, int duration, int delay) {
439 final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
440 final CellLayout layout = mLauncher.getWorkspace().getCurrentDropLayout();
441
442 ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
Adam Cohen120980b2010-12-08 11:05:37 -0800443 PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f),
444 PropertyValuesHolder.ofFloat("scaleX", ANIMATION_SCALE),
445 PropertyValuesHolder.ofFloat("scaleY", ANIMATION_SCALE));
Patrick Dubroy5f445422011-02-18 14:35:21 -0800446 anim.setInterpolator(new LinearInterpolator());
447 if (delay > 0) {
448 anim.setStartDelay(delay);
449 }
450 anim.setDuration(duration);
451 anim.addListener(new AnimatorListenerAdapter() {
452 public void onAnimationEnd(Animator animation) {
453 dragLayer.removeView(view);
454 mLauncher.addExternalItemToScreen(info, layout);
455 }
456 });
457 anim.start();
458 }
Adam Cohen120980b2010-12-08 11:05:37 -0800459
Patrick Dubroy5f445422011-02-18 14:35:21 -0800460 /**
461 * Animates the x,y position of the view, and optionally execute a Runnable on animation end.
462 */
463 private void animateIntoPosition(
464 View view, float toX, float toY, final Runnable endRunnable) {
465 ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
466 PropertyValuesHolder.ofFloat("x", toX),
467 PropertyValuesHolder.ofFloat("y", toY));
468 anim.setInterpolator(mQuintEaseOutInterpolator);
469 anim.setDuration(TRANSLATE_ANIM_DURATION);
470 if (endRunnable != null) {
471 anim.addListener(new AnimatorListenerAdapter() {
472 @Override
473 public void onAnimationEnd(Animator animation) {
474 endRunnable.run();
475 }
476 });
477 }
478 anim.start();
Adam Cohen120980b2010-12-08 11:05:37 -0800479 }
480
Patrick Dubroya669d792010-11-23 14:40:33 -0800481 @Override
Adam Cohen120980b2010-12-08 11:05:37 -0800482 public void onClick(final View v) {
Winson Chunge22a8e92010-11-12 13:40:58 -0800483 // Return early if this is not initiated from a touch
484 if (!v.isInTouchMode()) return;
485 // Return early if we are still animating the pages
Winson Chung4f9e1072010-11-15 15:28:24 -0800486 if (mNextPage != INVALID_PAGE) return;
Winson Chunge8878e32010-09-15 20:37:09 -0700487
Winson Chungd0d43012010-09-26 17:26:45 -0700488 // On certain pages, we allow single tap to mark items as selected so that they can be
489 // dropped onto the mini workspaces
Michael Jurka3125d9d2010-09-27 11:30:20 -0700490 boolean enterChoiceMode = false;
Winson Chungd0d43012010-09-26 17:26:45 -0700491 switch (mCustomizationType) {
492 case WidgetCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700493 mChoiceModeTitleText = R.string.cab_widget_selection_text;
494 enterChoiceMode = true;
495 break;
Winson Chungd0d43012010-09-26 17:26:45 -0700496 case ApplicationCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700497 mChoiceModeTitleText = R.string.cab_app_selection_text;
498 enterChoiceMode = true;
499 break;
Winson Chungd0d43012010-09-26 17:26:45 -0700500 case ShortcutCustomization:
Michael Jurka3125d9d2010-09-27 11:30:20 -0700501 mChoiceModeTitleText = R.string.cab_shortcut_selection_text;
502 enterChoiceMode = true;
503 break;
504 default:
505 break;
506 }
Winson Chungd0d43012010-09-26 17:26:45 -0700507
Michael Jurka3125d9d2010-09-27 11:30:20 -0700508 if (enterChoiceMode) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700509 final ItemInfo itemInfo = (ItemInfo) v.getTag();
Winson Chungd0d43012010-09-26 17:26:45 -0700510
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700511 Workspace w = mLauncher.getWorkspace();
512 int currentWorkspaceScreen = mLauncher.getCurrentWorkspaceScreen();
513 final CellLayout cl = (CellLayout)w.getChildAt(currentWorkspaceScreen);
Adam Cohen120980b2010-12-08 11:05:37 -0800514 final View dragView = getDragView(v);
Michael Jurkae17e19c2010-09-28 11:01:39 -0700515
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700516 animateClickFeedback(v, new Runnable() {
517 @Override
518 public void run() {
Patrick Dubroy047379a2010-12-19 22:02:04 -0800519 cl.calculateSpans(itemInfo);
520 if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) {
521 animateItemOntoScreen(dragView, cl, itemInfo);
522 } else {
523 mLauncher.showOutOfSpaceMessage();
524 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -0700525 }
526 });
Winson Chungd0d43012010-09-26 17:26:45 -0700527 return;
Winson Chungd0d43012010-09-26 17:26:45 -0700528 }
529
530 // Otherwise, we just handle the single click here
Winson Chunge8878e32010-09-15 20:37:09 -0700531 switch (mCustomizationType) {
532 case WallpaperCustomization:
533 // animate some feedback to the long press
Winson Chungd0d43012010-09-26 17:26:45 -0700534 final View clickView = v;
Winson Chunge8878e32010-09-15 20:37:09 -0700535 animateClickFeedback(v, new Runnable() {
536 @Override
537 public void run() {
538 // add the shortcut
Winson Chungd0d43012010-09-26 17:26:45 -0700539 ResolveInfo info = (ResolveInfo) clickView.getTag();
Winson Chung24ab2f12010-09-16 14:10:47 -0700540 Intent createWallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
541 ComponentName name = new ComponentName(info.activityInfo.packageName,
542 info.activityInfo.name);
543 createWallpapersIntent.setComponent(name);
544 mLauncher.processWallpaper(createWallpapersIntent);
Winson Chunge8878e32010-09-15 20:37:09 -0700545 }
546 });
Winson Chungd0d43012010-09-26 17:26:45 -0700547 break;
548 default:
549 break;
Winson Chunge8878e32010-09-15 20:37:09 -0700550 }
551 }
552
Winson Chung1908d072011-02-24 18:09:44 -0800553 private Bitmap drawableToBitmap(Drawable d, float scaleX, float scaleY) {
Patrick Dubroy5f445422011-02-18 14:35:21 -0800554 final Rect bounds = d.getBounds();
555 final int w = bounds.width();
556 final int h = bounds.height();
Michael Jurkac4e772e2011-02-10 13:32:01 -0800557 Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Winson Chung1908d072011-02-24 18:09:44 -0800558 renderDrawableToBitmap(d, b, 0, 0, w, h, scaleX, scaleY);
Michael Jurkaaf91de02010-11-23 16:23:58 -0800559 return b;
560 }
561
Adam Cohen120980b2010-12-08 11:05:37 -0800562 private View getDragView(View v) {
563 return (mCustomizationType == CustomizationType.WidgetCustomization) ?
564 v.findViewById(R.id.widget_preview) : v;
565 }
566
Michael Jurka72b079e2010-12-10 01:03:53 -0800567 protected boolean beginDragging(View v) {
Winson Chung304dcde2011-01-07 11:17:23 -0800568 if (!v.isInTouchMode()) return false;
569 if (!super.beginDragging(v)) return false;
570
Winson Chungd0d43012010-09-26 17:26:45 -0700571 // End the current choice mode before we start dragging anything
572 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
573 endChoiceMode();
574 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800575 final Workspace workspace = mLauncher.getWorkspace();
Winson Chung59e1f9a2010-12-21 11:31:54 -0800576 boolean result = false;
Winson Chung400438b2011-01-16 17:53:48 -0800577 mLauncher.lockScreenOrientation();
Winson Chung80baf5a2010-08-09 16:03:15 -0700578 switch (mCustomizationType) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800579 case WidgetCustomization: {
Winson Chung94569f42011-01-17 14:09:17 -0800580 if (v instanceof PagedViewWidget) {
581 // Get the widget preview as the drag representation
582 final LinearLayout l = (LinearLayout) v;
583 final ImageView i = (ImageView) l.findViewById(R.id.widget_preview);
Winson Chung1908d072011-02-24 18:09:44 -0800584
585 // Calculate how much to scale the drag preview
586 RectF tmpScaleRect = new RectF(0,0,1,1);
587 i.getImageMatrix().mapRect(tmpScaleRect);
588
589 mDragBitmap = drawableToBitmap(i.getDrawable(), tmpScaleRect.right,
590 tmpScaleRect.bottom);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800591 i.getLocationOnScreen(mDragViewOrigin);
Winson Chung94569f42011-01-17 14:09:17 -0800592 PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag();
Michael Jurkaa63c4522010-08-19 13:52:27 -0700593
Patrick Dubroy5f445422011-02-18 14:35:21 -0800594 int[] spanXY = CellLayout.rectToCell(getResources(),
595 createWidgetInfo.minWidth, createWidgetInfo.minHeight, null);
Winson Chung94569f42011-01-17 14:09:17 -0800596 createWidgetInfo.spanX = spanXY[0];
597 createWidgetInfo.spanY = spanXY[1];
Patrick Dubroy5f445422011-02-18 14:35:21 -0800598 workspace.onDragStartedWithItemSpans(spanXY[0], spanXY[1], mDragBitmap);
599 mDragController.startDrag(i, mDragBitmap, this, createWidgetInfo,
600 DragController.DRAG_ACTION_COPY, null);
Winson Chung94569f42011-01-17 14:09:17 -0800601 result = true;
602 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800603 break;
Michael Jurkad3ef3062010-11-23 16:23:58 -0800604 }
Patrick Dubroy5f445422011-02-18 14:35:21 -0800605 case ShortcutCustomization:
Michael Jurkad3ef3062010-11-23 16:23:58 -0800606 case ApplicationCustomization: {
Winson Chung94569f42011-01-17 14:09:17 -0800607 if (v instanceof PagedViewIcon) {
Winson Chung94569f42011-01-17 14:09:17 -0800608 // get icon (top compound drawable, index is 1)
609 final TextView tv = (TextView) v;
610 final Drawable icon = tv.getCompoundDrawables()[1];
Winson Chung1908d072011-02-24 18:09:44 -0800611 mDragBitmap = drawableToBitmap(icon, 1.0f, 1.0f);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700612
Patrick Dubroy5f445422011-02-18 14:35:21 -0800613 Object dragInfo = v.getTag();
614 if (mCustomizationType == CustomizationType.ApplicationCustomization) {
615 // TODO: Not sure why we have to copy this
616 dragInfo = new ApplicationInfo((ApplicationInfo) dragInfo);
617 }
618 workspace.onDragStartedWithItemSpans(1, 1, mDragBitmap);
619
620 // Calculate where to place the drag view in order to align the icon pixels with
621 // the original view.
622 v.getLocationOnScreen(mDragViewOrigin);
623 mDragViewOrigin[0] += (v.getWidth() - icon.getIntrinsicWidth()) / 2;
624 mDragViewOrigin[1] += v.getPaddingTop();
625
626 mDragController.startDrag(mDragBitmap, mDragViewOrigin[0], mDragViewOrigin[1],
627 this, dragInfo, DragController.DRAG_ACTION_COPY);
Winson Chung94569f42011-01-17 14:09:17 -0800628 result = true;
629 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800630 break;
Winson Chung80baf5a2010-08-09 16:03:15 -0700631 }
Michael Jurkad3ef3062010-11-23 16:23:58 -0800632 }
Winson Chung59e1f9a2010-12-21 11:31:54 -0800633
634 // We toggle the checked state _after_ we create the view for the drag in case toggling the
635 // checked state changes the view's look
Winson Chung94569f42011-01-17 14:09:17 -0800636 if (result && (v instanceof Checkable)) {
Winson Chung59e1f9a2010-12-21 11:31:54 -0800637 // In preparation for drag, we always reset the checked grand children regardless of
638 // what choice mode we are in
639 resetCheckedGrandchildren();
640
641 // Toggle the selection on the dragged app
642 Checkable checkable = (Checkable) v;
643
644 // Note: we toggle the checkable state to actually cause an alpha fade for the duration
645 // of the drag of the item. (The fade-in will occur when all checked states are
646 // disabled when dragging ends)
647 checkable.toggle();
648 }
649
650 return result;
Winson Chung80baf5a2010-08-09 16:03:15 -0700651 }
652
Winson Chunge3193b92010-09-10 11:44:42 -0700653 /**
654 * Pre-processes the layout of the different widget pages.
655 * @return the number of pages of widgets that we have
656 */
Winson Chung80baf5a2010-08-09 16:03:15 -0700657 private int relayoutWidgets() {
Winson Chunge3193b92010-09-10 11:44:42 -0700658 if (mWidgetList.isEmpty()) return 0;
Winson Chung80baf5a2010-08-09 16:03:15 -0700659
Winson Chunge3193b92010-09-10 11:44:42 -0700660 // create a new page for the first set of widgets
661 ArrayList<AppWidgetProviderInfo> newPage = new ArrayList<AppWidgetProviderInfo>();
Winson Chung80baf5a2010-08-09 16:03:15 -0700662 mWidgetPages.clear();
Winson Chunge3193b92010-09-10 11:44:42 -0700663 mWidgetPages.add(newPage);
664
665 // do this until we have no more widgets to lay out
666 final int maxNumCellsPerRow = mMaxWidgetsCellHSpan;
667 final int widgetCount = mWidgetList.size();
668 int numCellsInRow = 0;
Winson Chung80baf5a2010-08-09 16:03:15 -0700669 for (int i = 0; i < widgetCount; ++i) {
Winson Chunge3193b92010-09-10 11:44:42 -0700670 final AppWidgetProviderInfo info = mWidgetList.get(i);
Winson Chung80baf5a2010-08-09 16:03:15 -0700671
Winson Chunge3193b92010-09-10 11:44:42 -0700672 // determine the size of the current widget
673 int cellSpanX = Math.max(sMinWidgetCellHSpan, Math.min(sMaxWidgetCellHSpan,
674 mWorkspaceWidgetLayout.estimateCellHSpan(info.minWidth)));
Winson Chung80baf5a2010-08-09 16:03:15 -0700675
Winson Chunge3193b92010-09-10 11:44:42 -0700676 // create a new page if necessary
677 if ((numCellsInRow + cellSpanX) > maxNumCellsPerRow) {
678 numCellsInRow = 0;
679 newPage = new ArrayList<AppWidgetProviderInfo>();
680 mWidgetPages.add(newPage);
Winson Chung80baf5a2010-08-09 16:03:15 -0700681 }
682
Winson Chunge3193b92010-09-10 11:44:42 -0700683 // add the item to the current page
684 newPage.add(info);
685 numCellsInRow += cellSpanX;
Winson Chung80baf5a2010-08-09 16:03:15 -0700686 }
Winson Chunge3193b92010-09-10 11:44:42 -0700687
Winson Chung80baf5a2010-08-09 16:03:15 -0700688 return mWidgetPages.size();
689 }
690
Winson Chunge3193b92010-09-10 11:44:42 -0700691 /**
Winson Chung7da10252010-10-28 16:07:04 -0700692 * Helper function to draw a drawable to the specified canvas with the specified bounds.
693 */
Winson Chung1908d072011-02-24 18:09:44 -0800694 private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
695 float scaleX, float scaleY) {
Winson Chung7da10252010-10-28 16:07:04 -0700696 if (bitmap != null) mCanvas.setBitmap(bitmap);
697 mCanvas.save();
Winson Chung1908d072011-02-24 18:09:44 -0800698 mCanvas.scale(scaleX, scaleY);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800699 final Rect oldBounds = d.copyBounds();
700 d.setBounds(x, y, x + w, y + h);
Winson Chung7da10252010-10-28 16:07:04 -0700701 d.draw(mCanvas);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800702 d.setBounds(oldBounds); // Restore the bounds
Winson Chung7da10252010-10-28 16:07:04 -0700703 mCanvas.restore();
704 }
705
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800706 /*
707 * This method fetches an xml file specified in the manifest identified by
708 * WallpaperManager.WALLPAPER_PREVIEW_META_DATA). The xml file specifies
709 * an image which will be used as the wallpaper preview for an activity
710 * which responds to ACTION_SET_WALLPAPER. This image is returned and used
711 * in the customize drawer.
712 */
713 private Drawable parseWallpaperPreviewXml(ComponentName component, ResolveInfo ri) {
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800714 ActivityInfo activityInfo = ri.activityInfo;
715 XmlResourceParser parser = null;
716 try {
717 parser = activityInfo.loadXmlMetaData(mPackageManager,
718 WallpaperManager.WALLPAPER_PREVIEW_META_DATA);
719 if (parser == null) {
720 Slog.w(TAG, "No " + WallpaperManager.WALLPAPER_PREVIEW_META_DATA + " meta-data for "
721 + "wallpaper provider '" + component + '\'');
722 return null;
723 }
724
725 AttributeSet attrs = Xml.asAttributeSet(parser);
726
727 int type;
728 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
729 && type != XmlPullParser.START_TAG) {
730 // drain whitespace, comments, etc.
731 }
732
733 String nodeName = parser.getName();
734 if (!"wallpaper-preview".equals(nodeName)) {
735 Slog.w(TAG, "Meta-data does not start with wallpaper-preview tag for "
736 + "wallpaper provider '" + component + '\'');
737 return null;
738 }
739
740 // If metaData was null, we would have returned earlier when getting
741 // the parser No need to do the check here
742 Resources res = mPackageManager.getResourcesForApplication(
743 activityInfo.applicationInfo);
744
745 TypedArray sa = res.obtainAttributes(attrs,
746 com.android.internal.R.styleable.WallpaperPreviewInfo);
747
748 TypedValue value = sa.peekValue(
749 com.android.internal.R.styleable.WallpaperPreviewInfo_staticWallpaperPreview);
750 if (value == null) return null;
751
752 return res.getDrawable(value.resourceId);
753 } catch (Exception e) {
754 Slog.w(TAG, "XML parsing failed for wallpaper provider '" + component + '\'', e);
755 return null;
756 } finally {
757 if (parser != null) parser.close();
758 }
759 }
760
Winson Chung7da10252010-10-28 16:07:04 -0700761 /**
Winson Chung45e1d6e2010-11-09 17:19:49 -0800762 * This method will extract the preview image specified by the wallpaper source provider (if it
763 * exists) otherwise, it will try to generate a default image preview.
764 */
Winson Chung29d6fea2010-12-01 15:47:31 -0800765 private FastBitmapDrawable getWallpaperPreview(ResolveInfo info) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800766 // To be implemented later: resolving the up-to-date wallpaper thumbnail
767
768 final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1);
769 final int dim = mWorkspaceWidgetLayout.estimateCellWidth(mWallpaperCellHSpan);
770 Resources resources = mLauncher.getResources();
771
772 // Create a new bitmap to hold the widget preview
773 int width = (int) (dim * sScaleFactor);
774 int height = (int) (dim * sScaleFactor);
775 final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800776
777 Drawable background = parseWallpaperPreviewXml(
778 new ComponentName(info.activityInfo.packageName, info.activityInfo.name), info);
779 boolean foundCustomDrawable = background != null;
780
781 if (!foundCustomDrawable) {
782 background = resources.getDrawable(R.drawable.default_widget_preview);
783 }
784
Winson Chung1908d072011-02-24 18:09:44 -0800785 renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800786
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800787 // If we don't have a custom icon, we use the app icon on the default background
788 if (!foundCustomDrawable) {
789 try {
790 final IconCache iconCache =
791 ((LauncherApplication) mLauncher.getApplication()).getIconCache();
792 Drawable icon = new FastBitmapDrawable(Utilities.createIconBitmap(
793 iconCache.getFullResIcon(info, mPackageManager), mContext));
Winson Chung45e1d6e2010-11-09 17:19:49 -0800794
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800795 final int iconSize = minDim / 2;
796 final int offset = iconSize / 4;
Winson Chung1908d072011-02-24 18:09:44 -0800797 renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f);
Adam Cohen7b9d3a62010-12-07 21:49:34 -0800798 } catch (Resources.NotFoundException e) {
799 // if we can't find the icon, then just don't draw it
800 }
Winson Chung45e1d6e2010-11-09 17:19:49 -0800801 }
802
Winson Chung29d6fea2010-12-01 15:47:31 -0800803 FastBitmapDrawable drawable = new FastBitmapDrawable(bitmap);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800804 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
805 return drawable;
806 }
807
808 /**
Winson Chunge3193b92010-09-10 11:44:42 -0700809 * This method will extract the preview image specified by the widget developer (if it exists),
810 * otherwise, it will try to generate a default image preview with the widget's package icon.
Winson Chung45e1d6e2010-11-09 17:19:49 -0800811 * @return the drawable that will be used and sized in the ImageView to represent the widget
Winson Chunge3193b92010-09-10 11:44:42 -0700812 */
Winson Chung29d6fea2010-12-01 15:47:31 -0800813 private FastBitmapDrawable getWidgetPreview(AppWidgetProviderInfo info) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800814 final PackageManager packageManager = mPackageManager;
Winson Chung80baf5a2010-08-09 16:03:15 -0700815 String packageName = info.provider.getPackageName();
816 Drawable drawable = null;
Winson Chung29d6fea2010-12-01 15:47:31 -0800817 FastBitmapDrawable newDrawable = null;
Winson Chung80baf5a2010-08-09 16:03:15 -0700818 if (info.previewImage != 0) {
819 drawable = packageManager.getDrawable(packageName, info.previewImage, null);
820 if (drawable == null) {
821 Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon)
822 + " for provider: " + info.provider);
Winson Chung80baf5a2010-08-09 16:03:15 -0700823 }
824 }
825
826 // If we don't have a preview image, create a default one
Winson Chung7da10252010-10-28 16:07:04 -0700827 final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1);
828 final int maxDim = mWorkspaceWidgetLayout.estimateCellWidth(3);
Winson Chung80baf5a2010-08-09 16:03:15 -0700829 if (drawable == null) {
830 Resources resources = mLauncher.getResources();
831
Winson Chung80baf5a2010-08-09 16:03:15 -0700832 // Create a new bitmap to hold the widget preview
Winson Chunge3193b92010-09-10 11:44:42 -0700833 int width = (int) (Math.max(minDim, Math.min(maxDim, info.minWidth)) * sScaleFactor);
834 int height = (int) (Math.max(minDim, Math.min(maxDim, info.minHeight)) * sScaleFactor);
Winson Chung7da10252010-10-28 16:07:04 -0700835 final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
836 final Drawable background = resources.getDrawable(R.drawable.default_widget_preview);
Winson Chung1908d072011-02-24 18:09:44 -0800837 renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700838
Winson Chung45e1d6e2010-11-09 17:19:49 -0800839 // Draw the icon flush left
Winson Chung80baf5a2010-08-09 16:03:15 -0700840 try {
Winson Chung80baf5a2010-08-09 16:03:15 -0700841 Drawable icon = null;
Winson Chunge3193b92010-09-10 11:44:42 -0700842 if (info.icon > 0) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700843 icon = packageManager.getDrawable(packageName, info.icon, null);
Winson Chung5f941722010-09-28 16:36:43 -0700844 }
845 if (icon == null) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700846 icon = resources.getDrawable(R.drawable.ic_launcher_application);
847 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700848
Winson Chunge3193b92010-09-10 11:44:42 -0700849 final int iconSize = minDim / 2;
850 final int offset = iconSize / 4;
Winson Chung1908d072011-02-24 18:09:44 -0800851 renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700852 } catch (Resources.NotFoundException e) {
853 // if we can't find the icon, then just don't draw it
854 }
855
Winson Chung29d6fea2010-12-01 15:47:31 -0800856 newDrawable = new FastBitmapDrawable(bitmap);
Winson Chung7da10252010-10-28 16:07:04 -0700857 } else {
858 // Scale down the preview if necessary
Winson Chung94ba5b12010-11-08 17:17:47 -0800859 final float imageWidth = drawable.getIntrinsicWidth();
860 final float imageHeight = drawable.getIntrinsicHeight();
861 final float aspect = (float) imageWidth / imageHeight;
862 final int scaledWidth =
863 (int) (Math.max(minDim, Math.min(maxDim, imageWidth)) * sScaleFactor);
864 final int scaledHeight =
865 (int) (Math.max(minDim, Math.min(maxDim, imageHeight)) * sScaleFactor);
Winson Chung7da10252010-10-28 16:07:04 -0700866 int width;
867 int height;
Winson Chung94ba5b12010-11-08 17:17:47 -0800868 if (aspect >= 1.0f) {
Winson Chung7da10252010-10-28 16:07:04 -0700869 width = scaledWidth;
Winson Chung94ba5b12010-11-08 17:17:47 -0800870 height = (int) (((float) scaledWidth / imageWidth) * imageHeight);
Winson Chung7da10252010-10-28 16:07:04 -0700871 } else {
872 height = scaledHeight;
Winson Chung94ba5b12010-11-08 17:17:47 -0800873 width = (int) (((float) scaledHeight / imageHeight) * imageWidth);
Winson Chung7da10252010-10-28 16:07:04 -0700874 }
875
876 final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Winson Chung1908d072011-02-24 18:09:44 -0800877 renderDrawableToBitmap(drawable, bitmap, 0, 0, width, height, 1.0f, 1.0f);
Winson Chung7da10252010-10-28 16:07:04 -0700878
Winson Chung29d6fea2010-12-01 15:47:31 -0800879 newDrawable = new FastBitmapDrawable(bitmap);
Winson Chung80baf5a2010-08-09 16:03:15 -0700880 }
Winson Chung29d6fea2010-12-01 15:47:31 -0800881 newDrawable.setBounds(0, 0, newDrawable.getIntrinsicWidth(),
882 newDrawable.getIntrinsicHeight());
883 return newDrawable;
Winson Chung80baf5a2010-08-09 16:03:15 -0700884 }
885
886 private void setupPage(PagedViewCellLayout layout) {
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700887 layout.setCellCount(mCellCountX, mCellCountY);
888 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight,
889 mPageLayoutPaddingBottom);
Winson Chungef0066b2010-10-21 11:55:00 -0700890 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung80baf5a2010-08-09 16:03:15 -0700891 }
892
Winson Chunge3193b92010-09-10 11:44:42 -0700893 private void setupWorkspaceLayout() {
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700894 mWorkspaceWidgetLayout.setCellCount(mCellCountX, mCellCountY);
Winson Chunge3193b92010-09-10 11:44:42 -0700895 mWorkspaceWidgetLayout.setPadding(20, 10, 20, 0);
896
897 mMaxWidgetWidth = mWorkspaceWidgetLayout.estimateCellWidth(sMaxWidgetCellHSpan);
898 }
899
Winson Chung80baf5a2010-08-09 16:03:15 -0700900 private void syncWidgetPages() {
901 if (mWidgetList == null) return;
902
Winson Chunge3193b92010-09-10 11:44:42 -0700903 // we need to repopulate with the LinearLayout layout for the widget pages
904 removeAllViews();
Winson Chung80baf5a2010-08-09 16:03:15 -0700905 int numPages = relayoutWidgets();
Winson Chunge3193b92010-09-10 11:44:42 -0700906 for (int i = 0; i < numPages; ++i) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800907 LinearLayout layout = new PagedViewExtendedLayout(getContext());
Winson Chunge3193b92010-09-10 11:44:42 -0700908 layout.setGravity(Gravity.CENTER_HORIZONTAL);
Winson Chungef0066b2010-10-21 11:55:00 -0700909 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
910 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chunge3193b92010-09-10 11:44:42 -0700911
Winson Chunge22a8e92010-11-12 13:40:58 -0800912 addView(layout, new LinearLayout.LayoutParams(
913 LinearLayout.LayoutParams.WRAP_CONTENT,
914 LinearLayout.LayoutParams.MATCH_PARENT));
Winson Chung80baf5a2010-08-09 16:03:15 -0700915 }
916 }
917
918 private void syncWidgetPageItems(int page) {
919 // ensure that we have the right number of items on the pages
Winson Chunge3193b92010-09-10 11:44:42 -0700920 LinearLayout layout = (LinearLayout) getChildAt(page);
921 final ArrayList<AppWidgetProviderInfo> list = mWidgetPages.get(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700922 final int count = list.size();
Winson Chung04998342011-01-05 13:54:43 -0800923 final int numPages = getPageCount();
Winson Chung80baf5a2010-08-09 16:03:15 -0700924 layout.removeAllViews();
925 for (int i = 0; i < count; ++i) {
Winson Chung68846fd2010-10-29 11:00:27 -0700926 final AppWidgetProviderInfo info = (AppWidgetProviderInfo) list.get(i);
927 final PendingAddWidgetInfo createItemInfo = new PendingAddWidgetInfo(info, null, null);
Winson Chung29d6fea2010-12-01 15:47:31 -0800928 final int[] cellSpans = CellLayout.rectToCell(getResources(), info.minWidth,
929 info.minHeight, null);
930 final FastBitmapDrawable icon = getWidgetPreview(info);
Winson Chungd0d43012010-09-26 17:26:45 -0700931
Winson Chung29d6fea2010-12-01 15:47:31 -0800932 PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
Winson Chunge3193b92010-09-10 11:44:42 -0700933 R.layout.customize_paged_view_widget, layout, false);
Winson Chung1908d072011-02-24 18:09:44 -0800934
Winson Chung04998342011-01-05 13:54:43 -0800935 l.applyFromAppWidgetProviderInfo(info, icon, mMaxWidgetWidth, cellSpans,
936 mPageViewIconCache, (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -0700937 l.setTag(createItemInfo);
938 l.setOnClickListener(this);
Michael Jurka7426c422010-11-11 15:23:47 -0800939 l.setOnTouchListener(this);
Winson Chunge3193b92010-09-10 11:44:42 -0700940 l.setOnLongClickListener(this);
Winson Chung80baf5a2010-08-09 16:03:15 -0700941
Winson Chunge3193b92010-09-10 11:44:42 -0700942 layout.addView(l);
Winson Chung80baf5a2010-08-09 16:03:15 -0700943 }
944 }
945
Winson Chung45e1d6e2010-11-09 17:19:49 -0800946 private void syncWallpaperPages() {
947 if (mWallpaperList == null) return;
948
949 // We need to repopulate the LinearLayout for the wallpaper pages
950 removeAllViews();
951 int numPages = (int) Math.ceil((float) (mWallpaperList.size() * mWallpaperCellHSpan) /
Winson Chung78bd53c2010-12-09 13:50:24 -0800952 mMaxWallpaperCellHSpan);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800953 for (int i = 0; i < numPages; ++i) {
954 LinearLayout layout = new PagedViewExtendedLayout(getContext());
955 layout.setGravity(Gravity.CENTER_HORIZONTAL);
956 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
957 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
958
Winson Chunge22a8e92010-11-12 13:40:58 -0800959 addView(layout, new LinearLayout.LayoutParams(
960 LinearLayout.LayoutParams.WRAP_CONTENT,
961 LinearLayout.LayoutParams.MATCH_PARENT));
Winson Chung45e1d6e2010-11-09 17:19:49 -0800962 }
963 }
964
965 private void syncWallpaperPageItems(int page) {
966 // Load the items on to the pages
967 LinearLayout layout = (LinearLayout) getChildAt(page);
968 layout.removeAllViews();
969 final int count = mWallpaperList.size();
Winson Chung04998342011-01-05 13:54:43 -0800970 final int numPages = getPageCount();
Winson Chung78bd53c2010-12-09 13:50:24 -0800971 final int numItemsPerPage = mMaxWallpaperCellHSpan / mWallpaperCellHSpan;
Winson Chungd28ed492010-11-22 14:34:57 -0800972 final int startIndex = page * numItemsPerPage;
973 final int endIndex = Math.min(count, startIndex + numItemsPerPage);
974 for (int i = startIndex; i < endIndex; ++i) {
Winson Chung45e1d6e2010-11-09 17:19:49 -0800975 final ResolveInfo info = mWallpaperList.get(i);
Winson Chung29d6fea2010-12-01 15:47:31 -0800976 final FastBitmapDrawable icon = getWallpaperPreview(info);
Winson Chung45e1d6e2010-11-09 17:19:49 -0800977
Winson Chung29d6fea2010-12-01 15:47:31 -0800978 PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
Winson Chung45e1d6e2010-11-09 17:19:49 -0800979 R.layout.customize_paged_view_wallpaper, layout, false);
Winson Chung04998342011-01-05 13:54:43 -0800980 l.applyFromWallpaperInfo(info, mPackageManager, icon, mMaxWidgetWidth,
981 mPageViewIconCache, (numPages > 1));
Winson Chung45e1d6e2010-11-09 17:19:49 -0800982 l.setTag(info);
983 l.setOnClickListener(this);
984
Winson Chung45e1d6e2010-11-09 17:19:49 -0800985 layout.addView(l);
986 }
987 }
988
Winson Chung80baf5a2010-08-09 16:03:15 -0700989 private void syncListPages(List<ResolveInfo> list) {
Winson Chunge3193b92010-09-10 11:44:42 -0700990 // we need to repopulate with PagedViewCellLayouts
991 removeAllViews();
992
Winson Chung80baf5a2010-08-09 16:03:15 -0700993 // ensure that we have the right number of pages
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700994 int numPages = (int) Math.ceil((float) list.size() / (mCellCountX * mCellCountY));
Winson Chunge3193b92010-09-10 11:44:42 -0700995 for (int i = 0; i < numPages; ++i) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700996 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
997 setupPage(layout);
998 addView(layout);
999 }
1000 }
1001
1002 private void syncListPageItems(int page, List<ResolveInfo> list) {
1003 // ensure that we have the right number of items on the pages
Winson Chung04998342011-01-05 13:54:43 -08001004 final int numPages = getPageCount();
1005 final int numCells = mCellCountX * mCellCountY;
1006 final int startIndex = page * numCells;
1007 final int endIndex = Math.min(startIndex + numCells, list.size());
1008 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -07001009 // TODO: we can optimize by just re-applying to existing views
Michael Jurka8245a862011-02-01 17:53:59 -08001010 layout.removeAllViewsOnPage();
Winson Chung80baf5a2010-08-09 16:03:15 -07001011 for (int i = startIndex; i < endIndex; ++i) {
1012 ResolveInfo info = list.get(i);
Winson Chungd0d43012010-09-26 17:26:45 -07001013 PendingAddItemInfo createItemInfo = new PendingAddItemInfo();
1014
Winson Chung241c3b42010-08-25 16:53:03 -07001015 PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
1016 R.layout.customize_paged_view_item, layout, false);
Michael Jurkac9a96192010-11-01 11:52:08 -07001017 icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache,
Winson Chung04998342011-01-05 13:54:43 -08001018 ((LauncherApplication) mLauncher.getApplication()).getIconCache(),
1019 (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -07001020 switch (mCustomizationType) {
1021 case WallpaperCustomization:
Winson Chunge8878e32010-09-15 20:37:09 -07001022 icon.setOnClickListener(this);
Winson Chungd0d43012010-09-26 17:26:45 -07001023 break;
Winson Chungd0d43012010-09-26 17:26:45 -07001024 case ShortcutCustomization:
1025 createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
1026 createItemInfo.componentName = new ComponentName(info.activityInfo.packageName,
1027 info.activityInfo.name);
1028 icon.setTag(createItemInfo);
1029 icon.setOnClickListener(this);
Michael Jurka7426c422010-11-11 15:23:47 -08001030 icon.setOnTouchListener(this);
Winson Chungd0d43012010-09-26 17:26:45 -07001031 icon.setOnLongClickListener(this);
1032 break;
1033 default:
1034 break;
Winson Chunge8878e32010-09-15 20:37:09 -07001035 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001036
1037 final int index = i - startIndex;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001038 final int x = index % mCellCountX;
1039 final int y = index / mCellCountX;
1040 setupPage(layout);
1041 layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
1042 }
1043 }
1044
1045 private void syncAppPages() {
1046 if (mApps == null) return;
1047
1048 // We need to repopulate with PagedViewCellLayouts
1049 removeAllViews();
1050
1051 // Ensure that we have the right number of pages
1052 int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
1053 for (int i = 0; i < numPages; ++i) {
1054 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
1055 setupPage(layout);
1056 addView(layout);
1057 }
1058 }
1059
1060 private void syncAppPageItems(int page) {
1061 if (mApps == null) return;
1062
1063 // ensure that we have the right number of items on the pages
Winson Chung04998342011-01-05 13:54:43 -08001064 final int numPages = getPageCount();
1065 final int numCells = mCellCountX * mCellCountY;
1066 final int startIndex = page * numCells;
1067 final int endIndex = Math.min(startIndex + numCells, mApps.size());
1068 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001069 // TODO: we can optimize by just re-applying to existing views
Michael Jurka8245a862011-02-01 17:53:59 -08001070 layout.removeAllViewsOnPage();
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001071 for (int i = startIndex; i < endIndex; ++i) {
1072 final ApplicationInfo info = mApps.get(i);
1073 PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
1074 R.layout.all_apps_paged_view_application, layout, false);
Winson Chung04998342011-01-05 13:54:43 -08001075 icon.applyFromApplicationInfo(info, mPageViewIconCache, true, (numPages > 1));
Winson Chungd0d43012010-09-26 17:26:45 -07001076 icon.setOnClickListener(this);
Michael Jurka7426c422010-11-11 15:23:47 -08001077 icon.setOnTouchListener(this);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001078 icon.setOnLongClickListener(this);
1079
1080 final int index = i - startIndex;
1081 final int x = index % mCellCountX;
1082 final int y = index / mCellCountX;
Winson Chunge3193b92010-09-10 11:44:42 -07001083 setupPage(layout);
Winson Chung241c3b42010-08-25 16:53:03 -07001084 layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
Winson Chung80baf5a2010-08-09 16:03:15 -07001085 }
1086 }
1087
Winson Chung80baf5a2010-08-09 16:03:15 -07001088 @Override
1089 public void syncPages() {
Winson Chung1908d072011-02-24 18:09:44 -08001090 boolean enforceMinimumPagedWidths = false;
Winson Chunge3193b92010-09-10 11:44:42 -07001091 boolean centerPagedViewCellLayouts = false;
Winson Chung80baf5a2010-08-09 16:03:15 -07001092 switch (mCustomizationType) {
1093 case WidgetCustomization:
1094 syncWidgetPages();
Winson Chung1908d072011-02-24 18:09:44 -08001095 enforceMinimumPagedWidths = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001096 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001097 case ShortcutCustomization:
1098 syncListPages(mShortcutList);
Winson Chunge3193b92010-09-10 11:44:42 -07001099 centerPagedViewCellLayouts = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001100 break;
1101 case WallpaperCustomization:
Winson Chung45e1d6e2010-11-09 17:19:49 -08001102 syncWallpaperPages();
Winson Chung1908d072011-02-24 18:09:44 -08001103 enforceMinimumPagedWidths = true;
Winson Chung80baf5a2010-08-09 16:03:15 -07001104 break;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001105 case ApplicationCustomization:
1106 syncAppPages();
1107 centerPagedViewCellLayouts = false;
1108 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001109 default:
1110 removeAllViews();
Winson Chung86f77532010-08-24 11:08:22 -07001111 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -07001112 break;
1113 }
1114
1115 // only try and center the page if there is one page
1116 final int childCount = getChildCount();
Winson Chunge3193b92010-09-10 11:44:42 -07001117 if (centerPagedViewCellLayouts) {
1118 if (childCount == 1) {
1119 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(0);
1120 layout.enableCenteredContent(true);
1121 } else {
1122 for (int i = 0; i < childCount; ++i) {
1123 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
1124 layout.enableCenteredContent(false);
1125 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001126 }
1127 }
1128
Winson Chung1908d072011-02-24 18:09:44 -08001129 // Set a min page width for PagedView layout if we have more than a single page
1130 if (enforceMinimumPagedWidths) {
1131 setMinimumWidthOverride((childCount > 1) ? mMinPageWidth : 0);
1132 }
1133
1134 // Bound the current page index
Winson Chung03929772011-02-23 17:07:10 -08001135 requestLayout();
1136 post(new Runnable() {
1137 @Override
1138 public void run() {
1139 setCurrentPage(Math.max(0, Math.min(childCount - 1, getCurrentPage())));
1140 forceUpdateAdjacentPagesAlpha();
1141 }
1142 });
Winson Chung80baf5a2010-08-09 16:03:15 -07001143 }
1144
1145 @Override
1146 public void syncPageItems(int page) {
1147 switch (mCustomizationType) {
1148 case WidgetCustomization:
1149 syncWidgetPageItems(page);
1150 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001151 case ShortcutCustomization:
1152 syncListPageItems(page, mShortcutList);
1153 break;
1154 case WallpaperCustomization:
Winson Chung45e1d6e2010-11-09 17:19:49 -08001155 syncWallpaperPageItems(page);
Winson Chung80baf5a2010-08-09 16:03:15 -07001156 break;
Winson Chung5ffd8ea2010-09-23 18:40:29 -07001157 case ApplicationCustomization:
1158 syncAppPageItems(page);
1159 break;
Winson Chung80baf5a2010-08-09 16:03:15 -07001160 }
1161 }
Winson Chunge3193b92010-09-10 11:44:42 -07001162
Winson Chungd0d43012010-09-26 17:26:45 -07001163 @Override
Winson Chunge3193b92010-09-10 11:44:42 -07001164 protected int getAssociatedLowerPageBound(int page) {
1165 return 0;
1166 }
Winson Chungd0d43012010-09-26 17:26:45 -07001167 @Override
Winson Chunge3193b92010-09-10 11:44:42 -07001168 protected int getAssociatedUpperPageBound(int page) {
1169 return getChildCount();
1170 }
Winson Chungd0d43012010-09-26 17:26:45 -07001171
1172 @Override
1173 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -07001174 mode.setTitle(mChoiceModeTitleText);
Winson Chungd0d43012010-09-26 17:26:45 -07001175 return true;
1176 }
1177
1178 @Override
1179 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
1180 return true;
1181 }
1182
1183 @Override
1184 public void onDestroyActionMode(ActionMode mode) {
1185 endChoiceMode();
1186 }
1187
1188 @Override
1189 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
1190 return false;
1191 }
Winson Chung80baf5a2010-08-09 16:03:15 -07001192}