use of android.content.ClipDescription in project android_frameworks_base by DirtyUnicorns.
the class RemoteInput method getResultsFromIntent.
/**
* Get the remote input results bundle from an intent. The returned Bundle will
* contain a key/value for every result key populated by remote input collector.
* Use the {@link Bundle#getCharSequence(String)} method to retrieve a value.
* @param intent The intent object that fired in response to an action or content intent
* which also had one or more remote input requested.
*/
public static Bundle getResultsFromIntent(Intent intent) {
ClipData clipData = intent.getClipData();
if (clipData == null) {
return null;
}
ClipDescription clipDescription = clipData.getDescription();
if (!clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
return null;
}
if (clipDescription.getLabel().equals(RESULTS_CLIP_LABEL)) {
return clipData.getItemAt(0).getIntent().getExtras().getParcelable(EXTRA_RESULTS_DATA);
}
return null;
}
use of android.content.ClipDescription in project bitcoin-wallet by bitcoin-wallet.
the class SendingAddressesFragment method getAddressFromPrimaryClip.
private Address getAddressFromPrimaryClip() {
if (!clipboardManager.hasPrimaryClip())
return null;
final ClipData clip = clipboardManager.getPrimaryClip();
final ClipDescription clipDescription = clip.getDescription();
if (clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
final CharSequence clipText = clip.getItemAt(0).getText();
if (clipText == null)
return null;
try {
return Address.fromBase58(Constants.NETWORK_PARAMETERS, clipText.toString().trim());
} catch (final AddressFormatException x) {
return null;
}
} else if (clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) {
final Uri clipUri = clip.getItemAt(0).getUri();
if (clipUri == null)
return null;
try {
return new BitcoinURI(clipUri.toString()).getAddress();
} catch (final BitcoinURIParseException x) {
return null;
}
} else {
return null;
}
}
use of android.content.ClipDescription in project instructure-android by instructure.
the class RecipientEditTextView method handlePasteClip.
/**
* Handles pasting a {@link android.content.ClipData} to this {@link com.android.ex.chips.RecipientEditTextView}.
*/
// TODO : allow users to paste?
// Visible for testing.
void handlePasteClip(ClipData clip) {
if (clip == null) {
// Do nothing.
return;
}
final ClipDescription clipDesc = clip.getDescription();
boolean containsSupportedType = clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN) || clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML);
if (!containsSupportedType) {
return;
}
removeTextChangedListener(mTextWatcher);
final ClipDescription clipDescription = clip.getDescription();
for (int i = 0; i < clip.getItemCount(); i++) {
final String mimeType = clipDescription.getMimeType(i);
final boolean supportedType = ClipDescription.MIMETYPE_TEXT_PLAIN.equals(mimeType) || ClipDescription.MIMETYPE_TEXT_HTML.equals(mimeType);
if (!supportedType) {
// Only plain text and html can be pasted.
continue;
}
final CharSequence pastedItem = clip.getItemAt(i).getText();
if (!TextUtils.isEmpty(pastedItem)) {
final Editable editable = getText();
final int start = getSelectionStart();
final int end = getSelectionEnd();
if (start < 0 || end < 1) {
// No selection.
editable.append(pastedItem);
} else if (start == end) {
// Insert at position.
editable.insert(start, pastedItem);
} else {
editable.append(pastedItem, start, end);
}
handlePasteAndReplace();
}
}
mHandler.post(mAddTextWatcher);
}
use of android.content.ClipDescription in project Conversations by siacs.
the class VerifyActivity method pastePinFromClipboard.
private void pastePinFromClipboard() {
final ClipDescription description = clipboardManager != null ? clipboardManager.getPrimaryClipDescription() : null;
if (description != null && description.hasMimeType(MIMETYPE_TEXT_PLAIN)) {
final ClipData primaryClip = clipboardManager.getPrimaryClip();
if (primaryClip != null && primaryClip.getItemCount() > 0) {
final CharSequence clip = primaryClip.getItemAt(0).getText();
if (PinEntryWrapper.isValidPin(clip) && !clip.toString().equals(this.pasted)) {
this.pasted = clip.toString();
pinEntryWrapper.setPin(clip.toString());
final Snackbar snackbar = Snackbar.make(binding.coordinator, R.string.possible_pin, Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.undo, v -> pinEntryWrapper.clear());
snackbar.show();
}
}
}
}
use of android.content.ClipDescription in project platform_frameworks_base by android.
the class RemoteInput method getResultsFromIntent.
/**
* Get the remote input results bundle from an intent. The returned Bundle will
* contain a key/value for every result key populated by remote input collector.
* Use the {@link Bundle#getCharSequence(String)} method to retrieve a value.
* @param intent The intent object that fired in response to an action or content intent
* which also had one or more remote input requested.
*/
public static Bundle getResultsFromIntent(Intent intent) {
ClipData clipData = intent.getClipData();
if (clipData == null) {
return null;
}
ClipDescription clipDescription = clipData.getDescription();
if (!clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
return null;
}
if (clipDescription.getLabel().equals(RESULTS_CLIP_LABEL)) {
return clipData.getItemAt(0).getIntent().getExtras().getParcelable(EXTRA_RESULTS_DATA);
}
return null;
}
Aggregations