blob: c9c069f125d2158f3c1fa6db2faf59e88c728145 [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";
Winson Chung321e9ee2010-08-09 13:37:56 -070048
49 private Launcher mLauncher;
50 private DragController mDragController;
51
52 // preserve compatibility with 3D all apps:
53 // 0.0 -> hidden
54 // 1.0 -> shown and opaque
55 // intermediate values -> partially shown & partially opaque
56 private float mZoom;
57
58 // set of all applications
59 private ArrayList<ApplicationInfo> mApps;
60 private ArrayList<ApplicationInfo> mFilteredApps;
61
62 // the types of applications to filter
63 static final int ALL_APPS_FLAG = -1;
64 private int mAppFilter = ALL_APPS_FLAG;
65
Winson Chung321e9ee2010-08-09 13:37:56 -070066 private final LayoutInflater mInflater;
67
Patrick Dubroydea9e932010-09-22 15:04:29 -070068
Winson Chung321e9ee2010-08-09 13:37:56 -070069 public AllAppsPagedView(Context context) {
70 this(context, null);
71 }
72
73 public AllAppsPagedView(Context context, AttributeSet attrs) {
74 this(context, attrs, 0);
75 }
76
77 public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
78 super(context, attrs, defStyle);
79 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
80 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
81 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
82 mInflater = LayoutInflater.from(context);
83 a.recycle();
84 setSoundEffectsEnabled(false);
Michael Jurka72b079e2010-12-10 01:03:53 -080085
86 Resources r = context.getResources();
87 setDragSlopeThreshold(
88 r.getInteger(R.integer.config_allAppsDrawerDragSlopeThreshold) / 100.0f);
Winson Chung321e9ee2010-08-09 13:37:56 -070089 }
90
91 @Override
Winson Chung7da10252010-10-28 16:07:04 -070092 protected void init() {
93 super.init();
94 mCenterPagesVertically = false;
95 }
96
97 @Override
Winson Chung321e9ee2010-08-09 13:37:56 -070098 public void setLauncher(Launcher launcher) {
99 mLauncher = launcher;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700100 mLauncher.setAllAppsPagedView(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700101 }
102
103 @Override
104 public void setDragController(DragController dragger) {
105 mDragController = dragger;
106 }
107
108 public void setAppFilter(int filterType) {
109 mAppFilter = filterType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700110 if (mApps != null) {
111 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung86f77532010-08-24 11:08:22 -0700112 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700113 invalidatePageData();
114 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700115 }
116
117 @Override
118 public void zoom(float zoom, boolean animate) {
119 mZoom = zoom;
120 cancelLongPress();
121
122 if (isVisible()) {
123 getParent().bringChildToFront(this);
124 setVisibility(View.VISIBLE);
125 if (animate) {
126 startAnimation(AnimationUtils.loadAnimation(getContext(),
127 R.anim.all_apps_2d_fade_in));
128 } else {
129 onAnimationEnd();
130 }
131 } else {
132 if (animate) {
133 startAnimation(AnimationUtils.loadAnimation(getContext(),
134 R.anim.all_apps_2d_fade_out));
135 } else {
136 onAnimationEnd();
137 }
138 }
139 }
140
141 protected void onAnimationEnd() {
142 if (!isVisible()) {
143 setVisibility(View.GONE);
144 mZoom = 0.0f;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700145
146 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700147 } else {
148 mZoom = 1.0f;
149 }
150
151 if (mLauncher != null)
152 mLauncher.zoomed(mZoom);
153 }
154
155 private int getChildIndexForGrandChild(View v) {
156 final int childCount = getChildCount();
157 for (int i = 0; i < childCount; ++i) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700158 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
Winson Chung321e9ee2010-08-09 13:37:56 -0700159 if (layout.indexOfChild(v) > -1) {
160 return i;
161 }
162 }
163 return -1;
164 }
165
166 @Override
167 public void onClick(View v) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700168 // if we are already in a choice mode, then just change the selection
169 if (v instanceof Checkable) {
170 if (!isChoiceMode(CHOICE_MODE_NONE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700171 Checkable c = (Checkable) v;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700172 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700173 // Uncheck all the other grandchildren, and toggle the clicked one
174 boolean wasChecked = c.isChecked();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700175 resetCheckedGrandchildren();
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700176 c.setChecked(!wasChecked);
177 } else {
178 c.toggle();
179 }
180 if (getCheckedGrandchildren().size() == 0) {
181 endChoiceMode();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700182 }
183
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700184 return;
185 }
186 }
187
188 // otherwise continue and launch the application
Winson Chung321e9ee2010-08-09 13:37:56 -0700189 int childIndex = getChildIndexForGrandChild(v);
Winson Chung86f77532010-08-24 11:08:22 -0700190 if (childIndex == getCurrentPage()) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700191 final ApplicationInfo app = (ApplicationInfo) v.getTag();
192
Winson Chung80baf5a2010-08-09 16:03:15 -0700193 // animate some feedback to the click
194 animateClickFeedback(v, new Runnable() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700195 @Override
Winson Chung80baf5a2010-08-09 16:03:15 -0700196 public void run() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700197 mLauncher.startActivitySafely(app.intent, app);
198 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700199 });
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700200
201 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700202 }
203 }
204
Adam Cohencdc30d52010-12-01 15:09:47 -0800205 private void setupDragMode() {
Michael Jurkaaf91de02010-11-23 16:23:58 -0800206 mLauncher.getWorkspace().shrink(Workspace.ShrinkState.BOTTOM_VISIBLE);
Michael Jurkab8e14472010-12-20 16:06:10 -0800207 DeleteZone allAppsDeleteZone = (DeleteZone)
208 mLauncher.findViewById(R.id.all_apps_delete_zone);
209 allAppsDeleteZone.setDragAndDropEnabled(true);
210
Adam Cohencdc30d52010-12-01 15:09:47 -0800211 ApplicationInfoDropTarget allAppsInfoButton =
212 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
213 allAppsInfoButton.setDragAndDropEnabled(true);
Adam Cohencdc30d52010-12-01 15:09:47 -0800214 }
215
216 private void tearDownDragMode() {
217 post(new Runnable() {
218 // Once the drag operation has fully completed, hence the post, we want to disable the
219 // deleteZone and the appInfoButton in all apps, and re-enable the instance which
220 // live in the workspace
221 public void run() {
Michael Jurkab8e14472010-12-20 16:06:10 -0800222 DeleteZone allAppsDeleteZone =
223 (DeleteZone) mLauncher.findViewById(R.id.all_apps_delete_zone);
224 allAppsDeleteZone.setDragAndDropEnabled(false);
225
Adam Cohencdc30d52010-12-01 15:09:47 -0800226 ApplicationInfoDropTarget allAppsInfoButton =
227 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
228 allAppsInfoButton.setDragAndDropEnabled(false);
Adam Cohencdc30d52010-12-01 15:09:47 -0800229 }
230 });
231 resetCheckedGrandchildren();
232 mDragController.removeDropTarget(this);
233 }
234
Winson Chung321e9ee2010-08-09 13:37:56 -0700235 @Override
Michael Jurka72b079e2010-12-10 01:03:53 -0800236 protected boolean beginDragging(View v) {
Winson Chung304dcde2011-01-07 11:17:23 -0800237 if (!v.isInTouchMode()) return false;
238 if (!super.beginDragging(v)) return false;
Winson Chung321e9ee2010-08-09 13:37:56 -0700239
Adam Cohencdc30d52010-12-01 15:09:47 -0800240 // Start drag mode after the item is selected
241 setupDragMode();
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700242
Winson Chung321e9ee2010-08-09 13:37:56 -0700243 ApplicationInfo app = (ApplicationInfo) v.getTag();
244 app = new ApplicationInfo(app);
245
Michael Jurkad3ef3062010-11-23 16:23:58 -0800246 // get icon (top compound drawable, index is 1)
Winson Chungcd4bc492010-12-09 18:52:32 -0800247 final TextView tv = (TextView) v;
248 final Drawable icon = tv.getCompoundDrawables()[1];
249 Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Michael Jurkad3ef3062010-11-23 16:23:58 -0800250 Bitmap.Config.ARGB_8888);
251 Canvas c = new Canvas(b);
Winson Chungcd4bc492010-12-09 18:52:32 -0800252 c.translate((v.getWidth() - icon.getIntrinsicWidth()) / 2, v.getPaddingTop());
Michael Jurkad3ef3062010-11-23 16:23:58 -0800253 icon.draw(c);
Winson Chungcd4bc492010-12-09 18:52:32 -0800254
255 // We toggle the checked state _after_ we create the view for the drag in case toggling the
256 // checked state changes the view's look
257 if (v instanceof Checkable) {
258 // In preparation for drag, we always reset the checked grand children regardless of
259 // what choice mode we are in
260 resetCheckedGrandchildren();
261
262 // Toggle the selection on the dragged app
263 Checkable checkable = (Checkable) v;
Winson Chung59e1f9a2010-12-21 11:31:54 -0800264
265 // Note: we toggle the checkable state to actually cause an alpha fade for the duration
266 // of the drag of the item. (The fade-in will occur when all checked states are
267 // disabled when dragging ends)
Winson Chungcd4bc492010-12-09 18:52:32 -0800268 checkable.toggle();
269 }
270
271 // Start the drag
Michael Jurkad3ef3062010-11-23 16:23:58 -0800272 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
273 mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
Winson Chungcd4bc492010-12-09 18:52:32 -0800274 b.recycle();
Winson Chung321e9ee2010-08-09 13:37:56 -0700275 return true;
276 }
277
278 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800279 public void onDragViewVisible() {
280 }
281
282 @Override
Winson Chung321e9ee2010-08-09 13:37:56 -0700283 public void onDropCompleted(View target, boolean success) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700284 // close the choice action mode if we have a proper drop
285 if (target != this) {
286 endChoiceMode();
287 }
Adam Cohencdc30d52010-12-01 15:09:47 -0800288 tearDownDragMode();
Michael Jurka3e7c7632010-10-02 16:01:03 -0700289 mLauncher.getWorkspace().onDragStopped();
Winson Chung321e9ee2010-08-09 13:37:56 -0700290 }
291
292 @Override
293 public boolean isVisible() {
294 return mZoom > 0.001f;
295 }
296
297 @Override
298 public boolean isAnimating() {
299 return (getAnimation() != null);
300 }
301
302 private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
303 ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
304 if (mAppFilter == ALL_APPS_FLAG) {
305 return apps;
306 } else {
307 final int length = apps.size();
308 for (int i = 0; i < length; ++i) {
309 ApplicationInfo info = apps.get(i);
310 if ((info.flags & mAppFilter) > 0) {
311 filteredApps.add(info);
312 }
313 }
314 }
315 return filteredApps;
316 }
317
318 @Override
319 public void setApps(ArrayList<ApplicationInfo> list) {
320 mApps = list;
Winson Chung80baf5a2010-08-09 16:03:15 -0700321 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung321e9ee2010-08-09 13:37:56 -0700322 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung04998342011-01-05 13:54:43 -0800323 mPageViewIconCache.retainAllApps(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700324 invalidatePageData();
325 }
326
Winson Chung80baf5a2010-08-09 16:03:15 -0700327 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
328 // we add it in place, in alphabetical order
329 final int count = list.size();
330 for (int i = 0; i < count; ++i) {
331 final ApplicationInfo info = list.get(i);
332 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
333 if (index < 0) {
334 mApps.add(-(index + 1), info);
Winson Chung452821f2011-01-14 16:39:47 -0800335 } else {
336 mApps.add(index, info);
Winson Chung80baf5a2010-08-09 16:03:15 -0700337 }
338 }
339 mFilteredApps = rebuildFilteredApps(mApps);
340 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700341 @Override
342 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700343 addAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700344 invalidatePageData();
345 }
346
Winson Chung80baf5a2010-08-09 16:03:15 -0700347 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
Winson Chung10fefb12010-11-01 11:57:06 -0700348 // End the choice mode if any of the items in the list that are being removed are
349 // currently selected
350 ArrayList<Checkable> checkedList = getCheckedGrandchildren();
351 HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>();
352 for (Checkable checked : checkedList) {
353 PagedViewIcon icon = (PagedViewIcon) checked;
354 checkedAppInfos.add((ApplicationInfo) icon.getTag());
355 }
356 for (ApplicationInfo info : list) {
357 if (checkedAppInfos.contains(info)) {
358 endChoiceMode();
359 break;
360 }
361 }
362
363 // Loop through all the apps and remove apps that have the same component
Winson Chung321e9ee2010-08-09 13:37:56 -0700364 final int length = list.size();
365 for (int i = 0; i < length; ++i) {
Winson Chung241c3b42010-08-25 16:53:03 -0700366 final ApplicationInfo info = list.get(i);
367 int removeIndex = findAppByComponent(mApps, info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700368 if (removeIndex > -1) {
369 mApps.remove(removeIndex);
Winson Chung04998342011-01-05 13:54:43 -0800370 mPageViewIconCache.removeOutline(new PagedViewIconCache.Key(info));
Winson Chung321e9ee2010-08-09 13:37:56 -0700371 }
372 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700373 mFilteredApps = rebuildFilteredApps(mApps);
374 }
375 @Override
376 public void removeApps(ArrayList<ApplicationInfo> list) {
377 removeAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700378 invalidatePageData();
379 }
380
381 @Override
382 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700383 removeAppsWithoutInvalidate(list);
384 addAppsWithoutInvalidate(list);
385 invalidatePageData();
Winson Chung321e9ee2010-08-09 13:37:56 -0700386 }
387
388 private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
389 ComponentName removeComponent = item.intent.getComponent();
390 final int length = list.size();
391 for (int i = 0; i < length; ++i) {
392 ApplicationInfo info = list.get(i);
393 if (info.intent.getComponent().equals(removeComponent)) {
394 return i;
395 }
396 }
397 return -1;
398 }
399
400 @Override
401 public void dumpState() {
402 ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
403 }
404
405 @Override
406 public void surrender() {
407 // do nothing?
408 }
409
410 @Override
411 public void syncPages() {
Winson Chung96785572010-10-14 13:37:13 -0700412 // ensure that we have the right number of pages (min of 1, since we have placeholders)
413 int numPages = Math.max(1,
414 (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));
Winson Chung321e9ee2010-08-09 13:37:56 -0700415 int curNumPages = getChildCount();
416 // remove any extra pages after the "last" page
417 int extraPageDiff = curNumPages - numPages;
418 for (int i = 0; i < extraPageDiff; ++i) {
419 removeViewAt(numPages);
420 }
421 // add any necessary pages
422 for (int i = curNumPages; i < numPages; ++i) {
423 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
424 layout.setCellCount(mCellCountX, mCellCountY);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700425 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
426 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700427 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung321e9ee2010-08-09 13:37:56 -0700428 addView(layout);
429 }
430
431 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700432 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700433 }
434
435 @Override
436 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700437 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700438 final int cellsPerPage = mCellCountX * mCellCountY;
439 final int startIndex = page * cellsPerPage;
440 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700441 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700442
Winson Chung96785572010-10-14 13:37:13 -0700443 if (!mFilteredApps.isEmpty()) {
444 int curNumPageItems = layout.getChildCount();
445 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700446
Winson Chung96785572010-10-14 13:37:13 -0700447 // If we were previously an empty page, then restart anew
448 boolean wasEmptyPage = false;
449 if (curNumPageItems == 1) {
450 View icon = layout.getChildAt(0);
451 if (icon.getTag() == null) {
452 wasEmptyPage = true;
453 }
454 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700455
Winson Chung96785572010-10-14 13:37:13 -0700456 if (wasEmptyPage) {
457 // Remove all the previous items
458 curNumPageItems = 0;
459 layout.removeAllViews();
460 } else {
461 // Remove any extra items
462 int extraPageItemsDiff = curNumPageItems - numPageItems;
463 for (int i = 0; i < extraPageItemsDiff; ++i) {
464 layout.removeViewAt(numPageItems);
465 }
466 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700467
Winson Chung96785572010-10-14 13:37:13 -0700468 // Add any necessary items
469 for (int i = curNumPageItems; i < numPageItems; ++i) {
470 TextView text = (TextView) mInflater.inflate(
471 R.layout.all_apps_paged_view_application, layout, false);
472 text.setOnClickListener(this);
473 text.setOnLongClickListener(this);
Michael Jurka72b079e2010-12-10 01:03:53 -0800474 text.setOnTouchListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700475
Winson Chung96785572010-10-14 13:37:13 -0700476 layout.addViewToCellLayout(text, -1, i,
477 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
478 }
479
480 // Actually reapply to the existing text views
Winson Chung04998342011-01-05 13:54:43 -0800481 final int numPages = getPageCount();
Winson Chung96785572010-10-14 13:37:13 -0700482 for (int i = startIndex; i < endIndex; ++i) {
483 final int index = i - startIndex;
484 final ApplicationInfo info = mFilteredApps.get(i);
485 PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
Winson Chung04998342011-01-05 13:54:43 -0800486 icon.applyFromApplicationInfo(info, mPageViewIconCache, true, (numPages > 1));
Winson Chung96785572010-10-14 13:37:13 -0700487
488 PagedViewCellLayout.LayoutParams params =
489 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
490 params.cellX = index % mCellCountX;
491 params.cellY = index / mCellCountX;
492 }
493
494 // Default to left-aligned icons
495 layout.enableCenteredContent(false);
496 } else {
497 // There are no items, so show the user a small message
498 TextView icon = (TextView) mInflater.inflate(
499 R.layout.all_apps_no_items_placeholder, layout, false);
500 switch (mAppFilter) {
Winson Chung96785572010-10-14 13:37:13 -0700501 case ApplicationInfo.DOWNLOADED_FLAG:
502 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
503 break;
504 default: break;
505 }
506
507 // Center-align the message
508 layout.enableCenteredContent(true);
509 layout.removeAllViews();
510 layout.addViewToCellLayout(icon, -1, 0,
511 new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700512 }
513 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700514
515 /*
516 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
517 * to the workspace.
518 */
519 @Override
520 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
521 DragView dragView, Object dragInfo) {
522 return false;
523 }
524 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700525 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
526 int yOffset, DragView dragView, Object dragInfo) {
527 return null;
528 }
529 @Override
530 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
531 DragView dragView, Object dragInfo) {}
532 @Override
533 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
534 DragView dragView, Object dragInfo) {}
535 @Override
536 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
537 DragView dragView, Object dragInfo) {}
538 @Override
539 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
540 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700541
542 public boolean isDropEnabled() {
543 return true;
544 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700545}