Skip to content
Snippets Groups Projects
Commit b57b65e8 authored by akwizgran's avatar akwizgran
Browse files

Merge branch '331-viewfinder' into 'master'

Reinitialise viewfinder when camera view is shown

Thanks to @str4d for finding the cause of the bug. Closes #331.

See merge request !165
parents 160adca1 7ad21708
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, ...@@ -44,20 +44,19 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
public CameraView(Context context) { public CameraView(Context context) {
super(context); super(context);
initialize();
} }
public CameraView(Context context, AttributeSet attrs) { public CameraView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
initialize();
} }
public CameraView(Context context, AttributeSet attrs, int defStyleAttr) { public CameraView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
initialize();
} }
private void initialize() { @Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
setKeepScreenOn(true); setKeepScreenOn(true);
SurfaceHolder holder = getHolder(); SurfaceHolder holder = getHolder();
if (Build.VERSION.SDK_INT < 11) if (Build.VERSION.SDK_INT < 11)
...@@ -65,6 +64,13 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -65,6 +64,13 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
holder.addCallback(this); holder.addCallback(this);
} }
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
setKeepScreenOn(false);
getHolder().removeCallback(this);
}
public void start(Camera camera, PreviewConsumer previewConsumer, public void start(Camera camera, PreviewConsumer previewConsumer,
int rotationDegrees) { int rotationDegrees) {
this.camera = camera; this.camera = camera;
...@@ -93,9 +99,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -93,9 +99,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
camera.startPreview(); camera.startPreview();
if (autoFocus) camera.autoFocus(this); if (autoFocus) camera.autoFocus(this);
previewConsumer.start(camera); previewConsumer.start(camera);
} catch (IOException e) { } catch (IOException | RuntimeException e) {
LOG.log(WARNING, "Error starting camera preview", e);
} catch (RuntimeException e) {
LOG.log(WARNING, "Error starting camera preview", e); LOG.log(WARNING, "Error starting camera preview", e);
} }
} }
...@@ -246,7 +250,6 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -246,7 +250,6 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
LOG.info("Surface destroyed"); LOG.info("Surface destroyed");
surfaceExists = false; surfaceExists = false;
holder.removeCallback(this);
} }
public void onAutoFocus(boolean success, final Camera camera) { 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