[Android] Improve audio player gestures

Geoffrey Métais git at videolan.org
Wed Aug 8 18:57:19 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug  8 18:56:47 2018 +0200| [e68ab51542ae90f68bebe88bbe83d79bde576145] | committer: Geoffrey Métais

Improve audio player gestures

See #613

> https://code.videolan.org/videolan/vlc-android/commit/e68ab51542ae90f68bebe88bbe83d79bde576145
---

 .../org/videolan/vlc/gui/AudioPlayerContainerActivity.java    |  6 +++---
 vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt     |  5 ++++-
 .../src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java | 10 ++++++++++
 .../src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java     |  8 ++++----
 vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.java | 11 +++++------
 5 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index 0d6fe07a1..8915d77aa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -32,7 +32,6 @@ import android.os.Message;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.design.widget.AppBarLayout;
-import android.support.design.widget.BottomSheetBehavior;
 import android.support.design.widget.CoordinatorLayout;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -59,6 +58,7 @@ import org.videolan.vlc.ScanProgress;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.audio.AudioPlayer;
 import org.videolan.vlc.gui.browser.StorageBrowserFragment;
+import org.videolan.vlc.gui.helpers.BottomSheetBehavior;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.media.PlaylistManager;
@@ -76,7 +76,7 @@ public class AudioPlayerContainerActivity extends BaseActivity {
     protected AudioPlayer mAudioPlayer;
     private FrameLayout mAudioPlayerContainer;
     protected PlaybackService mService;
-    protected BottomSheetBehavior mBottomSheetBehavior;
+    public BottomSheetBehavior mBottomSheetBehavior;
     protected View mFragmentContainer;
     protected int mOriginalBottomPadding;
     private View mScanProgressLayout;
@@ -124,7 +124,7 @@ public class AudioPlayerContainerActivity extends BaseActivity {
     private void initAudioPlayer() {
         findViewById(R.id.audio_player_stub).setVisibility(View.VISIBLE);
         mAudioPlayer = (AudioPlayer) getSupportFragmentManager().findFragmentById(R.id.audio_player);
-        mBottomSheetBehavior = BottomSheetBehavior.from(mAudioPlayerContainer);
+        mBottomSheetBehavior = (BottomSheetBehavior) BottomSheetBehavior.from(mAudioPlayerContainer);
         mBottomSheetBehavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.player_peek_height));
         mBottomSheetBehavior.setBottomSheetCallback(mAudioPlayerBottomSheetCallback);
         showTipViewIfNeeded(R.id.audio_player_tips, Constants.PREF_AUDIOPLAYER_TIPS_SHOWN);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 50b453b6a..a59c10004 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -602,7 +602,9 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
 
     private val mCoverMediaSwitcherListener = object : AudioMediaSwitcherListener {
 
-        override fun onMediaSwitching() {}
+        override fun onMediaSwitching() {
+            (activity as? AudioPlayerContainerActivity)?.mBottomSheetBehavior?.lock(true)
+        }
 
         override fun onMediaSwitched(position: Int) {
             service?.apply {
@@ -611,6 +613,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
                     AudioMediaSwitcherListener.NEXT_MEDIA -> next()
                 }
             }
+            (activity as? AudioPlayerContainerActivity)?.mBottomSheetBehavior?.lock(false)
         }
 
         override fun onTouchDown() {}
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java b/vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java
index 2fda92391..28ef74c41 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java
@@ -9,6 +9,7 @@ import android.view.View;
 
 public class BottomSheetBehavior<V extends View> extends android.support.design.widget.BottomSheetBehavior<V> {
     public static final String TAG = "VLC/BottomSheetBehavior";
+    private boolean lock = false;
 
     public BottomSheetBehavior() {}
 
@@ -16,8 +17,13 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
         super(context, attrs);
     }
 
+    public void lock(boolean lock) {
+        this.lock = lock;
+    }
+
     @Override
     public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
+        if (lock) return false;
         try {
             return super.onInterceptTouchEvent(parent, child, event);
         } catch (NullPointerException ignored) {
@@ -28,6 +34,7 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
 
     @Override
     public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) {
+        if (lock) return;
         try {
             super.onStopNestedScroll(coordinatorLayout, child, target);
         } catch (NullPointerException ignored) {
@@ -37,6 +44,7 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
 
     @Override
     public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed) {
+        if (lock) return;
         try {
             super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
         } catch (NullPointerException ignored) {
@@ -46,6 +54,7 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
 
     @Override
     public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, V child, View target, float velocityX, float velocityY) {
+        if (lock) return false;
         try {
             return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
         } catch (NullPointerException ignored) {
@@ -56,6 +65,7 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
 
     @Override
     public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
+        if (lock) return false;
         try {
             return super.onTouchEvent(parent, child, event);
         } catch (NullPointerException ignored) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java b/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java
index de06645a2..be885e6b4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java
+++ b/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java
@@ -147,10 +147,10 @@ public abstract class AudioMediaSwitcher extends FlingViewGroup {
         mAudioMediaSwitcherListener = l;
     }
 
-    public static interface AudioMediaSwitcherListener {
-        public final static int PREVIOUS_MEDIA = 1;
-        public final static int CURRENT_MEDIA = 2;
-        public final static int NEXT_MEDIA = 3;
+    public interface AudioMediaSwitcherListener {
+        int PREVIOUS_MEDIA = 1;
+        int CURRENT_MEDIA = 2;
+        int NEXT_MEDIA = 3;
 
         void onMediaSwitching();
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.java b/vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.java
index d5ab7fb6f..2a340d87d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.java
+++ b/vlc-android/src/org/videolan/vlc/gui/view/FlingViewGroup.java
@@ -226,16 +226,15 @@ public class FlingViewGroup extends ViewGroup {
 
                 break;
         }
-
         return true;
     }
 
     @Override
-    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
-        super.onScrollChanged(l, t, oldl, oldt);
-        if (mViewSwitchListener != null) {
-            float progress = (float) l / (float) (getWidth() * (getChildCount() - 1));
-            if (l != mCurrentView * getWidth())
+    protected void onScrollChanged(int h, int v, int oldh, int oldv) {
+        super.onScrollChanged(h, v, oldh, oldv);
+        if (mViewSwitchListener != null && Math.abs(oldh-h) > Math.abs(oldv-v)) {
+            float progress = (float) h / (float) (getWidth() * (getChildCount() - 1));
+            if (h != mCurrentView * getWidth())
                 mViewSwitchListener.onSwitching(progress);
             else
                 mViewSwitchListener.onSwitched(mCurrentView);



More information about the Android mailing list