From f2c53ead8c21d510dbde0d8a21441bd5c7f8d301 Mon Sep 17 00:00:00 2001 From: Dylan McIntyre Date: Sat, 28 Jan 2017 15:34:33 -0500 Subject: [PATCH] fix crash with no camera avail --- .../com/flurgle/camerakit/PreviewImpl.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/camerakit/src/main/java/com/flurgle/camerakit/PreviewImpl.java b/camerakit/src/main/java/com/flurgle/camerakit/PreviewImpl.java index 14b9c77a..67902178 100644 --- a/camerakit/src/main/java/com/flurgle/camerakit/PreviewImpl.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/PreviewImpl.java @@ -67,19 +67,21 @@ public abstract class PreviewImpl { this.mTrueWidth = width; this.mTrueHeight = height; - AspectRatio aspectRatio = AspectRatio.of(width, height); - int targetHeight = (int) (getView().getWidth() * aspectRatio.toFloat()); - float scaleY; - if (getView().getHeight() > 0) { - scaleY = (float) targetHeight / (float) getView().getHeight(); - } else { - scaleY = 1; - } - - if (scaleY > 1) { - getView().setScaleY(scaleY); - } else { - getView().setScaleX(1 / scaleY); + if (width != 0 && height != 0) { + AspectRatio aspectRatio = AspectRatio.of(width, height); + int targetHeight = (int) (getView().getWidth() * aspectRatio.toFloat()); + float scaleY; + if (getView().getHeight() > 0) { + scaleY = (float) targetHeight / (float) getView().getHeight(); + } else { + scaleY = 1; + } + + if (scaleY > 1) { + getView().setScaleY(scaleY); + } else { + getView().setScaleX(1 / scaleY); + } } }