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

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

Optical bounds support for LinearLayout, TableLayout and TableRow.

The generic support for optical bounds provided in:

https://googleplex-android-review.googlesource.com/#/c/228269/

did not work correctly for nested LinearLayouts. With this fix
all the layouts in the APIdemos now seem to layout correctly
when the optical bounds mode is enabled.

(There's currently no, user level, way to do this. Instead, the
optical bounds layout mode has to be enabled on a per view basis.)

Change-Id: Id3d1d84445a8a2df277ddfe679c42f2d6cf775f4
parent 3cc8211e
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -2784,9 +2784,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        {
            paint.setColor(Color.RED);
            paint.setStyle(Paint.Style.STROKE);
            PathEffect pathEffect = paint.getPathEffect();
            int len = dipsToPixels(4);
            paint.setPathEffect(new DashPathEffect(new float[]{len, len}, 0));

            for (int i = 0; i < getChildCount(); i++) {
                View c = getChildAt(i);
@@ -2798,7 +2795,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                        c.getRight()  - insets.right  - 1,
                        c.getBottom() - insets.bottom - 1);
            }
            paint.setPathEffect(pathEffect);
        }

        // Draw margins
+18 −10
Original line number Diff line number Diff line
@@ -1431,9 +1431,9 @@ public class LinearLayout extends ViewGroup {
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        if (mOrientation == VERTICAL) {
            layoutVertical();
            layoutVertical(l, t, r, b);
        } else {
            layoutHorizontal();
            layoutHorizontal(l, t, r, b);
        }
    }

@@ -1444,15 +1444,19 @@ public class LinearLayout extends ViewGroup {
     * @see #getOrientation()
     * @see #setOrientation(int)
     * @see #onLayout(boolean, int, int, int, int)
     * @param left
     * @param top
     * @param right
     * @param bottom
     */
    void layoutVertical() {
    void layoutVertical(int left, int top, int right, int bottom) {
        final int paddingLeft = mPaddingLeft;

        int childTop;
        int childLeft;
        
        // Where right end of child should go
        final int width = mRight - mLeft;
        final int width = right - left;
        int childRight = width - mPaddingRight;
        
        // Space available for child
@@ -1466,12 +1470,12 @@ public class LinearLayout extends ViewGroup {
        switch (majorGravity) {
           case Gravity.BOTTOM:
               // mTotalLength contains the padding already
               childTop = mPaddingTop + mBottom - mTop - mTotalLength;
               childTop = mPaddingTop + bottom - top - mTotalLength;
               break;

               // mTotalLength contains the padding already
           case Gravity.CENTER_VERTICAL:
               childTop = mPaddingTop + (mBottom - mTop - mTotalLength) / 2;
               childTop = mPaddingTop + (bottom - top - mTotalLength) / 2;
               break;

           case Gravity.TOP:
@@ -1534,8 +1538,12 @@ public class LinearLayout extends ViewGroup {
     * @see #getOrientation()
     * @see #setOrientation(int)
     * @see #onLayout(boolean, int, int, int, int)
     * @param left
     * @param top
     * @param right
     * @param bottom
     */
    void layoutHorizontal() {
    void layoutHorizontal(int left, int top, int right, int bottom) {
        final boolean isLayoutRtl = isLayoutRtl();
        final int paddingTop = mPaddingTop;

@@ -1543,7 +1551,7 @@ public class LinearLayout extends ViewGroup {
        int childLeft;
        
        // Where bottom of child should go
        final int height = mBottom - mTop;
        final int height = bottom - top;
        int childBottom = height - mPaddingBottom; 
        
        // Space available for child
@@ -1563,12 +1571,12 @@ public class LinearLayout extends ViewGroup {
        switch (Gravity.getAbsoluteGravity(majorGravity, layoutDirection)) {
            case Gravity.RIGHT:
                // mTotalLength contains the padding already
                childLeft = mPaddingLeft + mRight - mLeft - mTotalLength;
                childLeft = mPaddingLeft + right - left - mTotalLength;
                break;

            case Gravity.CENTER_HORIZONTAL:
                // mTotalLength contains the padding already
                childLeft = mPaddingLeft + (mRight - mLeft - mTotalLength) / 2;
                childLeft = mPaddingLeft + (right - left - mTotalLength) / 2;
                break;

            case Gravity.LEFT:
+1 −1
Original line number Diff line number Diff line
@@ -445,7 +445,7 @@ public class TableLayout extends LinearLayout {
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        // enforce vertical layout
        layoutVertical();
        layoutVertical(l, t, r, b);
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public class TableRow extends LinearLayout {
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        // enforce horizontal layout
        layoutHorizontal();
        layoutHorizontal(l, t, r, b);
    }

    /**