Search in sources :

Example 41 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 42 with ClipboardManager

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

the class TextView method setPrimaryClip.

private void setPrimaryClip(ClipData clip) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(clip);
    sLastCutCopyOrTextChangedTime = SystemClock.uptimeMillis();
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 43 with ClipboardManager

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

the class TextView method paste.

/**
     * Paste clipboard content between min and max positions.
     */
private void paste(int min, int max, boolean withFormatting) {
    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++) {
            final CharSequence paste;
            if (withFormatting) {
                paste = clip.getItemAt(i).coerceToStyledText(getContext());
            } else {
                // Get an item as text and remove all spans by toString().
                final CharSequence text = clip.getItemAt(i).coerceToText(getContext());
                paste = (text instanceof Spanned) ? text.toString() : text;
            }
            if (paste != null) {
                if (!didFirst) {
                    Selection.setSelection((Spannable) mText, max);
                    ((Editable) mText).replace(min, max, paste);
                    didFirst = true;
                } else {
                    ((Editable) mText).insert(getSelectionEnd(), "\n");
                    ((Editable) mText).insert(getSelectionEnd(), paste);
                }
            }
        }
        sLastCutCopyOrTextChangedTime = 0;
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) Editable(android.text.Editable) ClipData(android.content.ClipData) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 44 with ClipboardManager

use of android.content.ClipboardManager in project weex-example by KalicyZhou.

the class WXClipboardModule method getString.

@Override
@JSMethod
public void getString(@Nullable JSCallback callback) {
    Context context = mWXSDKInstance.getContext();
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    Map<String, Object> map = new HashMap<>(2);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        ClipData.Item item = clip.getItemAt(0);
        CharSequence text = coerceToText(context, item);
        map.put(RESULT, text != null ? RESULT_OK : RESULT_FAILED);
        map.put(DATA, text != null ? text : "");
    } else {
        map.put(RESULT, RESULT_FAILED);
        map.put(DATA, "");
    }
    if (null != callback) {
        callback.invoke(map);
    }
}
Also used : Context(android.content.Context) ClipboardManager(android.content.ClipboardManager) HashMap(java.util.HashMap) ClipData(android.content.ClipData) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 45 with ClipboardManager

use of android.content.ClipboardManager in project wire-android by wireapp.

the class AvsOptionsDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup vcontainer, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_avs_options, vcontainer, false);
    loggingTextView = ViewUtils.getView(view, R.id.avs__logging);
    loggingTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean updatedValue = !getStoreFactory().getZMessagingApiStore().getAvs().isLoggingEnabled();
            getStoreFactory().getZMessagingApiStore().getAvs().setLoggingEnabled(updatedValue);
            updateButton(loggingTextView, updatedValue);
        }
    });
    postSessionIdTextView = ViewUtils.getView(view, R.id.avs__post_session_id);
    postSessionIdTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean updatedValue = !getControllerFactory().getUserPreferencesController().isPostSessionIdToConversation();
            getControllerFactory().getUserPreferencesController().setPostSessionIdToConversation(updatedValue);
            updateButton(postSessionIdTextView, updatedValue);
        }
    });
    lastSessionIdTextView = ViewUtils.getView(view, R.id.avs__last_session_id);
    final String lastCallSessionId = getControllerFactory().getUserPreferencesController().getLastCallSessionId();
    lastSessionIdTextView.setText(lastCallSessionId);
    lastSessionIdTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(getString(R.string.pref_dev_avs_last_call_session_id_title), lastCallSessionId);
            clipboard.setPrimaryClip(clip);
            Toast.makeText(getActivity(), getString(R.string.pref_dev_avs_last_call_session_id_copied_to_clipboard), Toast.LENGTH_SHORT).show();
        }
    });
    return view;
}
Also used : ClipboardManager(android.content.ClipboardManager) TextView(android.widget.TextView) View(android.view.View) 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