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

Commit 0af4b8b0 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Make ProgressBar / SeekBar / RatingBar widgets aware of layout direction

- see bug #5429822 UI should be mirrored for RTL locales (Arabic, Hebrew, farsi)

Change-Id: I8d76299090abf6b2b187696b1a83e71d7a44b1ce
parent 18e87680
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11359,6 +11359,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        resolveLayoutParams();
        resolveTextDirection();
        resolveTextAlignment();
        resolveDrawables();
    }
    /**
+30 −8
Original line number Diff line number Diff line
@@ -107,6 +107,9 @@ public abstract class AbsSeekBar extends ProgressBar {
        }
        if (thumb != null) {
            thumb.setCallback(this);
            if (canResolveLayoutDirection()) {
                thumb.setLayoutDirection(getResolvedLayoutDirection());
            }

            // Assuming the thumb drawable is symmetric, set the thumb offset
            // such that the thumb will hang halfway off either edge of the
@@ -304,6 +307,15 @@ public abstract class AbsSeekBar extends ProgressBar {
        thumb.setBounds(thumbPos, topBound, thumbPos + thumbWidth, bottomBound);
    }

    @Override
    public void onResolveDrawables(int layoutDirection) {
        super.onResolveDrawables(layoutDirection);

        if (mThumb != null) {
            mThumb.setLayoutDirection(layoutDirection);
        }
    }

    @Override
    protected synchronized void onDraw(Canvas canvas) {
        super.onDraw(canvas);
@@ -409,6 +421,16 @@ public abstract class AbsSeekBar extends ProgressBar {
        int x = (int)event.getX();
        float scale;
        float progress = 0;
        if (isLayoutRtl()) {
            if (x > width - mPaddingRight) {
                scale = 0.0f;
            } else if (x < mPaddingLeft) {
                scale = 1.0f;
            } else {
                scale = (float)(available - x + mPaddingLeft) / (float)available;
                progress = mTouchProgressOffset;
            }
        } else {
            if (x < mPaddingLeft) {
                scale = 0.0f;
            } else if (x > width - mPaddingRight) {
@@ -417,7 +439,7 @@ public abstract class AbsSeekBar extends ProgressBar {
                scale = (float)(x - mPaddingLeft) / (float)available;
                progress = mTouchProgressOffset;
            }
        
        }
        final int max = getMax();
        progress += scale * max;
        
+22 −3
Original line number Diff line number Diff line
@@ -478,8 +478,8 @@ public class ProgressBar extends View {
            d.setCallback(this);
        }
        mIndeterminateDrawable = d;
        if (mIndeterminateDrawable != null) {
            mIndeterminateDrawable.setLayoutDirection(getLayoutDirection());
        if (mIndeterminateDrawable != null && canResolveLayoutDirection()) {
            mIndeterminateDrawable.setLayoutDirection(getResolvedLayoutDirection());
        }
        if (mIndeterminate) {
            mCurrentDrawable = d;
@@ -520,7 +520,9 @@ public class ProgressBar extends View {

        if (d != null) {
            d.setCallback(this);
            d.setLayoutDirection(getLayoutDirection());
            if (canResolveLayoutDirection()) {
                d.setLayoutDirection(getResolvedLayoutDirection());
            }

            // Make sure the ProgressBar is always tall enough
            int drawableHeight = d.getMinimumHeight();
@@ -563,6 +565,20 @@ public class ProgressBar extends View {
        if (mIndeterminateDrawable != null) mIndeterminateDrawable.jumpToCurrentState();
    }

    @Override
    public void onResolveDrawables(int layoutDirection) {
        final Drawable d = mCurrentDrawable;
        if (d != null) {
            d.setLayoutDirection(layoutDirection);
        }
        if (mIndeterminateDrawable != null) {
            mIndeterminateDrawable.setLayoutDirection(layoutDirection);
        }
        if (mProgressDrawable != null) {
            mProgressDrawable.setLayoutDirection(layoutDirection);
        }
    }

    @Override
    public void postInvalidate() {
        if (!mNoInvalidate) {
@@ -652,6 +668,9 @@ public class ProgressBar extends View {

            if (d instanceof LayerDrawable) {
                progressDrawable = ((LayerDrawable) d).findDrawableByLayerId(id);
                if (progressDrawable != null && canResolveLayoutDirection()) {
                    progressDrawable.setLayoutDirection(getResolvedLayoutDirection());
                }
            }

            final int level = (int) (scale * MAX_LEVEL);
+0 −3
Original line number Diff line number Diff line
@@ -4463,9 +4463,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

        mTemporaryDetach = false;

        // Resolve drawables as the layout direction has been resolved
        resolveDrawables();

        if (mEditor != null) mEditor.onAttachedToWindow();
    }

+2 −0
Original line number Diff line number Diff line
@@ -21,11 +21,13 @@

    <item android:id="@android:id/secondaryProgress">
        <scale android:scaleWidth="100%"
               android:scaleGravity="start"
               android:drawable="@android:drawable/progress_secondary_holo_dark" />
    </item>

    <item android:id="@android:id/progress">
        <scale android:scaleWidth="100%"
               android:scaleGravity="start"
               android:drawable="@android:drawable/progress_primary_holo_dark" />
    </item>

Loading