summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Milne <pmilne@google.com>2011-07-12 14:49:45 -0700
committerPhilip Milne <pmilne@google.com>2011-07-13 21:31:20 -0700
commit93cd6a6c78683643de51f9e698b38847bd1f1155 (patch)
tree5e2ba751e7b06f2e3aacf3cb327d9b4781225559
parent64bd196fe4adf2d39b1e1bfd643043878c1714c0 (diff)
downloadframeworks_base-93cd6a6c78683643de51f9e698b38847bd1f1155.zip
frameworks_base-93cd6a6c78683643de51f9e698b38847bd1f1155.tar.gz
frameworks_base-93cd6a6c78683643de51f9e698b38847bd1f1155.tar.bz2
Rationalize API after adding maximum size feature.
. Change name of Group to Spec (with the addition of the fglexibility field, this class no longer represents a group) . Replace overloaded Group/Spec constructors with factory method . Bugfix for measure() when alignmentMode == ALIGN_BOUNDS . Bury as much Java API as possible, to minimize restrictions on future API enhancements - make all field access in Group package private - use factory methods in place of field assignment Change-Id: I46a5027a013bf7c3110b77108b8fd0427165cd18
-rw-r--r--api/current.txt20
-rw-r--r--core/java/android/widget/GridLayout.java417
-rwxr-xr-xcore/res/res/values/attrs.xml10
-rw-r--r--tests/GridLayoutTest/src/com/android/test/layout/Activity2.java31
-rwxr-xr-xtests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java5
-rw-r--r--tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java6
6 files changed, 262 insertions, 227 deletions
diff --git a/api/current.txt b/api/current.txt
index f3dda78..749edb1 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -25253,6 +25253,10 @@ package android.widget {
method public void setRowCount(int);
method public void setRowOrderPreserved(boolean);
method public void setUseDefaultMargins(boolean);
+ method public static android.widget.GridLayout.Spec spec(int, int, android.widget.GridLayout.Alignment, int);
+ method public static android.widget.GridLayout.Spec spec(int, android.widget.GridLayout.Alignment, int);
+ method public static android.widget.GridLayout.Spec spec(int, int, android.widget.GridLayout.Alignment);
+ method public static android.widget.GridLayout.Spec spec(int, android.widget.GridLayout.Alignment);
field public static final int ALIGN_BOUNDS = 0; // 0x0
field public static final int ALIGN_MARGINS = 1; // 0x1
field public static final android.widget.GridLayout.Alignment BASELINE;
@@ -25271,23 +25275,19 @@ package android.widget {
public static abstract class GridLayout.Alignment {
}
- public static class GridLayout.Group {
- ctor public GridLayout.Group(int, int, android.widget.GridLayout.Alignment);
- ctor public GridLayout.Group(int, android.widget.GridLayout.Alignment);
- field public final android.widget.GridLayout.Alignment alignment;
- field public int flexibility;
- }
-
public static class GridLayout.LayoutParams extends android.view.ViewGroup.MarginLayoutParams {
- ctor public GridLayout.LayoutParams(android.widget.GridLayout.Group, android.widget.GridLayout.Group);
+ ctor public GridLayout.LayoutParams(android.widget.GridLayout.Spec, android.widget.GridLayout.Spec);
ctor public GridLayout.LayoutParams();
ctor public GridLayout.LayoutParams(android.view.ViewGroup.LayoutParams);
ctor public GridLayout.LayoutParams(android.view.ViewGroup.MarginLayoutParams);
ctor public GridLayout.LayoutParams(android.widget.GridLayout.LayoutParams);
ctor public GridLayout.LayoutParams(android.content.Context, android.util.AttributeSet);
method public void setGravity(int);
- field public android.widget.GridLayout.Group columnGroup;
- field public android.widget.GridLayout.Group rowGroup;
+ field public android.widget.GridLayout.Spec columnSpec;
+ field public android.widget.GridLayout.Spec rowSpec;
+ }
+
+ public static class GridLayout.Spec {
}
public class GridView extends android.widget.AbsListView {
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index c2759e5..b9eb5ff 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -53,12 +53,12 @@ import static java.lang.Math.min;
* container and grid index {@code N} is fixed to its trailing edge
* (after padding is taken into account).
*
- * <h4>Row and Column Groups</h4>
+ * <h4>Row and Column Specs</h4>
*
* Children occupy one or more contiguous cells, as defined
- * by their {@link GridLayout.LayoutParams#rowGroup rowGroup} and
- * {@link GridLayout.LayoutParams#columnGroup columnGroup} layout parameters.
- * Each group specifies the set of rows or columns that are to be
+ * by their {@link GridLayout.LayoutParams#rowSpec rowSpec} and
+ * {@link GridLayout.LayoutParams#columnSpec columnSpec} layout parameters.
+ * Each spec defines the set of rows or columns that are to be
* occupied; and how children should be aligned within the resulting group of cells.
* Although cells do not normally overlap in a GridLayout, GridLayout does
* not prevent children being defined to occupy the same cell or group of cells.
@@ -92,7 +92,7 @@ import static java.lang.Math.min;
*
* <h4>Excess Space Distribution</h4>
*
- * A child's ability to stretch is controlled using the {@link Group#flexibility flexibility}
+ * A child's ability to stretch is controlled using the flexibility
* properties of its row and column groups.
* <p>
* <p>
@@ -167,8 +167,7 @@ public class GridLayout extends ViewGroup {
// Misc constants
private static final String TAG = GridLayout.class.getName();
- private static final boolean DEBUG = false;
- private static final double GOLDEN_RATIO = (1 + Math.sqrt(5)) / 2;
+ static final boolean DEBUG = false;
private static final int PRF = 1;
// Defaults
@@ -178,8 +177,9 @@ public class GridLayout extends ViewGroup {
private static final boolean DEFAULT_USE_DEFAULT_MARGINS = false;
private static final boolean DEFAULT_ORDER_PRESERVED = false;
private static final int DEFAULT_ALIGNMENT_MODE = ALIGN_MARGINS;
- // todo remove this
- private static final int DEFAULT_CONTAINER_MARGIN = 20;
+ private static final int DEFAULT_CONTAINER_MARGIN = 0;
+ private static final int DEFAULT_MARGIN = 8;
+ private static final int DEFAULT_CONTAINER_PADDING = 16;
private static final int MAX_SIZE = 100000;
// TypedArray indices
@@ -278,12 +278,12 @@ public class GridLayout extends ViewGroup {
/**
* Returns the current number of rows. This is either the last value that was set
* with {@link #setRowCount(int)} or, if no such value was set, the maximum
- * value of each the upper bounds defined in {@link LayoutParams#rowGroup}.
+ * value of each the upper bounds defined in {@link LayoutParams#rowSpec}.
*
* @return the current number of rows
*
* @see #setRowCount(int)
- * @see LayoutParams#rowGroup
+ * @see LayoutParams#rowSpec
*
* @attr ref android.R.styleable#GridLayout_rowCount
*/
@@ -299,7 +299,7 @@ public class GridLayout extends ViewGroup {
* @param rowCount the number of rows
*
* @see #getRowCount()
- * @see LayoutParams#rowGroup
+ * @see LayoutParams#rowSpec
*
* @attr ref android.R.styleable#GridLayout_rowCount
*/
@@ -310,12 +310,12 @@ public class GridLayout extends ViewGroup {
/**
* Returns the current number of columns. This is either the last value that was set
* with {@link #setColumnCount(int)} or, if no such value was set, the maximum
- * value of each the upper bounds defined in {@link LayoutParams#columnGroup}.
+ * value of each the upper bounds defined in {@link LayoutParams#columnSpec}.
*
* @return the current number of columns
*
* @see #setColumnCount(int)
- * @see LayoutParams#columnGroup
+ * @see LayoutParams#columnSpec
*
* @attr ref android.R.styleable#GridLayout_columnCount
*/
@@ -331,7 +331,7 @@ public class GridLayout extends ViewGroup {
* @param columnCount the number of columns.
*
* @see #getColumnCount()
- * @see LayoutParams#columnGroup
+ * @see LayoutParams#columnSpec
*
* @attr ref android.R.styleable#GridLayout_columnCount
*/
@@ -381,6 +381,10 @@ public class GridLayout extends ViewGroup {
*/
public void setUseDefaultMargins(boolean useDefaultMargins) {
mUseDefaultMargins = useDefaultMargins;
+ if (useDefaultMargins) {
+ int padding = DEFAULT_CONTAINER_PADDING;
+ setPadding(padding, padding, padding, padding);
+ }
requestLayout();
}
@@ -518,6 +522,14 @@ public class GridLayout extends ViewGroup {
return result;
}
+ private static int sum(int[] a) {
+ int result = 0;
+ for (int i = 0, N = a.length; i < N; i++) {
+ result += a[i];
+ }
+ return result;
+ }
+
private static <T> T[] append(T[] a, T[] b) {
T[] result = (T[]) Array.newInstance(a.getClass().getComponentType(), a.length + b.length);
System.arraycopy(a, 0, result, 0, a.length);
@@ -526,16 +538,10 @@ public class GridLayout extends ViewGroup {
}
private int getDefaultMargin(View c, boolean horizontal, boolean leading) {
- // In the absence of any other information, calculate a default gap such
- // that, in a grid of identical components, the heights and the vertical
- // gaps are in the proportion of the golden ratio.
- // To effect this with equal margins at each edge, set each of the
- // four margin values to half this amount.
- return (int) (c.getMeasuredHeight() / GOLDEN_RATIO / 2);
+ return DEFAULT_MARGIN;
}
private int getDefaultMargin(View c, boolean isAtEdge, boolean horizontal, boolean leading) {
- // todo remove DEFAULT_CONTAINER_MARGIN. Use padding? Seek advice on Themes/Styles, etc.
return isAtEdge ? DEFAULT_CONTAINER_MARGIN : getDefaultMargin(c, horizontal, leading);
}
@@ -543,9 +549,9 @@ public class GridLayout extends ViewGroup {
if (!mUseDefaultMargins) {
return 0;
}
- Group group = horizontal ? p.columnGroup : p.rowGroup;
+ Spec spec = horizontal ? p.columnSpec : p.rowSpec;
Axis axis = horizontal ? mHorizontalAxis : mVerticalAxis;
- Interval span = group.span;
+ Interval span = spec.span;
boolean isAtEdge = leading ? (span.min == 0) : (span.max == axis.getCount());
return getDefaultMargin(c, isAtEdge, horizontal, leading);
@@ -593,12 +599,12 @@ public class GridLayout extends ViewGroup {
if (isGone(c)) continue;
LayoutParams lp = getLayoutParams1(c);
- final Group colGroup = lp.columnGroup;
- final Interval cols = colGroup.span;
+ final Spec colSpec = lp.columnSpec;
+ final Interval cols = colSpec.span;
final int colSpan = cols.size();
- final Group rowGroup = lp.rowGroup;
- final Interval rows = rowGroup.span;
+ final Spec rowSpec = lp.rowSpec;
+ final Interval rows = rowSpec.span;
final int rowSpan = rows.size();
if (horizontal) {
@@ -623,8 +629,8 @@ public class GridLayout extends ViewGroup {
maxSize = max(maxSize, colSpan);
}
- lp.setColumnGroupSpan(new Interval(col, col + colSpan));
- lp.setRowGroupSpan(new Interval(row, row + rowSpan));
+ lp.setColumnSpecSpan(new Interval(col, col + colSpan));
+ lp.setRowSpecSpan(new Interval(row, row + rowSpan));
if (horizontal) {
col = col + colSpan;
@@ -737,7 +743,7 @@ public class GridLayout extends ViewGroup {
}
// Draw margins
- paint.setColor(Color.YELLOW);
+ paint.setColor(Color.MAGENTA);
for (int i = 0; i < getChildCount(); i++) {
View c = getChildAt(i);
drawRectangle(canvas,
@@ -872,11 +878,11 @@ public class GridLayout extends ViewGroup {
View c = getChildAt(i);
if (isGone(c)) continue;
LayoutParams lp = getLayoutParams(c);
- Group columnGroup = lp.columnGroup;
- Group rowGroup = lp.rowGroup;
+ Spec columnSpec = lp.columnSpec;
+ Spec rowSpec = lp.rowSpec;
- Interval colSpan = columnGroup.span;
- Interval rowSpan = rowGroup.span;
+ Interval colSpan = columnSpec.span;
+ Interval rowSpan = rowSpec.span;
int x1 = mHorizontalAxis.getLocationIncludingMargin(true, colSpan.min);
int y1 = mVerticalAxis.getLocationIncludingMargin(true, rowSpan.min);
@@ -890,8 +896,8 @@ public class GridLayout extends ViewGroup {
int pWidth = getMeasurement(c, true);
int pHeight = getMeasurement(c, false);
- Alignment hAlign = columnGroup.alignment;
- Alignment vAlign = rowGroup.alignment;
+ Alignment hAlign = columnSpec.alignment;
+ Alignment vAlign = rowSpec.alignment;
int dx, dy;
@@ -961,7 +967,7 @@ public class GridLayout extends ViewGroup {
public boolean countValid = false;
public boolean countWasExplicitySet = false;
- PackedMap<Group, Bounds> groupBounds;
+ PackedMap<Spec, Bounds> groupBounds;
public boolean groupBoundsValid = false;
PackedMap<Interval, MutableInt> forwardLinks;
@@ -998,9 +1004,9 @@ public class GridLayout extends ViewGroup {
View c = getChildAt(i);
if (isGone(c)) continue;
LayoutParams params = getLayoutParams(c);
- Group g = horizontal ? params.columnGroup : params.rowGroup;
- count = max(count, g.span.min);
- count = max(count, g.span.max);
+ Spec spec = horizontal ? params.columnSpec : params.rowSpec;
+ count = max(count, spec.span.min);
+ count = max(count, spec.span.max);
}
return count == -1 ? UNDEFINED : count;
}
@@ -1027,17 +1033,17 @@ public class GridLayout extends ViewGroup {
invalidateStructure();
}
- private PackedMap<Group, Bounds> createGroupBounds() {
- Assoc<Group, Bounds> assoc = Assoc.of(Group.class, Bounds.class);
+ private PackedMap<Spec, Bounds> createGroupBounds() {
+ Assoc<Spec, Bounds> assoc = Assoc.of(Spec.class, Bounds.class);
for (int i = 0, N = getChildCount(); i < N; i++) {
View c = getChildAt(i);
if (isGone(c)) {
- assoc.put(Group.GONE, Bounds.GONE);
+ assoc.put(Spec.GONE, Bounds.GONE);
} else {
LayoutParams lp = getLayoutParams(c);
- Group group = horizontal ? lp.columnGroup : lp.rowGroup;
- Bounds bounds = group.alignment.getBounds();
- assoc.put(group, bounds);
+ Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
+ Bounds bounds = spec.alignment.getBounds();
+ assoc.put(spec, bounds);
}
}
return assoc.pack();
@@ -1052,12 +1058,12 @@ public class GridLayout extends ViewGroup {
View c = getChildAt(i);
if (isGone(c)) continue;
LayoutParams lp = getLayoutParams(c);
- Group g = horizontal ? lp.columnGroup : lp.rowGroup;
- groupBounds.getValue(i).include(c, g, GridLayout.this, this);
+ Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
+ groupBounds.getValue(i).include(c, spec, GridLayout.this, this);
}
}
- private PackedMap<Group, Bounds> getGroupBounds() {
+ private PackedMap<Spec, Bounds> getGroupBounds() {
if (groupBounds == null) {
groupBounds = createGroupBounds();
}
@@ -1071,7 +1077,7 @@ public class GridLayout extends ViewGroup {
// Add values computed by alignment - taking the max of all alignments in each span
private PackedMap<Interval, MutableInt> createLinks(boolean min) {
Assoc<Interval, MutableInt> result = Assoc.of(Interval.class, MutableInt.class);
- Group[] keys = getGroupBounds().keys;
+ Spec[] keys = getGroupBounds().keys;
for (int i = 0, N = keys.length; i < N; i++) {
Interval span = min ? keys[i].span : keys[i].span.inverse();
result.put(span, new MutableInt());
@@ -1092,8 +1098,7 @@ public class GridLayout extends ViewGroup {
MutableInt valueHolder = links.getValue(i);
if (min) {
valueHolder.value = max(valueHolder.value, size);
- }
- else {
+ } else {
valueHolder.value = -max(-valueHolder.value, size);
}
}
@@ -1236,8 +1241,8 @@ public class GridLayout extends ViewGroup {
View c = getChildAt(i);
if (isGone(c)) continue;
LayoutParams lp = getLayoutParams(c);
- Group g = horizontal ? lp.columnGroup : lp.rowGroup;
- Interval span = g.span;
+ Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
+ Interval span = spec.span;
leadingEdgeCount[span.min]++;
trailingEdgeCount[span.max]++;
}
@@ -1436,8 +1441,8 @@ public class GridLayout extends ViewGroup {
View c = getChildAt(i);
if (isGone(c)) continue;
LayoutParams lp = getLayoutParams(c);
- Group g = horizontal ? lp.columnGroup : lp.rowGroup;
- Interval span = g.span;
+ Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
+ Interval span = spec.span;
int index = leading ? span.min : span.max;
margins[index] = max(margins[index], getMargin(c, horizontal, leading));
}
@@ -1514,6 +1519,12 @@ public class GridLayout extends ViewGroup {
}
private void setParentConstraints(int min, int max) {
+ if (mAlignmentMode != ALIGN_MARGINS) {
+ int margins = sum(getLeadingMargins()) + sum(getTrailingMargins());
+ min -= margins;
+ max -= margins;
+ }
+
parentMin.value = min;
parentMax.value = -max;
locationsValid = false;
@@ -1529,7 +1540,7 @@ public class GridLayout extends ViewGroup {
int size = MeasureSpec.getSize(measureSpec);
switch (mode) {
case MeasureSpec.UNSPECIFIED: {
- return getMeasure(0, MAX_SIZE);
+ return getMeasure(0, MAX_SIZE);
}
case MeasureSpec.EXACTLY: {
return getMeasure(size, size);
@@ -1584,14 +1595,14 @@ public class GridLayout extends ViewGroup {
* GridLayout supports both row and column spanning and arbitrary forms of alignment within
* each cell group. The fundamental parameters associated with each cell group are
* gathered into their vertical and horizontal components and stored
- * in the {@link #rowGroup} and {@link #columnGroup} layout parameters.
- * {@link Group Groups} are immutable structures and may be shared between the layout
+ * in the {@link #rowSpec} and {@link #columnSpec} layout parameters.
+ * {@link android.widget.GridLayout.Spec Specs} are immutable structures and may be shared between the layout
* parameters of different children.
* <p>
- * The row and column groups contain the leading and trailing indices along each axis
+ * The row and column specs contain the leading and trailing indices along each axis
* and together specify the four grid indices that delimit the cells of this cell group.
* <p>
- * The {@link Group#alignment alignment} fields of the row and column groups together specify
+ * The alignment properties of the row and column specs together specify
* both aspects of alignment within the cell group. It is also possible to specify a child's
* alignment within its cell group by using the {@link GridLayout.LayoutParams#setGravity(int)}
* method.
@@ -1620,10 +1631,10 @@ public class GridLayout extends ViewGroup {
* {@link GridLayout#setUseDefaultMargins(boolean) useDefaultMargins} is
* {@code false}; otherwise {@link #UNDEFINED}, to
* indicate that a default value should be computed on demand. </li>
- * <li>{@link #rowGroup}{@code .span} = {@code [0, 1]} </li>
- * <li>{@link #rowGroup}{@code .alignment} = {@link #BASELINE} </li>
- * <li>{@link #columnGroup}{@code .span} = {@code [0, 1]} </li>
- * <li>{@link #columnGroup}{@code .alignment} = {@link #LEFT} </li>
+ * <li>{@link #rowSpec}{@code .span} = {@code [0, 1]} </li>
+ * <li>{@link #rowSpec}{@code .alignment} = {@link #BASELINE} </li>
+ * <li>{@link #columnSpec}{@code .span} = {@code [0, 1]} </li>
+ * <li>{@link #columnSpec}{@code .alignment} = {@link #LEFT} </li>
* </ul>
*
* @attr ref android.R.styleable#GridLayout_Layout_layout_row
@@ -1678,48 +1689,48 @@ public class GridLayout extends ViewGroup {
// Instance variables
/**
- * The group that specifies the vertical characteristics of the cell group
+ * The spec that specifies the vertical characteristics of the cell group
* described by these layout parameters.
*/
- public Group rowGroup;
+ public Spec rowSpec;
/**
- * The group that specifies the horizontal characteristics of the cell group
+ * The spec that specifies the horizontal characteristics of the cell group
* described by these layout parameters.
*/
- public Group columnGroup;
+ public Spec columnSpec;
// Constructors
private LayoutParams(
int width, int height,
int left, int top, int right, int bottom,
- Group rowGroup, Group columnGroup) {
+ Spec rowSpec, Spec columnSpec) {
super(width, height);
setMargins(left, top, right, bottom);
- this.rowGroup = rowGroup;
- this.columnGroup = columnGroup;
+ this.rowSpec = rowSpec;
+ this.columnSpec = columnSpec;
}
/**
- * Constructs a new LayoutParams instance for this <code>rowGroup</code>
- * and <code>columnGroup</code>. All other fields are initialized with
+ * Constructs a new LayoutParams instance for this <code>rowSpec</code>
+ * and <code>columnSpec</code>. All other fields are initialized with
* default values as defined in {@link LayoutParams}.
*
- * @param rowGroup the rowGroup
- * @param columnGroup the columnGroup
+ * @param rowSpec the rowSpec
+ * @param columnSpec the columnSpec
*/
- public LayoutParams(Group rowGroup, Group columnGroup) {
+ public LayoutParams(Spec rowSpec, Spec columnSpec) {
this(DEFAULT_WIDTH, DEFAULT_HEIGHT,
DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN,
- rowGroup, columnGroup);
+ rowSpec, columnSpec);
}
/**
* Constructs a new LayoutParams with default values as defined in {@link LayoutParams}.
*/
public LayoutParams() {
- this(new Group(DEFAULT_SPAN, DEFAULT_ROW_ALIGNMENT),
- new Group(DEFAULT_SPAN, DEFAULT_COLUMN_ALIGNMENT));
+ this(new Spec(DEFAULT_SPAN, DEFAULT_ROW_ALIGNMENT, Spec.DEFAULT_FLEXIBILITY),
+ new Spec(DEFAULT_SPAN, DEFAULT_COLUMN_ALIGNMENT, Spec.DEFAULT_FLEXIBILITY));
}
// Copying constructors
@@ -1743,8 +1754,8 @@ public class GridLayout extends ViewGroup {
*/
public LayoutParams(LayoutParams that) {
super(that);
- this.columnGroup = new Group(that.columnGroup);
- this.rowGroup = new Group(that.rowGroup);
+ this.columnSpec = new Spec(that.columnSpec);
+ this.rowSpec = new Spec(that.rowSpec);
}
// AttributeSet constructors
@@ -1836,14 +1847,14 @@ public class GridLayout extends ViewGroup {
int column = a.getInt(COLUMN, DEFAULT_COLUMN);
int columnSpan = a.getInt(COLUMN_SPAN, DEFAULT_SPAN_SIZE);
Interval hSpan = new Interval(column, column + columnSpan);
- int hFlexibility = a.getInt(COLUMN_FLEXIBILITY, Group.DEFAULT_FLEXIBILITY);
- this.columnGroup = new Group(hSpan, getColAlignment(gravity, width), hFlexibility);
+ int hFlexibility = a.getInt(COLUMN_FLEXIBILITY, Spec.DEFAULT_FLEXIBILITY);
+ this.columnSpec = new Spec(hSpan, getColAlignment(gravity, width), hFlexibility);
int row = a.getInt(ROW, DEFAULT_ROW);
int rowSpan = a.getInt(ROW_SPAN, DEFAULT_SPAN_SIZE);
Interval vSpan = new Interval(row, row + rowSpan);
- int vFlexibility = a.getInt(ROW_FLEXIBILITY, Group.DEFAULT_FLEXIBILITY);
- this.rowGroup = new Group(vSpan, getRowAlignment(gravity, height), vFlexibility);
+ int vFlexibility = a.getInt(ROW_FLEXIBILITY, Spec.DEFAULT_FLEXIBILITY);
+ this.rowSpec = new Spec(vSpan, getRowAlignment(gravity, height), vFlexibility);
} finally {
a.recycle();
}
@@ -1858,8 +1869,8 @@ public class GridLayout extends ViewGroup {
* @attr ref android.R.styleable#GridLayout_Layout_layout_gravity
*/
public void setGravity(int gravity) {
- columnGroup = columnGroup.copyWriteAlignment(getColAlignment(gravity, width));
- rowGroup = rowGroup.copyWriteAlignment(getRowAlignment(gravity, height));
+ columnSpec = columnSpec.copyWriteAlignment(getColAlignment(gravity, width));
+ rowSpec = rowSpec.copyWriteAlignment(getRowAlignment(gravity, height));
}
@Override
@@ -1868,12 +1879,12 @@ public class GridLayout extends ViewGroup {
this.height = attributes.getLayoutDimension(heightAttr, DEFAULT_HEIGHT);
}
- private void setRowGroupSpan(Interval span) {
- rowGroup = rowGroup.copyWriteSpan(span);
+ private void setRowSpecSpan(Interval span) {
+ rowSpec = rowSpec.copyWriteSpan(span);
}
- private void setColumnGroupSpan(Interval span) {
- columnGroup = columnGroup.copyWriteSpan(span);
+ private void setColumnSpecSpan(Interval span) {
+ columnSpec = columnSpec.copyWriteSpan(span);
}
}
@@ -2019,14 +2030,14 @@ public class GridLayout extends ViewGroup {
}
/*
- For each Group (with a given alignment) we need to store the amount of space required
+ For each group (with a given alignment) we need to store the amount of space required
before the alignment point and the amount of space required after it. One side of this
calculation is always 0 for LEADING and TRAILING alignments but we don't make use of this.
For CENTER and BASELINE alignments both sides are needed and in the BASELINE case no
simple optimisations are possible.
The general algorithm therefore is to create a Map (actually a PackedMap) from
- Group to Bounds and to loop through all Views in the group taking the maximum
+ group to Bounds and to loop through all Views in the group taking the maximum
of the values for each View.
*/
private static class Bounds {
@@ -2067,11 +2078,11 @@ public class GridLayout extends ViewGroup {
return before - alignment.getAlignmentValue(c, size);
}
- protected void include(View c, Group group, GridLayout gridLayout, Axis axis) {
- this.flexibility &= group.flexibility;
+ protected void include(View c, Spec spec, GridLayout gridLayout, Axis axis) {
+ this.flexibility &= spec.flexibility;
int size = gridLayout.getMeasurementIncludingMargin(c, axis.horizontal);
// todo test this works correctly when the returned value is UNDEFINED
- int before = group.alignment.getAlignmentValue(c, size);
+ int before = spec.alignment.getAlignmentValue(c, size);
include(before, size - before);
}
@@ -2176,16 +2187,13 @@ public class GridLayout extends ViewGroup {
}
/**
- * A group specifies either the horizontal or vertical characteristics of a group of
+ * A spec defines either the horizontal or vertical characteristics of a group of
* cells.
- * <p>
- * Groups are immutable and so may be shared between views with the same
- * {@code span} and {@code alignment}.
*/
- public static class Group {
+ public static class Spec {
private static final int DEFAULT_FLEXIBILITY = UNDEFINED_FLEXIBILITY;
- private static final Group GONE = new Group(Interval.GONE, Alignment.GONE);
+ private static final Spec GONE = new Spec(Interval.GONE, Alignment.GONE);
/**
* The grid indices of the leading and trailing edges of this cell group for the
@@ -2200,7 +2208,7 @@ public class GridLayout extends ViewGroup {
* For row groups, this specifies the vertical alignment.
* For column groups, this specifies the horizontal alignment.
*/
- public final Alignment alignment;
+ final Alignment alignment;
/**
* The flexibility field tells GridLayout how to derive minimum and maximum size
@@ -2212,82 +2220,48 @@ public class GridLayout extends ViewGroup {
*
* @see GridLayout#CAN_STRETCH
*/
- public int flexibility = DEFAULT_FLEXIBILITY;
+ final int flexibility;
- /**
- * Construct a new Group, {@code group}, where:
- * <ul>
- * <li> {@code group.span = span} </li>
- * <li> {@code group.alignment = alignment} </li>
- * </ul>
- *
- * @param span the span
- * @param alignment the alignment
- */
- private Group(Interval span, Alignment alignment) {
+ private Spec(Interval span, Alignment alignment, int flexibility) {
this.span = span;
this.alignment = alignment;
+ this.flexibility = flexibility;
}
- private Group(Interval span, Alignment alignment, int flexibility) {
- this.span = span;
- this.alignment = alignment;
- this.flexibility = flexibility;
+ private Spec(Interval span, Alignment alignment) {
+ this(span, alignment, DEFAULT_FLEXIBILITY);
}
/* Copying constructor */
- private Group(Group that) {
- this.span = that.span;
- this.alignment = that.alignment;
- this.flexibility = that.flexibility;
+ private Spec(Spec that) {
+ this(that.span, that.alignment, that.flexibility);
}
- /**
- * Construct a new Group, {@code group}, where:
- * <ul>
- * <li> {@code group.span = [start, start + size]} </li>
- * <li> {@code group.alignment = alignment} </li>
- * </ul>
- *
- * @param start the start
- * @param size the size
- * @param alignment the alignment
- */
- public Group(int start, int size, Alignment alignment) {
- this(new Interval(start, start + size), alignment);
+ Spec(int start, int size, Alignment alignment, int flexibility) {
+ this(new Interval(start, start + size), alignment, flexibility);
}
- /**
- * Construct a new Group, {@code group}, where:
- * <ul>
- * <li> {@code group.span = [start, start + 1]} </li>
- * <li> {@code group.alignment = alignment} </li>
- * </ul>
- *
- * @param start the start index
- * @param alignment the alignment
- */
- public Group(int start, Alignment alignment) {
- this(start, 1, alignment);
+ private Spec copyWriteSpan(Interval span) {
+ return new Spec(span, alignment, flexibility);
}
- private Group copyWriteSpan(Interval span) {
- return new Group(span, alignment, flexibility);
+ private Spec copyWriteAlignment(Alignment alignment) {
+ return new Spec(span, alignment, flexibility);
}
- private Group copyWriteAlignment(Alignment alignment) {
- return new Group(span, alignment, flexibility);
+ private Spec copyWriteFlexibility(int flexibility) {
+ return new Spec(span, alignment, flexibility);
}
/**
- * Returns {@code true} if the {@link #getClass class}, {@link #alignment} and {@code span}
- * properties of this Group and the supplied parameter are pairwise equal,
+ * Returns {@code true} if the {@code class}, {@code alignment} and {@code span}
+ * properties of this Spec and the supplied parameter are pairwise equal,
* {@code false} otherwise.
*
- * @param that the object to compare this group with
+ * @param that the object to compare this spec with
*
* @return {@code true} if the specified object is equal to this
- * {@code Group}; {@code false} otherwise
+ * {@code Spec}; {@code false} otherwise
*/
@Override
public boolean equals(Object that) {
@@ -2298,12 +2272,12 @@ public class GridLayout extends ViewGroup {
return false;
}
- Group group = (Group) that;
+ Spec spec = (Spec) that;
- if (!alignment.equals(group.alignment)) {
+ if (!alignment.equals(spec.alignment)) {
return false;
}
- if (!span.equals(group.span)) {
+ if (!span.equals(spec.span)) {
return false;
}
@@ -2319,12 +2293,93 @@ public class GridLayout extends ViewGroup {
}
/**
+ * Temporary backward compatibility class for Launcher - to avoid
+ * dependent multi-project commit. This class will be deleted after
+ * AppsCustomizePagedView is updated to new API.
+ *
+ * @hide
+ */
+ @Deprecated
+ public static class Group extends Spec {
+ /**
+ * @deprecated Please replace with {@link #spec(int, int, Alignment)}
+ * @hide
+ */
+ @Deprecated
+ public Group(int start, int size, Alignment alignment) {
+ super(start, size, alignment, UNDEFINED_FLEXIBILITY);
+ }
+ }
+
+ /**
+ * Return a Spec, {@code spec}, where:
+ * <ul>
+ * <li> {@code spec.span = [start, start + size]} </li>
+ * <li> {@code spec.alignment = alignment} </li>
+ * <li> {@code spec.flexibility = flexibility} </li>
+ * </ul>
+ *
+ * @param start the start
+ * @param size the size
+ * @param alignment the alignment
+ * @param flexibility the flexibility
+ */
+ public static Spec spec(int start, int size, Alignment alignment, int flexibility) {
+ return new Spec(start, size, alignment, flexibility);
+ }
+
+ /**
+ * Return a Spec, {@code spec}, where:
+ * <ul>
+ * <li> {@code spec.span = [start, start + 1]} </li>
+ * <li> {@code spec.alignment = alignment} </li>
+ * <li> {@code spec.flexibility = flexibility} </li>
+ * </ul>
+ *
+ * @param start the start
+ * @param alignment the alignment
+ * @param flexibility the flexibility
+ */
+ public static Spec spec(int start, Alignment alignment, int flexibility) {
+ return spec(start, 1, alignment, flexibility);
+ }
+
+ /**
+ * Return a Spec, {@code spec}, where:
+ * <ul>
+ * <li> {@code spec.span = [start, start + size]} </li>
+ * <li> {@code spec.alignment = alignment} </li>
+ * </ul>
+ *
+ * @param start the start
+ * @param size the size
+ * @param alignment the alignment
+ */
+ public static Spec spec(int start, int size, Alignment alignment) {
+ return spec(start, size, alignment, Spec.DEFAULT_FLEXIBILITY);
+ }
+
+ /**
+ * Return a Spec, {@code spec}, where:
+ * <ul>
+ * <li> {@code spec.span = [start, start + 1]} </li>
+ * <li> {@code spec.alignment = alignment} </li>
+ * </ul>
+ *
+ * @param start the start index
+ * @param alignment the alignment
+ */
+ public static Spec spec(int start, Alignment alignment) {
+ return spec(start, 1, alignment);
+ }
+
+ /**
* Alignments specify where a view should be placed within a cell group and
* what size it should be.
* <p>
- * The {@link LayoutParams} class contains a {@link LayoutParams#rowGroup rowGroup}
- * and a {@link LayoutParams#columnGroup columnGroup} each of which contains an
- * {@link Group#alignment alignment}. Overall placement of the view in the cell
+ * The {@link LayoutParams} class contains a {@link LayoutParams#rowSpec rowSpec}
+ * and a {@link LayoutParams#columnSpec columnSpec} each of which contains an
+ * {@code alignment}. Overall placement of the view in the cell
* group is specified by the two alignments which act along each axis independently.
* <p>
* The GridLayout class defines the most common alignments used in general layout:
@@ -2425,8 +2480,8 @@ public class GridLayout extends ViewGroup {
/**
* Indicates that a view should be <em>centered</em> with the other views in its cell group.
- * This constant may be used in both {@link LayoutParams#rowGroup rowGroups} and {@link
- * LayoutParams#columnGroup columnGroups}.
+ * This constant may be used in both {@link LayoutParams#rowSpec rowSpecs} and {@link
+ * LayoutParams#columnSpec columnSpecs}.
*/
public static final Alignment CENTER = new Alignment() {
public int getAlignmentValue(View view, int viewSize) {
@@ -2437,7 +2492,7 @@ public class GridLayout extends ViewGroup {
/**
* Indicates that a view should be aligned with the <em>baselines</em>
* of the other views in its cell group.
- * This constant may only be used as an alignment in {@link LayoutParams#rowGroup rowGroups}.
+ * This constant may only be used as an alignment in {@link LayoutParams#rowSpec rowSpecs}.
*
* @see View#getBaseline()
*/
@@ -2488,8 +2543,8 @@ public class GridLayout extends ViewGroup {
/**
* Indicates that a view should expanded to fit the boundaries of its cell group.
- * This constant may be used in both {@link LayoutParams#rowGroup rowGroups} and
- * {@link LayoutParams#columnGroup columnGroups}.
+ * This constant may be used in both {@link LayoutParams#rowSpec rowSpecs} and
+ * {@link LayoutParams#columnSpec columnSpecs}.
*/
public static final Alignment FILL = new Alignment() {
public int getAlignmentValue(View view, int viewSize) {
@@ -2513,42 +2568,30 @@ public class GridLayout extends ViewGroup {
/**
* Indicates that a view requests precisely the size specified by its layout parameters.
*
- * @see Group#flexibility
- *
- * @hide
+ * @see Spec#flexibility
*/
- public static final int FIXED = 0;
+ private static final int NONE = 0;
/**
* Indicates that a view's size should lie between its minimum and the size specified by
* its layout parameters.
*
- * @see Group#flexibility
- *
- * @hide
+ * @see Spec#flexibility
*/
- public static final int CAN_SHRINK = 1;
+ private static final int CAN_SHRINK = 1;
/**
* Indicates that a view's size should be greater than or equal to the size specified by
* its layout parameters.
*
- * @see Group#flexibility
+ * @see Spec#flexibility
*/
public static final int CAN_STRETCH = 2;
/**
- * Indicates that a view will ignore its measurement, and can take any size that is greater
- * than its minimum.
- *
- * @see Group#flexibility
- */
- private static final int CAN_SHRINK_OR_STRETCH = CAN_SHRINK | CAN_STRETCH;
-
- /**
* A default value for flexibility.
*
- * @see Group#flexibility
+ * @see Spec#flexibility
*/
private static final int UNDEFINED_FLEXIBILITY = UNDEFINED | CAN_SHRINK | CAN_STRETCH;
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 9c2133f..ffd1f28 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3345,7 +3345,7 @@
<!-- The row span: the difference between the bottom and top
boundaries delimiting the group of cells occupied by this view.
The default is one.
- See {@link android.widget.GridLayout.Group}. -->
+ See {@link android.widget.GridLayout.Spec}. -->
<attr name="layout_rowSpan" format="integer" min="1" />
<!-- The column boundary delimiting the left of the group of cells
occupied by this view. -->
@@ -3353,23 +3353,21 @@
<!-- The column span: the difference between the right and left
boundaries delimiting the group of cells occupied by this view.
The default is one.
- See {@link android.widget.GridLayout.Group}. -->
+ See {@link android.widget.GridLayout.Spec}. -->
<attr name="layout_columnSpan" format="integer" min="1" />
<!-- Gravity specifies how a component should be placed in its group of cells.
The default is LEFT | BASELINE.
See {@link android.widget.GridLayout.LayoutParams#setGravity(int)}. -->
<attr name="layout_gravity" />
<!-- A value specifying how much deficit or excess width this component can accomodate.
- The default is FIXED.
- See {@link android.widget.GridLayout.Group#flexibility}.-->
+ The default is FIXED. -->
<attr name="layout_columnFlexibility" >
<!-- If possible, width should be greater than or equal to the specified width.
See {@link android.widget.GridLayout#CAN_STRETCH}. -->
<enum name="canStretch" value="2" />
</attr>
<!-- A value specifying how much deficit or excess height this component can accomodate.
- The default is FIXED.
- See {@link android.widget.GridLayout.Group#flexibility}.-->
+ The default is FIXED. -->
<attr name="layout_rowFlexibility" >
<!-- If possible, height should be greater than or equal to the specified height.
See {@link android.widget.GridLayout#CAN_STRETCH}. -->
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
index b9bf526..af5006f 100644
--- a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
+++ b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
@@ -38,20 +38,20 @@ public class Activity2 extends Activity {
vg.setUseDefaultMargins(true);
vg.setAlignmentMode(ALIGN_BOUNDS);
- Group row1 = new Group(1, CENTER);
- Group row2 = new Group(2, CENTER);
- Group row3 = new Group(3, BASELINE);
- Group row4 = new Group(4, BASELINE);
- Group row5 = new Group(5, FILL);
- Group row6 = new Group(6, CENTER);
- Group row7 = new Group(7, CENTER);
+ Spec row1 = spec(0, CENTER);
+ Spec row2 = spec(1, CENTER);
+ Spec row3 = spec(2, BASELINE);
+ Spec row4 = spec(3, BASELINE);
+ Spec row5 = spec(4, FILL, CAN_STRETCH);
+ Spec row6 = spec(5, CENTER);
+ Spec row7 = spec(6, CENTER);
- Group col1a = new Group(1, 4, CENTER);
- Group col1b = new Group(1, 4, LEFT);
- Group col1c = new Group(1, RIGHT);
- Group col2 = new Group(2, LEFT);
- Group col3 = new Group(3, FILL);
- Group col4 = new Group(4, FILL);
+ Spec col1a = spec(0, 4, CENTER);
+ Spec col1b = spec(0, 4, LEFT);
+ Spec col1c = spec(0, RIGHT);
+ Spec col2 = spec(1, LEFT);
+ Spec col3 = spec(2, FILL, CAN_STRETCH);
+ Spec col4 = spec(3, FILL);
{
TextView v = new TextView(context);
@@ -96,10 +96,7 @@ public class Activity2 extends Activity {
{
Space v = new Space(context);
{
- LayoutParams lp = new LayoutParams(row5, col3);
- lp.columnGroup.flexibility = CAN_STRETCH;
- lp.rowGroup.flexibility = CAN_STRETCH;
- vg.addView(v, lp);
+ vg.addView(v, new LayoutParams(row5, col3));
}
}
{
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java b/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java
index 505c83d..b1c4486 100755
--- a/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java
+++ b/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java
@@ -21,7 +21,6 @@ import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewParent;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridLayout;
@@ -84,9 +83,7 @@ public class AlignmentTest extends Activity {
Alignment va = VERTICAL_ALIGNMENTS[i];
for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) {
Alignment ha = HORIZONTAL_ALIGNMENTS[j];
- Group rowGroup = new Group(i, va);
- Group colGroup = new Group(j, ha);
- LayoutParams layoutParams = new LayoutParams(rowGroup, colGroup);
+ LayoutParams layoutParams = new LayoutParams(spec(i, va), spec(j, ha));
String name = VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j];
ViewFactory factory = FACTORIES[(i + j) % FACTORIES.length];
container.addView(factory.create(name, 20), layoutParams);
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java
index c5681e2..4ce449a 100644
--- a/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java
+++ b/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java
@@ -33,9 +33,9 @@ public class GridLayoutTest extends AbstractLayoutTest {
int va = VERTICAL_ALIGNMENTS[i];
for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) {
int ha = HORIZONTAL_ALIGNMENTS[j];
- GridLayout.Group rowGroup = new GridLayout.Group(UNDEFINED, null);
- GridLayout.Group colGroup = new GridLayout.Group(UNDEFINED, null);
- GridLayout.LayoutParams lp = new GridLayout.LayoutParams(rowGroup, colGroup);
+ Spec rowSpec = spec(UNDEFINED, null);
+ Spec colSpec = spec(UNDEFINED, null);
+ GridLayout.LayoutParams lp = new GridLayout.LayoutParams(rowSpec, colSpec);
//GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
lp.setGravity(va | ha);
View v = create(context, VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20);