Example usage for android.content ClipData newPlainText

List of usage examples for android.content ClipData newPlainText

Introduction

In this page you can find the example usage for android.content ClipData newPlainText.

Prototype

static public ClipData newPlainText(CharSequence label, CharSequence text) 

Source Link

Document

Create a new ClipData holding data of the type ClipDescription#MIMETYPE_TEXT_PLAIN .

Usage

From source file:com.druk.bonjour.browser.ui.adapter.TxtRecordsAdapter.java

public void onItemClick(View view, int position) {
    Context context = view.getContext();

    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(getKey(position), getValue(position));
    clipboard.setPrimaryClip(clip);/*from   w ww .  j a  v  a  2 s  . c o  m*/

    Snackbar snackbar = Snackbar.make(view,
            context.getResources().getString(R.string.copy_toast_message, getKey(position)),
            Snackbar.LENGTH_LONG);
    snackbar.getView().setBackgroundResource(R.color.accent);
    snackbar.show();
}

From source file:com.coloreight.plugin.clipboard.Clipboard.java

public void copy(final String text, final CallbackContext callbackContext) {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            ClipboardManager clipboard = (ClipboardManager) cordova.getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);

            try {
                ClipData clip = ClipData.newPlainText("Public.Text", text);

                clipboard.setPrimaryClip(clip);

                callbackContext.success(text);
            } catch (Exception e) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
            }/* w w  w.  j  a  va 2s  .  co  m*/
        }
    });
}

From source file:com.google.android.gcm.demo.ui.AbstractFragment.java

@Override
public boolean onLongClick(View v) {
    // Copy in the clipboard the value of the selected widget.
    String value = getValue(v.getId());
    if (value.length() > 0) {
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("GcmTestApp clipboard", value));
        Toast.makeText(getActivity(), value + "\nhas been copied in the clipboard", Toast.LENGTH_SHORT).show();
        return true;
    }//from ww w.  ja  v a 2 s . com
    return false;
}

From source file:com.xw.project.gracefulmovies.view.activity.AboutActivity.java

@OnClick({ R.id.about_gmail_img, R.id.about_github_img, R.id.about_license_text })
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.about_gmail_img:
        String s1 = "";
        String s2 = getString(R.string.gmail_address);

        ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = ClipData.newPlainText("content", s2);
        cmb.setPrimaryClip(clipData);//ww w .j ava  2  s.  c o  m

        showToast(getString(R.string.hint_clipboard, s1, s2));
        break;
    case R.id.about_github_img:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse(getString(R.string.github_page)));
        startActivity(Intent.createChooser(intent, "?"));
        break;
    case R.id.about_license_text:
        navigateTo(OpenLicenseActivity.class);
        break;
    }
}

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

@android.support.annotation.NonNull
@Override//from w  w w .ja va2s.  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:com.softminds.matrixcalculator.OperationFragments.NormOne.java

@Override
public void onListItemClick(ListView L, View V, int position, long id) {
    final int pos = position;
    final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
            getContext());//from  w  w w.ja  v  a 2 s .c  o  m
    builder.setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            ClipboardManager clipboardManager = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("NORM_ONE_RES", GetText(
                    ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(pos).getNorm1()));
            clipboardManager.setPrimaryClip(clipData);
            if (clipboardManager.hasPrimaryClip()) {
                Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show();
            } else
                Log.d("ClipData", "Failed to set to Clip board");
            dialogInterface.dismiss();
        }
    });

    builder.setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    builder.setMessage("First Norm is : " + GetText(
            ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position).getNorm1()));
    builder.setTitle(R.string.normOne);
    builder.setCancelable(false);
    builder.show();
}

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

@Override
public void onListItemClick(ListView L, View V, int position, long id) {
    final int pos = position;
    final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
            getContext());//w w  w. ja va 2  s .  c o m
    builder.setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            ClipboardManager clipboardManager = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("NORM_TWO_RES", GetText(
                    ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(pos).getNorm2()));
            clipboardManager.setPrimaryClip(clipData);
            if (clipboardManager.hasPrimaryClip()) {
                Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show();
            } else
                Log.d("ClipData", "Failed to set to Clip board");
            dialogInterface.dismiss();
        }
    });

    builder.setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    builder.setMessage("Second Norm is : " + GetText(
            ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position).getNorm2()));
    builder.setTitle(R.string.normTwo);
    builder.setCancelable(false);
    builder.show();
}

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

@Override
public void onListItemClick(ListView L, View V, int position, long id) {
    final int pos = position;
    final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
            getContext());/* w  w  w . j  ava2 s .  c o m*/
    builder.setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            ClipboardManager clipboardManager = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("NORM_FREB_RES",
                    GetText(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(pos)
                            .getNormFrobenious()));
            clipboardManager.setPrimaryClip(clipData);
            if (clipboardManager.hasPrimaryClip()) {
                Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show();
            } else
                Log.d("ClipData", "Failed to set to Clip board");
            dialogInterface.dismiss();
        }
    });

    builder.setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    builder.setMessage("Frebenious Norm is : " + GetText(((GlobalValues) getActivity().getApplication())
            .GetCompleteList().get(position).getNormFrobenious()));
    builder.setTitle(R.string.normFreb);
    builder.setCancelable(false);
    builder.show();
}

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

@Override
public void onListItemClick(ListView L, View V, int position, long id) {
    final int pos = position;
    final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
            getContext());//  w  w  w  .j a v  a2  s .  c o  m
    builder.setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            ClipboardManager clipboardManager = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("NORM_INFINITY_RES",
                    GetText(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(pos)
                            .getNormInfinity()));
            clipboardManager.setPrimaryClip(clipData);
            if (clipboardManager.hasPrimaryClip()) {
                Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show();
            } else
                Log.d("ClipData", "Failed to set to Clip board");
            dialogInterface.dismiss();
        }
    });

    builder.setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    builder.setMessage("Infinity Norm is : " + GetText(
            ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position).getNormInfinity()));
    builder.setTitle(R.string.normInfinity);
    builder.setCancelable(false);
    builder.show();
}

From source file:ooo.oxo.apps.earth.AboutActivity.java

private void copy(String text) {
    cm.setPrimaryClip(ClipData.newPlainText(text, text));
    Toast.makeText(this, getString(R.string.about_copied, text), Toast.LENGTH_SHORT).show();
}