本文整理匯總了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;
}