Skip to content

Commit

Permalink
Notify exception from the callback instead of crashing the app. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Diolor committed Jan 3, 2018
1 parent 4ed7242 commit 2513e42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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."
)
4 changes: 2 additions & 2 deletions fotoapparat/src/main/java/io/fotoapparat/view/CameraView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -75,7 +76,6 @@ class CameraView

}


private fun ViewGroup.layoutTextureView(
previewResolution: Resolution?,
scaleType: ScaleType?
Expand Down

0 comments on commit 2513e42

Please sign in to comment.