blob: c9a31193069502767f337fe41fa089a32e3f7c1f [file] [log] [blame]
Winson Chung321e9ee2010-08-09 13:37:56 -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 Jurkaaf91de02010-11-23 16:23:58 -080019import com.android.launcher.R;
Winson Chung321e9ee2010-08-09 13:37:56 -070020
21import android.content.ComponentName;
22import android.content.Context;
Michael Jurka72b079e2010-12-10 01:03:53 -080023import android.content.res.Resources;
Winson Chung321e9ee2010-08-09 13:37:56 -070024import android.content.res.TypedArray;
Michael Jurkad3ef3062010-11-23 16:23:58 -080025import android.graphics.Bitmap;
26import android.graphics.Canvas;
Winson Chungcd4bc492010-12-09 18:52:32 -080027import android.graphics.Color;
Michael Jurkad3ef3062010-11-23 16:23:58 -080028import android.graphics.drawable.Drawable;
Winson Chung321e9ee2010-08-09 13:37:56 -070029import android.util.AttributeSet;
30import android.view.LayoutInflater;
31import android.view.View;
Winson Chung321e9ee2010-08-09 13:37:56 -070032import android.view.animation.AnimationUtils;
Winson Chung5f2aa4e2010-08-20 14:49:25 -070033import android.widget.Checkable;
Winson Chung321e9ee2010-08-09 13:37:56 -070034import android.widget.TextView;
35
Michael Jurkaaf91de02010-11-23 16:23:58 -080036import java.util.ArrayList;
37import java.util.Collections;
38import java.util.HashSet;
Winson Chung321e9ee2010-08-09 13:37:56 -070039
40/**
41 * An implementation of PagedView that populates the pages of the workspace
42 * with all of the user's applications.
43 */
Michael Jurka72b079e2010-12-10 01:03:53 -080044public class AllAppsPagedView extends PagedViewWithDraggableItems implements AllAppsView,
45 View.OnClickListener, DragSource, DropTarget {
Winson Chung321e9ee2010-08-09 13:37:56 -070046
47 private static final String TAG = "AllAppsPagedView";
48 private static final boolean DEBUG = false;
49
50 private Launcher mLauncher;
51 private DragController mDragController;
52
53 // preserve compatibility with 3D all apps:
54 // 0.0 -> hidden
55 // 1.0 -> shown and opaque
56 // intermediate values -> partially shown & partially opaque
57 private float mZoom;
58
59 // set of all applications
60 private ArrayList<ApplicationInfo> mApps;
61 private ArrayList<ApplicationInfo> mFilteredApps;
62
63 // the types of applications to filter
64 static final int ALL_APPS_FLAG = -1;
65 private int mAppFilter = ALL_APPS_FLAG;
66
Winson Chung321e9ee2010-08-09 13:37:56 -070067 private final LayoutInflater mInflater;
68
Patrick Dubroydea9e932010-09-22 15:04:29 -070069
Winson Chung321e9ee2010-08-09 13:37:56 -070070 public AllAppsPagedView(Context context) {
71 this(context, null);
72 }
73
74 public AllAppsPagedView(Context context, AttributeSet attrs) {
75 this(context, attrs, 0);
76 }
77
78 public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
79 super(context, attrs, defStyle);
80 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
81 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
82 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
83 mInflater = LayoutInflater.from(context);
84 a.recycle();
85 setSoundEffectsEnabled(false);
Michael Jurka72b079e2010-12-10 01:03:53 -080086
87 Resources r = context.getResources();
88 setDragSlopeThreshold(
89 r.getInteger(R.integer.config_allAppsDrawerDragSlopeThreshold) / 100.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -070090 }
91
92 @Override
Winson Chung7da10252010-10-28 16:07:04 -070093 protected void init() {
94 super.init();
95 mCenterPagesVertically = false;
96 }
97
98 @Override
Winson Chung321e9ee2010-08-09 13:37:56 -070099 public void setLauncher(Launcher launcher) {
100 mLauncher = launcher;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700101 mLauncher.setAllAppsPagedView(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700102 }
103
104 @Override
105 public void setDragController(DragController dragger) {
106 mDragController = dragger;
107 }
108
109 public void setAppFilter(int filterType) {
110 mAppFilter = filterType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700111 if (mApps != null) {
112 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung86f77532010-08-24 11:08:22 -0700113 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700114 invalidatePageData();
115 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700116 }
117
118 @Override
119 public void zoom(float zoom, boolean animate) {
120 mZoom = zoom;
121 cancelLongPress();
122
123 if (isVisible()) {
124 getParent().bringChildToFront(this);
125 setVisibility(View.VISIBLE);
126 if (animate) {
127 startAnimation(AnimationUtils.loadAnimation(getContext(),
128 R.anim.all_apps_2d_fade_in));
129 } else {
130 onAnimationEnd();
131 }
132 } else {
133 if (animate) {
134 startAnimation(AnimationUtils.loadAnimation(getContext(),
135 R.anim.all_apps_2d_fade_out));
136 } else {
137 onAnimationEnd();
138 }
139 }
140 }
141
142 protected void onAnimationEnd() {
143 if (!isVisible()) {
144 setVisibility(View.GONE);
145 mZoom = 0.0f;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700146
147 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700148 } else {
149 mZoom = 1.0f;
150 }
151
152 if (mLauncher != null)
153 mLauncher.zoomed(mZoom);
154 }
155
156 private int getChildIndexForGrandChild(View v) {
157 final int childCount = getChildCount();
158 for (int i = 0; i < childCount; ++i) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700159 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
Winson Chung321e9ee2010-08-09 13:37:56 -0700160 if (layout.indexOfChild(v) > -1) {
161 return i;
162 }
163 }
164 return -1;
165 }
166
167 @Override
168 public void onClick(View v) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700169 // if we are already in a choice mode, then just change the selection
170 if (v instanceof Checkable) {
171 if (!isChoiceMode(CHOICE_MODE_NONE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700172 Checkable c = (Checkable) v;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700173 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700174 // Uncheck all the other grandchildren, and toggle the clicked one
175 boolean wasChecked = c.isChecked();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700176 resetCheckedGrandchildren();
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700177 c.setChecked(!wasChecked);
178 } else {
179 c.toggle();
180 }
181 if (getCheckedGrandchildren().size() == 0) {
182 endChoiceMode();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700183 }
184
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700185 return;
186 }
187 }
188
189 // otherwise continue and launch the application
Winson Chung321e9ee2010-08-09 13:37:56 -0700190 int childIndex = getChildIndexForGrandChild(v);
Winson Chung86f77532010-08-24 11:08:22 -0700191 if (childIndex == getCurrentPage()) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700192 final ApplicationInfo app = (ApplicationInfo) v.getTag();
193
Winson Chung80baf5a2010-08-09 16:03:15 -0700194 // animate some feedback to the click
195 animateClickFeedback(v, new Runnable() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700196 @Override
Winson Chung80baf5a2010-08-09 16:03:15 -0700197 public void run() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700198 mLauncher.startActivitySafely(app.intent, app);
199 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700200 });
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700201
202 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700203 }
204 }
205
Adam Cohencdc30d52010-12-01 15:09:47 -0800206 private void setupDragMode() {
Michael Jurkaaf91de02010-11-23 16:23:58 -0800207 mLauncher.getWorkspace().shrink(Workspace.ShrinkState.BOTTOM_VISIBLE);
Adam Cohencdc30d52010-12-01 15:09:47 -0800208
209 ApplicationInfoDropTarget infoButton =
210 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
211 infoButton.setDragAndDropEnabled(false);
212 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
213 deleteZone.setDragAndDropEnabled(false);
214
215 ApplicationInfoDropTarget allAppsInfoButton =
216 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
217 allAppsInfoButton.setDragAndDropEnabled(true);
218 DeleteZone allAppsDeleteZone = (DeleteZone)
219 mLauncher.findViewById(R.id.all_apps_delete_zone);
220 allAppsDeleteZone.setDragAndDropEnabled(true);
221 }
222
223 private void tearDownDragMode() {
224 post(new Runnable() {
225 // Once the drag operation has fully completed, hence the post, we want to disable the
226 // deleteZone and the appInfoButton in all apps, and re-enable the instance which
227 // live in the workspace
228 public void run() {
229 ApplicationInfoDropTarget infoButton =
230 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
231 infoButton.setDragAndDropEnabled(true);
232 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
233 deleteZone.setDragAndDropEnabled(true);
234
235 ApplicationInfoDropTarget allAppsInfoButton =
236 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
237 allAppsInfoButton.setDragAndDropEnabled(false);
238 DeleteZone allAppsDeleteZone =
239 (DeleteZone) mLauncher.findViewById(R.id.all_apps_delete_zone);
240 allAppsDeleteZone.setDragAndDropEnabled(false);
241 }
242 });
243 resetCheckedGrandchildren();
244 mDragController.removeDropTarget(this);
245 }
246
Winson Chung321e9ee2010-08-09 13:37:56 -0700247 @Override
Michael Jurka72b079e2010-12-10 01:03:53 -0800248 protected boolean beginDragging(View v) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700249 if (!v.isInTouchMode()) {
250 return false;
251 }
Michael Jurka72b079e2010-12-10 01:03:53 -0800252 super.beginDragging(v);
Winson Chung321e9ee2010-08-09 13:37:56 -0700253
Adam Cohencdc30d52010-12-01 15:09:47 -0800254 // Start drag mode after the item is selected
255 setupDragMode();
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700256
Winson Chung321e9ee2010-08-09 13:37:56 -0700257 ApplicationInfo app = (ApplicationInfo) v.getTag();
258 app = new ApplicationInfo(app);
259
Michael Jurkad3ef3062010-11-23 16:23:58 -0800260 // get icon (top compound drawable, index is 1)
Winson Chungcd4bc492010-12-09 18:52:32 -0800261 final TextView tv = (TextView) v;
262 final Drawable icon = tv.getCompoundDrawables()[1];
263 Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Michael Jurkad3ef3062010-11-23 16:23:58 -0800264 Bitmap.Config.ARGB_8888);
265 Canvas c = new Canvas(b);
Winson Chungcd4bc492010-12-09 18:52:32 -0800266 c.translate((v.getWidth() - icon.getIntrinsicWidth()) / 2, v.getPaddingTop());
Michael Jurkad3ef3062010-11-23 16:23:58 -0800267 icon.draw(c);
Winson Chungcd4bc492010-12-09 18:52:32 -0800268
269 // We toggle the checked state _after_ we create the view for the drag in case toggling the
270 // checked state changes the view's look
271 if (v instanceof Checkable) {
272 // In preparation for drag, we always reset the checked grand children regardless of
273 // what choice mode we are in
274 resetCheckedGrandchildren();
275
276 // Toggle the selection on the dragged app
277 Checkable checkable = (Checkable) v;
278 checkable.toggle();
279 }
280
281 // Start the drag
Michael Jurkad3ef3062010-11-23 16:23:58 -0800282 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
283 mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
Winson Chungcd4bc492010-12-09 18:52:32 -0800284 b.recycle();
Winson Chung321e9ee2010-08-09 13:37:56 -0700285 return true;
286 }
287
288 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800289 public void onDragViewVisible() {
290 }
291
292 @Override
Winson Chung321e9ee2010-08-09 13:37:56 -0700293 public void onDropCompleted(View target, boolean success) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700294 // close the choice action mode if we have a proper drop
295 if (target != this) {
296 endChoiceMode();
297 }
Adam Cohencdc30d52010-12-01 15:09:47 -0800298 tearDownDragMode();
Michael Jurka3e7c7632010-10-02 16:01:03 -0700299 mLauncher.getWorkspace().onDragStopped();
Winson Chung321e9ee2010-08-09 13:37:56 -0700300 }
301
302 @Override
303 public boolean isVisible() {
304 return mZoom > 0.001f;
305 }
306
307 @Override
308 public boolean isAnimating() {
309 return (getAnimation() != null);
310 }
311
312 private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
313 ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
314 if (mAppFilter == ALL_APPS_FLAG) {
315 return apps;
316 } else {
317 final int length = apps.size();
318 for (int i = 0; i < length; ++i) {
319 ApplicationInfo info = apps.get(i);
320 if ((info.flags & mAppFilter) > 0) {
321 filteredApps.add(info);
322 }
323 }
324 }
325 return filteredApps;
326 }
327
328 @Override
329 public void setApps(ArrayList<ApplicationInfo> list) {
330 mApps = list;
Winson Chung80baf5a2010-08-09 16:03:15 -0700331 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung321e9ee2010-08-09 13:37:56 -0700332 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung241c3b42010-08-25 16:53:03 -0700333 mPageViewIconCache.clear();
Winson Chung321e9ee2010-08-09 13:37:56 -0700334 invalidatePageData();
335 }
336
Winson Chung80baf5a2010-08-09 16:03:15 -0700337 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
338 // we add it in place, in alphabetical order
339 final int count = list.size();
340 for (int i = 0; i < count; ++i) {
341 final ApplicationInfo info = list.get(i);
342 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
343 if (index < 0) {
344 mApps.add(-(index + 1), info);
345 }
346 }
347 mFilteredApps = rebuildFilteredApps(mApps);
348 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700349 @Override
350 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700351 addAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700352 invalidatePageData();
353 }
354
Winson Chung80baf5a2010-08-09 16:03:15 -0700355 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
Winson Chung10fefb12010-11-01 11:57:06 -0700356 // End the choice mode if any of the items in the list that are being removed are
357 // currently selected
358 ArrayList<Checkable> checkedList = getCheckedGrandchildren();
359 HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>();
360 for (Checkable checked : checkedList) {
361 PagedViewIcon icon = (PagedViewIcon) checked;
362 checkedAppInfos.add((ApplicationInfo) icon.getTag());
363 }
364 for (ApplicationInfo info : list) {
365 if (checkedAppInfos.contains(info)) {
366 endChoiceMode();
367 break;
368 }
369 }
370
371 // Loop through all the apps and remove apps that have the same component
Winson Chung321e9ee2010-08-09 13:37:56 -0700372 final int length = list.size();
373 for (int i = 0; i < length; ++i) {
Winson Chung241c3b42010-08-25 16:53:03 -0700374 final ApplicationInfo info = list.get(i);
375 int removeIndex = findAppByComponent(mApps, info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700376 if (removeIndex > -1) {
377 mApps.remove(removeIndex);
Winson Chung241c3b42010-08-25 16:53:03 -0700378 mPageViewIconCache.removeOutline(info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700379 }
380 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700381 mFilteredApps = rebuildFilteredApps(mApps);
382 }
383 @Override
384 public void removeApps(ArrayList<ApplicationInfo> list) {
385 removeAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700386 invalidatePageData();
387 }
388
389 @Override
390 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700391 removeAppsWithoutInvalidate(list);
392 addAppsWithoutInvalidate(list);
393 invalidatePageData();
Winson Chung321e9ee2010-08-09 13:37:56 -0700394 }
395
396 private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
397 ComponentName removeComponent = item.intent.getComponent();
398 final int length = list.size();
399 for (int i = 0; i < length; ++i) {
400 ApplicationInfo info = list.get(i);
401 if (info.intent.getComponent().equals(removeComponent)) {
402 return i;
403 }
404 }
405 return -1;
406 }
407
408 @Override
409 public void dumpState() {
410 ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
411 }
412
413 @Override
414 public void surrender() {
415 // do nothing?
416 }
417
418 @Override
419 public void syncPages() {
Winson Chung96785572010-10-14 13:37:13 -0700420 // ensure that we have the right number of pages (min of 1, since we have placeholders)
421 int numPages = Math.max(1,
422 (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));
Winson Chung321e9ee2010-08-09 13:37:56 -0700423 int curNumPages = getChildCount();
424 // remove any extra pages after the "last" page
425 int extraPageDiff = curNumPages - numPages;
426 for (int i = 0; i < extraPageDiff; ++i) {
427 removeViewAt(numPages);
428 }
429 // add any necessary pages
430 for (int i = curNumPages; i < numPages; ++i) {
431 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
432 layout.setCellCount(mCellCountX, mCellCountY);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700433 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
434 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700435 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung321e9ee2010-08-09 13:37:56 -0700436 addView(layout);
437 }
438
439 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700440 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700441 }
442
443 @Override
444 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700445 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700446 final int cellsPerPage = mCellCountX * mCellCountY;
447 final int startIndex = page * cellsPerPage;
448 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700449 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700450
Winson Chung96785572010-10-14 13:37:13 -0700451 if (!mFilteredApps.isEmpty()) {
452 int curNumPageItems = layout.getChildCount();
453 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700454
Winson Chung96785572010-10-14 13:37:13 -0700455 // If we were previously an empty page, then restart anew
456 boolean wasEmptyPage = false;
457 if (curNumPageItems == 1) {
458 View icon = layout.getChildAt(0);
459 if (icon.getTag() == null) {
460 wasEmptyPage = true;
461 }
462 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700463
Winson Chung96785572010-10-14 13:37:13 -0700464 if (wasEmptyPage) {
465 // Remove all the previous items
466 curNumPageItems = 0;
467 layout.removeAllViews();
468 } else {
469 // Remove any extra items
470 int extraPageItemsDiff = curNumPageItems - numPageItems;
471 for (int i = 0; i < extraPageItemsDiff; ++i) {
472 layout.removeViewAt(numPageItems);
473 }
474 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700475
Winson Chung96785572010-10-14 13:37:13 -0700476 // Add any necessary items
477 for (int i = curNumPageItems; i < numPageItems; ++i) {
478 TextView text = (TextView) mInflater.inflate(
479 R.layout.all_apps_paged_view_application, layout, false);
480 text.setOnClickListener(this);
481 text.setOnLongClickListener(this);
Michael Jurka72b079e2010-12-10 01:03:53 -0800482 text.setOnTouchListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700483
Winson Chung96785572010-10-14 13:37:13 -0700484 layout.addViewToCellLayout(text, -1, i,
485 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
486 }
487
488 // Actually reapply to the existing text views
489 for (int i = startIndex; i < endIndex; ++i) {
490 final int index = i - startIndex;
491 final ApplicationInfo info = mFilteredApps.get(i);
492 PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700493 icon.applyFromApplicationInfo(info, mPageViewIconCache, true);
Winson Chung96785572010-10-14 13:37:13 -0700494
495 PagedViewCellLayout.LayoutParams params =
496 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
497 params.cellX = index % mCellCountX;
498 params.cellY = index / mCellCountX;
499 }
500
501 // Default to left-aligned icons
502 layout.enableCenteredContent(false);
503 } else {
504 // There are no items, so show the user a small message
505 TextView icon = (TextView) mInflater.inflate(
506 R.layout.all_apps_no_items_placeholder, layout, false);
507 switch (mAppFilter) {
Winson Chung96785572010-10-14 13:37:13 -0700508 case ApplicationInfo.DOWNLOADED_FLAG:
509 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
510 break;
511 default: break;
512 }
513
514 // Center-align the message
515 layout.enableCenteredContent(true);
516 layout.removeAllViews();
517 layout.addViewToCellLayout(icon, -1, 0,
518 new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700519 }
520 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700521
522 /*
523 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
524 * to the workspace.
525 */
526 @Override
527 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
528 DragView dragView, Object dragInfo) {
529 return false;
530 }
531 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700532 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
533 int yOffset, DragView dragView, Object dragInfo) {
534 return null;
535 }
536 @Override
537 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
538 DragView dragView, Object dragInfo) {}
539 @Override
540 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
541 DragView dragView, Object dragInfo) {}
542 @Override
543 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
544 DragView dragView, Object dragInfo) {}
545 @Override
546 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
547 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700548
549 public boolean isDropEnabled() {
550 return true;
551 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700552}