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.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/*  w  ww .  jav a 2 s.com*/
                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.ecuamobi.deckwallet.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_donate) {
        try {/*  w ww.j  a  va 2  s. c om*/
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(SCHEME_BITCOIN + ADDRESS_DONATE));
            startActivity(intent);
        } catch (Exception e) {
            ((ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE))
                    .setPrimaryClip(ClipData.newPlainText(getString(R.string.address), ADDRESS_DONATE));

            Util.showToast(this, R.string.donate_copied);
        }
        return true;
    }
    if (id == R.id.action_help) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(HELP_URL));
            startActivity(intent);
        } catch (Exception e) {
        }
        return true;
    }
    if (id == R.id.action_rate) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(MARKET_PREFIX_LOCAL + PACKAGE));
            startActivity(intent);
        } catch (Exception e) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(MARKET_PREFIX_REMOTE + PACKAGE));
            startActivity(intent);
        }
        return true;
    }
    if (id == R.id.action_clear) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.clear);
        builder.setMessage(R.string.clear_confirm);
        builder.setNegativeButton(R.string.no, null);
        builder.setPositiveButton(R.string.yes, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                clear();
            }
        });
        builder.show();
        return true;
    }
    if (id == R.id.action_check) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.check);
        builder.setMessage(R.string.check_confirm);
        builder.setNegativeButton(R.string.no, null);
        builder.setPositiveButton(R.string.yes, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                final String seed = temporalSeed;
                init(null);
                showFinalMenuItems(false);
                lastSeed = seed;
                Util.showToast(MainActivity.this, R.string.reenter_check, Toast.LENGTH_LONG);
            }
        });
        builder.show();
        return true;
    }
    if (id == R.id.action_share) {
        new GetAllAddresses().execute();
    }
    return super.onOptionsItemSelected(item);
}

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

private void showAlertDialog(final int pos) {
    CharSequence[] items = { getString(R.string.str_Save), 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) {
                SharedPrefStorage sharedPrefStorage = new SharedPrefStorage(getActivity());
                Gson gson = new Gson();

                if (!MyApplication.savedQuotesList.contains(popularQuotesList.get(pos))) {
                    MyApplication.savedQuotesList.add(popularQuotesList.get(pos));
                    sharedPrefStorage.setSavedQuotes(gson.toJson(MyApplication.savedQuotesList));
                }//from www. ja va  2  s  .c  om

                Snackbar.make(rootLayout, getString(R.string.str_AddedToFavoriteQuotes), Snackbar.LENGTH_SHORT)
                        .show();
            } else if (item == 1) {
                Intent shareIntent = new Intent(getActivity(), ShareActivity.class);
                shareIntent.putExtra("quote", popularQuotesList.get(pos).getQuoteText());
                shareIntent.putExtra("author", popularQuotesList.get(pos).getQuoteAuthor());
                startActivity(shareIntent);
            } else if (item == 2) {
                ClipboardManager clipboard = (ClipboardManager) getActivity()
                        .getSystemService(Activity.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("Copied Text", popularQuotesList.get(pos).getQuoteText()
                        + " - " + popularQuotesList.get(pos).getQuoteAuthor());
                clipboard.setPrimaryClip(clip);

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

From source file:com.microsoft.o365_android_onenote_rest.SnippetDetailFragment.java

@TargetApi(11)
private void clipboard11(TextView tv) {
    android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager) getActivity()
            .getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("OneNote", tv.getText());
    clipboardManager.setPrimaryClip(clipData);
}

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. ja v  a2  s  .  c o m
        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:com.mobshep.mobileshepherd.BrokenCrypto.java

public void copyMessage1(View v) {

    String copiedMessage = messageOne.getText().toString();

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("message1", copiedMessage);
    clipboard.setPrimaryClip(clip);//from  ww  w.  ja v a2  s .c  o m

    showToast();

}

From source file:com.codebutler.farebot.fragment.CardsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ClipboardManager clipboardManager = (ClipboardManager) getActivity()
            .getSystemService(Context.CLIPBOARD_SERVICE);
    try {// w  w w.  ja  v  a 2 s  . c om
        int itemId = item.getItemId();
        switch (itemId) {
        case R.id.import_file:
            Intent target = new Intent(Intent.ACTION_GET_CONTENT);
            target.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Environment.getExternalStorageDirectory()));
            target.setType("*/*");
            startActivityForResult(Intent.createChooser(target, getString(R.string.select_file)),
                    REQUEST_SELECT_FILE);
            return true;
        case R.id.import_clipboard:
            ClipData clip = clipboardManager.getPrimaryClip();
            if (clip != null && clip.getItemCount() > 0) {
                String text = clip.getItemAt(0).coerceToText(getActivity()).toString();
                onCardsImported(mExportHelper.importCards(text));
            }
            return true;
        case R.id.copy:
            clipboardManager.setPrimaryClip(ClipData.newPlainText(null, mExportHelper.exportCards()));
            Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
            return true;
        case R.id.share:
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, mExportHelper.exportCards());
            startActivity(intent);
            return true;
        case R.id.save:
            exportToFile();
            return true;
        }
    } catch (Exception ex) {
        Utils.showError(getActivity(), ex);
    }
    return false;
}

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

public void copyMessage2(View v) {

    String copiedMessage2 = messageTwo.getText().toString();

    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("message2", copiedMessage2);
    clipboard.setPrimaryClip(clip);/*from w w w .  j  a va 2 s .co m*/

    showToast();

}

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);//from   ww  w  .j a  v  a 2  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:arun.com.chromer.webheads.ui.context.WebHeadContextActivity.java

private void copyToClipboard(String label, String url) {
    final ClipData clip = ClipData.newPlainText(label, url);
    final ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    cm.setPrimaryClip(clip);//from ww w .ja v  a 2  s  .  c  om
    Toast.makeText(this, getString(R.string.copied) + " " + url, LENGTH_SHORT).show();
}