Example usage for android.text ClipboardManager setText

List of usage examples for android.text ClipboardManager setText

Introduction

In this page you can find the example usage for android.text ClipboardManager setText.

Prototype

public abstract void setText(CharSequence text);

Source Link

Document

Sets the contents of the clipboard to the specified text.

Usage

From source file:de.kodejak.hashr.fragmentHashFromFile.java

public void OnButtonToClipboardClick() {
    TextView txtOutput = (TextView) getView().findViewById(R.id.edOutput);
    String strOutput = txtOutput.getText().toString();

    ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setText(strOutput);

    Toast.makeText(mContext, fragJobStr + " copied to clipboard", Toast.LENGTH_SHORT).show();
}

From source file:org.solovyev.android.calculator.entities.BaseEntitiesFragment.java

@SuppressWarnings("deprecation")
protected final void copyText(@Nullable String text) {
    if (!Strings.isEmpty(text)) {
        return;/*from  w w w  . j a v a2s .c  om*/
    }
    final ClipboardManager clipboard = (ClipboardManager) getActivity()
            .getSystemService(Activity.CLIPBOARD_SERVICE);
    clipboard.setText(text);
}

From source file:org.adblockplus.android.AdvancedPreferences.java

@Override
protected Dialog onCreateDialog(final int id) {
    Dialog dialog = null;//from   w w w .j a v a2s  .  c  o m
    switch (id) {
    case CONFIGURATION_DIALOG:
        final List<String> items = new ArrayList<String>();
        items.add(AdblockPlus.getDeviceName());
        items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT,
                AdblockPlus.getApplication().getBuildNumber()));

        final ProxyService proxyService = this.serviceBinder.get();

        if (proxyService != null) {
            items.add(String.format("Local port: %d", proxyService.port));
            if (proxyService.isIptables()) {
                items.add("Running in root mode");
                items.add("iptables output:");
                final List<String> output = IptablesProxyConfigurator
                        .getIptablesOutput(getApplicationContext());
                if (output != null) {
                    for (final String line : output) {
                        if (StringUtils.isNotEmpty(line))
                            items.add(line);
                    }
                }
            }
            if (proxyService.isNativeProxyAutoConfigured()) {
                items.add("Has native proxy auto configured");
            }
            if (ProxyService.GLOBAL_PROXY_USER_CONFIGURABLE) {
                final ProxyProperties pp = ProxyProperties.fromContext(getApplicationContext());
                if (pp != null) {
                    items.add("System settings:");
                    items.add(String.format("Host: [%s] Port: [%d] Excl: [%s]", pp.getHost(), pp.getPort(),
                            pp.getExclusionList()));
                }
            }
            items.add("Proxy settings:");
            items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]",
                    proxyService.proxy.props.getProperty("adblock.proxyHost"),
                    proxyService.proxy.props.getProperty("adblock.proxyPort"),
                    proxyService.proxy.props.getProperty("adblock.proxyExcl")));
            if (proxyService.proxy.props.getProperty("adblock.auth") != null)
                items.add("Auth: yes");
        } else {
            items.add("Service not running");
        }

        final ScrollView scrollPane = new ScrollView(this);
        final TextView messageText = new TextView(this);
        messageText.setPadding(12, 6, 12, 6);
        messageText.setText(TextUtils.join("\n", items));
        messageText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                final TextView showTextParam = (TextView) v;
                manager.setText(showTextParam.getText());
                Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_SHORT).show();
            }
        });
        scrollPane.addView(messageText);

        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(scrollPane).setTitle(R.string.configuration_name)
                .setIcon(android.R.drawable.ic_dialog_info).setCancelable(false)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.cancel();
                    }
                });
        dialog = builder.create();
        break;
    }
    return dialog;
}

From source file:com.fbbackup.TagImageDetailActivity.java

private void setListener() {
    btn_share.setOnClickListener(new Button.OnClickListener() {

        @Override/* ww  w  .  ja v a2 s .  com*/
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // Gets a handle to the clipboard service.
            ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(clipBoardText);

            PackageManager pm = getPackageManager();
            Intent intent = pm.getLaunchIntentForPackage("jp.naver.line.android");
            startActivity(intent);

        }

    });

    btn_download_photo.setOnClickListener(new ImageButton.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            DownloadSinglePicTask download = new DownloadSinglePicTask();

            download.setContext(TagImageDetailActivity.this);

            download.setAlbunPhotoUrl(clipBoardText);

            Log.w("downloadpic", "ImageDetail albumName:" + albumName);

            download.setPath(extStorageDirectory + "/DCIM/FBBackup/" + name + "/TagMe" + "/");

            download.execute("test");
        }

    });
}

From source file:com.kaproduction.malibilgiler.MainActivity.java

private void copyToClipboard(String text) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);
    } else {//from  w  w  w .  j  a  v  a2  s  . c  o m
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", text);
        clipboard.setPrimaryClip(clip);
    }
}

From source file:com.feathercoin.wallet.feathercoin.ui.SendingAddressesFragment.java

private void handleCopyToClipboard(final String address) {
    int sdk = android.os.Build.VERSION.SDK_INT;
    if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) activity
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(address);
    } else {/* w  ww. java2 s .c om*/
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) activity
                .getSystemService(Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText("address", address);
        clipboard.setPrimaryClip(clip);
    }

    activity.toast(R.string.wallet_address_fragment_clipboard_msg);
}

From source file:com.microsoft.graph.snippets.SnippetDetailFragment.java

private void clipboard(TextView tv) {
    // which view are we copying to the clipboard?
    int which;/*w w  w. j  a  v  a 2s. c  o  m*/

    switch (tv.getId()) {
    case txt_request_url: // the url field
        which = code_snippet;
        break;

    case txt_response_body: // the response body
        which = raw_object;
        break;

    default:
        which = UNSET; // don't assign a prefix
    }

    // if we know which view we're copying, prefix it with useful info
    String what = which == UNSET ? "" : getString(which) + " ";

    // concat the clipboard data to this String
    what += getString(clippy);

    // inform the user that data was added to the clipboard
    Toast.makeText(getActivity(), what, Toast.LENGTH_SHORT).show();

    // depending on our API, do it one way or another...
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        // old way
        ClipboardManager clipboardManager = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboardManager.setText(tv.getText());
    } else {
        clipboard11(tv);
    }
}

From source file:org.kontalk.ui.DonationFragment.java

private void donateBitcoin() {
    final String address = getString(R.string.bitcoin_address);
    Uri uri = Uri.parse("bitcoin:" + address);
    Intent intent = SystemUtils.externalIntent(Intent.ACTION_VIEW, Uri.parse(uri.toString()));

    Activity ctx = getActivity();//  w w  w  .j av  a  2  s  .  c  o m
    final PackageManager pm = ctx.getPackageManager();
    if (pm.resolveActivity(intent, 0) != null)
        startActivity(intent);
    else
        new MaterialDialog.Builder(getActivity()).title(R.string.title_bitcoin_dialog)
                .content(getString(R.string.text_bitcoin_dialog, address)).positiveText(android.R.string.ok)
                .neutralText(R.string.copy_clipboard).onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        ClipboardManager cpm = (ClipboardManager) getActivity()
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        cpm.setText(address);

                        Toast.makeText(getActivity(), R.string.bitcoin_clipboard_copied, Toast.LENGTH_LONG)
                                .show();
                    }
                }).show();
}

From source file:marto.rtl_tcp_andro.StreamActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stream);
    prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);

    terminal = (TextView) findViewById(R.id.terminal);
    scroll = (ScrollView) findViewById(R.id.ScrollArea);
    arguments = (EditText) findViewById(R.id.commandline);

    terminal.setText(Log.getFullLog());// w w w .j a  v  a2 s.  c  om

    ((Button) findViewById(R.id.enable_gui)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.statusmsg).setVisibility(View.GONE);
            findViewById(R.id.gui).setVisibility(View.VISIBLE);
        }
    });

    (forceroot = (CheckBox) findViewById(R.id.forceRoot))
            .setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    final SharedPreferences.Editor editor = prefs.edit();

                    editor.putBoolean(DISABLE_JAVA_FIX_PREF, isChecked);

                    editor.commit();
                }
            });
    forceroot.setChecked(prefs.getBoolean(DISABLE_JAVA_FIX_PREF, false));

    (onoff = (ToggleButton) findViewById(R.id.onoff)).setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            onoff.setChecked(false);
            Log.clear();
            startActivityForResult(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("iqsrc://" + arguments.getText().toString())), START_REQ_CODE);
        }
    });

    ((Button) findViewById(R.id.copybutton)).setOnClickListener(new Button.OnClickListener() {

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            final String textToClip = terminal.getText().toString();
            int sdk = android.os.Build.VERSION.SDK_INT;
            if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                        Context.CLIPBOARD_SERVICE);
                clipboard.setText(textToClip);
            } else {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                        Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText("text label", textToClip);
                clipboard.setPrimaryClip(clip);
            }
            Toast.makeText(getApplicationContext(), R.string.copied_to_clip, Toast.LENGTH_LONG).show();
        }
    });

    ((Button) findViewById(R.id.clearbutton)).setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.clear();
        }
    });

    ((Button) findViewById(R.id.help)).setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(dialogs.DIAG_ABOUT);
        }
    });

    ((Button) findViewById(R.id.license)).setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(dialogs.DIAG_LICENSE);
        }
    });
}

From source file:microsoft.aspnet.signalr.client.test.integration.android.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_settings:
        startActivity(new Intent(this, SignalRPreferenceActivity.class));
        return true;

    case R.id.menu_run_tests:
        if (ApplicationContext.getServerUrl().trim().equals("")) {
            startActivity(new Intent(this, SignalRPreferenceActivity.class));
        } else {//from  www . j a  va 2s  . co  m
            runTests();
        }
        return true;

    case R.id.menu_check_all:
        changeCheckAllTests(true);
        return true;

    case R.id.menu_uncheck_all:
        changeCheckAllTests(false);
        return true;

    case R.id.menu_reset:
        refreshTestGroupsAndLog();
        return true;

    case R.id.menu_view_log:
        AlertDialog.Builder logDialogBuilder = new AlertDialog.Builder(this);
        logDialogBuilder.setTitle("Log");

        final WebView webView = new WebView(this);

        String logContent = TextUtils.htmlEncode(mLog.toString()).replace("\n", "<br />");
        String logHtml = "<html><body><pre>" + logContent + "</pre></body></html>";
        webView.loadData(logHtml, "text/html", "utf-8");

        logDialogBuilder.setPositiveButton("Copy", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                clipboardManager.setText(mLog.toString());
            }
        });

        final String postContent = mLog.toString();

        logDialogBuilder.setNeutralButton("Post data", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                new AsyncTask<Void, Void, Void>() {

                    @Override
                    protected Void doInBackground(Void... params) {
                        try {
                            String url = ApplicationContext.getLogPostURL();
                            if (url != null && url.trim() != "") {
                                url = url + "?platform=android";
                                HttpPost post = new HttpPost();
                                post.setEntity(new StringEntity(postContent, "utf-8"));

                                post.setURI(new URI(url));

                                new DefaultHttpClient().execute(post);
                            }
                        } catch (Exception e) {
                            // Wasn't able to post the data. Do nothing
                        }

                        return null;
                    }
                }.execute();
            }
        });

        logDialogBuilder.setView(webView);

        logDialogBuilder.create().show();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}