Skip to content

Commit

Permalink
[Fix #51][Fix #32] Fix RTL layout direction
Browse files Browse the repository at this point in the history
  • Loading branch information
tommybuonomo committed Sep 5, 2019
1 parent 47ea48f commit ba3ffd2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion viewpagerdotsindicator-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ dependencies {
}

implementation project(':viewpagerdotsindicator')
// implementation 'com.tbuonomo.andrui:viewpagerdotsindicator:2.1.2'
// implementation 'com.tbuonomo.andrui:viewpagerdotsindicator:4.0'
}
2 changes: 1 addition & 1 deletion viewpagerdotsindicator/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tbuonomo.viewpagerdotsindicator">

<application/>
<application android:supportsRtl="true" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.tbuonomo.viewpagerdotsindicator
import android.content.Context
import android.database.DataSetObserver
import android.graphics.Color
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
Expand Down Expand Up @@ -303,4 +305,13 @@ abstract class BaseDotsIndicator @JvmOverloads constructor(context: Context,
protected val ViewPager2?.isEmpty: Boolean
get() = this != null && this.adapter != null &&
adapter!!.itemCount == 0

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1 && layoutDirection == View.LAYOUT_DIRECTION_RTL) {
layoutDirection = View.LAYOUT_DIRECTION_LTR
rotation = 180f
requestLayout()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.tbuonomo.viewpagerdotsindicator

import android.animation.ArgbEvaluator
import android.content.Context
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.ImageView
import android.widget.LinearLayout
Expand Down Expand Up @@ -66,6 +69,11 @@ class DotsIndicator @JvmOverloads constructor(context: Context, attrs: Attribute
val dot = LayoutInflater.from(context).inflate(R.layout.dot_layout, this, false)
val imageView = dot.findViewById<ImageView>(R.id.dot)
val params = imageView.layoutParams as RelativeLayout.LayoutParams

if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
dot.layoutDirection = View.LAYOUT_DIRECTION_LTR
}

params.height = dotsSize.toInt()
params.width = params.height
params.setMargins(dotsSpacing.toInt(), 0, dotsSpacing.toInt(), 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.tbuonomo.viewpagerdotsindicator

import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
Expand All @@ -12,7 +14,6 @@ import android.widget.LinearLayout.HORIZONTAL
import android.widget.RelativeLayout
import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator.Type.SPRING

class SpringDotsIndicator @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null,
Expand Down Expand Up @@ -112,6 +113,10 @@ class SpringDotsIndicator @JvmOverloads constructor(context: Context, attrs: Att
private fun buildDot(stroke: Boolean): ViewGroup {
val dot = LayoutInflater.from(context).inflate(R.layout.spring_dot_layout, this,
false) as ViewGroup
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
dot.layoutDirection = View.LAYOUT_DIRECTION_LTR
}

val dotView = dot.findViewById<ImageView>(R.id.spring_dot)
dotView.setBackgroundResource(
if (stroke) R.drawable.spring_dot_stroke_background else R.drawable.spring_dot_background)
Expand Down Expand Up @@ -145,22 +150,6 @@ class SpringDotsIndicator @JvmOverloads constructor(context: Context, attrs: Att
setUpDotBackground(true, dots[index])
}

fun buildOnPageChangedListener2(): OnPageChangeListener {
return object : OnPageChangeListener {
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
val globalPositionOffsetPixels = position * (dotsSize + dotsSpacing * 2) + (dotsSize + dotsSpacing * 2) *
positionOffset
val indicatorTranslationX = globalPositionOffsetPixels + dotsStrokeWidth / 2f
dotIndicatorSpring?.spring?.finalPosition = indicatorTranslationX
dotIndicatorSpring?.animateToFinalPosition(indicatorTranslationX)
}

override fun onPageSelected(position: Int) {}

override fun onPageScrollStateChanged(state: Int) {}
};
}

override fun buildOnPageChangedListener(): OnPageChangeListenerHelper {
return object : OnPageChangeListenerHelper() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.tbuonomo.viewpagerdotsindicator

import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -116,6 +118,9 @@ class WormDotsIndicator @JvmOverloads constructor(context: Context, attrs: Attri
private fun buildDot(stroke: Boolean): ViewGroup {
val dot = LayoutInflater.from(context).inflate(R.layout.worm_dot_layout, this,
false) as ViewGroup
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
dot.layoutDirection = View.LAYOUT_DIRECTION_LTR
}
val dotImageView = dot.findViewById<View>(R.id.worm_dot)
dotImageView.setBackgroundResource(
if (stroke) R.drawable.worm_dot_stroke_background else R.drawable.worm_dot_background)
Expand Down

0 comments on commit ba3ffd2

Please sign in to comment.