|
|
@ -32,7 +32,7 @@ class Camera1 extends CameraImpl { |
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = Camera1.class.getSimpleName(); |
|
|
|
private static final String TAG = Camera1.class.getSimpleName(); |
|
|
|
|
|
|
|
|
|
|
|
private static final int FOCUS_AREA_SIZE_DEFAULT = 300; |
|
|
|
private static final int FOCUS_AREA_SIZE_DEFAULT = 200; |
|
|
|
private static final int FOCUS_METERING_AREA_WEIGHT_DEFAULT = 1000; |
|
|
|
private static final int FOCUS_METERING_AREA_WEIGHT_DEFAULT = 1000; |
|
|
|
private static final int DELAY_MILLIS_BEFORE_RESETTING_FOCUS = 3000; |
|
|
|
private static final int DELAY_MILLIS_BEFORE_RESETTING_FOCUS = 3000; |
|
|
|
|
|
|
|
|
|
|
@ -61,6 +61,7 @@ class Camera1 extends CameraImpl { |
|
|
|
@SessionType private int mSessionType; |
|
|
|
@SessionType private int mSessionType; |
|
|
|
private double mLatitude; |
|
|
|
private double mLatitude; |
|
|
|
private double mLongitude; |
|
|
|
private double mLongitude; |
|
|
|
|
|
|
|
private boolean mFocusOnTap; |
|
|
|
|
|
|
|
|
|
|
|
private Handler mHandler = new Handler(); |
|
|
|
private Handler mHandler = new Handler(); |
|
|
|
private ConstantMapper.MapperImpl mMapper = new ConstantMapper.Mapper1(); |
|
|
|
private ConstantMapper.MapperImpl mMapper = new ConstantMapper.Mapper1(); |
|
|
@ -217,44 +218,39 @@ class Camera1 extends CameraImpl { |
|
|
|
void setFocus(@Focus int focus) { |
|
|
|
void setFocus(@Focus int focus) { |
|
|
|
int old = mFocus; |
|
|
|
int old = mFocus; |
|
|
|
mFocus = focus; |
|
|
|
mFocus = focus; |
|
|
|
|
|
|
|
if (mCameraParameters == null) return; |
|
|
|
switch (focus) { |
|
|
|
switch (focus) { |
|
|
|
case FOCUS_CONTINUOUS: |
|
|
|
case FOCUS_CONTINUOUS: |
|
|
|
if (mCameraParameters != null) { |
|
|
|
mFocusOnTap = false; |
|
|
|
detachFocusTapListener(); |
|
|
|
|
|
|
|
final List<String> modes = mCameraParameters.getSupportedFocusModes(); |
|
|
|
final List<String> modes = mCameraParameters.getSupportedFocusModes(); |
|
|
|
if (modes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { |
|
|
|
if (modes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { |
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); |
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mFocus = old; |
|
|
|
mFocus = old; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case FOCUS_TAP: |
|
|
|
case FOCUS_TAP: |
|
|
|
case FOCUS_TAP_WITH_MARKER: |
|
|
|
case FOCUS_TAP_WITH_MARKER: |
|
|
|
if (mCameraParameters != null) { |
|
|
|
mFocusOnTap = true; |
|
|
|
attachFocusTapListener(); |
|
|
|
final List<String> modes1 = mCameraParameters.getSupportedFocusModes(); |
|
|
|
final List<String> modes = mCameraParameters.getSupportedFocusModes(); |
|
|
|
if (modes1.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { |
|
|
|
if (modes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { |
|
|
|
|
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); |
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mFocus = old; |
|
|
|
mFocus = old; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case FOCUS_OFF: |
|
|
|
case FOCUS_OFF: |
|
|
|
if (mCameraParameters != null) { |
|
|
|
mFocusOnTap = false; |
|
|
|
detachFocusTapListener(); |
|
|
|
final List<String> modes2 = mCameraParameters.getSupportedFocusModes(); |
|
|
|
final List<String> modes = mCameraParameters.getSupportedFocusModes(); |
|
|
|
if (modes2.contains(Camera.Parameters.FOCUS_MODE_FIXED)) { |
|
|
|
if (modes.contains(Camera.Parameters.FOCUS_MODE_FIXED)) { |
|
|
|
|
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED); |
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED); |
|
|
|
} else if (modes.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) { |
|
|
|
} else if (modes2.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) { |
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); |
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
mCameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -421,8 +417,8 @@ class Camera1 extends CameraImpl { |
|
|
|
mCaptureSize = new Size(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight); |
|
|
|
mCaptureSize = new Size(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight); |
|
|
|
} |
|
|
|
} |
|
|
|
mPreviewSize = computePreviewSize(previewSizes, mCaptureSize, mPreview.getSurfaceSize()); |
|
|
|
mPreviewSize = computePreviewSize(previewSizes, mCaptureSize, mPreview.getSurfaceSize()); |
|
|
|
Log.e("Camera1", "CaptureSize is "+mCaptureSize.toString()); |
|
|
|
// Log.e("Camera1", "CaptureSize is "+mCaptureSize.toString());
|
|
|
|
Log.e("Camera1", "PreviewSize is "+mPreviewSize.toString()); |
|
|
|
// Log.e("Camera1", "PreviewSize is "+mPreviewSize.toString());
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void adjustCameraParameters() { |
|
|
|
private void adjustCameraParameters() { |
|
|
@ -433,8 +429,6 @@ class Camera1 extends CameraImpl { |
|
|
|
); |
|
|
|
); |
|
|
|
mCameraParameters.setPreviewSize(getPreviewSize().getWidth(), getPreviewSize().getHeight()); |
|
|
|
mCameraParameters.setPreviewSize(getPreviewSize().getWidth(), getPreviewSize().getHeight()); |
|
|
|
mCameraParameters.setPictureSize(getCaptureSize().getWidth(), getCaptureSize().getHeight()); |
|
|
|
mCameraParameters.setPictureSize(getCaptureSize().getWidth(), getCaptureSize().getHeight()); |
|
|
|
// int rotation = calculateCaptureRotation();
|
|
|
|
|
|
|
|
// mCameraParameters.setRotation(rotation);
|
|
|
|
|
|
|
|
setFocus(mFocus); |
|
|
|
setFocus(mFocus); |
|
|
|
setFlash(mFlash); |
|
|
|
setFlash(mFlash); |
|
|
|
setLocation(mLatitude, mLongitude); |
|
|
|
setLocation(mLatitude, mLongitude); |
|
|
@ -547,69 +541,30 @@ class Camera1 extends CameraImpl { |
|
|
|
// Tap to focus stuff.
|
|
|
|
// Tap to focus stuff.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setTapToAutofocusListener(Camera.AutoFocusCallback callback) { |
|
|
|
|
|
|
|
if (this.mFocus != FOCUS_TAP) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Please set the camera to FOCUS_TAP."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.mAutofocusCallback = callback; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getFocusAreaSize() { |
|
|
|
|
|
|
|
return FOCUS_AREA_SIZE_DEFAULT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getFocusMeteringAreaWeight() { |
|
|
|
|
|
|
|
return FOCUS_METERING_AREA_WEIGHT_DEFAULT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void detachFocusTapListener() { |
|
|
|
|
|
|
|
mPreview.getView().setOnTouchListener(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void attachFocusTapListener() { |
|
|
|
|
|
|
|
mPreview.getView().setOnTouchListener(new View.OnTouchListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean onTouch(View v, MotionEvent event) { |
|
|
|
void onTouchEvent(MotionEvent event) { |
|
|
|
if (event.getAction() != MotionEvent.ACTION_UP) return false; |
|
|
|
if (!mFocusOnTap) return; |
|
|
|
if (mCamera == null) return false; |
|
|
|
if (mCamera == null) return; |
|
|
|
|
|
|
|
if (event.getAction() != MotionEvent.ACTION_UP) return; |
|
|
|
Camera.Parameters parameters = mCamera.getParameters(); |
|
|
|
Camera.Parameters parameters = mCamera.getParameters(); |
|
|
|
String focusMode = parameters.getFocusMode(); |
|
|
|
String focusMode = parameters.getFocusMode(); |
|
|
|
Rect rect = calculateFocusArea(event.getX(), event.getY()); |
|
|
|
Rect rect = calculateFocusArea(event.getX(), event.getY()); |
|
|
|
List<Camera.Area> meteringAreas = new ArrayList<>(); |
|
|
|
List<Camera.Area> meteringAreas = new ArrayList<>(); |
|
|
|
meteringAreas.add(new Camera.Area(rect, getFocusMeteringAreaWeight())); |
|
|
|
meteringAreas.add(new Camera.Area(rect, getFocusMeteringAreaWeight())); |
|
|
|
if (parameters.getMaxNumFocusAreas() != 0 && focusMode != null && |
|
|
|
|
|
|
|
(focusMode.equals(Camera.Parameters.FOCUS_MODE_AUTO) || |
|
|
|
boolean focusSupported = parameters.getMaxNumFocusAreas() > 0 && focusMode != null; |
|
|
|
|
|
|
|
focusSupported = focusSupported && (focusMode.equals(Camera.Parameters.FOCUS_MODE_AUTO) || |
|
|
|
focusMode.equals(Camera.Parameters.FOCUS_MODE_MACRO) || |
|
|
|
focusMode.equals(Camera.Parameters.FOCUS_MODE_MACRO) || |
|
|
|
focusMode.equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) || |
|
|
|
focusMode.equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) || |
|
|
|
focusMode.equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) |
|
|
|
focusMode.equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)); |
|
|
|
) { |
|
|
|
boolean autofocusSupported = parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
boolean meteringAreaSupported = parameters.getMaxNumMeteringAreas() > 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (focusSupported) { |
|
|
|
parameters.setFocusAreas(meteringAreas); |
|
|
|
parameters.setFocusAreas(meteringAreas); |
|
|
|
if (parameters.getMaxNumMeteringAreas() > 0) { |
|
|
|
if (meteringAreaSupported) parameters.setMeteringAreas(meteringAreas); |
|
|
|
parameters.setMeteringAreas(meteringAreas); |
|
|
|
if (autofocusSupported) { |
|
|
|
} |
|
|
|
|
|
|
|
if(!parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_AUTO)) { |
|
|
|
|
|
|
|
return false; //cannot autoFocus
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mCamera.setParameters(parameters); |
|
|
|
|
|
|
|
mCamera.autoFocus(new Camera.AutoFocusCallback() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onAutoFocus(boolean success, Camera camera) { |
|
|
|
|
|
|
|
resetFocus(success, camera); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (parameters.getMaxNumMeteringAreas() > 0) { |
|
|
|
|
|
|
|
if(!parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_AUTO)) { |
|
|
|
|
|
|
|
return false; //cannot autoFocus
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); |
|
|
|
parameters.setFocusAreas(meteringAreas); |
|
|
|
|
|
|
|
parameters.setMeteringAreas(meteringAreas); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCamera.setParameters(parameters); |
|
|
|
mCamera.setParameters(parameters); |
|
|
|
mCamera.autoFocus(new Camera.AutoFocusCallback() { |
|
|
|
mCamera.autoFocus(new Camera.AutoFocusCallback() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -617,19 +572,18 @@ class Camera1 extends CameraImpl { |
|
|
|
resetFocus(success, camera); |
|
|
|
resetFocus(success, camera); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
|
|
|
|
mCamera.autoFocus(new Camera.AutoFocusCallback() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onAutoFocus(boolean success, Camera camera) { |
|
|
|
|
|
|
|
if (mAutofocusCallback != null) { |
|
|
|
|
|
|
|
mAutofocusCallback.onAutoFocus(success, camera); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getFocusAreaSize() { |
|
|
|
|
|
|
|
return FOCUS_AREA_SIZE_DEFAULT; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getFocusMeteringAreaWeight() { |
|
|
|
|
|
|
|
return FOCUS_METERING_AREA_WEIGHT_DEFAULT; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -648,9 +602,7 @@ class Camera1 extends CameraImpl { |
|
|
|
camera.setParameters(params); |
|
|
|
camera.setParameters(params); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (mAutofocusCallback != null) { |
|
|
|
if (mAutofocusCallback != null) mAutofocusCallback.onAutoFocus(success, camera); |
|
|
|
mAutofocusCallback.onAutoFocus(success, camera); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, DELAY_MILLIS_BEFORE_RESETTING_FOCUS); |
|
|
|
}, DELAY_MILLIS_BEFORE_RESETTING_FOCUS); |
|
|
|