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

Commit 02a7d563 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Fix bug #8487785 Notification shade has text overlapping the icon

- follow up to the fix for bug #8480245 ViewGroup layout margins can be wrong in RTL mode
- deal with "RTL compatibility mode": if left/right margins are not defined and if we
haev some start/end ones then use the start/end ones.

Change-Id: I98fe3276de2bd14f60a1c423a47569a68046f7be
parent 0072f649
Loading
Loading
Loading
Loading
+60 −22
Original line number Diff line number Diff line
@@ -5887,6 +5887,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        private boolean mNeedResolution = false;
        private boolean mIsRtlCompatibilityMode = true;

        private static int UNDEFINED_MARGIN = DEFAULT_MARGIN_RELATIVE;

        private boolean mLeftMarginUndefined = false;
        private boolean mRightMarginUndefined = false;

        /**
         * Creates a new set of layout parameters. The values are extracted from
         * the supplied attributes set and context.
@@ -5913,16 +5918,26 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            } else {
                leftMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginLeft,
                        DEFAULT_MARGIN_RESOLVED);
                topMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginTop,
                        DEFAULT_MARGIN_RESOLVED);
                        UNDEFINED_MARGIN);
                if (leftMargin == UNDEFINED_MARGIN) {
                    mLeftMarginUndefined = true;
                    leftMargin = DEFAULT_MARGIN_RESOLVED;
                }
                rightMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginRight,
                        UNDEFINED_MARGIN);
                if (rightMargin == UNDEFINED_MARGIN) {
                    mRightMarginUndefined = true;
                    rightMargin = DEFAULT_MARGIN_RESOLVED;
                }

                topMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginTop,
                        DEFAULT_MARGIN_RESOLVED);
                bottomMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginBottom,
                        DEFAULT_MARGIN_RESOLVED);

                startMargin = a.getDimensionPixelSize(
                        R.styleable.ViewGroup_MarginLayout_layout_marginStart,
                        DEFAULT_MARGIN_RELATIVE);
@@ -5946,6 +5961,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        public MarginLayoutParams(int width, int height) {
            super(width, height);

            mLeftMarginUndefined = true;
            mRightMarginUndefined = true;

            mNeedResolution = false;
            mIsRtlCompatibilityMode = false;
        }
@@ -5966,6 +5984,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            this.startMargin = source.startMargin;
            this.endMargin = source.endMargin;

            this.mLeftMarginUndefined = source.mLeftMarginUndefined;
            this.mRightMarginUndefined = source.mRightMarginUndefined;

            this.mNeedResolution = source.mNeedResolution;
            this.mIsRtlCompatibilityMode = source.mIsRtlCompatibilityMode;

@@ -5978,6 +5999,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        public MarginLayoutParams(LayoutParams source) {
            super(source);

            mLeftMarginUndefined = true;
            mRightMarginUndefined = true;

            mNeedResolution = false;
            mIsRtlCompatibilityMode = false;
        }
@@ -6002,6 +6026,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            topMargin = top;
            rightMargin = right;
            bottomMargin = bottom;
            mLeftMarginUndefined = false;
            mRightMarginUndefined = false;
            mNeedResolution = isMarginRelative();
        }

@@ -6144,13 +6170,24 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

            // No relative margin or pre JB-MR1 case or no need to resolve, just dont do anything
            // Will use the left and right margins if no relative margin is defined.
            if (!isMarginRelative() || !mNeedResolution || mIsRtlCompatibilityMode) return;
            if (!isMarginRelative() || !mNeedResolution) return;

            // Proceed with resolution
            doResolveMargins();
        }

        private void doResolveMargins() {

            if (mIsRtlCompatibilityMode) {
                // if left or right margins are not defined and if we have some start or end margin
                // defined then use those start and end margins.
                if (mLeftMarginUndefined && startMargin > DEFAULT_MARGIN_RELATIVE) {
                    leftMargin = startMargin;
                }
                if (mRightMarginUndefined && endMargin > DEFAULT_MARGIN_RELATIVE) {
                    rightMargin = endMargin;
                }
            } else {
                // We have some relative margins (either the start one or the end one or both). So use
                // them and override what has been defined for left and right margins. If either start
                // or end margin is not defined, just set it to default "0".
@@ -6169,6 +6206,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                                endMargin : DEFAULT_MARGIN_RESOLVED;
                        break;
                }
            }
            mNeedResolution = false;
        }