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

Commit b76023af authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Introduce MarginLayoutParams marginStart and margingEnd

- update BiDiTest app for adding more unit tests concerning margin

Change-Id: Ia6a7e0a1948a2c375e8f3cc87d120a85351a8c27
parent 4c60c541
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -601,8 +601,10 @@ package android {
    field public static final int layout_height = 16842997; // 0x10100f5
    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 = 16843675; // 0x101039b
    field public static final int layout_marginLeft = 16842999; // 0x10100f7
    field public static final int layout_marginRight = 16843001; // 0x10100f9
    field public static final int layout_marginStart = 16843674; // 0x101039a
    field public static final int layout_marginTop = 16843000; // 0x10100f8
    field public static final int layout_row = 16843643; // 0x101037b
    field public static final int layout_rowSpan = 16843644; // 0x101037c
+4 −0
Original line number Diff line number Diff line
@@ -11830,6 +11830,10 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
        mPrivateFlags |= FORCE_LAYOUT;
        mPrivateFlags |= INVALIDATED;

        if (mLayoutParams != null) {
            mLayoutParams.resolveWithDirection(getResolvedLayoutDirection());
        }

        if (mParent != null && !mParent.isLayoutRequested()) {
            mParent.requestLayout();
        }
+140 −5
Original line number Diff line number Diff line
@@ -5174,6 +5174,21 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            height = a.getLayoutDimension(heightAttr, "layout_height");
        }

        /**
         * Resolve layout parameters depending on the layout direction. Subclasses that care about
         * layoutDirection changes should override this method. The default implementation does
         * nothing.
         *
         * @param layoutDirection the direction of the layout
         *
         * {@link View#LAYOUT_DIRECTION_LTR}
         * {@link View#LAYOUT_DIRECTION_RTL}
         *
         * @hide
         */
        protected void resolveWithDirection(int layoutDirection) {
        }

        /**
         * Returns a String representation of this set of layout parameters.
         *
@@ -5215,29 +5230,55 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     */
    public static class MarginLayoutParams extends ViewGroup.LayoutParams {
        /**
         * The left margin in pixels of the child.
         * The left margin in pixels of the child. Whenever this value is changed, a call to
         * {@link android.view.View#requestLayout()} needs to be done.
         */
        @ViewDebug.ExportedProperty(category = "layout")
        public int leftMargin;

        /**
         * The top margin in pixels of the child.
         * The top margin in pixels of the child. Whenever this value is changed, a call to
         * {@link android.view.View#requestLayout()} needs to be done.
         */
        @ViewDebug.ExportedProperty(category = "layout")
        public int topMargin;

        /**
         * The right margin in pixels of the child.
         * The right margin in pixels of the child. Whenever this value is changed, a call to
         * {@link android.view.View#requestLayout()} needs to be done.
         */
        @ViewDebug.ExportedProperty(category = "layout")
        public int rightMargin;

        /**
         * The bottom margin in pixels of the child.
         * The bottom margin in pixels of the child. Whenever this value is changed, a call to
         * {@link android.view.View#requestLayout()} needs to be done.
         */
        @ViewDebug.ExportedProperty(category = "layout")
        public int bottomMargin;

        /**
         * The start margin in pixels of the child.
         *
         * @hide
         *
         */
        @ViewDebug.ExportedProperty(category = "layout")
        protected int startMargin = DEFAULT_RELATIVE;

        /**
         * The end margin in pixels of the child.
         *
         * @hide
         */
        @ViewDebug.ExportedProperty(category = "layout")
        protected int endMargin = DEFAULT_RELATIVE;

        /**
         * The default start and end margin.
         */
        static private final int DEFAULT_RELATIVE = Integer.MIN_VALUE;

        /**
         * Creates a new set of layout parameters. The values are extracted from
         * the supplied attributes set and context.
@@ -5270,6 +5311,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                        R.styleable.ViewGroup_MarginLayout_layout_marginRight, 0);
                bottomMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginBottom, 0);
                startMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginStart, DEFAULT_RELATIVE);
                endMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginEnd, DEFAULT_RELATIVE);
            }

            a.recycle();
@@ -5295,6 +5340,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            this.topMargin = source.topMargin;
            this.rightMargin = source.rightMargin;
            this.bottomMargin = source.bottomMargin;
            this.startMargin = source.startMargin;
            this.endMargin = source.endMargin;
        }

        /**
@@ -5305,7 +5352,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }

        /**
         * Sets the margins, in pixels.
         * Sets the margins, in pixels. A call to {@link android.view.View#requestLayout()} needs
         * to be done so that the new margins are taken into account. Left and right margins may be
         * overriden by {@link android.view.View#requestLayout()} depending on layout direction.
         *
         * @param left the left margin size
         * @param top the top margin size
@@ -5323,6 +5372,92 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            rightMargin = right;
            bottomMargin = bottom;
        }

        /**
         * Sets the relative margins, in pixels. A call to {@link android.view.View#requestLayout()}
         * needs to be done so that the new relative margins are taken into account. Left and right
         * margins may be overriden by {@link android.view.View#requestLayout()} depending on layout
         * direction.
         *
         * @param start the start margin size
         * @param top the top margin size
         * @param end the right margin size
         * @param bottom the bottom margin size
         *
         * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart
         * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginTop
         * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd
         * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginBottom
         *
         * @hide
         */
        public void setMarginsRelative(int start, int top, int end, int bottom) {
            startMargin = start;
            topMargin = top;
            endMargin = end;
            bottomMargin = bottom;
        }

        /**
         * Returns the start margin in pixels.
         *
         * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart
         *
         * @return the start margin in pixels.
         *
         * @hide
         */
        public int getMarginStart() {
            return startMargin;
        }

        /**
         * Returns the end margin in pixels.
         *
         * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd
         *
         * @return the end margin in pixels.
         *
         * @hide
         */
        public int getMarginEnd() {
            return endMargin;
        }

        /**
         * Check if margins are relative.
         *
         * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart
         * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd
         *
         * @return true if either marginStart or marginEnd has been set
         *
         * @hide
         */
        public boolean isMarginRelative() {
            return (startMargin != DEFAULT_RELATIVE) || (endMargin != DEFAULT_RELATIVE);
        }

        /**
         * This will be called by {@link android.view.View#requestLayout()}. Left and Right margins
         * maybe overriden depending on layout direction.
         *
         * @hide
         */
        @Override
        protected void resolveWithDirection(int layoutDirection) {
            switch(layoutDirection) {
                case View.LAYOUT_DIRECTION_RTL:
                    leftMargin = (endMargin > DEFAULT_RELATIVE) ? endMargin : leftMargin;
                    rightMargin = (startMargin > DEFAULT_RELATIVE) ? startMargin : rightMargin;
                    break;
                case View.LAYOUT_DIRECTION_LTR:
                default:
                    leftMargin = (startMargin > DEFAULT_RELATIVE) ? startMargin : leftMargin;
                    rightMargin = (endMargin > DEFAULT_RELATIVE) ? endMargin : rightMargin;
                    break;
            }
        }
    }

    /* Describes a touched view and the ids of the pointers that it has captured.
+6 −0
Original line number Diff line number Diff line
@@ -2125,6 +2125,12 @@
        <!--  Specifies extra space on the bottom side of this view.
              This space is outside this view's bounds. -->
        <attr name="layout_marginBottom" format="dimension"  />
        <!--  Specifies extra space on the start side of this view.
              This space is outside this view's bounds. -->
        <attr name="layout_marginStart" format="dimension"  />
        <!--  Specifies extra space on the end side of this view.
              This space is outside this view's bounds. -->
        <attr name="layout_marginEnd" format="dimension"  />
    </declare-styleable>

    <!-- Use <code>input-method</code> as the root tag of the XML resource that
+3 −0
Original line number Diff line number Diff line
@@ -1778,4 +1778,7 @@
  <public type="attr" name="paddingStart"/>
  <public type="attr" name="paddingEnd"/>

  <public type="attr" name="layout_marginStart"/>
  <public type="attr" name="layout_marginEnd"/>

</resources>
Loading