diff --git a/changelog.md b/changelog.md index 222c1f1..44b9300 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,12 @@ +## 1.2.2 + +#### Fixes +- support RTL direction in horizontal mode when the view is RTL [#29](https://github.com/Tinkoff/ScrollingPagerIndicator/issues/29) + - turn off RTL direction by `setAutoRtl(false)` + +#### Changes +#### Additions + ## 1.2.1 #### Fixes diff --git a/gradle.properties b/gradle.properties index 5c90d2b..61c831e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,8 +18,8 @@ android.useAndroidX=true # org.gradle.parallel=true android.useAndroidX=true -VERSION_NAME=1.2.1 -VERSION_CODE=11 +VERSION_NAME=1.2.2 +VERSION_CODE=12 GROUP=ru.tinkoff.scrollingpagerindicator POM_DESCRIPTION=Pager indicator inspired by Instagram. Lightweight and easy to set up. diff --git a/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java b/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java index aa17f3d..8ba94ca 100644 --- a/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java +++ b/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java @@ -5,6 +5,7 @@ import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; +import android.os.Build; import android.util.AttributeSet; import android.util.SparseArray; import android.view.View; @@ -58,6 +59,7 @@ public class ScrollingPagerIndicator extends View { private Runnable attachRunnable; private PagerAttacher currentAttacher; + private boolean autoRtl = true; private boolean dotCountInitialized; @@ -314,6 +316,7 @@ public void detachFromPager() { currentAttacher.detachFromPager(); currentAttacher = null; attachRunnable = null; + autoRtl = true; } dotCountInitialized = false; } @@ -396,6 +399,17 @@ public void setCurrentPosition(int position) { updateScaleInIdleState(position); } + /** + * Sets Rtl direction availability when the view has Rtl direction. + * autoRtl is on by default. + * + * @param autoRtl false means rtl direction doesn't be apply even if view direction is Rtl. + */ + public void setAutoRtl(boolean autoRtl) { + this.autoRtl = autoRtl; + invalidate(); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Width @@ -538,7 +552,12 @@ protected void onDraw(Canvas canvas) { paint.setColor(calculateDotColor(scale)); if (orientation == LinearLayoutManager.HORIZONTAL) { - canvas.drawCircle(dot - visibleFramePosition, + float cx = dot - visibleFramePosition; + if (autoRtl && isRtl()) { + cx = getWidth() - cx; + } + + canvas.drawCircle(cx, getMeasuredHeight() / 2, diameter / 2, paint); @@ -552,6 +571,11 @@ protected void onDraw(Canvas canvas) { } } + private boolean isRtl() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && + getLayoutDirection() == LAYOUT_DIRECTION_RTL; + } + @ColorInt private int calculateDotColor(float dotScale) { return (Integer) colorEvaluator.evaluate(dotScale, dotColor, selectedDotColor);