List of usage examples for android.content ClipData ClipData
public ClipData(CharSequence label, String[] mimeTypes, Item item)
From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java
/** * Copies text to the clipboard/*from w w w. j a v a 2s . co m*/ * * @param item The context menu item that was selected. * @return boolean Return false to allow normal context menu processing to proceed, true to consume it here. */ @Override public boolean onContextItemSelected(android.view.MenuItem item) { if (getUserVisibleHint()) { String copyText = null; switch (item.getItemId()) { case R.id.copy: { copyText = mCopyString; break; } case R.id.copyall: { if (mNameTextView.getText() != null && mCostTextView.getText() != null && mTypeTextView.getText() != null && mSetTextView.getText() != null && mAbilityTextView.getText() != null && mFlavorTextView.getText() != null && mPowTouTextView.getText() != null && mArtistTextView.getText() != null && mNumberTextView.getText() != null) { // Hacky, but it works String costText = convertHtmlToPlainText( Html.toHtml(new SpannableString(mCostTextView.getText()))); String abilityText = convertHtmlToPlainText( Html.toHtml(new SpannableString(mAbilityTextView.getText()))); copyText = mNameTextView.getText().toString() + '\n' + costText + '\n' + mTypeTextView.getText().toString() + '\n' + mSetTextView.getText().toString() + '\n' + abilityText + '\n' + mFlavorTextView.getText().toString() + '\n' + mPowTouTextView.getText().toString() + '\n' + mArtistTextView.getText().toString() + '\n' + mNumberTextView.getText().toString(); } break; } default: { return super.onContextItemSelected(item); } } if (copyText != null) { ClipboardManager clipboard = (ClipboardManager) (this.mActivity .getSystemService(android.content.Context.CLIPBOARD_SERVICE)); String label = getResources().getString(R.string.app_name); String mimeTypes[] = { ClipDescription.MIMETYPE_TEXT_PLAIN }; ClipData cd = new ClipData(label, mimeTypes, new ClipData.Item(copyText)); clipboard.setPrimaryClip(cd); } return true; } return false; }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
private void onFinished(Uri... uris) { Log.d(TAG, "onFinished() " + Arrays.toString(uris)); final Intent intent = new Intent(); if (uris.length == 1) { intent.setData(uris[0]);//from www . j a va 2 s. c o m } else if (uris.length > 1) { final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0])); for (int i = 1; i < uris.length; i++) { clipData.addItem(new ClipData.Item(uris[i])); } intent.setClipData(clipData); } if (mState.action == ACTION_GET_CONTENT) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); } setResult(Activity.RESULT_OK, intent); finish(); }
From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java
private void onFinished(Uri... uris) { Log.d(TAG, "onFinished() " + Arrays.toString(uris)); final Intent intent = new Intent(); if (uris.length == 1) { intent.setData(uris[0]);//from www .j a v a 2s . c o m } else if (uris.length > 1) { final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0])); for (int i = 1; i < uris.length; i++) { clipData.addItem(new ClipData.Item(uris[i])); } if (Utils.hasJellyBean()) { intent.setClipData(clipData); } else { intent.setData(uris[0]); } } if (mState.action == ACTION_GET_CONTENT || mState.action == ACTION_BROWSE) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } setResult(Activity.RESULT_OK, intent); finish(); }
From source file:org.mdc.chess.MDChess.java
private void clipBoardDialog() { final int COPY_GAME = 0; final int COPY_POSITION = 1; final int PASTE = 2; setAutoMode(AutoMode.OFF);/* w w w. j a v a2 s . co m*/ List<CharSequence> lst = new ArrayList<>(); List<Integer> actions = new ArrayList<>(); lst.add(getString(R.string.copy_game)); actions.add(COPY_GAME); lst.add(getString(R.string.copy_position)); actions.add(COPY_POSITION); lst.add(getString(R.string.paste)); actions.add(PASTE); final List<Integer> finalActions = actions; new MaterialDialog.Builder(this).title(R.string.tools_menu).items(lst) .itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { switch (finalActions.get(which)) { case COPY_GAME: { String pgn = ctrl.getPGN(); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setPrimaryClip(new ClipData("MD Chess game", new String[] { "application/x-chess-pgn", ClipDescription.MIMETYPE_TEXT_PLAIN }, new ClipData.Item(pgn))); break; } case COPY_POSITION: { String fen = ctrl.getFEN() + "\n"; ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setPrimaryClip(new ClipData(fen, new String[] { "application/x-chess-fen", ClipDescription.MIMETYPE_TEXT_PLAIN }, new ClipData.Item(fen))); break; } case PASTE: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip()) { ClipData clip = clipboard.getPrimaryClip(); StringBuilder fenPgn = new StringBuilder(); for (int i = 0; i < clip.getItemCount(); i++) { fenPgn.append(clip.getItemAt(i).coerceToText(getApplicationContext())); } try { ctrl.setFENOrPGN(fenPgn.toString()); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show(); } } break; } } } }).show(); }