diff --git a/README.md b/README.md index bcff12da..b17f3336 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ repositories { maven { url 'https://jitpack.io' } } -compile 'io.fotoapparat.fotoapparat:library:2.0.1' +compile 'io.fotoapparat.fotoapparat:library:2.0.2' ``` Camera permission will be automatically added to your `AndroidManifest.xml`. Do not forget to request this permission on Marshmallow and higher. diff --git a/fotoapparat/src/main/java/io/fotoapparat/exception/camera/UnavailableSurfaceException.kt b/fotoapparat/src/main/java/io/fotoapparat/exception/camera/UnavailableSurfaceException.kt new file mode 100644 index 00000000..0d9c241b --- /dev/null +++ b/fotoapparat/src/main/java/io/fotoapparat/exception/camera/UnavailableSurfaceException.kt @@ -0,0 +1,9 @@ +package io.fotoapparat.exception.camera + +/** + * Thrown when the preview surface didn't become available. + */ +class UnavailableSurfaceException : CameraException( + "No preview surface became available before CameraView got detached from window. " + + "Camera didn't start. You may ignore this exception." +) \ No newline at end of file diff --git a/fotoapparat/src/main/java/io/fotoapparat/view/CameraView.kt b/fotoapparat/src/main/java/io/fotoapparat/view/CameraView.kt index 02bbd68a..12dd8830 100644 --- a/fotoapparat/src/main/java/io/fotoapparat/view/CameraView.kt +++ b/fotoapparat/src/main/java/io/fotoapparat/view/CameraView.kt @@ -6,6 +6,7 @@ import android.util.AttributeSet import android.view.TextureView import android.view.ViewGroup import android.widget.FrameLayout +import io.fotoapparat.exception.camera.UnavailableSurfaceException import io.fotoapparat.parameter.Resolution import io.fotoapparat.parameter.ScaleType import java.util.concurrent.CountDownLatch @@ -63,7 +64,7 @@ class CameraView private fun getPreviewAfterLatch(): Preview.Texture { textureLatch.await() - return surfaceTexture?.toPreview() ?: throw InterruptedException("No surface became available.") + return surfaceTexture?.toPreview() ?: throw UnavailableSurfaceException() } private fun TextureView.tryInitialize() = surfaceTexture ?: null.also { @@ -75,7 +76,6 @@ class CameraView } - private fun ViewGroup.layoutTextureView( previewResolution: Resolution?, scaleType: ScaleType?