Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timob-9845: Android: Camera with overlay does not auto focus #3578

Merged
merged 1 commit into from
Dec 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public class MediaModule extends KrollModule
protected static final int MSG_INVOKE_CALLBACK = KrollModule.MSG_LAST_ID + 100;
protected static final int MSG_LAST_ID = MSG_INVOKE_CALLBACK;

// The mode FOCUS_MODE_CONTINUOUS_PICTURE is added in API 14
public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";

@Kroll.constant public static final int UNKNOWN_ERROR = 0;
@Kroll.constant public static final int DEVICE_BUSY = 1;
@Kroll.constant public static final int NO_CAMERA = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.Size;
Expand Down Expand Up @@ -119,6 +120,17 @@ public void surfaceChanged(SurfaceHolder previewHolder, int format, int width, i
previewLayout.setAspectRatio(aspectRatio);
List<Size> supportedPreviewSizes = param.getSupportedPreviewSizes();
Size previewSize = getOptimalPreviewSize(supportedPreviewSizes, width, height, aspectRatio);

// Set appropriate focus mode if supported.
List<String> supportedFocusModes = param.getSupportedFocusModes();
if (supportedFocusModes.contains(MediaModule.FOCUS_MODE_CONTINUOUS_PICTURE)) {
param.setFocusMode(MediaModule.FOCUS_MODE_CONTINUOUS_PICTURE);
} else if (supportedFocusModes.contains(Parameters.FOCUS_MODE_AUTO)) {
param.setFocusMode(Parameters.FOCUS_MODE_AUTO);
} else if (supportedFocusModes.contains(Parameters.FOCUS_MODE_MACRO)) {
param.setFocusMode(Parameters.FOCUS_MODE_MACRO);
}

if (previewSize != null) {
param.setPreviewSize(previewSize.width, previewSize.height);
camera.setParameters(param);
Expand Down Expand Up @@ -268,8 +280,23 @@ private static void saveToPhotoGallery(byte[] data) {
activity.sendBroadcast(mediaScanIntent);
}

static public void takePicture() {
camera.takePicture(null, null, jpegCallback);
static public void takePicture()
{
String focusMode = camera.getParameters().getFocusMode();
if (!(focusMode.equals(Parameters.FOCUS_MODE_EDOF) || focusMode.equals(Parameters.FOCUS_MODE_FIXED)
|| focusMode.equals(Parameters.FOCUS_MODE_INFINITY))) {
AutoFocusCallback focusCallback = new AutoFocusCallback()
{
public void onAutoFocus(boolean success, Camera camera)
{
// Take the picture when the camera auto focus completes.
camera.takePicture(null, null, jpegCallback);
}
};
camera.autoFocus(focusCallback);
} else {
camera.takePicture(null, null, jpegCallback);
}
}

static PictureCallback jpegCallback = new PictureCallback() {
Expand Down