Search in sources :

Example 41 with ClipData

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

Example 42 with ClipData

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

Example 43 with ClipData

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

Example 44 with ClipData

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;
}
Also used : ClipboardManager(android.content.ClipboardManager) Tab(org.chromium.chrome.browser.tab.Tab) ClipData(android.content.ClipData)

Example 45 with ClipData

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

Aggregations

ClipData (android.content.ClipData)193 ClipboardManager (android.content.ClipboardManager)81 Intent (android.content.Intent)48 Uri (android.net.Uri)41 Paint (android.graphics.Paint)24 MenuItem (android.view.MenuItem)20 View (android.view.View)16 ArrayList (java.util.ArrayList)15 TextView (android.widget.TextView)12 PendingIntent (android.app.PendingIntent)11 Bundle (android.os.Bundle)11 RemoteException (android.os.RemoteException)11 ContentResolver (android.content.ContentResolver)10 Nullable (android.support.annotation.Nullable)10 TextPaint (android.text.TextPaint)10 ImageView (android.widget.ImageView)10 DocumentInfo (com.android.documentsui.model.DocumentInfo)10 Item (android.content.ClipData.Item)9 Editable (android.text.Editable)9 DialogInterface (android.content.DialogInterface)8