Skip to content

Commit

Permalink
Merge pull request #154 from juliansteenbakker/nullable
Browse files Browse the repository at this point in the history
Nullable
  • Loading branch information
juliansteenbakker authored May 23, 2022
2 parents 0ec80e3 + 39ea2e2 commit bc1529b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.mlkit:barcode-scanning:17.0.2'
implementation "androidx.camera:camera-camera2:1.1.0-rc01"
implementation "androidx.camera:camera-camera2:1.2.0-alpha01"
implementation 'androidx.camera:camera-lifecycle:1.2.0-alpha01'

// // The following line is optional, as the core library is included indirectly by camera-camera2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:

@ExperimentalGetImage
private fun start(call: MethodCall, result: MethodChannel.Result) {
if (camera != null && preview != null) {
if (camera?.cameraInfo != null && preview != null && textureEntry != null) {
val resolution = preview!!.resolutionInfo!!.resolution
val portrait = camera!!.cameraInfo.sensorRotationDegrees % 180 == 0
val width = resolution.width.toDouble()
Expand Down Expand Up @@ -151,9 +151,16 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:

future.addListener({
cameraProvider = future.get()
if (cameraProvider == null) {
result.error("cameraProvider", "cameraProvider is null", null)
return@addListener
}
cameraProvider!!.unbindAll()
textureEntry = textureRegistry.createSurfaceTexture()

if (textureEntry == null) {
result.error("textureEntry", "textureEntry is null", null)
return@addListener
}
// Preview
val surfaceProvider = Preview.SurfaceProvider { request ->
val texture = textureEntry!!.surfaceTexture()
Expand Down Expand Up @@ -187,6 +194,11 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:
Log.i("LOG", "Analyzer: $analysisSize")
Log.i("LOG", "Preview: $previewSize")

if (camera == null) {
result.error("camera", "camera is null", null)
return@addListener
}

// Register the torch listener
camera!!.cameraInfo.torchState.observe(activity) { state ->
// TorchState.OFF = 0; TorchState.ON = 1
Expand Down

0 comments on commit bc1529b

Please sign in to comment.