ソースを参照

ChangeScanAreaSize android function

flutter-beta
Alexander Tihomirov 5年前
コミット
fd2a7abf8e
2個のファイルの変更21行の追加0行の削除
  1. +13
    -0
      android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt
  2. +8
    -0
      lib/src/qr_code_scanner.dart

+ 13
- 0
android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt ファイルの表示

@@ -15,6 +15,7 @@ import com.journeyapps.barcodescanner.BarcodeResult
import com.journeyapps.barcodescanner.BarcodeView
import com.journeyapps.barcodescanner.DecoratedBarcodeView
import io.flutter.plugin.common.BinaryMessenger
import com.journeyapps.barcodescanner.Size
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry
@@ -89,6 +90,7 @@ class QRView(messenger: BinaryMessenger,private val id: Int, private val params:
"getCameraInfo" -> getCameraInfo(result)
"getFlashInfo" -> getFlashInfo(result)
"getSystemFeatures" -> getSystemFeatures(result)
"changeScanArea" -> changeScanArea(call.arguments as Double, result)
else -> result.notImplemented()
}
}
@@ -247,6 +249,17 @@ class QRView(messenger: BinaryMessenger,private val id: Int, private val params:
}
}

private fun changeScanArea(newSize: Double, result: MethodChannel.Result) {
setScanAreaSize(newSize, newSize)
result.success(true)
}

private fun setScanAreaSize(dpScanAreaWidth: Double, dpScanAreaHeight: Double) {
barcodeView?.barcodeView?.framingRectSize = Size(convertDpToPixels(dpScanAreaWidth), convertDpToPixels(dpScanAreaHeight))
}

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

private fun hasCameraPermission(): Boolean {
return permissionGranted ||
Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||


+ 8
- 0
lib/src/qr_code_scanner.dart ファイルの表示

@@ -341,6 +341,14 @@ class QRViewController {
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
} else if (defaultTargetPlatform == TargetPlatform.android) {
final cutOutSize = overlay?.cutOutSize;
if (cutOutSize != null) {
await channel.invokeMethod(
'changeScanArea',
cutOutSize,
);
}
}
return false;
}


読み込み中…
キャンセル
保存