mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
adding some click distance limitation to custom views
This commit is contained in:
parent
f495a0790e
commit
9abafd841f
6 changed files with 25 additions and 65 deletions
|
@ -555,7 +555,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
|||
togglePlayPause()
|
||||
}
|
||||
} else {
|
||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
toggleFullscreen()
|
||||
}
|
||||
}
|
||||
|
@ -673,7 +673,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
|||
togglePlayPause()
|
||||
}
|
||||
} else {
|
||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
toggleFullscreen()
|
||||
}
|
||||
}
|
||||
|
@ -735,53 +735,6 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
|||
video_surface.invalidate()
|
||||
}
|
||||
|
||||
private fun handleEventt(event: MotionEvent) {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val diffX = event.x - mTouchDownX
|
||||
val diffY = event.y - mTouchDownY
|
||||
|
||||
if (mIsDragged || (Math.abs(diffX) > mDragThreshold && Math.abs(diffX) > Math.abs(diffY))) {
|
||||
if (!mIsDragged) {
|
||||
arrayOf(video_curr_time, video_seekbar, video_duration).forEach {
|
||||
it.animate().alpha(1f).start()
|
||||
}
|
||||
}
|
||||
mIgnoreCloseDown = true
|
||||
mIsDragged = true
|
||||
var percent = ((diffX / mScreenWidth) * 100).toInt()
|
||||
percent = Math.min(100, Math.max(-100, percent))
|
||||
|
||||
val skipLength = (mDuration * 1000f) * (percent / 100f)
|
||||
var newProgress = mProgressAtDown + skipLength
|
||||
newProgress = Math.max(Math.min(mExoPlayer!!.duration.toFloat(), newProgress), 0f)
|
||||
val newSeconds = (newProgress / 1000).toInt()
|
||||
setPosition(newSeconds)
|
||||
resetPlayWhenReady()
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
mIgnoreCloseDown = false
|
||||
if (mIsDragged) {
|
||||
if (mIsFullscreen) {
|
||||
arrayOf(video_curr_time, video_seekbar, video_duration).forEach {
|
||||
it.animate().alpha(0f).start()
|
||||
}
|
||||
}
|
||||
|
||||
if (!mIsPlaying) {
|
||||
togglePlayPause()
|
||||
}
|
||||
} else {
|
||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
toggleFullscreen()
|
||||
}
|
||||
}
|
||||
mIsDragged = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// taken from https://github.com/Manuiq/ZoomableTextureView
|
||||
private inner class ScaleListener : ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
||||
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
||||
|
|
|
@ -731,15 +731,15 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
|||
val diffX = mTouchDownX - event.x
|
||||
val diffY = mTouchDownY - event.y
|
||||
|
||||
val downGestureDuration = System.currentTimeMillis() - mTouchDownTime
|
||||
if (!mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION && mSaveScale == 1f) {
|
||||
activity?.supportFinishAfterTransition()
|
||||
if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
mTextureView.performClick()
|
||||
} else {
|
||||
val downGestureDuration = System.currentTimeMillis() - mTouchDownTime
|
||||
if (!mIgnoreCloseDown && Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION && mSaveScale == 1f) {
|
||||
activity?.supportFinishAfterTransition()
|
||||
}
|
||||
}
|
||||
mIgnoreCloseDown = false
|
||||
|
||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
mTextureView.performClick()
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
mLastTouchX = event.x
|
||||
|
|
|
@ -103,6 +103,7 @@ const val GO_TO_PREV_ITEM = "go_to_prev_item"
|
|||
const val MAX_COLUMN_COUNT = 20
|
||||
const val SHOW_TEMP_HIDDEN_DURATION = 300000L
|
||||
const val CLICK_MAX_DURATION = 150
|
||||
const val CLICK_MAX_DISTANCE = 100
|
||||
const val MAX_CLOSE_DOWN_GESTURE_DURATION = 400
|
||||
const val DRAG_THRESHOLD = 8
|
||||
const val MONTH_MILLISECONDS = MONTH_SECONDS * 1000L
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.util.AttributeSet
|
|||
import android.view.MotionEvent
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DISTANCE
|
||||
import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION
|
||||
import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD
|
||||
|
||||
|
@ -40,7 +41,9 @@ class InstantItemSwitch(context: Context, attrs: AttributeSet) : RelativeLayout(
|
|||
mTouchDownTime = System.currentTimeMillis()
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
val diffX = mTouchDownX - event.x
|
||||
val diffY = mTouchDownY - event.y
|
||||
if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
performClick()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.widget.TextView
|
|||
import com.simplemobiletools.commons.extensions.onGlobalLayout
|
||||
import com.simplemobiletools.gallery.pro.R
|
||||
import com.simplemobiletools.gallery.pro.extensions.audioManager
|
||||
import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DISTANCE
|
||||
import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION
|
||||
import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD
|
||||
|
||||
|
@ -106,7 +107,9 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co
|
|||
mLastTouchY = event.y
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
val diffX = mTouchDownX - event.x
|
||||
val diffY = mTouchDownY - event.y
|
||||
if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
callback(event.rawX, event.rawY)
|
||||
}
|
||||
|
||||
|
|
|
@ -89,14 +89,14 @@ class MyZoomableGifTextureView(context: Context, attrs: AttributeSet) : GifTextu
|
|||
val diffX = mTouchDownX - event.x
|
||||
val diffY = mTouchDownY - event.y
|
||||
mCurrZoomMode = ZOOM_MODE_NONE
|
||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||
performClick()
|
||||
}
|
||||
|
||||
val downGestureDuration = System.currentTimeMillis() - mTouchDownTime
|
||||
val areDiffsOK = Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold
|
||||
if (mSaveScale == 1f && !mIgnoreCloseDown && areDiffsOK && context.config.allowDownGesture && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION) {
|
||||
mCloseDownCallback?.invoke()
|
||||
} else {
|
||||
val downGestureDuration = System.currentTimeMillis() - mTouchDownTime
|
||||
val areDiffsOK = Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold
|
||||
if (mSaveScale == 1f && !mIgnoreCloseDown && areDiffsOK && context.config.allowDownGesture && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION) {
|
||||
mCloseDownCallback?.invoke()
|
||||
}
|
||||
}
|
||||
mIgnoreCloseDown = false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue