From 4b0ed8c09ebc6afd97ff8b0de6a9617f6469ad1a Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Wed, 19 Oct 2011 15:24:49 -0700 Subject: Adding additional cases where we may have to recalculate the number of apps/widget pages. (Bug: 5475261) Change-Id: Ia5f0cea7a3b8bd0a972ec3ea2fadc72eb0f7689a --- .../android/launcher2/AppsCustomizePagedView.java | 33 ++++++++++++---------- .../android/launcher2/AppsCustomizeTabHost.java | 2 -- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 4718b31c4..ed9d0cffa 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -202,7 +202,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Dimens private int mContentWidth; private int mAppIconSize; - private int mMaxWidgetSpan, mMinWidgetSpan; private int mWidgetCountX, mWidgetCountY; private int mWidgetWidthGap, mWidgetHeightGap; private final int mWidgetPreviewIconPaddedDimension; @@ -223,7 +222,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Previews & outlines ArrayList mRunningTasks; private HolographicOutlineHelper mHolographicOutlineHelper; - private static final int sPageSleepDelay = 200; + private static final int sPageSleepDelay = 150; public AppsCustomizePagedView(Context context, AttributeSet attrs) { super(context, attrs); @@ -259,11 +258,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen a.recycle(); mWidgetSpacingLayout = new PagedViewCellLayout(getContext()); - // The max widget span is the length N, such that NxN is the largest bounds that the widget - // preview can be before applying the widget scaling - mMinWidgetSpan = 1; - mMaxWidgetSpan = 3; - // The padding on the non-matched dimension for the default widget preview icons // (top + bottom) mWidgetPreviewIconPaddedDimension = @@ -355,6 +349,12 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mSaveInstanceStateItemIndex = index; } + private void updatePageCounts() { + mNumWidgetPages = (int) Math.ceil(mWidgets.size() / + (float) (mWidgetCountX * mWidgetCountY)); + mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); + } + protected void onDataReady(int width, int height) { // Note that we transpose the counts in portrait so that we get a similar layout boolean isLandscape = getResources().getConfiguration().orientation == @@ -376,9 +376,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mWidgetSpacingLayout.calculateCellCount(width, height, maxCellCountX, maxCellCountY); mCellCountX = mWidgetSpacingLayout.getCellCountX(); mCellCountY = mWidgetSpacingLayout.getCellCountY(); - mNumWidgetPages = (int) Math.ceil(mWidgets.size() / - (float) (mWidgetCountX * mWidgetCountY)); - mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); + updatePageCounts(); // Force a measure to update recalculate the gaps int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST); @@ -390,6 +388,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen int page = getPageForComponent(mSaveInstanceStateItemIndex); invalidatePageData(Math.max(0, page)); + // Calculate the position for the cling punch through int[] offset = new int[2]; int[] pos = mWidgetSpacingLayout.estimateCellPosition(mClingFocusedX, mClingFocusedY); mLauncher.getDragLayer().getLocationInDragLayer(this, offset); @@ -455,6 +454,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mWidgets.addAll(shortcuts); Collections.sort(mWidgets, new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager)); + updatePageCounts(); if (wasEmpty) { // The next layout pass will trigger data-ready if both widgets and apps are set, so request @@ -605,7 +605,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen !layout.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY); } } - // TODO-APPS_CUSTOMIZE: We need to handle this for folders as well later. if (showOutOfSpaceMessage) { mLauncher.showOutOfSpaceMessage(); } @@ -636,10 +635,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } - public void setCurrentPageToWidgets() { - invalidatePageData(0); - } - protected void snapToPage(int whichPage, int delta, int duration) { super.snapToPage(whichPage, delta, duration); updateCurrentTab(whichPage); @@ -1300,6 +1295,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void setApps(ArrayList list) { mApps = list; Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); + updatePageCounts(); // The next layout pass will trigger data-ready if both widgets and apps are set, so // request a layout to do this test and invalidate the page data when ready. @@ -1319,6 +1315,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen @Override public void addApps(ArrayList list) { addAppsWithoutInvalidate(list); + updatePageCounts(); invalidatePageData(); } private int findAppByComponent(List list, ApplicationInfo item) { @@ -1346,6 +1343,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen @Override public void removeApps(ArrayList list) { removeAppsWithoutInvalidate(list); + updatePageCounts(); invalidatePageData(); } @Override @@ -1355,6 +1353,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // place in the list. removeAppsWithoutInvalidate(list); addAppsWithoutInvalidate(list); + updatePageCounts(); + invalidatePageData(); } @@ -1401,6 +1401,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void surrender() { // TODO: If we are in the middle of any process (ie. for holographic outlines, etc) we // should stop this now. + + // Stop all background tasks + cancelAllTasks(); } /* diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java index 404b088dc..3690c127c 100644 --- a/src/com/android/launcher2/AppsCustomizeTabHost.java +++ b/src/com/android/launcher2/AppsCustomizeTabHost.java @@ -75,8 +75,6 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona } void selectWidgetsTab() { setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets); - mAppsCustomizePane.setCurrentPageToWidgets(); - setCurrentTabByTag(WIDGETS_TAB_TAG); } -- cgit v1.2.3