FilterCameraPreview as interface, better CameraPreview APIs

pull/816/head
Mattia Iavarone 5 years ago
parent 5530c011fa
commit dc5cdd35a5
  1. 2
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/preview/MockCameraPreview.java
  2. 25
      cameraview/src/main/java/com/otaliastudios/cameraview/preview/CameraPreview.java
  3. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/preview/FilterCameraPreview.java
  4. 5
      cameraview/src/main/java/com/otaliastudios/cameraview/preview/GlCameraPreview.java
  5. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/preview/SurfaceCameraPreview.java
  6. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/preview/TextureCameraPreview.java

@ -10,7 +10,7 @@ import android.view.ViewGroup;
import com.otaliastudios.cameraview.filter.Filter; import com.otaliastudios.cameraview.filter.Filter;
import com.otaliastudios.cameraview.preview.CameraPreview; import com.otaliastudios.cameraview.preview.CameraPreview;
public class MockCameraPreview extends FilterCameraPreview<View, Void> { public class MockCameraPreview extends CameraPreview<View, Void> implements FilterCameraPreview {
public MockCameraPreview(Context context, ViewGroup parent) { public MockCameraPreview(Context context, ViewGroup parent) {
super(context, parent); super(context, parent);

@ -62,18 +62,24 @@ public abstract class CameraPreview<T extends View, Output> {
@VisibleForTesting CropCallback mCropCallback; @VisibleForTesting CropCallback mCropCallback;
private SurfaceCallback mSurfaceCallback; private SurfaceCallback mSurfaceCallback;
private T mView; private T mView;
boolean mCropping; @SuppressWarnings("WeakerAccess")
protected boolean mCropping;
// These are the surface dimensions in REF_VIEW. // These are the surface dimensions in REF_VIEW.
int mOutputSurfaceWidth; @SuppressWarnings("WeakerAccess")
int mOutputSurfaceHeight; protected int mOutputSurfaceWidth;
@SuppressWarnings("WeakerAccess")
protected int mOutputSurfaceHeight;
// These are the preview stream dimensions, in REF_VIEW. // These are the preview stream dimensions, in REF_VIEW.
int mInputStreamWidth; @SuppressWarnings("WeakerAccess")
int mInputStreamHeight; protected int mInputStreamWidth;
@SuppressWarnings("WeakerAccess")
protected int mInputStreamHeight;
// The rotation, if any, to be applied when drawing. // The rotation, if any, to be applied when drawing.
int mDrawRotation; @SuppressWarnings("WeakerAccess")
protected int mDrawRotation;
/** /**
* Creates a new preview. * Creates a new preview.
@ -88,7 +94,7 @@ public abstract class CameraPreview<T extends View, Output> {
* Sets a callback to be notified of surface events (creation, change, destruction) * Sets a callback to be notified of surface events (creation, change, destruction)
* @param callback a callback * @param callback a callback
*/ */
public final void setSurfaceCallback(@Nullable SurfaceCallback callback) { public void setSurfaceCallback(@Nullable SurfaceCallback callback) {
if (hasSurface() && mSurfaceCallback != null) { if (hasSurface() && mSurfaceCallback != null) {
mSurfaceCallback.onSurfaceDestroyed(); mSurfaceCallback.onSurfaceDestroyed();
} }
@ -124,9 +130,8 @@ public abstract class CameraPreview<T extends View, Output> {
* @return the root view * @return the root view
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
@VisibleForTesting
@NonNull @NonNull
abstract View getRootView(); public abstract View getRootView();
/** /**
* Returns the output surface object (for example a SurfaceHolder * Returns the output surface object (for example a SurfaceHolder
@ -162,7 +167,7 @@ public abstract class CameraPreview<T extends View, Output> {
* Returns the current input stream size, in view coordinates. * Returns the current input stream size, in view coordinates.
* @return the current input stream size * @return the current input stream size
*/ */
@SuppressWarnings("unused") @VisibleForTesting
@NonNull @NonNull
final Size getStreamSize() { final Size getStreamSize() {
return new Size(mInputStreamWidth, mInputStreamHeight); return new Size(mInputStreamWidth, mInputStreamHeight);

@ -16,18 +16,13 @@ import com.otaliastudios.cameraview.filter.Filter;
* The preview has the responsibility of calling {@link Filter#setSize(int, int)} * The preview has the responsibility of calling {@link Filter#setSize(int, int)}
* whenever the preview size changes and as soon as the filter is applied. * whenever the preview size changes and as soon as the filter is applied.
*/ */
public abstract class FilterCameraPreview<T extends View, Output> extends CameraPreview<T, Output> { public interface FilterCameraPreview {
@SuppressWarnings("WeakerAccess")
public FilterCameraPreview(@NonNull Context context, @NonNull ViewGroup parent) {
super(context, parent);
}
/** /**
* Sets a new filter. * Sets a new filter.
* @param filter new filter * @param filter new filter
*/ */
public abstract void setFilter(@NonNull Filter filter); void setFilter(@NonNull Filter filter);
/** /**
* Returns the currently used filter. * Returns the currently used filter.
@ -35,5 +30,5 @@ public abstract class FilterCameraPreview<T extends View, Output> extends Camera
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
@NonNull @NonNull
public abstract Filter getCurrentFilter(); Filter getCurrentFilter();
} }

@ -60,7 +60,8 @@ import javax.microedition.khronos.opengles.GL10;
* which means that we can fetch the GL context that was created and is managed * which means that we can fetch the GL context that was created and is managed
* by the {@link GLSurfaceView}. * by the {@link GLSurfaceView}.
*/ */
public class GlCameraPreview extends FilterCameraPreview<GLSurfaceView, SurfaceTexture> { public class GlCameraPreview extends CameraPreview<GLSurfaceView, SurfaceTexture>
implements FilterCameraPreview {
private boolean mDispatched; private boolean mDispatched;
private SurfaceTexture mInputSurfaceTexture; private SurfaceTexture mInputSurfaceTexture;
@ -110,7 +111,7 @@ public class GlCameraPreview extends FilterCameraPreview<GLSurfaceView, SurfaceT
@NonNull @NonNull
@Override @Override
View getRootView() { public View getRootView() {
return mRootView; return mRootView;
} }

@ -75,7 +75,7 @@ public class SurfaceCameraPreview extends CameraPreview<SurfaceView, SurfaceHold
@NonNull @NonNull
@Override @Override
View getRootView() { public View getRootView() {
return mRootView; return mRootView;
} }

@ -68,7 +68,7 @@ public class TextureCameraPreview extends CameraPreview<TextureView, SurfaceText
@NonNull @NonNull
@Override @Override
View getRootView() { public View getRootView() {
return mRootView; return mRootView;
} }

Loading…
Cancel
Save