Example usage for android.content ClipboardManager setPrimaryClip

List of usage examples for android.content ClipboardManager setPrimaryClip

Introduction

In this page you can find the example usage for android.content ClipboardManager setPrimaryClip.

Prototype

public void setPrimaryClip(@NonNull ClipData clip) 

Source Link

Document

Sets the current primary clip on the clipboard.

Usage

From source file:com.gudong.appkit.ui.activity.MainActivity.java

private void showDonateDialog() {
    String htmlFileName = Utils.isChineseLanguage() ? "donate_ch.html" : "donate.html";
    DialogUtil.showCustomDialogWithTwoAction(this, getSupportFragmentManager(),
            getString(R.string.action_donate), htmlFileName, "donate", getString(R.string.action_close), null,
            getString(R.string.action_copy_to_clipboard), new DialogInterface.OnClickListener() {
                @Override// ww w.ja v a2s.  c  o m
                public void onClick(DialogInterface dialog, int which) {
                    String alipay = "com.eg.android.AlipayGphone";
                    AppEntity alipayApp = DataHelper.getAppByPackageName(alipay);
                    if (alipayApp != null) {
                        //??
                        ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                        cmb.setPrimaryClip(ClipData.newPlainText(null, "gudong.name@gmail.com"));
                        Toast.makeText(MainActivity.this, R.string.copy_success, Toast.LENGTH_LONG).show();
                        //?
                        try {
                            NavigationManager.openApp(MainActivity.this, alipay);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        Toast.makeText(MainActivity.this, getString(R.string.support_exception_for_alipay),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}

From source file:com.vsmartcard.acardemulator.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_copy:
        // Code to Copy the content of Text View to the Clip board.
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("simple text", textViewVPCDStatus.getText());
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getApplicationContext(), "Log copied to clipboard.", Toast.LENGTH_LONG).show();
        return true;
    case R.id.action_delete:
        textViewVPCDStatus.setText("");
        return true;
    case R.id.action_help:
        showStartupMessage();//  w w w.  j  av a 2s  .  co  m
        return true;
    case R.id.action_settings:
        startActivity(new Intent(this, SettingsActivity.class));
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:io.soramitsu.iroha.presenter.AssetReceivePresenter.java

public View.OnClickListener onPublicKeyTextClicked() {
    return new View.OnClickListener() {
        private static final String CLIP_DATA_LABEL_TEXT_DATA = "text_data";

        @Override//from   w w w  . j  a v  a 2  s  .  c o  m
        public void onClick(View view) {
            final Context context = assetReceiveView.getContext();

            ClipData.Item item = new ClipData.Item(assetReceiveView.getPublicKey());

            String[] mimeType = new String[1];
            mimeType[0] = ClipDescription.MIMETYPE_TEXT_URILIST;

            ClipData cd = new ClipData(new ClipDescription(CLIP_DATA_LABEL_TEXT_DATA, mimeType), item);

            ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
            cm.setPrimaryClip(cd);

            Toast.makeText(context, R.string.message_copy_to_clipboard, Toast.LENGTH_SHORT).show();
        }
    };
}

From source file:com.coinprism.wallet.QRCodeDialog.java

@android.support.annotation.NonNull
@Override/*from   www  . ja v  a  2s  .  c  om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    final View view = inflater.inflate(R.layout.dialog_qr_code, null);
    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(view);

    builder.setNegativeButton(getString(R.string.tab_wallet_dialog_qr_close),
            new DialogInterface.OnClickListener() {
                // Close the dialog
                public void onClick(DialogInterface dialog, int id) {
                    QRCodeDialog.this.getDialog().cancel();
                }
            });

    builder.setNeutralButton(getString(R.string.tab_wallet_dialog_qr_copy_address),
            new DialogInterface.OnClickListener() {
                // Copy the address into the clipboard
                public void onClick(DialogInterface dialogInterface, int i) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity()
                            .getSystemService(FragmentActivity.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("label", QRCodeDialog.this.address);
                    clipboard.setPrimaryClip(clip);
                }
            });

    final Dialog result = builder.create();
    result.setTitle(this.title);

    final ImageView qrCode = (ImageView) view.findViewById(R.id.qrCode);
    QRCodeEncoder.createQRCode(this.address, qrCode, 592, 592, 0, 0x00FFFFFF);

    return result;
}

From source file:me.zchang.onchart.ui.DonateFragment.java

@NonNull
@Override/*from www.  j  ava 2 s .  c  o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setPositiveButton(getString(R.string.button_donate), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = getActivity().getPackageManager()
                    .getLaunchIntentForPackage("com.eg.android.AlipayGphone");
            ClipboardManager clipboardManager = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData data = ClipData.newPlainText(ClipDescription.MIMETYPE_TEXT_PLAIN,
                    getString(R.string.alipay_account));
            clipboardManager.setPrimaryClip(data);
            if (intent != null) {
                Toast.makeText(getActivity(), getString(R.string.alert_clipboard_complete), Toast.LENGTH_LONG)
                        .show();
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), getString(R.string.alert_no_alipay), Toast.LENGTH_SHORT).show();
            }
        }
    }).setView(getActivity().getLayoutInflater().inflate(R.layout.fragment_donate, null));
    return builder.create();
}

From source file:com.softminds.matrixcalculator.OperationFragments.TraceFragment.java

private void RunToGetTrace(int position, ProgressDialog progressDialog) {
    double result = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position).getTrace();
    final String formatted = GetText(result);
    progressDialog.dismiss();/*from w  w w  .  j a va  2  s .  c  o  m*/
    String formatted2 = getString(R.string.trace_is) + " " + formatted;
    new AlertDialog.Builder(getContext()).setCancelable(true).setMessage(formatted2)
            .setTitle(R.string.trace_text)
            .setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ClipboardManager manager = (ClipboardManager) getContext()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData data = ClipData.newPlainText("TRACE_RES", formatted);
                    manager.setPrimaryClip(data);
                    if (manager.hasPrimaryClip())
                        Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show();
                    else
                        Log.e(TAG, "Cannot Put Data to Clip");
                    dialog.dismiss();
                }
            }).setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).show();
}

From source file:click.kobaken.rxirohaandroid_sample.presenter.AssetReceivePresenter.java

public View.OnClickListener onPublicKeyTextClicked() {
    return view -> {
        final String CLIP_DATA_LABEL_TEXT_DATA = "text_data";
        final Context context = assetReceiveView.getContext();

        ClipData.Item item = new ClipData.Item(assetReceiveView.getPublicKey());

        String[] mimeType = new String[1];
        mimeType[0] = ClipDescription.MIMETYPE_TEXT_URILIST;

        ClipData cd = new ClipData(new ClipDescription(CLIP_DATA_LABEL_TEXT_DATA, mimeType), item);

        ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
        cm.setPrimaryClip(cd);

        Toast.makeText(context, R.string.message_copy_to_clipboard, Toast.LENGTH_SHORT).show();
    };//from   w ww.ja v a  2 s .co  m
}

From source file:de.dknapps.pswgendroid.ServiceDetailFragment.java

/**
 * Generiert das Passwort und kopiert es in die Zwischenablage.
 * //from  w  ww. j av  a 2s  . c  o m
 * FIXME dkn Die callingActivity kann durch getActivity() ersetzt werden.
 */
public void onClickButtonCopyPassword(final Activity callingActivity, final View buttonOpenUrl) {
    try {
        String password = getValidatedOrGeneratedPassword();
        ClipboardManager clipboard = (ClipboardManager) callingActivity
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText(null, password));
    } catch (Exception e) {
        PswGenAdapter.handleThrowable(callingActivity, e);
    }
}

From source file:com.mobshep.mobileshepherd.BrokenCrypto1.java

public void copyMessage3(View v) {

    String copiedMessage3 = messageThree.getText().toString();

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("message3", copiedMessage3);
    clipboard.setPrimaryClip(clip);

    showToast();//  www .ja v a  2s .  c  o m
}

From source file:cat.ereza.customactivityoncrash.activity.DefaultErrorReportActivity.java

private void copyErrorToClipboard() {
    String errorInformation = CustomActivityOnCrash
            .getAllErrorDetailsFromIntent(DefaultErrorReportActivity.this, getIntent());

    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(
            getString(R.string.customactivityoncrash_error_activity_error_details_clipboard_label),
            errorInformation);//from  www. ja va 2  s. co m
    clipboard.setPrimaryClip(clip);
}