[Android] Equalizer: allow to scroll right and left the equalizer also from the equalizer bars

Adrien Maglo git at videolan.org
Thu Feb 6 15:41:34 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Thu Feb  6 15:38:42 2014 +0100| [0026541d5ee140a3bad26fa270130e69c4b81871] | committer: Adrien Maglo

Equalizer: allow to scroll right and left the equalizer also from the equalizer bars

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=0026541d5ee140a3bad26fa270130e69c4b81871
---

 vlc-android/res/layout/equalizer_bar.xml           |    5 ++-
 .../videolan/vlc/gui/audio/EqualizerFragment.java  |   11 ------
 .../org/videolan/vlc/widget/VerticalSeekBar.java   |   39 +++++++++++++++++---
 3 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/vlc-android/res/layout/equalizer_bar.xml b/vlc-android/res/layout/equalizer_bar.xml
index 5e86a99..2d8c656 100644
--- a/vlc-android/res/layout/equalizer_bar.xml
+++ b/vlc-android/res/layout/equalizer_bar.xml
@@ -1,16 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="64dp"
+    android:layout_width="wrap_content"
     android:layout_height="match_parent"
     android:orientation="vertical" >
 
+    <!-- Be careful: the view is rotated by 90 degrees. -->
     <org.videolan.vlc.widget.VerticalSeekBar
         android:id="@+id/equalizer_seek"
         android:layout_width="wrap_content"
         android:layout_height="0dp"
         android:layout_gravity="center_horizontal"
         android:layout_weight="1"
+        android:paddingTop="20dp"
+        android:paddingBottom="20dp"
         android:maxHeight="4dip"
         android:minHeight="4dip"
         android:progressDrawable="@drawable/po_seekbar"
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.java
index 406a682..8a1c377 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.java
@@ -77,17 +77,6 @@ public class EqualizerFragment extends SherlockFragment {
         preamp = (SeekBar) v.findViewById(R.id.equalizer_preamp);
         bands_layout = (LinearLayout) v.findViewById(R.id.equalizer_bands);
 
-        // only allow scroll in the lower 50dp part of the layout (where frequencies are displayed)
-        HorizontalScrollView scroll = (HorizontalScrollView) v.findViewById(R.id.equalizer_scroll);
-        final float density = this.getResources().getDisplayMetrics().density;
-        scroll.setOnTouchListener(new OnTouchListener() {
-            @Override
-            public boolean onTouch(View v, MotionEvent event) {
-                int delta = v.getHeight() - (int) event.getY();
-                return delta > 50 * density;
-            }
-        });
-
         return v;
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/widget/VerticalSeekBar.java b/vlc-android/src/org/videolan/vlc/widget/VerticalSeekBar.java
index 0d47b78..4b59f5a 100644
--- a/vlc-android/src/org/videolan/vlc/widget/VerticalSeekBar.java
+++ b/vlc-android/src/org/videolan/vlc/widget/VerticalSeekBar.java
@@ -28,6 +28,9 @@ import android.widget.SeekBar;
 
 public class VerticalSeekBar extends SeekBar {
 
+    private boolean mIsMovingThumb = false;
+    static private float THUMB_SLOP = 25;
+
     public VerticalSeekBar(Context context) {
         super(context);
     }
@@ -63,23 +66,49 @@ public class VerticalSeekBar extends SeekBar {
         onSizeChanged(getWidth(), getHeight(), 0, 0);
     }
 
+    private boolean isWithinThumb(MotionEvent event) {
+        final float progress = getProgress();
+        final float density = this.getResources().getDisplayMetrics().density;
+        final float height = getHeight();
+        final float y = event.getY();
+        final float max = getMax();
+        if (progress >= max - (int)(max * (y + THUMB_SLOP * density) / height)
+            && progress <= max - (int)(max * (y - THUMB_SLOP * density) / height))
+            return true;
+        else
+            return false;
+    }
+
     @Override
     public boolean onTouchEvent(MotionEvent event) {
         if (!isEnabled()) {
             return false;
         }
 
+        boolean handled = false;
+
         switch (event.getAction()) {
             case MotionEvent.ACTION_DOWN:
+                if (isWithinThumb(event)) {
+                    getParent().requestDisallowInterceptTouchEvent(true);
+                    mIsMovingThumb = true;
+                    handled = true;
+                }
+                break;
             case MotionEvent.ACTION_MOVE:
-            case MotionEvent.ACTION_UP:
-                setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
-                onSizeChanged(getWidth(), getHeight(), 0, 0);
+                if (mIsMovingThumb) {
+                    setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
+                    onSizeChanged(getWidth(), getHeight(), 0, 0);
+                    handled = true;
+                }
                 break;
-
+            case MotionEvent.ACTION_UP:
             case MotionEvent.ACTION_CANCEL:
+                getParent().requestDisallowInterceptTouchEvent(false);
+                mIsMovingThumb = false;
+                handled = true;
                 break;
         }
-        return true;
+        return handled;
     }
 }



More information about the Android mailing list