Search in sources :

Example 1 with ClipboardManager

use of android.content.ClipboardManager in project android_frameworks_base by ParanoidAndroid.

the class TextView method paste.

/**
     * Paste clipboard content between min and max positions.
     */
private void paste(int min, int max) {
    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++) {
            CharSequence paste = clip.getItemAt(i).coerceToStyledText(getContext());
            if (paste != null) {
                if (!didFirst) {
                    long minMax = prepareSpacesAroundPaste(min, max, paste);
                    min = TextUtils.unpackRangeStartFromLong(minMax);
                    max = TextUtils.unpackRangeEndFromLong(minMax);
                    Selection.setSelection((Spannable) mText, max);
                    ((Editable) mText).replace(min, max, paste);
                    didFirst = true;
                } else {
                    ((Editable) mText).insert(getSelectionEnd(), "\n");
                    ((Editable) mText).insert(getSelectionEnd(), paste);
                }
            }
        }
        stopSelectionActionMode();
        LAST_CUT_OR_COPY_TIME = 0;
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) Editable(android.text.Editable) ClipData(android.content.ClipData) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 2 with ClipboardManager

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;
}
Also used : Context(android.content.Context) ClipboardManager(android.content.ClipboardManager)

Example 3 with ClipboardManager

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;
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 4 with ClipboardManager

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);
        }
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 5 with ClipboardManager

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);
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Aggregations

ClipboardManager (android.content.ClipboardManager)112 ClipData (android.content.ClipData)71 Intent (android.content.Intent)17 View (android.view.View)13 Context (android.content.Context)10 TextView (android.widget.TextView)10 Paint (android.graphics.Paint)9 DialogInterface (android.content.DialogInterface)7 Editable (android.text.Editable)7 TextPaint (android.text.TextPaint)7 TargetApi (android.annotation.TargetApi)5 Uri (android.net.Uri)5 AlertDialog (android.support.v7.app.AlertDialog)5 Spanned (android.text.Spanned)5 AlertDialog (android.app.AlertDialog)4 ImageView (android.widget.ImageView)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Drawable (android.graphics.drawable.Drawable)3 MenuItem (android.view.MenuItem)3 SharedPreferences (android.content.SharedPreferences)2