Skip to content

Commit

Permalink
Call progress with user flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmmarlow committed Dec 25, 2018
1 parent 28f7e03 commit 141f2a0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import android.content.Context
import android.graphics.Canvas
import android.graphics.RectF
import android.graphics.drawable.Drawable
import android.os.Build
import android.support.v4.content.ContextCompat
import android.support.v7.widget.AppCompatSeekBar
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.ProgressBar
import co.sodalabs.view.slider.R

/**
Expand Down Expand Up @@ -61,6 +63,26 @@ abstract class StyledBaseSliderView : AppCompatSeekBar {

protected val tmpBound = RectF()

protected val progressInternalMethod by lazy {
val clazz = ProgressBar::class.java

val setProgressInternal = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
clazz.getDeclaredMethod(
"setProgress",
Int::class.java,
Boolean::class.java)
} else {
clazz.getDeclaredMethod(
"setProgressInternal",
Int::class.java,
Boolean::class.java,
Boolean::class.java)
}

setProgressInternal.isAccessible = true
return@lazy setProgressInternal
}

constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
Expand Down Expand Up @@ -211,7 +233,8 @@ abstract class StyledBaseSliderView : AppCompatSeekBar {
from = thumbStartX,
to = thumbEndX)

progress = positionToIntProgress(x)
val prog = positionToIntProgress(x)
callProgressInternal(prog, true)
}

return true
Expand All @@ -226,7 +249,8 @@ abstract class StyledBaseSliderView : AppCompatSeekBar {
from = thumbStartX,
to = thumbEndX)

progress = positionToIntProgress(x)
val prog = positionToIntProgress(x)
callProgressInternal(prog, true)

return true
}
Expand All @@ -235,6 +259,14 @@ abstract class StyledBaseSliderView : AppCompatSeekBar {
}
}

protected fun callProgressInternal(progress: Int, fromUser: Boolean, animate: Boolean = false) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
progressInternalMethod.invoke(this, progress, fromUser)
} else {
progressInternalMethod.invoke(this, progress, fromUser, animate)
}
}

protected fun isTouchDrag(touchX: Float): Boolean {
return Math.abs(touchX - touchStartX) > touchDragSlop
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ open class StyledMarkerSliderView : StyledBaseSliderView {
from = thumbStartX,
to = thumbEndX)

progress = positionToIntProgress(x)
val prog = positionToIntProgress(x)
callProgressInternal(prog, true)
}

return true
Expand Down Expand Up @@ -235,7 +236,8 @@ open class StyledMarkerSliderView : StyledBaseSliderView {
thumbAnimator?.cancel()
thumbAnimator = ValueAnimator.ofInt(currentProgress, nextProgress)
thumbAnimator?.addUpdateListener { animator ->
progress = animator.animatedValue as Int
val prog = animator.animatedValue as Int
callProgressInternal(prog, true)
}
thumbAnimator?.interpolator = AccelerateDecelerateInterpolator()
thumbAnimator?.duration = (450 * (Math.abs(currentProgress - nextProgress) / 100f)).toLong()
Expand Down

0 comments on commit 141f2a0

Please sign in to comment.