blob: 1ad7e078a6b1b1e5aa164072d573a20a72e41866 [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;
23import android.content.res.TypedArray;
Michael Jurkad3ef3062010-11-23 16:23:58 -080024import android.graphics.Bitmap;
25import android.graphics.Canvas;
Winson Chungcd4bc492010-12-09 18:52:32 -080026import android.graphics.Color;
Michael Jurkad3ef3062010-11-23 16:23:58 -080027import android.graphics.drawable.Drawable;
Winson Chung321e9ee2010-08-09 13:37:56 -070028import android.util.AttributeSet;
Michael Jurkad3ef3062010-11-23 16:23:58 -080029import android.util.Log;
Winson Chung321e9ee2010-08-09 13:37:56 -070030import 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 */
44public class AllAppsPagedView extends PagedView
Winson Chung5f2aa4e2010-08-20 14:49:25 -070045 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource,
Adam Cohencdc30d52010-12-01 15:09:47 -080046 DropTarget {
Winson Chung321e9ee2010-08-09 13:37:56 -070047
48 private static final String TAG = "AllAppsPagedView";
49 private static final boolean DEBUG = false;
50
51 private Launcher mLauncher;
52 private DragController mDragController;
53
54 // preserve compatibility with 3D all apps:
55 // 0.0 -> hidden
56 // 1.0 -> shown and opaque
57 // intermediate values -> partially shown & partially opaque
58 private float mZoom;
59
60 // set of all applications
61 private ArrayList<ApplicationInfo> mApps;
62 private ArrayList<ApplicationInfo> mFilteredApps;
63
64 // the types of applications to filter
65 static final int ALL_APPS_FLAG = -1;
66 private int mAppFilter = ALL_APPS_FLAG;
67
Winson Chung321e9ee2010-08-09 13:37:56 -070068 private final LayoutInflater mInflater;
69
Patrick Dubroydea9e932010-09-22 15:04:29 -070070
Winson Chung321e9ee2010-08-09 13:37:56 -070071 public AllAppsPagedView(Context context) {
72 this(context, null);
73 }
74
75 public AllAppsPagedView(Context context, AttributeSet attrs) {
76 this(context, attrs, 0);
77 }
78
79 public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
80 super(context, attrs, defStyle);
81 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
82 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
83 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
84 mInflater = LayoutInflater.from(context);
85 a.recycle();
86 setSoundEffectsEnabled(false);
87 }
88
89 @Override
Winson Chung7da10252010-10-28 16:07:04 -070090 protected void init() {
91 super.init();
92 mCenterPagesVertically = false;
93 }
94
95 @Override
Winson Chung321e9ee2010-08-09 13:37:56 -070096 public void setLauncher(Launcher launcher) {
97 mLauncher = launcher;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -070098 mLauncher.setAllAppsPagedView(this);
Winson Chung321e9ee2010-08-09 13:37:56 -070099 }
100
101 @Override
102 public void setDragController(DragController dragger) {
103 mDragController = dragger;
104 }
105
106 public void setAppFilter(int filterType) {
107 mAppFilter = filterType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700108 if (mApps != null) {
109 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung86f77532010-08-24 11:08:22 -0700110 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700111 invalidatePageData();
112 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700113 }
114
115 @Override
116 public void zoom(float zoom, boolean animate) {
117 mZoom = zoom;
118 cancelLongPress();
119
120 if (isVisible()) {
121 getParent().bringChildToFront(this);
122 setVisibility(View.VISIBLE);
123 if (animate) {
124 startAnimation(AnimationUtils.loadAnimation(getContext(),
125 R.anim.all_apps_2d_fade_in));
126 } else {
127 onAnimationEnd();
128 }
129 } else {
130 if (animate) {
131 startAnimation(AnimationUtils.loadAnimation(getContext(),
132 R.anim.all_apps_2d_fade_out));
133 } else {
134 onAnimationEnd();
135 }
136 }
137 }
138
139 protected void onAnimationEnd() {
140 if (!isVisible()) {
141 setVisibility(View.GONE);
142 mZoom = 0.0f;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700143
144 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700145 } else {
146 mZoom = 1.0f;
147 }
148
149 if (mLauncher != null)
150 mLauncher.zoomed(mZoom);
151 }
152
153 private int getChildIndexForGrandChild(View v) {
154 final int childCount = getChildCount();
155 for (int i = 0; i < childCount; ++i) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700156 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
Winson Chung321e9ee2010-08-09 13:37:56 -0700157 if (layout.indexOfChild(v) > -1) {
158 return i;
159 }
160 }
161 return -1;
162 }
163
164 @Override
165 public void onClick(View v) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700166 // if we are already in a choice mode, then just change the selection
167 if (v instanceof Checkable) {
168 if (!isChoiceMode(CHOICE_MODE_NONE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700169 Checkable c = (Checkable) v;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700170 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700171 // Uncheck all the other grandchildren, and toggle the clicked one
172 boolean wasChecked = c.isChecked();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700173 resetCheckedGrandchildren();
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700174 c.setChecked(!wasChecked);
175 } else {
176 c.toggle();
177 }
178 if (getCheckedGrandchildren().size() == 0) {
179 endChoiceMode();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700180 }
181
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700182 return;
183 }
184 }
185
186 // otherwise continue and launch the application
Winson Chung321e9ee2010-08-09 13:37:56 -0700187 int childIndex = getChildIndexForGrandChild(v);
Winson Chung86f77532010-08-24 11:08:22 -0700188 if (childIndex == getCurrentPage()) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700189 final ApplicationInfo app = (ApplicationInfo) v.getTag();
190
Winson Chung80baf5a2010-08-09 16:03:15 -0700191 // animate some feedback to the click
192 animateClickFeedback(v, new Runnable() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700193 @Override
Winson Chung80baf5a2010-08-09 16:03:15 -0700194 public void run() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700195 mLauncher.startActivitySafely(app.intent, app);
196 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700197 });
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700198
199 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700200 }
201 }
202
Adam Cohencdc30d52010-12-01 15:09:47 -0800203 private void setupDragMode() {
Michael Jurkaaf91de02010-11-23 16:23:58 -0800204 mLauncher.getWorkspace().shrink(Workspace.ShrinkState.BOTTOM_VISIBLE);
Adam Cohencdc30d52010-12-01 15:09:47 -0800205
206 ApplicationInfoDropTarget infoButton =
207 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
208 infoButton.setDragAndDropEnabled(false);
209 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
210 deleteZone.setDragAndDropEnabled(false);
211
212 ApplicationInfoDropTarget allAppsInfoButton =
213 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
214 allAppsInfoButton.setDragAndDropEnabled(true);
215 DeleteZone allAppsDeleteZone = (DeleteZone)
216 mLauncher.findViewById(R.id.all_apps_delete_zone);
217 allAppsDeleteZone.setDragAndDropEnabled(true);
218 }
219
220 private void tearDownDragMode() {
221 post(new Runnable() {
222 // Once the drag operation has fully completed, hence the post, we want to disable the
223 // deleteZone and the appInfoButton in all apps, and re-enable the instance which
224 // live in the workspace
225 public void run() {
226 ApplicationInfoDropTarget infoButton =
227 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
228 infoButton.setDragAndDropEnabled(true);
229 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
230 deleteZone.setDragAndDropEnabled(true);
231
232 ApplicationInfoDropTarget allAppsInfoButton =
233 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
234 allAppsInfoButton.setDragAndDropEnabled(false);
235 DeleteZone allAppsDeleteZone =
236 (DeleteZone) mLauncher.findViewById(R.id.all_apps_delete_zone);
237 allAppsDeleteZone.setDragAndDropEnabled(false);
238 }
239 });
240 resetCheckedGrandchildren();
241 mDragController.removeDropTarget(this);
242 }
243
Winson Chung321e9ee2010-08-09 13:37:56 -0700244 @Override
245 public boolean onLongClick(View v) {
246 if (!v.isInTouchMode()) {
247 return false;
248 }
249
Adam Cohencdc30d52010-12-01 15:09:47 -0800250 // Start drag mode after the item is selected
251 setupDragMode();
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700252
Winson Chung321e9ee2010-08-09 13:37:56 -0700253 ApplicationInfo app = (ApplicationInfo) v.getTag();
254 app = new ApplicationInfo(app);
255
Michael Jurkad3ef3062010-11-23 16:23:58 -0800256 // get icon (top compound drawable, index is 1)
Winson Chungcd4bc492010-12-09 18:52:32 -0800257 final TextView tv = (TextView) v;
258 final Drawable icon = tv.getCompoundDrawables()[1];
259 Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Michael Jurkad3ef3062010-11-23 16:23:58 -0800260 Bitmap.Config.ARGB_8888);
261 Canvas c = new Canvas(b);
Winson Chungcd4bc492010-12-09 18:52:32 -0800262 c.translate((v.getWidth() - icon.getIntrinsicWidth()) / 2, v.getPaddingTop());
Michael Jurkad3ef3062010-11-23 16:23:58 -0800263 icon.draw(c);
Winson Chungcd4bc492010-12-09 18:52:32 -0800264
265 // We toggle the checked state _after_ we create the view for the drag in case toggling the
266 // checked state changes the view's look
267 if (v instanceof Checkable) {
268 // In preparation for drag, we always reset the checked grand children regardless of
269 // what choice mode we are in
270 resetCheckedGrandchildren();
271
272 // Toggle the selection on the dragged app
273 Checkable checkable = (Checkable) v;
274 checkable.toggle();
275 }
276
277 // Start the drag
Michael Jurkad3ef3062010-11-23 16:23:58 -0800278 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
279 mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
Winson Chungcd4bc492010-12-09 18:52:32 -0800280 b.recycle();
Winson Chung321e9ee2010-08-09 13:37:56 -0700281 return true;
282 }
283
284 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800285 public void onDragViewVisible() {
286 }
287
288 @Override
Winson Chung321e9ee2010-08-09 13:37:56 -0700289 public void onDropCompleted(View target, boolean success) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700290 // close the choice action mode if we have a proper drop
291 if (target != this) {
292 endChoiceMode();
293 }
Adam Cohencdc30d52010-12-01 15:09:47 -0800294 tearDownDragMode();
Michael Jurka3e7c7632010-10-02 16:01:03 -0700295 mLauncher.getWorkspace().onDragStopped();
Winson Chung321e9ee2010-08-09 13:37:56 -0700296 }
297
298 @Override
299 public boolean isVisible() {
300 return mZoom > 0.001f;
301 }
302
303 @Override
304 public boolean isAnimating() {
305 return (getAnimation() != null);
306 }
307
308 private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
309 ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
310 if (mAppFilter == ALL_APPS_FLAG) {
311 return apps;
312 } else {
313 final int length = apps.size();
314 for (int i = 0; i < length; ++i) {
315 ApplicationInfo info = apps.get(i);
316 if ((info.flags & mAppFilter) > 0) {
317 filteredApps.add(info);
318 }
319 }
320 }
321 return filteredApps;
322 }
323
324 @Override
325 public void setApps(ArrayList<ApplicationInfo> list) {
326 mApps = list;
Winson Chung80baf5a2010-08-09 16:03:15 -0700327 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung321e9ee2010-08-09 13:37:56 -0700328 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung241c3b42010-08-25 16:53:03 -0700329 mPageViewIconCache.clear();
Winson Chung321e9ee2010-08-09 13:37:56 -0700330 invalidatePageData();
331 }
332
Winson Chung80baf5a2010-08-09 16:03:15 -0700333 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
334 // we add it in place, in alphabetical order
335 final int count = list.size();
336 for (int i = 0; i < count; ++i) {
337 final ApplicationInfo info = list.get(i);
338 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
339 if (index < 0) {
340 mApps.add(-(index + 1), info);
341 }
342 }
343 mFilteredApps = rebuildFilteredApps(mApps);
344 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700345 @Override
346 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700347 addAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700348 invalidatePageData();
349 }
350
Winson Chung80baf5a2010-08-09 16:03:15 -0700351 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
Winson Chung10fefb12010-11-01 11:57:06 -0700352 // End the choice mode if any of the items in the list that are being removed are
353 // currently selected
354 ArrayList<Checkable> checkedList = getCheckedGrandchildren();
355 HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>();
356 for (Checkable checked : checkedList) {
357 PagedViewIcon icon = (PagedViewIcon) checked;
358 checkedAppInfos.add((ApplicationInfo) icon.getTag());
359 }
360 for (ApplicationInfo info : list) {
361 if (checkedAppInfos.contains(info)) {
362 endChoiceMode();
363 break;
364 }
365 }
366
367 // Loop through all the apps and remove apps that have the same component
Winson Chung321e9ee2010-08-09 13:37:56 -0700368 final int length = list.size();
369 for (int i = 0; i < length; ++i) {
Winson Chung241c3b42010-08-25 16:53:03 -0700370 final ApplicationInfo info = list.get(i);
371 int removeIndex = findAppByComponent(mApps, info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700372 if (removeIndex > -1) {
373 mApps.remove(removeIndex);
Winson Chung241c3b42010-08-25 16:53:03 -0700374 mPageViewIconCache.removeOutline(info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700375 }
376 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700377 mFilteredApps = rebuildFilteredApps(mApps);
378 }
379 @Override
380 public void removeApps(ArrayList<ApplicationInfo> list) {
381 removeAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700382 invalidatePageData();
383 }
384
385 @Override
386 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700387 removeAppsWithoutInvalidate(list);
388 addAppsWithoutInvalidate(list);
389 invalidatePageData();
Winson Chung321e9ee2010-08-09 13:37:56 -0700390 }
391
392 private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
393 ComponentName removeComponent = item.intent.getComponent();
394 final int length = list.size();
395 for (int i = 0; i < length; ++i) {
396 ApplicationInfo info = list.get(i);
397 if (info.intent.getComponent().equals(removeComponent)) {
398 return i;
399 }
400 }
401 return -1;
402 }
403
404 @Override
405 public void dumpState() {
406 ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
407 }
408
409 @Override
410 public void surrender() {
411 // do nothing?
412 }
413
414 @Override
415 public void syncPages() {
Winson Chung96785572010-10-14 13:37:13 -0700416 // ensure that we have the right number of pages (min of 1, since we have placeholders)
417 int numPages = Math.max(1,
418 (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));
Winson Chung321e9ee2010-08-09 13:37:56 -0700419 int curNumPages = getChildCount();
420 // remove any extra pages after the "last" page
421 int extraPageDiff = curNumPages - numPages;
422 for (int i = 0; i < extraPageDiff; ++i) {
423 removeViewAt(numPages);
424 }
425 // add any necessary pages
426 for (int i = curNumPages; i < numPages; ++i) {
427 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
428 layout.setCellCount(mCellCountX, mCellCountY);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700429 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
430 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700431 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung321e9ee2010-08-09 13:37:56 -0700432 addView(layout);
433 }
434
435 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700436 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700437 }
438
439 @Override
440 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700441 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700442 final int cellsPerPage = mCellCountX * mCellCountY;
443 final int startIndex = page * cellsPerPage;
444 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700445 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700446
Winson Chung96785572010-10-14 13:37:13 -0700447 if (!mFilteredApps.isEmpty()) {
448 int curNumPageItems = layout.getChildCount();
449 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700450
Winson Chung96785572010-10-14 13:37:13 -0700451 // If we were previously an empty page, then restart anew
452 boolean wasEmptyPage = false;
453 if (curNumPageItems == 1) {
454 View icon = layout.getChildAt(0);
455 if (icon.getTag() == null) {
456 wasEmptyPage = true;
457 }
458 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700459
Winson Chung96785572010-10-14 13:37:13 -0700460 if (wasEmptyPage) {
461 // Remove all the previous items
462 curNumPageItems = 0;
463 layout.removeAllViews();
464 } else {
465 // Remove any extra items
466 int extraPageItemsDiff = curNumPageItems - numPageItems;
467 for (int i = 0; i < extraPageItemsDiff; ++i) {
468 layout.removeViewAt(numPageItems);
469 }
470 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700471
Winson Chung96785572010-10-14 13:37:13 -0700472 // Add any necessary items
473 for (int i = curNumPageItems; i < numPageItems; ++i) {
474 TextView text = (TextView) mInflater.inflate(
475 R.layout.all_apps_paged_view_application, layout, false);
476 text.setOnClickListener(this);
477 text.setOnLongClickListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700478
Winson Chung96785572010-10-14 13:37:13 -0700479 layout.addViewToCellLayout(text, -1, i,
480 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
481 }
482
483 // Actually reapply to the existing text views
484 for (int i = startIndex; i < endIndex; ++i) {
485 final int index = i - startIndex;
486 final ApplicationInfo info = mFilteredApps.get(i);
487 PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700488 icon.applyFromApplicationInfo(info, mPageViewIconCache, true);
Winson Chung96785572010-10-14 13:37:13 -0700489
490 PagedViewCellLayout.LayoutParams params =
491 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
492 params.cellX = index % mCellCountX;
493 params.cellY = index / mCellCountX;
494 }
495
496 // Default to left-aligned icons
497 layout.enableCenteredContent(false);
498 } else {
499 // There are no items, so show the user a small message
500 TextView icon = (TextView) mInflater.inflate(
501 R.layout.all_apps_no_items_placeholder, layout, false);
502 switch (mAppFilter) {
Winson Chung96785572010-10-14 13:37:13 -0700503 case ApplicationInfo.DOWNLOADED_FLAG:
504 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
505 break;
506 default: break;
507 }
508
509 // Center-align the message
510 layout.enableCenteredContent(true);
511 layout.removeAllViews();
512 layout.addViewToCellLayout(icon, -1, 0,
513 new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700514 }
515 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700516
517 /*
518 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
519 * to the workspace.
520 */
521 @Override
522 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
523 DragView dragView, Object dragInfo) {
524 return false;
525 }
526 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700527 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
528 int yOffset, DragView dragView, Object dragInfo) {
529 return null;
530 }
531 @Override
532 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
533 DragView dragView, Object dragInfo) {}
534 @Override
535 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
536 DragView dragView, Object dragInfo) {}
537 @Override
538 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
539 DragView dragView, Object dragInfo) {}
540 @Override
541 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
542 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700543
544 public boolean isDropEnabled() {
545 return true;
546 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700547}