android.content.ClipDescription Java Examples

The following examples show how to use android.content.ClipDescription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentsProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private final AssetFileDescriptor openTypedAssetFileImpl(
        Uri uri, String mimeTypeFilter, Bundle opts, CancellationSignal signal)
        throws FileNotFoundException {
    enforceTree(uri);
    final String documentId = getDocumentId(uri);
    if (opts != null && opts.containsKey(ContentResolver.EXTRA_SIZE)) {
        final Point sizeHint = opts.getParcelable(ContentResolver.EXTRA_SIZE);
        return openDocumentThumbnail(documentId, sizeHint, signal);
    }
    if ("*/*".equals(mimeTypeFilter)) {
         // If they can take anything, the untyped open call is good enough.
         return openAssetFile(uri, "r");
    }
    final String baseType = getType(uri);
    if (baseType != null && ClipDescription.compareMimeTypes(baseType, mimeTypeFilter)) {
        // Use old untyped open call if this provider has a type for this
        // URI and it matches the request.
        return openAssetFile(uri, "r");
    }
    // For any other yet unhandled case, let the provider subclass handle it.
    return openTypedDocument(documentId, mimeTypeFilter, opts, signal);
}
 
Example #2
Source File: Clipboard.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public String clipDataToHtmlText(ClipData clipData) {
    ClipDescription description = clipData.getDescription();
    if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
        return clipData.getItemAt(0).getHtmlText();
    }

    if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        CharSequence text = clipData.getItemAt(0).getText();
        if (!(text instanceof Spanned)) return null;
        Spanned spanned = (Spanned) text;
        if (hasStyleSpan(spanned)) {
            return ApiCompatibilityUtils.toHtml(
                    spanned, Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
        }
    }
    return null;
}
 
Example #3
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public boolean canPasteAsPlainText() {
    // String resource "paste_as_plain_text" only exist in O.
    // Also this is an O feature, we need to make it consistant with TextView.
    if (!BuildInfo.isAtLeastO()) return false;
    if (!mCanEditRichlyForPastePopup) return false;
    ClipboardManager clipMgr =
            (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
    if (!clipMgr.hasPrimaryClip()) return false;

    ClipData clipData = clipMgr.getPrimaryClip();
    ClipDescription description = clipData.getDescription();
    CharSequence text = clipData.getItemAt(0).getText();
    boolean isPlainType = description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    // On Android, Spanned could be copied to Clipboard as plain_text MIME type, but in some
    // cases, Spanned could have text format, we need to show "paste as plain text" when
    // that happens.
    if (isPlainType && (text instanceof Spanned)) {
        Spanned spanned = (Spanned) text;
        if (hasStyleSpan(spanned)) return true;
    }
    return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML);
}
 
Example #4
Source File: ItemsContentProvider.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
public String[] getStreamTypes(@NonNull final Uri uri, @NonNull final String mimeTypeFilter) {

        switch (sUriMatcher.match(uri)) {
            case MATCHER_ID_FILE:
                if (mimeTypeFilter != null) {
                    // We use ClipDescription just so we can use its filterMimeTypes()
                    // though we are not intested in ClipData here.
                    // TODO: Find a more suitable utility function?
                    final ClipDescription clip = new ClipDescription(null, FILE_MIME_TYPES);
                    return clip.filterMimeTypes(mimeTypeFilter);
                } else {
                    //We return a clone rather than the array itself,
                    //because that would theoretically allow the caller to
                    //modify the items, which is theoretically a
                    //security vulnerability.
                    return FILE_MIME_TYPES.clone();
                }
            default:
                throw new IllegalArgumentException("Unknown type: " +
                        uri);
        }
    }
 
Example #5
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Handles pasting a {@link ClipData} to this {@link RecipientEditTextView}.
 */
private void handlePasteClip(final ClipData clip)
  {
  removeTextChangedListener(mTextWatcher);
  if(clip!=null&&clip.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))
    for(int i=0;i<clip.getItemCount();i++)
      {
      final CharSequence paste=clip.getItemAt(i).getText();
      if(paste!=null)
        {
        final int start=getSelectionStart();
        final int end=getSelectionEnd();
        final Editable editable=getText();
        if(start>=0&&end>=0&&start!=end)
          editable.append(paste,start,end);
        else editable.insert(end,paste);
        handlePasteAndReplace();
        }
      }
  mHandler.post(mAddTextWatcher);
  }
 
Example #6
Source File: VerifyActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
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();
            }
        }
    }
}
 
Example #7
Source File: DragState.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void sendDragStartedLocked(WindowState newWin, float touchX, float touchY,
        ClipDescription desc) {
    if (mDragInProgress && isValidDropTarget(newWin)) {
        DragEvent event = obtainDragEvent(newWin, DragEvent.ACTION_DRAG_STARTED,
                touchX, touchY, null, desc, null, null, false);
        try {
            newWin.mClient.dispatchDragEvent(event);
            // track each window that we've notified that the drag is starting
            mNotifiedWindows.add(newWin);
        } catch (RemoteException e) {
            Slog.w(TAG_WM, "Unable to drag-start window " + newWin);
        } finally {
            // if the callee was local, the dispatch has already recycled the event
            if (Process.myPid() != newWin.mSession.mPid) {
                event.recycle();
            }
        }
    }
}
 
Example #8
Source File: ImageKeyboard.java    From input-samples with Apache License 2.0 6 votes vote down vote up
private boolean isCommitContentSupported(
        @Nullable EditorInfo editorInfo, @NonNull String mimeType) {
    if (editorInfo == null) {
        return false;
    }

    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) {
        return false;
    }

    if (!validatePackageName(editorInfo)) {
        return false;
    }

    final String[] supportedMimeTypes = EditorInfoCompat.getContentMimeTypes(editorInfo);
    for (String supportedMimeType : supportedMimeTypes) {
        if (ClipDescription.compareMimeTypes(mimeType, supportedMimeType)) {
            return true;
        }
    }
    return false;
}
 
Example #9
Source File: DragEvent.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** @hide */
public static DragEvent obtain(int action, float x, float y, Object localState,
        ClipDescription description, ClipData data,
        IDragAndDropPermissions dragAndDropPermissions, boolean result) {
    final DragEvent ev;
    synchronized (gRecyclerLock) {
        if (gRecyclerTop == null) {
            ev = new DragEvent();
            ev.init(action, x, y, description, data, dragAndDropPermissions, localState,
                    result);
            return ev;
        }
        ev = gRecyclerTop;
        gRecyclerTop = ev.mNext;
        gRecyclerUsed -= 1;
    }
    ev.mRecycledLocation = null;
    ev.mRecycled = false;
    ev.mNext = null;

    ev.init(action, x, y, description, data, dragAndDropPermissions, localState, result);

    return ev;
}
 
Example #10
Source File: DragEvent.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public DragEvent createFromParcel(Parcel in) {
    DragEvent event = DragEvent.obtain();
    event.mAction = in.readInt();
    event.mX = in.readFloat();
    event.mY = in.readFloat();
    event.mDragResult = (in.readInt() != 0);
    if (in.readInt() != 0) {
        event.mClipData = ClipData.CREATOR.createFromParcel(in);
    }
    if (in.readInt() != 0) {
        event.mClipDescription = ClipDescription.CREATOR.createFromParcel(in);
    }
    if (in.readInt() != 0) {
        event.mDragAndDropPermissions =
                IDragAndDropPermissions.Stub.asInterface(in.readStrongBinder());;
    }
    return event;
}
 
Example #11
Source File: MainActivity.java    From user-interface-samples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    TextView thisTextView = (TextView) v;
    String dragContent = "Dragged Text: " + thisTextView.getText();

    //Set the drag content and type.
    ClipData.Item item = new ClipData.Item(dragContent);
    ClipData dragData = new ClipData(dragContent,
            new String[] {ClipDescription.MIMETYPE_TEXT_PLAIN}, item);

    //Set the visual look of the dragged object.
    //Can be extended and customized. Default is used here.
    View.DragShadowBuilder dragShadow = new View.DragShadowBuilder(v);

    // Starts the drag, note: global flag allows for cross-application drag.
    v.startDragAndDrop(dragData, dragShadow, null, DRAG_FLAG_GLOBAL);

    return false;
}
 
Example #12
Source File: ClipboardManagerUtil.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
public static CharSequence getText() {
    android.text.ClipboardManager clipboardManager = ServiceUtil.getClipboardManager();
    if (APILevel.require(11)) {
        ClipboardManager cm = (ClipboardManager) clipboardManager;
        ClipDescription description = cm.getPrimaryClipDescription();
        ClipData clipData = cm.getPrimaryClip();
        if (clipData != null
                && description != null
                && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))
            return clipData.getItemAt(0).getText();
        else
            return null;
    } else {
        return clipboardManager.getText();
    }
}
 
Example #13
Source File: TextChipsEditView.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * Handles drag event.
 */
@Override
public boolean onDragEvent(DragEvent event) {
    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
            // Only handle plain text drag and drop.
            return event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
        case DragEvent.ACTION_DRAG_ENTERED:
            requestFocus();
            return true;
        case DragEvent.ACTION_DROP:
            handlePasteClip(event.getClipData());
            return true;
    }
    return false;
}
 
Example #14
Source File: ClipboardUtils.java    From XposedSmsCode with GNU General Public License v3.0 6 votes vote down vote up
public static void clearClipboard(Context context) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (cm == null) {
        XLog.e("Clear failed, clipboard manager is null");
        return;
    }
    if(cm.hasPrimaryClip()) {
        ClipDescription cd = cm.getPrimaryClipDescription();
        if (cd != null) {
            if (cd.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                cm.setPrimaryClip(ClipData.newPlainText("Copy text", ""));
                XLog.i("Clear clipboard succeed");
            }
        }
    }
}
 
Example #15
Source File: TextChipsEditView.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * Handles pasting a {@link ClipData} to this {@link TextChipsEditView}.
 */
private void handlePasteClip(ClipData clip) {
    removeTextChangedListener(mTextWatcher);

    if (clip != null && clip.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        for (int i = 0; i < clip.getItemCount(); i++) {
            CharSequence paste = clip.getItemAt(i).getText();
            if (paste != null) {
                int start = getSelectionStart();
                int end = getSelectionEnd();
                Editable editable = getText();
                if (start >= 0 && end >= 0 && start != end) {
                    editable.append(paste, start, end);
                } else {
                    editable.insert(end, paste);
                }
                handlePasteAndReplace();
            }
        }
    }

    mHandler.post(mAddTextWatcher);
}
 
Example #16
Source File: RecipientEditTextView.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * Handles drag event.
 */
@Override
public boolean onDragEvent(DragEvent event) {
    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
            // Only handle plain text drag and drop.
            return event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
        case DragEvent.ACTION_DRAG_ENTERED:
            requestFocus();
            return true;
        case DragEvent.ACTION_DROP:
            handlePasteClip(event.getClipData());
            return true;
    }
    return false;
}
 
Example #17
Source File: RecipientEditTextView.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * Handles pasting a {@link ClipData} to this {@link RecipientEditTextView}.
 */
private void handlePasteClip(ClipData clip) {
    removeTextChangedListener(mTextWatcher);

    if (clip != null && clip.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        for (int i = 0; i < clip.getItemCount(); i++) {
            CharSequence paste = clip.getItemAt(i).getText();
            if (paste != null) {
                int start = getSelectionStart();
                int end = getSelectionEnd();
                Editable editable = getText();
                if (start >= 0 && end >= 0 && start != end) {
                    editable.append(paste, start, end);
                } else {
                    editable.insert(end, paste);
                }
                handlePasteAndReplace();
            }
        }
    }

    mHandler.post(mAddTextWatcher);
}
 
Example #18
Source File: ClipboardUtils.java    From AdBlockedWebView-Android with MIT License 6 votes vote down vote up
public static CharSequence getText(Context context) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ClipDescription description = cm.getPrimaryClipDescription();
        ClipData clipData = cm.getPrimaryClip();
        if (clipData != null && description != null && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
            return clipData.getItemAt(0).getText();
        } else {
            return "";
        }
    } else {
        //noinspection deprecation
        return cm.getText();
    }
}
 
Example #19
Source File: DocumentsProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private final AssetFileDescriptor openTypedAssetFileImpl(
        Uri uri, String mimeTypeFilter, Bundle opts, CancellationSignal signal)
        throws FileNotFoundException {
    enforceTree(uri);
    final String documentId = getDocumentId(uri);
    if (opts != null && opts.containsKey(ContentResolver.EXTRA_SIZE)) {
        final Point sizeHint = opts.getParcelable(ContentResolver.EXTRA_SIZE);
        return openDocumentThumbnail(documentId, sizeHint, signal);
    }
    if ("*/*".equals(mimeTypeFilter)) {
         // If they can take anything, the untyped open call is good enough.
         return openAssetFile(uri, "r");
    }
    final String baseType = getType(uri);
    if (baseType != null && ClipDescription.compareMimeTypes(baseType, mimeTypeFilter)) {
        // Use old untyped open call if this provider has a type for this
        // URI and it matches the request.
        return openAssetFile(uri, "r");
    }
    // For any other yet unhandled case, let the provider subclass handle it.
    return openTypedDocument(documentId, mimeTypeFilter, opts, signal);
}
 
Example #20
Source File: ImageKeyboard.java    From android-CommitContentSampleIME with Apache License 2.0 6 votes vote down vote up
private boolean isCommitContentSupported(
        @Nullable EditorInfo editorInfo, @NonNull String mimeType) {
    if (editorInfo == null) {
        return false;
    }

    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) {
        return false;
    }

    if (!validatePackageName(editorInfo)) {
        return false;
    }

    final String[] supportedMimeTypes = EditorInfoCompat.getContentMimeTypes(editorInfo);
    for (String supportedMimeType : supportedMimeTypes) {
        if (ClipDescription.compareMimeTypes(mimeType, supportedMimeType)) {
            return true;
        }
    }
    return false;
}
 
Example #21
Source File: DocumentsProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private final AssetFileDescriptor openTypedAssetFileImpl(
        Uri uri, String mimeTypeFilter, Bundle opts, CancellationSignal signal)
        throws FileNotFoundException {
    enforceTree(uri);
    final String documentId = getDocumentId(uri);
    if (opts != null && opts.containsKey(ContentResolver.EXTRA_SIZE)) {
        final Point sizeHint = opts.getParcelable(ContentResolver.EXTRA_SIZE);
        return openDocumentThumbnail(documentId, sizeHint, signal);
    }
    if ("*/*".equals(mimeTypeFilter)) {
         // If they can take anything, the untyped open call is good enough.
         return openAssetFile(uri, "r");
    }
    final String baseType = getType(uri);
    if (baseType != null && ClipDescription.compareMimeTypes(baseType, mimeTypeFilter)) {
        // Use old untyped open call if this provider has a type for this
        // URI and it matches the request.
        return openAssetFile(uri, "r");
    }
    // For any other yet unhandled case, let the provider subclass handle it.
    return openTypedDocument(documentId, mimeTypeFilter, opts, signal);
}
 
Example #22
Source File: DocumentsProvider.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * @hide
 */
private final AssetFileDescriptor openTypedAssetFileImpl(
        Uri uri, String mimeTypeFilter, Bundle opts, CancellationSignal signal)
        throws FileNotFoundException {
    enforceTree(uri);
    final String documentId = getDocumentId(uri);
    if (opts != null && opts.containsKey(ContentResolver.EXTRA_SIZE)) {
        final Point sizeHint = opts.getParcelable(ContentResolver.EXTRA_SIZE);
        return openDocumentThumbnail(documentId, sizeHint, signal);
    }
    if ("*/*".equals(mimeTypeFilter)) {
         // If they can take anything, the untyped open call is good enough.
         return openAssetFile(uri, "r");
    }
    final String baseType = getType(uri);
    if (baseType != null && ClipDescription.compareMimeTypes(baseType, mimeTypeFilter)) {
        // Use old untyped open call if this provider has a type for this
        // URI and it matches the request.
        return openAssetFile(uri, "r");
    }
    // For any other yet unhandled case, let the provider subclass handle it.
    return openTypedDocument(documentId, mimeTypeFilter, opts, signal);
}
 
Example #23
Source File: MainActivity.java    From SaveInsta with Apache License 2.0 5 votes vote down vote up
private String pastClipboard() {
    String textToPaste = null;
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
            textToPaste = clip.getItemAt(0).getText().toString();
        }
    }
    return textToPaste;
}
 
Example #24
Source File: Utils.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
public static String readFromClipboard() {
    ClipboardManager clipboard = (ClipboardManager) App.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()) {
        android.content.ClipDescription description = clipboard.getPrimaryClipDescription();
        android.content.ClipData data = clipboard.getPrimaryClip();
        if (data != null && description != null && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))
            return String.valueOf(data.getItemAt(0).getText());
    }
    return null;
}
 
Example #25
Source File: ContentFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
boolean processDragStarted(DragEvent event) {
    // Determine whether to continue processing drag and drop based on the
    // plain text mime type.
    ClipDescription clipDesc = event.getClipDescription();
    if (clipDesc != null) {
        return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    }
    return false;
}
 
Example #26
Source File: ClipboardUtils.java    From AdBlockedWebView-Android with MIT License 5 votes vote down vote up
public static boolean hasText(Context context) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ClipDescription description = cm.getPrimaryClipDescription();
        ClipData clipData = cm.getPrimaryClip();
        return clipData != null
                && description != null
                && (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN));
    } else {
        //noinspection deprecation
        return cm.hasText();
    }
}
 
Example #27
Source File: ActivityServiceUtils.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Pastes the first clip item containing the mimetype text.
 *
 * @param activity Activity where CLIPBOARD_SERVICE can be fetched.
 *
 * @return CharSequence text from clipboard, empty if there isn't any.
 */
public static CharSequence pasteFromClipboard(Activity activity) {
    ClipboardManager clipboardManager = (ClipboardManager) activity
            .getSystemService(Context.CLIPBOARD_SERVICE);

    if (clipboardManager != null && clipboardManager.hasPrimaryClip()
            && clipboardManager.getPrimaryClipDescription()
                               .hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        return clipboardManager.getPrimaryClip().getItemAt(0).getText();
    } else {
        return "";
    }
}
 
Example #28
Source File: MentionsEditText.java    From Spyglass with Apache License 2.0 5 votes vote down vote up
/**
 * Save the selected text and intent in ClipboardManager
 */
private void saveToClipboard(@NonNull CharSequence selectedText, @Nullable Intent intent) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData.Item item = new ClipData.Item(selectedText, intent, null);
    ClipData clip = new ClipData(null, new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN}, item);
    clipboard.setPrimaryClip(clip);
}
 
Example #29
Source File: ContentFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
boolean processDragStarted(DragEvent event) {
    // Determine whether to continue processing drag and drop based on the
    // plain text mime type.
    ClipDescription clipDesc = event.getClipDescription();
    if (clipDesc != null) {
        return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    }
    return false;
}
 
Example #30
Source File: ContentFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
boolean processDragStarted(DragEvent event) {
    // Determine whether to continue processing drag and drop based on the
    // plain text mime type.
    ClipDescription clipDesc = event.getClipDescription();
    if (clipDesc != null) {
        return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    }
    return false;
}