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

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

Fix for bug 8272673: GridLayout in battery details is cut off.

Change-Id: Iabcc2d2c486162cf88990eb1a25aca2e7558a57c
parent 37f58dcc
Loading
Loading
Loading
Loading
+27 −16
Original line number Diff line number Diff line
@@ -944,15 +944,17 @@ public class GridLayout extends ViewGroup {

    // Measurement

    // Note: padding has already been removed from the supplied specs
    private void measureChildWithMargins2(View child, int parentWidthSpec, int parentHeightSpec,
            int childWidth, int childHeight) {
        int childWidthSpec = getChildMeasureSpec(parentWidthSpec,
                mPaddingLeft + mPaddingRight + getTotalMargin(child, true), childWidth);
                getTotalMargin(child, true), childWidth);
        int childHeightSpec = getChildMeasureSpec(parentHeightSpec,
                mPaddingTop + mPaddingBottom + getTotalMargin(child, false), childHeight);
                getTotalMargin(child, false), childHeight);
        child.measure(childWidthSpec, childHeightSpec);
    }

    // Note: padding has already been removed from the supplied specs
    private void measureChildrenWithMargins(int widthSpec, int heightSpec, boolean firstPass) {
        for (int i = 0, N = getChildCount(); i < N; i++) {
            View c = getChildAt(i);
@@ -979,6 +981,11 @@ public class GridLayout extends ViewGroup {
        }
    }

    static int adjust(int measureSpec, int delta) {
        return makeMeasureSpec(
                MeasureSpec.getSize(measureSpec + delta),  MeasureSpec.getMode(measureSpec));
    }

    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {
        consistencyCheck();
@@ -987,26 +994,30 @@ public class GridLayout extends ViewGroup {
         *  is  likely to have changed. We must invalidate if so. */
        invalidateValues();

        measureChildrenWithMargins(widthSpec, heightSpec, true);
        int hPadding = getPaddingLeft() + getPaddingRight();
        int vPadding = getPaddingTop()  + getPaddingBottom();

        int widthSpecSansPadding =  adjust( widthSpec, -hPadding);
        int heightSpecSansPadding = adjust(heightSpec, -vPadding);

        int width, height;
        measureChildrenWithMargins(widthSpecSansPadding, heightSpecSansPadding, true);

        int widthSansPadding;
        int heightSansPadding;

        // Use the orientation property to decide which axis should be laid out first.
        if (orientation == HORIZONTAL) {
            width = horizontalAxis.getMeasure(widthSpec);
            measureChildrenWithMargins(widthSpec, heightSpec, false);
            height = verticalAxis.getMeasure(heightSpec);
            widthSansPadding = horizontalAxis.getMeasure(widthSpecSansPadding);
            measureChildrenWithMargins(widthSpecSansPadding, heightSpecSansPadding, false);
            heightSansPadding = verticalAxis.getMeasure(heightSpecSansPadding);
        } else {
            height = verticalAxis.getMeasure(heightSpec);
            measureChildrenWithMargins(widthSpec, heightSpec, false);
            width = horizontalAxis.getMeasure(widthSpec);
            heightSansPadding = verticalAxis.getMeasure(heightSpecSansPadding);
            measureChildrenWithMargins(widthSpecSansPadding, heightSpecSansPadding, false);
            widthSansPadding = horizontalAxis.getMeasure(widthSpecSansPadding);
        }

        int hPadding = getPaddingLeft() + getPaddingRight();
        int vPadding = getPaddingTop() + getPaddingBottom();

        int measuredWidth = Math.max(hPadding + width, getSuggestedMinimumWidth());
        int measuredHeight = Math.max(vPadding + height, getSuggestedMinimumHeight());
        int measuredWidth  = Math.max(widthSansPadding  + hPadding, getSuggestedMinimumWidth());
        int measuredHeight = Math.max(heightSansPadding + vPadding, getSuggestedMinimumHeight());

        setMeasuredDimension(
                resolveSizeAndState(measuredWidth,   widthSpec, 0),