From 2b378cde411b551464f0040e935692073cfb119f Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Wed, 30 Jan 2013 16:39:33 -0800 Subject: [PATCH] Fix progress bar and spinner in RTL mode Add "mirrorForRtl" property for ProgressBar (default is "false") and use it accordingly to the following RTL rules: - time still goes from left to right - clocks still rotate clockwise Change-Id: Ib91ce6ab341aa6097c0f43b13703174a2ee9ec70 --- api/current.txt | 1 + core/java/android/widget/AbsSeekBar.java | 4 ++-- core/java/android/widget/ProgressBar.java | 8 ++++++-- core/res/res/values/attrs.xml | 3 +++ core/res/res/values/public.xml | 1 + core/res/res/values/styles.xml | 5 +++++ 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/api/current.txt b/api/current.txt index 473769fc35951..ecf9ca0e39594 100644 --- a/api/current.txt +++ b/api/current.txt @@ -725,6 +725,7 @@ package android { field public static final int minSdkVersion = 16843276; // 0x101020c field public static final int minWidth = 16843071; // 0x101013f field public static final int mipMap = 16843725; // 0x10103cd + field public static final int mirrorForRtl = 16843726; // 0x10103ce field public static final int mode = 16843134; // 0x101017e field public static final int moreIcon = 16843061; // 0x1010135 field public static final int multiprocess = 16842771; // 0x1010013 diff --git a/core/java/android/widget/AbsSeekBar.java b/core/java/android/widget/AbsSeekBar.java index 3b5e75b91d979..7674837e3a129 100644 --- a/core/java/android/widget/AbsSeekBar.java +++ b/core/java/android/widget/AbsSeekBar.java @@ -305,7 +305,7 @@ public abstract class AbsSeekBar extends ProgressBar { } // Canvas will be translated, so 0,0 is where we start drawing - final int left = isLayoutRtl() ? available - thumbPos : thumbPos; + final int left = (isLayoutRtl() && mMirrorForRtl) ? available - thumbPos : thumbPos; thumb.setBounds(left, topBound, left + thumbWidth, bottomBound); } @@ -426,7 +426,7 @@ public abstract class AbsSeekBar extends ProgressBar { int x = (int)event.getX(); float scale; float progress = 0; - if (isLayoutRtl()) { + if (isLayoutRtl() && mMirrorForRtl) { if (x > width - mPaddingRight) { scale = 0.0f; } else if (x < mPaddingLeft) { diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index f2d2c65b44301..d816200947cdf 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -223,6 +223,8 @@ public class ProgressBar extends View { private boolean mAttached; private boolean mRefreshIsPosted; + boolean mMirrorForRtl = false; + private final ArrayList mRefreshData = new ArrayList(); private AccessibilityEventSender mAccessibilityEventSender; @@ -302,6 +304,8 @@ public class ProgressBar extends View { setIndeterminate(mOnlyIndeterminate || a.getBoolean( R.styleable.ProgressBar_indeterminate, mIndeterminate)); + mMirrorForRtl = a.getBoolean(R.styleable.ProgressBar_mirrorForRtl, mMirrorForRtl); + a.recycle(); } @@ -1004,7 +1008,7 @@ public class ProgressBar extends View { } } } - if (isLayoutRtl()) { + if (isLayoutRtl() && mMirrorForRtl) { int tempLeft = left; left = w - right; right = w - tempLeft; @@ -1026,7 +1030,7 @@ public class ProgressBar extends View { // Translate canvas so a indeterminate circular progress bar with padding // rotates properly in its animation canvas.save(); - if(isLayoutRtl()) { + if(isLayoutRtl() && mMirrorForRtl) { canvas.translate(getWidth() - mPaddingRight, mPaddingTop); canvas.scale(-1.0f, 1.0f); } else { diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index dc921e60e388f..96fcfe3e7af7b 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2960,6 +2960,9 @@ + + diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 49b536dc339ab..0d800829a4e14 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -2034,5 +2034,6 @@ + diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index f489786937de8..56c22357f344f 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -370,6 +370,7 @@ please see styles_device_defaults.xml. 48dip 48dip 48dip + false