blob: 1da6fe07bb3aa845c19606cf39c5567dd6626eb7 [file] [log] [blame]
Winson Chung785d2eb2011-04-14 16:08:02 -07001/*
2 * Copyright (C) 2011 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
Winson Chung55b65502011-05-26 12:03:43 -070019import android.animation.AnimatorSet;
Winson Chung4b576be2011-04-27 17:40:20 -070020import android.animation.ObjectAnimator;
Winson Chungd2e87b32011-06-02 10:53:07 -070021import android.animation.ValueAnimator;
Winson Chung785d2eb2011-04-14 16:08:02 -070022import android.appwidget.AppWidgetManager;
23import android.appwidget.AppWidgetProviderInfo;
24import android.content.ComponentName;
25import android.content.Context;
26import android.content.Intent;
Winson Chung46af2e82011-05-09 16:00:53 -070027import android.content.pm.ActivityInfo;
Winson Chung785d2eb2011-04-14 16:08:02 -070028import android.content.pm.PackageManager;
29import android.content.pm.ResolveInfo;
Winson Chungf0ea4d32011-06-06 14:27:16 -070030import android.content.res.Configuration;
Winson Chung785d2eb2011-04-14 16:08:02 -070031import android.content.res.Resources;
32import android.content.res.TypedArray;
33import android.graphics.Bitmap;
Winson Chungf0ea4d32011-06-06 14:27:16 -070034import android.graphics.Bitmap.Config;
Winson Chung785d2eb2011-04-14 16:08:02 -070035import android.graphics.Canvas;
Winson Chung70fc4382011-08-08 15:31:33 -070036import android.graphics.PorterDuff;
Winson Chung785d2eb2011-04-14 16:08:02 -070037import android.graphics.Rect;
38import android.graphics.drawable.Drawable;
Winson Chungb44b5242011-06-13 11:32:14 -070039import android.os.AsyncTask;
40import android.os.Process;
Winson Chung785d2eb2011-04-14 16:08:02 -070041import android.util.AttributeSet;
42import android.util.Log;
Winson Chung72d8b392011-07-29 13:56:44 -070043import android.view.Gravity;
Winson Chung785d2eb2011-04-14 16:08:02 -070044import android.view.LayoutInflater;
Winson Chungde1af762011-07-21 16:44:07 -070045import android.view.MotionEvent;
Winson Chung785d2eb2011-04-14 16:08:02 -070046import android.view.View;
Winson Chung63257c12011-05-05 17:06:13 -070047import android.view.ViewGroup;
Winson Chung55b65502011-05-26 12:03:43 -070048import android.view.animation.AccelerateInterpolator;
Winson Chungfd3385f2011-06-15 19:51:24 -070049import android.widget.GridLayout;
Winson Chung785d2eb2011-04-14 16:08:02 -070050import android.widget.ImageView;
Winson Chung55b65502011-05-26 12:03:43 -070051import android.widget.Toast;
Winson Chung785d2eb2011-04-14 16:08:02 -070052
53import com.android.launcher.R;
Adam Cohenc0dcf592011-06-01 15:30:43 -070054import com.android.launcher2.DropTarget.DragObject;
55
56import java.util.ArrayList;
57import java.util.Collections;
58import java.util.Iterator;
59import java.util.List;
Winson Chung785d2eb2011-04-14 16:08:02 -070060
Winson Chungb44b5242011-06-13 11:32:14 -070061/**
62 * A simple callback interface which also provides the results of the task.
63 */
64interface AsyncTaskCallback {
65 void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data);
66}
Winson Chung4e076542011-06-23 13:04:10 -070067
Winson Chungb44b5242011-06-13 11:32:14 -070068/**
69 * The data needed to perform either of the custom AsyncTasks.
70 */
71class AsyncTaskPageData {
Winson Chung875de7e2011-06-28 14:25:17 -070072 enum Type {
73 LoadWidgetPreviewData,
74 LoadHolographicIconsData
75 }
76
Winson Chungb44b5242011-06-13 11:32:14 -070077 AsyncTaskPageData(int p, ArrayList<Object> l, ArrayList<Bitmap> si, AsyncTaskCallback bgR,
78 AsyncTaskCallback postR) {
79 page = p;
80 items = l;
Winson Chung4e076542011-06-23 13:04:10 -070081 sourceImages = si;
82 generatedImages = new ArrayList<Bitmap>();
Winson Chungb44b5242011-06-13 11:32:14 -070083 cellWidth = cellHeight = -1;
84 doInBackgroundCallback = bgR;
85 postExecuteCallback = postR;
86 }
Winson Chungd2945262011-06-24 15:22:14 -070087 AsyncTaskPageData(int p, ArrayList<Object> l, int cw, int ch, int ccx, AsyncTaskCallback bgR,
Winson Chungb44b5242011-06-13 11:32:14 -070088 AsyncTaskCallback postR) {
89 page = p;
90 items = l;
Winson Chung4e076542011-06-23 13:04:10 -070091 generatedImages = new ArrayList<Bitmap>();
Winson Chungb44b5242011-06-13 11:32:14 -070092 cellWidth = cw;
93 cellHeight = ch;
Winson Chungd2945262011-06-24 15:22:14 -070094 cellCountX = ccx;
Winson Chungb44b5242011-06-13 11:32:14 -070095 doInBackgroundCallback = bgR;
96 postExecuteCallback = postR;
97 }
98 int page;
99 ArrayList<Object> items;
Winson Chung4e076542011-06-23 13:04:10 -0700100 ArrayList<Bitmap> sourceImages;
101 ArrayList<Bitmap> generatedImages;
Winson Chungb44b5242011-06-13 11:32:14 -0700102 int cellWidth;
103 int cellHeight;
Winson Chungd2945262011-06-24 15:22:14 -0700104 int cellCountX;
Winson Chungb44b5242011-06-13 11:32:14 -0700105 AsyncTaskCallback doInBackgroundCallback;
106 AsyncTaskCallback postExecuteCallback;
107}
Winson Chung4e076542011-06-23 13:04:10 -0700108
Winson Chungb44b5242011-06-13 11:32:14 -0700109/**
110 * A generic template for an async task used in AppsCustomize.
111 */
112class AppsCustomizeAsyncTask extends AsyncTask<AsyncTaskPageData, Void, AsyncTaskPageData> {
Winson Chung875de7e2011-06-28 14:25:17 -0700113 AppsCustomizeAsyncTask(int p, AppsCustomizePagedView.ContentType t, AsyncTaskPageData.Type ty) {
Winson Chungb44b5242011-06-13 11:32:14 -0700114 page = p;
115 pageContentType = t;
116 threadPriority = Process.THREAD_PRIORITY_DEFAULT;
Winson Chung875de7e2011-06-28 14:25:17 -0700117 dataType = ty;
Winson Chungb44b5242011-06-13 11:32:14 -0700118 }
119 @Override
120 protected AsyncTaskPageData doInBackground(AsyncTaskPageData... params) {
121 if (params.length != 1) return null;
122 // Load each of the widget previews in the background
123 params[0].doInBackgroundCallback.run(this, params[0]);
124 return params[0];
125 }
126 @Override
127 protected void onPostExecute(AsyncTaskPageData result) {
128 // All the widget previews are loaded, so we can just callback to inflate the page
129 result.postExecuteCallback.run(this, result);
130 }
131
132 void setThreadPriority(int p) {
133 threadPriority = p;
134 }
135 void syncThreadPriority() {
136 Process.setThreadPriority(threadPriority);
137 }
138
139 // The page that this async task is associated with
Winson Chung875de7e2011-06-28 14:25:17 -0700140 AsyncTaskPageData.Type dataType;
Winson Chungb44b5242011-06-13 11:32:14 -0700141 int page;
142 AppsCustomizePagedView.ContentType pageContentType;
143 int threadPriority;
144}
Winson Chungb44b5242011-06-13 11:32:14 -0700145
146/**
147 * The Apps/Customize page that displays all the applications, widgets, and shortcuts.
148 */
Winson Chung785d2eb2011-04-14 16:08:02 -0700149public class AppsCustomizePagedView extends PagedViewWithDraggableItems implements
150 AllAppsView, View.OnClickListener, DragSource {
151 static final String LOG_TAG = "AppsCustomizePagedView";
152
153 /**
154 * The different content types that this paged view can show.
155 */
156 public enum ContentType {
157 Applications,
Winson Chung6a26e5b2011-05-26 14:36:06 -0700158 Widgets
Winson Chung785d2eb2011-04-14 16:08:02 -0700159 }
160
161 // Refs
162 private Launcher mLauncher;
163 private DragController mDragController;
164 private final LayoutInflater mLayoutInflater;
165 private final PackageManager mPackageManager;
166
167 // Content
168 private ContentType mContentType;
169 private ArrayList<ApplicationInfo> mApps;
Winson Chungd2945262011-06-24 15:22:14 -0700170 private ArrayList<Object> mWidgets;
Winson Chung1ed747a2011-05-03 16:18:34 -0700171
172 // Caching
Winson Chungb44b5242011-06-13 11:32:14 -0700173 private Canvas mCanvas;
Winson Chung1ed747a2011-05-03 16:18:34 -0700174 private Drawable mDefaultWidgetBackground;
Winson Chung4dbea792011-05-05 14:21:32 -0700175 private IconCache mIconCache;
Winson Chung70fc4382011-08-08 15:31:33 -0700176 private int mDragViewMultiplyColor;
Winson Chung785d2eb2011-04-14 16:08:02 -0700177
178 // Dimens
179 private int mContentWidth;
Winson Chungd2945262011-06-24 15:22:14 -0700180 private int mAppIconSize;
Winson Chung4b576be2011-04-27 17:40:20 -0700181 private int mMaxWidgetSpan, mMinWidgetSpan;
Winson Chung4b576be2011-04-27 17:40:20 -0700182 private int mWidgetCountX, mWidgetCountY;
Winson Chungd2945262011-06-24 15:22:14 -0700183 private int mWidgetWidthGap, mWidgetHeightGap;
Winson Chung1ed747a2011-05-03 16:18:34 -0700184 private final int mWidgetPreviewIconPaddedDimension;
185 private final float sWidgetPreviewIconPaddingPercentage = 0.25f;
Winson Chung785d2eb2011-04-14 16:08:02 -0700186 private PagedViewCellLayout mWidgetSpacingLayout;
187
Winson Chungb44b5242011-06-13 11:32:14 -0700188 // Previews & outlines
189 ArrayList<AppsCustomizeAsyncTask> mRunningTasks;
190 private HolographicOutlineHelper mHolographicOutlineHelper;
Winson Chungf314b0e2011-08-16 11:54:27 -0700191 private static final int sPageSleepDelay = 200;
Winson Chung4b576be2011-04-27 17:40:20 -0700192
Winson Chung785d2eb2011-04-14 16:08:02 -0700193 public AppsCustomizePagedView(Context context, AttributeSet attrs) {
194 super(context, attrs);
195 mLayoutInflater = LayoutInflater.from(context);
196 mPackageManager = context.getPackageManager();
197 mContentType = ContentType.Applications;
198 mApps = new ArrayList<ApplicationInfo>();
Winson Chung1ed747a2011-05-03 16:18:34 -0700199 mWidgets = new ArrayList<Object>();
Winson Chung4dbea792011-05-05 14:21:32 -0700200 mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache();
Winson Chungb44b5242011-06-13 11:32:14 -0700201 mHolographicOutlineHelper = new HolographicOutlineHelper();
202 mCanvas = new Canvas();
203 mRunningTasks = new ArrayList<AppsCustomizeAsyncTask>();
Winson Chung1ed747a2011-05-03 16:18:34 -0700204
205 // Save the default widget preview background
206 Resources resources = context.getResources();
Winson Chung967289b2011-06-30 18:09:30 -0700207 mDefaultWidgetBackground = resources.getDrawable(R.drawable.default_widget_preview_holo);
Winson Chung70fc4382011-08-08 15:31:33 -0700208 mAppIconSize = resources.getDimensionPixelSize(R.dimen.app_icon_size);
209 mDragViewMultiplyColor = resources.getColor(R.color.drag_view_multiply_color);
Winson Chung785d2eb2011-04-14 16:08:02 -0700210
211 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, 0, 0);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700212 // TODO-APPS_CUSTOMIZE: remove these unnecessary attrs after
Winson Chung785d2eb2011-04-14 16:08:02 -0700213 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
214 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
215 a.recycle();
Winson Chung4b576be2011-04-27 17:40:20 -0700216 a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700217 mWidgetWidthGap =
218 a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellWidthGap, 0);
219 mWidgetHeightGap =
220 a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellHeightGap, 0);
Winson Chung4b576be2011-04-27 17:40:20 -0700221 mWidgetCountX = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountX, 2);
222 mWidgetCountY = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountY, 2);
223 a.recycle();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700224 mWidgetSpacingLayout = new PagedViewCellLayout(getContext());
Winson Chung4b576be2011-04-27 17:40:20 -0700225
226 // The max widget span is the length N, such that NxN is the largest bounds that the widget
227 // preview can be before applying the widget scaling
228 mMinWidgetSpan = 1;
229 mMaxWidgetSpan = 3;
Winson Chung1ed747a2011-05-03 16:18:34 -0700230
231 // The padding on the non-matched dimension for the default widget preview icons
232 // (top + bottom)
Winson Chung1ed747a2011-05-03 16:18:34 -0700233 mWidgetPreviewIconPaddedDimension =
Winson Chungd2945262011-06-24 15:22:14 -0700234 (int) (mAppIconSize * (1 + (2 * sWidgetPreviewIconPaddingPercentage)));
Winson Chung54c725c2011-08-03 12:03:40 -0700235 mFadeInAdjacentScreens = LauncherApplication.isScreenLarge();
Winson Chung785d2eb2011-04-14 16:08:02 -0700236 }
237
238 @Override
239 protected void init() {
240 super.init();
241 mCenterPagesVertically = false;
242
243 Context context = getContext();
244 Resources r = context.getResources();
245 setDragSlopeThreshold(r.getInteger(R.integer.config_appsCustomizeDragSlopeThreshold)/100f);
246 }
247
Winson Chungf0ea4d32011-06-06 14:27:16 -0700248 @Override
Michael Jurkad771c962011-08-09 15:00:48 -0700249 protected void onUnhandledTap(MotionEvent ev) {
250 if (LauncherApplication.isScreenLarge()) {
Winson Chungde1af762011-07-21 16:44:07 -0700251 // Dismiss AppsCustomize if we tap
252 mLauncher.showWorkspace(true);
253 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700254 }
255
256 /**
257 * This differs from isDataReady as this is the test done if isDataReady is not set.
258 */
259 private boolean testDataReady() {
Winson Chungfd3385f2011-06-15 19:51:24 -0700260 // We only do this test once, and we default to the Applications page, so we only really
261 // have to wait for there to be apps.
262 return !mApps.isEmpty();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700263 }
264
265 protected void onDataReady(int width, int height) {
266 // Note that we transpose the counts in portrait so that we get a similar layout
267 boolean isLandscape = getResources().getConfiguration().orientation ==
268 Configuration.ORIENTATION_LANDSCAPE;
269 int maxCellCountX = Integer.MAX_VALUE;
270 int maxCellCountY = Integer.MAX_VALUE;
271 if (LauncherApplication.isScreenLarge()) {
272 maxCellCountX = (isLandscape ? LauncherModel.getCellCountX() :
273 LauncherModel.getCellCountY());
274 maxCellCountY = (isLandscape ? LauncherModel.getCellCountY() :
275 LauncherModel.getCellCountX());
276 }
277
278 // Now that the data is ready, we can calculate the content width, the number of cells to
279 // use for each page
280 mWidgetSpacingLayout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
281 mWidgetSpacingLayout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
282 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
283 mWidgetSpacingLayout.calculateCellCount(width, height, maxCellCountX, maxCellCountY);
284 mCellCountX = mWidgetSpacingLayout.getCellCountX();
285 mCellCountY = mWidgetSpacingLayout.getCellCountY();
Winson Chung5a808352011-06-27 19:08:49 -0700286
Winson Chungdb1138b2011-06-30 14:39:35 -0700287 // Force a measure to update recalculate the gaps
288 int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
289 int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
290 mWidgetSpacingLayout.measure(widthSpec, heightSpec);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700291 mContentWidth = mWidgetSpacingLayout.getContentWidth();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700292 invalidatePageData();
293 }
294
295 @Override
296 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
297 int width = MeasureSpec.getSize(widthMeasureSpec);
298 int height = MeasureSpec.getSize(heightMeasureSpec);
299 if (!isDataReady()) {
300 if (testDataReady()) {
301 setDataIsReady();
302 setMeasuredDimension(width, height);
303 onDataReady(width, height);
304 }
305 }
306
307 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
308 }
309
Winson Chung34efdaf2011-05-24 14:19:56 -0700310 /** Removes and returns the ResolveInfo with the specified ComponentName */
311 private ResolveInfo removeResolveInfoWithComponentName(List<ResolveInfo> list,
312 ComponentName cn) {
313 Iterator<ResolveInfo> iter = list.iterator();
314 while (iter.hasNext()) {
315 ResolveInfo rinfo = iter.next();
316 ActivityInfo info = rinfo.activityInfo;
317 ComponentName c = new ComponentName(info.packageName, info.name);
318 if (c.equals(cn)) {
319 iter.remove();
320 return rinfo;
321 }
322 }
323 return null;
324 }
325
Winson Chung785d2eb2011-04-14 16:08:02 -0700326 public void onPackagesUpdated() {
Winson Chung1ed747a2011-05-03 16:18:34 -0700327 // Get the list of widgets and shortcuts
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700328 boolean wasEmpty = mWidgets.isEmpty();
Winson Chung1ed747a2011-05-03 16:18:34 -0700329 mWidgets.clear();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700330 List<AppWidgetProviderInfo> widgets =
331 AppWidgetManager.getInstance(mLauncher).getInstalledProviders();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700332 Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
333 List<ResolveInfo> shortcuts = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700334 mWidgets.addAll(widgets);
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700335 mWidgets.addAll(shortcuts);
336 Collections.sort(mWidgets,
337 new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
Winson Chung785d2eb2011-04-14 16:08:02 -0700338
Winson Chung875de7e2011-06-28 14:25:17 -0700339 if (wasEmpty) {
340 // The next layout pass will trigger data-ready if both widgets and apps are set, so request
341 // a layout to do this test and invalidate the page data when ready.
342 if (testDataReady()) requestLayout();
343 } else {
344 invalidatePageData();
345 }
Winson Chung4b576be2011-04-27 17:40:20 -0700346 }
347
348 @Override
349 public void onClick(View v) {
Adam Cohenfc53cd22011-07-20 15:45:11 -0700350 // When we have exited all apps or are in transition, disregard clicks
351 if (!mLauncher.isAllAppsCustomizeOpen() ||
352 mLauncher.getWorkspace().isSwitchingState()) return;
353
Winson Chung4b576be2011-04-27 17:40:20 -0700354 if (v instanceof PagedViewIcon) {
355 // Animate some feedback to the click
356 final ApplicationInfo appInfo = (ApplicationInfo) v.getTag();
357 animateClickFeedback(v, new Runnable() {
358 @Override
359 public void run() {
360 mLauncher.startActivitySafely(appInfo.intent, appInfo);
361 }
362 });
363 } else if (v instanceof PagedViewWidget) {
Winson Chungd2e87b32011-06-02 10:53:07 -0700364 // Let the user know that they have to long press to add a widget
365 Toast.makeText(getContext(), R.string.long_press_widget_to_add,
366 Toast.LENGTH_SHORT).show();
Winson Chung46af2e82011-05-09 16:00:53 -0700367
Winson Chungd2e87b32011-06-02 10:53:07 -0700368 // Create a little animation to show that the widget can move
369 float offsetY = getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY);
370 final ImageView p = (ImageView) v.findViewById(R.id.widget_preview);
371 AnimatorSet bounce = new AnimatorSet();
372 ValueAnimator tyuAnim = ObjectAnimator.ofFloat(p, "translationY", offsetY);
373 tyuAnim.setDuration(125);
374 ValueAnimator tydAnim = ObjectAnimator.ofFloat(p, "translationY", 0f);
375 tydAnim.setDuration(100);
376 bounce.play(tyuAnim).before(tydAnim);
377 bounce.setInterpolator(new AccelerateInterpolator());
378 bounce.start();
Winson Chung4b576be2011-04-27 17:40:20 -0700379 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700380 }
381
382 /*
383 * PagedViewWithDraggableItems implementation
384 */
385 @Override
386 protected void determineDraggingStart(android.view.MotionEvent ev) {
387 // Disable dragging by pulling an app down for now.
388 }
Adam Cohenac8c8762011-07-13 11:15:27 -0700389
Winson Chung4b576be2011-04-27 17:40:20 -0700390 private void beginDraggingApplication(View v) {
Adam Cohenac8c8762011-07-13 11:15:27 -0700391 mLauncher.getWorkspace().onDragStartedWithItem(v);
392 mLauncher.getWorkspace().beginDragShared(v, this);
Winson Chung4b576be2011-04-27 17:40:20 -0700393 }
Adam Cohenac8c8762011-07-13 11:15:27 -0700394
Winson Chung4b576be2011-04-27 17:40:20 -0700395 private void beginDraggingWidget(View v) {
396 // Get the widget preview as the drag representation
397 ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
Winson Chung1ed747a2011-05-03 16:18:34 -0700398 PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();
Winson Chung4b576be2011-04-27 17:40:20 -0700399
400 // Compose the drag image
Winson Chung1ed747a2011-05-03 16:18:34 -0700401 Bitmap b;
Winson Chung4b576be2011-04-27 17:40:20 -0700402 Drawable preview = image.getDrawable();
403 int w = preview.getIntrinsicWidth();
404 int h = preview.getIntrinsicHeight();
Winson Chung1ed747a2011-05-03 16:18:34 -0700405 if (createItemInfo instanceof PendingAddWidgetInfo) {
406 PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) createItemInfo;
407 int[] spanXY = CellLayout.rectToCell(getResources(),
408 createWidgetInfo.minWidth, createWidgetInfo.minHeight, null);
409 createItemInfo.spanX = spanXY[0];
410 createItemInfo.spanY = spanXY[1];
411
412 b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Winson Chung70fc4382011-08-08 15:31:33 -0700413 renderDrawableToBitmap(preview, b, 0, 0, w, h, 1, 1, mDragViewMultiplyColor);
Winson Chung1ed747a2011-05-03 16:18:34 -0700414 } else {
415 // Workaround for the fact that we don't keep the original ResolveInfo associated with
416 // the shortcut around. To get the icon, we just render the preview image (which has
417 // the shortcut icon) to a new drag bitmap that clips the non-icon space.
418 b = Bitmap.createBitmap(mWidgetPreviewIconPaddedDimension,
419 mWidgetPreviewIconPaddedDimension, Bitmap.Config.ARGB_8888);
Winson Chungb44b5242011-06-13 11:32:14 -0700420 mCanvas.setBitmap(b);
421 mCanvas.save();
422 preview.draw(mCanvas);
423 mCanvas.restore();
Winson Chung70fc4382011-08-08 15:31:33 -0700424 mCanvas.drawColor(mDragViewMultiplyColor, PorterDuff.Mode.MULTIPLY);
Adam Cohenaaf473c2011-08-03 12:02:47 -0700425 mCanvas.setBitmap(null);
Winson Chung1ed747a2011-05-03 16:18:34 -0700426 createItemInfo.spanX = createItemInfo.spanY = 1;
427 }
Winson Chung4b576be2011-04-27 17:40:20 -0700428
429 // Start the drag
Winson Chung4b576be2011-04-27 17:40:20 -0700430 mLauncher.lockScreenOrientation();
Winson Chung1ed747a2011-05-03 16:18:34 -0700431 mLauncher.getWorkspace().onDragStartedWithItemSpans(createItemInfo.spanX,
432 createItemInfo.spanY, b);
433 mDragController.startDrag(image, b, this, createItemInfo,
Winson Chung4b576be2011-04-27 17:40:20 -0700434 DragController.DRAG_ACTION_COPY, null);
435 b.recycle();
436 }
437 @Override
438 protected boolean beginDragging(View v) {
439 if (!super.beginDragging(v)) return false;
440
Winson Chungc07918d2011-07-01 15:35:26 -0700441 // Go into spring loaded mode (must happen before we startDrag())
442 int currentPageIndex = mLauncher.getWorkspace().getCurrentPage();
443 CellLayout currentPage = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPageIndex);
444 mLauncher.enterSpringLoadedDragMode(currentPage);
Winson Chungfc79c802011-05-02 13:35:34 -0700445
Winson Chung4b576be2011-04-27 17:40:20 -0700446 if (v instanceof PagedViewIcon) {
447 beginDraggingApplication(v);
448 } else if (v instanceof PagedViewWidget) {
449 beginDraggingWidget(v);
450 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700451 return true;
452 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700453 private void endDragging(View target, boolean success) {
Winson Chung785d2eb2011-04-14 16:08:02 -0700454 mLauncher.getWorkspace().onDragStopped(success);
Adam Cohend4d7aa52011-07-19 21:47:37 -0700455 if (!success || (target != mLauncher.getWorkspace() &&
456 !(target instanceof DeleteDropTarget))) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700457 // Exit spring loaded mode if we have not successfully dropped or have not handled the
458 // drop in Workspace
459 mLauncher.exitSpringLoadedDragMode();
460 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700461 mLauncher.unlockScreenOrientation();
Winson Chungb26f3d62011-06-02 10:49:29 -0700462
Winson Chung785d2eb2011-04-14 16:08:02 -0700463 }
464
Winson Chung785d2eb2011-04-14 16:08:02 -0700465 @Override
Adam Cohenc0dcf592011-06-01 15:30:43 -0700466 public void onDropCompleted(View target, DragObject d, boolean success) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700467 endDragging(target, success);
Winson Chungfc79c802011-05-02 13:35:34 -0700468
469 // Display an error message if the drag failed due to there not being enough space on the
470 // target layout we were dropping on.
471 if (!success) {
472 boolean showOutOfSpaceMessage = false;
473 if (target instanceof Workspace) {
474 int currentScreen = mLauncher.getCurrentWorkspaceScreen();
475 Workspace workspace = (Workspace) target;
476 CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen);
Adam Cohenc0dcf592011-06-01 15:30:43 -0700477 ItemInfo itemInfo = (ItemInfo) d.dragInfo;
Winson Chungfc79c802011-05-02 13:35:34 -0700478 if (layout != null) {
479 layout.calculateSpans(itemInfo);
480 showOutOfSpaceMessage =
481 !layout.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY);
482 }
483 }
484 // TODO-APPS_CUSTOMIZE: We need to handle this for folders as well later.
485 if (showOutOfSpaceMessage) {
486 mLauncher.showOutOfSpaceMessage();
487 }
488 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700489 }
490
491 public void setContentType(ContentType type) {
492 mContentType = type;
Winson Chungf314b0e2011-08-16 11:54:27 -0700493 invalidatePageData(0, true);
Winson Chung785d2eb2011-04-14 16:08:02 -0700494 }
495
Winson Chungb44b5242011-06-13 11:32:14 -0700496 public boolean isContentType(ContentType type) {
497 return (mContentType == type);
498 }
499
Winson Chung5a808352011-06-27 19:08:49 -0700500 public void setCurrentPageToWidgets() {
501 invalidatePageData(0);
502 }
Winson Chung5a808352011-06-27 19:08:49 -0700503
Winson Chung785d2eb2011-04-14 16:08:02 -0700504 /*
505 * Apps PagedView implementation
506 */
Winson Chung63257c12011-05-05 17:06:13 -0700507 private void setVisibilityOnChildren(ViewGroup layout, int visibility) {
508 int childCount = layout.getChildCount();
509 for (int i = 0; i < childCount; ++i) {
510 layout.getChildAt(i).setVisibility(visibility);
511 }
512 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700513 private void setupPage(PagedViewCellLayout layout) {
514 layout.setCellCount(mCellCountX, mCellCountY);
515 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
516 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
517 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
518
Winson Chung63257c12011-05-05 17:06:13 -0700519 // Note: We force a measure here to get around the fact that when we do layout calculations
520 // immediately after syncing, we don't have a proper width. That said, we already know the
521 // expected page width, so we can actually optimize by hiding all the TextView-based
522 // children that are expensive to measure, and let that happen naturally later.
523 setVisibilityOnChildren(layout, View.GONE);
Winson Chungdb1138b2011-06-30 14:39:35 -0700524 int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
Winson Chung785d2eb2011-04-14 16:08:02 -0700525 int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
Winson Chung63257c12011-05-05 17:06:13 -0700526 layout.setMinimumWidth(getPageContentWidth());
Winson Chung785d2eb2011-04-14 16:08:02 -0700527 layout.measure(widthSpec, heightSpec);
Winson Chung63257c12011-05-05 17:06:13 -0700528 setVisibilityOnChildren(layout, View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -0700529 }
530 public void syncAppsPages() {
531 // Ensure that we have the right number of pages
532 Context context = getContext();
533 int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
534 for (int i = 0; i < numPages; ++i) {
535 PagedViewCellLayout layout = new PagedViewCellLayout(context);
536 setupPage(layout);
537 addView(layout);
538 }
539 }
Winson Chungf314b0e2011-08-16 11:54:27 -0700540 public void syncAppsPageItems(int page, boolean immediate) {
Winson Chung785d2eb2011-04-14 16:08:02 -0700541 // ensure that we have the right number of items on the pages
542 int numPages = getPageCount();
543 int numCells = mCellCountX * mCellCountY;
544 int startIndex = page * numCells;
545 int endIndex = Math.min(startIndex + numCells, mApps.size());
546 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung875de7e2011-06-28 14:25:17 -0700547
Winson Chung785d2eb2011-04-14 16:08:02 -0700548 layout.removeAllViewsOnPage();
Winson Chungb44b5242011-06-13 11:32:14 -0700549 ArrayList<Object> items = new ArrayList<Object>();
550 ArrayList<Bitmap> images = new ArrayList<Bitmap>();
Winson Chung785d2eb2011-04-14 16:08:02 -0700551 for (int i = startIndex; i < endIndex; ++i) {
552 ApplicationInfo info = mApps.get(i);
553 PagedViewIcon icon = (PagedViewIcon) mLayoutInflater.inflate(
554 R.layout.apps_customize_application, layout, false);
Winson Chungb44b5242011-06-13 11:32:14 -0700555 icon.applyFromApplicationInfo(info, true, mHolographicOutlineHelper);
Winson Chung785d2eb2011-04-14 16:08:02 -0700556 icon.setOnClickListener(this);
557 icon.setOnLongClickListener(this);
558 icon.setOnTouchListener(this);
559
560 int index = i - startIndex;
561 int x = index % mCellCountX;
562 int y = index / mCellCountX;
Winson Chung6a70e9f2011-05-17 16:24:49 -0700563 layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
Winson Chungb44b5242011-06-13 11:32:14 -0700564
565 items.add(info);
566 images.add(info.iconBitmap);
Winson Chung785d2eb2011-04-14 16:08:02 -0700567 }
Winson Chungf0ea4d32011-06-06 14:27:16 -0700568
569 // Create the hardware layers
570 layout.allowHardwareLayerCreation();
571 layout.createHardwareLayers();
Winson Chungb44b5242011-06-13 11:32:14 -0700572
Winson Chung54c725c2011-08-03 12:03:40 -0700573 if (mFadeInAdjacentScreens) {
574 prepareGenerateHoloOutlinesTask(page, items, images);
575 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700576 }
Winson Chungb44b5242011-06-13 11:32:14 -0700577
578 /**
579 * Return the appropriate thread priority for loading for a given page (we give the current
580 * page much higher priority)
581 */
582 private int getThreadPriorityForPage(int page) {
583 // TODO-APPS_CUSTOMIZE: detect number of cores and set thread priorities accordingly below
584 int pageDiff = Math.abs(page - mCurrentPage);
585 if (pageDiff <= 0) {
586 // return Process.THREAD_PRIORITY_DEFAULT;
587 return Process.THREAD_PRIORITY_MORE_FAVORABLE;
588 } else if (pageDiff <= 1) {
589 // return Process.THREAD_PRIORITY_BACKGROUND;
590 return Process.THREAD_PRIORITY_DEFAULT;
591 } else {
592 // return Process.THREAD_PRIORITY_LOWEST;
593 return Process.THREAD_PRIORITY_DEFAULT;
594 }
595 }
Winson Chungf314b0e2011-08-16 11:54:27 -0700596 private int getSleepForPage(int page) {
597 int pageDiff = Math.abs(page - mCurrentPage) - 1;
598 return Math.max(0, pageDiff * sPageSleepDelay);
599 }
Winson Chungb44b5242011-06-13 11:32:14 -0700600 /**
601 * Creates and executes a new AsyncTask to load a page of widget previews.
602 */
603 private void prepareLoadWidgetPreviewsTask(int page, ArrayList<Object> widgets,
Winson Chungd2945262011-06-24 15:22:14 -0700604 int cellWidth, int cellHeight, int cellCountX) {
Winson Chungb44b5242011-06-13 11:32:14 -0700605 // Prune all tasks that are no longer needed
606 Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
607 while (iter.hasNext()) {
608 AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
609 int taskPage = task.page;
Winson Chung875de7e2011-06-28 14:25:17 -0700610 if ((taskPage == page) ||
611 taskPage < getAssociatedLowerPageBound(mCurrentPage) ||
Winson Chung4e076542011-06-23 13:04:10 -0700612 taskPage > getAssociatedUpperPageBound(mCurrentPage)) {
Winson Chungb44b5242011-06-13 11:32:14 -0700613 task.cancel(false);
614 iter.remove();
615 } else {
616 task.setThreadPriority(getThreadPriorityForPage(taskPage));
617 }
618 }
619
Winson Chungf314b0e2011-08-16 11:54:27 -0700620 // We introduce a slight delay to order the loading of side pages so that we don't thrash
621 final int sleepMs = getSleepForPage(page);
Winson Chungb44b5242011-06-13 11:32:14 -0700622 AsyncTaskPageData pageData = new AsyncTaskPageData(page, widgets, cellWidth, cellHeight,
Winson Chungd2945262011-06-24 15:22:14 -0700623 cellCountX, new AsyncTaskCallback() {
Winson Chungb44b5242011-06-13 11:32:14 -0700624 @Override
625 public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) {
Winson Chungf314b0e2011-08-16 11:54:27 -0700626 try {
627 Thread.sleep(sleepMs);
628 } catch (Exception e) {}
629 loadWidgetPreviewsInBackground(task, data);
Winson Chungb44b5242011-06-13 11:32:14 -0700630 }
631 },
632 new AsyncTaskCallback() {
633 @Override
634 public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) {
635 mRunningTasks.remove(task);
Winson Chung875de7e2011-06-28 14:25:17 -0700636 if (task.isCancelled()) return;
Winson Chungb44b5242011-06-13 11:32:14 -0700637 if (task.page > getPageCount()) return;
638 if (task.pageContentType != mContentType) return;
639 onSyncWidgetPageItems(data);
640 }
641 });
642
643 // Ensure that the task is appropriately prioritized and runs in parallel
Winson Chung875de7e2011-06-28 14:25:17 -0700644 AppsCustomizeAsyncTask t = new AppsCustomizeAsyncTask(page, mContentType,
645 AsyncTaskPageData.Type.LoadWidgetPreviewData);
Winson Chungb44b5242011-06-13 11:32:14 -0700646 t.setThreadPriority(getThreadPriorityForPage(page));
647 t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageData);
648 mRunningTasks.add(t);
649 }
650 /**
651 * Creates and executes a new AsyncTask to load the outlines for a page of content.
652 */
653 private void prepareGenerateHoloOutlinesTask(int page, ArrayList<Object> items,
654 ArrayList<Bitmap> images) {
Winson Chung875de7e2011-06-28 14:25:17 -0700655 // Prune old tasks for this page
656 Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
657 while (iter.hasNext()) {
658 AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
659 int taskPage = task.page;
660 if ((taskPage == page) &&
661 (task.dataType == AsyncTaskPageData.Type.LoadHolographicIconsData)) {
662 task.cancel(false);
663 iter.remove();
664 }
665 }
666
Winson Chungb44b5242011-06-13 11:32:14 -0700667 AsyncTaskPageData pageData = new AsyncTaskPageData(page, items, images,
668 new AsyncTaskCallback() {
669 @Override
670 public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) {
671 // Ensure that this task starts running at the correct priority
672 task.syncThreadPriority();
673
Winson Chung4e076542011-06-23 13:04:10 -0700674 ArrayList<Bitmap> images = data.generatedImages;
675 ArrayList<Bitmap> srcImages = data.sourceImages;
Winson Chungb44b5242011-06-13 11:32:14 -0700676 int count = srcImages.size();
677 Canvas c = new Canvas();
678 for (int i = 0; i < count && !task.isCancelled(); ++i) {
679 // Before work on each item, ensure that this task is running at the correct
680 // priority
681 task.syncThreadPriority();
682
683 Bitmap b = srcImages.get(i);
684 Bitmap outline = Bitmap.createBitmap(b.getWidth(), b.getHeight(),
685 Bitmap.Config.ARGB_8888);
686
687 c.setBitmap(outline);
688 c.save();
689 c.drawBitmap(b, 0, 0, null);
690 c.restore();
Adam Cohenaaf473c2011-08-03 12:02:47 -0700691 c.setBitmap(null);
Winson Chungb44b5242011-06-13 11:32:14 -0700692
693 images.add(outline);
694 }
695 }
696 },
697 new AsyncTaskCallback() {
698 @Override
699 public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) {
700 mRunningTasks.remove(task);
Winson Chung875de7e2011-06-28 14:25:17 -0700701 if (task.isCancelled()) return;
Winson Chungb44b5242011-06-13 11:32:14 -0700702 if (task.page > getPageCount()) return;
703 if (task.pageContentType != mContentType) return;
704 onHolographicPageItemsLoaded(data);
705 }
706 });
707
708 // Ensure that the outline task always runs in the background, serially
Winson Chung4e076542011-06-23 13:04:10 -0700709 AppsCustomizeAsyncTask t =
Winson Chung875de7e2011-06-28 14:25:17 -0700710 new AppsCustomizeAsyncTask(page, mContentType,
711 AsyncTaskPageData.Type.LoadHolographicIconsData);
Winson Chungb44b5242011-06-13 11:32:14 -0700712 t.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
713 t.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, pageData);
714 mRunningTasks.add(t);
715 }
716
Winson Chung785d2eb2011-04-14 16:08:02 -0700717 /*
718 * Widgets PagedView implementation
719 */
Winson Chung4e6a9762011-05-09 11:56:34 -0700720 private void setupPage(PagedViewGridLayout layout) {
Winson Chung785d2eb2011-04-14 16:08:02 -0700721 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
722 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chung63257c12011-05-05 17:06:13 -0700723
724 // Note: We force a measure here to get around the fact that when we do layout calculations
Winson Chungd52f3d82011-07-12 14:29:11 -0700725 // immediately after syncing, we don't have a proper width.
Winson Chung63257c12011-05-05 17:06:13 -0700726 int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
727 int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
Winson Chung785d2eb2011-04-14 16:08:02 -0700728 layout.setMinimumWidth(getPageContentWidth());
Winson Chung63257c12011-05-05 17:06:13 -0700729 layout.measure(widthSpec, heightSpec);
Winson Chung785d2eb2011-04-14 16:08:02 -0700730 }
Michael Jurkabe69cc82011-07-07 16:05:33 -0700731 private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
Winson Chung785d2eb2011-04-14 16:08:02 -0700732 float scaleX, float scaleY) {
Winson Chung70fc4382011-08-08 15:31:33 -0700733 renderDrawableToBitmap(d, bitmap, x, y, w, h, scaleX, scaleY, 0xFFFFFFFF);
734 }
735 private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
736 float scaleX, float scaleY, int multiplyColor) {
Winson Chung201bc822011-06-20 15:41:53 -0700737 if (bitmap != null) {
Winson Chungb44b5242011-06-13 11:32:14 -0700738 Canvas c = new Canvas(bitmap);
Winson Chung201bc822011-06-20 15:41:53 -0700739 c.scale(scaleX, scaleY);
740 Rect oldBounds = d.copyBounds();
741 d.setBounds(x, y, x + w, y + h);
742 d.draw(c);
743 d.setBounds(oldBounds); // Restore the bounds
Winson Chung70fc4382011-08-08 15:31:33 -0700744 if (multiplyColor != 0xFFFFFFFF) {
745 c.drawColor(mDragViewMultiplyColor, PorterDuff.Mode.MULTIPLY);
746 }
Adam Cohenaaf473c2011-08-03 12:02:47 -0700747 c.setBitmap(null);
Winson Chung201bc822011-06-20 15:41:53 -0700748 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700749 }
Winson Chungd2945262011-06-24 15:22:14 -0700750 private Bitmap getShortcutPreview(ResolveInfo info, int cellWidth, int cellHeight) {
Winson Chung1ed747a2011-05-03 16:18:34 -0700751 // Render the icon
Winson Chungd2945262011-06-24 15:22:14 -0700752 Bitmap preview = Bitmap.createBitmap(cellWidth, mAppIconSize, Config.ARGB_8888);
Winson Chung4dbea792011-05-05 14:21:32 -0700753 Drawable icon = mIconCache.getFullResIcon(info, mPackageManager);
Winson Chungd2945262011-06-24 15:22:14 -0700754 renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize, 1f, 1f);
Winson Chungb44b5242011-06-13 11:32:14 -0700755 return preview;
Winson Chung1ed747a2011-05-03 16:18:34 -0700756 }
Winson Chung4e076542011-06-23 13:04:10 -0700757 private Bitmap getWidgetPreview(AppWidgetProviderInfo info,
Winson Chungb44b5242011-06-13 11:32:14 -0700758 int cellHSpan, int cellVSpan, int cellWidth, int cellHeight) {
Winson Chung1ed747a2011-05-03 16:18:34 -0700759
Winson Chung4b576be2011-04-27 17:40:20 -0700760 // Calculate the size of the drawable
761 cellHSpan = Math.max(mMinWidgetSpan, Math.min(mMaxWidgetSpan, cellHSpan));
762 cellVSpan = Math.max(mMinWidgetSpan, Math.min(mMaxWidgetSpan, cellVSpan));
763 int expectedWidth = mWidgetSpacingLayout.estimateCellWidth(cellHSpan);
764 int expectedHeight = mWidgetSpacingLayout.estimateCellHeight(cellVSpan);
765
766 // Scale down the bitmap to fit the space
767 float widgetPreviewScale = (float) cellWidth / expectedWidth;
768 expectedWidth = (int) (widgetPreviewScale * expectedWidth);
769 expectedHeight = (int) (widgetPreviewScale * expectedHeight);
770
771 // Load the preview image if possible
772 String packageName = info.provider.getPackageName();
773 Drawable drawable = null;
Winson Chungb44b5242011-06-13 11:32:14 -0700774 Bitmap preview = null;
Winson Chung4b576be2011-04-27 17:40:20 -0700775 if (info.previewImage != 0) {
776 drawable = mPackageManager.getDrawable(packageName, info.previewImage, null);
777 if (drawable == null) {
778 Log.w(LOG_TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon)
779 + " for provider: " + info.provider);
780 } else {
781 // Scale down the preview to the dimensions we want
782 int imageWidth = drawable.getIntrinsicWidth();
783 int imageHeight = drawable.getIntrinsicHeight();
784 float aspect = (float) imageWidth / imageHeight;
785 int newWidth = imageWidth;
786 int newHeight = imageHeight;
787 if (aspect > 1f) {
788 newWidth = expectedWidth;
789 newHeight = (int) (imageHeight * ((float) expectedWidth / imageWidth));
790 } else {
791 newHeight = expectedHeight;
792 newWidth = (int) (imageWidth * ((float) expectedHeight / imageHeight));
793 }
794
Winson Chungb44b5242011-06-13 11:32:14 -0700795 preview = Bitmap.createBitmap(newWidth, newHeight, Config.ARGB_8888);
Winson Chung4b576be2011-04-27 17:40:20 -0700796 renderDrawableToBitmap(drawable, preview, 0, 0, newWidth, newHeight, 1f, 1f);
Winson Chung4b576be2011-04-27 17:40:20 -0700797 }
798 }
799
800 // Generate a preview image if we couldn't load one
801 if (drawable == null) {
Winson Chung1ed747a2011-05-03 16:18:34 -0700802 Resources resources = mLauncher.getResources();
Winson Chung273c1022011-07-11 13:40:52 -0700803 int bitmapWidth;
804 int bitmapHeight;
Winson Chung1ed747a2011-05-03 16:18:34 -0700805
Winson Chung273c1022011-07-11 13:40:52 -0700806 // Specify the dimensions of the bitmap (since we are using a default preview bg with
807 // the full icon, we only imply the aspect ratio of the widget)
808 if (cellHSpan == cellVSpan) {
809 bitmapWidth = bitmapHeight = cellWidth;
810 expectedWidth = expectedHeight = mWidgetPreviewIconPaddedDimension;
811 } else if (cellHSpan >= cellVSpan) {
812 bitmapWidth = expectedWidth = cellWidth;
813 bitmapHeight = expectedHeight = mWidgetPreviewIconPaddedDimension;
Winson Chung1ed747a2011-05-03 16:18:34 -0700814 } else {
815 // Note that in vertical widgets, we might not have enough space due to the text
816 // label, so be conservative and use the width as a height bound
Winson Chung273c1022011-07-11 13:40:52 -0700817 bitmapWidth = expectedWidth = mWidgetPreviewIconPaddedDimension;
818 bitmapHeight = expectedHeight = cellWidth;
Winson Chung1ed747a2011-05-03 16:18:34 -0700819 }
Winson Chung4b576be2011-04-27 17:40:20 -0700820
Winson Chung273c1022011-07-11 13:40:52 -0700821 preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
Winson Chung1ed747a2011-05-03 16:18:34 -0700822 renderDrawableToBitmap(mDefaultWidgetBackground, preview, 0, 0, expectedWidth,
Winson Chung70fc4382011-08-08 15:31:33 -0700823 expectedHeight, 1f, 1f);
Winson Chung4b576be2011-04-27 17:40:20 -0700824
825 // Draw the icon in the top left corner
826 try {
827 Drawable icon = null;
828 if (info.icon > 0) icon = mPackageManager.getDrawable(packageName, info.icon, null);
829 if (icon == null) icon = resources.getDrawable(R.drawable.ic_launcher_application);
830
Winson Chungd2945262011-06-24 15:22:14 -0700831 int offset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage);
832 renderDrawableToBitmap(icon, preview, offset, offset,
833 mAppIconSize, mAppIconSize, 1f, 1f);
Winson Chung4b576be2011-04-27 17:40:20 -0700834 } catch (Resources.NotFoundException e) {}
Winson Chung4b576be2011-04-27 17:40:20 -0700835 }
Winson Chungb44b5242011-06-13 11:32:14 -0700836 return preview;
Winson Chung785d2eb2011-04-14 16:08:02 -0700837 }
838 public void syncWidgetPages() {
839 // Ensure that we have the right number of pages
840 Context context = getContext();
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700841 int numPages = (int) Math.ceil(mWidgets.size() /
842 (float) (mWidgetCountX * mWidgetCountY));
843 for (int j = 0; j < numPages; ++j) {
844 PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX,
845 mWidgetCountY);
846 setupPage(layout);
847 addView(layout);
Winson Chung785d2eb2011-04-14 16:08:02 -0700848 }
849 }
Winson Chungf314b0e2011-08-16 11:54:27 -0700850 public void syncWidgetPageItems(int page, boolean immediate) {
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700851 int numItemsPerPage = mWidgetCountX * mWidgetCountY;
Winson Chungd2945262011-06-24 15:22:14 -0700852 int contentWidth = mWidgetSpacingLayout.getContentWidth();
853 int contentHeight = mWidgetSpacingLayout.getContentHeight();
Winson Chungb44b5242011-06-13 11:32:14 -0700854
Winson Chungd2945262011-06-24 15:22:14 -0700855 // Calculate the dimensions of each cell we are giving to each widget
Winson Chungd2945262011-06-24 15:22:14 -0700856 ArrayList<Object> items = new ArrayList<Object>();
857 int cellWidth = ((contentWidth - mPageLayoutPaddingLeft - mPageLayoutPaddingRight
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700858 - ((mWidgetCountX - 1) * mWidgetWidthGap)) / mWidgetCountX);
Winson Chungd2945262011-06-24 15:22:14 -0700859 int cellHeight = ((contentHeight - mPageLayoutPaddingTop - mPageLayoutPaddingBottom
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700860 - ((mWidgetCountY - 1) * mWidgetHeightGap)) / mWidgetCountY);
Winson Chungd2945262011-06-24 15:22:14 -0700861
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700862 int offset = page * numItemsPerPage;
863 for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) {
864 items.add(mWidgets.get(i));
Winson Chungb44b5242011-06-13 11:32:14 -0700865 }
866
Winson Chungf314b0e2011-08-16 11:54:27 -0700867 if (immediate) {
868 AsyncTaskPageData data = new AsyncTaskPageData(page, items, cellWidth, cellHeight,
869 mWidgetCountX, null, null);
870 loadWidgetPreviewsInBackground(null, data);
871 onSyncWidgetPageItems(data);
872 } else {
873 prepareLoadWidgetPreviewsTask(page, items, cellWidth, cellHeight, mWidgetCountX);
874 }
875 }
876 private void loadWidgetPreviewsInBackground(AppsCustomizeAsyncTask task,
877 AsyncTaskPageData data) {
878 if (task != null) {
879 // Ensure that this task starts running at the correct priority
880 task.syncThreadPriority();
881 }
882
883 // Load each of the widget/shortcut previews
884 ArrayList<Object> items = data.items;
885 ArrayList<Bitmap> images = data.generatedImages;
886 int count = items.size();
887 int cellWidth = data.cellWidth;
888 int cellHeight = data.cellHeight;
889 for (int i = 0; i < count; ++i) {
890 if (task != null) {
891 // Ensure we haven't been cancelled yet
892 if (task.isCancelled()) break;
893 // Before work on each item, ensure that this task is running at the correct
894 // priority
895 task.syncThreadPriority();
896 }
897
898 Object rawInfo = items.get(i);
899 if (rawInfo instanceof AppWidgetProviderInfo) {
900 AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
901 int[] cellSpans = CellLayout.rectToCell(getResources(),
902 info.minWidth, info.minHeight, null);
903 images.add(getWidgetPreview(info, cellSpans[0],cellSpans[1],
904 cellWidth, cellHeight));
905 } else if (rawInfo instanceof ResolveInfo) {
906 // Fill in the shortcuts information
907 ResolveInfo info = (ResolveInfo) rawInfo;
908 images.add(getShortcutPreview(info, cellWidth, cellHeight));
909 }
910 }
Winson Chungb44b5242011-06-13 11:32:14 -0700911 }
912 private void onSyncWidgetPageItems(AsyncTaskPageData data) {
913 int page = data.page;
Winson Chung4e6a9762011-05-09 11:56:34 -0700914 PagedViewGridLayout layout = (PagedViewGridLayout) getChildAt(page);
Winson Chungd52f3d82011-07-12 14:29:11 -0700915 // Only set the column count once we have items
916 layout.setColumnCount(layout.getCellCountX());
Winson Chung785d2eb2011-04-14 16:08:02 -0700917
Winson Chungb44b5242011-06-13 11:32:14 -0700918 ArrayList<Object> items = data.items;
919 int count = items.size();
920 int cellWidth = data.cellWidth;
921 int cellHeight = data.cellHeight;
Winson Chungd2945262011-06-24 15:22:14 -0700922 int cellCountX = data.cellCountX;
Winson Chungb44b5242011-06-13 11:32:14 -0700923 for (int i = 0; i < count; ++i) {
924 Object rawInfo = items.get(i);
Winson Chung1ed747a2011-05-03 16:18:34 -0700925 PendingAddItemInfo createItemInfo = null;
Winson Chung4b576be2011-04-27 17:40:20 -0700926 PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate(
927 R.layout.apps_customize_widget, layout, false);
Winson Chung1ed747a2011-05-03 16:18:34 -0700928 if (rawInfo instanceof AppWidgetProviderInfo) {
929 // Fill in the widget information
930 AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
931 createItemInfo = new PendingAddWidgetInfo(info, null, null);
Winson Chungb44b5242011-06-13 11:32:14 -0700932 int[] cellSpans = CellLayout.rectToCell(getResources(),
933 info.minWidth, info.minHeight, null);
Winson Chung4e076542011-06-23 13:04:10 -0700934 FastBitmapDrawable preview = new FastBitmapDrawable(data.generatedImages.get(i));
Winson Chung9f4e0fd2011-06-02 18:59:36 -0700935 widget.applyFromAppWidgetProviderInfo(info, preview, -1, cellSpans,
Winson Chungb44b5242011-06-13 11:32:14 -0700936 mHolographicOutlineHelper);
Winson Chung1ed747a2011-05-03 16:18:34 -0700937 widget.setTag(createItemInfo);
938 } else if (rawInfo instanceof ResolveInfo) {
939 // Fill in the shortcuts information
940 ResolveInfo info = (ResolveInfo) rawInfo;
941 createItemInfo = new PendingAddItemInfo();
942 createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
943 createItemInfo.componentName = new ComponentName(info.activityInfo.packageName,
944 info.activityInfo.name);
Winson Chung4e076542011-06-23 13:04:10 -0700945 FastBitmapDrawable preview = new FastBitmapDrawable(data.generatedImages.get(i));
Winson Chungb44b5242011-06-13 11:32:14 -0700946 widget.applyFromResolveInfo(mPackageManager, info, preview,
947 mHolographicOutlineHelper);
Winson Chung1ed747a2011-05-03 16:18:34 -0700948 widget.setTag(createItemInfo);
949 }
Winson Chung4b576be2011-04-27 17:40:20 -0700950 widget.setOnClickListener(this);
951 widget.setOnLongClickListener(this);
952 widget.setOnTouchListener(this);
953
954 // Layout each widget
Winson Chungd2945262011-06-24 15:22:14 -0700955 int ix = i % cellCountX;
956 int iy = i / cellCountX;
Winson Chungfd3385f2011-06-15 19:51:24 -0700957 GridLayout.LayoutParams lp = new GridLayout.LayoutParams(
Winson Chung72d8b392011-07-29 13:56:44 -0700958 GridLayout.spec(iy, GridLayout.LEFT),
959 GridLayout.spec(ix, GridLayout.TOP));
Winson Chungfd3385f2011-06-15 19:51:24 -0700960 lp.width = cellWidth;
961 lp.height = cellHeight;
Winson Chung72d8b392011-07-29 13:56:44 -0700962 lp.setGravity(Gravity.TOP | Gravity.LEFT);
Winson Chungfd3385f2011-06-15 19:51:24 -0700963 if (ix > 0) lp.leftMargin = mWidgetWidthGap;
964 if (iy > 0) lp.topMargin = mWidgetHeightGap;
Winson Chung4e6a9762011-05-09 11:56:34 -0700965 layout.addView(widget, lp);
Winson Chung785d2eb2011-04-14 16:08:02 -0700966 }
Winson Chungb44b5242011-06-13 11:32:14 -0700967
968 invalidate();
969 forceUpdateAdjacentPagesAlpha();
Winson Chung54c725c2011-08-03 12:03:40 -0700970
971 if (mFadeInAdjacentScreens) {
972 prepareGenerateHoloOutlinesTask(data.page, data.items, data.generatedImages);
973 }
Winson Chungb44b5242011-06-13 11:32:14 -0700974 }
975 private void onHolographicPageItemsLoaded(AsyncTaskPageData data) {
976 // Invalidate early to short-circuit children invalidates
977 invalidate();
978
979 int page = data.page;
980 ViewGroup layout = (ViewGroup) getChildAt(page);
981 if (layout instanceof PagedViewCellLayout) {
982 PagedViewCellLayout cl = (PagedViewCellLayout) layout;
983 int count = cl.getPageChildCount();
Winson Chung875de7e2011-06-28 14:25:17 -0700984 if (count != data.generatedImages.size()) return;
Winson Chungb44b5242011-06-13 11:32:14 -0700985 for (int i = 0; i < count; ++i) {
986 PagedViewIcon icon = (PagedViewIcon) cl.getChildOnPageAt(i);
Winson Chung4e076542011-06-23 13:04:10 -0700987 icon.setHolographicOutline(data.generatedImages.get(i));
Winson Chungb44b5242011-06-13 11:32:14 -0700988 }
989 } else {
990 int count = layout.getChildCount();
Winson Chung875de7e2011-06-28 14:25:17 -0700991 if (count != data.generatedImages.size()) return;
Winson Chungb44b5242011-06-13 11:32:14 -0700992 for (int i = 0; i < count; ++i) {
993 View v = layout.getChildAt(i);
Winson Chung4e076542011-06-23 13:04:10 -0700994 ((PagedViewWidget) v).setHolographicOutline(data.generatedImages.get(i));
Winson Chungb44b5242011-06-13 11:32:14 -0700995 }
996 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700997 }
Winson Chung46af2e82011-05-09 16:00:53 -0700998
Winson Chung785d2eb2011-04-14 16:08:02 -0700999 @Override
1000 public void syncPages() {
1001 removeAllViews();
Winson Chung875de7e2011-06-28 14:25:17 -07001002
1003 // Remove all background asyc tasks if we are loading content anew
1004 Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
1005 while (iter.hasNext()) {
1006 AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
1007 task.cancel(false);
1008 iter.remove();
1009 }
1010
Winson Chung785d2eb2011-04-14 16:08:02 -07001011 switch (mContentType) {
1012 case Applications:
1013 syncAppsPages();
1014 break;
1015 case Widgets:
1016 syncWidgetPages();
1017 break;
1018 }
1019 }
1020 @Override
Winson Chungf314b0e2011-08-16 11:54:27 -07001021 public void syncPageItems(int page, boolean immediate) {
Winson Chung785d2eb2011-04-14 16:08:02 -07001022 switch (mContentType) {
1023 case Applications:
Winson Chungf314b0e2011-08-16 11:54:27 -07001024 syncAppsPageItems(page, immediate);
Winson Chung785d2eb2011-04-14 16:08:02 -07001025 break;
1026 case Widgets:
Winson Chungf314b0e2011-08-16 11:54:27 -07001027 syncWidgetPageItems(page, immediate);
Winson Chung785d2eb2011-04-14 16:08:02 -07001028 break;
1029 }
1030 }
1031
1032 /**
1033 * Used by the parent to get the content width to set the tab bar to
1034 * @return
1035 */
1036 public int getPageContentWidth() {
1037 return mContentWidth;
1038 }
1039
Winson Chungb26f3d62011-06-02 10:49:29 -07001040 @Override
1041 protected void onPageBeginMoving() {
1042 /* TO BE ENABLED LATER
1043 setChildrenDrawnWithCacheEnabled(true);
1044 for (int i = 0; i < getChildCount(); ++i) {
1045 View v = getChildAt(i);
1046 if (v instanceof PagedViewCellLayout) {
1047 ((PagedViewCellLayout) v).setChildrenDrawingCacheEnabled(true);
1048 }
1049 }
1050 */
1051 super.onPageBeginMoving();
1052 }
1053
1054 @Override
1055 protected void onPageEndMoving() {
1056 /* TO BE ENABLED LATER
1057 for (int i = 0; i < getChildCount(); ++i) {
1058 View v = getChildAt(i);
1059 if (v instanceof PagedViewCellLayout) {
1060 ((PagedViewCellLayout) v).setChildrenDrawingCacheEnabled(false);
1061 }
1062 }
1063 setChildrenDrawnWithCacheEnabled(false);
1064 */
1065 super.onPageEndMoving();
1066 }
1067
Winson Chung785d2eb2011-04-14 16:08:02 -07001068 /*
1069 * AllAppsView implementation
1070 */
1071 @Override
1072 public void setup(Launcher launcher, DragController dragController) {
1073 mLauncher = launcher;
1074 mDragController = dragController;
1075 }
1076 @Override
1077 public void zoom(float zoom, boolean animate) {
1078 // TODO-APPS_CUSTOMIZE: Call back to mLauncher.zoomed()
1079 }
1080 @Override
1081 public boolean isVisible() {
1082 return (getVisibility() == VISIBLE);
1083 }
1084 @Override
1085 public boolean isAnimating() {
1086 return false;
1087 }
1088 @Override
1089 public void setApps(ArrayList<ApplicationInfo> list) {
1090 mApps = list;
1091 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001092
Winson Chung875de7e2011-06-28 14:25:17 -07001093 // The next layout pass will trigger data-ready if both widgets and apps are set, so
1094 // request a layout to do this test and invalidate the page data when ready.
Winson Chungf0ea4d32011-06-06 14:27:16 -07001095 if (testDataReady()) requestLayout();
Winson Chung785d2eb2011-04-14 16:08:02 -07001096 }
1097 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
1098 // We add it in place, in alphabetical order
1099 int count = list.size();
1100 for (int i = 0; i < count; ++i) {
1101 ApplicationInfo info = list.get(i);
1102 int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
1103 if (index < 0) {
1104 mApps.add(-(index + 1), info);
1105 }
1106 }
1107 }
1108 @Override
1109 public void addApps(ArrayList<ApplicationInfo> list) {
1110 addAppsWithoutInvalidate(list);
1111 invalidatePageData();
1112 }
1113 private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) {
1114 ComponentName removeComponent = item.intent.getComponent();
1115 int length = list.size();
1116 for (int i = 0; i < length; ++i) {
1117 ApplicationInfo info = list.get(i);
1118 if (info.intent.getComponent().equals(removeComponent)) {
1119 return i;
1120 }
1121 }
1122 return -1;
1123 }
1124 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
1125 // loop through all the apps and remove apps that have the same component
1126 int length = list.size();
1127 for (int i = 0; i < length; ++i) {
1128 ApplicationInfo info = list.get(i);
1129 int removeIndex = findAppByComponent(mApps, info);
1130 if (removeIndex > -1) {
1131 mApps.remove(removeIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001132 }
1133 }
1134 }
1135 @Override
1136 public void removeApps(ArrayList<ApplicationInfo> list) {
1137 removeAppsWithoutInvalidate(list);
1138 invalidatePageData();
1139 }
1140 @Override
1141 public void updateApps(ArrayList<ApplicationInfo> list) {
1142 // We remove and re-add the updated applications list because it's properties may have
1143 // changed (ie. the title), and this will ensure that the items will be in their proper
1144 // place in the list.
1145 removeAppsWithoutInvalidate(list);
1146 addAppsWithoutInvalidate(list);
1147 invalidatePageData();
1148 }
Michael Jurka35aa14d2011-07-07 17:01:08 -07001149
Winson Chung785d2eb2011-04-14 16:08:02 -07001150 @Override
1151 public void reset() {
Winson Chungfc79c802011-05-02 13:35:34 -07001152 if (mContentType != ContentType.Applications) {
1153 // Reset to the first page of the Apps pane
1154 AppsCustomizeTabHost tabs = (AppsCustomizeTabHost)
1155 mLauncher.findViewById(R.id.apps_customize_pane);
Winson Chung5a808352011-06-27 19:08:49 -07001156 tabs.selectAppsTab();
Michael Jurka35aa14d2011-07-07 17:01:08 -07001157 } else if (getCurrentPage() != 0) {
Winson Chung5a808352011-06-27 19:08:49 -07001158 invalidatePageData(0);
Winson Chungfc79c802011-05-02 13:35:34 -07001159 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001160 }
1161 @Override
1162 public void dumpState() {
1163 // TODO: Dump information related to current list of Applications, Widgets, etc.
1164 ApplicationInfo.dumpApplicationInfoList(LOG_TAG, "mApps", mApps);
1165 dumpAppWidgetProviderInfoList(LOG_TAG, "mWidgets", mWidgets);
1166 }
1167 private void dumpAppWidgetProviderInfoList(String tag, String label,
Winson Chungd2945262011-06-24 15:22:14 -07001168 ArrayList<Object> list) {
Winson Chung785d2eb2011-04-14 16:08:02 -07001169 Log.d(tag, label + " size=" + list.size());
Winson Chung1ed747a2011-05-03 16:18:34 -07001170 for (Object i: list) {
1171 if (i instanceof AppWidgetProviderInfo) {
1172 AppWidgetProviderInfo info = (AppWidgetProviderInfo) i;
1173 Log.d(tag, " label=\"" + info.label + "\" previewImage=" + info.previewImage
1174 + " resizeMode=" + info.resizeMode + " configure=" + info.configure
1175 + " initialLayout=" + info.initialLayout
1176 + " minWidth=" + info.minWidth + " minHeight=" + info.minHeight);
1177 } else if (i instanceof ResolveInfo) {
1178 ResolveInfo info = (ResolveInfo) i;
1179 Log.d(tag, " label=\"" + info.loadLabel(mPackageManager) + "\" icon="
1180 + info.icon);
1181 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001182 }
1183 }
1184 @Override
1185 public void surrender() {
1186 // TODO: If we are in the middle of any process (ie. for holographic outlines, etc) we
1187 // should stop this now.
1188 }
Winson Chung007c6982011-06-14 13:27:53 -07001189
Winson Chungb44b5242011-06-13 11:32:14 -07001190 /*
1191 * We load an extra page on each side to prevent flashes from scrolling and loading of the
1192 * widget previews in the background with the AsyncTasks.
1193 */
1194 protected int getAssociatedLowerPageBound(int page) {
1195 return Math.max(0, page - 2);
1196 }
1197 protected int getAssociatedUpperPageBound(int page) {
1198 final int count = getChildCount();
1199 return Math.min(page + 2, count - 1);
1200 }
Winson Chung6a0f57d2011-06-29 20:10:49 -07001201
1202 @Override
1203 protected String getCurrentPageDescription() {
1204 int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
1205 int stringId = R.string.default_scroll_format;
1206 switch (mContentType) {
1207 case Applications:
1208 stringId = R.string.apps_customize_apps_scroll_format;
1209 break;
1210 case Widgets:
1211 stringId = R.string.apps_customize_widgets_scroll_format;
1212 break;
1213 }
1214 return String.format(mContext.getString(stringId), page + 1, getChildCount());
1215 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001216}