Skip to content

Commit ba3ffd2

Browse files
committed
[Fix #51][Fix #32] Fix RTL layout direction
1 parent 47ea48f commit ba3ffd2

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

viewpagerdotsindicator-sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ dependencies {
4141
}
4242

4343
implementation project(':viewpagerdotsindicator')
44-
// implementation 'com.tbuonomo.andrui:viewpagerdotsindicator:2.1.2'
44+
// implementation 'com.tbuonomo.andrui:viewpagerdotsindicator:4.0'
4545
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.tbuonomo.viewpagerdotsindicator">
33

4-
<application/>
4+
<application android:supportsRtl="true" />
55

66
</manifest>

viewpagerdotsindicator/src/main/java/com/tbuonomo/viewpagerdotsindicator/BaseDotsIndicator.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.tbuonomo.viewpagerdotsindicator
33
import android.content.Context
44
import android.database.DataSetObserver
55
import android.graphics.Color
6+
import android.os.Build.VERSION
7+
import android.os.Build.VERSION_CODES
68
import android.util.AttributeSet
79
import android.util.TypedValue
810
import android.view.View
@@ -303,4 +305,13 @@ abstract class BaseDotsIndicator @JvmOverloads constructor(context: Context,
303305
protected val ViewPager2?.isEmpty: Boolean
304306
get() = this != null && this.adapter != null &&
305307
adapter!!.itemCount == 0
308+
309+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
310+
super.onLayout(changed, left, top, right, bottom)
311+
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1 && layoutDirection == View.LAYOUT_DIRECTION_RTL) {
312+
layoutDirection = View.LAYOUT_DIRECTION_LTR
313+
rotation = 180f
314+
requestLayout()
315+
}
316+
}
306317
}

viewpagerdotsindicator/src/main/java/com/tbuonomo/viewpagerdotsindicator/DotsIndicator.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package com.tbuonomo.viewpagerdotsindicator
22

33
import android.animation.ArgbEvaluator
44
import android.content.Context
5+
import android.os.Build.VERSION
6+
import android.os.Build.VERSION_CODES
57
import android.util.AttributeSet
68
import android.view.LayoutInflater
9+
import android.view.View
710
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
811
import android.widget.ImageView
912
import android.widget.LinearLayout
@@ -66,6 +69,11 @@ class DotsIndicator @JvmOverloads constructor(context: Context, attrs: Attribute
6669
val dot = LayoutInflater.from(context).inflate(R.layout.dot_layout, this, false)
6770
val imageView = dot.findViewById<ImageView>(R.id.dot)
6871
val params = imageView.layoutParams as RelativeLayout.LayoutParams
72+
73+
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
74+
dot.layoutDirection = View.LAYOUT_DIRECTION_LTR
75+
}
76+
6977
params.height = dotsSize.toInt()
7078
params.width = params.height
7179
params.setMargins(dotsSpacing.toInt(), 0, dotsSpacing.toInt(), 0)

viewpagerdotsindicator/src/main/java/com/tbuonomo/viewpagerdotsindicator/SpringDotsIndicator.kt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.tbuonomo.viewpagerdotsindicator
22

33
import android.content.Context
44
import android.graphics.drawable.GradientDrawable
5+
import android.os.Build.VERSION
6+
import android.os.Build.VERSION_CODES
57
import android.util.AttributeSet
68
import android.view.LayoutInflater
79
import android.view.View
@@ -12,7 +14,6 @@ import android.widget.LinearLayout.HORIZONTAL
1214
import android.widget.RelativeLayout
1315
import androidx.dynamicanimation.animation.SpringAnimation
1416
import androidx.dynamicanimation.animation.SpringForce
15-
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
1617
import com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator.Type.SPRING
1718

1819
class SpringDotsIndicator @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null,
@@ -112,6 +113,10 @@ class SpringDotsIndicator @JvmOverloads constructor(context: Context, attrs: Att
112113
private fun buildDot(stroke: Boolean): ViewGroup {
113114
val dot = LayoutInflater.from(context).inflate(R.layout.spring_dot_layout, this,
114115
false) as ViewGroup
116+
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
117+
dot.layoutDirection = View.LAYOUT_DIRECTION_LTR
118+
}
119+
115120
val dotView = dot.findViewById<ImageView>(R.id.spring_dot)
116121
dotView.setBackgroundResource(
117122
if (stroke) R.drawable.spring_dot_stroke_background else R.drawable.spring_dot_background)
@@ -145,22 +150,6 @@ class SpringDotsIndicator @JvmOverloads constructor(context: Context, attrs: Att
145150
setUpDotBackground(true, dots[index])
146151
}
147152

148-
fun buildOnPageChangedListener2(): OnPageChangeListener {
149-
return object : OnPageChangeListener {
150-
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
151-
val globalPositionOffsetPixels = position * (dotsSize + dotsSpacing * 2) + (dotsSize + dotsSpacing * 2) *
152-
positionOffset
153-
val indicatorTranslationX = globalPositionOffsetPixels + dotsStrokeWidth / 2f
154-
dotIndicatorSpring?.spring?.finalPosition = indicatorTranslationX
155-
dotIndicatorSpring?.animateToFinalPosition(indicatorTranslationX)
156-
}
157-
158-
override fun onPageSelected(position: Int) {}
159-
160-
override fun onPageScrollStateChanged(state: Int) {}
161-
};
162-
}
163-
164153
override fun buildOnPageChangedListener(): OnPageChangeListenerHelper {
165154
return object : OnPageChangeListenerHelper() {
166155

viewpagerdotsindicator/src/main/java/com/tbuonomo/viewpagerdotsindicator/WormDotsIndicator.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.tbuonomo.viewpagerdotsindicator
22

33
import android.content.Context
44
import android.graphics.drawable.GradientDrawable
5+
import android.os.Build.VERSION
6+
import android.os.Build.VERSION_CODES
57
import android.util.AttributeSet
68
import android.view.LayoutInflater
79
import android.view.View
@@ -116,6 +118,9 @@ class WormDotsIndicator @JvmOverloads constructor(context: Context, attrs: Attri
116118
private fun buildDot(stroke: Boolean): ViewGroup {
117119
val dot = LayoutInflater.from(context).inflate(R.layout.worm_dot_layout, this,
118120
false) as ViewGroup
121+
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
122+
dot.layoutDirection = View.LAYOUT_DIRECTION_LTR
123+
}
119124
val dotImageView = dot.findViewById<View>(R.id.worm_dot)
120125
dotImageView.setBackgroundResource(
121126
if (stroke) R.drawable.worm_dot_stroke_background else R.drawable.worm_dot_background)

0 commit comments

Comments
 (0)