diff options
author | Philip Milne <pmilne@google.com> | 2011-06-17 15:43:13 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-17 15:43:13 -0700 |
commit | 405efeeeab6c1c0a76f6903881fdea0ee0b58259 (patch) | |
tree | 2d2e755ecfec0fd5f0e78aab90eecd746aee8307 /core/java/android | |
parent | ced4bb1df71355ff308ca4e8bfdc4a43ae53795b (diff) | |
parent | a789cafb066fd98e0e7f7ce506e3defa8104ba80 (diff) | |
download | frameworks_base-405efeeeab6c1c0a76f6903881fdea0ee0b58259.zip frameworks_base-405efeeeab6c1c0a76f6903881fdea0ee0b58259.tar.gz frameworks_base-405efeeeab6c1c0a76f6903881fdea0ee0b58259.tar.bz2 |
Merge "Pass width/height specs in the standard way when measuring children."
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/widget/GridLayout.java | 50 | ||||
-rw-r--r-- | core/java/android/widget/Space.java | 31 |
2 files changed, 37 insertions, 44 deletions
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java index a15ca0c..4a514bf 100644 --- a/core/java/android/widget/GridLayout.java +++ b/core/java/android/widget/GridLayout.java @@ -38,8 +38,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static android.view.View.MeasureSpec.EXACTLY; -import static android.view.View.MeasureSpec.UNSPECIFIED; import static java.lang.Math.max; import static java.lang.Math.min; @@ -760,43 +758,6 @@ public class GridLayout extends ViewGroup { // Measurement - private static int getChildMeasureSpec2(int spec, int padding, int childDimension) { - int resultSize; - int resultMode; - - if (childDimension >= 0) { - resultSize = childDimension; - resultMode = EXACTLY; - } else { - /* - using the following lines would replicate the logic of ViewGroup.getChildMeasureSpec() - - int specMode = MeasureSpec.getMode(spec); - int specSize = MeasureSpec.getSize(spec); - int size = Math.max(0, specSize - padding); - - resultSize = size; - resultMode = (specMode == EXACTLY && childDimension == LayoutParams.WRAP_CONTENT) ? - AT_MOST : specMode; - */ - resultSize = 0; - resultMode = UNSPECIFIED; - } - return MeasureSpec.makeMeasureSpec(resultSize, resultMode); - } - - @Override - protected void measureChild(View child, int parentWidthSpec, int parentHeightSpec) { - ViewGroup.LayoutParams lp = child.getLayoutParams(); - - int childWidthMeasureSpec = getChildMeasureSpec2(parentWidthSpec, - mPaddingLeft + mPaddingRight, lp.width); - int childHeightMeasureSpec = getChildMeasureSpec2(parentHeightSpec, - mPaddingTop + mPaddingBottom, lp.height); - - child.measure(childWidthMeasureSpec, childHeightMeasureSpec); - } - @Override protected void onMeasure(int widthSpec, int heightSpec) { measureChildren(widthSpec, heightSpec); @@ -1145,9 +1106,6 @@ public class GridLayout extends ViewGroup { return result; } - /* - Topological sort. - */ private Arc[] topologicalSort(final Arc[] arcs, int start) { // todo ensure the <start> vertex is added in edge cases final List<Arc> result = new ArrayList<Arc>(); @@ -2214,7 +2172,9 @@ public class GridLayout extends ViewGroup { * * @param view the view to which this alignment should be applied * @param viewSize the measured size of the view - * @param measurementType the type of measurement that should be made + * @param measurementType The type of measurement that should be made. This feature + * is currently unused as GridLayout only supports one + * type of measurement: {@link View#measure(int, int)}. * * @return the alignment value */ @@ -2230,7 +2190,9 @@ public class GridLayout extends ViewGroup { * @param view the view to which this alignment should be applied * @param viewSize the measured size of the view * @param cellSize the size of the cell into which this view will be placed - * @param measurementType the type of measurement that should be made + * @param measurementType The type of measurement that should be made. This feature + * is currently unused as GridLayout only supports one + * type of measurement: {@link View#measure(int, int)}. * * @return the aligned size */ diff --git a/core/java/android/widget/Space.java b/core/java/android/widget/Space.java index d98b937..d7b2ec2 100644 --- a/core/java/android/widget/Space.java +++ b/core/java/android/widget/Space.java @@ -72,4 +72,35 @@ public final class Space extends View { public void setLayoutParams(ViewGroup.LayoutParams params) { super.setLayoutParams(params); } + + /** + * Compare to: {@link View#getDefaultSize(int, int)} + * If mode is AT_MOST, return the child size instead of the parent size + * (unless it is too big). + */ + private static int getDefaultSize2(int size, int measureSpec) { + int result = size; + int specMode = MeasureSpec.getMode(measureSpec); + int specSize = MeasureSpec.getSize(measureSpec); + + switch (specMode) { + case MeasureSpec.UNSPECIFIED: + result = size; + break; + case MeasureSpec.AT_MOST: + result = Math.min(size, specSize); + break; + case MeasureSpec.EXACTLY: + result = specSize; + break; + } + return result; + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + setMeasuredDimension( + getDefaultSize2(getSuggestedMinimumWidth(), widthMeasureSpec), + getDefaultSize2(getSuggestedMinimumHeight(), heightMeasureSpec)); + } } |