Search in sources :

Example 16 with Analytics

use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.

the class DeviceDetailFragment method onCheckedChanged.

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
        Pairings pairings = Silo.shared(getContext()).pairings();
        Analytics analytics = new Analytics(getContext());
        if (buttonView == manualButton) {
            pairings.setApproved(pairingUUID, false);
            analytics.postEvent("manual approval", String.valueOf(true), null, null, false);
        }
        if (buttonView == automaticButton) {
            pairings.setApproved(pairingUUID, true);
            analytics.postEvent("manual approval", String.valueOf(false), null, null, false);
        }
        updateApprovalButtons();
    }
}
Also used : Pairings(co.krypt.krypton.pairing.Pairings) Analytics(co.krypt.krypton.analytics.Analytics)

Example 17 with Analytics

use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.

the class DeviceDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_device_detail, container, false);
    final Pairing pairing = Silo.shared(getContext()).pairings().getPairing(pairingUUID);
    if (pairing == null) {
        return view;
    }
    View deviceCardView = inflater.inflate(R.layout.device_card, container, false);
    TextView deviceName = (TextView) deviceCardView.findViewById(R.id.deviceName);
    deviceName.setText(pairing.workstationName);
    manualButton = (RadioButton) deviceCardView.findViewById(R.id.alwaysAsk);
    automaticButton = (RadioButton) deviceCardView.findViewById(R.id.automaticApprovalButton);
    viewTemporaryApprovalsButton = deviceCardView.findViewById(R.id.temporaryApprovalsViewButton);
    viewTemporaryApprovalsButton.setOnClickListener(v -> {
        ApprovalsFragment f = ApprovalsFragment.newInstance(pairing.uuid);
        getFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_right_fast, R.anim.exit_to_right_fast, R.anim.enter_from_right_fast, R.anim.exit_to_right_fast).addToBackStack(null).add(R.id.childFragmentContainer, f).commit();
    });
    resetTemporaryApprovalsButton = deviceCardView.findViewById(R.id.temporaryApprovalsResetButton);
    resetTemporaryApprovalsButton.setOnClickListener(v -> {
        try {
            Approval.deleteApprovalsForPairing(Silo.shared(v.getContext()).pairings().dbHelper.getApprovalDao(), pairing.uuid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    });
    temporaryApprovalsContainer = deviceCardView.findViewById(R.id.temporaryApprovalsContainer);
    updateApprovalButtons();
    unpairButton = (Button) deviceCardView.findViewById(R.id.unpairButton);
    unpairButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Silo.shared(v.getContext()).unpair(pairing, true);
            new Analytics(getContext()).postEvent("device", "unpair", null, null, false);
            getFragmentManager().popBackStackImmediate();
        }
    });
    final SwitchCompat askUnknownHostsSwitch = (SwitchCompat) deviceCardView.findViewById(R.id.requireUnknownHostApprovalSwitch);
    askUnknownHostsSwitch.setChecked(new Pairings(getContext()).requireUnknownHostManualApproval(pairing));
    askUnknownHostsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            new Pairings(getContext()).setRequireUnknownHostManualApproval(pairing, isChecked);
        }
    });
    signatureLogAdapter.deviceCardView.set(deviceCardView);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    Context context = recyclerView.getContext();
    if (mColumnCount <= 1) {
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
    } else {
        recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
    }
    recyclerView.setAdapter(signatureLogAdapter);
    onDeviceLogReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            signatureLogAdapter.setLogs(Silo.shared(getContext()).pairings().getAllLogsTimeDescending(pairingUUID));
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Pairings.ON_DEVICE_LOG_ACTION);
    LocalBroadcastManager.getInstance(context).registerReceiver(onDeviceLogReceiver, filter);
    Silo.shared(getContext()).pairings().registerOnSharedPreferenceChangedListener(this);
    return view;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) ApprovalsFragment(co.krypt.krypton.approval.ApprovalsFragment) SQLException(java.sql.SQLException) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BroadcastReceiver(android.content.BroadcastReceiver) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Analytics(co.krypt.krypton.analytics.Analytics) Pairings(co.krypt.krypton.pairing.Pairings) GridLayoutManager(android.support.v7.widget.GridLayoutManager) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Pairing(co.krypt.krypton.pairing.Pairing) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 18 with Analytics

use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.

the class PairDialogFragment method createOutdatedPairingDialog.

private Dialog createOutdatedPairingDialog(final PairFragment pairFragment) {
    final Analytics analytics = new Analytics(getActivity());
    AlertDialog.Builder builder = new AlertDialog.Builder(getTargetFragment().getContext());
    builder.setMessage(pairFragment.getPendingPairingQR().workstationName + " is running an old version of kr. Please update kr by running \"curl https://krypt.co/kr-beta | sh\" and pair again.").setPositiveButton("OK", new DialogInterface.OnClickListener() {

        public void onClick(final DialogInterface dialog, int id) {
            if (getTargetFragment() instanceof PairListener) {
                final PairListener listener = (PairListener) getTargetFragment();
                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) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) Analytics(co.krypt.krypton.analytics.Analytics)

Example 19 with Analytics

use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.

the class PairFragment method onPairingSuccess.

private void onPairingSuccess(final Pairing pairing) {
    Intent successIntent = new Intent(PAIRING_SUCCESS_ACTION);
    successIntent.putExtra("deviceName", pairing.workstationName);
    Context context = getContext();
    if (context != null) {
        LocalBroadcastManager.getInstance(context).sendBroadcast(successIntent);
        new Analytics(context).postEvent("device", "pair", "success", null, false);
    }
    pairingStatusText.setText("Paired with\n" + pairing.workstationName);
    pairingStatusView.setVisibility(View.VISIBLE);
    pairingStatusView.postDelayed(new Runnable() {

        @Override
        public void run() {
            pendingPairingQR.set(null);
            pairingStatusView.setVisibility(View.INVISIBLE);
        }
    }, 2000);
}
Also used : Context(android.content.Context) Intent(android.content.Intent) Analytics(co.krypt.krypton.analytics.Analytics)

Example 20 with Analytics

use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.

the class KnownHostsRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    holder.knownHost = knownHosts.get(position);
    holder.hostName.setText(holder.knownHost.hostName);
    holder.hostKeyFingerprint.setText(holder.knownHost.fingerprint());
    CharSequence relativeDateTime = DateUtils.getRelativeDateTimeString(activity.getApplicationContext(), holder.knownHost.addedUnixSeconds * 1000, DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);
    holder.addedTime.setText(relativeDateTime);
    holder.mView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle("Unpin public key of " + holder.knownHost.hostName + "?");
            builder.setIcon(R.mipmap.ic_launcher);
            builder.setMessage("Only unpin this key if it has been purposefully changed on the server.");
            builder.setPositiveButton("Unpin", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    try {
                        Silo.shared(activity.getApplicationContext()).deleteKnownHost(holder.knownHost.hostName);
                        new Analytics(activity.getApplicationContext()).postEvent("known_host", "delete", null, null, false);
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            });
            builder.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                }
            });
            final AlertDialog dialog = builder.create();
            dialog.setOnShowListener(new DialogInterface.OnShowListener() {

                @Override
                public void onShow(DialogInterface dialogI) {
                    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(Color.RED);
                }
            });
            dialog.show();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) SQLException(java.sql.SQLException) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Analytics(co.krypt.krypton.analytics.Analytics)

Aggregations

Analytics (co.krypt.krypton.analytics.Analytics)20 View (android.view.View)8 TextView (android.widget.TextView)6 Intent (android.content.Intent)5 FragmentTransaction (android.support.v4.app.FragmentTransaction)5 MeStorage (co.krypt.krypton.me.MeStorage)5 Button (android.widget.Button)4 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 DialogInterface (android.content.DialogInterface)3 Fragment (android.support.v4.app.Fragment)3 CryptoException (co.krypt.krypton.exception.CryptoException)3 Pairing (co.krypt.krypton.pairing.Pairing)3 UnpairRequest (co.krypt.krypton.protocol.UnpairRequest)3 Activity (android.app.Activity)2 Dialog (android.app.Dialog)2 Context (android.content.Context)2 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ProtocolException (co.krypt.krypton.exception.ProtocolException)2