Skip to content

Commit 4902a22

Browse files
committed
fix lint warnings
1 parent 6342808 commit 4902a22

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import java.io.IOException
5353
import java.util.concurrent.Executors
5454
import kotlin.math.roundToInt
5555

56+
@ExperimentalGetImage
5657
class MobileScanner(
5758
private val activity: Activity,
5859
private val textureRegistry: TextureRegistry,
@@ -499,7 +500,7 @@ class MobileScanner(
499500
} else {
500501
it.cameraControl.setZoomRatio(initialZoom.toFloat())
501502
}
502-
} catch (e: Exception) {
503+
} catch (_: Exception) {
503504
mobileScannerErrorCallback(ZoomNotInRange())
504505

505506
return@addListener
@@ -678,7 +679,7 @@ class MobileScanner(
678679
* Set the zoom rate of the camera.
679680
*/
680681
fun setScale(scale: Double) {
681-
if (scale > 1.0 || scale < 0) throw ZoomNotInRange()
682+
if (scale !in 0.0..1.0) throw ZoomNotInRange()
682683
if (camera == null) throw ZoomWhenStopped()
683684
camera?.cameraControl?.setLinearZoom(scale.toFloat())
684685
}

android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.net.Uri
88
import android.os.Handler
99
import android.os.Looper
1010
import android.util.Size
11+
import androidx.annotation.OptIn
1112
import androidx.camera.core.CameraSelector
1213
import androidx.camera.core.ExperimentalGetImage
1314
import androidx.camera.core.ExperimentalLensFacing
@@ -25,6 +26,7 @@ import io.flutter.view.TextureRegistry
2526
import java.io.File
2627
import com.google.mlkit.vision.barcode.ZoomSuggestionOptions
2728

29+
@OptIn(ExperimentalGetImage::class)
2830
class MobileScannerHandler(
2931
private val activity: Activity,
3032
private val barcodeHandler: BarcodeHandler,
@@ -175,7 +177,7 @@ class MobileScannerHandler(
175177
val invertImage: Boolean = call.argument<Boolean>("invertImage") ?: false
176178
val initialZoom: Double? = call.argument<Double?>("initialZoom")
177179

178-
val barcodeScannerOptions: BarcodeScannerOptions? = buildBarcodeScannerOptions(formats, autoZoom)
180+
val barcodeScannerOptions: BarcodeScannerOptions = buildBarcodeScannerOptions(formats, autoZoom)
179181

180182
val position =
181183
if (facing == 0) CameraSelector.DEFAULT_FRONT_CAMERA else CameraSelector.DEFAULT_BACK_CAMERA
@@ -267,7 +269,7 @@ class MobileScannerHandler(
267269
try {
268270
mobileScanner!!.stop(force)
269271
result.success(null)
270-
} catch (e: AlreadyStopped) {
272+
} catch (_: AlreadyStopped) {
271273
result.success(null)
272274
}
273275
}
@@ -294,10 +296,10 @@ class MobileScannerHandler(
294296
try {
295297
mobileScanner!!.setScale(call.arguments as Double)
296298
result.success(null)
297-
} catch (e: ZoomWhenStopped) {
299+
} catch (_: ZoomWhenStopped) {
298300
result.error(
299301
MobileScannerErrorCodes.SET_SCALE_WHEN_STOPPED_ERROR, MobileScannerErrorCodes.SET_SCALE_WHEN_STOPPED_ERROR_MESSAGE, null)
300-
} catch (e: ZoomNotInRange) {
302+
} catch (_: ZoomNotInRange) {
301303
result.error(
302304
MobileScannerErrorCodes.GENERIC_ERROR, MobileScannerErrorCodes.INVALID_ZOOM_SCALE_ERROR_MESSAGE, null)
303305
}
@@ -307,15 +309,15 @@ class MobileScannerHandler(
307309
try {
308310
mobileScanner!!.setZoomRatio(scale.toDouble())
309311
return true
310-
} catch (e: ZoomWhenStopped) { }
312+
} catch (_: ZoomWhenStopped) { }
311313
return false
312314
}
313315

314316
private fun resetScale(result: MethodChannel.Result) {
315317
try {
316318
mobileScanner!!.resetScale()
317319
result.success(null)
318-
} catch (e: ZoomWhenStopped) {
320+
} catch (_: ZoomWhenStopped) {
319321
result.error(
320322
MobileScannerErrorCodes.SET_SCALE_WHEN_STOPPED_ERROR, MobileScannerErrorCodes.SET_SCALE_WHEN_STOPPED_ERROR_MESSAGE, null)
321323
}
@@ -327,8 +329,8 @@ class MobileScannerHandler(
327329
result.success(null)
328330
}
329331

330-
private fun buildBarcodeScannerOptions(formats: List<Int>?, autoZoom: Boolean): BarcodeScannerOptions? {
331-
val builder : BarcodeScannerOptions.Builder?
332+
private fun buildBarcodeScannerOptions(formats: List<Int>?, autoZoom: Boolean): BarcodeScannerOptions {
333+
val builder : BarcodeScannerOptions.Builder
332334
if (formats == null) {
333335
builder = BarcodeScannerOptions.Builder()
334336
} else {
@@ -338,10 +340,10 @@ class MobileScannerHandler(
338340
formatsList.add(BarcodeFormats.fromRawValue(formatValue).intValue)
339341
}
340342

341-
if (formatsList.size == 1) {
342-
builder = BarcodeScannerOptions.Builder().setBarcodeFormats(formatsList.first())
343+
builder = if (formatsList.size == 1) {
344+
BarcodeScannerOptions.Builder().setBarcodeFormats(formatsList.first())
343345
} else {
344-
builder = BarcodeScannerOptions.Builder().setBarcodeFormats(
346+
BarcodeScannerOptions.Builder().setBarcodeFormats(
345347
formatsList.first(),
346348
*formatsList.subList(1, formatsList.size).toIntArray()
347349
)
@@ -394,7 +396,7 @@ class MobileScannerHandler(
394396
try {
395397
mobileScanner?.setFocus(dx, dy)
396398
result.success(null)
397-
} catch (e: ZoomWhenStopped) {
399+
} catch (_: ZoomWhenStopped) {
398400
result.error(
399401
MobileScannerErrorCodes.GENERIC_ERROR,
400402
"Cannot set focus when camera is stopped.",

0 commit comments

Comments
 (0)