* commit '5782c16d34d839282978f94b1421e91da1e70cde': Applying ChannelScrolling to remove calculateDragAngle
This commit is contained in:
@@ -1254,6 +1254,40 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
|
|
||||||
mAutoFillData = new WebViewCore.AutoFillData();
|
mAutoFillData = new WebViewCore.AutoFillData();
|
||||||
mEditTextScroller = new Scroller(context);
|
mEditTextScroller = new Scroller(context);
|
||||||
|
|
||||||
|
// Calculate channel distance
|
||||||
|
calculateChannelDistance(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate sChannelDistance based on the screen information.
|
||||||
|
* @param context A Context object used to access application assets.
|
||||||
|
*/
|
||||||
|
private void calculateChannelDistance(Context context) {
|
||||||
|
// The channel distance is adjusted for density and screen size
|
||||||
|
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||||
|
final double screenSize = Math.hypot((double)(metrics.widthPixels/metrics.densityDpi),
|
||||||
|
(double)(metrics.heightPixels/metrics.densityDpi));
|
||||||
|
if (screenSize < 3.0) {
|
||||||
|
sChannelDistance = 16;
|
||||||
|
} else if (screenSize < 5.0) {
|
||||||
|
sChannelDistance = 22;
|
||||||
|
} else if (screenSize < 7.0) {
|
||||||
|
sChannelDistance = 28;
|
||||||
|
} else {
|
||||||
|
sChannelDistance = 34;
|
||||||
|
}
|
||||||
|
sChannelDistance = (int)(sChannelDistance * metrics.density);
|
||||||
|
if (sChannelDistance < 16) sChannelDistance = 16;
|
||||||
|
|
||||||
|
if (DebugFlags.WEB_VIEW) {
|
||||||
|
Log.v(LOGTAG, "sChannelDistance : " + sChannelDistance
|
||||||
|
+ ", density : " + metrics.density
|
||||||
|
+ ", screenSize : " + screenSize
|
||||||
|
+ ", metrics.heightPixels : " + metrics.heightPixels
|
||||||
|
+ ", metrics.widthPixels : " + metrics.widthPixels
|
||||||
|
+ ", metrics.densityDpi : " + metrics.densityDpi);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebViewProvider bindings
|
// WebViewProvider bindings
|
||||||
@@ -5718,32 +5752,13 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
}
|
}
|
||||||
return mWebViewPrivate.super_dispatchKeyEvent(event);
|
return mWebViewPrivate.super_dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
private static final int SNAP_BOUND = 16;
|
||||||
* Here is the snap align logic:
|
private static int sChannelDistance = 16;
|
||||||
* 1. If it starts nearly horizontally or vertically, snap align;
|
private int mFirstTouchX = -1; // the first touched point
|
||||||
* 2. If there is a dramitic direction change, let it go;
|
private int mFirstTouchY = -1;
|
||||||
*
|
private int mDistanceX = 0;
|
||||||
* Adjustable parameters. Angle is the radians on a unit circle, limited
|
private int mDistanceY = 0;
|
||||||
* to quadrant 1. Values range from 0f (horizontal) to PI/2 (vertical)
|
|
||||||
*/
|
|
||||||
private static final float HSLOPE_TO_START_SNAP = .25f;
|
|
||||||
private static final float HSLOPE_TO_BREAK_SNAP = .4f;
|
|
||||||
private static final float VSLOPE_TO_START_SNAP = 1.25f;
|
|
||||||
private static final float VSLOPE_TO_BREAK_SNAP = .95f;
|
|
||||||
/*
|
|
||||||
* These values are used to influence the average angle when entering
|
|
||||||
* snap mode. If is is the first movement entering snap, we set the average
|
|
||||||
* to the appropriate ideal. If the user is entering into snap after the
|
|
||||||
* first movement, then we average the average angle with these values.
|
|
||||||
*/
|
|
||||||
private static final float ANGLE_VERT = 2f;
|
|
||||||
private static final float ANGLE_HORIZ = 0f;
|
|
||||||
/*
|
|
||||||
* The modified moving average weight.
|
|
||||||
* Formula: MAV[t]=MAV[t-1] + (P[t]-MAV[t-1])/n
|
|
||||||
*/
|
|
||||||
private static final float MMA_WEIGHT_N = 5;
|
|
||||||
|
|
||||||
private boolean inFullScreenMode() {
|
private boolean inFullScreenMode() {
|
||||||
return mFullScreenHolder != null;
|
return mFullScreenHolder != null;
|
||||||
@@ -5833,12 +5848,6 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private float calculateDragAngle(int dx, int dy) {
|
|
||||||
dx = Math.abs(dx);
|
|
||||||
dy = Math.abs(dy);
|
|
||||||
return (float) Math.atan2(dy, dx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Common code for single touch and multi-touch.
|
* Common code for single touch and multi-touch.
|
||||||
* (x, y) denotes current focus point, which is the touch point for single touch
|
* (x, y) denotes current focus point, which is the touch point for single touch
|
||||||
@@ -5864,6 +5873,12 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_DOWN: {
|
case MotionEvent.ACTION_DOWN: {
|
||||||
mConfirmMove = false;
|
mConfirmMove = false;
|
||||||
|
|
||||||
|
// Channel Scrolling
|
||||||
|
mFirstTouchX = x;
|
||||||
|
mFirstTouchY = y;
|
||||||
|
mDistanceX = mDistanceY = 0;
|
||||||
|
|
||||||
if (!mEditTextScroller.isFinished()) {
|
if (!mEditTextScroller.isFinished()) {
|
||||||
mEditTextScroller.abortAnimation();
|
mEditTextScroller.abortAnimation();
|
||||||
}
|
}
|
||||||
@@ -6001,20 +6016,16 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only lock dragging to one axis if we don't have a scale in progress.
|
if ((detector == null || !detector.isInProgress())
|
||||||
// Scaling implies free-roaming movement. Note this is only ever a question
|
&& SNAP_NONE == mSnapScrollMode) {
|
||||||
// if mZoomManager.supportsPanDuringZoom() is true.
|
int ax = Math.abs(x - mFirstTouchX);
|
||||||
mAverageAngle = calculateDragAngle(deltaX, deltaY);
|
int ay = Math.abs(y - mFirstTouchY);
|
||||||
if (detector == null || !detector.isInProgress()) {
|
if (ax < SNAP_BOUND && ay < SNAP_BOUND) {
|
||||||
// if it starts nearly horizontal or vertical, enforce it
|
break;
|
||||||
if (mAverageAngle < HSLOPE_TO_START_SNAP) {
|
} else if (ax < SNAP_BOUND) {
|
||||||
mSnapScrollMode = SNAP_X;
|
|
||||||
mSnapPositive = deltaX > 0;
|
|
||||||
mAverageAngle = ANGLE_HORIZ;
|
|
||||||
} else if (mAverageAngle > VSLOPE_TO_START_SNAP) {
|
|
||||||
mSnapScrollMode = SNAP_Y;
|
mSnapScrollMode = SNAP_Y;
|
||||||
mSnapPositive = deltaY > 0;
|
} else if (ay < SNAP_BOUND) {
|
||||||
mAverageAngle = ANGLE_VERT;
|
mSnapScrollMode = SNAP_X;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6033,31 +6044,21 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
if (deltaX == 0 && deltaY == 0) {
|
if (deltaX == 0 && deltaY == 0) {
|
||||||
keepScrollBarsVisible = true;
|
keepScrollBarsVisible = true;
|
||||||
} else {
|
} else {
|
||||||
mAverageAngle +=
|
if (mSnapScrollMode == SNAP_X || mSnapScrollMode == SNAP_Y) {
|
||||||
(calculateDragAngle(deltaX, deltaY) - mAverageAngle)
|
mDistanceX += Math.abs(deltaX);
|
||||||
/ MMA_WEIGHT_N;
|
mDistanceY += Math.abs(deltaY);
|
||||||
if (mSnapScrollMode != SNAP_NONE) {
|
|
||||||
if (mSnapScrollMode == SNAP_Y) {
|
|
||||||
// radical change means getting out of snap mode
|
|
||||||
if (mAverageAngle < VSLOPE_TO_BREAK_SNAP) {
|
|
||||||
mSnapScrollMode = SNAP_NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mSnapScrollMode == SNAP_X) {
|
if (mSnapScrollMode == SNAP_X) {
|
||||||
// radical change means getting out of snap mode
|
if (mDistanceY > sChannelDistance) {
|
||||||
if (mAverageAngle > HSLOPE_TO_BREAK_SNAP) {
|
|
||||||
mSnapScrollMode = SNAP_NONE;
|
mSnapScrollMode = SNAP_NONE;
|
||||||
}
|
} else if (mDistanceX > sChannelDistance) {
|
||||||
|
mDistanceX = mDistanceY = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mAverageAngle < HSLOPE_TO_START_SNAP) {
|
if (mDistanceX > sChannelDistance) {
|
||||||
mSnapScrollMode = SNAP_X;
|
mSnapScrollMode = SNAP_NONE;
|
||||||
mSnapPositive = deltaX > 0;
|
} else if (mDistanceY > sChannelDistance) {
|
||||||
mAverageAngle = (mAverageAngle + ANGLE_HORIZ) / 2;
|
mDistanceX = mDistanceY = 0;
|
||||||
} else if (mAverageAngle > VSLOPE_TO_START_SNAP) {
|
}
|
||||||
mSnapScrollMode = SNAP_Y;
|
|
||||||
mSnapPositive = deltaY > 0;
|
|
||||||
mAverageAngle = (mAverageAngle + ANGLE_VERT) / 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mSnapScrollMode != SNAP_NONE) {
|
if (mSnapScrollMode != SNAP_NONE) {
|
||||||
@@ -6092,6 +6093,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_UP: {
|
case MotionEvent.ACTION_UP: {
|
||||||
|
mFirstTouchX = mFirstTouchY = -1;
|
||||||
if (mIsEditingText && mSelectionStarted) {
|
if (mIsEditingText && mSelectionStarted) {
|
||||||
endScrollEdit();
|
endScrollEdit();
|
||||||
mPrivateHandler.sendEmptyMessageDelayed(SCROLL_HANDLE_INTO_VIEW,
|
mPrivateHandler.sendEmptyMessageDelayed(SCROLL_HANDLE_INTO_VIEW,
|
||||||
|
|||||||
Reference in New Issue
Block a user