From 3fb5ebeee4fc32c7206164ffda5d079986db00bc Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Jan 2019 16:34:03 +0100 Subject: [PATCH] allow closing VideoPlayerActivity with Down gestures --- .../pro/activities/VideoPlayerActivity.kt | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt index f90599354..41285d25b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt @@ -7,10 +7,7 @@ import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle import android.util.DisplayMetrics -import android.view.Menu -import android.view.MenuItem -import android.view.View -import android.view.WindowManager +import android.view.* import android.widget.SeekBar import com.simplemobiletools.commons.extensions.beInvisibleIf import com.simplemobiletools.commons.extensions.getFilenameFromUri @@ -27,6 +24,11 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen private var mIsFullscreen = false private var mUri: Uri? = null + private var mTouchDownX = 0f + private var mTouchDownY = 0f + private var mCloseDownThreshold = 100f + private var mIgnoreCloseDown = false + public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_video_player) @@ -75,6 +77,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen video_player_holder.setOnClickListener { fullscreenToggled(!mIsFullscreen) } + + if (config.allowDownGesture) { + video_player_holder.setOnTouchListener { v, event -> + handleEvent(event) + false + } + } } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -151,6 +160,25 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen } + private fun handleEvent(event: MotionEvent) { + when (event.actionMasked) { + MotionEvent.ACTION_DOWN -> { + mTouchDownX = event.x + mTouchDownY = event.y + } + MotionEvent.ACTION_POINTER_DOWN -> mIgnoreCloseDown = true + MotionEvent.ACTION_UP -> { + val diffX = mTouchDownX - event.x + val diffY = mTouchDownY - event.y + + if (!mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold) { + supportFinishAfterTransition() + } + mIgnoreCloseDown = false + } + } + } + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { }