Is it possible to set the focus area in an Android camera application without any touch interaction, but by coordinates, which are received via a Network?
UPDATE: So far I tried the following code snippet:
public void doFocus(final Rect focusRect) {
try {
if (camera != null) {
List<Area> focusList = new ArrayList<Area>();
Area focusArea = new Area(focusRect, 1000);
focusList.add(focusArea);
Parameters param = camera.getParameters();
//param.setFocusMode(Parameters.FOCUS_MODE_AUTO);
Log.d(TAG, param.getMaxNumFocusAreas() + ";" + param.getMaxNumMeteringAreas() + " >> " + focusRect.toString());
param.setFocusAreas(focusList);
param.setMeteringAreas(focusList);
camera.setParameters(param);
camera.autoFocus(autoFocusCallback);
}
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "Unable to autofocus");
}
}
This method is called in here:
// Fixation of focus with touch
public void setCoordinates() {
float x = new MainActivity().coordinates().get(0);
float y = 1490f - (new MainActivity().coordinates().get(1)); //previewHeight minus input to get y coord in Android
Rect rect = new Rect(
(int) (x - 100),
(int) (y - 100),
(int) (x + 100),
(int) (y + 100));
final Rect targetFocusRect = new Rect(
rect.left * 2000 / previewWidth - 1000,
rect.top * 2000 / previewHeight - 1000,
rect.right * 2000 / previewWidth - 1000,
rect.bottom * 2000 / previewHeight - 1000);
out.println("FINAL RECT:" + targetFocusRect);
cameraPreview.doFocus(targetFocusRect);
}
This code works fine with touch input, but since I modified it and put only specific coordinates, the focus won't be set.