Skip to content

Commit

Permalink
Merge pull request #134 from journeyapps/fix/paused-viewfinder
Browse files Browse the repository at this point in the history
Keep drawing viewfinder after pausing
  • Loading branch information
rkistner committed Feb 6, 2016
2 parents 9dd1022 + b61c0dc commit 062feb8
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class ViewfinderView extends View {
protected List<ResultPoint> lastPossibleResultPoints;
protected CameraPreview cameraPreview;

// Cache the framingRect and previewFramingRect, so that we can still draw it after the preview
// stopped.
protected Rect framingRect;
protected Rect previewFramingRect;

// This constructor is used when the class is built from an XML resource.
public ViewfinderView(Context context, AttributeSet attrs) {
super(context, attrs);
Expand Down Expand Up @@ -92,6 +97,7 @@ public void setCameraPreview(CameraPreview view) {
view.addStateListener(new CameraPreview.StateListener() {
@Override
public void previewSized() {
refreshSizes();
invalidate();
}

Expand All @@ -112,16 +118,29 @@ public void cameraError(Exception error) {
});
}

protected void refreshSizes() {
if(cameraPreview == null) {
return;
}
Rect framingRect = cameraPreview.getFramingRect();
Rect previewFramingRect = cameraPreview.getPreviewFramingRect();
if(framingRect != null && previewFramingRect != null) {
this.framingRect = framingRect;
this.previewFramingRect = previewFramingRect;
}
}


@SuppressLint("DrawAllocation")
@Override
public void onDraw(Canvas canvas) {
if (cameraPreview == null || cameraPreview.getPreviewFramingRect() == null || cameraPreview.getFramingRect() == null) {
refreshSizes();
if (framingRect == null || previewFramingRect == null) {
return;
}

Rect frame = cameraPreview.getFramingRect();
Rect previewFrame = cameraPreview.getPreviewFramingRect();
Rect frame = framingRect;
Rect previewFrame = previewFramingRect;

int width = canvas.getWidth();
int height = canvas.getHeight();
Expand Down

0 comments on commit 062feb8

Please sign in to comment.