本文整理汇总了Java中android.content.ClipDescription.getMimeType方法的典型用法代码示例。如果您正苦于以下问题:Java ClipDescription.getMimeType方法的具体用法?Java ClipDescription.getMimeType怎么用?Java ClipDescription.getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ClipDescription
的用法示例。
在下文中一共展示了ClipDescription.getMimeType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateDrag
import android.content.ClipDescription; //导入方法依赖的package包/类
/**
* 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;
}
示例2: extractTextFromClipData
import android.content.ClipDescription; //导入方法依赖的package包/类
private String extractTextFromClipData(ClipData clipData) {
if (clipData == null) {
return null;
}
ClipData.Item item = clipData.getItemAt(0);
if (item == null) {
return null;
}
ClipDescription description = clipData.getDescription();
if (description == null) {
return null;
}
String mimeType = description.getMimeType(0);
if ("text/plain".equals(mimeType)) {
CharSequence text = item.getText();
if (text != null) {
return text.toString();
}
} else if ("text/html".equals(mimeType) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
String html = item.getHtmlText();
return Jsoup.parse(html).text();
}
return null;
}