Example usage for android.content ClipboardManager setText

List of usage examples for android.content ClipboardManager setText

Introduction

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

Prototype

@Deprecated
public void setText(CharSequence text) 

Source Link

Usage

From source file:ru.valle.safetrade.BuyActivity.java

@SuppressWarnings("deprecation")
private void copyTextToClipboard(String label, String text) {
    if (Build.VERSION.SDK_INT >= 11) {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText(label, text);
        clipboard.setPrimaryClip(clip);//  w  w w . j  av a 2s.  co  m
    } else {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);
    }
}

From source file:de.syss.MifareClassicTool.Common.java

/**
 * Copy a text to the Android clipboard.
 * @param text The text that should by stored on the clipboard.
 * @param context Context of the SystemService
 * (and the Toast message that will by shown).
 *//*  www.  jav  a2s. c o m*/
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void copyToClipboard(String text, Context context) {
    if (!text.equals("")) {
        if (Build.VERSION.SDK_INT >= 11) {
            // Android API level 11+.
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData.newPlainText("mifare classic tool data",
                    text);
            clipboard.setPrimaryClip(clip);
        } else {
            // Android API level 10.
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(text);
        }
        Toast.makeText(context, R.string.info_copied_to_clipboard, Toast.LENGTH_SHORT).show();
    }
}

From source file:net.zjy.zxcardumper.Common.java

/**
 * Copy a text to the Android clipboard.
 * @param text The text that should by stored on the clipboard.
 * @param context Context of the SystemService
 * (and the Toast message that will by shown).
 *//*w  w w.j  a  v a2  s .  c  o m*/
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void copyToClipboard(String text, Context context) {
    if (!text.equals("")) {
        if (Build.VERSION.SDK_INT >= 11) {
            // Android API level 11+.
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData.newPlainText("MIFARE classic tool data",
                    text);
            clipboard.setPrimaryClip(clip);
        } else {
            // Android API level 10.
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(text);
        }
        Toast.makeText(context, R.string.info_copied_to_clipboard, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java

@TargetApi(11)
private void copyAliasCurrentChatBox() {
    ChatBox chatBox = mCurrentChatBoxManager.getCurrentChatBox();
    if (chatBox == null || chatBox.getAlias() == null) {
        return;/*w  w w .j  ava 2s.  c om*/
    }
    AppCompatActivity activity = mActivityDelegate.getActivity();

    if (Build.VERSION.SDK_INT >= 11) {
        ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(activity.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("alias_copied", constructAliasLink(chatBox.getAlias())));
    } else {
        android.text.ClipboardManager oldClipboard = (android.text.ClipboardManager) activity
                .getSystemService(activity.CLIPBOARD_SERVICE);
        oldClipboard.setText(constructAliasLink(chatBox.getAlias()));
    }

    Toast.makeText(activity, R.string.message_current_chat_box_alias_copied, Toast.LENGTH_SHORT).show();
}

From source file:de.enlightened.peris.SocialFragment.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private void storePostInClipboard() {

    //Copy text support for all Android versions
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        final ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        final ClipData cd = ClipData.newHtmlText(this.selectedPost.author + "'s Social Post",
                this.selectedPost.body, this.selectedPost.body);
        clipboard.setPrimaryClip(cd);/*from  w  ww .ja  v a2 s .  co m*/
    } else {
        final android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(this.selectedPost.body);
    }

    final Toast toast = Toast.makeText(this.getActivity(), "Text copied!", Toast.LENGTH_SHORT);
    toast.show();
}

From source file:sjizl.com.ChatFriendListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int index = info.position;
    String textTocopy = stock_list3.get(index);

    switch (item.getItemId()) {
    case R.id.delete:
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        naam_to_delete = stock_list2.get(info.position);
        new DeleteConversation().execute();

        return false;

    case R.id.copy:
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("simple text", textTocopy);
            clipboard.setPrimaryClip(clip);
        } else {//from www . ja va2  s.  c om
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(textTocopy);

        }

        //place your TextView's text in clipboard

        Toast.makeText(getActivity().getApplicationContext(), "Item copied", Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}

From source file:com.gmail.taneza.ronald.carbs.main.MainActivity.java

@SuppressWarnings("deprecation")
private void copyMealTotalToClipboard() {
    String mealTotalValue = String.format(Locale.getDefault(), "%.1f", mTotalCarbsInGrams);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText("Carbs meal total",
                mealTotalValue);//from   w  w  w . j a  v a 2  s . com
        clipboard.setPrimaryClip(clip);
    } else {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(mealTotalValue);
    }

    String message = String.format(Locale.US, getResources().getString(R.string.meal_total_copied_to_clipboard),
            mealTotalValue);
    Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}

From source file:jahirfiquitiva.iconshowcase.fragments.DonationsFragment.java

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

    /* Flattr *//*from   w  ww . ja  va2 s.  c om*/
    if (mFlattrEnabled) {
        // inflate flattr view into stub
        ViewStub flattrViewStub = (ViewStub) getActivity().findViewById(R.id.donations__flattr_stub);
        flattrViewStub.inflate();

        buildFlattrView();
    }

    /* Google */
    if (mGoogleEnabled) {
        // inflate google view into stub
        ViewStub googleViewStub = (ViewStub) getActivity().findViewById(R.id.donations__google_stub);
        googleViewStub.inflate();

        // choose donation amount
        mGoogleSpinner = (Spinner) getActivity().findViewById(R.id.donations__google_android_market_spinner);
        ArrayAdapter<CharSequence> adapter;
        if (mDebug) {
            adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item,
                    CATALOG_DEBUG);
        } else {
            adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item,
                    mGoogleCatalogValues);
        }
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mGoogleSpinner.setAdapter(adapter);

        Button btGoogle = (Button) getActivity()
                .findViewById(R.id.donations__google_android_market_donate_button);
        btGoogle.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                donateGoogleOnClick(v);
            }
        });

        // Create the helper, passing it our context and the public key to verify signatures with
        if (mDebug)
            Utils.showLog(context, "Creating IAB helper.");
        mHelper = new IabHelper(getActivity(), mGooglePubkey);

        // enable debug logging (for a production application, you should set this to false).
        mHelper.enableDebugLogging(mDebug);

        // Start setup. This is asynchronous and the specified listener
        // will be called once setup completes.
        if (mDebug)
            Utils.showLog(context, "Starting setup.");
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (mDebug)
                    Utils.showLog(context, "Setup finished.");

                if (!result.isSuccess()) {
                    // Oh noes, there was a problem.
                    openDialog(android.R.drawable.ic_dialog_alert,
                            R.string.donations__google_android_market_not_supported_title,
                            getString(R.string.donations__google_android_market_not_supported));
                }

            }
        });
    }

    /* PayPal */
    if (mPaypalEnabled) {
        // inflate paypal view into stub
        ViewStub paypalViewStub = (ViewStub) getActivity().findViewById(R.id.donations__paypal_stub);
        paypalViewStub.inflate();

        Button btPayPal = (Button) getActivity().findViewById(R.id.donations__paypal_donate_button);
        btPayPal.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                donatePayPalOnClick(v);
            }
        });
    }

    /* Bitcoin */
    if (mBitcoinEnabled) {
        // inflate bitcoin view into stub
        ViewStub bitcoinViewStub = (ViewStub) getActivity().findViewById(R.id.donations__bitcoin_stub);
        bitcoinViewStub.inflate();

        Button btBitcoin = (Button) getActivity().findViewById(R.id.donations__bitcoin_button);
        btBitcoin.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                donateBitcoinOnClick(v);
            }
        });
        btBitcoin.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                // http://stackoverflow.com/a/11012443/832776
                if (Build.VERSION.SDK_INT >= 11) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText(mBitcoinAddress, mBitcoinAddress);
                    clipboard.setPrimaryClip(clip);
                } else {
                    @SuppressWarnings("deprecation")
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(mBitcoinAddress);
                }
                Toast.makeText(getActivity(), R.string.donations__bitcoin_toast_copy, Toast.LENGTH_SHORT)
                        .show();
                return true;
            }
        });
    }
}

From source file:org.mozilla.gecko.toolbar.SiteIdentityPopup.java

private void addSelectLoginDoorhanger(Tab tab) throws JSONException {
    final SiteLogins siteLogins = tab.getSiteLogins();
    if (siteLogins == null) {
        return;/*  www.  ja  v a 2 s  . com*/
    }

    final JSONArray logins = siteLogins.getLogins();
    if (logins.length() == 0) {
        return;
    }

    final JSONObject login = (JSONObject) logins.get(0);

    // Create button click listener for copying a password to the clipboard.
    final OnButtonClickListener buttonClickListener = new OnButtonClickListener() {
        @Override
        public void onButtonClick(JSONObject response, DoorHanger doorhanger) {
            try {
                final int buttonId = response.getInt("callback");
                if (buttonId == ButtonType.COPY.ordinal()) {
                    final ClipboardManager manager = (ClipboardManager) mContext
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    String password;
                    if (response.has("password")) {
                        // Click listener being called from List Dialog.
                        password = response.optString("password");
                    } else {
                        password = login.getString("password");
                    }
                    if (AppConstants.Versions.feature11Plus) {
                        manager.setPrimaryClip(ClipData.newPlainText("password", password));
                    } else {
                        manager.setText(password);
                    }
                    Toast.makeText(mContext, R.string.doorhanger_login_select_toast_copy, Toast.LENGTH_SHORT)
                            .show();
                }
                dismiss();
            } catch (JSONException e) {
                Log.e(LOGTAG, "Error handling Select login button click", e);
                Toast.makeText(mContext, R.string.doorhanger_login_select_toast_copy_error, Toast.LENGTH_SHORT)
                        .show();
            }
        }
    };

    final DoorhangerConfig config = new DoorhangerConfig(DoorHanger.Type.LOGIN, buttonClickListener);

    // Set buttons.
    config.setButton(mContext.getString(R.string.button_cancel), ButtonType.CANCEL.ordinal(), false);
    config.setButton(mContext.getString(R.string.button_copy), ButtonType.COPY.ordinal(), true);

    // Set message.
    String username = ((JSONObject) logins.get(0)).getString("username");
    if (TextUtils.isEmpty(username)) {
        username = mContext.getString(R.string.doorhanger_login_no_username);
    }

    final String message = mContext.getString(R.string.doorhanger_login_select_message).replace(FORMAT_S,
            username);
    config.setMessage(message);

    // Set options.
    final JSONObject options = new JSONObject();

    // Add action text only if there are other logins to select.
    if (logins.length() > 1) {

        final JSONObject actionText = new JSONObject();
        actionText.put("type", "SELECT");

        final JSONObject bundle = new JSONObject();
        bundle.put("logins", logins);

        actionText.put("bundle", bundle);
        options.put("actionText", actionText);
    }

    config.setOptions(options);

    ThreadUtils.postToUiThread(new Runnable() {
        @Override
        public void run() {
            if (!mInflated) {
                init();
            }

            removeSelectLoginDoorhanger();

            mSelectLoginDoorhanger = DoorHanger.Get(mContext, config);
            mContent.addView(mSelectLoginDoorhanger);
            mDivider.setVisibility(View.VISIBLE);
        }
    });
}

From source file:com.tinfoil.sms.sms.SendMessageActivity.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void copyText(String message) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText(MESSAGE_LABEL, message);
        clipboard.setPrimaryClip(clip);/*  ww w.ja va2 s  .c o m*/
    } else {

        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(message);
    }
}