diff options
author | Winson Chung <winsonc@google.com> | 2011-06-06 14:27:16 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2011-06-13 11:49:32 -0700 |
commit | f0ea4d3378be7b962c8e0bce2392df5e82491fb8 (patch) | |
tree | 72300454a7751c7d1b239c5264a73233736fc8a0 /src/com/android/launcher2/PagedViewCellLayout.java | |
parent | bf5a5c894d8af7f3b3001ebbc596fd83a0a73c7e (diff) | |
download | android_packages_apps_Trebuchet-f0ea4d3378be7b962c8e0bce2392df5e82491fb8.tar.gz android_packages_apps_Trebuchet-f0ea4d3378be7b962c8e0bce2392df5e82491fb8.tar.bz2 android_packages_apps_Trebuchet-f0ea4d3378be7b962c8e0bce2392df5e82491fb8.zip |
Replacing AllApps/Customize in tablet UI with Apps/Customize.
Change-Id: I11a296b25472e4bf298a468865b0dff29f500aaa
Diffstat (limited to 'src/com/android/launcher2/PagedViewCellLayout.java')
-rw-r--r-- | src/com/android/launcher2/PagedViewCellLayout.java | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java index 901ac2680..d7f8784a5 100644 --- a/src/com/android/launcher2/PagedViewCellLayout.java +++ b/src/com/android/launcher2/PagedViewCellLayout.java @@ -40,6 +40,7 @@ public class PagedViewCellLayout extends ViewGroup implements Page { private int mCellHeight; private int mWidthGap; private int mHeightGap; + private float mPeekWidth; protected PagedViewCellLayoutChildren mChildren; private PagedViewCellLayoutChildren mHolographicChildren; private boolean mAllowHardwareLayerCreation = false; @@ -62,6 +63,7 @@ public class PagedViewCellLayout extends ViewGroup implements Page { Resources resources = context.getResources(); mCellWidth = resources.getDimensionPixelSize(R.dimen.apps_customize_cell_width); mCellHeight = resources.getDimensionPixelSize(R.dimen.apps_customize_cell_height); + mPeekWidth = resources.getDimensionPixelSize(R.dimen.apps_customize_peek_width); mCellCountX = LauncherModel.getCellCountX(); mCellCountY = LauncherModel.getCellCountY(); mWidthGap = mHeightGap = -1; @@ -229,11 +231,11 @@ public class PagedViewCellLayout extends ViewGroup implements Page { int vSpaceLeft = heightSpecSize - mPaddingTop - mPaddingBottom - (cellHeight * mCellCountY); - int heightGap = vSpaceLeft / numHeightGaps; + int heightGap = (numHeightGaps <= 0) ? 0 : (vSpaceLeft / numHeightGaps); int hSpaceLeft = widthSpecSize - mPaddingLeft - mPaddingRight - (cellWidth * mCellCountX); - int widthGap = hSpaceLeft / numWidthGaps; + int widthGap = (numWidthGaps <= 0) ? 0 : (hSpaceLeft / numWidthGaps); // center it around the min gaps int minGap = Math.min(widthGap, heightGap); @@ -271,15 +273,7 @@ public class PagedViewCellLayout extends ViewGroup implements Page { } int getContentWidth() { - if (LauncherApplication.isScreenLarge()) { - // Return the distance from the left edge of the content of the leftmost icon to - // the right edge of the content of the rightmost icon - - // icons are centered within cells, find out how much padding that accounts for - return getWidthBeforeFirstLayout() - (mCellWidth - Utilities.getIconContentSize()); - } else { - return getWidthBeforeFirstLayout() + mPaddingLeft + mPaddingRight; - } + return getWidthBeforeFirstLayout() + mPaddingLeft + mPaddingRight; } int getContentHeight() { @@ -308,7 +302,20 @@ public class PagedViewCellLayout extends ViewGroup implements Page { @Override public boolean onTouchEvent(MotionEvent event) { - return super.onTouchEvent(event) || true; + boolean result = super.onTouchEvent(event); + int count = getPageChildCount(); + if (count > 0) { + // We only intercept the touch if we are tapping in empty space after the final row + View child = getChildOnPageAt(count - 1); + int bottom = child.getBottom(); + int numRows = (int) Math.ceil((float) getPageChildCount() / getCellCountX()); + if (numRows < getCellCountY()) { + // Add a little bit of buffer if there is room for another row + bottom += mCellHeight / 2; + } + result = result || (event.getY() < bottom); + } + return result; } public void enableCenteredContent(boolean enabled) { @@ -361,16 +368,37 @@ public class PagedViewCellLayout extends ViewGroup implements Page { * Estimates the number of cells that the specified width would take up. */ public int estimateCellHSpan(int width) { - // TODO: we need to take widthGap into effect - return (width + mCellWidth) / mCellWidth; + // The space for a page assuming that we want to show half of a column of the previous and + // next pages is the width - left padding (current & next page) - right padding (previous & + // current page) - half cell width (for previous and next pages) + int availWidth = (int) (width - (2 * mPaddingLeft + 2 * mPaddingRight) - (2 * mPeekWidth)); + + // We know that we have to fit N cells with N-1 width gaps, so we just juggle to solve for N + int n = Math.max(1, (availWidth + mWidthGap) / (mCellWidth + mWidthGap)); + + // We don't do anything fancy to determine if we squeeze another row in. + return n; } /** * Estimates the number of cells that the specified height would take up. */ public int estimateCellVSpan(int height) { - // TODO: we need to take heightGap into effect - return (height + mCellHeight) / mCellHeight; + // The space for a page is the height - top padding (current page) - bottom padding (current + // page) + int availHeight = height - (mPaddingTop + mPaddingBottom); + + // We know that we have to fit N cells with N-1 height gaps, so we juggle to solve for N + int n = Math.max(1, (availHeight + mHeightGap) / (mCellHeight + mHeightGap)); + + // We don't do anything fancy to determine if we squeeze another row in. + return n; + } + + public void calculateCellCount(int width, int height, int maxCellCountX, int maxCellCountY) { + mCellCountX = Math.min(maxCellCountX, estimateCellHSpan(width)); + mCellCountY = Math.min(maxCellCountY, estimateCellVSpan(height)); + requestLayout(); } /** |