use of co.krypt.krypton.onboarding.OnboardingActivity in project krypton-android by kryptco.
the class PairDialogFragment method createPairingDialog.
private Dialog createPairingDialog(final PairFragment pairFragment) {
final Analytics analytics = new Analytics(getActivity());
final String workstationName = pairFragment.getPendingPairingQR().workstationName;
AlertDialog.Builder builder = new AlertDialog.Builder(getTargetFragment().getContext());
builder.setMessage("Pair with " + workstationName + "?").setPositiveButton("Pair", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int id) {
if (getTargetFragment() instanceof PairListener) {
Runnable onPair = new Runnable() {
@Override
public void run() {
HashSet<Pairing> existingPairings = Silo.shared(getContext()).pairings().loadAll();
for (Pairing existingPairing : existingPairings) {
if (existingPairing.workstationName.equals(workstationName)) {
Silo.shared(getContext()).pairings().unpair(existingPairing);
}
}
final PairListener listener = (PairListener) getTargetFragment();
analytics.postEvent("device", "pair", "new", null, false);
listener.pair();
}
};
Activity activity = getActivity();
if (activity instanceof OnboardingActivity) {
onPair.run();
} else {
LocalAuthentication.requestAuthentication(getActivity(), "Pair Device Confirmation", "Pair with " + pairFragment.getPendingPairingQR().workstationName + "?\nThis device will be able to request SSH operations.", onPair);
}
}
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (getTargetFragment() instanceof PairListener) {
final PairListener listener = (PairListener) getTargetFragment();
analytics.postEvent("device", "pair", "reject", null, false);
listener.cancel();
}
}
});
Dialog dialog = builder.create();
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
return dialog;
}
use of co.krypt.krypton.onboarding.OnboardingActivity 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;
}
Aggregations