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

Commit 0762cec0 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Fix bug #7112174 ActionMenuView should be aware of layout direction

- do correct layout of action items depending of layout direction

Change-Id: Iff0181ffa2cb69884920edd5c37eb1a8a8196816
parent 18e87680
Loading
Loading
Loading
Loading
+40 −14
Original line number Diff line number Diff line
@@ -400,6 +400,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
        int nonOverflowCount = 0;
        int widthRemaining = right - left - getPaddingRight() - getPaddingLeft();
        boolean hasOverflow = false;
        final boolean isLayoutRtl = isLayoutRtl();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v.getVisibility() == GONE) {
@@ -414,8 +415,15 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
                }

                int height = v.getMeasuredHeight();
                int r = getWidth() - getPaddingRight() - p.rightMargin;
                int l = r - overflowWidth;
                int r;
                int l;
                if (isLayoutRtl) {
                    l = getPaddingLeft() + p.leftMargin;
                    r = l + overflowWidth;
                } else {
                    r = getWidth() - getPaddingRight() - p.rightMargin;
                    l = r - overflowWidth;
                }
                int t = midVertical - (height / 2);
                int b = t + height;
                v.layout(l, t, r, b);
@@ -448,6 +456,23 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
        final int spacerCount = nonOverflowCount - (hasOverflow ? 0 : 1);
        final int spacerSize = Math.max(0, spacerCount > 0 ? widthRemaining / spacerCount : 0);

        if (isLayoutRtl) {
            int startRight = getWidth() - getPaddingRight();
            for (int i = 0; i < childCount; i++) {
                final View v = getChildAt(i);
                final LayoutParams lp = (LayoutParams) v.getLayoutParams();
                if (v.getVisibility() == GONE || lp.isOverflowButton) {
                    continue;
                }

                startRight -= lp.rightMargin;
                int width = v.getMeasuredWidth();
                int height = v.getMeasuredHeight();
                int t = midVertical - height / 2;
                v.layout(startRight - width, t, startRight, t + height);
                startRight -= width + lp.leftMargin + spacerSize;
            }
        } else {
            int startLeft = getPaddingLeft();
            for (int i = 0; i < childCount; i++) {
                final View v = getChildAt(i);
@@ -464,6 +489,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
                startLeft += width + lp.rightMargin + spacerSize;
            }
        }
    }

    @Override
    public void onDetachedFromWindow() {