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:com.mikifus.padland.PadListActivity.java

/**
 * If there is a share intent this function gets the extra text
 * and copies it into clipboard//from  w w w . j  ava  2s .  c  o m
 */
private void _textFromIntent() {
    String extra_text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
    if (extra_text != null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(extra_text);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", extra_text);
            clipboard.setPrimaryClip(clip);
        }

        Toast.makeText(this, getString(R.string.activity_padlist_implicitintent_text_copied), Toast.LENGTH_LONG)
                .show();
    }
}

From source file:net.yolosec.upckeygen.ui.NetworkFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share:
        try {/*from ww  w  . j a  v  a 2  s . c o  m*/
            if (passwordList == null)
                return true;
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_SUBJECT, wifiNetwork.getSsidName() + getString(R.string.share_msg_begin));
            i.putExtra(Intent.EXTRA_TEXT, buildShareString());
            startActivity(Intent.createChooser(i, getString(R.string.share_title)));
        } catch (Exception e) {
            Toast.makeText(getActivity(), R.string.msg_err_sendto, Toast.LENGTH_SHORT).show();
        }
        return true;
    case R.id.menu_save_sd:
        if (passwordList == null)
            return true;

        final String toCopy = buildShareString();
        try {
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                clipboard.setText(toCopy);
            } else {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", toCopy);
                clipboard.setPrimaryClip(clip);
            }

            Toast.makeText(getActivity(), getString(R.string.msg_copied, wifiNetwork.getSsidName()),
                    Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Log.e(TAG, "Copy to clipboard failed", e);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.dtr.zxing.activity.CaptureActivity.java

private void showCopyTextOption(final String text) {
    DialogHelp.getConfirmDialog(this, text, new DialogInterface.OnClickListener() {
        @Override// ww w .  ja va 2s . co  m
        public void onClick(DialogInterface dialogInterface, int i) {
            ClipboardManager cbm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            cbm.setText(text);
            AppContext.showToast("??");
            finish();
        }
    }, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            finish();
        }
    }).show();
}

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

private void clipboard(TextView tv) {
    int which;/* w w w. j  a va  2 s  . c o  m*/
    switch (tv.getId()) {
    case txt_request_url:
        which = req_url;
        break;
    case txt_response_headers:
        which = response_headers;
        break;
    case txt_response_body:
        which = response_body;
        break;
    default:
        which = UNSET;
    }
    String what = which == UNSET ? "" : getString(which) + " ";
    what += getString(clippy);
    Toast.makeText(getActivity(), what, Toast.LENGTH_SHORT).show();
    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:info.mayuragarkar.calculator.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    /** CREATE DATABASE FOR HISTORY HERE */
    DatabaseHandler.calcDB = getBaseContext().openOrCreateDatabase(dbName + ".db", MODE_PRIVATE, null);
    DatabaseHandler.calcDB.execSQL(//from  www . j  av  a2  s . com
            "CREATE TABLE IF NOT EXISTS " + tableName + " (firstNum TEXT, secondNum TEXT, answerNum TEXT)");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();
    }
    });*/

    /** Button Logics */
    firstNumberEditText = (EditText) findViewById(R.id.firstNumberEditText);
    secondNumberEditText = (EditText) findViewById(R.id.secondNumberEditText);
    resultEditText = (EditText) findViewById(R.id.resultEditText);
    addBtn = (Button) findViewById(R.id.plus);
    factorial = (Button) findViewById(R.id.factorial);
    subBtn = (Button) findViewById(R.id.minus);
    divBtn = (Button) findViewById(R.id.divide);
    mulBtn = (Button) findViewById(R.id.multiply);
    clearBtn = (Button) findViewById(R.id.clearAll);
    raisedto = (Button) findViewById(R.id.raisedto);
    mod = (Button) findViewById(R.id.mod);
    modinverse = (Button) findViewById(R.id.modinverse);
    isPrime = (Button) findViewById(R.id.isPrime);
    copyBtn = (Button) findViewById(R.id.copyBtn);
    operationApplied = (TextView) findViewById(R.id.operationAppliedText);

    /** make operation applied empty on run time */
    operationApplied.setText("");

    /** Make View Pager Initialized Here */
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setAdapter(new CustomPagerAdapter(this));
    //Bind the title indicator to the adapter
    CirclePageIndicator titleIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
    titleIndicator.setViewPager(viewPager);

    /** clear all button */
    clearBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            clearall();
            clearText();
        }
    });

    /** copy contents button */
    copyBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (resultEditText.length() > 0) {
                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(resultEditText.getText());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("Big Number History",
                            resultEditText.getText());
                    clipboard.setPrimaryClip(clip);
                }
                Toast.makeText(getApplicationContext(), "Result Copied.", Toast.LENGTH_LONG).show();
            } else if (resultEditText.length() <= 0) {
                Toast.makeText(getApplicationContext(), "Nothing to Copy.", Toast.LENGTH_LONG).show();
            }

        }
    });

}

From source file:net.yolosec.upckeygen.ui.NetworkFragment.java

private void displayResults() {
    if (passwordList.isEmpty()) {
        root.findViewById(R.id.loading_spinner).setVisibility(View.GONE);
        messages.setText(R.string.msg_errnomatches);

    } else {/*from  www .  j a  va 2  s  .co m*/
        WiFiKey wiFiKey = passwordList.get(0);
        boolean isUbee = TextUtils.isEmpty(wiFiKey.getSerial());

        final ListView list = (ListView) root.findViewById(R.id.list_keys);
        Collections.sort(passwordList, new Comparator<WiFiKey>() {
            @Override
            public int compare(WiFiKey lhs, WiFiKey rhs) {
                if (lhs.getBandType() != rhs.getBandType()) {
                    return lhs.getBandType() < rhs.getBandType() ? -1 : 1;
                }

                final String serialL = lhs.getSerial();
                final String serialR = rhs.getSerial();
                if (serialL == null && serialR != null) {
                    return -1;
                } else if (serialL != null && serialR == null) {
                    return 1;
                } else if (serialL != null && !serialL.equals(serialR)) {
                    return serialL.compareTo(serialR);
                }

                return lhs.getKey().compareTo(rhs.getKey());
            }
        });

        list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final WiFiKey key = (WiFiKey) parent.getItemAtPosition(position);
                Toast.makeText(getActivity(), getString(R.string.msg_copied, key.getKey()), Toast.LENGTH_SHORT)
                        .show();

                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(key.getKey());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("key", key.getKey());
                    clipboard.setPrimaryClip(clip);
                }

                openWifiSettings();
            }
        });
        if (isUbee) {
            list.setAdapter(
                    new WiFiKeyUbeeAdapter(getActivity(), android.R.layout.simple_list_item_1, passwordList));
        } else {
            list.setAdapter(
                    new WiFiKeyAdapter(getActivity(), android.R.layout.simple_list_item_1, passwordList));
        }

        root.showNext();
    }
}

From source file:com.irccloud.android.activity.ImageViewerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();//from   w w  w  . j a  v  a 2 s  .co m
        overridePendingTransition(R.anim.fade_in, R.anim.slide_out_right);
        return true;
    } else if (item.getItemId() == R.id.action_browser) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                getIntent().getDataString().replace(getResources().getString(R.string.IMAGE_SCHEME), "http")));
        startActivity(intent);
        finish();
        return true;
    } else if (item.getItemId() == R.id.action_copy) {
        if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            clipboard.setText(getIntent().getDataString()
                    .replace(getResources().getString(R.string.IMAGE_SCHEME), "http"));
        } else {
            @SuppressLint("ServiceCast")
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData.newRawUri("IRCCloud Image URL",
                    Uri.parse(getIntent().getDataString()
                            .replace(getResources().getString(R.string.IMAGE_SCHEME), "http")));
            clipboard.setPrimaryClip(clip);
        }
        Toast.makeText(ImageViewerActivity.this, "Link copied to clipboard", Toast.LENGTH_SHORT).show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:eu.funceptionapps.convertitall.ui.ConverterInterface.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == android.R.id.home) {

        if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
            mDrawerLayout.closeDrawer(mDrawerList);
        } else {/*from   ww w .j a  v a2 s.  c om*/
            mDrawerLayout.openDrawer(mDrawerList);
        }
    }

    switch (item.getItemId()) {
    case R.id.homeAsUp:
        return true;

    case R.id.menu_item_copy:
        EditText edResult = (EditText) findViewById(R.id.ed_unitOut);

        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(edResult.getText().toString());
        Toast.makeText(this, getResources().getString(R.string.toast_copy_to_clipboard), Toast.LENGTH_SHORT)
                .show();
        break;

    case R.id.menu_item_favorite:
        makeFavoriteDialog();
        break;

    case R.id.menu_item_update_currencies:
        makeUpdateDialog();
        break;

    case R.id.menu_item_settings:
        Intent intent = new Intent(this, SettingsInterface.class);
        startActivityForResult(intent, settingsRequestCode);
        break;

    case R.id.menu_item_share:
        if (mShareActionProvider != null) {
            sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, sharingMsg);
            sendIntent.setType("text/plain");
            mShareActionProvider.setShareIntent(sendIntent);
        }
        break;

    case R.id.menu_item_feedback:
        Intent feedback = new Intent();
        feedback.setAction(Intent.ACTION_SEND);

        String gmail = getResources().getString(R.string.gmail);

        String[] recipients = new String[] { gmail, "", };

        feedback.putExtra(Intent.EXTRA_EMAIL, recipients);
        feedback.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
        feedback.setType("message/rfc822");
        startActivity(feedback);
        break;
    }
    return true;
}

From source file:com.irccloud.android.activity.PastebinViewerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();/* w ww.j a v a2s. c  o  m*/
        if (getWindowManager().getDefaultDisplay().getWidth() < TypedValue
                .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 800, getResources().getDisplayMetrics())
                || isMultiWindow())
            overridePendingTransition(R.anim.fade_in, R.anim.slide_out_right);
        return true;
    } else if (item.getItemId() == R.id.delete) {
        if (Uri.parse(url).getQueryParameter("own_paste").equals("1")) {
            AlertDialog.Builder builder = new AlertDialog.Builder(PastebinViewerActivity.this);
            builder.setTitle("Delete Snippet");
            builder.setMessage("Are you sure you want to delete this snippet?");
            builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    NetworkConnection.getInstance().delete_paste(Uri.parse(url).getQueryParameter("id"));
                    finish();
                    Toast.makeText(PastebinViewerActivity.this, "Snippet deleted", Toast.LENGTH_SHORT).show();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            });
            AlertDialog d = builder.create();
            d.setOwnerActivity(PastebinViewerActivity.this);
            d.show();
        }
    } else if (item.getItemId() == R.id.action_linenumbers) {
        item.setChecked(!item.isChecked());
        mWebView.loadUrl("javascript:window.PASTEVIEW.doToggleLines()");
    } else if (item.getItemId() == R.id.action_browser) {
        if (!PreferenceManager
                .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext())
                .getBoolean("browser", false)
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
            builder.setToolbarColor(ColorScheme.getInstance().navBarColor);
            builder.addDefaultShareMenuItem();
            builder.addMenuItem("Copy URL",
                    PendingIntent.getBroadcast(this, 0, new Intent(this, ChromeCopyLinkBroadcastReceiver.class),
                            PendingIntent.FLAG_UPDATE_CURRENT));

            CustomTabsIntent intent = builder.build();
            intent.intent.setData(Uri.parse(url.contains("?") ? url.substring(0, url.indexOf("?")) : url));
            if (Build.VERSION.SDK_INT >= 22)
                intent.intent.putExtra(Intent.EXTRA_REFERRER,
                        Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + getPackageName()));
            if (Build.VERSION.SDK_INT >= 16 && intent.startAnimationBundle != null) {
                startActivity(intent.intent, intent.startAnimationBundle);
            } else {
                startActivity(intent.intent);
            }
        } else {
            Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(url.contains("?") ? url.substring(0, url.indexOf("?")) : url));
            startActivity(intent);
        }
        finish();
        return true;
    } else if (item.getItemId() == R.id.action_copy) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            if (url.contains("?"))
                clipboard.setText(url.substring(0, url.indexOf("?")));
            else
                clipboard.setText(url);
        } else {
            @SuppressLint("ServiceCast")
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            android.content.ClipData clip;
            if (url.contains("?"))
                clip = android.content.ClipData.newRawUri("IRCCloud Snippet URL",
                        Uri.parse(url.substring(0, url.indexOf("?"))));
            else
                clip = android.content.ClipData.newRawUri("IRCCloud Snippet URL", Uri.parse(url));
            clipboard.setPrimaryClip(clip);
        }
        Toast.makeText(PastebinViewerActivity.this, "Link copied to clipboard", Toast.LENGTH_SHORT).show();
    } else if (item.getItemId() == R.id.action_share) {
        if (getIntent() != null && getIntent().getDataString() != null) {
            Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(url));
            intent.setType("text/plain");
            if (url.contains("?"))
                intent.putExtra(Intent.EXTRA_TEXT, url.substring(0, url.indexOf("?")));
            else
                intent.putExtra(Intent.EXTRA_TEXT, url);
            intent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getPackageName());
            intent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY,
                    getPackageManager().getLaunchIntentForPackage(getPackageName()).getComponent());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(Intent.createChooser(intent, "Share Snippet"));
            Answers.getInstance().logShare(new ShareEvent().putContentType("Pastebin"));
        }
    } else if (item.getItemId() == R.id.action_edit) {
        mSpinner.setVisibility(View.VISIBLE);
        Intent i = new Intent(this, PastebinEditorActivity.class);
        i.putExtra("paste_id", Uri.parse(url).getQueryParameter("id"));
        startActivityForResult(i, 1);
    }
    return super.onOptionsItemSelected(item);
}

From source file:uk.co.ashtonbrsc.intentexplode.Explode.java

private void copyIntentDetails() {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    clipboard.setText(getIntentDetailsString());
    Toast.makeText(this, R.string.intent_details_copied_to_clipboard, Toast.LENGTH_SHORT).show();
}