mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-01 15:56:44 +01:00
fix touch to focus by rotating the matrix
This commit is contained in:
parent
b319fcb8b5
commit
a08e526815
@ -162,8 +162,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
camera.cancelAutoFocus();
|
camera.cancelAutoFocus();
|
||||||
Rect focusRect = calculateFocusArea(event.getX(), event.getY());
|
final Rect focusRect = calculateFocusArea(event.getX(), event.getY());
|
||||||
|
|
||||||
final Camera.Parameters parameters = camera.getParameters();
|
final Camera.Parameters parameters = camera.getParameters();
|
||||||
if (parameters.getMaxNumFocusAreas() > 0) {
|
if (parameters.getMaxNumFocusAreas() > 0) {
|
||||||
final List<Camera.Area> focusAreas = new ArrayList<>(1);
|
final List<Camera.Area> 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) {
|
private Rect calculateFocusArea(float x, float y) {
|
||||||
int left = clamp(Float.valueOf((x / surfaceView.getWidth()) * 2000 - 1000).intValue());
|
int left = Float.valueOf((x / surfaceView.getWidth()) * 2000 - 1000).intValue();
|
||||||
int top = clamp(Float.valueOf((y / surfaceView.getHeight()) * 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) {
|
final int rectLeft = Math.max(left - FOCUS_AREA_SIZE / 2, -1000);
|
||||||
if (Math.abs(touchCoord) + FOCUS_AREA_SIZE / 2 > 1000) {
|
final int rectTop = Math.max(top - FOCUS_AREA_SIZE / 2, -1000);
|
||||||
if (touchCoord > 0) {
|
final int rectRight = Math.min(left + FOCUS_AREA_SIZE / 2, 1000);
|
||||||
return 1000 - FOCUS_AREA_SIZE / 2;
|
final int rectBottom = Math.min(top + FOCUS_AREA_SIZE / 2, 1000);
|
||||||
} else {
|
return new Rect(rectLeft, rectTop, rectRight, rectBottom);
|
||||||
return -1000 + FOCUS_AREA_SIZE / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return touchCoord - FOCUS_AREA_SIZE / 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseCamera() {
|
public void releaseCamera() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user