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

Commit 600d7dd1 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Fix bug #11256076 Spinner text is too close from the opening triangle in RTL Locales

Background Drawable padding was not taken into account in RTL Locales

- make sure the Drawables are resolved before resolving padding
- during padding resolution take care about background padding

Change-Id: Ib0c722adf5341ab4fa2182a0d0ac2ca639e85cfc
parent b5da7b23
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -3087,6 +3087,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static final int UNDEFINED_PADDING = Integer.MIN_VALUE;
    private boolean mUseBackgroundPadding = false;
    /**
     * @hide
     */
@@ -12111,12 +12113,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        if (!isTextAlignmentResolved()) {
            resolveTextAlignment();
        }
        if (!isPaddingResolved()) {
            resolvePadding();
        }
        // Should resolve Drawables before Padding because we need the layout direction of the
        // Drawable to correctly resolve Padding.
        if (!isDrawablesResolved()) {
            resolveDrawables();
        }
        if (!isPaddingResolved()) {
            resolvePadding();
        }
        onRtlPropertiesChanged(getLayoutDirection());
        return true;
    }
@@ -12319,6 +12323,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // If start / end padding are defined, they will be resolved (hence overriding) to
            // left / right or right / left depending on the resolved layout direction.
            // If start / end padding are not defined, use the left / right ones.
            if (mBackground != null && mUseBackgroundPadding) {
                Rect padding = sThreadLocal.get();
                if (padding == null) {
                    padding = new Rect();
                    sThreadLocal.set(padding);
                }
                mBackground.getPadding(padding);
                mUserPaddingLeftInitial = padding.left;
                mUserPaddingRightInitial = padding.right;
            }
            switch (resolvedLayoutDirection) {
                case LAYOUT_DIRECTION_RTL:
                    if (mUserPaddingStart != UNDEFINED_PADDING) {
@@ -15314,6 +15328,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                        mUserPaddingRightInitial = padding.right;
                        internalSetPadding(padding.left, padding.top, padding.right, padding.bottom);
                }
                mUseBackgroundPadding = true;
            } else {
                mUseBackgroundPadding = false;
            }
            // Compare the minimum sizes of the old Drawable and the new.  If there isn't an old or
@@ -15339,6 +15356,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            /* Remove the background */
            mBackground = null;
            mUseBackgroundPadding = false;
            if ((mPrivateFlags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0) {
                /*
                 * This view ONLY drew the background before and we're removing
@@ -15410,6 +15429,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        mUserPaddingLeftInitial = left;
        mUserPaddingRightInitial = right;
        mUseBackgroundPadding = false;
        internalSetPadding(left, top, right, bottom);
    }
@@ -15496,6 +15517,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        mUserPaddingStart = start;
        mUserPaddingEnd = end;
        mUseBackgroundPadding = false;
        switch(getLayoutDirection()) {
            case LAYOUT_DIRECTION_RTL:
                mUserPaddingLeftInitial = end;
+25 −6
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.graphics.Insets;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.SystemClock;
import android.util.LayoutDirection;
import android.util.SparseArray;

/**
@@ -59,6 +60,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
    private long mExitAnimationEnd;
    private Drawable mLastDrawable;

    private Insets mInsets;

    // overrides from Drawable

    @Override
@@ -78,18 +81,30 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
                | mDrawableContainerState.mChildrenChangingConfigurations;
    }

    private boolean needsMirroring() {
        return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL;
    }

    @Override
    public boolean getPadding(Rect padding) {
        final Rect r = mDrawableContainerState.getConstantPadding();
        boolean result = true;
        if (r != null) {
            padding.set(r);
            return true;
        }
        } else {
            if (mCurrDrawable != null) {
            return mCurrDrawable.getPadding(padding);
                result = mCurrDrawable.getPadding(padding);
            } else {
            return super.getPadding(padding);
                result = super.getPadding(padding);
            }
        }
        if (needsMirroring()) {
            final int left = padding.left;
            final int right = padding.right;
            padding.left = right;
            padding.right = left;
        }
        return result;
    }

    /**
@@ -97,7 +112,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
     */
    @Override
    public Insets getOpticalInsets() {
        return (mCurrDrawable == null) ? Insets.NONE : mCurrDrawable.getOpticalInsets();
        return mInsets;
    }

    @Override
@@ -334,6 +349,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
            mCurrDrawable = d;
            mCurIndex = idx;
            if (d != null) {
                mInsets = d.getOpticalInsets();
                d.mutate();
                if (mDrawableContainerState.mEnterFadeDuration > 0) {
                    mEnterAnimationEnd = now + mDrawableContainerState.mEnterFadeDuration;
@@ -348,9 +364,12 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
                d.setBounds(getBounds());
                d.setLayoutDirection(getLayoutDirection());
                d.setAutoMirrored(mDrawableContainerState.mAutoMirrored);
            } else {
                mInsets = Insets.NONE;
            }
        } else {
            mCurrDrawable = null;
            mInsets = Insets.NONE;
            mCurIndex = -1;
        }