Skip to content
Snippets Groups Projects
Unverified Commit 7ad21708 authored by akwizgran's avatar akwizgran
Browse files

Reinitialise viewfinder when camera view is shown. #331

parent ea973b61
No related branches found
No related tags found
No related merge requests found
......@@ -44,20 +44,19 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
public CameraView(Context context) {
super(context);
initialize();
}
public CameraView(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
public CameraView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}
private void initialize() {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
setKeepScreenOn(true);
SurfaceHolder holder = getHolder();
if (Build.VERSION.SDK_INT < 11)
......@@ -65,6 +64,13 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
holder.addCallback(this);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
setKeepScreenOn(false);
getHolder().removeCallback(this);
}
public void start(Camera camera, PreviewConsumer previewConsumer,
int rotationDegrees) {
this.camera = camera;
......@@ -93,9 +99,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
camera.startPreview();
if (autoFocus) camera.autoFocus(this);
previewConsumer.start(camera);
} catch (IOException e) {
LOG.log(WARNING, "Error starting camera preview", e);
} catch (RuntimeException e) {
} catch (IOException | RuntimeException e) {
LOG.log(WARNING, "Error starting camera preview", e);
}
}
......@@ -246,7 +250,6 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
public void surfaceDestroyed(SurfaceHolder holder) {
LOG.info("Surface destroyed");
surfaceExists = false;
holder.removeCallback(this);
}
public void onAutoFocus(boolean success, final Camera camera) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment