blob: bfe6ec1710b5f05cedf6e5021a87f08ff7c09592 [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;
27import android.graphics.drawable.Drawable;
Winson Chung321e9ee2010-08-09 13:37:56 -070028import android.util.AttributeSet;
29import android.view.LayoutInflater;
30import android.view.View;
Winson Chung321e9ee2010-08-09 13:37:56 -070031import android.view.animation.AnimationUtils;
Winson Chung5f2aa4e2010-08-20 14:49:25 -070032import android.widget.Checkable;
Winson Chung321e9ee2010-08-09 13:37:56 -070033import android.widget.TextView;
34
Michael Jurkaaf91de02010-11-23 16:23:58 -080035import java.util.ArrayList;
36import java.util.Collections;
37import java.util.HashSet;
Winson Chung321e9ee2010-08-09 13:37:56 -070038
39/**
40 * An implementation of PagedView that populates the pages of the workspace
41 * with all of the user's applications.
42 */
Michael Jurka72b079e2010-12-10 01:03:53 -080043public class AllAppsPagedView extends PagedViewWithDraggableItems implements AllAppsView,
44 View.OnClickListener, DragSource, DropTarget {
Winson Chung321e9ee2010-08-09 13:37:56 -070045
46 private static final String TAG = "AllAppsPagedView";
Winson Chung321e9ee2010-08-09 13:37:56 -070047
48 private Launcher mLauncher;
49 private DragController mDragController;
50
51 // preserve compatibility with 3D all apps:
52 // 0.0 -> hidden
53 // 1.0 -> shown and opaque
54 // intermediate values -> partially shown & partially opaque
55 private float mZoom;
56
57 // set of all applications
58 private ArrayList<ApplicationInfo> mApps;
59 private ArrayList<ApplicationInfo> mFilteredApps;
60
61 // the types of applications to filter
62 static final int ALL_APPS_FLAG = -1;
63 private int mAppFilter = ALL_APPS_FLAG;
64
Winson Chung321e9ee2010-08-09 13:37:56 -070065 private final LayoutInflater mInflater;
66
Patrick Dubroydea9e932010-09-22 15:04:29 -070067
Winson Chung321e9ee2010-08-09 13:37:56 -070068 public AllAppsPagedView(Context context) {
69 this(context, null);
70 }
71
72 public AllAppsPagedView(Context context, AttributeSet attrs) {
73 this(context, attrs, 0);
74 }
75
76 public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
77 super(context, attrs, defStyle);
78 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
79 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
80 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
81 mInflater = LayoutInflater.from(context);
Winson Chung8b534782011-02-23 13:43:59 -080082 mApps = new ArrayList<ApplicationInfo>();
83 mFilteredApps = new ArrayList<ApplicationInfo>();
Winson Chung321e9ee2010-08-09 13:37:56 -070084 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) {
Michael Jurka8245a862011-02-01 17:53:59 -0800159 final Page layout = (Page) getChildAt(i);
160 if (layout.indexOfChildOnPage(v) > -1) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700161 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);
Michael Jurkab8e14472010-12-20 16:06:10 -0800208 DeleteZone allAppsDeleteZone = (DeleteZone)
209 mLauncher.findViewById(R.id.all_apps_delete_zone);
210 allAppsDeleteZone.setDragAndDropEnabled(true);
211
Adam Cohencdc30d52010-12-01 15:09:47 -0800212 ApplicationInfoDropTarget allAppsInfoButton =
213 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
214 allAppsInfoButton.setDragAndDropEnabled(true);
Adam Cohencdc30d52010-12-01 15:09:47 -0800215 }
216
217 private void tearDownDragMode() {
218 post(new Runnable() {
219 // Once the drag operation has fully completed, hence the post, we want to disable the
220 // deleteZone and the appInfoButton in all apps, and re-enable the instance which
221 // live in the workspace
222 public void run() {
Michael Jurkab8e14472010-12-20 16:06:10 -0800223 DeleteZone allAppsDeleteZone =
224 (DeleteZone) mLauncher.findViewById(R.id.all_apps_delete_zone);
Michael Jurkac31820d2011-01-16 16:57:05 -0800225 // if onDestroy was called on Launcher, we might have already deleted the
226 // all apps delete zone / info button, so check if they are null
227 if (allAppsDeleteZone != null) allAppsDeleteZone.setDragAndDropEnabled(false);
Michael Jurkab8e14472010-12-20 16:06:10 -0800228
Adam Cohencdc30d52010-12-01 15:09:47 -0800229 ApplicationInfoDropTarget allAppsInfoButton =
230 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
Michael Jurkac31820d2011-01-16 16:57:05 -0800231 if (allAppsInfoButton != null) allAppsInfoButton.setDragAndDropEnabled(false);
Adam Cohencdc30d52010-12-01 15:09:47 -0800232 }
233 });
234 resetCheckedGrandchildren();
235 mDragController.removeDropTarget(this);
236 }
237
Winson Chung321e9ee2010-08-09 13:37:56 -0700238 @Override
Michael Jurka72b079e2010-12-10 01:03:53 -0800239 protected boolean beginDragging(View v) {
Winson Chung304dcde2011-01-07 11:17:23 -0800240 if (!v.isInTouchMode()) return false;
241 if (!super.beginDragging(v)) return false;
Winson Chung321e9ee2010-08-09 13:37:56 -0700242
Adam Cohencdc30d52010-12-01 15:09:47 -0800243 // Start drag mode after the item is selected
244 setupDragMode();
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700245
Winson Chung321e9ee2010-08-09 13:37:56 -0700246 ApplicationInfo app = (ApplicationInfo) v.getTag();
247 app = new ApplicationInfo(app);
248
Michael Jurkad3ef3062010-11-23 16:23:58 -0800249 // get icon (top compound drawable, index is 1)
Winson Chungcd4bc492010-12-09 18:52:32 -0800250 final TextView tv = (TextView) v;
251 final Drawable icon = tv.getCompoundDrawables()[1];
252 Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Michael Jurkad3ef3062010-11-23 16:23:58 -0800253 Bitmap.Config.ARGB_8888);
254 Canvas c = new Canvas(b);
Winson Chungcd4bc492010-12-09 18:52:32 -0800255 c.translate((v.getWidth() - icon.getIntrinsicWidth()) / 2, v.getPaddingTop());
Michael Jurkad3ef3062010-11-23 16:23:58 -0800256 icon.draw(c);
Winson Chungcd4bc492010-12-09 18:52:32 -0800257
258 // We toggle the checked state _after_ we create the view for the drag in case toggling the
259 // checked state changes the view's look
260 if (v instanceof Checkable) {
261 // In preparation for drag, we always reset the checked grand children regardless of
262 // what choice mode we are in
263 resetCheckedGrandchildren();
264
265 // Toggle the selection on the dragged app
266 Checkable checkable = (Checkable) v;
Winson Chung59e1f9a2010-12-21 11:31:54 -0800267
268 // Note: we toggle the checkable state to actually cause an alpha fade for the duration
269 // of the drag of the item. (The fade-in will occur when all checked states are
270 // disabled when dragging ends)
Winson Chungcd4bc492010-12-09 18:52:32 -0800271 checkable.toggle();
272 }
273
274 // Start the drag
Winson Chung400438b2011-01-16 17:53:48 -0800275 mLauncher.lockScreenOrientation();
Michael Jurkad3ef3062010-11-23 16:23:58 -0800276 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
277 mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
Winson Chungcd4bc492010-12-09 18:52:32 -0800278 b.recycle();
Winson Chung321e9ee2010-08-09 13:37:56 -0700279 return true;
280 }
281
282 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800283 public void onDragViewVisible() {
284 }
285
286 @Override
Patrick Dubroy5f445422011-02-18 14:35:21 -0800287 public void onDropCompleted(View target, Object dragInfo, boolean success) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700288 // close the choice action mode if we have a proper drop
289 if (target != this) {
290 endChoiceMode();
291 }
Adam Cohencdc30d52010-12-01 15:09:47 -0800292 tearDownDragMode();
Patrick Dubroy7bccb422011-01-20 14:50:55 -0800293 mLauncher.getWorkspace().onDragStopped(success);
Winson Chung400438b2011-01-16 17:53:48 -0800294 mLauncher.unlockScreenOrientation();
Winson Chung321e9ee2010-08-09 13:37:56 -0700295 }
296
297 @Override
298 public boolean isVisible() {
299 return mZoom > 0.001f;
300 }
301
302 @Override
303 public boolean isAnimating() {
304 return (getAnimation() != null);
305 }
306
307 private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
308 ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
309 if (mAppFilter == ALL_APPS_FLAG) {
310 return apps;
311 } else {
312 final int length = apps.size();
313 for (int i = 0; i < length; ++i) {
314 ApplicationInfo info = apps.get(i);
315 if ((info.flags & mAppFilter) > 0) {
316 filteredApps.add(info);
317 }
318 }
Winson Chung78403fe2011-01-21 15:38:02 -0800319 Collections.sort(filteredApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
Winson Chung321e9ee2010-08-09 13:37:56 -0700320 }
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 Chung04998342011-01-05 13:54:43 -0800329 mPageViewIconCache.retainAllApps(list);
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);
Winson Chung452821f2011-01-14 16:39:47 -0800341 } else {
342 mApps.add(index, info);
Winson Chung80baf5a2010-08-09 16:03:15 -0700343 }
344 }
345 mFilteredApps = rebuildFilteredApps(mApps);
346 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700347 @Override
348 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700349 addAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700350 invalidatePageData();
351 }
352
Winson Chung80baf5a2010-08-09 16:03:15 -0700353 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
Winson Chung10fefb12010-11-01 11:57:06 -0700354 // End the choice mode if any of the items in the list that are being removed are
355 // currently selected
356 ArrayList<Checkable> checkedList = getCheckedGrandchildren();
357 HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>();
358 for (Checkable checked : checkedList) {
359 PagedViewIcon icon = (PagedViewIcon) checked;
360 checkedAppInfos.add((ApplicationInfo) icon.getTag());
361 }
362 for (ApplicationInfo info : list) {
363 if (checkedAppInfos.contains(info)) {
364 endChoiceMode();
365 break;
366 }
367 }
368
369 // Loop through all the apps and remove apps that have the same component
Winson Chung321e9ee2010-08-09 13:37:56 -0700370 final int length = list.size();
371 for (int i = 0; i < length; ++i) {
Winson Chung241c3b42010-08-25 16:53:03 -0700372 final ApplicationInfo info = list.get(i);
373 int removeIndex = findAppByComponent(mApps, info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700374 if (removeIndex > -1) {
375 mApps.remove(removeIndex);
Winson Chung04998342011-01-05 13:54:43 -0800376 mPageViewIconCache.removeOutline(new PagedViewIconCache.Key(info));
Winson Chung321e9ee2010-08-09 13:37:56 -0700377 }
378 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700379 mFilteredApps = rebuildFilteredApps(mApps);
380 }
381 @Override
382 public void removeApps(ArrayList<ApplicationInfo> list) {
383 removeAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700384 invalidatePageData();
385 }
386
387 @Override
388 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700389 removeAppsWithoutInvalidate(list);
390 addAppsWithoutInvalidate(list);
391 invalidatePageData();
Winson Chung321e9ee2010-08-09 13:37:56 -0700392 }
393
394 private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
Winson Chung8b534782011-02-23 13:43:59 -0800395 if (item != null && item.intent != null) {
396 ComponentName removeComponent = item.intent.getComponent();
397 final int length = list.size();
398 for (int i = 0; i < length; ++i) {
399 ApplicationInfo info = list.get(i);
400 if (info.intent.getComponent().equals(removeComponent)) {
401 return i;
402 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700403 }
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());
Michael Jurkac0759f52011-02-03 16:47:14 -0800432 layout.enableHardwareLayers();
Winson Chung321e9ee2010-08-09 13:37:56 -0700433 layout.setCellCount(mCellCountX, mCellCountY);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700434 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
435 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700436 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung321e9ee2010-08-09 13:37:56 -0700437 addView(layout);
438 }
439
440 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700441 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700442 }
443
444 @Override
445 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700446 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700447 final int cellsPerPage = mCellCountX * mCellCountY;
448 final int startIndex = page * cellsPerPage;
449 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700450 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700451
Winson Chung96785572010-10-14 13:37:13 -0700452 if (!mFilteredApps.isEmpty()) {
Michael Jurka8245a862011-02-01 17:53:59 -0800453 int curNumPageItems = layout.getPageChildCount();
Winson Chung96785572010-10-14 13:37:13 -0700454 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700455
Winson Chung96785572010-10-14 13:37:13 -0700456 // If we were previously an empty page, then restart anew
457 boolean wasEmptyPage = false;
458 if (curNumPageItems == 1) {
Michael Jurka8245a862011-02-01 17:53:59 -0800459 View icon = layout.getChildOnPageAt(0);
Winson Chung96785572010-10-14 13:37:13 -0700460 if (icon.getTag() == null) {
461 wasEmptyPage = true;
462 }
463 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700464
Winson Chung96785572010-10-14 13:37:13 -0700465 if (wasEmptyPage) {
466 // Remove all the previous items
467 curNumPageItems = 0;
Michael Jurka8245a862011-02-01 17:53:59 -0800468 layout.removeAllViewsOnPage();
Winson Chung96785572010-10-14 13:37:13 -0700469 } else {
470 // Remove any extra items
471 int extraPageItemsDiff = curNumPageItems - numPageItems;
472 for (int i = 0; i < extraPageItemsDiff; ++i) {
Michael Jurka8245a862011-02-01 17:53:59 -0800473 layout.removeViewOnPageAt(numPageItems);
Winson Chung96785572010-10-14 13:37:13 -0700474 }
475 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700476
Winson Chung96785572010-10-14 13:37:13 -0700477 // Add any necessary items
478 for (int i = curNumPageItems; i < numPageItems; ++i) {
479 TextView text = (TextView) mInflater.inflate(
480 R.layout.all_apps_paged_view_application, layout, false);
481 text.setOnClickListener(this);
482 text.setOnLongClickListener(this);
Michael Jurka72b079e2010-12-10 01:03:53 -0800483 text.setOnTouchListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700484
Winson Chung96785572010-10-14 13:37:13 -0700485 layout.addViewToCellLayout(text, -1, i,
486 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
487 }
488
489 // Actually reapply to the existing text views
Winson Chung04998342011-01-05 13:54:43 -0800490 final int numPages = getPageCount();
Winson Chung96785572010-10-14 13:37:13 -0700491 for (int i = startIndex; i < endIndex; ++i) {
492 final int index = i - startIndex;
493 final ApplicationInfo info = mFilteredApps.get(i);
Michael Jurka8245a862011-02-01 17:53:59 -0800494 PagedViewIcon icon = (PagedViewIcon) layout.getChildOnPageAt(index);
Winson Chung04998342011-01-05 13:54:43 -0800495 icon.applyFromApplicationInfo(info, mPageViewIconCache, true, (numPages > 1));
Winson Chung96785572010-10-14 13:37:13 -0700496
497 PagedViewCellLayout.LayoutParams params =
498 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
499 params.cellX = index % mCellCountX;
500 params.cellY = index / mCellCountX;
501 }
502
503 // Default to left-aligned icons
504 layout.enableCenteredContent(false);
505 } else {
506 // There are no items, so show the user a small message
507 TextView icon = (TextView) mInflater.inflate(
508 R.layout.all_apps_no_items_placeholder, layout, false);
509 switch (mAppFilter) {
Winson Chung96785572010-10-14 13:37:13 -0700510 case ApplicationInfo.DOWNLOADED_FLAG:
511 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
512 break;
513 default: break;
514 }
515
516 // Center-align the message
517 layout.enableCenteredContent(true);
Michael Jurka8245a862011-02-01 17:53:59 -0800518 layout.removeAllViewsOnPage();
Winson Chung96785572010-10-14 13:37:13 -0700519 layout.addViewToCellLayout(icon, -1, 0,
Winson Chung532a52a2011-01-18 12:18:00 -0800520 new PagedViewCellLayout.LayoutParams(0, 0, 4, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700521 }
Michael Jurkac5e49022011-02-16 12:04:02 -0800522 layout.createHardwareLayers();
Winson Chung321e9ee2010-08-09 13:37:56 -0700523 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700524
525 /*
526 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
527 * to the workspace.
528 */
529 @Override
530 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
531 DragView dragView, Object dragInfo) {
532 return false;
533 }
534 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700535 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
536 int yOffset, DragView dragView, Object dragInfo) {
537 return null;
538 }
539 @Override
540 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
541 DragView dragView, Object dragInfo) {}
542 @Override
543 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
544 DragView dragView, Object dragInfo) {}
545 @Override
546 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
547 DragView dragView, Object dragInfo) {}
548 @Override
549 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
550 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700551
552 public boolean isDropEnabled() {
553 return true;
554 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700555}