Bug 1337440 - [RTL] Get drawing offset relatively when rtl and horizontal, r=sebastian
authormaliu <max@mxli.us>
Wed, 22 Mar 2017 14:55:31 +0800
changeset 348997 cd12bd4827548b4556b2e1b40f56f6315d018060
parent 348996 4e2d53d22566a45c5402c4f0785d5fbc5628f92a
child 348998 258d94311e1e707d6cec608bfe13d23095cea5ec
push id39376
push usermax@mxli.us
push dateThu, 23 Mar 2017 05:19:13 +0000
treeherderautoland@cd12bd482754 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1337440
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1337440 - [RTL] Get drawing offset relatively when rtl and horizontal, r=sebastian MozReview-Commit-ID: JZAnNJwxCyI
mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/CirclePageIndicator.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/CirclePageIndicator.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/CirclePageIndicator.java
@@ -23,16 +23,17 @@ import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Paint.Style;
 import android.graphics.drawable.Drawable;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.support.v4.view.MotionEventCompat;
 import android.support.v4.view.ViewConfigurationCompat;
 import android.support.v4.view.ViewPager;
+import android.support.v7.widget.ViewUtils;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewConfiguration;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.util.FloatUtils;
 
@@ -209,16 +210,24 @@ public class CirclePageIndicator
         mSnap = snap;
         invalidate();
     }
 
     public boolean isSnap() {
         return mSnap;
     }
 
+    private boolean isRtl() {
+        return ViewUtils.isLayoutRtl(this);
+    }
+
+    private float getRadiusRelativly() {
+        return getRadius() * (isRtl() ? -1 : 1);
+    }
+
     @Override
     protected void onDraw(Canvas canvas) {
         super.onDraw(canvas);
 
         if (mViewPager == null) {
             return;
         }
         final int count = mViewPager.getAdapter().getCount();
@@ -226,33 +235,35 @@ public class CirclePageIndicator
             return;
         }
 
         if (mCurrentPage >= count) {
             setCurrentItem(count - 1);
             return;
         }
 
-        int longSize;
-        int longPaddingBefore;
-        int longPaddingAfter;
-        int shortPaddingBefore;
+        final int longSize;
+        final int longPaddingBefore;
+        final int longPaddingAfter;
+        final int shortPaddingBefore;
+        final float threeRadius;
         if (mOrientation == HORIZONTAL) {
             longSize = getWidth();
             longPaddingBefore = getPaddingLeft();
             longPaddingAfter = getPaddingRight();
             shortPaddingBefore = getPaddingTop();
+            threeRadius = getRadiusRelativly() * SEPARATION_FACTOR;
         } else {
             longSize = getHeight();
             longPaddingBefore = getPaddingTop();
             longPaddingAfter = getPaddingBottom();
             shortPaddingBefore = getPaddingLeft();
+            threeRadius = mRadius * SEPARATION_FACTOR;
         }
 
-        final float threeRadius = mRadius * SEPARATION_FACTOR;
         final float shortOffset = shortPaddingBefore + mRadius;
         float longOffset = longPaddingBefore + mRadius;
         if (mCentered) {
             longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f);
         }
 
         float dX;
         float dY;