@@ -1340,20 +1340,40 @@ private void onHandleUiEvent(MotionEvent event, int eventType, int flags) {
13401340
13411341 private void onHandleUiTouchEvent (MotionEvent ev ) {
13421342 final ScaleGestureDetector detector =
1343- mZoomManager .getMultiTouchGestureDetector ();
1343+ mZoomManager .getScaleGestureDetector ();
13441344
1345- float x = ev .getX ();
1346- float y = ev .getY ();
1345+ int action = ev .getActionMasked ();
1346+ final boolean pointerUp = action == MotionEvent .ACTION_POINTER_UP ;
1347+ final boolean configChanged =
1348+ action == MotionEvent .ACTION_POINTER_UP ||
1349+ action == MotionEvent .ACTION_POINTER_DOWN ;
1350+ final int skipIndex = pointerUp ? ev .getActionIndex () : -1 ;
1351+
1352+ // Determine focal point
1353+ float sumX = 0 , sumY = 0 ;
1354+ final int count = ev .getPointerCount ();
1355+ for (int i = 0 ; i < count ; i ++) {
1356+ if (skipIndex == i ) continue ;
1357+ sumX += ev .getX (i );
1358+ sumY += ev .getY (i );
1359+ }
1360+ final int div = pointerUp ? count - 1 : count ;
1361+ float x = sumX / div ;
1362+ float y = sumY / div ;
1363+
1364+ if (configChanged ) {
1365+ mLastTouchX = Math .round (x );
1366+ mLastTouchY = Math .round (y );
1367+ mLastTouchTime = ev .getEventTime ();
1368+ mWebView .cancelLongPress ();
1369+ mPrivateHandler .removeMessages (SWITCH_TO_LONGPRESS );
1370+ }
13471371
13481372 if (detector != null ) {
13491373 detector .onTouchEvent (ev );
13501374 if (detector .isInProgress ()) {
13511375 mLastTouchTime = ev .getEventTime ();
1352- x = detector .getFocusX ();
1353- y = detector .getFocusY ();
13541376
1355- mWebView .cancelLongPress ();
1356- mPrivateHandler .removeMessages (SWITCH_TO_LONGPRESS );
13571377 if (!mZoomManager .supportsPanDuringZoom ()) {
13581378 return ;
13591379 }
@@ -1364,14 +1384,9 @@ private void onHandleUiTouchEvent(MotionEvent ev) {
13641384 }
13651385 }
13661386
1367- int action = ev .getActionMasked ();
13681387 if (action == MotionEvent .ACTION_POINTER_DOWN ) {
13691388 cancelTouch ();
13701389 action = MotionEvent .ACTION_DOWN ;
1371- } else if (action == MotionEvent .ACTION_POINTER_UP ) {
1372- // set mLastTouchX/Y to the remaining points for multi-touch.
1373- mLastTouchX = Math .round (x );
1374- mLastTouchY = Math .round (y );
13751390 } else if (action == MotionEvent .ACTION_MOVE ) {
13761391 // negative x or y indicate it is on the edge, skip it.
13771392 if (x < 0 || y < 0 ) {
@@ -4357,7 +4372,7 @@ public boolean performLongClick() {
43574372
43584373 // A multi-finger gesture can look like a long press; make sure we don't take
43594374 // long press actions if we're scaling.
4360- final ScaleGestureDetector detector = mZoomManager .getMultiTouchGestureDetector ();
4375+ final ScaleGestureDetector detector = mZoomManager .getScaleGestureDetector ();
43614376 if (detector != null && detector .isInProgress ()) {
43624377 return false ;
43634378 }
@@ -5764,7 +5779,7 @@ private float calculateDragAngle(int dx, int dy) {
57645779 * and the middle point for multi-touch.
57655780 */
57665781 private void handleTouchEventCommon (MotionEvent event , int action , int x , int y ) {
5767- ScaleGestureDetector detector = mZoomManager .getMultiTouchGestureDetector ();
5782+ ScaleGestureDetector detector = mZoomManager .getScaleGestureDetector ();
57685783
57695784 long eventTime = event .getEventTime ();
57705785
0 commit comments