Search in sources :

Example 31 with ClipboardManager

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

Example 32 with ClipboardManager

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

Example 33 with ClipboardManager

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

Example 34 with ClipboardManager

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

Example 35 with ClipboardManager

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

Aggregations

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