add function to subtitle layer
This commit is contained in:
@@ -8,6 +8,7 @@ import android.graphics.drawable.GradientDrawable
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import android.graphics.Typeface
|
||||
import android.text.TextUtils
|
||||
import android.view.MotionEvent
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -166,7 +167,28 @@ internal class PlayerChrome(
|
||||
addView(createPlayerView())
|
||||
},
|
||||
)
|
||||
val subtitleContainer = LinearLayout(activity).apply {
|
||||
val subtitleContainer = object : LinearLayout(activity) {
|
||||
private var forwardTouchToPlayer = false
|
||||
|
||||
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
forwardTouchToPlayer = !isTouchOverInteractiveControl(this, event)
|
||||
}
|
||||
val forwarded = if (forwardTouchToPlayer) {
|
||||
bindings.playerView.forwardGestureFrom(this, event)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
val handled = forwarded || super.dispatchTouchEvent(event)
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP ||
|
||||
event.actionMasked == MotionEvent.ACTION_CANCEL
|
||||
) {
|
||||
forwardTouchToPlayer = false
|
||||
}
|
||||
return handled
|
||||
}
|
||||
|
||||
}.apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
@@ -503,4 +525,33 @@ internal class PlayerChrome(
|
||||
}
|
||||
view.startAnimation(animation)
|
||||
}
|
||||
|
||||
/** Lets controls own their touches while the subtitle background drives player gestures. */
|
||||
private fun isTouchOverInteractiveControl(root: View, event: MotionEvent): Boolean =
|
||||
hasInteractiveTouchTarget(root, event.rawX, event.rawY)
|
||||
|
||||
private fun hasInteractiveTouchTarget(view: View, screenX: Float, screenY: Float): Boolean {
|
||||
if (view.visibility != View.VISIBLE || !view.isEnabled) {
|
||||
return false
|
||||
}
|
||||
if (view.isClickable || view.isLongClickable || view.isContextClickable) {
|
||||
val location = IntArray(2).also(view::getLocationOnScreen)
|
||||
if (screenX >= location[0] &&
|
||||
screenX < location[0] + view.width &&
|
||||
screenY >= location[1] &&
|
||||
screenY < location[1] + view.height
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if (view !is ViewGroup) {
|
||||
return false
|
||||
}
|
||||
for (index in view.childCount - 1 downTo 0) {
|
||||
if (hasInteractiveTouchTarget(view.getChildAt(index), screenX, screenY)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user