|
|
|
@ -12,41 +12,38 @@ import android.view.ViewGroup; |
|
|
|
|
// Currently this does NOT support cropping (e. g. the crop inside behavior),
|
|
|
|
|
// so we return false in supportsCropping() in order to have proper measuring.
|
|
|
|
|
// This means that CameraView is forced to be wrap_content.
|
|
|
|
|
class SurfaceCameraPreview extends CameraPreview<View, SurfaceHolder> { |
|
|
|
|
class SurfaceCameraPreview extends CameraPreview<SurfaceView, SurfaceHolder> { |
|
|
|
|
|
|
|
|
|
private final static CameraLogger LOG = CameraLogger.create(SurfaceCameraPreview.class.getSimpleName()); |
|
|
|
|
|
|
|
|
|
private boolean mDispatched; |
|
|
|
|
|
|
|
|
|
SurfaceCameraPreview(Context context, ViewGroup parent, SurfaceCallback callback) { |
|
|
|
|
super(context, parent, callback); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private SurfaceView mSurfaceView; |
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
@Override |
|
|
|
|
protected View onCreateView(Context context, ViewGroup parent) { |
|
|
|
|
protected SurfaceView onCreateView(Context context, ViewGroup parent) { |
|
|
|
|
View root = LayoutInflater.from(context).inflate(R.layout.cameraview_surface_view, parent, false); |
|
|
|
|
parent.addView(root, 0); |
|
|
|
|
mSurfaceView = root.findViewById(R.id.surface_view); |
|
|
|
|
final SurfaceHolder holder = mSurfaceView.getHolder(); |
|
|
|
|
SurfaceView surfaceView = root.findViewById(R.id.surface_view); |
|
|
|
|
final SurfaceHolder holder = surfaceView.getHolder(); |
|
|
|
|
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); |
|
|
|
|
holder.addCallback(new SurfaceHolder.Callback() { |
|
|
|
|
|
|
|
|
|
private boolean mFirstTime = true; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void surfaceCreated(SurfaceHolder holder) { |
|
|
|
|
// Looks like this is too early to call anything.
|
|
|
|
|
// This is too early to call anything.
|
|
|
|
|
// surfaceChanged is guaranteed to be called after, with exact dimensions.
|
|
|
|
|
LOG.i("callback:", "surfaceCreated"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
|
|
|
|
LOG.i("callback:", "surfaceChanged", "w:", width, "h:", height, "firstTime:", mFirstTime); |
|
|
|
|
if (mFirstTime) { |
|
|
|
|
LOG.i("callback:", "surfaceChanged", "w:", width, "h:", height, "dispatched:", mDispatched); |
|
|
|
|
if (!mDispatched) { |
|
|
|
|
dispatchOnOutputSurfaceAvailable(width, height); |
|
|
|
|
mFirstTime = false; |
|
|
|
|
mDispatched = true; |
|
|
|
|
} else { |
|
|
|
|
dispatchOnOutputSurfaceSizeChanged(width, height); |
|
|
|
|
} |
|
|
|
@ -56,15 +53,15 @@ class SurfaceCameraPreview extends CameraPreview<View, SurfaceHolder> { |
|
|
|
|
public void surfaceDestroyed(SurfaceHolder holder) { |
|
|
|
|
LOG.i("callback:", "surfaceDestroyed"); |
|
|
|
|
dispatchOnOutputSurfaceDestroyed(); |
|
|
|
|
mFirstTime = true; |
|
|
|
|
mDispatched = false; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return root.findViewById(R.id.surface_view_root); |
|
|
|
|
return surfaceView; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
SurfaceHolder getOutput() { |
|
|
|
|
return mSurfaceView.getHolder(); |
|
|
|
|
return getView().getHolder(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -72,26 +69,5 @@ class SurfaceCameraPreview extends CameraPreview<View, SurfaceHolder> { |
|
|
|
|
return SurfaceHolder.class; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void applyCrop(float scaleX, float scaleY) { |
|
|
|
|
/* float currWidth = getView().getWidth(); |
|
|
|
|
float currHeight = getView().getHeight(); |
|
|
|
|
float cropX = currWidth * (scaleX - 1) / 2f; |
|
|
|
|
float cropY = currHeight * (scaleX - 1) / 2f; |
|
|
|
|
LOG.e("applyCrop:", "currWidth:", currWidth, "currHeight:", currHeight); |
|
|
|
|
LOG.e("applyCrop:", "scaleX:", scaleX, "scaleY:", scaleY); |
|
|
|
|
mSurfaceView.setTop((int) -cropY); |
|
|
|
|
mSurfaceView.setLeft((int) -cropX); |
|
|
|
|
mSurfaceView.setBottom((int) (currHeight + cropY)); |
|
|
|
|
mSurfaceView.setRight((int) (currWidth + cropX)); |
|
|
|
|
LOG.e("applyCrop:", "top:", -cropY, "left:", -cropX, "bottom:", currHeight+cropY, "right:", currWidth+cropX); |
|
|
|
|
mSurfaceView.requestLayout(); */ |
|
|
|
|
// mSurfaceView.getLayoutParams().width = (int) (currWidth * scaleX);
|
|
|
|
|
// mSurfaceView.getLayoutParams().height = (int) (currHeight * scaleY);
|
|
|
|
|
// mSurfaceView.setTranslationY(-cropY / 2f);
|
|
|
|
|
// mSurfaceView.setTranslationX(-cropX / 2f);
|
|
|
|
|
// getView().setScrollX((int) (cropX / 2f));
|
|
|
|
|
// getView().setScrollY((int) (cropY / 2f));
|
|
|
|
|
// mSurfaceView.requestLayout();
|
|
|
|
|
// super.applyCrop(scaleX, scaleY);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|