mirror of https://github.com/M66B/FairEmail.git
WebView: keep scrolling left/right
This commit is contained in:
parent
b52386c1a1
commit
89f2cee08c
|
@ -296,7 +296,9 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
|
||||||
return super.onGenericMotionEvent(event);
|
return super.onGenericMotionEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float lastX;
|
||||||
private float lastY;
|
private float lastY;
|
||||||
|
private Integer lastXoff;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
@ -304,18 +306,39 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN)
|
if (event.getAction() == MotionEvent.ACTION_DOWN)
|
||||||
intercept = true; // Prevent ACTION_CANCEL on fling
|
intercept = true; // Prevent ACTION_CANCEL on fling
|
||||||
else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||||
int range = computeVerticalScrollRange();
|
int yrange = computeVerticalScrollRange();
|
||||||
int extend = computeVerticalScrollExtent();
|
int yextend = computeVerticalScrollExtent();
|
||||||
boolean canScrollVertical = (range > extend);
|
boolean canScrollVertical = (yrange > yextend);
|
||||||
if (canScrollVertical) {
|
if (canScrollVertical) {
|
||||||
int bottom = range - extend;
|
int bottom = yrange - yextend;
|
||||||
int off = computeVerticalScrollOffset();
|
int yoff = computeVerticalScrollOffset();
|
||||||
float dy = lastY - event.getY();
|
float dy = lastY - event.getY();
|
||||||
intercept = (off > 0 || dy >= 0) && (off < bottom || dy <= 0);
|
intercept = (yoff > 0 || dy >= 0) && (yoff < bottom || dy <= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intercept)
|
||||||
|
lastXoff = computeHorizontalScrollOffset();
|
||||||
|
else {
|
||||||
|
int xrange = computeHorizontalScrollRange();
|
||||||
|
int xextend = computeHorizontalScrollExtent();
|
||||||
|
boolean canScrollHorizontal = (xrange > xextend);
|
||||||
|
//Log.i("MMM xrange=" + xrange + " xextend=" + xextend + " can=" + canScrollHorizontal);
|
||||||
|
if (canScrollHorizontal) {
|
||||||
|
int right = xrange - xextend;
|
||||||
|
int xoff = computeHorizontalScrollOffset();
|
||||||
|
if (lastXoff == null)
|
||||||
|
lastXoff = xoff;
|
||||||
|
float dx = lastX - event.getX();
|
||||||
|
intercept = (xoff > 0 || dx >= 0) &&
|
||||||
|
(xoff < right || dx <= 0) &&
|
||||||
|
(Math.signum(dx) == Math.signum(xoff - lastXoff));
|
||||||
|
lastXoff = xoff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getParent().requestDisallowInterceptTouchEvent(intercept || event.getPointerCount() > 1);
|
getParent().requestDisallowInterceptTouchEvent(intercept || event.getPointerCount() > 1);
|
||||||
|
|
||||||
|
lastX = event.getX();
|
||||||
lastY = event.getY();
|
lastY = event.getY();
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue