Search in sources :

Example 1 with PairingQR

use of co.krypt.krypton.protocol.PairingQR in project krypton-android by kryptco.

the class PairDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (!(getTargetFragment() instanceof PairFragment)) {
        Log.e(TAG, "targetFragment !instanceof PairFragment");
        return null;
    }
    final PairFragment pairFragment = (PairFragment) getTargetFragment();
    final PairingQR pendingPairingQR = pairFragment.getPendingPairingQR();
    if (pendingPairingQR == null) {
        Log.e(TAG, "pendingPairingQR null");
        return null;
    }
    if (pendingPairingQR.version == null) {
        return createOutdatedPairingDialog(pairFragment);
    }
    // Create the AlertDialog object and return it
    return createPairingDialog(pairFragment);
}
Also used : PairingQR(co.krypt.krypton.protocol.PairingQR)

Example 2 with PairingQR

use of co.krypt.krypton.protocol.PairingQR 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)

Example 3 with PairingQR

use of co.krypt.krypton.protocol.PairingQR in project krypton-android by kryptco.

the class PairFragment method pair.

@Override
public void pair() {
    Log.i(TAG, "pair");
    final PairingQR qr = pendingPairingQR.get();
    if (qr == null) {
        Log.e(TAG, "pendingQR null");
        return;
    }
    threadPool.execute(new Runnable() {

        @Override
        public void run() {
            try {
                // This part contains crypto, so we run on a background thread. If the crypto
                // is proven to be fast enough for the UI thread on slower devices, then this
                // thread should be removed to greatly simplify the code.
                final Pairing pairing = Pairing.generate(qr);
                Silo.shared(getContext()).pair(pairing);
                pairingStatusView.post(new Runnable() {

                    @Override
                    public void run() {
                        pairingReady(pairing);
                    }
                });
            } catch (CryptoException | TransportException e) {
                pendingPairingQR.set(null);
                e.printStackTrace();
            }
        }
    });
}
Also used : PairingQR(co.krypt.krypton.protocol.PairingQR)

Aggregations

PairingQR (co.krypt.krypton.protocol.PairingQR)3 View (android.view.View)1 TextView (android.widget.TextView)1 OnboardingActivity (co.krypt.krypton.onboarding.OnboardingActivity)1 JsonParseException (com.google.gson.JsonParseException)1 ResultPoint (com.google.zxing.ResultPoint)1 BarcodeCallback (com.journeyapps.barcodescanner.BarcodeCallback)1 BarcodeResult (com.journeyapps.barcodescanner.BarcodeResult)1 BarcodeView (com.journeyapps.barcodescanner.BarcodeView)1