Add option to lock controls in mpv player (#491)

This commit is contained in:
Quickdesh 2022-04-06 20:39:43 +09:00 committed by GitHub
parent 895e822e3d
commit c15ff1c564
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View file

@ -44,6 +44,7 @@ class Gestures(
}
override fun onDoubleTap(e: MotionEvent): Boolean {
if (activity.isLocked) return false
if (e.y < height * 0.05F || e.y > height * 0.95F) return false
val interval = preferences.skipLengthPreference()
when {
@ -60,6 +61,7 @@ class Gestures(
distanceX: Float,
distanceY: Float
): Boolean {
if (activity.isLocked) return false
if (e1.y < height * 0.05F || e1.y > height * 0.95F) return false
val dx = e1.x - e2.x
val dy = e1.y - e2.y

View file

@ -80,6 +80,8 @@ class PlayerActivity :
private var width = 0
private var height = 0
internal var isLocked = false
private var audioFocusRestore: () -> Unit = {}
private val audioFocusChangeListener = AudioManager.OnAudioFocusChangeListener { type ->
@ -247,6 +249,12 @@ class PlayerActivity :
gestures.onTouch(v, event)
mDetector.onTouchEvent(event)
}
// Lock and Unlock controls
binding.lockControls.setOnClickListener { isLocked = true; toggleControls() }
binding.unlockControls.setOnClickListener { isLocked = false; toggleControls() }
// Cycle, Long click controls
binding.cycleAudioBtn.setOnLongClickListener { pickAudio(); true }
binding.cycleSpeedBtn.setOnLongClickListener { pickSpeed(); true }
binding.cycleSubsBtn.setOnLongClickListener { pickSub(); true }
@ -271,7 +279,13 @@ class PlayerActivity :
}
fun toggleControls() {
binding.controls.isVisible = !binding.controls.isVisible
if (isLocked) {
binding.unlockControls.isVisible = !binding.unlockControls.isVisible
binding.controls.isVisible = false
} else {
binding.unlockControls.isVisible = false
binding.controls.isVisible = !binding.controls.isVisible
}
}
private fun pickAudio() {

View file

@ -13,6 +13,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/unlockControls"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/ic_lock_open_24dp"
android:visibility="gone"
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface" />
<!-- This LinearLayout only exists to prevent clipping -->
<LinearLayout
android:layout_width="match_parent"
@ -180,7 +190,15 @@
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/lockControls"
android:layout_width="48dp"
android:layout_height="match_parent"
android:onClick="cycleAudio"
android:src="@drawable/ic_lock_24dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface" />
<ImageButton
android:layout_marginHorizontal="5dp"