本文整理汇总了Java中android.content.ClipDescription.hasMimeType方法的典型用法代码示例。如果您正苦于以下问题:Java ClipDescription.hasMimeType方法的具体用法?Java ClipDescription.hasMimeType怎么用?Java ClipDescription.hasMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ClipDescription
的用法示例。
在下文中一共展示了ClipDescription.hasMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResultsFromIntent
import android.content.ClipDescription; //导入方法依赖的package包/类
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;
}
示例2: onClickButtonPasteToUrlField
import android.content.ClipDescription; //导入方法依赖的package包/类
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();
}
}
示例3: getText
import android.content.ClipDescription; //导入方法依赖的package包/类
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();
}
}
示例4: getText
import android.content.ClipDescription; //导入方法依赖的package包/类
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();
}
}
示例5: canPasteAsPlainText
import android.content.ClipDescription; //导入方法依赖的package包/类
@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);
}
示例6: clipDataToHtmlText
import android.content.ClipDescription; //导入方法依赖的package包/类
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;
}
示例7: processDragStarted
import android.content.ClipDescription; //导入方法依赖的package包/类
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;
}
示例8: handleSystemDragStart
import android.content.ClipDescription; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.N)
private void handleSystemDragStart(DragEvent event) {
if (!FeatureFlags.LAUNCHER3_USE_SYSTEM_DRAG_DRIVER || !Utilities.isNycOrAbove()) {
return;
}
if (mLauncher.isWorkspaceLocked()) {
return;
}
ClipDescription description = event.getClipDescription();
if (!description.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
return;
}
ShortcutInfo info = new ShortcutInfo();
// Set a dummy intent until we get the final value
info.intent = new Intent();
// Since we are not going through the workspace for starting the drag, set drag related
// information on the workspace before starting the drag.
ExternalDragPreviewProvider previewProvider =
new ExternalDragPreviewProvider(mLauncher, info);
mLauncher.getWorkspace().prepareDragWithProvider(previewProvider);
DragOptions options = new DragOptions();
options.systemDndStartPoint = new Point((int) event.getX(), (int) event.getY());
int halfPadding = previewProvider.previewPadding / 2;
mDragController.startDrag(
Bitmap.createBitmap(1, 1, Config.ARGB_8888),
0, 0,
new AnotherWindowDragSource(mLauncher), info,
new Point(- halfPadding, halfPadding),
previewProvider.getPreviewBounds(), 1f, options);
}
示例9: hasText
import android.content.ClipDescription; //导入方法依赖的package包/类
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();
}
}
示例10: getResultsFromIntent
import android.content.ClipDescription; //导入方法依赖的package包/类
static Bundle getResultsFromIntent(Intent intent) {
ClipData clipData = intent.getClipData();
if (clipData == null) {
return null;
}
ClipDescription clipDescription = clipData.getDescription();
if (!clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
return null;
}
if (clipDescription.getLabel().equals(RESULTS_CLIP_LABEL)) {
return clipData.getItemAt(0).getIntent().getExtras().getParcelable(EXTRA_RESULTS_DATA);
}
return null;
}
示例11: getClipParameter
import android.content.ClipDescription; //导入方法依赖的package包/类
/**
* Gets the current clip parameter from the clipboard.
*
* @return The text value of the clip parameter, or null if there is no text on the clipboard.
*/
private static String getClipParameter(Context context) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if ((clipboard != null) && clipboard.hasPrimaryClip()) {
// Get the current primary clip on the clipboard
final ClipData clip = clipboard.getPrimaryClip();
if ((clip != null) && (clip.getItemCount() > 0)) {
final ClipDescription description = clip.getDescription();
// Return null if the clipboard does not contain plain text or html text
if (!description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN) &&
!description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
return null;
}
// Ignore and return null if it's a clip previously copied by LoneColor
final CharSequence label = description.getLabel();
if ((label != null) && (label.equals(context.getString(R.string.app_name)))) {
return null;
}
// Get the text from the clipboard
final CharSequence sequence = clip.getItemAt(0).getText();
if (sequence != null) {
return sequence.toString();
}
}
}
return null;
}
示例12: hasText
import android.content.ClipDescription; //导入方法依赖的package包/类
public static boolean hasText() {
android.text.ClipboardManager clipboardManager = ServiceUtil.getClipboardManager();
if (APILevel.require(11)) {
ClipboardManager cm = (ClipboardManager) clipboardManager;
ClipDescription description = cm.getPrimaryClipDescription();
ClipData clipData = cm.getPrimaryClip();
return clipData != null
&& description != null
&& (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN));
} else {
return clipboardManager.hasText();
}
}
示例13: a
import android.content.ClipDescription; //导入方法依赖的package包/类
public final Bundle a(Intent paramIntent)
{
ClipData localClipData = paramIntent.getClipData();
if (localClipData != null)
{
ClipDescription localClipDescription = localClipData.getDescription();
if ((localClipDescription.hasMimeType("text/vnd.android.intent")) && (localClipDescription.getLabel().equals("android.remoteinput.results"))) {
return (Bundle)localClipData.getItemAt(0).getIntent().getExtras().getParcelable("android.remoteinput.resultsData");
}
}
return null;
}
示例14: write
import android.content.ClipDescription; //导入方法依赖的package包/类
/**
* Write the clipboard to the keyboard device using the {@link DeviceWriter}.
*/
public void write() {
ClipData clipData = clipboardManager.getPrimaryClip();
ClipDescription clipDescription = clipData.getDescription();
if (clipData.getItemCount() > 0 && clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
ClipData.Item item = clipData.getItemAt(0);
String data = String.valueOf(item.getText());
DeviceWriter.write(data);
}
}
示例15: makeClipMemo
import android.content.ClipDescription; //导入方法依赖的package包/类
private void makeClipMemo() {
/*上一个便签插入是否结束*/
// boolean insertFinish = true;
// if (!insertFinish) {
// //LogUtil.e("上次插入事务尚未结束");
// return;
// }
long nowTime = System.currentTimeMillis();
if (nowTime - this.mLastUpdateTime < 1000L) {
//LogUtil.e("与上次间隔时间太短");
return;
}
newDataModel = new DataModel();
ClipDescription clipDescription;
ClipData clipData;
StringBuilder stringBuilder;
clipDescription = this.mClipboardManager.getPrimaryClipDescription();
if ((!clipDescription.hasMimeType("text/plain")) && (!clipDescription.hasMimeType("text/html"))) {
//LogUtil.e("剪切板里面的不是文本内容");
return;
}
this.mLastUpdateTime = nowTime;
clipData = this.mClipboardManager.getPrimaryClip();
stringBuilder = new StringBuilder();
int count = clipData.getItemCount();
for (int i = 0; i < count; i++) {
ClipData.Item item = clipData.getItemAt(i);
if (null != item) {
stringBuilder.append(item.getText());
}
}
newDataModel.setContent(stringBuilder.toString());
}