Skip to content

Commit

Permalink
not using focus/autofocus if camera don't support it
Browse files Browse the repository at this point in the history
  • Loading branch information
shliama committed Oct 7, 2014
1 parent fa70432 commit 901fd33
Showing 1 changed file with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,31 @@
package com.yalantis.cameramodule.control;

import android.app.Activity;
import android.graphics.*;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
import android.hardware.Camera;
import android.view.*;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageView;

import com.yalantis.cameramodule.interfaces.FocusCallback;
import com.yalantis.cameramodule.interfaces.KeyEventsListener;
import com.yalantis.cameramodule.model.FocusMode;
import timber.log.Timber;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

import timber.log.Timber;

public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback, Camera.AutoFocusCallback {

Expand Down Expand Up @@ -141,15 +155,21 @@ private void startFocusing() {
}

public void takePicture() {
if (focusMode == FocusMode.AUTO) {
startFocusing();
}
if (focusMode == FocusMode.TOUCH) {
if (focused && tapArea != null) {
focused();
} else {
List<String> supportedFocusModes = camera.getParameters().getSupportedFocusModes();
boolean hasAutoFocus = supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO);
if (hasAutoFocus) {
if (focusMode == FocusMode.AUTO) {
startFocusing();
}
if (focusMode == FocusMode.TOUCH) {
if (focused && tapArea != null) {
focused();
} else {
startFocusing();
}
}
} else {
focused();
}
}

Expand Down Expand Up @@ -206,7 +226,7 @@ private void clearCameraFocus() {
camera.setParameters(parameters);
} catch (Exception e) {
Timber.e(e, "clearCameraFocus");
} finally {
} finally {
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvasFrame.draw(canvas);
canvasFrame.invalidate();
Expand Down Expand Up @@ -323,7 +343,8 @@ private void scale(float scaleFactor) {

private class CameraTouchListener implements OnTouchListener {

private ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(activity, new ScaleListener());;
private ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(activity, new ScaleListener());
;
private GestureDetector mTapDetector = new GestureDetector(activity, new TapListener());

@Override
Expand Down

0 comments on commit 901fd33

Please sign in to comment.