/** * Convert screen coordinate to source coordinate. * @param vxy view X/Y coordinate. * @return a coordinate representing the corresponding source coordinate. */ @Nullable public final PointF viewToSourceCoord(PointF vxy) { return viewToSourceCoord(vxy.x, vxy.y, new PointF()); }
/** * Convert screen coordinate to source coordinate. * @param vx view X coordinate. * @param vy view Y coordinate. * @return a coordinate representing the corresponding source coordinate. */ @Nullable public final PointF viewToSourceCoord(float vx, float vy) { return viewToSourceCoord(vx, vy, new PointF()); }
/** * Convert screen coordinate to source coordinate. * @param vxy view coordinates to convert. * @param sTarget target object for result. The same instance is also returned. * @return source coordinates. This is the same instance passed to the sTarget param. */ @Nullable public final PointF viewToSourceCoord(PointF vxy, @NonNull PointF sTarget) { return viewToSourceCoord(vxy.x, vxy.y, sTarget); }
@Override public boolean onDoubleTap(MotionEvent e) { if (imageView.isReady()) { PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY()); Toast.makeText(getApplicationContext(), "Double tap: " + ((int)sCoord.x) + ", " + ((int)sCoord.y), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Double tap: Image not ready", Toast.LENGTH_SHORT).show(); } return true; } });
@Override public boolean onSingleTapConfirmed(MotionEvent e) { if (imageView.isReady()) { PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY()); Toast.makeText(getApplicationContext(), "Single tap: " + ((int)sCoord.x) + ", " + ((int)sCoord.y), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Single tap: Image not ready", Toast.LENGTH_SHORT).show(); } return true; } @Override
@Override public void onLongPress(MotionEvent e) { if (imageView.isReady()) { PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY()); Toast.makeText(getApplicationContext(), "Long press: " + ((int)sCoord.x) + ", " + ((int)sCoord.y), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Long press: Image not ready", Toast.LENGTH_SHORT).show(); } } @Override
/** * Returns the source point at the center of the view. * @return the source coordinates current at the center of the view. */ @Nullable public final PointF getCenter() { int mX = getWidth()/2; int mY = getHeight()/2; return viewToSourceCoord(mX, mY); }
@Override public boolean onDoubleTap(MotionEvent e) { if (zoomEnabled && readySent && vTranslate != null) { // Hacky solution for #15 - after a double tap the GestureDetector gets in a state // where the next fling is ignored, so here we replace it with a new one. setGestureDetector(context); if (quickScaleEnabled) { // Store quick scale params. This will become either a double tap zoom or a // quick scale depending on whether the user swipes. vCenterStart = new PointF(e.getX(), e.getY()); vTranslateStart = new PointF(vTranslate.x, vTranslate.y); scaleStart = scale; isQuickScaling = true; isZooming = true; quickScaleLastDistance = -1F; quickScaleSCenter = viewToSourceCoord(vCenterStart); quickScaleVStart = new PointF(e.getX(), e.getY()); quickScaleVLastPoint = new PointF(quickScaleSCenter.x, quickScaleSCenter.y); quickScaleMoved = false; // We need to get events in onTouchEvent after this. return false; } else { // Start double tap zoom animation. doubleTapZoom(viewToSourceCoord(new PointF(e.getX(), e.getY())), new PointF(e.getX(), e.getY())); return true; } } return super.onDoubleTapEvent(e); } });
/** * Convert screen coordinate to source coordinate. */ public final PointF viewToSourceCoord(PointF vxy, PointF sTarget) { return viewToSourceCoord(vxy.x, vxy.y, sTarget); }
/** * Convert screen coordinate to source coordinate. */ public final PointF viewToSourceCoord(float vx, float vy) { return viewToSourceCoord(vx, vy, new PointF()); }
/** * Convert screen coordinate to source coordinate. */ public final PointF viewToSourceCoord(PointF vxy) { return viewToSourceCoord(vxy.x, vxy.y, new PointF()); }
@Override public boolean onDoubleTap(MotionEvent e) { if (zoomEnabled && readySent && vTranslate != null) { // Hacky solution for #15 - after a double tap the GestureDetector gets in a state // where the next fling is ignored, so here we replace it with a new one. setGestureDetector(context); if (quickScaleEnabled) { // Store quick scale params. This will become either a double tap zoom or a // quick scale depending on whether the user swipes. vCenterStart = new PointF(e.getX(), e.getY()); vTranslateStart = new PointF(vTranslate.x, vTranslate.y); scaleStart = scale; isQuickScaling = true; isZooming = true; quickScaleLastDistance = -1F; quickScaleSCenter = viewToSourceCoord(vCenterStart); quickScaleVStart = new PointF(e.getX(), e.getY()); quickScaleVLastPoint = new PointF(quickScaleSCenter.x, quickScaleSCenter.y); quickScaleMoved = false; // We need to get events in onTouchEvent after this. return false; } else { // Start double tap zoom animation. doubleTapZoom(viewToSourceCoord(new PointF(e.getX(), e.getY())), new PointF(e.getX(), e.getY())); return true; } } return super.onDoubleTapEvent(e); } });
/** * Returns the source point at the center of the view. */ public final PointF getCenter() { int mX = getWidth()/2; int mY = getHeight()/2; return viewToSourceCoord(mX, mY); }