From a08e526815b528e27f7dcbe013f5670853ed66ef Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 18 Apr 2016 13:33:35 +0200 Subject: [PATCH] fix touch to focus by rotating the matrix --- .../com/simplemobiletools/camera/Preview.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/camera/Preview.java b/app/src/main/java/com/simplemobiletools/camera/Preview.java index 36704b87..84fe9174 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Preview.java +++ b/app/src/main/java/com/simplemobiletools/camera/Preview.java @@ -162,8 +162,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O return; camera.cancelAutoFocus(); - Rect focusRect = calculateFocusArea(event.getX(), event.getY()); - + final Rect focusRect = calculateFocusArea(event.getX(), event.getY()); final Camera.Parameters parameters = camera.getParameters(); if (parameters.getMaxNumFocusAreas() > 0) { final List focusAreas = new ArrayList<>(1); @@ -183,22 +182,18 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O } private Rect calculateFocusArea(float x, float y) { - int left = clamp(Float.valueOf((x / surfaceView.getWidth()) * 2000 - 1000).intValue()); - int top = clamp(Float.valueOf((y / surfaceView.getHeight()) * 2000 - 1000).intValue()); + int left = Float.valueOf((x / surfaceView.getWidth()) * 2000 - 1000).intValue(); + int top = Float.valueOf((y / surfaceView.getHeight()) * 2000 - 1000).intValue(); - return new Rect(left, top, Math.min(left + FOCUS_AREA_SIZE, 1000), Math.min(top + FOCUS_AREA_SIZE, 1000)); - } + int tmp = left; + left = top; + top = -tmp; - private int clamp(int touchCoord) { - if (Math.abs(touchCoord) + FOCUS_AREA_SIZE / 2 > 1000) { - if (touchCoord > 0) { - return 1000 - FOCUS_AREA_SIZE / 2; - } else { - return -1000 + FOCUS_AREA_SIZE / 2; - } - } - - return touchCoord - FOCUS_AREA_SIZE / 2; + final int rectLeft = Math.max(left - FOCUS_AREA_SIZE / 2, -1000); + final int rectTop = Math.max(top - FOCUS_AREA_SIZE / 2, -1000); + final int rectRight = Math.min(left + FOCUS_AREA_SIZE / 2, 1000); + final int rectBottom = Math.min(top + FOCUS_AREA_SIZE / 2, 1000); + return new Rect(rectLeft, rectTop, rectRight, rectBottom); } public void releaseCamera() {