Committed by
GitHub
Merge pull request #154 from juliansteenbakker/nullable
Nullable
Showing
2 changed files
with
15 additions
and
3 deletions
| @@ -47,7 +47,7 @@ android { | @@ -47,7 +47,7 @@ android { | ||
| 47 | dependencies { | 47 | dependencies { |
| 48 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | 48 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" |
| 49 | implementation 'com.google.mlkit:barcode-scanning:17.0.2' | 49 | implementation 'com.google.mlkit:barcode-scanning:17.0.2' |
| 50 | - implementation "androidx.camera:camera-camera2:1.1.0-rc01" | 50 | + implementation "androidx.camera:camera-camera2:1.2.0-alpha01" |
| 51 | implementation 'androidx.camera:camera-lifecycle:1.2.0-alpha01' | 51 | implementation 'androidx.camera:camera-lifecycle:1.2.0-alpha01' |
| 52 | 52 | ||
| 53 | // // The following line is optional, as the core library is included indirectly by camera-camera2 | 53 | // // The following line is optional, as the core library is included indirectly by camera-camera2 |
| @@ -120,7 +120,7 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | @@ -120,7 +120,7 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | ||
| 120 | 120 | ||
| 121 | @ExperimentalGetImage | 121 | @ExperimentalGetImage |
| 122 | private fun start(call: MethodCall, result: MethodChannel.Result) { | 122 | private fun start(call: MethodCall, result: MethodChannel.Result) { |
| 123 | - if (camera != null && preview != null) { | 123 | + if (camera?.cameraInfo != null && preview != null && textureEntry != null) { |
| 124 | val resolution = preview!!.resolutionInfo!!.resolution | 124 | val resolution = preview!!.resolutionInfo!!.resolution |
| 125 | val portrait = camera!!.cameraInfo.sensorRotationDegrees % 180 == 0 | 125 | val portrait = camera!!.cameraInfo.sensorRotationDegrees % 180 == 0 |
| 126 | val width = resolution.width.toDouble() | 126 | val width = resolution.width.toDouble() |
| @@ -151,9 +151,16 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | @@ -151,9 +151,16 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | ||
| 151 | 151 | ||
| 152 | future.addListener({ | 152 | future.addListener({ |
| 153 | cameraProvider = future.get() | 153 | cameraProvider = future.get() |
| 154 | + if (cameraProvider == null) { | ||
| 155 | + result.error("cameraProvider", "cameraProvider is null", null) | ||
| 156 | + return@addListener | ||
| 157 | + } | ||
| 154 | cameraProvider!!.unbindAll() | 158 | cameraProvider!!.unbindAll() |
| 155 | textureEntry = textureRegistry.createSurfaceTexture() | 159 | textureEntry = textureRegistry.createSurfaceTexture() |
| 156 | - | 160 | + if (textureEntry == null) { |
| 161 | + result.error("textureEntry", "textureEntry is null", null) | ||
| 162 | + return@addListener | ||
| 163 | + } | ||
| 157 | // Preview | 164 | // Preview |
| 158 | val surfaceProvider = Preview.SurfaceProvider { request -> | 165 | val surfaceProvider = Preview.SurfaceProvider { request -> |
| 159 | val texture = textureEntry!!.surfaceTexture() | 166 | val texture = textureEntry!!.surfaceTexture() |
| @@ -187,6 +194,11 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | @@ -187,6 +194,11 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: | ||
| 187 | Log.i("LOG", "Analyzer: $analysisSize") | 194 | Log.i("LOG", "Analyzer: $analysisSize") |
| 188 | Log.i("LOG", "Preview: $previewSize") | 195 | Log.i("LOG", "Preview: $previewSize") |
| 189 | 196 | ||
| 197 | + if (camera == null) { | ||
| 198 | + result.error("camera", "camera is null", null) | ||
| 199 | + return@addListener | ||
| 200 | + } | ||
| 201 | + | ||
| 190 | // Register the torch listener | 202 | // Register the torch listener |
| 191 | camera!!.cameraInfo.torchState.observe(activity) { state -> | 203 | camera!!.cameraInfo.torchState.observe(activity) { state -> |
| 192 | // TorchState.OFF = 0; TorchState.ON = 1 | 204 | // TorchState.OFF = 0; TorchState.ON = 1 |
-
Please register or login to post a comment