summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/AllAppsPagedView.java
diff options
context:
space:
mode:
authorPatrick Dubroy <dubroy@google.com>2011-05-19 16:48:48 -0700
committerPatrick Dubroy <dubroy@google.com>2011-05-20 14:03:14 -0700
commit244d74cb353f1260c4d633e719bf84bb3b6e52bc (patch)
treeb509b59b9fdef5b0f52fba899a4bd57c5c23099b /src/com/android/launcher2/AllAppsPagedView.java
parentdc4682a47446b38c912a30fe43b6a5c5cb53a367 (diff)
downloadandroid_packages_apps_Trebuchet-244d74cb353f1260c4d633e719bf84bb3b6e52bc.tar.gz
android_packages_apps_Trebuchet-244d74cb353f1260c4d633e719bf84bb3b6e52bc.tar.bz2
android_packages_apps_Trebuchet-244d74cb353f1260c4d633e719bf84bb3b6e52bc.zip
Dynamically determine # of rows/cols in All Apps.
Change-Id: Ia8c1b3915325823f7617862e0e4e0db865ea0d5d
Diffstat (limited to 'src/com/android/launcher2/AllAppsPagedView.java')
-rw-r--r--src/com/android/launcher2/AllAppsPagedView.java86
1 files changed, 67 insertions, 19 deletions
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index 59ba57bdf..d3082092f 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -66,11 +66,12 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
private final LayoutInflater mInflater;
private boolean mAllowHardwareLayerCreation;
- private boolean mFirstMeasure = true;
-
private int mPageContentWidth;
private boolean mHasMadeSuccessfulDrop;
+ private int mLastMeasureWidth = -1;
+ private int mLastMeasureHeight = -1;
+
public AllAppsPagedView(Context context) {
this(context, null);
}
@@ -82,8 +83,6 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
- mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
- mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
mInflater = LayoutInflater.from(context);
mApps = new ArrayList<ApplicationInfo>();
mFilteredApps = new ArrayList<ApplicationInfo>();
@@ -103,27 +102,76 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ final int width = MeasureSpec.getSize(widthMeasureSpec);
+ final int height = MeasureSpec.getSize(heightMeasureSpec);
+
+ if (mLastMeasureWidth != width || mLastMeasureHeight != height) {
+ // Create a dummy page and set it up to find out the content width (used by our parent)
+ PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
+ setupPage(layout);
+ mPageContentWidth = layout.getContentWidth();
+
+ mCellCountX = determineCellCountX(width, layout);
+ mCellCountY = determineCellCountY(height, layout);
+ mLastMeasureWidth = width;
+ mLastMeasureHeight = height;
+ }
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
- final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
- final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ if (mFirstLayout) {
+ invalidatePageData();
- if (mFirstMeasure) {
- mFirstMeasure = false;
+ // invalidatePageData() is what causes the child pages to be created. We need the
+ // children to be measured before layout, so force a new measure here.
+ measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY));
+ }
+ super.onLayout(changed, left, top, right, bottom);
+ }
- // TODO: actually calculate mCellCountX/mCellCountY as some function of
- // widthSize and heightSize
- //mCellCountX = ?;
- //mCellCountY = ?;
+ private int determineCellCountX(int availableWidth, PagedViewCellLayout layout) {
+ int cellCountX = 0;
+ final int cellWidth = layout.getCellWidth();
- // Since mCellCountX/mCellCountY changed, we need to update the pages
- invalidatePageData();
+ // Subtract padding for current page and adjacent pages
+ availableWidth -= mPageLayoutPaddingLeft * 2 + mPageLayoutPaddingRight * 2;
- // Create a dummy page and set it up to find out the content width (used by our parent)
- PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
- setupPage(layout);
- mPageContentWidth = layout.getContentWidth();
+ availableWidth -= cellWidth; // Assume at least one column
+ cellCountX = 1 + availableWidth / (cellWidth + mPageLayoutWidthGap);
+ availableWidth = availableWidth % (cellWidth + mPageLayoutWidthGap);
+
+ // Ensures that we show at least 30% of the holo icons on each side
+ final int minLeftoverWidth = (int) (cellWidth * 0.6f);
+
+ // Reserve room for the holo outlines
+ if (cellCountX <= 4) {
+ // When we're really tight on space, just pack the icons a bit closer together
+ final int missingWidth = minLeftoverWidth - availableWidth;
+ if (missingWidth > 0) {
+ mPageLayoutWidthGap -= Math.ceil(missingWidth * 1.0f / (cellCountX - 1));
+ }
+ } else {
+ if (cellCountX >= 8) {
+ // Carve out a few extra columns for very large widths
+ cellCountX = (int) (cellCountX * 0.9f);
+ } else if (availableWidth < minLeftoverWidth) {
+ cellCountX -= 1;
+ }
}
+ return cellCountX;
+ }
+
+ private int determineCellCountY(int availableHeight, PagedViewCellLayout layout) {
+ final int cellHeight = layout.getCellHeight();
+ final int screenHeight = mLauncher.getResources().getDisplayMetrics().heightPixels;
+
+ availableHeight -= mPageLayoutPaddingTop + mPageLayoutPaddingBottom;
+ availableHeight -= cellHeight; // Assume at least one row
+ availableHeight -= screenHeight * 0.16f;
+ return (1 + availableHeight / (cellHeight + mPageLayoutHeightGap));
}
void allowHardwareLayerCreation() {
@@ -504,7 +552,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
@Override
public void syncPages() {
- if (mFirstMeasure) {
+ if (mCellCountX <= 0 || mCellCountY <= 0) {
// We don't know our size yet, which means we haven't calculated cell count x/y;
// onMeasure will call us once we figure out our size
return;