Skip to content

Instantly share code, notes, and snippets.

@Eduardo-Nunes
Created June 3, 2020 17:37
Show Gist options
  • Save Eduardo-Nunes/1ebf359dfa7ddc1dbdb4031d4dce128a to your computer and use it in GitHub Desktop.
Save Eduardo-Nunes/1ebf359dfa7ddc1dbdb4031d4dce128a to your computer and use it in GitHub Desktop.
open class DeactivatedViewPager(
context: Context,
attrs: AttributeSet? = null
) : ViewPager(context, attrs) {
var isPagingEnabled = false
override fun onTouchEvent(ev: MotionEvent?): Boolean {
if (ev?.action == MotionEvent.ACTION_UP) performClick()
return isPagingEnabled && super.onTouchEvent(ev)
}
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return isPagingEnabled && super.onInterceptTouchEvent(ev)
}
open fun nextItem() {
if (canScrollHorizontally(+1)) currentItem += 1
}
open fun previousItem() {
if (canScrollHorizontally(-1)) currentItem -= 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment