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.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";
    }//  w w  w .  j a  v  a 2  s .com

    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:at.alladin.rmbt.android.about.RMBTAboutFragment.java

private View createView(View view, LayoutInflater inflater) {
    activity = getActivity();/*from ww w.j  ava  2s  .co m*/

    getAppInfo(activity);

    final String clientUUID = String.format("U%s", ConfigHelper.getUUID(activity.getApplicationContext()));

    final String controlServerVersion = ConfigHelper.getControlServerVersion(activity);

    final ListView listView = (ListView) view.findViewById(R.id.aboutList);

    final ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    HashMap<String, String> item;
    item = new HashMap<String, String>();
    item.put("title", clientName);
    item.put("text1", this.getString(R.string.about_rtr_line1));
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", this.getString(R.string.about_version_title));
    item.put("text1", clientVersion);
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_clientid_title));
    item.put("text1", clientUUID);
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_web_title));
    item.put("text1", getString(R.string.about_web_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_email_title));
    item.put("text1", getString(R.string.about_email_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_terms_title));
    item.put("text1", getString(R.string.about_terms_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_git_title));
    item.put("text1", getString(R.string.about_git_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_dev_title));
    item.put("text1", getString(R.string.about_dev_line1));
    item.put("text2", getString(R.string.about_dev_line2));
    list.add(item);

    final String openSourceSoftwareLicenseInfo = GooglePlayServicesUtil
            .getOpenSourceSoftwareLicenseInfo(getActivity());

    if (openSourceSoftwareLicenseInfo != null) {
        item = new HashMap<String, String>();
        item.put("title", getString(R.string.about_gms_legal_title));
        item.put("text1", getString(R.string.about_gms_legal_line1));
        item.put("text2", "");
        list.add(item);
    }

    if (ConfigHelper.isDevEnabled(getActivity())) {
        item = new HashMap<String, String>();
        item.put("title", getString(R.string.about_test_counter_title));
        item.put("text1", Integer.toString(ConfigHelper.getTestCounter(getActivity())));
        item.put("text2", "");
        list.add(item);
    }

    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_control_server_version));
    item.put("text1", controlServerVersion != null ? controlServerVersion : "---");
    item.put("text2", "");
    list.add(item);

    sa = new RMBTAboutAdapter(getActivity(), list, R.layout.about_item,
            new String[] { "title", "text1", "text2" }, new int[] { R.id.title, R.id.text1, R.id.text2 });

    listView.setAdapter(sa);

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> l, final View v, final int position, final long id) {

            switch (position) {

            case 1:
                handleHiddenCode();
                break;

            case 2:
                final android.content.ClipboardManager clipBoard = (android.content.ClipboardManager) getActivity()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("client_uuid", clientUUID);
                clipBoard.setPrimaryClip(clip);
                final Toast toast = Toast.makeText(getActivity(), R.string.about_clientid_toast,
                        Toast.LENGTH_LONG);
                toast.show();
                break;

            case 3:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_web_link))));
                break;

            case 4:
                /* Create the Intent */
                final Intent emailIntent = new Intent(Intent.ACTION_SEND);

                /* Fill it with Data */
                emailIntent.setType("plain/text");
                emailIntent.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { getString(R.string.about_email_email) });
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.about_email_subject));
                emailIntent.putExtra(Intent.EXTRA_TEXT, "");

                /* Send it off to the Activity-Chooser */
                startActivity(Intent.createChooser(emailIntent, getString(R.string.about_email_sending)));

                break;

            case 5:
                final FragmentManager fm = activity.getSupportFragmentManager();
                FragmentTransaction ft;
                ft = fm.beginTransaction();
                ft.replace(R.id.fragment_content, new RMBTTermsFragment(), "terms");
                ft.addToBackStack("terms");
                ft.commit();
                break;

            case 6:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_git_link))));
                break;

            case 7:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_dev_link))));
                break;

            case 8:
                final String licenseInfo = GooglePlayServicesUtil
                        .getOpenSourceSoftwareLicenseInfo(getActivity());
                AlertDialog.Builder licenseDialog = new AlertDialog.Builder(getActivity());
                licenseDialog.setMessage(licenseInfo);
                licenseDialog.show();
                break;

            default:
                break;
            }
        }

    });

    return view;
}

From source file:com.mobshep.mobileshepherd.BrokenCrypto.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);//from w  w w .j  av  a  2 s.c o m

    showToast();

}

From source file:org.protocoderrunner.apprunner.api.PDevice.java

@ProtoMethod(description = "Copy the content into the clipboard", example = "")
@ProtoMethodParam(params = { "label", "text" })
public void copyToClipboard(String label, String text) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText(label, text));
}

From source file:com.italankin.dictionary.ui.main.MainActivity.java

private void setupRecyclerView() {
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    Resources res = getResources();
    int left = res.getDimensionPixelSize(R.dimen.list_item_margin_left);
    int top = res.getDimensionPixelSize(R.dimen.list_item_margin_top);
    int right = res.getDimensionPixelSize(R.dimen.list_item_margin_right);
    int bottom = res.getDimensionPixelSize(R.dimen.list_item_margin_bottom);
    mRecyclerView.addItemDecoration(new SimpleItemDecoration(left, top, right, bottom));

    // allow input layout to be scrolled along with recycler view
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override//from w w  w . j a  v  a  2 s.  co m
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            updateInputLayoutPosition();
        }
    });

    top = getResources().getDimensionPixelSize(R.dimen.list_top_offset);
    int inputHeight = getResources().getDimensionPixelSize(R.dimen.input_panel_height);
    mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), inputHeight + top, mRecyclerView.getPaddingRight(),
            mRecyclerView.getPaddingBottom());

    // on click listener

    mRecyclerViewAdapter = new TranslationAdapter(this);
    mRecyclerViewAdapter.setListener(new TranslationAdapter.OnAdapterItemClickListener() {
        @Override
        public void onItemClick(int position) {
            TranslationEx item = _presenter.getLastResult().translations.get(position);
            startActivity(TranslationActivity.getStartIntent(getApplicationContext(), item));
        }

        @Override
        public void onItemMenuClick(int position, int menuItemId) {
            ClipData clip = null;
            TranslationEx item = _presenter.getLastResult().translations.get(position);
            switch (menuItemId) {
            case R.id.action_lookup_word:
                lookupNext(item.text);
                break;

            case R.id.action_copy_mean:
                clip = ClipData.newPlainText("means", item.means);
                break;

            case R.id.action_copy_synonyms:
                clip = ClipData.newPlainText("synonyms", item.synonyms);
                break;

            case R.id.action_copy_translation:
                clip = ClipData.newPlainText("translation", item.text);
                break;
            }
            if (clip != null) {
                mClipboardManager.setPrimaryClip(clip);
                Toast.makeText(MainActivity.this, R.string.msg_copied, Toast.LENGTH_SHORT).show();
            }
        }
    });

    mRecyclerView.setAdapter(mRecyclerViewAdapter);
}

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

public void copyMessage4(View v) {

    String copiedMessage4 = messageFour.getText().toString();

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("message4", copiedMessage4);
    clipboard.setPrimaryClip(clip);/*from  w w w . j  a v  a 2s.  c o m*/

    showToast();

}

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   ww w.jav a 2 s  .c  om*/
    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:fr.free.nrw.commons.Utils.java

public static void copy(String label, String text, Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(label, text);
    clipboard.setPrimaryClip(clip);/*from  www.  ja  v a  2 s .  co  m*/
}

From source file:com.keylesspalace.tusky.fragment.SFragment.java

protected void more(final Status status, View view, final int position) {
    final String id = status.getActionableId();
    final String accountId = status.getActionableStatus().getAccount().getId();
    final String accountUsename = status.getActionableStatus().getAccount().getUsername();
    final Spanned content = status.getActionableStatus().getContent();
    final String statusUrl = status.getActionableStatus().getUrl();
    PopupMenu popup = new PopupMenu(getContext(), view);
    // Give a different menu depending on whether this is the user's own toot or not.
    if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) {
        popup.inflate(R.menu.status_more);
    } else {//from w  w w.  ja  v a2s .com
        popup.inflate(R.menu.status_more_for_user);
        Menu menu = popup.getMenu();
        if (status.getVisibility() == Status.Visibility.PRIVATE) {
            boolean reblogged = status.getReblogged();
            if (status.getReblog() != null)
                reblogged = status.getReblog().getReblogged();
            menu.findItem(R.id.status_reblog_private).setVisible(!reblogged);
            menu.findItem(R.id.status_unreblog_private).setVisible(reblogged);
        }
    }
    popup.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()) {
        case R.id.status_share_content: {
            StringBuilder sb = new StringBuilder();
            sb.append(status.getAccount().getUsername());
            sb.append(" - ");
            sb.append(status.getContent().toString());

            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, sb.toString());
            sendIntent.setType("text/plain");
            startActivity(
                    Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_content_to)));
            return true;
        }
        case R.id.status_share_link: {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, statusUrl);
            sendIntent.setType("text/plain");
            startActivity(
                    Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to)));
            return true;
        }
        case R.id.status_copy_link: {
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(null, statusUrl);
            clipboard.setPrimaryClip(clip);
            return true;
        }
        case R.id.status_mute: {
            timelineCases().mute(accountId);
            return true;
        }
        case R.id.status_block: {
            timelineCases().block(accountId);
            return true;
        }
        case R.id.status_report: {
            openReportPage(accountId, accountUsename, id, content);
            return true;
        }
        case R.id.status_unreblog_private: {
            onReblog(false, position);
            return true;
        }
        case R.id.status_reblog_private: {
            onReblog(true, position);
            return true;
        }
        case R.id.status_delete: {
            timelineCases().delete(id);
            removeItem(position);
            return true;
        }
        }
        return false;
    });
    popup.show();
}

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

public void copyMessage5(View v) {

    String copiedMessage5 = messageFive.getText().toString();

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("message5", copiedMessage5);
    clipboard.setPrimaryClip(clip);/*w w w. j  a  va  2 s  . c o  m*/

    showToast();

}