use of android.hardware.camera2.CameraDevice in project robolectric by robolectric.
the class ShadowCameraDeviceImplTest method createCaptureSession_configuration_throwsIllegalStateExceptionAfterClose.
@Test
@Config(sdk = VERSION_CODES.P)
public void createCaptureSession_configuration_throwsIllegalStateExceptionAfterClose() throws CameraAccessException {
cameraDevice.close();
SessionConfiguration configuration = new SessionConfiguration(SessionConfiguration.SESSION_REGULAR, Collections.singletonList(new OutputConfiguration(mock(Surface.class))), MoreExecutors.directExecutor(), new CaptureSessionCallback(/*useExecutor=*/
true));
IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> cameraDevice.createCaptureSession(configuration));
assertThat(thrown).hasMessageThat().contains("CameraDevice was already closed");
}
use of android.hardware.camera2.CameraDevice in project collect by opendatakit.
the class Camera2VideoFragment method startPreview.
/**
* Start the camera preview.
*/
private void startPreview() {
if (null == cameraDevice || !textureView.isAvailable() || null == previewSize) {
return;
}
try {
closePreviewSession();
SurfaceTexture texture = textureView.getSurfaceTexture();
assert texture != null;
texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
previewBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
Surface previewSurface = new Surface(texture);
previewBuilder.addTarget(previewSurface);
cameraDevice.createCaptureSession(Collections.singletonList(previewSurface), new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
previewSession = session;
updatePreview();
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession session) {
Activity activity = getActivity();
if (null != activity) {
ToastUtils.showShortToast(getActivity(), "Failed");
}
}
}, backgroundHandler);
} catch (CameraAccessException e) {
Timber.e(e);
}
}
use of android.hardware.camera2.CameraDevice in project collect by opendatakit.
the class Camera2VideoFragment method updatePreview.
/**
* Update the camera preview. {@link #startPreview()} needs to be called in advance.
*/
private void updatePreview() {
if (null == cameraDevice) {
return;
}
try {
setUpCaptureRequestBuilder(previewBuilder);
HandlerThread thread = new HandlerThread("CameraPreview");
thread.start();
previewSession.setRepeatingRequest(previewBuilder.build(), null, backgroundHandler);
} catch (CameraAccessException e) {
Timber.e(e);
}
}
use of android.hardware.camera2.CameraDevice in project MazeSolver by Thukor.
the class Camera2 method createCameraPreview.
protected void createCameraPreview() {
try {
SurfaceTexture texture = textureView.getSurfaceTexture();
assert texture != null;
texture.setDefaultBufferSize(imageDimension.getWidth(), imageDimension.getHeight());
Surface surface = new Surface(texture);
captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
captureRequestBuilder.addTarget(surface);
cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
// The camera is already closed
if (null == cameraDevice) {
return;
}
// When the session is ready, we start displaying the preview.
cameraCaptureSessions = cameraCaptureSession;
updatePreview();
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
Toast.makeText(Camera2.this, "Configuration change", Toast.LENGTH_SHORT).show();
}
}, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
Aggregations