Parcourir la source

migrate to flutter-beta

flutter-beta
X-SLAYER il y a 4 ans
Parent
révision
0fe54cbb19
2 fichiers modifiés avec 27 ajouts et 26 suppressions
  1. +25
    -24
      android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt
  2. +2
    -2
      lib/src/qr_code_scanner.dart

+ 25
- 24
android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt Voir le fichier

@@ -71,7 +71,7 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
} }


override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
when(call.method) {
when (call.method) {
"startScan" -> startScan(call.arguments as? List<Int>, result) "startScan" -> startScan(call.arguments as? List<Int>, result)
"stopScan" -> stopScan() "stopScan" -> stopScan()
"flipCamera" -> flipCamera(result) "flipCamera" -> flipCamera(result)
@@ -85,10 +85,10 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
"getFlashInfo" -> getFlashInfo(result) "getFlashInfo" -> getFlashInfo(result)
"getSystemFeatures" -> getSystemFeatures(result) "getSystemFeatures" -> getSystemFeatures(result)
"changeScanArea" -> changeScanArea( "changeScanArea" -> changeScanArea(
call.argument<Double>("scanAreaWidth")!!,
call.argument<Double>("scanAreaHeight")!!,
call.argument<Double>("cutOutBottomOffset")!!,
result,
call.argument<Double>("scanAreaWidth")!!,
call.argument<Double>("scanAreaHeight")!!,
call.argument<Double>("cutOutBottomOffset")!!,
result,
) )
"invertScan" -> setInvertScan(call.argument<Boolean>("isInvertScan")!!, result) "invertScan" -> setInvertScan(call.argument<Boolean>("isInvertScan")!!, result)
else -> result.notImplemented() else -> result.notImplemented()
@@ -109,7 +109,7 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
barcodeView!!.pause() barcodeView!!.pause()
val settings = barcodeView!!.cameraSettings val settings = barcodeView!!.cameraSettings


if(settings.requestedCameraId == CameraInfo.CAMERA_FACING_FRONT)
if (settings.requestedCameraId == CameraInfo.CAMERA_FACING_FRONT)
settings.requestedCameraId = CameraInfo.CAMERA_FACING_BACK settings.requestedCameraId = CameraInfo.CAMERA_FACING_BACK
else else
settings.requestedCameraId = CameraInfo.CAMERA_FACING_FRONT settings.requestedCameraId = CameraInfo.CAMERA_FACING_FRONT
@@ -194,7 +194,7 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
private fun initBarCodeView(): CustomFramingRectBarcodeView? { private fun initBarCodeView(): CustomFramingRectBarcodeView? {
if (barcodeView == null) { if (barcodeView == null) {
barcodeView = barcodeView =
CustomFramingRectBarcodeView(Shared.activity)
CustomFramingRectBarcodeView(Shared.activity)
if (params["cameraFacing"] as Int == 1) { if (params["cameraFacing"] as Int == 1) {
barcodeView?.cameraSettings?.requestedCameraId = CameraInfo.CAMERA_FACING_FRONT barcodeView?.cameraSettings?.requestedCameraId = CameraInfo.CAMERA_FACING_FRONT
} }
@@ -213,7 +213,7 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
allowedBarcodeTypes.add(BarcodeFormat.values()[it]) allowedBarcodeTypes.add(BarcodeFormat.values()[it])
} }
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
result.error(null, null, null)
result.error("null", e.message, "null")
} }


barcodeView?.decodeContinuous( barcodeView?.decodeContinuous(
@@ -244,15 +244,15 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
"hasBackCamera" to hasBackCamera(), "hasFlash" to hasFlash(), "hasBackCamera" to hasBackCamera(), "hasFlash" to hasFlash(),
"activeCamera" to barcodeView?.cameraSettings?.requestedCameraId)) "activeCamera" to barcodeView?.cameraSettings?.requestedCameraId))
} catch (e: Exception) { } catch (e: Exception) {
result.error(null, null, null)
result.error("Error", e.message, null)
} }
} }


private fun changeScanArea( private fun changeScanArea(
dpScanAreaWidth: Double,
dpScanAreaHeight: Double,
cutOutBottomOffset: Double,
result: MethodChannel.Result
dpScanAreaWidth: Double,
dpScanAreaHeight: Double,
cutOutBottomOffset: Double,
result: MethodChannel.Result
) { ) {
setScanAreaSize(dpScanAreaWidth, dpScanAreaHeight, cutOutBottomOffset) setScanAreaSize(dpScanAreaWidth, dpScanAreaHeight, cutOutBottomOffset)
result.success(true) result.success(true)
@@ -267,19 +267,19 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
} }


private fun setScanAreaSize( private fun setScanAreaSize(
dpScanAreaWidth: Double,
dpScanAreaHeight: Double,
dpCutOutBottomOffset: Double
dpScanAreaWidth: Double,
dpScanAreaHeight: Double,
dpCutOutBottomOffset: Double
) { ) {
barcodeView?.setFramingRect( barcodeView?.setFramingRect(
convertDpToPixels(dpScanAreaWidth),
convertDpToPixels(dpScanAreaHeight),
convertDpToPixels(dpCutOutBottomOffset),
convertDpToPixels(dpScanAreaWidth),
convertDpToPixels(dpScanAreaHeight),
convertDpToPixels(dpCutOutBottomOffset),
) )
} }


private fun convertDpToPixels(dp: Double) = private fun convertDpToPixels(dp: Double) =
(dp * context.resources.displayMetrics.density).toInt()
(dp * context.resources.displayMetrics.density).toInt()


private fun hasCameraPermission(): Boolean { private fun hasCameraPermission(): Boolean {
return permissionGranted || return permissionGranted ||
@@ -307,10 +307,10 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
} }
} }


override fun onRequestPermissionsResult( requestCode: Int,
permissions: Array<out String>?,
grantResults: IntArray): Boolean {
if(requestCode == Shared.CAMERA_REQUEST_ID + this.id) {
override fun onRequestPermissionsResult(requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray): Boolean {
if (requestCode == Shared.CAMERA_REQUEST_ID + this.id) {
return if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { return if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
permissionGranted = true permissionGranted = true
channel.invokeMethod("onPermissionSet", true) channel.invokeMethod("onPermissionSet", true)
@@ -324,5 +324,6 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
return false return false
} }



} }



+ 2
- 2
lib/src/qr_code_scanner.dart Voir le fichier

@@ -65,7 +65,7 @@ class _QRViewState extends State<QRView> {
void initState() { void initState() {
super.initState(); super.initState();
_observer = LifecycleEventHandler(resumeCallBack: updateDimensions); _observer = LifecycleEventHandler(resumeCallBack: updateDimensions);
WidgetsBinding.instance!.addObserver(_observer);
WidgetsBinding.instance.addObserver(_observer);
} }


@override @override
@@ -83,7 +83,7 @@ class _QRViewState extends State<QRView> {
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
WidgetsBinding.instance!.removeObserver(_observer);
WidgetsBinding.instance.removeObserver(_observer);
} }


Future<void> updateDimensions() async { Future<void> updateDimensions() async {


Chargement…
Annuler
Enregistrer