mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
pinch to zoom
This commit is contained in:
parent
fca884651f
commit
ce66873ef3
@ -15,4 +15,8 @@ interface PlayerGestureOptions {
|
|||||||
fun onSwipeRightScreen(distanceY: Float)
|
fun onSwipeRightScreen(distanceY: Float)
|
||||||
|
|
||||||
fun onSwipeEnd()
|
fun onSwipeEnd()
|
||||||
|
|
||||||
|
fun onZoom()
|
||||||
|
|
||||||
|
fun onMinimize()
|
||||||
}
|
}
|
||||||
|
@ -492,4 +492,12 @@ internal class CustomExoPlayerView(
|
|||||||
gestureViewBinding.brightnessControlView.visibility = View.GONE
|
gestureViewBinding.brightnessControlView.visibility = View.GONE
|
||||||
gestureViewBinding.volumeControlView.visibility = View.GONE
|
gestureViewBinding.volumeControlView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onZoom() {
|
||||||
|
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMinimize() {
|
||||||
|
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.os.Looper
|
|||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import android.view.ScaleGestureDetector
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.github.libretube.ui.interfaces.PlayerGestureOptions
|
import com.github.libretube.ui.interfaces.PlayerGestureOptions
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
@ -24,11 +25,13 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
|
|
||||||
private val handler: Handler = Handler(Looper.getMainLooper())
|
private val handler: Handler = Handler(Looper.getMainLooper())
|
||||||
private val gestureDetector: GestureDetector
|
private val gestureDetector: GestureDetector
|
||||||
|
private val scaleGestureDetector: ScaleGestureDetector
|
||||||
private var isMoving = false
|
private var isMoving = false
|
||||||
var isEnabled = true
|
var isEnabled = true
|
||||||
|
|
||||||
init {
|
init {
|
||||||
gestureDetector = GestureDetector(context, GestureListener(), handler)
|
gestureDetector = GestureDetector(context, GestureListener(), handler)
|
||||||
|
scaleGestureDetector = ScaleGestureDetector(context, ScaleGestureListener(), handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@ -40,13 +43,35 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
|
|
||||||
// Event can be already consumed by some view which may lead to NPE.
|
// Event can be already consumed by some view which may lead to NPE.
|
||||||
try {
|
try {
|
||||||
gestureDetector.onTouchEvent(event)
|
val consumed = gestureDetector.onTouchEvent(event)
|
||||||
|
if (!consumed) scaleGestureDetector.onTouchEvent(event)
|
||||||
} catch (_: Exception) { }
|
} catch (_: Exception) { }
|
||||||
|
|
||||||
// If orientation is landscape then allow `onScroll` to consume event and return true.
|
// If orientation is landscape then allow `onScroll` to consume event and return true.
|
||||||
return orientation == Configuration.ORIENTATION_LANDSCAPE
|
return orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inner class ScaleGestureListener : ScaleGestureDetector.OnScaleGestureListener {
|
||||||
|
var scaleFactor: Float = 1f
|
||||||
|
|
||||||
|
override fun onScale(detector: ScaleGestureDetector): Boolean {
|
||||||
|
scaleFactor *= detector.scaleFactor
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onScaleEnd(detector: ScaleGestureDetector) {
|
||||||
|
when {
|
||||||
|
scaleFactor < 0.8 -> listner.onMinimize()
|
||||||
|
scaleFactor > 1.2 -> listner.onZoom()
|
||||||
|
}
|
||||||
|
scaleFactor = 1f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||||
private var lastClick = 0L
|
private var lastClick = 0L
|
||||||
private var lastDoubleClick = 0L
|
private var lastDoubleClick = 0L
|
||||||
|
Loading…
x
Reference in New Issue
Block a user