Search in sources :

Example 1 with MainActivity

use of co.krypt.kryptonite.MainActivity in project krypton-android by kryptco.

the class SettingsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_settings, container, false);
    Button doneButton = (Button) root.findViewById(R.id.doneButton);
    final Fragment self = this;
    doneButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MainActivity activity = (MainActivity) getActivity();
            activity.postCurrentActivePageView();
            getActivity().getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_bottom, R.anim.exit_to_bottom).hide(self).commit();
        }
    });
    TextView versionText = (TextView) root.findViewById(R.id.versionText);
    try {
        PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
        versionText.setText(packageInfo.versionName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    ImageButton deleteButton = (ImageButton) root.findViewById(R.id.deleteButton);
    deleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LocalAuthentication.requestAuthentication(getActivity(), "Destroy key pair permanently?", "You will have to generate a new key pair and re-add it to services like GitHub.", () -> new Thread(() -> {
                try {
                    new Analytics(getContext()).postEvent("keypair", "destroy", null, null, false);
                    EventBus.getDefault().post(new TeamService.RequestTeamOperation(Sigchain.RequestableTeamOperation.leave(), C.background(getContext())));
                    Silo.shared(getContext()).unpairAll();
                    KeyManager.deleteAllMeKeyPairs(getContext());
                    new MeStorage(getContext()).delete();
                    new JoinTeamProgress(getContext()).resetAndDeleteTeam(getContext());
                    new CreateTeamProgress(getContext()).reset();
                    startActivity(new Intent(getContext(), OnboardingActivity.class));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }).start());
        }
    });
    Button contactButton = (Button) root.findViewById(R.id.contactUsButton);
    contactButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            Uri data = Uri.parse("mailto:hello@krypt.co?subject=Krypton%20Feedback&body=");
            intent.setData(data);
            startActivity(intent);
        }
    });
    Button softwareButton = (Button) root.findViewById(R.id.softwareButton);
    softwareButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://krypt.co/app/open-source-libraries/"));
            startActivity(browserIntent);
        }
    });
    Button privacyButton = (Button) root.findViewById(R.id.privacyButton);
    privacyButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://krypt.co/app/privacy/"));
            startActivity(browserIntent);
        }
    });
    SwitchCompat disableAnalyticsSwitch = (SwitchCompat) root.findViewById(R.id.disableAnalyticsSwitch);
    disableAnalyticsSwitch.setChecked(new Analytics(getContext()).isDisabled());
    disableAnalyticsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            new Analytics(getContext()).setAnalyticsDisabled(isChecked);
        }
    });
    SwitchCompat enableApprovedNotifications = (SwitchCompat) root.findViewById(R.id.enableAutoApproveNotificationsSwitch);
    enableApprovedNotifications.setChecked(new Settings(getContext()).approvedNotificationsEnabled());
    enableApprovedNotifications.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            new Settings(getContext()).setApprovedNotificationsEnabled(isChecked);
        }
    });
    SwitchCompat silenceNotifications = (SwitchCompat) root.findViewById(R.id.silenceNotificationsSwitch);
    silenceNotifications.setChecked(new Settings(getContext()).silenceNotifications());
    silenceNotifications.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            new Settings(getContext()).setSilenceNotifications(isChecked);
        }
    });
    ImageButton exportLogsButton = (ImageButton) root.findViewById(R.id.exportLogsButton);
    exportLogsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                String token = AuditLogContentProvider.setToken(v.getContext());
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Krypton Audit Log");
                sendIntent.setType("application/x-sqlite3");
                Uri auditLogUriWithToken = AuditLogContentProvider.getAuditLogURIWithToken();
                if (auditLogUriWithToken == null) {
                    return;
                }
                sendIntent.putExtra(Intent.EXTRA_STREAM, auditLogUriWithToken);
                startActivity(sendIntent);
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(v.getContext(), "Error exporting audit log: " + e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    });
    Button editKnownHostsButton = (Button) root.findViewById(R.id.editKnownHostsButton);
    editKnownHostsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getView().setTranslationZ(0);
            FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
            KnownHostsFragment knownHostsFragment = new KnownHostsFragment();
            transaction.setCustomAnimations(R.anim.enter_from_bottom, R.anim.delayed).replace(R.id.fragmentOverlay, knownHostsFragment).commit();
            new Analytics(getActivity().getApplicationContext()).postPageView("KnownHostsEdit");
        }
    });
    return root;
}
Also used : MainActivity(co.krypt.kryptonite.MainActivity) Fragment(android.support.v4.app.Fragment) KnownHostsFragment(co.krypt.krypton.knownhosts.KnownHostsFragment) Uri(android.net.Uri) ImageButton(android.widget.ImageButton) FragmentTransaction(android.support.v4.app.FragmentTransaction) PackageManager(android.content.pm.PackageManager) ImageButton(android.widget.ImageButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextView(android.widget.TextView) PackageInfo(android.content.pm.PackageInfo) JoinTeamProgress(co.krypt.krypton.team.onboarding.join.JoinTeamProgress) Intent(android.content.Intent) IOException(java.io.IOException) View(android.view.View) TextView(android.widget.TextView) Analytics(co.krypt.krypton.analytics.Analytics) IOException(java.io.IOException) MeStorage(co.krypt.krypton.me.MeStorage) CreateTeamProgress(co.krypt.krypton.team.onboarding.create.CreateTeamProgress) KnownHostsFragment(co.krypt.krypton.knownhosts.KnownHostsFragment) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 2 with MainActivity

use of co.krypt.kryptonite.MainActivity in project krypton-android by kryptco.

the class DevicesFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_devices_list, container, false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    // Set the adapter
    Context context = recyclerView.getContext();
    if (mColumnCount <= 1) {
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
    } else {
        recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
    }
    recyclerView.setAdapter(devicesAdapter);
    noPairedDevicesContainer = view.findViewById(R.id.devicesEmptyContainer);
    Button pairNewDeviceButton = (Button) view.findViewById(R.id.pairNewDeviceButton);
    pairNewDeviceButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Activity activity = getActivity();
            if (activity instanceof MainActivity) {
                ((MainActivity) activity).setActiveTab(MainActivity.PAIR_FRAGMENT_POSITION);
            }
        }
    });
    onDeviceLogReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            populateDevices();
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Pairings.ON_DEVICE_LOG_ACTION);
    LocalBroadcastManager.getInstance(getContext()).registerReceiver(onDeviceLogReceiver, filter);
    Silo.shared(getContext()).pairings().registerOnSharedPreferenceChangedListener(this);
    populateDevices();
    return view;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) MainActivity(co.krypt.kryptonite.MainActivity) Activity(android.app.Activity) Intent(android.content.Intent) MainActivity(co.krypt.kryptonite.MainActivity) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BroadcastReceiver(android.content.BroadcastReceiver) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Button(android.widget.Button) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with MainActivity

use of co.krypt.kryptonite.MainActivity in project krypton-android by kryptco.

the class HelpFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_help, container, false);
    Button doneButton = (Button) root.findViewById(R.id.doneButton);
    final Fragment self = this;
    doneButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MainActivity activity = (MainActivity) getActivity();
            activity.postCurrentActivePageView();
            getActivity().getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_bottom, R.anim.exit_to_bottom).hide(self).commit();
        }
    });
    Button pairButton = (Button) root.findViewById(R.id.pairButton);
    pairButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Activity activity = getActivity();
            if (activity != null && activity instanceof MainActivity) {
                MainActivity mainActivity = (MainActivity) activity;
                mainActivity.getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_bottom, R.anim.exit_to_bottom).hide(self).remove(self).commit();
                mainActivity.setActiveTab(MainActivity.PAIR_FRAGMENT_POSITION);
            }
        }
    });
    curlButton = root.findViewById(R.id.curlHelp);
    brewButton = root.findViewById(R.id.brewHelp);
    npmButton = root.findViewById(R.id.npmHelp);
    moreButton = root.findViewById(R.id.moreHelp);
    installCommand = root.findViewById(R.id.installCommandHelp);
    curlButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            installCommand.setText("$ curl https://krypt.co/kr | sh");
            resetButtons();
            curlButton.setTextColor(getResources().getColor(R.color.appGreen));
            new Analytics(getContext()).postEvent("help_install", "curl", null, null, false);
        }
    });
    brewButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            installCommand.setText("$ brew install kryptco/tap/kr");
            resetButtons();
            brewButton.setTextColor(getResources().getColor(R.color.appGreen));
            new Analytics(getContext()).postEvent("help_install", "brew", null, null, false);
        }
    });
    npmButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            installCommand.setText("$ npm install -g krd # mac only");
            resetButtons();
            npmButton.setTextColor(getResources().getColor(R.color.appGreen));
            new Analytics(getContext()).postEvent("help_install", "npm", null, null, false);
        }
    });
    moreButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            installCommand.setText("# go to https://krypt.co/install");
            resetButtons();
            moreButton.setTextColor(getResources().getColor(R.color.appGreen));
            new Analytics(getContext()).postEvent("help_install", "more", null, null, false);
        }
    });
    return root;
}
Also used : Button(android.widget.Button) MainActivity(co.krypt.kryptonite.MainActivity) Activity(android.app.Activity) MainActivity(co.krypt.kryptonite.MainActivity) TextView(android.widget.TextView) View(android.view.View) Fragment(android.support.v4.app.Fragment) Analytics(co.krypt.krypton.analytics.Analytics)

Aggregations

View (android.view.View)3 Button (android.widget.Button)3 MainActivity (co.krypt.kryptonite.MainActivity)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 Fragment (android.support.v4.app.Fragment)2 TextView (android.widget.TextView)2 Analytics (co.krypt.krypton.analytics.Analytics)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 CompoundButton (android.widget.CompoundButton)1