Julian Steenbakker
Committed by GitHub

Merge pull request #1299 from yujune/fix-android-jank-ui

fix: fix android jank ui when returnImage is true
## 6.0.4
Bugs fixed:
* [Android] Fixed UI jank when `returnImage` is true.
## 6.0.3
New features:
* Adds pause function to pause the camera but keep textures in place.
... ...
... ... @@ -79,7 +79,8 @@ 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'
testImplementation 'org.mockito:mockito-core:5.12.0'
}
... ...
... ... @@ -35,6 +35,10 @@ 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
... ... @@ -97,6 +101,7 @@ class MobileScanner(
if (newScannedBarcodes == lastScanned) {
// New scanned is duplicate, returning
imageProxy.close()
return@addOnSuccessListener
}
if (newScannedBarcodes.isNotEmpty()) {
... ... @@ -118,10 +123,12 @@ class MobileScanner(
}
if (barcodeMap.isEmpty()) {
imageProxy.close()
return@addOnSuccessListener
}
if (!returnImage) {
imageProxy.close()
mobileScannerCallback(
barcodeMap,
null,
... ... @@ -130,31 +137,36 @@ class MobileScanner(
return@addOnSuccessListener
}
val bitmap = Bitmap.createBitmap(mediaImage.width, mediaImage.height, Bitmap.Config.ARGB_8888)
val imageFormat = YuvToRgbConverter(activity.applicationContext)
CoroutineScope(Dispatchers.IO).launch {
val bitmap = Bitmap.createBitmap(mediaImage.width, mediaImage.height, Bitmap.Config.ARGB_8888)
val imageFormat = YuvToRgbConverter(activity.applicationContext)
imageFormat.yuvToRgb(mediaImage, bitmap)
imageFormat.yuvToRgb(mediaImage, bitmap)
val bmResult = rotateBitmap(bitmap, camera?.cameraInfo?.sensorRotationDegrees?.toFloat() ?: 90f)
val bmResult = rotateBitmap(bitmap, camera?.cameraInfo?.sensorRotationDegrees?.toFloat() ?: 90f)
val stream = ByteArrayOutputStream()
bmResult.compress(Bitmap.CompressFormat.PNG, 100, stream)
val byteArray = stream.toByteArray()
val bmWidth = bmResult.width
val bmHeight = bmResult.height
bmResult.recycle()
val stream = ByteArrayOutputStream()
bmResult.compress(Bitmap.CompressFormat.PNG, 100, stream)
val byteArray = stream.toByteArray()
val bmWidth = bmResult.width
val bmHeight = bmResult.height
bmResult.recycle()
imageProxy.close()
mobileScannerCallback(
barcodeMap,
byteArray,
bmWidth,
bmHeight
)
}
mobileScannerCallback(
barcodeMap,
byteArray,
bmWidth,
bmHeight
)
}.addOnFailureListener { e ->
mobileScannerErrorCallback(
e.localizedMessage ?: e.toString()
)
}.addOnCompleteListener { imageProxy.close() }
}
}
if (detectionSpeed == DetectionSpeed.NORMAL) {
... ...