Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ public final class AutoFocusManager {

private static final String TAG = AutoFocusManager.class.getSimpleName();

private static final long AUTO_FOCUS_INTERVAL_MS = 2000L;

private boolean stopped;
private boolean focusing;
private final boolean useAutoFocus;
private long autoFocusDelay;
private final Camera camera;
private Handler handler;

Expand Down Expand Up @@ -76,13 +75,14 @@ public AutoFocusManager(Camera camera, CameraSettings settings) {
this.camera = camera;
String currentFocusMode = camera.getParameters().getFocusMode();
useAutoFocus = settings.isAutoFocusEnabled() && FOCUS_MODES_CALLING_AF.contains(currentFocusMode);
autoFocusDelay = settings.getAutoFocusDelay();
Log.i(TAG, "Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus);
start();
}

private synchronized void autoFocusAgainLater() {
if (!stopped && !handler.hasMessages(MESSAGE_FOCUS)) {
handler.sendMessageDelayed(handler.obtainMessage(MESSAGE_FOCUS), AUTO_FOCUS_INTERVAL_MS);
handler.sendMessageDelayed(handler.obtainMessage(MESSAGE_FOCUS), autoFocusDelay);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CameraSettings {
private boolean barcodeSceneModeEnabled = false;
private boolean meteringEnabled = false;
private boolean autoFocusEnabled = true;
private long autoFocusDelay = 2000L;
private boolean continuousFocusEnabled = false;
private boolean exposureEnabled = false;
private boolean autoTorchEnabled = false;
Expand Down Expand Up @@ -114,6 +115,19 @@ public void setAutoFocusEnabled(boolean autoFocusEnabled) {
}
}

/**
* Returns the delay of auto-focus, in milliseconds
*
* @return delay in milliseconds
*/
public long getAutoFocusDelay() {
return autoFocusDelay;
}

public void setAutoFocusDelay(long autoFocusDelay) {
this.autoFocusDelay = autoFocusDelay;
}

/**
* Default to false.
*
Expand Down