Created
June 3, 2020 17:37
-
-
Save Eduardo-Nunes/1ebf359dfa7ddc1dbdb4031d4dce128a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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