Code example for PointF

Methods: set

0
			if (ev.getPointerCount() == 2) {
				oldDistance = spacing(ev);
 
				if (oldDistance > 10f) {
					isPinch = true;
					PointF midPoint = new PointF();
					midPoint(midPoint, ev);
					if (pinchListener != null) {
						return pinchListener.onPinchBegin(midPoint);
					} 
				} 
			} 
			break; 
		case MotionEvent.ACTION_MOVE:
			if (isPinch) {
				float newDistance = spacing(ev);
 
				if (newDistance > 10f) {
					float scale = newDistance / oldDistance;
					if (pinchListener != null) {
						return pinchListener.onPinch(scale);
					} 
				} 
				return false; 
			} 
			break; 
		case MotionEvent.ACTION_POINTER_UP:
			if (isPinch) {
				isPinch = false;
				if (pinchListener != null) {
					pinchListener.onPinchEnd();
				} 
			} 
			break; 
		default: 
			break; 
		} 
 
		return super.onTouchEvent(ev);
	} 
 
	private float spacing(MotionEvent event) {
		float x = event.getX(0) - event.getX(1);
		float y = event.getY(0) - event.getY(1);
 
		float sqrtF = FloatMath.sqrt(x * x + y * y);
		return sqrtF;
	} 
 
	private void midPoint(PointF point, MotionEvent event) {
		float x = event.getX(0) + event.getX(1);
		float y = event.getY(0) + event.getY(1);
		point.set(x / 2, y / 2);
	} 
}