Commit 0026541d authored by Adrien Maglo's avatar Adrien Maglo
Browse files

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

parent ac3cdb67
<?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"
......
......@@ -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;
}
......
......@@ -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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment