diff options
author | Winson Chung <winsonc@google.com> | 2011-06-30 14:39:35 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2011-06-30 14:45:03 -0700 |
commit | db1138b4efae89a3b5833547958a3606e5408a71 (patch) | |
tree | db3455a620afffd9abd153064b4bec44b9ffa275 /src/com | |
parent | 6a0f57dfafced837a2a282d8feec28d5418be3b9 (diff) | |
download | android_packages_apps_Trebuchet-db1138b4efae89a3b5833547958a3606e5408a71.tar.gz android_packages_apps_Trebuchet-db1138b4efae89a3b5833547958a3606e5408a71.tar.bz2 android_packages_apps_Trebuchet-db1138b4efae89a3b5833547958a3606e5408a71.zip |
Tweaking AppsCustomize spacing to match CellLayout.
Change-Id: I5c3fa215659b51c7fc8dcda19dd1fd753d192f5e
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/launcher2/AppsCustomizePagedView.java | 6 | ||||
-rw-r--r-- | src/com/android/launcher2/PagedViewCellLayout.java | 69 |
2 files changed, 40 insertions, 35 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 54a2e42ff..35ca3e9a1 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -283,6 +283,10 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mShortcutCountX = Math.max(1, (int) Math.round(mCellCountX / 2f)); mShortcutCountY = Math.max(1, (int) Math.round(mCellCountY / 2f)); + // Force a measure to update recalculate the gaps + int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST); + int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST); + mWidgetSpacingLayout.measure(widthSpec, heightSpec); mContentWidth = mWidgetSpacingLayout.getContentWidth(); invalidatePageData(); @@ -537,7 +541,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // expected page width, so we can actually optimize by hiding all the TextView-based // children that are expensive to measure, and let that happen naturally later. setVisibilityOnChildren(layout, View.GONE); - int widthSpec = MeasureSpec.makeMeasureSpec(getPageContentWidth(), MeasureSpec.AT_MOST); + int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST); int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST); layout.setMinimumWidth(getPageContentWidth()); layout.measure(widthSpec, heightSpec); diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java index 9c37c019f..fc1b01288 100644 --- a/src/com/android/launcher2/PagedViewCellLayout.java +++ b/src/com/android/launcher2/PagedViewCellLayout.java @@ -19,6 +19,7 @@ package com.android.launcher2; import android.content.Context; import android.content.res.Resources; import android.util.AttributeSet; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewDebug; @@ -36,10 +37,13 @@ public class PagedViewCellLayout extends ViewGroup implements Page { private int mCellCountX; private int mCellCountY; + private int mOriginalCellWidth; + private int mOriginalCellHeight; private int mCellWidth; private int mCellHeight; private int mWidthGap; private int mHeightGap; + private int mMaxGap; private float mPeekWidth; protected PagedViewCellLayoutChildren mChildren; private PagedViewCellLayoutChildren mHolographicChildren; @@ -61,12 +65,15 @@ public class PagedViewCellLayout extends ViewGroup implements Page { // setup default cell parameters Resources resources = context.getResources(); - mCellWidth = resources.getDimensionPixelSize(R.dimen.apps_customize_cell_width); - mCellHeight = resources.getDimensionPixelSize(R.dimen.apps_customize_cell_height); + mOriginalCellWidth = mCellWidth = + resources.getDimensionPixelSize(R.dimen.apps_customize_cell_width); + mOriginalCellHeight = 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; + mMaxGap = resources.getDimensionPixelSize(R.dimen.apps_customize_max_gap); mChildren = new PagedViewCellLayoutChildren(context); mChildren.setCellDimensions(mCellWidth, mCellHeight); @@ -214,53 +221,47 @@ public class PagedViewCellLayout extends ViewGroup implements Page { throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions"); } - final int cellWidth = mCellWidth; - final int cellHeight = mCellHeight; + int numWidthGaps = mCellCountX - 1; int numHeightGaps = mCellCountY - 1; - int vSpaceLeft = heightSpecSize - mPaddingTop - - mPaddingBottom - (cellHeight * mCellCountY); - int heightGap = (numHeightGaps <= 0) ? 0 : (vSpaceLeft / numHeightGaps); - - int hSpaceLeft = widthSpecSize - mPaddingLeft - - mPaddingRight - (cellWidth * mCellCountX); - int widthGap = (numWidthGaps <= 0) ? 0 : (hSpaceLeft / numWidthGaps); - - // center it around the min gaps - int minGap = Math.min(widthGap, heightGap); - /* - if (minGap < heightGap) { - // vertical space has shrunken, so change padding accordingly - paddingTop += ((heightGap - minGap) * (mCellCountY - 1)) / 2; - } else if (minGap < widthGap) { - // horizontal space has shrunken, so change padding accordingly - paddingLeft += ((widthGap - minGap) * (mCellCountX - 1)) / 2; - } - */ - if (mWidthGap > -1 && mHeightGap > -1) { - widthGap = mWidthGap; - heightGap = mHeightGap; - } else { - widthGap = heightGap = minGap; + if (mWidthGap < 0 || mHeightGap < 0) { + int hSpace = widthSpecSize - mPaddingLeft - mPaddingRight; + int vSpace = heightSpecSize - mPaddingTop - mPaddingBottom; + int hFreeSpace = hSpace - (mCellCountX * mOriginalCellWidth); + int vFreeSpace = vSpace - (mCellCountY * mOriginalCellHeight); + mWidthGap = Math.min(mMaxGap, numWidthGaps > 0 ? (hFreeSpace / numWidthGaps) : 0); + mHeightGap = Math.min(mMaxGap,numHeightGaps > 0 ? (vFreeSpace / numHeightGaps) : 0); + + mChildren.setGap(mWidthGap, mHeightGap); + mHolographicChildren.setGap(mWidthGap, mHeightGap); } - int newWidth = (mCellCountX * cellWidth) + ((mCellCountX - 1) * widthGap); - int newHeight = (mCellCountY * cellHeight) + ((mCellCountY - 1) * heightGap); + // Initial values correspond to widthSpecMode == MeasureSpec.EXACTLY + int newWidth = widthSpecSize; + int newHeight = heightSpecSize; + if (widthSpecMode == MeasureSpec.AT_MOST) { + newWidth = mPaddingLeft + mPaddingRight + (mCellCountX * mCellWidth) + + ((mCellCountX - 1) * mWidthGap); + newHeight = mPaddingTop + mPaddingBottom + (mCellCountY * mCellHeight) + + ((mCellCountY - 1) * mHeightGap); + setMeasuredDimension(newWidth, newHeight); + } final int count = getChildCount(); for (int i = 0; i < count; i++) { View child = getChildAt(i); int childWidthMeasureSpec = - MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY); + MeasureSpec.makeMeasureSpec(newWidth - mPaddingLeft - + mPaddingRight, MeasureSpec.EXACTLY); int childheightMeasureSpec = - MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY); + MeasureSpec.makeMeasureSpec(newHeight - mPaddingTop - + mPaddingBottom, MeasureSpec.EXACTLY); child.measure(childWidthMeasureSpec, childheightMeasureSpec); } - setMeasuredDimension(newWidth + mPaddingLeft + mPaddingRight, - newHeight + mPaddingTop + mPaddingBottom); + setMeasuredDimension(newWidth, newHeight); } int getContentWidth() { |