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

Commit a1f7b10f authored by Philip Milne's avatar Philip Milne
Browse files

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

Also:

. Make all of the methods in Alignment package private.
. Inlucde Tor's test case

Change-Id: If78a6a3b653723d9e12d6b162fd0c86b11a82dff
parent 0ff6d7ee
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -24878,9 +24878,6 @@ package android.widget {
  }
  }
  public static abstract class GridLayout.Alignment {
  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 {
  public static class GridLayout.Group {
+63 −18
Original line number Original line Diff line number Diff line
@@ -925,8 +925,8 @@ public class GridLayout extends ViewGroup {
                int mHeight = topMargin + pHeight + bottomMargin;
                int mHeight = topMargin + pHeight + bottomMargin;


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


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


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


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


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


        private void reset() {
        protected void reset() {
            before = Integer.MIN_VALUE;
            before = Integer.MIN_VALUE;
            after = 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.before = max(this.before, before);
            this.after = max(this.after, after);
            this.after = max(this.after, after);
        }
        }


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


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

        @Override
        @Override
        public String toString() {
        public String toString() {
            return "Bounds{" +
            return "Bounds{" +
@@ -2233,15 +2237,18 @@ public class GridLayout extends ViewGroup {
     * {@link Group#alignment alignment}. Overall placement of the view in the cell
     * {@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.
     * group is specified by the two alignments which act along each axis independently.
     * <p>
     * <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)},
     * An Alignment implementation must define {@link #getAlignmentValue(View, int, int)},
     * to return the appropriate value for the type of alignment being defined.
     * to return the appropriate value for the type of alignment being defined.
     * The enclosing algorithms position the children
     * The enclosing algorithms position the children
     * so that the locations defined by the alignment values
     * so that the locations defined by the alignment values
     * are the same for all of the views in a group.
     * are the same for all of the views in a group.
     * <p>
     * <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 {
    public static abstract class Alignment {
        private static final Alignment GONE = new 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
         * 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
         * 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
         * @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.
         * Returns the size of the view specified by this alignment.
@@ -2281,9 +2291,13 @@ public class GridLayout extends ViewGroup {
         *
         *
         * @return the aligned size
         * @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;
            return viewSize;
        }
        }

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


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

                return 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 Original line Diff line number Diff line
@@ -15,56 +15,26 @@


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

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

    android:columnCount="2"
    <LinearLayout
    <Space
        android:orientation="horizontal"
            android:layout_row="0"
        android:layout_width="match_parent"
            android:layout_column="0"
        android:layout_height="wrap_content"
            android:layout_width="109dip"
        android:paddingTop="10dip" >
            android:layout_height="108dip"/>


        <TextView
    <Button
            android:layout_width="wrap_content"
            android:text="Button 1"
            android:layout_height="wrap_content"
            android:layout_row="0"
            android:paddingRight="5dip"
            android:layout_column="1"
            android:text="flabe" />
            />


        <Button android:id="@+id/initialActivity"
    <Button
            android:layout_width="match_parent"
            android:text="Button 2"
            android:layout_height="wrap_content"
            android:layout_row="1"
            android:text="bax" />
            android:layout_column="1"
    </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" />


</GridLayout>
</GridLayout>