use of android.content.ClipboardManager 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.ClipboardManager 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.ClipboardManager in project AndroidDevelop by 7449.
the class UIUtils method copyCL.
public static void copyCL(TextView textView) {
ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(textView.getText().toString().trim());
}
use of android.content.ClipboardManager 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;
}
use of android.content.ClipboardManager in project zxing by zxing.
the class ClipboardInterface method hasText.
public static boolean hasText(Context context) {
ClipboardManager clipboard = getManager(context);
ClipData clip = clipboard.getPrimaryClip();
return clip != null && clip.getItemCount() > 0;
}
Aggregations