use of android.content.ClipData in project Douya by DreaminginCodeZH.
the class ClipboardUtils method copyRawUriInt.
private static void copyRawUriInt(CharSequence label, Uri uri, Context context) {
ClipData clipData = ClipData.newRawUri(label, uri);
getClipboardManager(context).setPrimaryClip(clipData);
showToast(uri.toString(), context);
}
use of android.content.ClipData in project bilibili-android-client by HotBitmapGG.
the class ClipboardUtil method setText.
/**
* 为剪切板设置内容
*/
public static void setText(Context context, CharSequence text) {
if (isNew()) {
instance(context);
ClipData clip = ClipData.newPlainText("simple text", text);
mNewCliboardManager.setPrimaryClip(clip);
} else {
instance(context);
mClipboardManager.setText(text);
}
}
use of android.content.ClipData in project AndroidChromium by JackyAndroid.
the class UrlBar method onTextContextMenuItem.
@Override
public boolean onTextContextMenuItem(int id) {
if (id == android.R.id.paste) {
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = clipboard.getPrimaryClip();
if (clipData != null) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < clipData.getItemCount(); i++) {
builder.append(clipData.getItemAt(i).coerceToText(getContext()));
}
String pasteString = OmniboxViewUtil.sanitizeTextForPaste(builder.toString());
int min = 0;
int max = getText().length();
if (isFocused()) {
final int selStart = getSelectionStart();
final int selEnd = getSelectionEnd();
min = Math.max(0, Math.min(selStart, selEnd));
max = Math.max(0, Math.max(selStart, selEnd));
}
Selection.setSelection(getText(), max);
getText().replace(min, max, pasteString);
mIsPastedText = true;
return true;
}
}
if (mOriginalUrlLocation == null || mFormattedUrlLocation == null) {
return super.onTextContextMenuItem(id);
}
int selectedStartIndex = getSelectionStart();
int selectedEndIndex = getSelectionEnd();
// If we are copying/cutting the full previously formatted URL, reset the URL
// text before initiating the TextViews handling of the context menu.
String currentText = getText().toString();
if (selectedStartIndex == 0 && (id == android.R.id.cut || id == android.R.id.copy) && currentText.startsWith(mFormattedUrlLocation) && selectedEndIndex >= mFormattedUrlLocation.length()) {
String newText = mOriginalUrlLocation + currentText.substring(mFormattedUrlLocation.length());
selectedEndIndex = selectedEndIndex - mFormattedUrlLocation.length() + mOriginalUrlLocation.length();
setIgnoreTextChangesForAutocomplete(true);
setText(newText);
setSelection(0, selectedEndIndex);
boolean retVal = super.onTextContextMenuItem(id);
if (getText().toString().equals(newText)) {
setText(currentText);
setSelection(getText().length());
}
setIgnoreTextChangesForAutocomplete(false);
return retVal;
}
return super.onTextContextMenuItem(id);
}
use of android.content.ClipData in project AndroidChromium by JackyAndroid.
the class CustomTabToolbar method onLongClick.
@Override
public boolean onLongClick(View v) {
if (v == mCloseButton) {
return showAccessibilityToast(v, getResources().getString(R.string.close_tab));
} else if (v == mCustomActionButton) {
return showAccessibilityToast(v, mCustomActionButton.getContentDescription());
} else if (v == mTitleUrlContainer) {
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
Tab tab = getCurrentTab();
if (tab == null)
return false;
String url = tab.getOriginalUrl();
ClipData clip = ClipData.newPlainText("url", url);
clipboard.setPrimaryClip(clip);
Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
use of android.content.ClipData in project zxing by zxing.
the class ClipboardInterface method getText.
public static CharSequence getText(Context context) {
ClipboardManager clipboard = getManager(context);
ClipData clip = clipboard.getPrimaryClip();
return hasText(context) ? clip.getItemAt(0).coerceToText(context) : null;
}
Aggregations