handle double clicks on volume/brightness controllers too

This commit is contained in:
tibbi 2020-02-20 11:45:51 +01:00
parent 0d7aa81442
commit da8aaa71d0
2 changed files with 31 additions and 13 deletions

View file

@ -174,12 +174,8 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
val gestureDetector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() { val gestureDetector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() {
override fun onDoubleTap(e: MotionEvent?): Boolean { override fun onDoubleTap(e: MotionEvent?): Boolean {
val instantWidth = mScreenWidth / 7 if (e != null) {
val clickedX = e?.rawX ?: 0f handleDoubleTap(e.rawX)
when {
clickedX <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false)
clickedX >= mScreenWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true)
else -> togglePlayPause()
} }
return true return true
@ -198,10 +194,14 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
if (config.allowVideoGestures) { if (config.allowVideoGestures) {
video_brightness_controller.initialize(this, slide_info, true, video_player_holder, singleTap = { x, y -> video_brightness_controller.initialize(this, slide_info, true, video_player_holder, singleTap = { x, y ->
toggleFullscreen() toggleFullscreen()
}, doubleTap = {x, y ->
doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false)
}) })
video_volume_controller.initialize(this, slide_info, false, video_player_holder, singleTap = { x, y -> video_volume_controller.initialize(this, slide_info, false, video_player_holder, singleTap = { x, y ->
toggleFullscreen() toggleFullscreen()
}, doubleTap = {x, y ->
doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true)
}) })
} else { } else {
video_brightness_controller.beGone() video_brightness_controller.beGone()
@ -304,6 +304,15 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
} }
} }
private fun handleDoubleTap(x: Float) {
val instantWidth = mScreenWidth / 7
when {
x <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false)
x >= mScreenWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true)
else -> togglePlayPause()
}
}
private fun resumeVideo() { private fun resumeVideo() {
video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline) video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline)
if (mExoPlayer == null) { if (mExoPlayer == null) {

View file

@ -132,13 +132,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
} }
override fun onDoubleTap(e: MotionEvent?): Boolean { override fun onDoubleTap(e: MotionEvent?): Boolean {
val viewWidth = width if (e != null) {
val instantWidth = viewWidth / 7 handleDoubleTap(e.rawX)
val clickedX = e?.rawX ?: 0f
when {
clickedX <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false)
clickedX >= viewWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true)
else -> togglePlayPause()
} }
return true return true
@ -211,6 +206,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
} else { } else {
toggleFullscreen() toggleFullscreen()
} }
}, doubleTap = {x, y ->
doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false)
}) })
mVolumeSideScroll.initialize(activity!!, slide_info, false, container, singleTap = { x, y -> mVolumeSideScroll.initialize(activity!!, slide_info, false, container, singleTap = { x, y ->
@ -219,6 +216,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
} else { } else {
toggleFullscreen() toggleFullscreen()
} }
}, doubleTap = {x, y ->
doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true)
}) })
video_surface.onGlobalLayout { video_surface.onGlobalLayout {
@ -428,6 +427,16 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
listener?.fragmentClicked() listener?.fragmentClicked()
} }
private fun handleDoubleTap(x: Float) {
val viewWidth = mView.width
val instantWidth = viewWidth / 7
when {
x <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false)
x >= viewWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true)
else -> togglePlayPause()
}
}
private fun checkExtendedDetails() { private fun checkExtendedDetails() {
if (mConfig.showExtendedDetails) { if (mConfig.showExtendedDetails) {
mView.video_details.apply { mView.video_details.apply {