Bläddra i källkod

Created CustomFramingRectBarcodeView to support changing cutOutBottomOffset

flutter-beta
Tihomirov 5 år sedan
förälder
incheckning
b8911a7fc1
3 ändrade filer med 62 tillägg och 11 borttagningar
  1. +50
    -0
      android/src/main/kotlin/net/touchcapture/qr/flutterqr/CustomFramingRectBarcodeView.java
  2. +5
    -6
      android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt
  3. +7
    -5
      example/lib/main.dart

+ 50
- 0
android/src/main/kotlin/net/touchcapture/qr/flutterqr/CustomFramingRectBarcodeView.java Visa fil

@@ -0,0 +1,50 @@
package net.touchcapture.qr.flutterqr;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;

import com.journeyapps.barcodescanner.BarcodeView;
import com.journeyapps.barcodescanner.Size;

public class CustomFramingRectBarcodeView extends BarcodeView {

private static final int BOTTOM_OFFSET_NOT_SET_VALUE = -1;

private int bottomOffset = BOTTOM_OFFSET_NOT_SET_VALUE;

public CustomFramingRectBarcodeView(Context context) {
super(context);
}

public CustomFramingRectBarcodeView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public CustomFramingRectBarcodeView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
protected Rect calculateFramingRect(Rect container, Rect surface) {
Rect containerArea = new Rect(container);
boolean intersects = containerArea.intersect(surface);//adjusts the containerArea (code from super.calculateFramingRect)
Rect scanAreaRect = super.calculateFramingRect(container, surface);
if (bottomOffset != BOTTOM_OFFSET_NOT_SET_VALUE) {//if the setFramingRect function was called, then we shift the scan area by Y
Rect scanAreaRectWithOffset = new Rect(scanAreaRect);
scanAreaRectWithOffset.bottom -= bottomOffset;
scanAreaRectWithOffset.top -= bottomOffset;

boolean belongsToContainer = scanAreaRectWithOffset.intersect(containerArea);
if(belongsToContainer){
return scanAreaRectWithOffset;
}
}
return scanAreaRect;
}

public void setFramingRect(int rectWidth, int rectHeight, int bottomOffset) {
this.bottomOffset = bottomOffset;
this.setFramingRectSize(new Size(rectWidth, rectHeight));
}
}

+ 5
- 6
android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt Visa fil

@@ -13,8 +13,6 @@ import com.google.zxing.BarcodeFormat
import com.google.zxing.ResultPoint
import com.journeyapps.barcodescanner.BarcodeCallback
import com.journeyapps.barcodescanner.BarcodeResult
import com.journeyapps.barcodescanner.BarcodeView
import com.journeyapps.barcodescanner.Size
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
@@ -27,7 +25,7 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v

private var isTorchOn: Boolean = false
private var isPaused: Boolean = false
private var barcodeView: BarcodeView? = null
private var barcodeView: CustomFramingRectBarcodeView? = null
private val channel: MethodChannel = MethodChannel(messenger, "net.touchcapture.qr.flutterqr/qrview_$id")
private var permissionGranted: Boolean = false

@@ -193,9 +191,10 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
return initBarCodeView().apply {}!!
}

private fun initBarCodeView(): BarcodeView? {
private fun initBarCodeView(): CustomFramingRectBarcodeView? {
if (barcodeView == null) {
barcodeView = BarcodeView(Shared.activity)
barcodeView =
CustomFramingRectBarcodeView(Shared.activity)
if (params["cameraFacing"] as Int == 1) {
barcodeView?.cameraSettings?.requestedCameraId = CameraInfo.CAMERA_FACING_FRONT
}
@@ -255,7 +254,7 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
}

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

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


+ 7
- 5
example/lib/main.dart Visa fil

@@ -151,11 +151,13 @@ class _QRViewExampleState extends State<QRViewExample> {
key: qrKey,
onQRViewCreated: _onQRViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Colors.red,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: scanArea),
borderColor: Colors.red,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: /*scanArea*/100,
cutOutBottomOffset: 150,
),
onPermissionSet: (ctrl, p) => _onPermissionSet(context, ctrl, p),
);
}


Laddar…
Avbryt
Spara