Issue 1044 maybe avoid NPE in onDraw() before CaptureActivity.onResume()

git-svn-id: https://zxing.googlecode.com/svn/trunk@2007 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2011-11-02 17:04:54 +00:00
parent 5d47b0f8d0
commit 6f5841d8bb

View file

@ -75,7 +75,11 @@ public final class ViewfinderView extends View {
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
Rect frame = CameraManager.get().getFramingRect(); CameraManager cameraManager = CameraManager.get();
if (cameraManager == null) {
return;
}
Rect frame = cameraManager.getFramingRect();
if (frame == null) { if (frame == null) {
return; return;
} }
@ -109,7 +113,7 @@ public final class ViewfinderView extends View {
int middle = frame.height() / 2 + frame.top; int middle = frame.height() / 2 + frame.top;
canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
Rect previewFrame = CameraManager.get().getFramingRectInPreview(); Rect previewFrame = cameraManager.getFramingRectInPreview();
float scaleX = frame.width() / (float) previewFrame.width(); float scaleX = frame.width() / (float) previewFrame.width();
float scaleY = frame.height() / (float) previewFrame.height(); float scaleY = frame.height() / (float) previewFrame.height();