public boolean onScale(ScaleGestureDetector detector) { // the velocity of the pinch in scale factor per ms float velocity = (detector.getCurrentSpan() - detector.getPreviousSpan()) / detector.getTimeDelta(); float currentSpan = detector.getCurrentSpanX(); float prevSpan = detector.getPreviousSpanX(); double diff = Math.abs(currentSpan - prevSpan); /* * If Shove is in progress do not handle scale * If previous scale is handled then keep on handling scale * else give some buffer for shove to be processed */ if (mDoubleTapScale || mScaleHandled || (!mShoveHandled && diff > PINCH_THRESHOLD * Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels))) { mScaleHandled = true; float focusX = mDoubleTapScale ? mapView.getWidth() * 0.5f : detector.getFocusX(); float focusY = mDoubleTapScale ? mapView.getHeight() * 0.5f : detector.getFocusY(); mLastDoubleGestureTime = detector.getEventTime(); handlePinchGesture(focusX, focusY, detector.getScaleFactor(), velocity); return true; } mScaleHandled = false; return false; }
@Override public boolean onScale(ScaleGestureDetector detector) { float xScale = ((float) detector.getCurrentSpanX()) / detector.getPreviousSpanX(); yAmplifier *= (((float) detector.getCurrentSpanY()) / detector.getPreviousSpanY()); yAmplifier = Math.max(Math.min(yAmplifier, MAX_YAMP), MIN_YAMP); shownDataAmount /= xScale; shownDataAmount = Math.min(Math.max(1, (shownDataAmount)), MAXSAMPLEPACKETS); return true; }
@Override public boolean onScale(ScaleGestureDetector scaleGestureDetector) { float spanX = scaleGestureDetector.getCurrentSpanX() - scaleGestureDetector.getPreviousSpanX(); float spanY = scaleGestureDetector.getCurrentSpanY() - scaleGestureDetector.getPreviousSpanY(); LayoutParams lParams = (LayoutParams) getLayoutParams(); float newWidth = lParams.width + spanX; float newHeight = lParams.height + spanY; lParams.width = (int) newWidth; lParams.height = (int) newHeight; setLayoutParams(lParams); Log.i("spanX", spanX + ""); Log.i("spanY", spanY + ""); return true; }
//// TODO: 16/12/15 Still get better method to judge the rotate gesture private boolean judgeRotate(ScaleGestureDetector detector) { boolean res = false; double preDistX = detector.getPreviousSpanX(); double preDistY = detector.getPreviousSpanY(); double curDistX = detector.getCurrentSpanX(); double curDistY = detector.getCurrentSpanY(); double atanPre = Math.atan2(preDistY, preDistX); double atanCur = Math.atan2(curDistY, curDistX); rotate = atanCur - atanPre; if (Math.abs(rotate) > ROTATE_THRESHOLD) { res = true; gestureName = GESTURE_ROTATE; focus_x = detector.getFocusX(); focus_y = detector.getFocusY(); gestureLabel.setText( gestureName + "\n x:" + focus_x + " y:" + focus_y + "\ndeltaAngel:" + rotate); } return res; }