Search in sources :

Example 21 with ClipboardManager

use of android.content.ClipboardManager in project CoCoin by Nightonke.

the class CoCoinUtil method copyToClipboard.

public static void copyToClipboard(String content, Context context) {
    ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    cmb.setText(content.trim());
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 22 with ClipboardManager

use of android.content.ClipboardManager in project WordPress-Android by wordpress-mobile.

the class Utils method getUrlFromClipboard.

/**
     * Checks the Clipboard for text that matches the {@link Patterns#WEB_URL} pattern.
     *
     * @return the URL text in the clipboard, if it exists; otherwise null
     */
public static String getUrlFromClipboard(Context context) {
    if (context == null)
        return null;
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData data = clipboard != null ? clipboard.getPrimaryClip() : null;
    if (data == null || data.getItemCount() <= 0)
        return null;
    String clipText = String.valueOf(data.getItemAt(0).getText());
    return Patterns.WEB_URL.matcher(clipText).matches() ? clipText : null;
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 23 with ClipboardManager

use of android.content.ClipboardManager in project CloudReader by youlookwhat.

the class BaseTools method copy.

/**
     * 实现文本复制功能
     *
     * @param content 复制的文本
     */
public static void copy(String content) {
    // 得到剪贴板管理器
    ClipboardManager cmb = (ClipboardManager) CloudReaderApplication.getInstance().getSystemService(Context.CLIPBOARD_SERVICE);
    cmb.setText(content.trim());
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 24 with ClipboardManager

use of android.content.ClipboardManager in project Tusky by Vavassor.

the class ParserUtils method getPastedURLText.

// ComposeActivity : EditText inside the onTextChanged
public String getPastedURLText(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    String pasteData;
    if (clipboard.hasPrimaryClip()) {
        // get what is in the clipboard
        ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
        pasteData = item.getText().toString();
        // If we share with an app, it's not only an url
        List<String> strings = StringUtils.extractUrl(pasteData);
        // we assume that the first url is the good one
        String url = strings.get(0);
        if (strings.size() > 0) {
            if (URLUtil.isValidUrl(url)) {
                new ThreadHeaderInfo().execute(url);
            }
        }
    }
    return null;
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 25 with ClipboardManager

use of android.content.ClipboardManager in project Rocket.Chat.Android by RocketChat.

the class MarkDown method createLinkSpan.

/*package*/
static ClickableSpan createLinkSpan(final String url) {
    return new ClickableSpan() {

        @Override
        public void onClick(View view) {
            final Context context = view.getContext();
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                return;
            } catch (Exception exception) {
            }
            try {
                ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                clipboardManager.setPrimaryClip(ClipData.newPlainText("linkURL", url));
                Toast.makeText(context, "Copied to clipboard", Toast.LENGTH_SHORT).show();
            } catch (Exception exception) {
            }
        }
    };
}
Also used : Context(android.content.Context) ClipboardManager(android.content.ClipboardManager) Intent(android.content.Intent) ClickableSpan(android.text.style.ClickableSpan) TextView(android.widget.TextView) View(android.view.View)

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