Search in sources :

Example 1 with BarcodeCallback

use of com.journeyapps.barcodescanner.BarcodeCallback in project krypton-android by kryptco.

the class AdminScan method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_teams_invite_inperson_scan, container, false);
    lastScannedPayload.set(null);
    barcodeView = v.findViewById(R.id.camera_preview_in_person_scan);
    barcodeView.decodeContinuous(new BarcodeCallback() {

        @Override
        public void barcodeResult(BarcodeResult result) {
            if (result.getText() != null) {
                try {
                    Sigchain.MemberQRPayload qr = JSON.fromJson(result.getText(), Sigchain.QRPayload.class).memberQRPayload;
                    if (qr == null) {
                        Error.shortToast(getContext(), "Make sure you are scanning a member that is trying to join the team.");
                        return;
                    }
                    if (lastScannedPayload.compareAndSet(null, qr)) {
                        Transitions.beginSlide(AdminScan.this).addToBackStack(null).replace(R.id.fragmentOverlay, new AdminVerify()).commitAllowingStateLoss();
                    } else {
                        Log.i(TAG, "not first scan");
                    }
                } catch (JsonParseException e) {
                    Log.e(TAG, "could not parse QR code", e);
                    Error.shortToast(getContext(), "Invalid QR code");
                }
            }
        }

        @Override
        public void possibleResultPoints(List<ResultPoint> resultPoints) {
        }
    });
    AppCompatTextView detailText = v.findViewById(R.id.inPersonScanDetail);
    detailText.setText("Scan your team member's QR code to add them to your team.");
    return v;
}
Also used : BarcodeResult(com.journeyapps.barcodescanner.BarcodeResult) BarcodeCallback(com.journeyapps.barcodescanner.BarcodeCallback) ResultPoint(com.google.zxing.ResultPoint) Sigchain(co.krypt.krypton.team.Sigchain) AppCompatTextView(android.support.v7.widget.AppCompatTextView) JsonParseException(com.google.gson.JsonParseException) AppCompatTextView(android.support.v7.widget.AppCompatTextView) BarcodeView(com.journeyapps.barcodescanner.BarcodeView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 2 with BarcodeCallback

use of com.journeyapps.barcodescanner.BarcodeCallback in project collect by opendatakit.

the class BarcodeViewDecoder method waitForBarcode.

public LiveData<BarcodeResult> waitForBarcode(DecoratedBarcodeView view) {
    MutableLiveData<BarcodeResult> liveData = new MutableLiveData<>();
    view.decodeContinuous(new BarcodeCallback() {

        @Override
        public void barcodeResult(BarcodeResult result) {
            liveData.setValue(result);
        }

        @Override
        public void possibleResultPoints(List<ResultPoint> resultPoints) {
        }
    });
    return liveData;
}
Also used : BarcodeResult(com.journeyapps.barcodescanner.BarcodeResult) BarcodeCallback(com.journeyapps.barcodescanner.BarcodeCallback) ResultPoint(com.google.zxing.ResultPoint) MutableLiveData(androidx.lifecycle.MutableLiveData)

Example 3 with BarcodeCallback

use of com.journeyapps.barcodescanner.BarcodeCallback in project krypton-android by kryptco.

the class MemberScan method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_teams_invite_inperson_scan, container, false);
    lastScannedPayload.set(null);
    barcodeView = v.findViewById(R.id.camera_preview_in_person_scan);
    barcodeView.decodeContinuous(new BarcodeCallback() {

        @Override
        public void barcodeResult(BarcodeResult result) {
            if (result.getText() != null) {
                try {
                    Sigchain.AdminQRPayload qr = JSON.fromJson(result.getText(), Sigchain.QRPayload.class).adminQRPayload;
                    if (qr == null) {
                        Error.shortToast(getContext(), "Make sure you are scanning an admin that is already on a team.");
                        return;
                    }
                    if (lastScannedPayload.compareAndSet(null, qr)) {
                        Transitions.beginSlide(MemberScan.this).addToBackStack(null).replace(R.id.fragmentOverlay, new MemberEnterEmail()).commitAllowingStateLoss();
                    } else {
                        Log.i(TAG, "not first scan");
                    }
                } catch (JsonParseException e) {
                    Log.e(TAG, "could not parse QR code", e);
                    Error.shortToast(getContext(), "Invalid QR code");
                }
            }
        }

        @Override
        public void possibleResultPoints(List<ResultPoint> resultPoints) {
        }
    });
    AppCompatTextView detailText = v.findViewById(R.id.inPersonScanDetail);
    detailText.setText("Scan your team admin's QR code to join their team.");
    return v;
}
Also used : BarcodeResult(com.journeyapps.barcodescanner.BarcodeResult) BarcodeCallback(com.journeyapps.barcodescanner.BarcodeCallback) ResultPoint(com.google.zxing.ResultPoint) Sigchain(co.krypt.krypton.team.Sigchain) AppCompatTextView(android.support.v7.widget.AppCompatTextView) JsonParseException(com.google.gson.JsonParseException) AppCompatTextView(android.support.v7.widget.AppCompatTextView) BarcodeView(com.journeyapps.barcodescanner.BarcodeView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 4 with BarcodeCallback

use of com.journeyapps.barcodescanner.BarcodeCallback in project krypton-android by kryptco.

the class PairFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    final View rootView = inflater.inflate(R.layout.fragment_pair, container, false);
    barcodeView = (BarcodeView) rootView.findViewById(R.id.camera_preview);
    barcodeView.decodeContinuous(new BarcodeCallback() {

        @Override
        public void barcodeResult(BarcodeResult result) {
            if (result.getText() != null) {
                try {
                    PairingQR pairingQR = PairingQR.parseJson(result.getText());
                    Log.i(TAG, "found pairingQR: " + Base64.encodeToString(pairingQR.workstationPublicKey, Base64.DEFAULT));
                    onPairingScanned(pairingQR);
                } catch (JsonParseException e) {
                    Log.e(TAG, "could not parse QR code", e);
                }
            }
        }

        @Override
        public void possibleResultPoints(List<ResultPoint> resultPoints) {
        }
    });
    pairingStatusView = rootView.findViewById(R.id.pairingStatusLayout);
    pairingStatusText = (TextView) rootView.findViewById(R.id.pairingStatusText);
    cameraPermissionInfoLayout = (ConstraintLayout) rootView.findViewById(R.id.cameraPermissionInfo);
    cameraPermissionInfoLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickRequestCameraPermission(getActivity());
        }
    });
    requestCameraPermissionButton = (Button) rootView.findViewById(R.id.requestCameraPermissionButton);
    requestCameraPermissionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickRequestCameraPermission(getActivity());
        }
    });
    refreshCameraPermissionInfoVisibility();
    cameraPermissionHeader = (TextView) rootView.findViewById(R.id.cameraPermissionTitle);
    cameraPermissionText = (TextView) rootView.findViewById(R.id.cameraPermissionExplanation);
    if (getActivity() instanceof OnboardingActivity) {
        cameraPermissionHeader.setTextSize(16);
        cameraPermissionText.setTextSize(14);
    }
    return rootView;
}
Also used : BarcodeResult(com.journeyapps.barcodescanner.BarcodeResult) BarcodeCallback(com.journeyapps.barcodescanner.BarcodeCallback) ResultPoint(com.google.zxing.ResultPoint) OnboardingActivity(co.krypt.krypton.onboarding.OnboardingActivity) JsonParseException(com.google.gson.JsonParseException) BarcodeView(com.journeyapps.barcodescanner.BarcodeView) View(android.view.View) TextView(android.widget.TextView) PairingQR(co.krypt.krypton.protocol.PairingQR)

Aggregations

ResultPoint (com.google.zxing.ResultPoint)4 BarcodeCallback (com.journeyapps.barcodescanner.BarcodeCallback)4 BarcodeResult (com.journeyapps.barcodescanner.BarcodeResult)4 View (android.view.View)3 JsonParseException (com.google.gson.JsonParseException)3 BarcodeView (com.journeyapps.barcodescanner.BarcodeView)3 Nullable (android.support.annotation.Nullable)2 AppCompatTextView (android.support.v7.widget.AppCompatTextView)2 Sigchain (co.krypt.krypton.team.Sigchain)2 TextView (android.widget.TextView)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 OnboardingActivity (co.krypt.krypton.onboarding.OnboardingActivity)1 PairingQR (co.krypt.krypton.protocol.PairingQR)1