Example usage for android.content Context CLIPBOARD_SERVICE

List of usage examples for android.content Context CLIPBOARD_SERVICE

Introduction

In this page you can find the example usage for android.content Context CLIPBOARD_SERVICE.

Prototype

String CLIPBOARD_SERVICE

To view the source code for android.content Context CLIPBOARD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

Usage

From source file:ru.valle.btc.MainActivity.java

@SuppressWarnings("deprecation")
private void copyTextToClipboard(String label, String text) {
    if (Build.VERSION.SDK_INT >= 11) {
        clipboardHelper.copyTextToClipboard(label, text);
    } else {//from  ww w.j  a  va 2s .  com
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);
    }
}

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);//  ww  w .j  ava2 s.co  m
    } else {
        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.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);//from  www .  j a  v  a  2  s  .  com
    } else {
        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.application.akscorp.yandextranslator2017.TranslateScreen.java

private void CopyTextToClipBoard(String text) {
    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(text);//from   w ww.j  av  a2s .  co  m
    } else {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", text);
        clipboard.setPrimaryClip(clip);
    }
    Toast.makeText(context, LanguageWork.GetResourceString(context, "copy_text"), Toast.LENGTH_SHORT).show();
}

From source file:com.hrs.filltheform.dialog.FillTheFormDialog.java

private void copyToClipboard(String inputData) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(inputData, inputData);
    clipboard.setPrimaryClip(clip);//from w  ww .  jav  a 2 s .  co m
}

From source file:de.electricdynamite.pasty.ClipboardFragment.java

@Override
public void onLoadFinished(Loader<PastyLoader.PastyResponse> loader, PastyLoader.PastyResponse response) {

    ProgressBar pbLoading = (ProgressBar) getSherlockActivity().findViewById(R.id.progressbar_downloading);
    pbLoading.setVisibility(View.GONE);
    pbLoading = null;/*from w  w w  .j a  v a  2 s . c om*/

    mHelpTextBig.setTextColor(getResources().getColor(R.color.abs__primary_text_holo_light));
    mHelpTextBig.setBackgroundDrawable(mBackground);

    if (response.isFinal) {
        getSherlockActivity().setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
        if (response.getResultSource() == PastyResponse.SOURCE_CACHE) {
            Toast.makeText(getSherlockActivity().getApplicationContext(),
                    getString(R.string.warning_no_network_short), Toast.LENGTH_SHORT).show();
        }
    }
    if (response.hasException) {
        if (LOCAL_LOG)
            Log.v(TAG, "onLoadFinished(): Loader delivered exception; calling handleException()");
        // an error occured

        getSherlockActivity().setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
        PastyException mException = response.getException();
        handleException(mException);
    } else {
        switch (loader.getId()) {
        case PastyLoader.TASK_CLIPBOARD_FETCH:
            JSONArray Clipboard = response.getClipboard();
            mItems.clear();
            mAdapter.notifyDataSetChanged();
            getListView().invalidateViews();
            try {
                if (Clipboard.length() == 0) {
                    //Clipboard is empty
                    mHelpTextBig.setText(R.string.helptext_PastyActivity_clipboard_empty);
                    mHelpTextSmall.setText(R.string.helptext_PastyActivity_how_to_add);
                } else {
                    for (int i = 0; i < Clipboard.length(); i++) {
                        JSONObject Item = Clipboard.getJSONObject(i);
                        ClipboardItem cbItem = new ClipboardItem(Item.getString("_id"), Item.getString("item"));
                        this.mItems.add(cbItem);
                    }

                    mHelpTextBig.setText(R.string.helptext_PastyActivity_copy);
                    mHelpTextSmall.setText(R.string.helptext_PastyActivity_options);

                    //Assign adapter to ListView
                    ListView listView = (ListView) getSherlockActivity().findViewById(R.id.listItems);
                    listView.setAdapter(mAdapter);
                    listView.setItemsCanFocus(false);
                    listView.setOnItemClickListener(new OnItemClickListener() {
                        @SuppressLint("NewApi")
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            ClipboardItem Item = mItems.get(position); // get a ClipboardItem from the clicked position
                            if (Item.isLinkified() && prefs.getClickableLinks()) {
                                /* If the clicked item was originally linkified and prefs.getClickableLinks() is true, we manually
                                 * fire an ACTION_VIEW intent to simulate Linkify() behavior
                                 */
                                String url = Item.getText();
                                if (!URLUtil.isValidUrl(url))
                                    url = "http://" + url;
                                Intent i = new Intent(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(url));
                                startActivity(i);
                            } else {
                                /* Else we copy the item to the systems clipboard,
                                 * show a Toast and finish() the activity
                                 */
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                    android.content.ClipboardManager sysClipboard = (android.content.ClipboardManager) getSherlockActivity()
                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                    Item.copyToClipboard(sysClipboard);
                                    sysClipboard = null;
                                } else {
                                    ClipboardManager sysClipboard = (ClipboardManager) getSherlockActivity()
                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                    Item.copyToClipboard(sysClipboard);
                                    sysClipboard = null;
                                }
                                Toast.makeText(getSherlockActivity().getApplicationContext(),
                                        getString(R.string.item_copied), Toast.LENGTH_LONG).show();
                                getSherlockActivity().finish();
                            }
                        }
                    });
                    registerForContextMenu(listView);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        default:
            break;
        }
    }
}

From source file:piuk.blockchain.android.ui.WalletAddressesActivity.java

private void handlePasteClipboard() {
    final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

    if (clipboardManager.hasText()) {
        final String text = clipboardManager.getText().toString().trim();

        try {/*from w  w w . j  a v a 2  s  . c  o  m*/
            final Address address = new Address(Constants.NETWORK_PARAMETERS, text);
            EditAddressBookEntryFragment.edit(getSupportFragmentManager(), address.toString());
        } catch (final AddressFormatException x) {
            toast(R.string.send_coins_parse_address_error_msg);
        }
    } else {
        toast(R.string.address_book_msg_clipboard_empty);
    }
}

From source file:org.smssecure.smssecure.ConversationFragment.java

private void handleCopyMessage(final Set<MessageRecord> messageRecords) {
    List<MessageRecord> messageList = new LinkedList<>(messageRecords);
    Collections.sort(messageList, new Comparator<MessageRecord>() {
        @Override/* w ww.  j  a  v a 2  s  .  c  o  m*/
        public int compare(MessageRecord lhs, MessageRecord rhs) {
            if (lhs.getDateReceived() < rhs.getDateReceived())
                return -1;
            else if (lhs.getDateReceived() == rhs.getDateReceived())
                return 0;
            else
                return 1;
        }
    });

    StringBuilder bodyBuilder = new StringBuilder();
    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    boolean first = true;

    for (MessageRecord messageRecord : messageList) {
        String body = messageRecord.getDisplayBody().toString();

        if (body != null) {
            if (!first)
                bodyBuilder.append('\n');
            bodyBuilder.append(body);
            first = false;
        }
    }

    String result = bodyBuilder.toString();

    if (!TextUtils.isEmpty(result))
        clipboard.setText(result);
}

From source file:com.googlecode.networklog.LogFragment.java

@SuppressWarnings("deprecation")
public void copyDestIp(ListItem item) {
    String dstAddr;//from w  w w  .  j  a v  a2 s. c om
    String dstPort;

    if (NetworkLog.resolveHosts && NetworkLog.resolveCopies) {
        String resolved = NetworkLog.resolver.resolveAddress(item.dstAddr);

        if (resolved != null) {
            dstAddr = resolved;
        } else {
            dstAddr = item.dstAddr;
        }
    } else {
        dstAddr = item.dstAddr;
    }

    if (NetworkLog.resolvePorts && NetworkLog.resolveCopies) {
        dstPort = NetworkLog.resolver.resolveService(String.valueOf(item.dstPort));
    } else {
        dstPort = String.valueOf(item.dstPort);
    }

    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);

    /* newer API 11 clipboard unsupported on older devices
       ClipData clip = ClipData.newPlainText("NetworkLog Dest IP", dstAddr + ":" + dstPort);
       clipboard.setPrimaryClip(clip);
       */

    /* use older deprecated ClipboardManager to support older devices */
    clipboard.setText(dstAddr + ":" + dstPort);
}

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;// w ww .j  a  v  a  2s. com
    }
    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);
    }
}