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:ac.robinson.ticqr.TicQRActivity.java

private void sendOrder() {
    try {/*from w w w . j  a  v  a2s . c  o  m*/
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", TextUtils.isEmpty(mDestinationEmail) ? "" : mDestinationEmail, null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject));
        emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_body, mEmailContents));
        startActivity(Intent.createChooser(emailIntent, getString(R.string.email_prompt)));
    } catch (ActivityNotFoundException e) {
        // copy to clipboard instead if no email client found
        String clipboardText = getString(R.string.email_backup_sender,
                TextUtils.isEmpty(mDestinationEmail) ? "" : mDestinationEmail,
                getString(R.string.email_body, mEmailContents));

        // see: http://stackoverflow.com/a/11012443
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            @SuppressLint("ServiceCast")
            @SuppressWarnings("deprecation")
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            clipboard.setText(clipboardText);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData
                    .newPlainText(getString(R.string.email_subject), clipboardText);
            clipboard.setPrimaryClip(clip);
        }

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

From source file:com.adam.aslfms.service.ScrobblingService.java

private void handleCommand(Intent i, int startId) {
    if (i == null) {
        Log.e(TAG, "got null intent");
        return;/*  ww w . jav a2  s .  c  om*/
    }
    String action = i.getAction();
    Bundle extras = i.getExtras();
    if (action.equals(ACTION_CLEARCREDS)) {
        if (extras.getBoolean("clearall", false)) {
            mNetManager.launchClearAllCreds();
        } else {
            String snapp = extras.getString("netapp");
            if (snapp != null) {
                mNetManager.launchClearCreds(NetApp.valueOf(snapp));
            } else
                Log.e(TAG, "launchClearCreds got null napp");
        }
    } else if (action.equals(ACTION_AUTHENTICATE)) {
        String snapp = extras.getString("netapp");
        if (snapp != null)
            mNetManager.launchAuthenticator(NetApp.valueOf(snapp));
        else {
            Log.e(TAG, "launchHandshaker got null napp");
            mNetManager.launchHandshakers();
        }
    } else if (action.equals(ACTION_JUSTSCROBBLE)) {
        if (extras.getBoolean("scrobbleall", false)) {
            Log.d(TAG, "Scrobble All TRUE");
            mNetManager.launchAllScrobblers();
        } else {
            Log.e(TAG, "Scrobble All False");
            String snapp = extras.getString("netapp");
            if (snapp != null) {
                mNetManager.launchScrobbler(NetApp.valueOf(snapp));
            } else
                Log.e(TAG, "launchScrobbler got null napp");
        }
    } else if (action.equals(ACTION_PLAYSTATECHANGED)) {
        if (extras == null) {
            Log.e(TAG, "Got null extras on playstatechange");
            return;
        }
        Track.State state = Track.State.valueOf(extras.getString("state"));

        Track track = InternalTrackTransmitter.popTrack();

        if (track == null) {
            Log.e(TAG, "A null track got through!! (Ignoring it)");
            return;
        }

        onPlayStateChanged(track, state);

    } else if (action.equals(ACTION_HEART)) {
        if (!settings.getUsername(NetApp.LASTFM).equals("")) {
            if (mCurrentTrack != null && mCurrentTrack.hasBeenQueued()) {
                try {
                    if (mDb.fetchRecentTrack() == null) {
                        Toast.makeText(this, this.getString(R.string.no_heart_track), Toast.LENGTH_LONG).show();
                    } else {
                        mDb.loveRecentTrack();
                        Toast.makeText(this, this.getString(R.string.song_is_ready), Toast.LENGTH_SHORT).show();
                        Log.d(TAG, "Love Track Rating!");
                    }
                } catch (Exception e) {
                    Log.e(TAG, "CAN'T COPY TRACK" + e);
                }
            } else if (mCurrentTrack != null) {
                mCurrentTrack.setRating();
                Toast.makeText(this, this.getString(R.string.song_is_ready), Toast.LENGTH_SHORT).show();
                Log.d(TAG, "Love Track Rating!");
            } else {
                Toast.makeText(this, this.getString(R.string.no_current_track), Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(this, this.getString(R.string.no_lastFm), Toast.LENGTH_LONG).show();
        }
    } else if (action.equals(ACTION_COPY)) {
        if (mCurrentTrack != null && mCurrentTrack.hasBeenQueued()) {
            try {
                Log.e(TAG, mDb.fetchRecentTrack().toString());
                Track tempTrack = mDb.fetchRecentTrack();
                int sdk = Build.VERSION.SDK_INT;
                if (sdk < Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    clipboard.setText(tempTrack.getTrack() + " by " + tempTrack.getArtist() + ", "
                            + tempTrack.getAlbum());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("Track",
                            tempTrack.getTrack() + " by " + tempTrack.getArtist() + ", "
                                    + tempTrack.getAlbum());
                    clipboard.setPrimaryClip(clip);
                }
                Log.d(TAG, "Copy Track!");
            } catch (Exception e) {
                Toast.makeText(this, this.getString(R.string.no_copy_track), Toast.LENGTH_LONG).show();
                Log.e(TAG, "CAN'T COPY TRACK" + e);
            }
        } else if (mCurrentTrack != null) {
            try {
                int sdk = Build.VERSION.SDK_INT;
                if (sdk < Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    clipboard.setText(mCurrentTrack.getTrack() + " by " + mCurrentTrack.getArtist() + ", "
                            + mCurrentTrack.getAlbum());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("Track",
                            mCurrentTrack.getTrack() + " by " + mCurrentTrack.getArtist() + ", "
                                    + mCurrentTrack.getAlbum());
                    clipboard.setPrimaryClip(clip);
                }
                Log.d(TAG, "Copy Track!");
            } catch (Exception e) {
                Toast.makeText(this, this.getString(R.string.no_copy_track), Toast.LENGTH_LONG).show();
                Log.e(TAG, "CAN'T COPY TRACK" + e);
            }
        } else {
            Toast.makeText(this, this.getString(R.string.no_current_track), Toast.LENGTH_SHORT).show();
        }
    } else {
        Log.e(TAG, "Weird action in onStart: " + action);
    }
}

From source file:org.thoughtcrime.securesms.logsubmit.SubmitLogFragment.java

private TextView handleBuildSuccessTextView(final String logUrl) {
    TextView showText = new TextView(getActivity());

    showText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    showText.setPadding(15, 30, 15, 30);
    showText.setText(getString(R.string.log_submit_activity__copy_this_url_and_add_it_to_your_issue, logUrl));
    showText.setAutoLinkMask(Activity.RESULT_OK);
    showText.setMovementMethod(LinkMovementMethod.getInstance());
    showText.setOnLongClickListener(new View.OnLongClickListener() {

        @Override/*  w w w . j  a  v  a2s.co m*/
        public boolean onLongClick(View v) {
            @SuppressWarnings("deprecation")
            ClipboardManager manager = (ClipboardManager) getActivity()
                    .getSystemService(Activity.CLIPBOARD_SERVICE);
            manager.setText(logUrl);
            Toast.makeText(getActivity(), R.string.log_submit_activity__copied_to_clipboard, Toast.LENGTH_SHORT)
                    .show();
            return true;
        }
    });

    Linkify.addLinks(showText, Linkify.WEB_URLS);
    return showText;
}

From source file:com.adam.aslfms.service.ScrobblingService.java

private void handleCommand(Intent i, int startId) {
    if (i == null) {
        Log.e(TAG, "got null intent");
        return;/*from  w ww.  java  2  s.co  m*/
    }
    String action = i.getAction();
    Bundle extras = i.getExtras();
    if (action.equals(ACTION_CLEARCREDS)) {
        if (extras.getBoolean("clearall", false)) {
            mNetManager.launchClearAllCreds();
        } else {
            String snapp = extras.getString("netapp");
            if (snapp != null) {
                mNetManager.launchClearCreds(NetApp.valueOf(snapp));
            } else
                Log.e(TAG, "launchClearCreds got null napp");
        }
    } else if (action.equals(ACTION_AUTHENTICATE)) {
        String snapp = extras.getString("netapp");
        if (snapp != null)
            mNetManager.launchAuthenticator(NetApp.valueOf(snapp));
        else {
            Log.e(TAG, "launchHandshaker got null napp");
            mNetManager.launchHandshakers();
        }
    } else if (action.equals(ACTION_JUSTSCROBBLE)) {
        if (extras.getBoolean("scrobbleall", false)) {
            Log.d(TAG, "Scrobble All TRUE");
            mNetManager.launchAllScrobblers();
        } else {
            Log.e(TAG, "Scrobble All False");
            String snapp = extras.getString("netapp");
            if (snapp != null) {
                mNetManager.launchScrobbler(NetApp.valueOf(snapp));
            } else
                Log.e(TAG, "launchScrobbler got null napp");
        }
    } else if (action.equals(ACTION_PLAYSTATECHANGED)) {
        if (extras == null) {
            Log.e(TAG, "Got null extras on playstatechange");
            return;
        }
        Track.State state = Track.State.valueOf(extras.getString("state"));

        Track track = InternalTrackTransmitter.popTrack();

        if (track == null) {
            Log.e(TAG, "A null track got through!! (Ignoring it)");
            return;
        }

        onPlayStateChanged(track, state);

    } else if (action.equals(ACTION_HEART)) {
        if (mCurrentTrack != null && mCurrentTrack.hasBeenQueued()) {
            try {
                if (mDb.fetchRecentTrack() == null) {
                    Toast.makeText(this, this.getString(R.string.no_heart_track), Toast.LENGTH_LONG).show();
                } else {
                    mDb.loveRecentTrack();
                    Toast.makeText(this, this.getString(R.string.song_is_ready), Toast.LENGTH_SHORT).show();
                    Log.d(TAG, "Love Track Rating!");
                }
            } catch (Exception e) {
                Log.e(TAG, "CAN'T COPY TRACK" + e);
            }
        } else if (mCurrentTrack != null) {
            mCurrentTrack.setRating();
            Toast.makeText(this, this.getString(R.string.song_is_ready), Toast.LENGTH_SHORT).show();
            Log.d(TAG, "Love Track Rating!");
        } else {
            Toast.makeText(this, this.getString(R.string.no_current_track), Toast.LENGTH_SHORT).show();
        }
    } else if (action.equals(ACTION_COPY)) {
        if (mCurrentTrack != null && mCurrentTrack.hasBeenQueued()) {
            try {
                Log.e(TAG, mDb.fetchRecentTrack().toString());
                Track tempTrack = mDb.fetchRecentTrack();
                int sdk = Build.VERSION.SDK_INT;
                if (sdk < Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    clipboard.setText(tempTrack.getTrack() + " by " + tempTrack.getArtist() + ", "
                            + tempTrack.getAlbum());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("Track",
                            tempTrack.getTrack() + " by " + tempTrack.getArtist() + ", "
                                    + tempTrack.getAlbum());
                    clipboard.setPrimaryClip(clip);
                }
                Log.d(TAG, "Copy Track!");
            } catch (Exception e) {
                Toast.makeText(this, this.getString(R.string.no_copy_track), Toast.LENGTH_LONG).show();
                Log.e(TAG, "CAN'T COPY TRACK" + e);
            }
        } else if (mCurrentTrack != null) {
            try {
                int sdk = Build.VERSION.SDK_INT;
                if (sdk < Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    clipboard.setText(mCurrentTrack.getTrack() + " by " + mCurrentTrack.getArtist() + ", "
                            + mCurrentTrack.getAlbum());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                            Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("Track",
                            mCurrentTrack.getTrack() + " by " + mCurrentTrack.getArtist() + ", "
                                    + mCurrentTrack.getAlbum());
                    clipboard.setPrimaryClip(clip);
                }
                Log.d(TAG, "Copy Track!");
            } catch (Exception e) {
                Toast.makeText(this, this.getString(R.string.no_copy_track), Toast.LENGTH_LONG).show();
                Log.e(TAG, "CAN'T COPY TRACK" + e);
            }
        } else {
            Toast.makeText(this, this.getString(R.string.no_current_track), Toast.LENGTH_SHORT).show();
        }
    } else {
        Log.e(TAG, "Weird action in onStart: " + action);
    }
}

From source file:com.lemon.lime.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    final View coordinatorLayoutView = findViewById(R.id.snackbarPosition);
    switch (item.getItemId()) {

    case R.id.back:
        mWebView.goBack();/*from  w w w  . j a v a 2  s . c o  m*/
        break;

    case R.id.forward:
        mWebView.goForward();
        break;

    case R.id.reload:
        mWebView.reload();
        break;

    case R.id.new_tab:
        Intent c = new Intent(this, MainActivity.class);
        startActivityForResult(c, RESULT_SETTINGS);
        break;

    case R.id.add_bookmark:
        Intent book = new Intent(this, BookMarkActivity.class);
        startActivityForResult(book, RESULT_SETTINGS);
        break;

    case R.id.share:
        String url = mWebView.getUrl().toString();
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        clipboard.setText(url);
        Snackbar snackbar = Snackbar.make(coordinatorLayoutView, R.string.clipboard, Snackbar.LENGTH_LONG);
        snackbar.show();
        break;

    case R.id.menu_settings:
        Intent i = new Intent(this, UserSettingActivity.class);
        startActivityForResult(i, RESULT_SETTINGS);
        break;

    case R.id.invert:

        if (night == 0) {
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
            mWebView.setBackgroundColor(Color.parseColor("#000000"));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setNavigationBarColor(Color.BLACK);
                window.setStatusBarColor(Color.BLACK);
            }

            night = 1;
        } else {
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#7AB317")));
            mWebView.setBackgroundColor(Color.TRANSPARENT);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setNavigationBarColor(Color.parseColor("#7AB317"));
                window.setStatusBarColor(Color.parseColor("#7AB317"));
            }

            night = 0;
        }

        break;

    case R.id.hide:
        View decorView = window.getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        getSupportActionBar().hide();
        break;

    case R.id.easteregg:
        Toast.makeText(this, "(  Y  )", Toast.LENGTH_SHORT).show();
        mPlayer.start();
        addBarGraphRenderers();
        break;

    }

    return true;
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.MainActivity.java

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

    case R.id.menu_run_tests:
        if (getMobileServiceKey().trim() == "" || getMobileServiceURL().trim() == "") {
            startActivity(new Intent(this, ZumoPreferenceActivity.class));
        } else {//from   ww  w.j a  va2 s. c o  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());
            }
        });

        logDialogBuilder.setView(webView);

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

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

From source file:com.wellsandwhistles.android.redditsp.adapters.MainMenuListingManager.java

private void onSubredditActionMenuItemSelected(String subredditCanonicalName, AppCompatActivity activity,
        SubredditAction action) {//from www  .  j a v  a 2s . c  o m
    try {
        final String url = "https://"
                + SubredditPostListURL.getSubreddit(subredditCanonicalName).humanReadableUrl();
        RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager.getSingleton(activity,
                RedditAccountManager.getInstance(activity).getDefaultAccount());
        List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(mActivity,
                PreferenceManager.getDefaultSharedPreferences(mActivity));
        List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(mActivity,
                PreferenceManager.getDefaultSharedPreferences(mActivity));

        switch (action) {
        case SHARE:
            final Intent mailer = new Intent(Intent.ACTION_SEND);
            mailer.setType("text/plain");
            mailer.putExtra(Intent.EXTRA_TEXT, url);
            activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share)));
            break;
        case COPY_URL:
            ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
            manager.setText(url);
            break;

        case EXTERNAL:
            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            activity.startActivity(intent);
            break;

        case PIN:
            if (!pinnedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_pinned_subreddits_add(mActivity,
                        PreferenceManager.getDefaultSharedPreferences(mActivity), subredditCanonicalName);
            } else {
                Toast.makeText(mActivity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show();
            }
            break;

        case UNPIN:
            if (pinnedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_pinned_subreddits_remove(mActivity,
                        PreferenceManager.getDefaultSharedPreferences(mActivity), subredditCanonicalName);
            } else {
                Toast.makeText(mActivity, R.string.mainmenu_toast_not_pinned, Toast.LENGTH_SHORT).show();
            }
            break;

        case BLOCK:

            if (!blockedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_blocked_subreddits_add(mActivity,
                        PreferenceManager.getDefaultSharedPreferences(mActivity), subredditCanonicalName);
            } else {
                Toast.makeText(mActivity, R.string.mainmenu_toast_blocked, Toast.LENGTH_SHORT).show();
            }
            break;

        case UNBLOCK:

            if (blockedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_blocked_subreddits_remove(mActivity,
                        PreferenceManager.getDefaultSharedPreferences(mActivity), subredditCanonicalName);
            } else {
                Toast.makeText(mActivity, R.string.mainmenu_toast_not_blocked, Toast.LENGTH_SHORT).show();
            }
            break;

        case SUBSCRIBE:

            if (subMan.getSubscriptionState(
                    subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.NOT_SUBSCRIBED) {
                subMan.subscribe(subredditCanonicalName, activity);
                setPinnedSubreddits();
                setBlockedSubreddits();
                Toast.makeText(mActivity, R.string.options_subscribing, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mActivity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show();
            }
            break;

        case UNSUBSCRIBE:

            if (subMan.getSubscriptionState(
                    subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) {
                subMan.unsubscribe(subredditCanonicalName, activity);
                setPinnedSubreddits();
                setBlockedSubreddits();
                Toast.makeText(mActivity, R.string.options_unsubscribing, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mActivity, R.string.mainmenu_toast_not_subscribed, Toast.LENGTH_SHORT).show();
            }
            break;
        }
    } catch (RedditSubreddit.InvalidSubredditNameException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:tinygsn.gui.android.ActivityViewDataNew.java

@SuppressWarnings("deprecation")
private void copyTextToClipboard(String text) {
    int sdk = android.os.Build.VERSION.SDK_INT;
    if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) this
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);
    } else {/*from ww  w  .  j  a  v a2  s. c om*/
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) this
                .getSystemService(Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = ClipData.newPlainText("simple text", text);
        clipboard.setPrimaryClip(clip);
    }
}

From source file:org.sufficientlysecure.donations.DonationsFragment.java

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

    /* Flattr *//* w  w w  .  j  a  v  a2s  .  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 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)
            Log.d(TAG, "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)
            Log.d(TAG, "Starting setup.");
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (mDebug)
                    Log.d(TAG, "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));
                    return;
                }

                // Have we been disposed of in the meantime? If so, quit.
                if (mHelper == null)
                    return;
            }
        });
    }

    /* 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 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) {
                Toast.makeText(getActivity(), R.string.donations__bitcoin_toast_copy, Toast.LENGTH_SHORT)
                        .show();
                // http://stackoverflow.com/a/11012443/832776
                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                            .getSystemService(getActivity().CLIPBOARD_SERVICE);
                    clipboard.setText(mBitcoinAddress);
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                            .getSystemService(getActivity().CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText(mBitcoinAddress,
                            mBitcoinAddress);
                    clipboard.setPrimaryClip(clip);
                }
                return true;
            }
        });
    }
}

From source file:org.tigase.mobile.chat.ChatHistoryFragment.java

private void copyMessageBody(final long id) {
    ClipboardManager clipMan = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    Cursor cc = null;/*w  w w . j  av a 2  s  .  c o m*/
    try {
        cc = getChatEntry(id);
        String t = cc.getString(cc.getColumnIndex(ChatTableMetaData.FIELD_BODY));
        clipMan.setText(t);
    } finally {
        if (cc != null && !cc.isClosed())
            cc.close();
    }

}