Add setLocation() for geo exif tags

pull/1/head
Mattia Iavarone 7 years ago
parent f644bfdfef
commit f43af464f9
  1. 6
      README.md
  2. 24
      camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
  3. 15
      camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java
  4. 3
      camerakit/src/main/base/com/flurgle/camerakit/CameraImpl.java
  5. 19
      camerakit/src/main/base/com/flurgle/camerakit/PreviewImpl.java
  6. 4
      camerakit/src/main/base/com/flurgle/camerakit/TextureViewPreview.java
  7. 17
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
  8. 1
      camerakit/src/main/res/layout/texture_view.xml
  9. 2
      camerakit/src/main/res/values/attrs.xml
  10. 14
      camerakit/src/main/types/com/flurgle/camerakit/Zoom.java

@ -18,7 +18,7 @@ CameraKit is an easy to use utility to work with the Android Camera APIs. Everyt
- [cameraFlash](#cameraflash) - [cameraFlash](#cameraflash)
- [cameraFocus](#camerafocus) - [cameraFocus](#camerafocus)
- [cameraCaptureMethod](#cameracapturemethod) - [cameraCaptureMethod](#cameracapturemethod)
- [cameraZoom](#camerazoom) - [cameraZoomMode](#camerazoommode)
- [cameraCropOutput](#cameracropoutput) - [cameraCropOutput](#cameracropoutput)
- [cameraJpegQuality](#camerajpegquality) - [cameraJpegQuality](#camerajpegquality)
- [Permissions Behavior](#permissions-behavior) - [Permissions Behavior](#permissions-behavior)
@ -166,7 +166,7 @@ camera.setCameraListener(new CameraListener() {
|[`cameraFlash`](#cameraflash)|`setFlash()`|`off` `on` `auto` `torch`|`off`| |[`cameraFlash`](#cameraflash)|`setFlash()`|`off` `on` `auto` `torch`|`off`|
|[`cameraFocus`](#camerafocus)|`setFocus()`|`off` `continuous` `tap` `tapWithMarker`|`continuous`| |[`cameraFocus`](#camerafocus)|`setFocus()`|`off` `continuous` `tap` `tapWithMarker`|`continuous`|
|[`cameraCaptureMethod`](#cameracapturemethod)|`setCaptureMethod()`|`standard` `frame`|`standard`| |[`cameraCaptureMethod`](#cameracapturemethod)|`setCaptureMethod()`|`standard` `frame`|`standard`|
|[`cameraZoom`](#camerazoom)|`setZoom()`|`off` `pinch`|`off`| |[`cameraZoomMode`](#camerazoommode)|`setZoom()`|`off` `pinch`|`off`|
|[`cameraPermissionPolicy`](#camerapermissionpolicy)|`setPermissionPolicy()`|`picture` `video`|`picture`| |[`cameraPermissionPolicy`](#camerapermissionpolicy)|`setPermissionPolicy()`|`picture` `video`|`picture`|
|[`cameraCropOutput`](#cameracropoutput)|`setCropOutput()`|`true` `false`|`false`| |[`cameraCropOutput`](#cameracropoutput)|`setCropOutput()`|`true` `false`|`false`|
|[`cameraJpegQuality`](#camerajpegquality)|`setJpegQuality()`|`0 <= n <= 100`|`100`| |[`cameraJpegQuality`](#camerajpegquality)|`setJpegQuality()`|`0 <= n <= 100`|`100`|
@ -213,7 +213,7 @@ cameraView.setMethod(CameraKit.Constants.CAPTURE_METHOD_STANDARD);
cameraView.setMethod(CameraKit.Constants.CAPTURE_METHOD_FRAME); cameraView.setMethod(CameraKit.Constants.CAPTURE_METHOD_FRAME);
``` ```
### cameraZoom ### cameraZoomMode
TODO: work in progress. Right now 'off' is the onlly option. TODO: work in progress. Right now 'off' is the onlly option.

@ -54,16 +54,18 @@ class Camera1 extends CameraImpl {
@Flash private int mFlash; @Flash private int mFlash;
@Focus private int mFocus; @Focus private int mFocus;
@Method private int mMethod; @Method private int mMethod;
@Zoom private int mZoom; @ZoomMode private int mZoom;
@VideoQuality private int mVideoQuality; @VideoQuality private int mVideoQuality;
private double mLatitude;
private double mLongitude;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
Camera1(CameraListener callback, PreviewImpl preview) { Camera1(CameraListener callback, PreviewImpl preview) {
super(callback, preview); super(callback, preview);
preview.setCallback(new PreviewImpl.OnSurfaceChangedCallback() { preview.setCallback(new PreviewImpl.OnPreviewSurfaceChangedCallback() {
@Override @Override
public void onSurfaceChanged() { public void onPreviewSurfaceChanged() {
if (mCamera != null) { if (mCamera != null) {
setupPreview(); setupPreview();
collectCameraSizes(); collectCameraSizes();
@ -121,6 +123,17 @@ class Camera1 extends CameraImpl {
this.mDeviceOrientation = deviceOrientation; this.mDeviceOrientation = deviceOrientation;
} }
@Override
void setLocation(double latitude, double longitude) {
mLatitude = latitude;
mLongitude = longitude;
if (mCameraParameters != null) {
mCameraParameters.setGpsLatitude(latitude);
mCameraParameters.setGpsLongitude(longitude);
mCamera.setParameters(mCameraParameters);
}
}
@Override @Override
void setFacing(@Facing int facing) { void setFacing(@Facing int facing) {
int internalFacing = new ConstantMapper.Facing(facing).map(); int internalFacing = new ConstantMapper.Facing(facing).map();
@ -214,7 +227,7 @@ class Camera1 extends CameraImpl {
} }
@Override @Override
void setZoom(@Zoom int zoom) { void setZoom(@ZoomMode int zoom) {
this.mZoom = zoom; this.mZoom = zoom;
} }
@ -373,7 +386,7 @@ class Camera1 extends CameraImpl {
* This is called either on cameraView.start(), or when the underlying surface changes. * This is called either on cameraView.start(), or when the underlying surface changes.
* It is possible that in the first call the preview surface has not already computed its * It is possible that in the first call the preview surface has not already computed its
* dimensions. * dimensions.
* But when it does, the {@link PreviewImpl.OnSurfaceChangedCallback} should be called, * But when it does, the {@link PreviewImpl.OnPreviewSurfaceChangedCallback} should be called,
* and this should be refreshed. * and this should be refreshed.
* *
* *
@ -406,6 +419,7 @@ class Camera1 extends CameraImpl {
// mCameraParameters.setRotation(rotation); // mCameraParameters.setRotation(rotation);
setFocus(mFocus); setFocus(mFocus);
setFlash(mFlash); setFlash(mFlash);
setLocation(mLatitude, mLongitude);
mCamera.setParameters(mCameraParameters); mCamera.setParameters(mCameraParameters);
} }

@ -35,9 +35,9 @@ class Camera2 extends CameraImpl {
Camera2(CameraListener callback, PreviewImpl preview, Context context) { Camera2(CameraListener callback, PreviewImpl preview, Context context) {
super(callback, preview); super(callback, preview);
preview.setCallback(new PreviewImpl.OnSurfaceChangedCallback() { preview.setCallback(new PreviewImpl.OnPreviewSurfaceChangedCallback() {
@Override @Override
public void onSurfaceChanged() { public void onPreviewSurfaceChanged() {
} }
}); });
@ -65,8 +65,8 @@ class Camera2 extends CameraImpl {
float w = size.getWidth(); float w = size.getWidth();
float h = size.getHeight(); float h = size.getHeight();
mCameraPropertyMap.put(cameraId, new CameraProperties( mCameraPropertyMap.put(cameraId, new CameraProperties(
(float) Math.toDegrees(2*Math.atan(size.getWidth()/(maxFocus[0]*2))), (float) Math.toDegrees(2*Math.atan(w/(maxFocus[0]*2))),
(float) Math.toDegrees(2*Math.atan(size.getHeight()/(maxFocus[0]*2))) (float) Math.toDegrees(2*Math.atan(h/(maxFocus[0]*2)))
)); ));
} }
} }
@ -155,7 +155,12 @@ class Camera2 extends CameraImpl {
} }
@Override @Override
void setZoom(@Zoom int zoom) { void setZoom(@ZoomMode int zoom) {
}
@Override
void setLocation(double latitude, double longitude) {
} }

@ -22,8 +22,9 @@ abstract class CameraImpl {
abstract void setFlash(@Flash int flash); abstract void setFlash(@Flash int flash);
abstract void setFocus(@Focus int focus); abstract void setFocus(@Focus int focus);
abstract void setMethod(@Method int method); abstract void setMethod(@Method int method);
abstract void setZoom(@Zoom int zoom); abstract void setZoom(@ZoomMode int zoom);
abstract void setVideoQuality(@VideoQuality int videoQuality); abstract void setVideoQuality(@VideoQuality int videoQuality);
abstract void setLocation(double latitude, double longitude);
abstract void captureImage(); abstract void captureImage();
abstract void startVideo(); abstract void startVideo();

@ -1,18 +1,17 @@
package com.flurgle.camerakit; package com.flurgle.camerakit;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.util.Log;
import android.view.Surface; import android.view.Surface;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.View; import android.view.View;
abstract class PreviewImpl { abstract class PreviewImpl {
interface OnSurfaceChangedCallback { interface OnPreviewSurfaceChangedCallback {
void onSurfaceChanged(); void onPreviewSurfaceChanged();
} }
private OnSurfaceChangedCallback mOnSurfaceChangedCallback; private OnPreviewSurfaceChangedCallback mOnPreviewSurfaceChangedCallback;
// As far as I can see, these are the view/surface dimensions. // As far as I can see, these are the view/surface dimensions.
// This live in the 'View' orientation. // This live in the 'View' orientation.
@ -23,8 +22,8 @@ abstract class PreviewImpl {
private int mDesiredWidth; private int mDesiredWidth;
private int mDesiredHeight; private int mDesiredHeight;
void setCallback(OnSurfaceChangedCallback callback) { void setCallback(OnPreviewSurfaceChangedCallback callback) {
mOnSurfaceChangedCallback = callback; mOnPreviewSurfaceChangedCallback = callback;
} }
abstract Surface getSurface(); abstract Surface getSurface();
@ -39,7 +38,7 @@ abstract class PreviewImpl {
abstract boolean isReady(); abstract boolean isReady();
protected void dispatchSurfaceChanged() { protected void dispatchSurfaceChanged() {
mOnSurfaceChangedCallback.onSurfaceChanged(); mOnPreviewSurfaceChangedCallback.onPreviewSurfaceChanged();
} }
SurfaceHolder getSurfaceHolder() { SurfaceHolder getSurfaceHolder() {
@ -51,8 +50,7 @@ abstract class PreviewImpl {
} }
// As far as I can see, these are the view/surface dimensions. // As far as I can see, these are the view/surface dimensions.
// This is called by subclasses. 1080, 1794 -- 1080, 1440 // This is called by subclasses.
protected void setSurfaceSize(int width, int height) { protected void setSurfaceSize(int width, int height) {
this.mSurfaceWidth = width; this.mSurfaceWidth = width;
this.mSurfaceHeight = height; this.mSurfaceHeight = height;
@ -60,7 +58,8 @@ abstract class PreviewImpl {
} }
// As far as I can see, these are the actual preview dimensions, as set in CameraParameters. // As far as I can see, these are the actual preview dimensions, as set in CameraParameters.
// This is called by the CameraImpl. 1200, 1600 // This is called by the CameraImpl.
// These must be alredy rotated, if needed, to be consistent with surface/view sizes.
void setDesiredSize(int width, int height) { void setDesiredSize(int width, int height) {
this.mDesiredWidth = width; this.mDesiredWidth = width;
this.mDesiredHeight = height; this.mDesiredHeight = height;

@ -45,7 +45,7 @@ class TextureViewPreview extends PreviewImpl {
@Override @Override
Surface getSurface() { Surface getSurface() {
return new Surface(mTextureView.getSurfaceTexture()); return new Surface(getSurfaceTexture());
} }
@Override @Override
@ -60,7 +60,7 @@ class TextureViewPreview extends PreviewImpl {
@Override @Override
boolean isReady() { boolean isReady() {
return mTextureView.getSurfaceTexture() != null; return getSurfaceTexture() != null;
} }
@Override @Override

@ -80,7 +80,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@Flash private int mFlash; @Flash private int mFlash;
@Focus private int mFocus; @Focus private int mFocus;
@Method private int mMethod; @Method private int mMethod;
@Zoom private int mZoom; @ZoomMode
private int mZoom;
@Permissions private int mPermissions; @Permissions private int mPermissions;
@VideoQuality private int mVideoQuality; @VideoQuality private int mVideoQuality;
private int mJpegQuality; private int mJpegQuality;
@ -113,7 +114,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mFlash = a.getInteger(R.styleable.CameraView_cameraFlash, CameraKit.Defaults.DEFAULT_FLASH); mFlash = a.getInteger(R.styleable.CameraView_cameraFlash, CameraKit.Defaults.DEFAULT_FLASH);
mFocus = a.getInteger(R.styleable.CameraView_cameraFocus, CameraKit.Defaults.DEFAULT_FOCUS); mFocus = a.getInteger(R.styleable.CameraView_cameraFocus, CameraKit.Defaults.DEFAULT_FOCUS);
mMethod = a.getInteger(R.styleable.CameraView_cameraCaptureMethod, CameraKit.Defaults.DEFAULT_METHOD); mMethod = a.getInteger(R.styleable.CameraView_cameraCaptureMethod, CameraKit.Defaults.DEFAULT_METHOD);
mZoom = a.getInteger(R.styleable.CameraView_cameraZoom, CameraKit.Defaults.DEFAULT_ZOOM); mZoom = a.getInteger(R.styleable.CameraView_cameraZoomMode, CameraKit.Defaults.DEFAULT_ZOOM);
mPermissions = a.getInteger(R.styleable.CameraView_cameraPermissionPolicy, CameraKit.Defaults.DEFAULT_PERMISSIONS); mPermissions = a.getInteger(R.styleable.CameraView_cameraPermissionPolicy, CameraKit.Defaults.DEFAULT_PERMISSIONS);
mVideoQuality = a.getInteger(R.styleable.CameraView_cameraVideoQuality, CameraKit.Defaults.DEFAULT_VIDEO_QUALITY); mVideoQuality = a.getInteger(R.styleable.CameraView_cameraVideoQuality, CameraKit.Defaults.DEFAULT_VIDEO_QUALITY);
mJpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, CameraKit.Defaults.DEFAULT_JPEG_QUALITY); mJpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, CameraKit.Defaults.DEFAULT_JPEG_QUALITY);
@ -355,6 +356,16 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
return mCameraImpl.getCameraProperties(); return mCameraImpl.getCameraProperties();
} }
/**
* Set location coordinates to be found later in the jpeg EXIF header
* @param latitude current latitude
* @param longitude current longitude
*/
public void setLocation(double latitude, double longitude) {
mCameraImpl.setLocation(latitude, longitude);
}
@Facing @Facing
public int getFacing() { public int getFacing() {
return mFacing; return mFacing;
@ -396,7 +407,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mCameraImpl.setMethod(mMethod); mCameraImpl.setMethod(mMethod);
} }
public void setZoom(@Zoom int zoom) { public void setZoom(@ZoomMode int zoom) {
this.mZoom = zoom; this.mZoom = zoom;
mCameraImpl.setZoom(mZoom); mCameraImpl.setZoom(mZoom);
} }

@ -3,6 +3,7 @@
<TextureView <TextureView
android:id="@+id/texture_view" android:id="@+id/texture_view"
android:gravity="center"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />

@ -22,7 +22,7 @@
<enum name="tapWithMarker" value="3" /> <enum name="tapWithMarker" value="3" />
</attr> </attr>
<attr name="cameraZoom" format="enum"> <attr name="cameraZoomMode" format="enum">
<enum name="off" value="0" /> <enum name="off" value="0" />
<!-- TODO: Set to unique value when feature added --> <!-- TODO: Set to unique value when feature added -->

@ -1,14 +0,0 @@
package com.flurgle.camerakit;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static com.flurgle.camerakit.CameraKit.Constants.ZOOM_OFF;
import static com.flurgle.camerakit.CameraKit.Constants.ZOOM_PINCH;
@Retention(RetentionPolicy.SOURCE)
@IntDef({ZOOM_OFF, ZOOM_PINCH})
public @interface Zoom {
}
Loading…
Cancel
Save