use of android.content.ClipData in project sharelock-android by auth0.
the class ComposeActivity method onEvent.
public void onEvent(RequestLinkEvent event) {
final Secret secret = event.getSecret();
final EventBus bus = this.bus;
SharedPreferences preferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
client = new LinkAPIClient(preferences.getString(LinkAPIClient.SHARELOCK_ENDPOINT_KEY, LinkAPIClient.DEFAULT_URL));
client.generateLinkForSecret(secret, this, new LinkAPIClient.LinkCallback() {
@Override
public void onSuccess(final Uri link) {
Log.d(TAG, "Obtained link path " + link);
handler.postDelayed(new Runnable() {
@Override
public void run() {
bus.postSticky(new NewLinkEvent(link));
final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
final ClipData clipData = ClipData.newRawUri("sharelocked-link", link);
clipboardManager.setPrimaryClip(clipData);
Snackbar snackbar = Snackbar.with(ComposeActivity.this).text(R.string.link_in_clipboard_message).duration(Snackbar.SnackbarDuration.LENGTH_SHORT);
SnackbarManager.show(snackbar);
}
}, DELAY_MILLIS);
}
@Override
public void onError(Throwable reason) {
Log.e(TAG, "Failed to generate link", reason);
bus.post(new SharelockAPIErrorEvent());
AlertDialog dialog = new AlertDialog.Builder(ComposeActivity.this).setTitle(R.string.link_generation_failed_title).setMessage(R.string.link_generation_failed).setCancelable(true).setPositiveButton(R.string.retry_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
bus.post(new RequestLinkEvent(secret));
}
}).setNegativeButton(R.string.cancel_button, null).create();
dialog.show();
}
});
}
use of android.content.ClipData in project Conversations by siacs.
the class ConversationActivity method extractUriFromIntent.
@SuppressLint("NewApi")
private static List<Uri> extractUriFromIntent(final Intent intent) {
List<Uri> uris = new ArrayList<>();
if (intent == null) {
return uris;
}
Uri uri = intent.getData();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) {
final ClipData clipData = intent.getClipData();
if (clipData != null) {
for (int i = 0; i < clipData.getItemCount(); ++i) {
uris.add(clipData.getItemAt(i).getUri());
}
}
} else {
uris.add(uri);
}
return uris;
}
use of android.content.ClipData in project platform_frameworks_base by android.
the class Editor method onDrop.
void onDrop(DragEvent event) {
StringBuilder content = new StringBuilder("");
final DragAndDropPermissions permissions = DragAndDropPermissions.obtain(event);
if (permissions != null) {
permissions.takeTransient();
}
try {
ClipData clipData = event.getClipData();
final int itemCount = clipData.getItemCount();
for (int i = 0; i < itemCount; i++) {
Item item = clipData.getItemAt(i);
content.append(item.coerceToStyledText(mTextView.getContext()));
}
} finally {
if (permissions != null) {
permissions.release();
}
}
final int offset = mTextView.getOffsetForPosition(event.getX(), event.getY());
Object localState = event.getLocalState();
DragLocalState dragLocalState = null;
if (localState instanceof DragLocalState) {
dragLocalState = (DragLocalState) localState;
}
boolean dragDropIntoItself = dragLocalState != null && dragLocalState.sourceTextView == mTextView;
if (dragDropIntoItself) {
if (offset >= dragLocalState.start && offset < dragLocalState.end) {
// A drop inside the original selection discards the drop.
return;
}
}
final int originalLength = mTextView.getText().length();
int min = offset;
int max = offset;
Selection.setSelection((Spannable) mTextView.getText(), max);
mTextView.replaceText_internal(min, max, content);
if (dragDropIntoItself) {
int dragSourceStart = dragLocalState.start;
int dragSourceEnd = dragLocalState.end;
if (max <= dragSourceStart) {
// Inserting text before selection has shifted positions
final int shift = mTextView.getText().length() - originalLength;
dragSourceStart += shift;
dragSourceEnd += shift;
}
mUndoInputFilter.setForceMerge(true);
try {
// Delete original selection
mTextView.deleteText_internal(dragSourceStart, dragSourceEnd);
// Make sure we do not leave two adjacent spaces.
final int prevCharIdx = Math.max(0, dragSourceStart - 1);
final int nextCharIdx = Math.min(mTextView.getText().length(), dragSourceStart + 1);
if (nextCharIdx > prevCharIdx + 1) {
CharSequence t = mTextView.getTransformedText(prevCharIdx, nextCharIdx);
if (Character.isSpaceChar(t.charAt(0)) && Character.isSpaceChar(t.charAt(1))) {
mTextView.deleteText_internal(prevCharIdx, prevCharIdx + 1);
}
}
} finally {
mUndoInputFilter.setForceMerge(false);
}
}
}
use of android.content.ClipData in project platform_frameworks_base by android.
the class Editor method startDragAndDrop.
private void startDragAndDrop() {
// TODO: Fix drag and drop in full screen extracted mode.
if (mTextView.isInExtractedMode()) {
return;
}
final int start = mTextView.getSelectionStart();
final int end = mTextView.getSelectionEnd();
CharSequence selectedText = mTextView.getTransformedText(start, end);
ClipData data = ClipData.newPlainText(null, selectedText);
DragLocalState localState = new DragLocalState(mTextView, start, end);
mTextView.startDragAndDrop(data, getTextThumbnailBuilder(start, end), localState, View.DRAG_FLAG_GLOBAL);
stopTextActionMode();
if (hasSelectionController()) {
getSelectionController().resetTouchOffsets();
}
}
use of android.content.ClipData in project platform_frameworks_base by android.
the class DocumentClipper method hasItemsToPaste.
public boolean hasItemsToPaste() {
if (mClipboard.hasPrimaryClip()) {
ClipData clipData = mClipboard.getPrimaryClip();
int count = clipData.getItemCount();
if (count > 0) {
for (int i = 0; i < count; ++i) {
ClipData.Item item = clipData.getItemAt(i);
Uri uri = item.getUri();
if (isDocumentUri(uri)) {
return true;
}
}
}
}
return false;
}
Aggregations