yujune

fix: fix android ui jank when returnImage set to true.

... ... @@ -79,6 +79,7 @@ dependencies {
implementation 'androidx.camera:camera-lifecycle:1.3.4'
implementation 'androidx.camera:camera-camera2:1.3.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.mockito:mockito-core:5.12.0'
... ...
... ... @@ -35,9 +35,12 @@ import dev.steenbakker.mobile_scanner.objects.DetectionSpeed
import dev.steenbakker.mobile_scanner.objects.MobileScannerStartParameters
import dev.steenbakker.mobile_scanner.utils.YuvToRgbConverter
import io.flutter.view.TextureRegistry
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import java.io.ByteArrayOutputStream
import kotlin.math.roundToInt
class MobileScanner(
private val activity: Activity,
private val textureRegistry: TextureRegistry,
... ... @@ -97,6 +100,7 @@ class MobileScanner(
if (newScannedBarcodes == lastScanned) {
// New scanned is duplicate, returning
imageProxy.close()
return@addOnSuccessListener
}
if (newScannedBarcodes.isNotEmpty()) {
... ... @@ -118,10 +122,12 @@ class MobileScanner(
}
if (barcodeMap.isEmpty()) {
imageProxy.close()
return@addOnSuccessListener
}
if (!returnImage) {
imageProxy.close()
mobileScannerCallback(
barcodeMap,
null,
... ... @@ -130,6 +136,7 @@ class MobileScanner(
return@addOnSuccessListener
}
CoroutineScope(Dispatchers.IO).launch {
val bitmap = Bitmap.createBitmap(mediaImage.width, mediaImage.height, Bitmap.Config.ARGB_8888)
val imageFormat = YuvToRgbConverter(activity.applicationContext)
... ... @@ -143,18 +150,20 @@ class MobileScanner(
val bmWidth = bmResult.width
val bmHeight = bmResult.height
bmResult.recycle()
imageProxy.close()
mobileScannerCallback(
barcodeMap,
byteArray,
bmWidth,
bmHeight
)
}
}.addOnFailureListener { e ->
mobileScannerErrorCallback(
e.localizedMessage ?: e.toString()
)
}.addOnCompleteListener { imageProxy.close() }
}
}
if (detectionSpeed == DetectionSpeed.NORMAL) {
... ...