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;
}
}
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();
}
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;
}
}
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);
}
}
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;
}
Aggregations