Skip to content

Commit 2513e42

Browse files
committed
Notify exception from the callback instead of crashing the app. Fixes #164, #165
1 parent 4ed7242 commit 2513e42

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ repositories {
166166
maven { url 'https://jitpack.io' }
167167
}
168168
169-
compile 'io.fotoapparat.fotoapparat:library:2.0.1'
169+
compile 'io.fotoapparat.fotoapparat:library:2.0.2'
170170
```
171171

172172
Camera permission will be automatically added to your `AndroidManifest.xml`. Do not forget to request this permission on Marshmallow and higher.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.fotoapparat.exception.camera
2+
3+
/**
4+
* Thrown when the preview surface didn't become available.
5+
*/
6+
class UnavailableSurfaceException : CameraException(
7+
"No preview surface became available before CameraView got detached from window. " +
8+
"Camera didn't start. You may ignore this exception."
9+
)

fotoapparat/src/main/java/io/fotoapparat/view/CameraView.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.util.AttributeSet
66
import android.view.TextureView
77
import android.view.ViewGroup
88
import android.widget.FrameLayout
9+
import io.fotoapparat.exception.camera.UnavailableSurfaceException
910
import io.fotoapparat.parameter.Resolution
1011
import io.fotoapparat.parameter.ScaleType
1112
import java.util.concurrent.CountDownLatch
@@ -63,7 +64,7 @@ class CameraView
6364

6465
private fun getPreviewAfterLatch(): Preview.Texture {
6566
textureLatch.await()
66-
return surfaceTexture?.toPreview() ?: throw InterruptedException("No surface became available.")
67+
return surfaceTexture?.toPreview() ?: throw UnavailableSurfaceException()
6768
}
6869

6970
private fun TextureView.tryInitialize() = surfaceTexture ?: null.also {
@@ -75,7 +76,6 @@ class CameraView
7576

7677
}
7778

78-
7979
private fun ViewGroup.layoutTextureView(
8080
previewResolution: Resolution?,
8181
scaleType: ScaleType?

0 commit comments

Comments
 (0)