use of android.content.ClipboardManager in project BarcodeEye by BarcodeEye.
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 android_frameworks_base by ParanoidAndroid.
the class SelectActionModeCallback method onCreateActionMode.
// ActionMode.Callback implementation
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_copy, menu);
final Context context = mWebView.getContext();
mode.setTitle(context.getString(com.android.internal.R.string.textSelectionCABTitle));
mode.setTitleOptionalHint(true);
// If the action mode UI we're running in isn't capable of taking window focus
// the user won't be able to type into the find on page UI. Disable this functionality.
// (Note that this should only happen in floating dialog windows.)
// This can be removed once we can handle multiple focusable windows at a time
// in a better way.
ClipboardManager cm = (ClipboardManager) (context.getSystemService(Context.CLIPBOARD_SERVICE));
boolean isFocusable = mode.isUiFocusable();
boolean isEditable = mWebView.focusCandidateIsEditableText();
boolean canPaste = isEditable && cm.hasPrimaryClip() && isFocusable;
boolean canFind = !isEditable && isFocusable;
boolean canCut = isEditable && mIsTextSelected && isFocusable;
boolean canCopy = mIsTextSelected;
boolean canWebSearch = mIsTextSelected;
setMenuVisibility(menu, canFind, com.android.internal.R.id.find);
setMenuVisibility(menu, canPaste, com.android.internal.R.id.paste);
setMenuVisibility(menu, canCut, com.android.internal.R.id.cut);
setMenuVisibility(menu, canCopy, com.android.internal.R.id.copy);
setMenuVisibility(menu, canWebSearch, com.android.internal.R.id.websearch);
mActionMode = mode;
return true;
}
use of android.content.ClipboardManager in project android_frameworks_base by ParanoidAndroid.
the class WebViewClassic method copySelection.
/**
* Copy the selection to the clipboard
*
* This is an implementation detail.
*/
public boolean copySelection() {
boolean copiedSomething = false;
String selection = getSelection();
if (selection != null && selection != "") {
if (DebugFlags.WEB_VIEW) {
Log.v(LOGTAG, "copySelection \"" + selection + "\"");
}
Toast.makeText(mContext, com.android.internal.R.string.text_copied, Toast.LENGTH_SHORT).show();
copiedSomething = true;
ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(selection);
int[] handles = new int[4];
getSelectionHandles(handles);
mWebViewCore.sendMessage(EventHub.COPY_TEXT, handles);
}
// remove selection region and pointer
invalidate();
return copiedSomething;
}
use of android.content.ClipboardManager in project android_frameworks_base by ParanoidAndroid.
the class WebViewClassic method pasteFromClipboard.
/**
* Paste text from the clipboard to the cursor position.
*
* This is an implementation detail
*/
public void pasteFromClipboard() {
ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = cm.getPrimaryClip();
if (clipData != null) {
ClipData.Item clipItem = clipData.getItemAt(0);
CharSequence pasteText = clipItem.coerceToText(mContext);
if (mInputConnection != null) {
mInputConnection.replaceSelection(pasteText);
}
}
}
use of android.content.ClipboardManager in project android_frameworks_base by ParanoidAndroid.
the class WebViewClassic method copyToClipboard.
/**
* Copy text into the clipboard. This is called indirectly from
* WebViewCore.
* @param text The text to put into the clipboard.
*/
private void copyToClipboard(String text) {
ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(getTitle(), text);
cm.setPrimaryClip(clip);
}
Aggregations