@@ -1336,20 +1336,40 @@ private void onHandleUiEvent(MotionEvent event, int eventType, int flags) {
13361336
13371337 private void onHandleUiTouchEvent (MotionEvent ev ) {
13381338 final ScaleGestureDetector detector =
1339- mZoomManager .getMultiTouchGestureDetector ();
1339+ mZoomManager .getScaleGestureDetector ();
13401340
1341- float x = ev .getX ();
1342- float y = ev .getY ();
1341+ int action = ev .getActionMasked ();
1342+ final boolean pointerUp = action == MotionEvent .ACTION_POINTER_UP ;
1343+ final boolean configChanged =
1344+ action == MotionEvent .ACTION_POINTER_UP ||
1345+ action == MotionEvent .ACTION_POINTER_DOWN ;
1346+ final int skipIndex = pointerUp ? ev .getActionIndex () : -1 ;
1347+
1348+ // Determine focal point
1349+ float sumX = 0 , sumY = 0 ;
1350+ final int count = ev .getPointerCount ();
1351+ for (int i = 0 ; i < count ; i ++) {
1352+ if (skipIndex == i ) continue ;
1353+ sumX += ev .getX (i );
1354+ sumY += ev .getY (i );
1355+ }
1356+ final int div = pointerUp ? count - 1 : count ;
1357+ float x = sumX / div ;
1358+ float y = sumY / div ;
1359+
1360+ if (configChanged ) {
1361+ mLastTouchX = Math .round (x );
1362+ mLastTouchY = Math .round (y );
1363+ mLastTouchTime = ev .getEventTime ();
1364+ mWebView .cancelLongPress ();
1365+ mPrivateHandler .removeMessages (SWITCH_TO_LONGPRESS );
1366+ }
13431367
13441368 if (detector != null ) {
13451369 detector .onTouchEvent (ev );
13461370 if (detector .isInProgress ()) {
13471371 mLastTouchTime = ev .getEventTime ();
1348- x = detector .getFocusX ();
1349- y = detector .getFocusY ();
13501372
1351- mWebView .cancelLongPress ();
1352- mPrivateHandler .removeMessages (SWITCH_TO_LONGPRESS );
13531373 if (!mZoomManager .supportsPanDuringZoom ()) {
13541374 return ;
13551375 }
@@ -1360,14 +1380,9 @@ private void onHandleUiTouchEvent(MotionEvent ev) {
13601380 }
13611381 }
13621382
1363- int action = ev .getActionMasked ();
13641383 if (action == MotionEvent .ACTION_POINTER_DOWN ) {
13651384 cancelTouch ();
13661385 action = MotionEvent .ACTION_DOWN ;
1367- } else if (action == MotionEvent .ACTION_POINTER_UP ) {
1368- // set mLastTouchX/Y to the remaining points for multi-touch.
1369- mLastTouchX = Math .round (x );
1370- mLastTouchY = Math .round (y );
13711386 } else if (action == MotionEvent .ACTION_MOVE ) {
13721387 // negative x or y indicate it is on the edge, skip it.
13731388 if (x < 0 || y < 0 ) {
@@ -4345,7 +4360,7 @@ public boolean performLongClick() {
43454360
43464361 // A multi-finger gesture can look like a long press; make sure we don't take
43474362 // long press actions if we're scaling.
4348- final ScaleGestureDetector detector = mZoomManager .getMultiTouchGestureDetector ();
4363+ final ScaleGestureDetector detector = mZoomManager .getScaleGestureDetector ();
43494364 if (detector != null && detector .isInProgress ()) {
43504365 return false ;
43514366 }
@@ -5752,7 +5767,7 @@ private float calculateDragAngle(int dx, int dy) {
57525767 * and the middle point for multi-touch.
57535768 */
57545769 private void handleTouchEventCommon (MotionEvent event , int action , int x , int y ) {
5755- ScaleGestureDetector detector = mZoomManager .getMultiTouchGestureDetector ();
5770+ ScaleGestureDetector detector = mZoomManager .getScaleGestureDetector ();
57565771
57575772 long eventTime = event .getEventTime ();
57585773
0 commit comments