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

Commit 368c0f90 authored by Philip Milne's avatar Philip Milne Committed by Android (Google) Code Review
Browse files

Merge "Handle baseline aligned rows in which some components define baseline and some don't."

parents 8457f0fe a1f7b10f
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -24878,9 +24878,6 @@ package android.widget {
  }
  public static abstract class GridLayout.Alignment {
    ctor public GridLayout.Alignment();
    method public abstract int getAlignmentValue(android.view.View, int, int);
    method public int getSizeInCell(android.view.View, int, int, int);
  }
  public static class GridLayout.Group {
+63 −18
Original line number Diff line number Diff line
@@ -925,8 +925,8 @@ public class GridLayout extends ViewGroup {
                int mHeight = topMargin + pHeight + bottomMargin;

                // Alignment offsets: the location of the view relative to its alignment group.
                int a2vx = colBounds.before - hAlign.getAlignmentValue(c, mWidth, type);
                int a2vy = rowBounds.before - vAlign.getAlignmentValue(c, mHeight, type);
                int a2vx = colBounds.getOffset(c, hAlign, type, mWidth);
                int a2vy = rowBounds.getOffset(c, vAlign, type, mHeight);

                dx = c2ax + a2vx + leftMargin;
                dy = c2ay + a2vy + topMargin;
@@ -935,8 +935,8 @@ public class GridLayout extends ViewGroup {
                cellHeight -= topMargin + bottomMargin;
            } else {
                // Alignment offsets: the location of the view relative to its alignment group.
                int a2vx = colBounds.before - hAlign.getAlignmentValue(c, pWidth, type);
                int a2vy = rowBounds.before - vAlign.getAlignmentValue(c, pHeight, type);
                int a2vx = colBounds.getOffset(c, hAlign, type, pWidth);
                int a2vy = rowBounds.getOffset(c, vAlign, type, pHeight);

                dx = c2ax + a2vx;
                dy = c2ay + a2vy;
@@ -1048,7 +1048,7 @@ public class GridLayout extends ViewGroup {
                Group group = horizontal ? lp.columnGroup : lp.rowGroup;

                groups[i] = group;
                bounds[i] = new Bounds();
                bounds[i] = group.alignment.getBounds();
            }

            return new PackedMap<Group, Bounds>(groups, bounds);
@@ -1994,20 +1994,24 @@ public class GridLayout extends ViewGroup {
            reset();
        }

        private void reset() {
        protected void reset() {
            before = Integer.MIN_VALUE;
            after = Integer.MIN_VALUE;
        }

        private void include(int before, int after) {
        protected void include(int before, int after) {
            this.before = max(this.before, before);
            this.after = max(this.after, after);
        }

        private int size() {
        protected int size() {
            return before + after;
        }

        protected int getOffset(View c, Alignment alignment, int type, int size) {
            return before - alignment.getAlignmentValue(c, size, type);
        }

        @Override
        public String toString() {
            return "Bounds{" +
@@ -2233,15 +2237,18 @@ public class GridLayout extends ViewGroup {
     * {@link Group#alignment 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:
     * {@link #TOP}, {@link #LEFT}, {@link #BOTTOM}, {@link #RIGHT}, {@link #CENTER}, {@link
     * #BASELINE} and {@link #FILL}.
     */
    /*
     * An Alignment implementation must define {@link #getAlignmentValue(View, int, int)},
     * to return the appropriate value for the type of alignment being defined.
     * The enclosing algorithms position the children
     * so that the locations defined by the alignment values
     * are the same for all of the views in a group.
     * <p>
     *  The GridLayout class defines the most common alignments used in general layout:
     * {@link #TOP}, {@link #LEFT}, {@link #BOTTOM}, {@link #RIGHT}, {@link #CENTER}, {@link
     * #BASELINE} and {@link #FILL}.

     */
    public static abstract class Alignment {
        private static final Alignment GONE = new Alignment() {
@@ -2251,6 +2258,9 @@ public class GridLayout extends ViewGroup {
            }
        };

        /*pp*/ Alignment() {
        }

        /**
         * Returns an alignment value. In the case of vertical alignments the value
         * returned should indicate the distance from the top of the view to the
@@ -2264,7 +2274,7 @@ public class GridLayout extends ViewGroup {
         *
         * @return the alignment value
         */
        public abstract int getAlignmentValue(View view, int viewSize, int measurementType);
        /*pp*/ abstract int getAlignmentValue(View view, int viewSize, int measurementType);

        /**
         * Returns the size of the view specified by this alignment.
@@ -2281,9 +2291,13 @@ public class GridLayout extends ViewGroup {
         *
         * @return the aligned size
         */
        public int getSizeInCell(View view, int viewSize, int cellSize, int measurementType) {
        /*pp*/ int getSizeInCell(View view, int viewSize, int cellSize, int measurementType) {
            return viewSize;
        }

        /*pp*/ Bounds getBounds() {
            return new Bounds();
        }
    }

    private static final Alignment LEADING = new Alignment() {
@@ -2347,11 +2361,42 @@ public class GridLayout extends ViewGroup {
                return UNDEFINED;
            }
            int baseline = view.getBaseline();
            if (baseline == -1) {
                return UNDEFINED;
            } else {
                return baseline;
            return (baseline == -1) ? UNDEFINED : baseline;
        }

        @Override
        public Bounds getBounds() {
            return new Bounds() {
                /*
                In a baseline aligned row in which some components define a baseline
                and some don't, we need a third variable to properly account for all
                the sizes. This tracks the maximum size of all the components -
                including those that don't define a baseline.
                */
                private int size;

                @Override
                protected void reset() {
                    super.reset();
                    size = 0;
                }

                @Override
                protected void include(int before, int after) {
                    super.include(before, after);
                    size = max(size, before + after);
                }

                @Override
                protected int size() {
                    return max(super.size(), size);
                }

                @Override
                protected int getOffset(View c, Alignment alignment, int type, int size) {
                    return max(0, super.getOffset(c, alignment, type, size));
                }
            };
        }
    };

+19 −49
Original line number Diff line number Diff line
@@ -15,56 +15,26 @@

<GridLayout
        xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dip" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="5dip"
            android:text="flabe" />

        <Button android:id="@+id/initialActivity"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="bax" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dip" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="5dip"
            android:text="bar" />

        <EditText android:id="@+id/numberOfEvents"
            android:layout_marginLeft="2dip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background"
            android:numeric="integer"
            android:scrollHorizontally="true"
            android:maxLines="1" />
    </LinearLayout>

    <Button android:id="@+id/start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="10dip"
        android:text="Foo" />
    android:columnCount="2"
    <Space
            android:layout_row="0"
            android:layout_column="0"
            android:layout_width="109dip"
            android:layout_height="108dip"/>

    <Button
            android:text="Button 1"
            android:layout_row="0"
            android:layout_column="1"
            />

    <Button
            android:text="Button 2"
            android:layout_row="1"
            android:layout_column="1"
            />

</GridLayout>