[Android] Hide player options on simple touch
Geoffrey Métais
git at videolan.org
Fri Jan 18 14:41:21 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jan 18 14:40:14 2019 +0100| [aef1a7c166db57f9492e0a649fb1849f766f3f2f] | committer: Geoffrey Métais
Hide player options on simple touch
And remove swipe gestures
> https://code.videolan.org/videolan/vlc-android/commit/aef1a7c166db57f9492e0a649fb1849f766f3f2f
---
vlc-android/res/layout-land/audio_player.xml | 3 +-
vlc-android/res/layout/audio_player.xml | 3 +-
vlc-android/res/layout/player.xml | 7 ++--
vlc-android/res/layout/player_options.xml | 10 ++++--
vlc-android/res/layout/player_remote_control.xml | 7 ++--
.../vlc/gui/helpers/PlayerOptionsDelegate.kt | 14 +++++---
.../videolan/vlc/gui/video/VideoTouchDelegate.kt | 40 +---------------------
7 files changed, 26 insertions(+), 58 deletions(-)
diff --git a/vlc-android/res/layout-land/audio_player.xml b/vlc-android/res/layout-land/audio_player.xml
index 18b18ff49..aab18d3a7 100644
--- a/vlc-android/res/layout-land/audio_player.xml
+++ b/vlc-android/res/layout-land/audio_player.xml
@@ -336,10 +336,11 @@
<androidx.appcompat.widget.ViewStubCompat
android:id="@+id/player_options_stub"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout="@layout/player_options" />
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/vlc-android/res/layout/audio_player.xml b/vlc-android/res/layout/audio_player.xml
index 299db5b93..bf4039f9c 100644
--- a/vlc-android/res/layout/audio_player.xml
+++ b/vlc-android/res/layout/audio_player.xml
@@ -334,10 +334,11 @@
<androidx.appcompat.widget.ViewStubCompat
android:id="@+id/player_options_stub"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout="@layout/player_options" />
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/vlc-android/res/layout/player.xml b/vlc-android/res/layout/player.xml
index 546184fd1..9519e09a9 100644
--- a/vlc-android/res/layout/player.xml
+++ b/vlc-android/res/layout/player.xml
@@ -77,11 +77,8 @@
<androidx.appcompat.widget.ViewStubCompat
android:id="@+id/player_options_stub"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_centerVertical="true"
- android:fitsSystemWindows="false"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
android:layout="@layout/player_options" />
</RelativeLayout>
diff --git a/vlc-android/res/layout/player_options.xml b/vlc-android/res/layout/player_options.xml
index 1fd033a3a..52ffc7685 100644
--- a/vlc-android/res/layout/player_options.xml
+++ b/vlc-android/res/layout/player_options.xml
@@ -1,9 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/options_background"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:clickable="true">
<androidx.recyclerview.widget.RecyclerView
- xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/options_list"
android:layout_width="wrap_content"
- android:layout_height="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center|end"
android:paddingBottom="@dimen/default_margin"
android:paddingTop="@dimen/default_margin"
android:background="?attr/rounded_bg" />
+</FrameLayout>
diff --git a/vlc-android/res/layout/player_remote_control.xml b/vlc-android/res/layout/player_remote_control.xml
index d14a2766c..8b6be569b 100644
--- a/vlc-android/res/layout/player_remote_control.xml
+++ b/vlc-android/res/layout/player_remote_control.xml
@@ -105,11 +105,8 @@
<androidx.appcompat.widget.ViewStubCompat
android:id="@+id/player_options_stub"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_centerVertical="true"
- android:fitsSystemWindows="false"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
android:layout="@layout/player_options" />
</RelativeLayout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
index d9dc9b58e..0e1ab58e9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
@@ -9,6 +9,7 @@ import android.text.format.DateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.FrameLayout
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.ViewStubCompat
@@ -61,6 +62,7 @@ private const val ID_ABREPEAT = 13
class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: PlaybackService) : LifecycleObserver {
private lateinit var recyclerview : RecyclerView
+ private lateinit var rootView : FrameLayout
private val toast by lazy(LazyThreadSafetyMode.NONE) { Toast.makeText(activity, "", Toast.LENGTH_SHORT) }
private val primary = activity is VideoPlayerActivity && activity.mDisplayManager.isPrimary
@@ -116,18 +118,20 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
fun show() {
activity.findViewById<ViewStubCompat>(R.id.player_options_stub)?.let {
- recyclerview = it.inflate() as RecyclerView
- activity.lifecycle.addObserver(this)
+ rootView = it.inflate() as FrameLayout
+ recyclerview = rootView.findViewById(R.id.options_list)
service.lifecycle.addObserver(this)
+ activity.lifecycle.addObserver(this)
if (recyclerview.layoutManager == null) recyclerview.layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
recyclerview.adapter = OptionsAdapter()
+ rootView.setOnClickListener { hide() }
setup()
}
- recyclerview.visibility = View.VISIBLE
+ rootView.visibility = View.VISIBLE
}
fun hide() {
- recyclerview.visibility = View.GONE
+ rootView.visibility = View.GONE
}
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
@@ -316,7 +320,7 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
toast.show()
}
- fun isShowing() = recyclerview.visibility == View.VISIBLE
+ fun isShowing() = rootView.visibility == View.VISIBLE
private inner class OptionsAdapter : DiffUtilAdapter<PlayerOption, OptionsAdapter.ViewHolder>() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
index 533d59b76..f35078cbb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
@@ -8,7 +8,6 @@ import androidx.core.view.GestureDetectorCompat
import androidx.core.view.ScaleGestureDetectorCompat
import org.videolan.libvlc.MediaPlayer
import org.videolan.medialibrary.Tools
-import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.util.AndroidDevices
@@ -82,11 +81,6 @@ class VideoTouchDelegate(private val player: VideoPlayerActivity,
mTouchAction = TOUCH_IGNORE
return true
}
- if (player.isOptionsListShowing) {
- mTouchAction = TOUCH_IGNORE
- player.hideOptions()
- return true
- }
if (mTouchControls == 0 || player.isLocked) {
// locked or swipe disabled, only handle show/hide & ignore all actions
if (event.action == MotionEvent.ACTION_UP && mTouchAction != TOUCH_IGNORE) player.toggleOverlay()
@@ -363,39 +357,7 @@ class VideoTouchDelegate(private val player: VideoPlayerActivity,
return false
}
- override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float ) = try {
- if (e1.x < screenConfig.metrics.widthPixels * 0.95) false
- else {
- val diffY = e2.y - e1.y
- val diffX = e2.x - e1.x
- if (Math.abs(diffX) > Math.abs(diffY)) {
- if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
- if (diffX > 0) onSwipeRight()
- else onSwipeLeft()
- true
- } else false
- } else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
- if (diffY > 0) onSwipeBottom()
- else onSwipeTop()
- true
- } else false
- }
- } catch (exception: Exception) {
- if (BuildConfig.DEBUG) exception.printStackTrace()
- false
- }
-
- fun onSwipeRight() {
- player.hideOptions()
- }
-
- fun onSwipeLeft() {
- player.showAdvancedOptions()
- }
-
- fun onSwipeTop() {}
-
- fun onSwipeBottom() {}
+ override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float ) = false
}
}
More information about the Android
mailing list