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:org.gdgsp.fragment.EventFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share:
        Intent sharePageIntent = new Intent();
        sharePageIntent.setAction(Intent.ACTION_SEND);
        sharePageIntent.putExtra(Intent.EXTRA_TEXT, event.getName() + " " + event.getLink());
        sharePageIntent.setType("text/plain");
        startActivity(Intent.createChooser(sharePageIntent, getResources().getText(R.string.share)));
        return true;
    case R.id.menu_people:
        Intent intent = new Intent(activity, PeopleActivity.class);
        intent.putExtra("event", event);
        startActivity(intent);/*  w w w .j a  v  a2 s  . c o m*/
        return true;
    case R.id.menu_copylink:
        if (Build.VERSION.SDK_INT <= 10) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(event.getLink());
        } else {
            ClipboardManager clipboardManager = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText(event.getLink(), event.getLink());
            clipboardManager.setPrimaryClip(clipData);
        }
        Other.showToast(activity, getString(R.string.link_copyed));
        return true;
    case R.id.menu_openinbrowser:
        Other.openSite(activity, event.getLink());
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.coinblesk.client.TransactionDetailActivity.java

private void copyTx() {
    Log.d(TAG, "Copy Transaction Hash: " + transactionHash);
    Log.d(TAG, "Transaction Details:\n" + walletServiceBinder.getTransaction(transactionHash).toString());

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("Your TX", transactionHash);
    clipboard.setPrimaryClip(clip);

    View root = findViewById(android.R.id.content);
    if (root != null) {
        Snackbar.make(root, UIUtils.toFriendlySnackbarString(this, getString(R.string.snackbar_address_copied)),
                Snackbar.LENGTH_LONG).setActionTextColor(ContextCompat.getColor(this, R.color.colorAccent))
                .setAction("Action", null).show();
    }//from w ww  .j  a v a2s .c  o  m
}

From source file:com.raza.betternts.activities.TabFragment1.java

private void menuOption(Cursor cursor, int selectedOption) {
    String name = cursor.getString(cursor.getColumnIndex(DbSchema.COL_NAME));
    String url = cursor.getString(cursor.getColumnIndex(DbSchema.COL_URL));
    switch (selectedOption) {
    //Open in browser
    case 0: {//from   w w  w.  j  a  v  a2  s .c  om
        Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(browse);
        break;
    }
    //Copy to clipboard
    case 1: {
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText(name, url);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getContext(), "Link copied to clipboard", Toast.LENGTH_SHORT).show();
        break;
    }
    //Share
    case 2: {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, url);
        sendIntent.setType("text/plain");
        startActivity(sendIntent);
        break;
    }
    case 3: {
        moveToIgnored(cursor);
        Toast.makeText(getContext(), name + "\nremoved to ignored posts", Toast.LENGTH_SHORT).show();
        break;
    }
    }
}

From source file:kr.rrcoporation.rrfestival.festival.activity.FestivalDetailActivity.java

@Override
public void onClick(View v) {
    int id = v.getId();

    switch (id) {
    case R.id.button_facebook:
        break;/*from   w  ww .  ja v  a 2  s  .c  o  m*/
    case R.id.textview_address:
        //TODO: check.
        //                MapFragment.newInstance(bodyItem.getMapy(), bodyItem.getMapx(), "FROM_DETAIL");
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("address", address.getText());
        clipboard.setPrimaryClip(clip);
        Toast.makeText(this, " ?? .", Toast.LENGTH_SHORT)
                .show();
        break;
    case R.id.imageview_share:
        sendLocationToKakao();
        break;
    case R.id.fab:
        if (db == null) {
            db = this.openOrCreateDatabase("FESTIVALS.db", Context.MODE_PRIVATE, null);
        }
        saveBookmark();
        break;
    }
}

From source file:com.qiscus.sdk.ui.QiscusBaseChatActivity.java

protected void onSelectedCommentsAction(ActionMode mode, MenuItem item, List<QiscusComment> selectedComments) {
    int i = item.getItemId();
    String text = "";
    for (QiscusComment qiscusComment : selectedComments) {
        text += qiscusComment.getSender() + ": ";
        text += qiscusComment.isAttachment() ? qiscusComment.getAttachmentName() : qiscusComment.getMessage();
        text += "\n";
    }/*from w  w  w.  j  a v  a2  s.  c om*/

    if (i == R.id.action_copy) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText(getString(R.string.chat_activity_label_clipboard), text);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(this, selectedComments.size() + " messages copied!", Toast.LENGTH_SHORT).show();
    } else if (i == R.id.action_share) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, "Messages");
        intent.putExtra(Intent.EXTRA_TEXT, text);
        startActivity(Intent.createChooser(intent, "Share"));
    }
    mode.finish();
}

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());// w w  w. j  av  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  .  j  a  v  a2s .  c om
    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.endiansoftware.echo.remotewatch.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    mDisplay = (TextView) findViewById(R.id.display);

    context = getApplicationContext();/*  w  w w. j  ava2s  . c  om*/

    // Check device for Play Services APK. If check succeeds, proceed with GCM registration.
    if (checkPlayServices()) {
        gcm = GoogleCloudMessaging.getInstance(this);
        regid = getRegistrationId(context);

        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("label", regid);
        clipboard.setPrimaryClip(clip);

        if (regid.isEmpty()) {
            registerInBackground();
        }
    } else {
        Log.i(TAG, "No valid Google Play Services APK found.");
    }
}

From source file:co.dilaver.quoter.fragments.QODFragment.java

@Override
public void qodCopyClicked() {
    if (!qodString.equals("") && !authorString.equals("")) {
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Activity.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("Copied Text", qodString + " - " + authorString);
        clipboard.setPrimaryClip(clip);

        Snackbar.make(rootLayout, getString(R.string.str_QuoteCopied), Snackbar.LENGTH_SHORT).show();
    }//w  w w  .j  a v a2s . c o  m
}

From source file:co.dilaver.quoter.fragments.FavoriteQuotesFragment.java

private void showAlertDialog(final int pos) {
    CharSequence[] items = { getString(R.string.str_Delete), getString(R.string.str_Share),
            getString(R.string.str_Copy) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                //Delete

                SharedPrefStorage sharedPrefStorage = new SharedPrefStorage(getActivity());
                Gson gson = new Gson();

                for (int i = 0; i < MyApplication.savedQuotesList.size(); i++) {
                    if (MyApplication.savedQuotesList.get(i).getQuoteAuthor()
                            .equals(favoriteQuotesList.get(pos).getQuoteAuthor())
                            && MyApplication.savedQuotesList.get(i).getQuoteText()
                                    .equals(favoriteQuotesList.get(pos).getQuoteText())) {

                        MyApplication.savedQuotesList.remove(i);
                        favoriteQuotesList = MyApplication.savedQuotesList;
                        sharedPrefStorage.setSavedQuotes(gson.toJson(MyApplication.savedQuotesList));
                    }/*from ww w .ja  v a  2  s . c o m*/
                }

                quotesAdapter.setList(favoriteQuotesList);
                quotesAdapter.notifyDataSetChanged();

            } else if (item == 1) {
                Intent shareIntent = new Intent(getActivity(), ShareActivity.class);
                shareIntent.putExtra("quote", favoriteQuotesList.get(pos).getQuoteText());
                shareIntent.putExtra("author", favoriteQuotesList.get(pos).getQuoteAuthor());
                startActivity(shareIntent);
            } else if (item == 2) {
                ClipboardManager clipboard = (ClipboardManager) getActivity()
                        .getSystemService(Activity.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("Copied Text", favoriteQuotesList.get(pos).getQuoteText()
                        + " - " + favoriteQuotesList.get(pos).getQuoteAuthor());
                clipboard.setPrimaryClip(clip);

                Snackbar.make(rootLayout, getString(R.string.str_QuoteCopied), Snackbar.LENGTH_SHORT).show();
            }
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}