Search in sources :

Example 1 with ClipboardSecretEvent

use of com.auth0.sharelock.event.ClipboardSecretEvent in project sharelock-android by auth0.

the class ComposeActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    final int entryCount = getSupportFragmentManager().getBackStackEntryCount();
    final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if (entryCount == 0 && clipboardManager.hasPrimaryClip() && clipboardManager.getPrimaryClip().getItemCount() > 0) {
        final ClipData primaryClip = clipboardManager.getPrimaryClip();
        final ClipData.Item item = primaryClip.getItemAt(0);
        final String text = item.coerceToText(this).toString();
        if (text.trim().length() > 0) {
            final Snackbar snackbar = Snackbar.with(this).text(getString(R.string.paste_from_clipboard_prompt)).actionLabel(getString(R.string.paste_clipboard_action)).actionColorResource(R.color.sharelock_orange).actionListener(new ActionClickListener() {

                @Override
                public void onActionClicked(Snackbar snackbar) {
                    bus.postSticky(new ClipboardSecretEvent(text));
                    clipboardManager.setPrimaryClip(ClipData.newPlainText("", ""));
                }
            }).duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE);
            SnackbarManager.show(snackbar);
        }
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData) ActionClickListener(com.nispok.snackbar.listeners.ActionClickListener) Snackbar(com.nispok.snackbar.Snackbar) ClipboardSecretEvent(com.auth0.sharelock.event.ClipboardSecretEvent)

Aggregations

ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 ClipboardSecretEvent (com.auth0.sharelock.event.ClipboardSecretEvent)1 Snackbar (com.nispok.snackbar.Snackbar)1 ActionClickListener (com.nispok.snackbar.listeners.ActionClickListener)1