Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d1a9840 authored by Philip Milne's avatar Philip Milne
Browse files

Simplify and tidy the API for maximum value support.

Also:

. Remove CAN_SHRINK, FIXED from public view. These can be added later.

Change-Id: I63a64ac4748605da60373c8e3c2109178b5260c2
parent b75a7984
Loading
Loading
Loading
Loading
+5 −12
Original line number Diff line number Diff line
@@ -598,10 +598,10 @@ package android {
    field public static final int layout_centerInParent = 16843151; // 0x101018f
    field public static final int layout_centerVertical = 16843153; // 0x1010191
    field public static final int layout_column = 16843084; // 0x101014c
    field public static final int layout_columnSpan = 16843644; // 0x101037c
    field public static final int layout_columnFlexibility = 16843646; // 0x101037e
    field public static final int layout_columnSpan = 16843645; // 0x101037d
    field public static final int layout_gravity = 16842931; // 0x10100b3
    field public static final int layout_height = 16842997; // 0x10100f5
    field public static final int layout_heightSpec = 16843646; // 0x101037e
    field public static final int layout_margin = 16842998; // 0x10100f6
    field public static final int layout_marginBottom = 16843002; // 0x10100fa
    field public static final int layout_marginEnd = 16843674; // 0x101039a
@@ -610,6 +610,7 @@ package android {
    field public static final int layout_marginStart = 16843673; // 0x1010399
    field public static final int layout_marginTop = 16843000; // 0x10100f8
    field public static final int layout_row = 16843642; // 0x101037a
    field public static final int layout_rowFlexibility = 16843644; // 0x101037c
    field public static final int layout_rowSpan = 16843643; // 0x101037b
    field public static final int layout_scale = 16843155; // 0x1010193
    field public static final int layout_span = 16843085; // 0x101014d
@@ -617,7 +618,6 @@ package android {
    field public static final int layout_toRightOf = 16843139; // 0x1010183
    field public static final int layout_weight = 16843137; // 0x1010181
    field public static final int layout_width = 16842996; // 0x10100f4
    field public static final int layout_widthSpec = 16843645; // 0x101037d
    field public static final int layout_x = 16843135; // 0x101017f
    field public static final int layout_y = 16843136; // 0x1010180
    field public static final int left = 16843181; // 0x10101ad
@@ -24953,11 +24953,9 @@ package android.widget {
    field public static final int ALIGN_MARGINS = 1; // 0x1
    field public static final android.widget.GridLayout.Alignment BASELINE;
    field public static final android.widget.GridLayout.Alignment BOTTOM;
    field public static final android.widget.GridLayout.Spec CAN_SHRINK;
    field public static final android.widget.GridLayout.Spec CAN_STRETCH;
    field public static final int CAN_STRETCH = 2; // 0x2
    field public static final android.widget.GridLayout.Alignment CENTER;
    field public static final android.widget.GridLayout.Alignment FILL;
    field public static final android.widget.GridLayout.Spec FIXED;
    field public static final int HORIZONTAL = 0; // 0x0
    field public static final android.widget.GridLayout.Alignment LEFT;
    field public static final android.widget.GridLayout.Alignment RIGHT;
@@ -24973,6 +24971,7 @@ package android.widget {
    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 {
@@ -24984,13 +24983,7 @@ package android.widget {
    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.Spec heightSpec;
    field public android.widget.GridLayout.Group rowGroup;
    field public android.widget.GridLayout.Spec widthSpec;
  }
  public static abstract class GridLayout.Spec {
    ctor public GridLayout.Spec();
  }
  public class GridView extends android.widget.AbsListView {
+104 −78
Original line number Diff line number Diff line
@@ -92,10 +92,8 @@ import static java.lang.Math.min;
 *
 * <h4>Excess Space Distribution</h4>
 *
 * Like {@link LinearLayout}, a child's ability to stretch is controlled
 * using <em>weights</em>, which are specified using the
 * {@link GridLayout.LayoutParams#widthSpec widthSpec} and
 * {@link GridLayout.LayoutParams#heightSpec heightSpec} layout parameters.
 * A child's ability to stretch is controlled using the {@link Group#flexibility flexibility}
 * properties of its row and column groups.
 * <p>
 * <p>
 * See {@link GridLayout.LayoutParams} for a full description of the
@@ -1055,7 +1053,7 @@ public class GridLayout extends ViewGroup {
                if (isGone(c)) continue;
                LayoutParams lp = getLayoutParams(c);
                Group g = horizontal ? lp.columnGroup : lp.rowGroup;
                groupBounds.getValue(i).include(c, g, GridLayout.this, this, lp);
                groupBounds.getValue(i).include(c, g, GridLayout.this, this);
            }
        }

@@ -1087,13 +1085,17 @@ public class GridLayout extends ViewGroup {
                spans[i].reset();
            }

            // use getter to trigger a re-evaluation
            // Use getter to trigger a re-evaluation
            Bounds[] bounds = getGroupBounds().values;
            for (int i = 0; i < bounds.length; i++) {
                int size = bounds[i].size(min);
                int value = min ? size : -size;
                MutableInt valueHolder = links.getValue(i);
                valueHolder.value = max(valueHolder.value, value);
                if (min) {
                    valueHolder.value = max(valueHolder.value, size);
                }
                else {
                    valueHolder.value = -max(-valueHolder.value, size);
                }
            }
        }

@@ -1622,16 +1624,14 @@ public class GridLayout extends ViewGroup {
     *     <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 #widthSpec} = {@link #FIXED} </li>
     *     <li>{@link #heightSpec} = {@link #FIXED} </li>
     * </ul>
     *
     * @attr ref android.R.styleable#GridLayout_Layout_layout_row
     * @attr ref android.R.styleable#GridLayout_Layout_layout_rowSpan
     * @attr ref android.R.styleable#GridLayout_Layout_layout_heightSpec
     * @attr ref android.R.styleable#GridLayout_Layout_layout_rowFlexibility
     * @attr ref android.R.styleable#GridLayout_Layout_layout_column
     * @attr ref android.R.styleable#GridLayout_Layout_layout_columnSpan
     * @attr ref android.R.styleable#GridLayout_Layout_layout_widthSpec
     * @attr ref android.R.styleable#GridLayout_Layout_layout_columnFlexibility
     * @attr ref android.R.styleable#GridLayout_Layout_layout_gravity
     */
    public static class LayoutParams extends MarginLayoutParams {
@@ -1647,19 +1647,12 @@ public class GridLayout extends ViewGroup {
        private static final int DEFAULT_SPAN_SIZE = DEFAULT_SPAN.size();
        private static final Alignment DEFAULT_COLUMN_ALIGNMENT = LEFT;
        private static final Alignment DEFAULT_ROW_ALIGNMENT = BASELINE;
        private static final Group DEFAULT_COLUMN_GROUP =
                new Group(DEFAULT_SPAN, DEFAULT_COLUMN_ALIGNMENT);
        private static final Group DEFAULT_ROW_GROUP =
                new Group(DEFAULT_SPAN, DEFAULT_ROW_ALIGNMENT);
        private static final Spec DEFAULT_SPEC = FIXED;
        private static final int DEFAULT_SPEC_INDEX = 0;

        // Misc

        private static final Rect CONTAINER_BOUNDS = new Rect(0, 0, 2, 2);
        private static final Alignment[] COLUMN_ALIGNMENTS = { LEFT, CENTER, RIGHT };
        private static final Alignment[] ROW_ALIGNMENTS = { TOP, CENTER, BOTTOM };
        private static final Spec[] SPECS = { FIXED, CAN_SHRINK, CAN_STRETCH };

        // TypedArray indices

@@ -1672,10 +1665,14 @@ public class GridLayout extends ViewGroup {

        private static final int COLUMN = styleable.GridLayout_Layout_layout_column;
        private static final int COLUMN_SPAN = styleable.GridLayout_Layout_layout_columnSpan;
        private static final int WIDTH_SPEC = styleable.GridLayout_Layout_layout_widthSpec;
        private static final int COLUMN_FLEXIBILITY =
                styleable.GridLayout_Layout_layout_columnFlexibility;

        private static final int ROW = styleable.GridLayout_Layout_layout_row;
        private static final int ROW_SPAN = styleable.GridLayout_Layout_layout_rowSpan;
        private static final int HEIGHT_SPEC = styleable.GridLayout_Layout_layout_heightSpec;
        private static final int ROW_FLEXIBILITY =
                styleable.GridLayout_Layout_layout_rowFlexibility;

        private static final int GRAVITY = styleable.GridLayout_Layout_layout_gravity;

        // Instance variables
@@ -1690,30 +1687,17 @@ public class GridLayout extends ViewGroup {
         * described by these layout parameters.
         */
        public Group columnGroup;
        /**
         * The proportional space that should be taken by the associated column group
         * during excess space distribution.
         */
        public Spec widthSpec;
        /**
         * The proportional space that should be taken by the associated row group
         * during excess space distribution.
         */
        public Spec heightSpec;

        // Constructors

        private LayoutParams(
                int width, int height,
                int left, int top, int right, int bottom,
                Group rowGroup, Group columnGroup,
                Spec widthSpec, Spec heightSpec) {
                Group rowGroup, Group columnGroup) {
            super(width, height);
            setMargins(left, top, right, bottom);
            this.rowGroup = rowGroup;
            this.columnGroup = columnGroup;
            this.heightSpec = heightSpec;
            this.widthSpec = widthSpec;
        }

        /**
@@ -1727,14 +1711,15 @@ public class GridLayout extends ViewGroup {
        public LayoutParams(Group rowGroup, Group columnGroup) {
            this(DEFAULT_WIDTH, DEFAULT_HEIGHT,
                    DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN, DEFAULT_MARGIN,
                    rowGroup, columnGroup, DEFAULT_SPEC, DEFAULT_SPEC);
                    rowGroup, columnGroup);
        }

        /**
         * Constructs a new LayoutParams with default values as defined in {@link LayoutParams}.
         */
        public LayoutParams() {
            this(DEFAULT_ROW_GROUP, DEFAULT_COLUMN_GROUP);
            this(new Group(DEFAULT_SPAN, DEFAULT_ROW_ALIGNMENT),
                 new Group(DEFAULT_SPAN, DEFAULT_COLUMN_ALIGNMENT));
        }

        // Copying constructors
@@ -1758,10 +1743,8 @@ public class GridLayout extends ViewGroup {
         */
        public LayoutParams(LayoutParams that) {
            super(that);
            this.columnGroup = that.columnGroup;
            this.rowGroup = that.rowGroup;
            this.widthSpec = that.widthSpec;
            this.heightSpec = that.heightSpec;
            this.columnGroup = new Group(that.columnGroup);
            this.rowGroup = new Group(that.rowGroup);
        }

        // AttributeSet constructors
@@ -1825,7 +1808,7 @@ public class GridLayout extends ViewGroup {

        // Gravity. For conversion from the static the integers defined in the Gravity class,
        // use Gravity.apply() to apply gravity to a view of zero size and see where it ends up.
        private static Alignment getColumnAlignment(int gravity, int width) {
        private static Alignment getColAlignment(int gravity, int width) {
            Rect r = new Rect(0, 0, 0, 0);
            Gravity.apply(gravity, 0, 0, CONTAINER_BOUNDS, r);

@@ -1853,14 +1836,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);
                this.columnGroup = new Group(hSpan, getColumnAlignment(gravity, width));
                this.widthSpec = SPECS[a.getInt(WIDTH_SPEC, DEFAULT_SPEC_INDEX)];
                int hFlexibility = a.getInt(COLUMN_FLEXIBILITY, Group.DEFAULT_FLEXIBILITY);
                this.columnGroup = new Group(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);
                this.rowGroup = new Group(vSpan, getRowAlignment(gravity, height));
                this.heightSpec = SPECS[a.getInt(HEIGHT_SPEC, DEFAULT_SPEC_INDEX)];
                int vFlexibility = a.getInt(ROW_FLEXIBILITY, Group.DEFAULT_FLEXIBILITY);
                this.rowGroup = new Group(vSpan, getRowAlignment(gravity, height), vFlexibility);
            } finally {
                a.recycle();
            }
@@ -1875,7 +1858,7 @@ public class GridLayout extends ViewGroup {
         * @attr ref android.R.styleable#GridLayout_Layout_layout_gravity
         */
        public void setGravity(int gravity) {
            columnGroup = columnGroup.copyWriteAlignment(getColumnAlignment(gravity, width));
            columnGroup = columnGroup.copyWriteAlignment(getColAlignment(gravity, width));
            rowGroup = rowGroup.copyWriteAlignment(getRowAlignment(gravity, height));
        }

@@ -2051,7 +2034,7 @@ public class GridLayout extends ViewGroup {

        public int before;
        public int after;
        public boolean canStretch;
        public int flexibility;

        private Bounds() {
            reset();
@@ -2060,7 +2043,7 @@ public class GridLayout extends ViewGroup {
        protected void reset() {
            before = Integer.MIN_VALUE;
            after = Integer.MIN_VALUE;
            canStretch = false;
            flexibility = UNDEFINED_FLEXIBILITY;
        }

        protected void include(int before, int after) {
@@ -2069,9 +2052,14 @@ public class GridLayout extends ViewGroup {
        }

        protected int size(boolean min) {
            if (!min && canStretch) {
            if (!min) {
                // Note in the usual case, components don't define anything
                // leaving their flexibility is undefined and their stretchability
                // defined as if the CAN_STRETCH flag was false.
                if (canStretch(flexibility) && !isUndefined(flexibility)) {
                    return MAX_SIZE;
                }
            }
            return before + after;
        }

@@ -2079,14 +2067,11 @@ public class GridLayout extends ViewGroup {
            return before - alignment.getAlignmentValue(c, size);
        }

        protected void include(View c, Group g, GridLayout gridLayout, Axis axis, LayoutParams lp) {
            Spec spec = axis.horizontal ? lp.widthSpec : lp.heightSpec;
            if (spec == CAN_STRETCH) {
                canStretch = true;
            }
        protected void include(View c, Group group, GridLayout gridLayout, Axis axis) {
            this.flexibility &= group.flexibility;
            int size = gridLayout.getMeasurementIncludingMargin(c, axis.horizontal);
            // todo test this works correctly when the returned value is UNDEFINED
            int before = g.alignment.getAlignmentValue(c, size);
            int before = group.alignment.getAlignmentValue(c, size);
            include(before, size - before);
        }

@@ -2198,6 +2183,8 @@ public class GridLayout extends ViewGroup {
     * {@code span} and {@code alignment}.
     */
    public static class Group {
        private static final int DEFAULT_FLEXIBILITY = UNDEFINED_FLEXIBILITY;

        private static final Group GONE = new Group(Interval.GONE, Alignment.GONE);

        /**
@@ -2215,6 +2202,18 @@ public class GridLayout extends ViewGroup {
         */
        public final Alignment alignment;

        /**
         * The flexibility field tells GridLayout how to derive minimum and maximum size
         * values for a component. Specifications are made with respect to a child's
         * 'measured size'. A child's measured size is, in turn, controlled by its
         * height and width layout parameters which either specify a size or, in
         * the case of {@link LayoutParams#WRAP_CONTENT WRAP_CONTENT}, defer to
         * the computed size of the component.
         *
         * @see GridLayout#CAN_STRETCH
         */
         public int flexibility = DEFAULT_FLEXIBILITY;

        /**
         * Construct a new Group, {@code group}, where:
         * <ul>
@@ -2225,9 +2224,22 @@ public class GridLayout extends ViewGroup {
         * @param span      the span
         * @param alignment the alignment
         */
        Group(Interval span, Alignment alignment) {
        private Group(Interval span, Alignment alignment) {
            this.span = span;
            this.alignment = alignment;
        }

        private Group(Interval span, Alignment alignment, int flexibility) {
            this.span = span;
            this.alignment = alignment;
            this.flexibility = flexibility;
        }

        /* Copying constructor */
        private Group(Group that) {
            this.span = that.span;
            this.alignment = that.alignment;
            this.flexibility = that.flexibility;
        }

        /**
@@ -2260,11 +2272,11 @@ public class GridLayout extends ViewGroup {
        }

        private Group copyWriteSpan(Interval span) {
            return new Group(span, alignment);
            return new Group(span, alignment, flexibility);
        }

        private Group copyWriteAlignment(Alignment alignment) {
            return new Group(span, alignment);
            return new Group(span, alignment, flexibility);
        }

        /**
@@ -2490,40 +2502,54 @@ public class GridLayout extends ViewGroup {
        }
    };

    /**
     * Spec's tell GridLayout how to derive minimum and maximum size values for a
     * component. Specifications are made with respect to a child's 'measured size'.
     * A child's measured size is, in turn, controlled by its height and width
     * layout parameters which either specify a size or, in the case of
     * WRAP_CONTENT, defer to the computed size of the component.
     */
    public static abstract class Spec {
    private static boolean canStretch(int flexibility) {
        return (flexibility & CAN_STRETCH) != 0;
    }

    private static boolean isUndefined(int flexibility) {
        return (flexibility & UNDEFINED) != 0;
    }

    /**
     * Indicates that a view requests precisely the size specified by its layout parameters.
     *
     * @see Spec
     * @see Group#flexibility
     *
     * @hide
     */
    public static final Spec FIXED = new Spec() {
    };
    public static final int FIXED = 0;

    /**
     * Indicates that a view's size should lie between its minimum and the size specified by
     * its layout parameters.
     *
     * @see Spec
     * @see Group#flexibility
     *
     * @hide
     */
    public static final Spec CAN_SHRINK = new Spec() {
    };
    public 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 Spec
     * @see Group#flexibility
     */
    public static final Spec CAN_STRETCH = new Spec() {
    };
    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
     */
    private static final int UNDEFINED_FLEXIBILITY = UNDEFINED | CAN_SHRINK | CAN_STRETCH;

}
+8 −9
Original line number Diff line number Diff line
@@ -24,15 +24,13 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:rowCount="11"
    android:rowCount="10"
    android:id="@+id/root"
    android:clipChildren="false">

    <!-- Column 0 -->
    <Space android:height="20dip"/>

    <com.android.internal.widget.DigitalClock android:id="@+id/time"
        android:layout_marginTop="16dip"
        android:layout_marginTop="8dip"
        android:layout_marginBottom="8dip"
        android:layout_gravity="right">

@@ -120,7 +118,10 @@
        android:layout_gravity="right"
        />

    <Space android:height="20dip"/>
    <Space
        android:layout_rowFlexibility="canStretch"
        android:layout_columnFlexibility="canStretch"
        />

    <TextView
        android:id="@+id/carrier"
@@ -156,15 +157,13 @@
    />

    <!-- Column 1 -->
    <Space android:layout_widthSpec="canStretch" android:layout_rowSpan="11" />
    <Space android:layout_width="32dip" android:layout_rowSpan="10" />

    <!-- Column 2 - password entry field and PIN keyboard -->
    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center|fill"
        android:layout_rowSpan="11">
        android:layout_rowSpan="10">

        <EditText android:id="@+id/passwordEntry"
            android:layout_height="wrap_content"
+9 −11
Original line number Diff line number Diff line
@@ -24,15 +24,13 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:rowCount="10"
    android:rowCount="8"
    android:id="@+id/root"
    android:clipChildren="false">

    <!-- Column 0 -->
    <Space android:height="20dip"/>

    <com.android.internal.widget.DigitalClock android:id="@+id/time"
        android:layout_marginTop="16dip"
        android:layout_marginTop="8dip"
        android:layout_marginBottom="8dip"
        android:layout_gravity="right">

@@ -120,7 +118,10 @@
        android:layout_gravity="right"
        />

    <Space android:height="20dip"/>
    <Space
        android:layout_rowFlexibility="canStretch"
        android:layout_columnFlexibility="canStretch"
        />

    <LinearLayout android:orientation="vertical"
        android:layout_gravity="right"
@@ -169,17 +170,14 @@
    </LinearLayout>

    <!-- Column 1 -->
    <Space
        android:width="20dip"
        android:layout_heightSpec="canStretch"
        android:layout_rowSpan="10" />
    <Space android:layout_width="32dip" android:layout_rowSpan="8" />

    <!-- Column 2 -->
    <com.android.internal.widget.multiwaveview.MultiWaveView
        android:id="@+id/unlock_widget"
        android:layout_width="300dip"
        android:layout_width="200dip"
        android:layout_height="match_parent"
        android:layout_rowSpan="10"
        android:layout_rowSpan="8"

        android:targetDrawables="@array/lockscreen_targets_when_silent"
        android:handleDrawable="@drawable/ic_lockscreen_handle"
+2 −14
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@

    <!-- Column 0: Time, date and status -->
    <com.android.internal.widget.DigitalClock android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dip"
        android:layout_marginBottom="12dip"
        android:layout_gravity="right">
@@ -66,8 +64,6 @@

    <TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textAppearance="?android:attr/textAppearanceMedium"
@@ -77,8 +73,6 @@

    <TextView
        android:id="@+id/alarm_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textAppearance="?android:attr/textAppearanceMedium"
@@ -89,8 +83,6 @@

    <TextView
        android:id="@+id/status1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textAppearance="?android:attr/textAppearanceMedium"
@@ -100,10 +92,8 @@

    <!-- TODO: remove hard coded height since layout_rowWeight doesn't seem to be working -->
    <Space
        android:layout_height="43dip"
        android:layout_gravity="fill"
        android:layout_heightSpec="canStretch"
        android:layout_widthSpec="canStretch"
        android:layout_rowFlexibility="canStretch"
        android:layout_columnFlexibility="canStretch"
        />

    <TextView android:id="@+id/carrier"
@@ -117,8 +107,6 @@
    <LinearLayout
        style="?android:attr/buttonBarStyle"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right">

        <Button android:id="@+id/emergencyCallButton"
Loading