Created
September 11, 2018 13:26
-
-
Save armcha/936e532612b7d80ec64c3f73e679e3c9 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
class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeSet? = null) : MotionLayout(context, attributeSet) { | |
private val viewToDetectTouch by lazy { | |
findViewById<View>(R.id.videoViewContainer) //TODO move to Attributes | |
} | |
private val viewRect = Rect() | |
private var touchStarted = false | |
init { | |
setTransitionListener(object : MotionLayout.TransitionListener { | |
override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, p3: Float) { | |
} | |
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) { | |
touchStarted = false | |
} | |
}) | |
} | |
override fun onTouchEvent(event: MotionEvent): Boolean { | |
when (event.actionMasked) { | |
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { | |
touchStarted = false | |
return super.onTouchEvent(event) | |
} | |
} | |
if (!touchStarted) { | |
viewToDetectTouch.getHitRect(viewRect) | |
touchStarted = viewRect.contains(event.x.toInt(), event.y.toInt()) | |
} | |
return touchStarted && super.onTouchEvent(event) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment