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

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

Merge "Change includeMarginsInAlignment flag to aligmentMode property."

parents 59dab49c 1e548251
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -218,6 +218,7 @@ package android {
    field public static final int alertDialogIcon = 16843605; // 0x1010355
    field public static final int alertDialogStyle = 16842845; // 0x101005d
    field public static final int alertDialogTheme = 16843529; // 0x1010309
    field public static final int alignmentMode = 16843642; // 0x101037a
    field public static final int allContactsName = 16843468; // 0x10102cc
    field public static final int allowBackup = 16843392; // 0x1010280
    field public static final int allowClearUserData = 16842757; // 0x1010005
@@ -636,7 +637,6 @@ package android {
    field public static final int loopViews = 16843527; // 0x1010307
    field public static final int manageSpaceActivity = 16842756; // 0x1010004
    field public static final int mapViewStyle = 16842890; // 0x101008a
    field public static final int marginsIncludedInAlignment = 16843642; // 0x101037a
    field public static final int marqueeRepeatLimit = 16843293; // 0x101021d
    field public static final int max = 16843062; // 0x1010136
    field public static final int maxDate = 16843584; // 0x1010340
@@ -24777,21 +24777,23 @@ package android.widget {
    ctor public GridLayout(android.content.Context);
    ctor public GridLayout(android.content.Context, android.util.AttributeSet, int);
    ctor public GridLayout(android.content.Context, android.util.AttributeSet);
    method public int getAlignmentMode();
    method public int getColumnCount();
    method public boolean getMarginsIncludedInAlignment();
    method public int getOrientation();
    method public int getRowCount();
    method public boolean getUseDefaultMargins();
    method public boolean isColumnOrderPreserved();
    method public boolean isRowOrderPreserved();
    method protected void onLayout(boolean, int, int, int, int);
    method public void setAlignmentMode(int);
    method public void setColumnCount(int);
    method public void setColumnOrderPreserved(boolean);
    method public void setMarginsIncludedInAlignment(boolean);
    method public void setOrientation(int);
    method public void setRowCount(int);
    method public void setRowOrderPreserved(boolean);
    method public void setUseDefaultMargins(boolean);
    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;
    field public static final android.widget.GridLayout.Alignment BOTTOM;
    field public static final android.widget.GridLayout.Alignment CENTER;
+78 −40
Original line number Diff line number Diff line
@@ -135,11 +135,44 @@ public class GridLayout extends ViewGroup {
     */
    public static final int UNDEFINED = Integer.MIN_VALUE;

    /**
     * This constant is an {@link #setAlignmentMode(int) alignmentMode}.
     * When the {@code alignmentMode} is set to {@link #ALIGN_BOUNDS}, alignment
     * is made between the edges of each component's raw
     * view boundary: i.e. the area delimited by the component's:
     * {@link android.view.View#getTop() top},
     * {@link android.view.View#getLeft() left},
     * {@link android.view.View#getBottom() bottom} and
     * {@link android.view.View#getRight() right} properties.
     * <p>
     * For example, when {@code GridLayout} is in {@link #ALIGN_BOUNDS} mode,
     * children that belong to a row group that uses {@link #TOP} alignment will
     * all return the same value when their {@link android.view.View#getTop()}
     * method is called.
     *
     * @see #setAlignmentMode(int)
     */
    public static final int ALIGN_BOUNDS = 0;

    /**
     * This constant is an {@link #setAlignmentMode(int) alignmentMode}.
     * When the {@code alignmentMode} is set to {@link #ALIGN_MARGINS},
     * the bounds of each view are extended outwards, according
     * to their margins, before the edges of the resulting rectangle are aligned.
     * <p>
     * For example, when {@code GridLayout} is in {@link #ALIGN_MARGINS} mode,
     * the quantity {@code top - layoutParams.topMargin} is the same for all children that
     * belong to a row group that uses {@link #TOP} alignment.
     *
     * @see #setAlignmentMode(int)
     */
    public static final int ALIGN_MARGINS = 1;

    // Misc constants

    private static final String TAG = GridLayout.class.getName();
    private static final boolean DEBUG = false;
    private static final Paint GRID_PAINT = new Paint();
    private static Paint GRID_PAINT;
    private static final double GOLDEN_RATIO = (1 + Math.sqrt(5)) / 2;
    private static final int MIN = 0;
    private static final int PRF = 1;
@@ -151,7 +184,7 @@ public class GridLayout extends ViewGroup {
    private static final int DEFAULT_COUNT = UNDEFINED;
    private static final boolean DEFAULT_USE_DEFAULT_MARGINS = false;
    private static final boolean DEFAULT_ORDER_PRESERVED = false;
    private static final boolean DEFAULT_MARGINS_INCLUDED = true;
    private static final int DEFAULT_ALIGNMENT_MODE = ALIGN_MARGINS;
    // todo remove this
    private static final int DEFAULT_CONTAINER_MARGIN = 20;

@@ -161,15 +194,18 @@ public class GridLayout extends ViewGroup {
    private static final int ROW_COUNT = styleable.GridLayout_rowCount;
    private static final int COLUMN_COUNT = styleable.GridLayout_columnCount;
    private static final int USE_DEFAULT_MARGINS = styleable.GridLayout_useDefaultMargins;
    private static final int MARGINS_INCLUDED = styleable.GridLayout_marginsIncludedInAlignment;
    private static final int ALIGNMENT_MODE = styleable.GridLayout_alignmentMode;
    private static final int ROW_ORDER_PRESERVED = styleable.GridLayout_rowOrderPreserved;
    private static final int COLUMN_ORDER_PRESERVED = styleable.GridLayout_columnOrderPreserved;

    // Static initialization

    static {
        if (DEBUG) {
            GRID_PAINT = new Paint();
            GRID_PAINT.setColor(Color.argb(50, 255, 255, 255));
        }
    }

    // Instance variables

@@ -178,7 +214,7 @@ public class GridLayout extends ViewGroup {
    private boolean mLayoutParamsValid = false;
    private int mOrientation = DEFAULT_ORIENTATION;
    private boolean mUseDefaultMargins = DEFAULT_USE_DEFAULT_MARGINS;
    private boolean mMarginsIncludedInAlignment = DEFAULT_MARGINS_INCLUDED;
    private int mAlignmentMode = DEFAULT_ALIGNMENT_MODE;
    private int mDefaultGravity = Gravity.NO_GRAVITY;

    /* package */ boolean accommodateBothMinAndMax = false;
@@ -213,11 +249,11 @@ public class GridLayout extends ViewGroup {
    private void processAttributes(Context context, AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs, styleable.GridLayout);
        try {
            setRowCount(a.getInteger(ROW_COUNT, DEFAULT_COUNT));
            setColumnCount(a.getInteger(COLUMN_COUNT, DEFAULT_COUNT));
            mOrientation = a.getInteger(ORIENTATION, DEFAULT_ORIENTATION);
            setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT));
            setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT));
            mOrientation = a.getInt(ORIENTATION, DEFAULT_ORIENTATION);
            mUseDefaultMargins = a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS);
            mMarginsIncludedInAlignment = a.getBoolean(MARGINS_INCLUDED, DEFAULT_MARGINS_INCLUDED);
            mAlignmentMode = a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE);
            setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
            setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
        } finally {
@@ -347,15 +383,15 @@ public class GridLayout extends ViewGroup {
     * When {@code false}, the default value of all margins is zero.
     * <p>
     * When setting to {@code true}, consider setting the value of the
     * {@link #setMarginsIncludedInAlignment(boolean) marginsIncludedInAlignment}
     * property to {@code false}.
     * {@link #setAlignmentMode(int) alignmentMode}
     * property to {@link #ALIGN_BOUNDS}.
     * <p>
     * The default value of this property is {@code false}.
     *
     * @param useDefaultMargins use {@code true} to make GridLayout allocate default margins
     *
     * @see #getUseDefaultMargins()
     * @see #setMarginsIncludedInAlignment(boolean)
     * @see #setAlignmentMode(int)
     *
     * @see MarginLayoutParams#leftMargin
     * @see MarginLayoutParams#topMargin
@@ -370,36 +406,38 @@ public class GridLayout extends ViewGroup {
    }

    /**
     * Returns whether GridLayout aligns the edges of the view or the edges
     * of the larger rectangle created by extending the view by its associated
     * margins.
     * Returns the alignment mode.
     *
     * @return the alignment mode; either {@link #ALIGN_BOUNDS} or {@link #ALIGN_MARGINS}
     *
     * @see #setMarginsIncludedInAlignment(boolean)
     * @see #ALIGN_BOUNDS
     * @see #ALIGN_MARGINS
     *
     * @return {@code true} if alignment is between edges including margins
     * @see #setAlignmentMode(int)
     *
     * @attr ref android.R.styleable#GridLayout_marginsIncludedInAlignment
     * @attr ref android.R.styleable#GridLayout_alignmentMode
     */
    public boolean getMarginsIncludedInAlignment() {
        return mMarginsIncludedInAlignment;
    public int getAlignmentMode() {
        return mAlignmentMode;
    }

    /**
     * When {@code true}, the bounds of a view are extended outwards according to its
     * margins before the edges of the resulting rectangle are aligned.
     * When {@code false}, alignment occurs between the bounds of the view - i.e.
     * {@link #LEFT} alignment means align the left edges of the view.
     * Sets the alignment mode to be used for all of the alignments between the
     * children of this container.
     * <p>
     * The default value of this property is {@code true}.
     * The default value of this property is {@link #ALIGN_MARGINS}.
     *
     * @param alignmentMode either {@link #ALIGN_BOUNDS} or {@link #ALIGN_MARGINS}
     *
     * @param marginsIncludedInAlignment {@code true} if alignment between edges includes margins
     * @see #ALIGN_BOUNDS
     * @see #ALIGN_MARGINS
     *
     * @see #getMarginsIncludedInAlignment()
     * @see #getAlignmentMode()
     *
     * @attr ref android.R.styleable#GridLayout_marginsIncludedInAlignment
     * @attr ref android.R.styleable#GridLayout_alignmentMode
     */
    public void setMarginsIncludedInAlignment(boolean marginsIncludedInAlignment) {
        mMarginsIncludedInAlignment = marginsIncludedInAlignment;
    public void setAlignmentMode(int alignmentMode) {
        mAlignmentMode = alignmentMode;
        requestLayout();
    }

@@ -781,7 +819,7 @@ public class GridLayout extends ViewGroup {

    private int getMeasurementIncludingMargin(View c, boolean horizontal, int measurementType) {
        int result = getMeasurement(c, horizontal, measurementType);
        if (mMarginsIncludedInAlignment) {
        if (mAlignmentMode == ALIGN_MARGINS) {
            int leadingMargin = getMargin(c, true, horizontal);
            int trailingMargin = getMargin(c, false, horizontal);
            return result + leadingMargin + trailingMargin;
@@ -856,7 +894,7 @@ public class GridLayout extends ViewGroup {
            int c2ax = protect(hAlign.getAlignmentValue(null, cellWidth - colBounds.size(), type));
            int c2ay = protect(vAlign.getAlignmentValue(null, cellHeight - rowBounds.size(), type));

            if (mMarginsIncludedInAlignment) {
            if (mAlignmentMode == ALIGN_MARGINS) {
                int leftMargin = getMargin(view, true, true);
                int topMargin = getMargin(view, true, false);
                int rightMargin = getMargin(view, false, true);
@@ -1358,7 +1396,7 @@ public class GridLayout extends ViewGroup {
        private int getLocationIncludingMargin(View view, boolean leading, int index) {
            int location = locations[index];
            int margin;
            if (!mMarginsIncludedInAlignment) {
            if (mAlignmentMode != ALIGN_MARGINS) {
                margin = (leading ? leadingMargins : trailingMargins)[index];
            } else {
                margin = 0;
@@ -1370,7 +1408,7 @@ public class GridLayout extends ViewGroup {
            Arrays.fill(a, MIN_VALUE);
            a[0] = 0;
            solve(getArcs(), a);
            if (!mMarginsIncludedInAlignment) {
            if (mAlignmentMode != ALIGN_MARGINS) {
                addMargins();
            }
        }
@@ -1751,16 +1789,16 @@ public class GridLayout extends ViewGroup {
        private void init(Context context, AttributeSet attrs, int defaultGravity) {
            TypedArray a = context.obtainStyledAttributes(attrs, styleable.GridLayout_Layout);
            try {
                int gravity = a.getInteger(GRAVITY, defaultGravity);
                int gravity = a.getInt(GRAVITY, defaultGravity);

                int column = a.getInteger(COLUMN, DEFAULT_COLUMN);
                int columnSpan = a.getInteger(COLUMN_SPAN, DEFAULT_SPAN_SIZE);
                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.columnWeight = a.getFloat(COLUMN_WEIGHT, getDefaultWeight(width));

                int row = a.getInteger(ROW, DEFAULT_ROW);
                int rowSpan = a.getInteger(ROW_SPAN, DEFAULT_SPAN_SIZE);
                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.rowWeight = a.getFloat(ROW_WEIGHT, getDefaultWeight(height));
@@ -2160,7 +2198,7 @@ public class GridLayout extends ViewGroup {
     * 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 alignmnet values
     * 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:
+15 −5
Original line number Diff line number Diff line
@@ -1206,6 +1206,16 @@
        <enum name="vertical" value="1" />
    </attr>

    <!-- Alignment constants. -->
    <attr name="alignmentMode">
        <!-- Align the bounds of the children.
        See {@link android.widget.GridLayout#ALIGN_BOUNDS}. -->
        <enum name="alignBounds" value="0" />
        <!-- Align the margins of the children.
        See {@link android.widget.GridLayout#ALIGN_MARGINS}. -->
        <enum name="alignMargins" value="1" />
    </attr>

    <!-- ========================== -->
    <!-- Key Codes                  -->
    <!-- ========================== -->
@@ -2541,12 +2551,12 @@
        The default value is false.
        See {@link android.widget.GridLayout#setUseDefaultMargins(boolean)}.-->
        <attr name="useDefaultMargins" format="boolean" />
        <!-- When set to true, causes alignment to take place between the outer
        boundary of a view, as defined by its margins. When set to false,
        <!-- When set to alignMargins, causes alignment to take place between the outer
        boundary of a view, as defined by its margins. When set to alignBounds,
        causes alignment to take place between the edges of the view.
        The default is true.
        See {@link android.widget.GridLayout#setMarginsIncludedInAlignment(boolean)}.-->
        <attr name="marginsIncludedInAlignment" format="boolean" />
        The default is alignMargins.
        See {@link android.widget.GridLayout#setAlignmentMode(int)}.-->
        <attr name="alignmentMode" />
        <!-- When set to true, forces row boundaries to appear in the same order
        as row indices.
        The default is false.
+1 −1
Original line number Diff line number Diff line
@@ -1733,7 +1733,7 @@
  <public type="attr" name="columnCount" />
  <public type="attr" name="columnOrderPreserved" />
  <public type="attr" name="useDefaultMargins" />
  <public type="attr" name="marginsIncludedInAlignment" />
  <public type="attr" name="alignmentMode" />

  <public type="attr" name="layout_row" />
  <public type="attr" name="layout_rowSpan" />
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
        android:layout_height="match_parent"

        android:useDefaultMargins="true"
        android:marginsIncludedInAlignment="false"
        android:alignmentMode="alignBounds"

        android:columnCount="4"
        >
Loading