use of android.content.ClipData in project platform_frameworks_base by android.
the class TextView method paste.
/**
* Paste clipboard content between min and max positions.
*/
private void paste(int min, int max, boolean withFormatting) {
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null) {
boolean didFirst = false;
for (int i = 0; i < clip.getItemCount(); i++) {
final CharSequence paste;
if (withFormatting) {
paste = clip.getItemAt(i).coerceToStyledText(getContext());
} else {
// Get an item as text and remove all spans by toString().
final CharSequence text = clip.getItemAt(i).coerceToText(getContext());
paste = (text instanceof Spanned) ? text.toString() : text;
}
if (paste != null) {
if (!didFirst) {
Selection.setSelection((Spannable) mText, max);
((Editable) mText).replace(min, max, paste);
didFirst = true;
} else {
((Editable) mText).insert(getSelectionEnd(), "\n");
((Editable) mText).insert(getSelectionEnd(), paste);
}
}
}
sLastCutCopyOrTextChangedTime = 0;
}
}
use of android.content.ClipData in project libgdx by libgdx.
the class AndroidClipboard method getContents.
@Override
public String getContents() {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
if (clipboard.getText() == null)
return null;
return clipboard.getText().toString();
} else {
ClipData clip = honeycombClipboard.getPrimaryClip();
if (clip == null)
return null;
CharSequence text = clip.getItemAt(0).getText();
if (text == null)
return null;
return text.toString();
}
}
use of android.content.ClipData in project Talon-for-Twitter by klinker24.
the class TouchableSpan method copy.
private void copy() {
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Activity.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("link", full);
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, R.string.copied, Toast.LENGTH_SHORT).show();
}
use of android.content.ClipData in project android-common by litesuits.
the class ClipboardUtil method getItemCount.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getItemCount(Context context) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData data = clipboard.getPrimaryClip();
return data.getItemCount();
}
use of android.content.ClipData in project sharelock-android by auth0.
the class ComposeActivity method onResume.
@Override
protected void onResume() {
super.onResume();
final int entryCount = getSupportFragmentManager().getBackStackEntryCount();
final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (entryCount == 0 && clipboardManager.hasPrimaryClip() && clipboardManager.getPrimaryClip().getItemCount() > 0) {
final ClipData primaryClip = clipboardManager.getPrimaryClip();
final ClipData.Item item = primaryClip.getItemAt(0);
final String text = item.coerceToText(this).toString();
if (text.trim().length() > 0) {
final Snackbar snackbar = Snackbar.with(this).text(getString(R.string.paste_from_clipboard_prompt)).actionLabel(getString(R.string.paste_clipboard_action)).actionColorResource(R.color.sharelock_orange).actionListener(new ActionClickListener() {
@Override
public void onActionClicked(Snackbar snackbar) {
bus.postSticky(new ClipboardSecretEvent(text));
clipboardManager.setPrimaryClip(ClipData.newPlainText("", ""));
}
}).duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE);
SnackbarManager.show(snackbar);
}
}
}
Aggregations