Search in sources :

Example 1 with OnboardingActivity

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;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnboardingActivity(co.krypt.krypton.onboarding.OnboardingActivity) OnboardingActivity(co.krypt.krypton.onboarding.OnboardingActivity) Activity(android.app.Activity) Analytics(co.krypt.krypton.analytics.Analytics) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog)

Example 2 with OnboardingActivity

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;
}
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

OnboardingActivity (co.krypt.krypton.onboarding.OnboardingActivity)2 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 TextView (android.widget.TextView)1 Analytics (co.krypt.krypton.analytics.Analytics)1 PairingQR (co.krypt.krypton.protocol.PairingQR)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