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);
}
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;
}
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();
}
}
});
}
Aggregations