mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-24 08:38:51 -05:00
Be a little more graceful when scrolling horizontally in a (vertical) scroll view.
Not quite to the point of diagonal scrolling, but hopefully closer.
This commit is contained in:
parent
bcb1131cb5
commit
b1d8e49d72
@ -2,16 +2,19 @@ package com.fsck.k9.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.ScrollView;
|
||||
|
||||
public class ToggleScrollView extends ScrollView
|
||||
{
|
||||
private GestureDetector mDetector;
|
||||
private boolean mScrolling = true;
|
||||
|
||||
public ToggleScrollView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
mDetector = new GestureDetector(new YScrollDetector());
|
||||
}
|
||||
|
||||
public void setScrolling(boolean enable)
|
||||
@ -28,6 +31,43 @@ public class ToggleScrollView extends ScrollView
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev)
|
||||
{
|
||||
return (mScrolling) ? super.onInterceptTouchEvent(ev) : false;
|
||||
if(!mScrolling) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This doesn't quite get us to diagonal scrolling, but it's somewhat better than what we've
|
||||
// currently got. This is based on
|
||||
// http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling
|
||||
boolean result = super.onInterceptTouchEvent(ev);
|
||||
if (mDetector.onTouchEvent(ev))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return false if we're scrolling in the x direction
|
||||
class YScrollDetector extends GestureDetector.SimpleOnGestureListener
|
||||
{
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Math.abs(distanceY) > Math.abs(distanceX))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user