Java 类android.content.ClipDescription 实例源码

项目:SmingZZick_App    文件:StickerApplyAdapter.java   
@Override
public boolean onLongClick(View v) {
    ClipData.Item item = new ClipData.Item("" + v.getTag());
    ClipData dragData = new ClipData("" + v.getTag(), new String[] {ClipDescription.MIMETYPE_TEXT_PLAIN},item);

    View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v);

    showDragBuide();
    v.startDrag(dragData,  // the data to be dragged
            myShadow,  // the drag shadow builder
            null,      // no need to use local data
            0          // flags (not currently used, set to 0)
    );
    v.setAlpha(0.2f);
    return true;
}
项目:Demos    文件:DragFillBlankView.java   
/**
 * 开始拖拽
 *
 * @param v 当前对象
 */
private void startDrag(View v) {
    // 选项内容
    String optionContent = ((Button) v).getText().toString();
    // 记录当前答案选项的位置
    optionPosition = getOptionPosition(optionContent);
    // 开始拖拽后在列表中隐藏答案选项
    v.setVisibility(INVISIBLE);

    ClipData.Item item = new ClipData.Item(optionContent);
    ClipData data = new ClipData(null, new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN}, item);
    v.startDrag(data, new DragShadowBuilder(v), null, 0);
}
项目:ROKOmoji.Emoji.Keyboard.App-Android    文件:KeyboardService.java   
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;
}
项目:easyfilemanager    文件:DocumentsProvider.java   
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);
}
项目:iroha-demo-android    文件:AssetReceivePresenter.java   
public View.OnClickListener onPublicKeyTextClicked() {
    return new View.OnClickListener() {
        private static final String CLIP_DATA_LABEL_TEXT_DATA = "text_data";

        @Override
        public void onClick(View view) {
            final Context context = assetReceiveView.getContext();

            ClipData.Item item = new ClipData.Item(assetReceiveView.getPublicKey());

            String[] mimeType = new String[1];
            mimeType[0] = ClipDescription.MIMETYPE_TEXT_URILIST;

            ClipData cd = new ClipData(new ClipDescription(CLIP_DATA_LABEL_TEXT_DATA, mimeType), item);

            ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
            cm.setPrimaryClip(cd);

            Toast.makeText(context, R.string.message_copy_to_clipboard, Toast.LENGTH_SHORT).show();
        }
    };
}
项目:Blockly    文件:DraggerTest.java   
/** Drag events are not always block related.  Ignore other blocks. */
@Test
public void testIgnoreDragThatIsntBlocks() throws BlockLoadingException {
    // Setup
    mTouchedBlock = mDraggedBlock = mBlockFactory.obtainBlockFrom(
            new BlockTemplate().ofType("simple_input_output"));
    mTargetBlock = mBlockFactory.obtainBlockFrom(new BlockTemplate().ofType("output_no_input"));

    Mockito.when(mMockBlockClipDataHelper.isBlockData(any(ClipDescription.class)))
            .thenReturn(false);

    setupDrag();
    dragBlockToTarget();

    Mockito.verify(mMockConnectionManager, never())
            .findBestConnection(Matchers.same(mTouchedBlock), anyInt());
    Mockito.verify(mMockController, never())
            .connect(any(Connection.class), any(Connection.class));
}
项目:Blockly    文件:DraggerTest.java   
/** Drag together two compatible blocks. */
@Test
public void testDragConnect() throws BlockLoadingException {
    // Setup
    mTouchedBlock = mDraggedBlock = mBlockFactory.obtainBlockFrom(
            new BlockTemplate().ofType("simple_input_output"));
    mTargetBlock = mBlockFactory.obtainBlockFrom(new BlockTemplate().ofType("output_no_input"));

    Mockito.when(mMockBlockClipDataHelper.isBlockData(any(ClipDescription.class)))
            .thenReturn(true);
    Mockito.when(
            mMockConnectionManager.findBestConnection(Matchers.same(mTouchedBlock), anyInt()))
            .thenReturn(Pair.create(mTouchedBlock.getOnlyValueInput().getConnection(),
                    mTargetBlock.getOutputConnection()));

    setupDrag();
    dragBlockToTarget();

    Mockito.verify(mMockConnectionManager, atLeastOnce())
            .findBestConnection(Matchers.same(mTouchedBlock), anyInt());
    Mockito.verify(mMockController).connect(
            mTouchedBlock.getOnlyValueInput().getConnection(),
            mTargetBlock.getOutputConnection());
}
项目:Blockly    文件:DraggerTest.java   
/** Drag together two incompatible blocks. */
@Test
public void testDragNoConnect() throws BlockLoadingException {
    // Setup
    mTouchedBlock = mDraggedBlock = mBlockFactory.obtainBlockFrom(
            new BlockTemplate().ofType("simple_input_output"));
    mTargetBlock = mBlockFactory.obtainBlockFrom(new BlockTemplate().ofType("output_no_input"));

    Mockito.when(mMockBlockClipDataHelper.isBlockData(any(ClipDescription.class)))
            .thenReturn(true);
    Mockito.when(mMockConnectionManager.findBestConnection(any(Block.class), anyInt()))
            .thenReturn(null);

    setupDrag();
    dragBlockToTarget();

    Mockito.verify(mMockConnectionManager, atLeastOnce())
            .findBestConnection(Matchers.same(mTouchedBlock), anyInt());
    Mockito.verify(mMockController, never())
            .connect(any(Connection.class), any(Connection.class));
}
项目:FireFiles    文件:DocumentsProvider.java   
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);
}
项目:boohee_v5.6    文件:RemoteInputCompatJellybean.java   
static Bundle getResultsFromIntent(Intent intent) {
    ClipData clipData = intent.getClipData();
    if (clipData == null) {
        return null;
    }
    ClipDescription clipDescription = clipData.getDescription();
    if (clipDescription.hasMimeType("text/vnd.android.intent") && clipDescription.getLabel().equals("android.remoteinput.results")) {
        return (Bundle) clipData.getItemAt(0).getIntent().getExtras().getParcelable("android.remoteinput.resultsData");
    }
    return null;
}
项目:simple-share-android    文件:DocumentsProvider.java   
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);
}
项目:DownInsta    文件:MainActivity.java   
public void onClickButtonPasteToUrlField(View v) {
    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    if (cm.hasPrimaryClip()) {
        ClipDescription desc = cm.getPrimaryClipDescription();
        Log.e("asd", desc.toString());
        if (desc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
            CharSequence pasteText = cm.getPrimaryClip().getItemAt(0).getText();
            editTextUrl.setText(pasteText);
            download();
        } else {
            Log.e("asd", "not text");
            //makeToast("Unable to paste non-text data. Please copy from Instagram again.");
            Snackbar.make(v, "Unable to paste non-text data. Please copy from Instagram again.", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    } else {
        Log.e("asd", "nothing to paste");
        //makeToast("Clipboard is empty. Please copy from Instagram again.");
        Snackbar.make(v, "Clipboard is empty. Please copy from Instagram again.", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();
    }
}
项目:AdBlockedWebView-Android    文件:ClipboardUtils.java   
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();
    }
}
项目:webviewer-android    文件:ClipboardUtils.java   
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();
    }
}
项目:talk-android    文件:RecipientEditTextView.java   
/**
 * 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);
}
项目:talk-android    文件:RecipientEditTextView.java   
/**
 * 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;
}
项目:talk-android    文件:TextChipsEditView.java   
/**
 * 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);
}
项目:talk-android    文件:TextChipsEditView.java   
/**
 * 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;
}
项目:iroha-demo-android    文件:AssetReceivePresenter.java   
public View.OnClickListener onPublicKeyTextClicked() {
    return new View.OnClickListener() {
        private static final String CLIP_DATA_LABEL_TEXT_DATA = "text_data";

        @Override
        public void onClick(View view) {
            final Context context = assetReceiveView.getContext();

            ClipData.Item item = new ClipData.Item(assetReceiveView.getPublicKey());

            String[] mimeType = new String[1];
            mimeType[0] = ClipDescription.MIMETYPE_TEXT_URILIST;

            ClipData cd = new ClipData(new ClipDescription(CLIP_DATA_LABEL_TEXT_DATA, mimeType), item);

            ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
            cm.setPrimaryClip(cd);

            Toast.makeText(context, R.string.message_copy_to_clipboard, Toast.LENGTH_SHORT).show();
        }
    };
}
项目:SoundNotes    文件:RichEditText.java   
public void onTextPaste(int[] textInfo) {
    int startSelPos = textInfo[0];
    int prevDevLineCount = textInfo[1];
    ClipboardManager clipboard = (ClipboardManager) ctx.get().getSystemService(Context.CLIPBOARD_SERVICE);

    String pasteData = "";

    // Controllo che la clipboard contenga qualcosa e che sia testo incollabile
    if (clipboard.hasPrimaryClip() &&
            clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
        pasteData = item.getText().toString();
        if (pasteData != null) {
            int linesAdded = countOccurrences('\n', pasteData, 0, '\0');


            recView.get().insertNewline(linesAdded, startSelPos, prevDevLineCount);
        }
    }
}
项目:Android-App-Template    文件:ClipboardManagerUtil.java   
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();
    }
}
项目:discover-android-n    文件:ExplorerListAdapter.java   
@Override
public void onItemLongClick(View view, File f) {
    if (f.isDirectory()) {
        Snackbar.make(view, "Sorry, no drag'n'drop support for directories", Snackbar.LENGTH_SHORT).show();
        return;
    }
    // prepare drag parameters
    ClipDescription description = new ClipDescription(f.getName(), new String[]{ClipDescription.MIMETYPE_TEXT_URILIST});
    ClipData.Item clipDataItem = new ClipData.Item(Uri.fromFile(f));
    ClipData draggedData = new ClipData(description, clipDataItem);
    View.DragShadowBuilder dragShadowBuilder = new View.DragShadowBuilder(view);
    // start drag and drop operation for proper platform
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        view.startDragAndDrop(draggedData, dragShadowBuilder, null, View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ);
    } else {
        //noinspection deprecation
        view.startDrag(draggedData, dragShadowBuilder, null, 0);
    }
}
项目:shr    文件:MainActivity.java   
/**
 * 从Clip中取数据
 */
private void checkClipboard() {
  clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
  ClipData.Item item = null;

  // 无数据时直接返回
  if (!clipboard.hasPrimaryClip()) {
    Toast.makeText(getApplicationContext(), "剪贴板中无数据", Toast.LENGTH_SHORT).show();
    return;
  }

  // 如果是文本信息
  if (clipboard.getPrimaryClipDescription().hasMimeType(
      ClipDescription.MIMETYPE_TEXT_PLAIN)) {
    ClipData cdText = clipboard.getPrimaryClip();
    item = cdText.getItemAt(0);
    // 此处是TEXT文本信息
    if (item.getText() == null) {
      Toast.makeText(getApplicationContext(), "剪贴板中无内容", Toast.LENGTH_SHORT).show();
      // return;
    } else {
      Toast.makeText(getApplicationContext(), item.getText(), Toast.LENGTH_SHORT).show();
      text_from_clipboard = item.getText().toString();
    }
  }
}
项目:shr    文件:BaseActivity.java   
/**
 * 从Clip中取数据
 */
protected void checkClipboard() {
  clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
  ClipData.Item item = null;

  // 无数据时直接返回
  if (!clipboard.hasPrimaryClip()) {
    Toast.makeText(getApplicationContext(), "剪贴板中无数据", Toast.LENGTH_SHORT).show();
    return;
  }

  // 如果是文本信息
  if (clipboard.getPrimaryClipDescription().hasMimeType(
      ClipDescription.MIMETYPE_TEXT_PLAIN)) {
    ClipData cdText = clipboard.getPrimaryClip();
    item = cdText.getItemAt(0);
    // 此处是TEXT文本信息
    if (item.getText() == null) {
      Toast.makeText(getApplicationContext(), "剪贴板中无内容", Toast.LENGTH_SHORT).show();
      // return;
    } else {
      Toast.makeText(getApplicationContext(), item.getText(), Toast.LENGTH_SHORT).show();
      text_from_clipboard = item.getText().toString();
    }
  }
}
项目:365browser    文件:SelectionPopupController.java   
@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);
}
项目:365browser    文件:Clipboard.java   
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;
}
项目:onChart    文件:DonateFragment.java   
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setPositiveButton(getString(R.string.button_donate), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage("com.eg.android.AlipayGphone");
            ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData data = ClipData.newPlainText(ClipDescription.MIMETYPE_TEXT_PLAIN, getString(R.string.alipay_account));
            clipboardManager.setPrimaryClip(data);
            if (intent != null) {
                Toast.makeText(getActivity(), getString(R.string.alert_clipboard_complete), Toast.LENGTH_LONG).show();
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), getString(R.string.alert_no_alipay), Toast.LENGTH_SHORT).show();
            }
        }
    })
            .setView(getActivity().getLayoutInflater().inflate(R.layout.fragment_donate, null));
    return builder.create();
}
项目:android-galaxyzoo    文件:ItemsContentProvider.java   
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);
        }
    }
项目:ClubHelperAndroid    文件:PersonListFragment.java   
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View childView,
        int position, long id) {

    Person person = controller.getPersonAt(position);

    String text = person.toString();
    ClipData.Item item = new ClipData.Item(text);
    String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
    ClipData data = new ClipData(text, mimeTypes, item);
    DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(childView);

    childView.startDrag(data, shadowBuilder, childView, 0);
    childView.setVisibility(View.INVISIBLE);
    filter.setVisibility(View.GONE);

    buttonBarDropTarget.setVisibility(View.VISIBLE);
    return true;
}
项目:ClubHelperAndroid    文件:PersonDetailFragment.java   
@Override
public boolean onLongClick(View v) {
    Object tag = v.getTag();
    long contactId = (Long) tag;
    PersonContact contact = controller.findContactWithId(contactId);
    String text = contact.getType() + " - " + contact.getValue();
    ClipData.Item item = new ClipData.Item(text);
    String[] mimeTypes = { ClipDescription.MIMETYPE_TEXT_PLAIN };
    ClipData data = new ClipData(text, mimeTypes, item);
    DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);

    v.startDrag(data, shadowBuilder, v, 0);
    v.setVisibility(View.INVISIBLE);

    buttonBarMain.setVisibility(View.GONE);
    buttonBarDropContact.setVisibility(View.VISIBLE);
    txtFullNameView.setEnabled(false);
    return true;
}
项目:matrix-android-sdk    文件:FileMessage.java   
@Override
public String getMimeType() {
    if (null != info) {
        // the mimetype was not provided or it's invalid
        // some android application set the mimetype to text/uri-list
        // it should be fixed on application side but we need to patch it on client side.
        if ((TextUtils.isEmpty(info.mimetype) || ClipDescription.MIMETYPE_TEXT_URILIST.equals(info.mimetype)) && (body.indexOf('.') > 0)) {
            // the body should contain the filename so try to extract the mimetype from the extension
            String extension = body.substring(body.lastIndexOf('.') + 1, body.length());

            try {
                info.mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
            } catch (Exception e) {
                Log.e(LOG_TAG, "## getMimeType() : getMimeTypeFromExtensionfailed " + e.getMessage());
            }
        }

        if (TextUtils.isEmpty(info.mimetype)) {
            info.mimetype = "application/octet-stream";
        }

        return info.mimetype;
    } else {
        return null;
    }
}
项目:sms_DualCard    文件:RecipientEditTextView.java   
/**
 * 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);
}
项目:sms_DualCard    文件:RecipientEditTextView.java   
/**
 * 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;
}
项目:desktop_for_android    文件:ListViewMenu.java   
protected boolean onMenuItemLongClick(AdapterView<?> parent, View view, int position) {
    String packageName = ((ListViewMenuItem) parent.getAdapter()
            .getItem(position)).getPackageName();
    ClipData.Item clipIconType = new ClipData.Item(Desktop.sListViewMenuIcon);
    ClipData.Item clipPackageName = new ClipData.Item(packageName);
    String[] clipDescription = { ClipDescription.MIMETYPE_TEXT_PLAIN };
    ClipData dragData = new ClipData("", clipDescription, clipIconType);
    dragData.addItem(clipPackageName);

    ImageView dragIcon = (ImageView) view.findViewById(R.id.icon);
    ListViewMenuItemDSB shadowBuilder = new ListViewMenuItemDSB(dragIcon,
            mDragShadowSize, mDragShadowSize);
    view.startDrag(dragData, shadowBuilder, view, 0);

    return true;
}
项目:Sokoban    文件:SokoSelActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_soko_sel);
    loader=new SokoStageLoader(this);
    Intent theIntent=getIntent();
    if(theIntent!=null) {
        String action=theIntent.getAction();
        String type=theIntent.getType();
        if(ClipDescription.MIMETYPE_TEXT_PLAIN.equals(type)) {
            if(Intent.ACTION_VIEW.equals(action)|| Intent.ACTION_SEND.equals(action)) {
                final String str_in=theIntent.getStringExtra(Intent.EXTRA_TEXT);
                if(str_in!=null) {
                    importFile(str_in);
                }
            }
        }
    }
}
项目:ChipsLibrary    文件:RecipientEditTextView.java   
/**
 * 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);
  }
项目:androidProject    文件:Workspace.java   
/**
 * Tests to see if the drop will be accepted by Launcher, and if so, includes additional data
 * in the returned structure related to the widgets that match the drop (or a null list if it is
 * a shortcut drop).  If the drop is not accepted then a null structure is returned.
 */
private Pair<Integer, List<WidgetMimeTypeHandlerData>> validateDrag(DragEvent event) {
    final LauncherModel model = mLauncher.getModel();
    final ClipDescription desc = event.getClipDescription();
    final int mimeTypeCount = desc.getMimeTypeCount();
    for (int i = 0; i < mimeTypeCount; ++i) {
        final String mimeType = desc.getMimeType(i);
        if (mimeType.equals(InstallShortcutReceiver.SHORTCUT_MIMETYPE)) {
            return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, null);
        } else {
            final List<WidgetMimeTypeHandlerData> widgets =
                model.resolveWidgetsForMimeType(mContext, mimeType);
            if (widgets.size() > 0) {
                return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, widgets);
            }
        }
    }
    return null;
}
项目:Calendar_lunar    文件:RecipientEditTextView.java   
/**
 * 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);
}
项目:Calendar_lunar    文件:RecipientEditTextView.java   
/**
 * 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;
}
项目:clip-blacklist    文件:Comparator.java   
/**
 * Compare ClipDescription
 * @param a
 * @param b
 * @return true if equals
 */
public static boolean equals(ClipDescription a, ClipDescription b) {
    boolean ret = a == b;
    if (!ret && a != null && b != null && a.getMimeTypeCount() == b.getMimeTypeCount()) {
        ret = equals(a.getLabel(), b.getLabel());
        if (ret) {
            for (int i = 0; i < a.getMimeTypeCount(); i++) {
                if (!equals(a.getMimeType(i), b.getMimeType(i))) {
                    ret = false;
                    break;
                }
            }
        }
    }

    return ret;
}