Search in sources :

Example 11 with ClipboardManager

use of android.text.ClipboardManager in project android-ocr by rmtheis.

the class CaptureActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    switch(item.getItemId()) {
        case OPTIONS_COPY_RECOGNIZED_TEXT_ID:
            clipboardManager.setText(ocrResultView.getText());
            if (clipboardManager.hasText()) {
                Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
                toast.setGravity(Gravity.BOTTOM, 0, 0);
                toast.show();
            }
            return true;
        case OPTIONS_SHARE_RECOGNIZED_TEXT_ID:
            Intent shareRecognizedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareRecognizedTextIntent.setType("text/plain");
            shareRecognizedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, ocrResultView.getText());
            startActivity(Intent.createChooser(shareRecognizedTextIntent, "Share via"));
            return true;
        case OPTIONS_COPY_TRANSLATED_TEXT_ID:
            clipboardManager.setText(translationView.getText());
            if (clipboardManager.hasText()) {
                Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
                toast.setGravity(Gravity.BOTTOM, 0, 0);
                toast.show();
            }
            return true;
        case OPTIONS_SHARE_TRANSLATED_TEXT_ID:
            Intent shareTranslatedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareTranslatedTextIntent.setType("text/plain");
            shareTranslatedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, translationView.getText());
            startActivity(Intent.createChooser(shareTranslatedTextIntent, "Share via"));
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
Also used : ClipboardManager(android.text.ClipboardManager) Toast(android.widget.Toast) Intent(android.content.Intent)

Example 12 with ClipboardManager

use of android.text.ClipboardManager in project bee by orhanobut.

the class UiHandler method initListView.

private void initListView(ListView listView) {
    final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ContentHolder contentHolder = (ContentHolder) parent.getItemAtPosition(position);
            clipboard.setText(contentHolder.getValue());
            showToast(contentHolder.getValue() + " is copied to clipboard");
            return true;
        }
    });
}
Also used : ClipboardManager(android.text.ClipboardManager) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Point(android.graphics.Point)

Example 13 with ClipboardManager

use of android.text.ClipboardManager in project wechat by motianhuo.

the class PasteEditText method onTextContextMenuItem.

@SuppressLint("NewApi")
@Override
public boolean onTextContextMenuItem(int id) {
    if (id == android.R.id.paste) {
        ClipboardManager clip = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        if (clip == null || clip.getText() == null) {
            return false;
        }
        String text = clip.getText().toString();
        if (text.startsWith(ChatActivity.COPY_IMAGE)) {
            // intent.setDataAndType(Uri.fromFile(new
            // File("/sdcard/mn1.jpg")), "image/*");
            text = text.replace(ChatActivity.COPY_IMAGE, "");
            Intent intent = new Intent(context, AlertDialog.class);
            String str = "发送以下图片?";
            intent.putExtra("title", str);
            intent.putExtra("forwardImage", text);
            intent.putExtra("cancel", true);
            ((Activity) context).startActivityForResult(intent, ChatActivity.REQUEST_CODE_COPY_AND_PASTE);
        // clip.setText("");
        }
    }
    return super.onTextContextMenuItem(id);
}
Also used : ClipboardManager(android.text.ClipboardManager) ChatActivity(com.juns.wechat.chat.ChatActivity) Activity(android.app.Activity) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 14 with ClipboardManager

use of android.text.ClipboardManager in project android-toolbox by Knickedi.

the class SafeClipboard method setText.

// PUBLIC =====================================================================================
/**
	 * Save text on clipboard and let it clear itself after given amount of milliseconds.<br>
	 * <br>
	 * Clipboard will only be cleared if it contains the text which was set with this method before,
	 * so when another text is clipped (e.g. by another application) it won't be cleared. A new call
	 * will stop old clearance timeout and start a new one.
	 * 
	 * @param context
	 * @param text
	 *            text to save on clipboard ({@code null} will clear clipboard)
	 * @param timeout
	 *            amount of milliseconds text will be available on clipboard ({@code < 1000} equals
	 *            forever)
	 */
public static void setText(Context context, String text, long timeout) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    cm.setText(text);
    Intent service = new Intent(context, SafeClipboard.class);
    if (text == null || timeout < 1000) {
        // kill running service (if its running) because it's not needed anymore
        context.stopService(service);
    } else {
        // start (or update) service which will clear
        service.putExtra(EXTRA_TEXT, text);
        service.putExtra(EXTRA_TIMEOUT, timeout);
        context.startService(service);
    }
}
Also used : ClipboardManager(android.text.ClipboardManager) Intent(android.content.Intent)

Example 15 with ClipboardManager

use of android.text.ClipboardManager in project android-toolbox by Knickedi.

the class SwipeableListQuickActionActivity method onQuickAction.

/**
	 * React on quick action click.
	 */
@Override
public void onQuickAction(AdapterView<?> parent, View view, int position, int quickActionId) {
    switch(quickActionId) {
        case QuickAction.OPEN:
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(ITEMS[position][1]));
            startActivity(i);
            break;
        case QuickAction.COPY:
            ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            cm.setText(ITEMS[position][1]);
            Toast.makeText(this, "URL copied to clipboard", Toast.LENGTH_SHORT).show();
            break;
    }
}
Also used : ClipboardManager(android.text.ClipboardManager) Intent(android.content.Intent)

Aggregations

ClipboardManager (android.text.ClipboardManager)15 Intent (android.content.Intent)5 View (android.view.View)2 ImageView (android.widget.ImageView)2 SocketException (java.net.SocketException)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Editable (android.text.Editable)1 Spanned (android.text.Spanned)1 TextPaint (android.text.TextPaint)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AdapterView (android.widget.AdapterView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 PopupWindow (android.widget.PopupWindow)1 ScrollView (android.widget.ScrollView)1