本文整理匯總了Java中android.content.ClipData類的典型用法代碼示例。如果您正苦於以下問題:Java ClipData類的具體用法?Java ClipData怎麽用?Java ClipData使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClipData類屬於android.content包,在下文中一共展示了ClipData類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: importVideoFromClipData
import android.content.ClipData; //導入依賴的package包/類
private static void importVideoFromClipData(Intent data) {
ClipData clipData = data.getClipData();
Log.d(TAG,"Video importFromClipData");
if (clipData.getItemCount() == 0)
return;
ArrayList<Uri> uris = new ArrayList(clipData.getItemCount());
for (int i = 0 ; i < clipData.getItemCount() ; i++ ){
Uri uri = clipData.getItemAt(i).getUri();
uris.add(resolveUri(uri));
}
importVideoFromFileUri(uris);
}
示例2: importImageFromClipData
import android.content.ClipData; //導入依賴的package包/類
private static void importImageFromClipData(Intent data) {
ClipData clipData = data.getClipData();
Log.d(TAG,"importFromClipData");
if (clipData.getItemCount() == 0)
return;
ArrayList<Uri> uris = new ArrayList(clipData.getItemCount());
for (int i = 0 ; i < clipData.getItemCount() ; i++ ){
Uri uri = clipData.getItemAt(i).getUri();
uris.add(resolveUri(uri));
}
importImageFromFileUri(uris);
}
示例3: onMenuItemClick
import android.content.ClipData; //導入依賴的package包/類
@Override
public boolean onMenuItemClick(MenuItem item, LogLine logLine) {
if (logLine != null) {
switch (item.getItemId()) {
case CONTEXT_MENU_COPY_ID:
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText(null, logLine.getOriginalLine()));
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
return true;
case CONTEXT_MENU_FILTER_ID:
if (logLine.getProcessId() == -1) {
// invalid line
return false;
}
showSearchByDialog(logLine);
return true;
}
}
return false;
}
示例4: onOptionsItemSelected
import android.content.ClipData; //導入依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.miCopySysInfo:
ClipboardManager manager = (ClipboardManager)getSystemService(Activity.CLIPBOARD_SERVICE);
if (manager == null) {
Toast.makeText(this, "Couldn't access clipboard", Toast.LENGTH_LONG).show();
return true;
}
manager.setPrimaryClip(ClipData.newPlainText(CLIP_TITLE, debugOutput));
Toast.makeText(this, "Copied to clipboard", Toast.LENGTH_LONG).show();
return true;
case R.id.miShareSysInfo:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, debugOutput);
startActivity(i);
return true;
}
return super.onOptionsItemSelected(item);
}
示例5: onBindViewHolder
import android.content.ClipData; //導入依賴的package包/類
@Override
public void onBindViewHolder(GifViewHolder holder, int position) {
final Api.GifResult result = results[position];
holder.gifView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager clipboard =
(ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip =
ClipData.newPlainText("giphy_url", result.images.fixed_height.url);
clipboard.setPrimaryClip(clip);
Intent fullscreenIntent = FullscreenActivity.getIntent(activity, result);
activity.startActivity(fullscreenIntent);
}
});
requestBuilder.load(result).into(holder.gifView);
preloadSizeProvider.setView(holder.gifView);
}
示例6: copyLink
import android.content.ClipData; //導入依賴的package包/類
@Override
public void copyLink() {
if (checkNull()) {
view.showCopyTextError();
return;
}
ClipboardManager manager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = null;
switch (type) {
case TYPE_ZHIHU:
clipData = ClipData.newPlainText("text", Html.fromHtml(zhihuDailyStory.getShare_url()).toString());
break;
case TYPE_GUOKR:
clipData = ClipData.newPlainText("text", Html.fromHtml(Api.GUOKR_ARTICLE_LINK_V1 + id).toString());
break;
case TYPE_DOUBAN:
clipData = ClipData.newPlainText("text", Html.fromHtml(doubanMomentStory.getOriginal_url()).toString());
}
manager.setPrimaryClip(clipData);
view.showTextCopied();
}
示例7: copyText
import android.content.ClipData; //導入依賴的package包/類
@Override
public void copyText() {
if (checkNull()) {
view.showCopyTextError();
return;
}
ClipboardManager manager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = null;
switch (type) {
case TYPE_ZHIHU:
clipData = ClipData.newPlainText("text", Html.fromHtml(title + "\n" + zhihuDailyStory.getBody()).toString());
break;
case TYPE_GUOKR:
clipData = ClipData.newPlainText("text", Html.fromHtml(guokrStory).toString());
break;
case TYPE_DOUBAN:
clipData = ClipData.newPlainText("text", Html.fromHtml(title + "\n" + doubanMomentStory.getContent()).toString());
}
manager.setPrimaryClip(clipData);
view.showTextCopied();
}
示例8: onCreate
import android.content.ClipData; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list_view);
adapter = new PortListAdapter(MainActivity.this, ports);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String item = ports.get(i);
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("copy port", item);
clipboard.setPrimaryClip(clip);
Toast.makeText(MainActivity.this, "port '" + item + "' copied", Toast.LENGTH_LONG).show();
}
});
}
示例9: getIntent
import android.content.ClipData; //導入依賴的package包/類
/**
* 獲取剪貼板的意圖
*
* @return 剪貼板的意圖
*/
public static Intent getIntent() {
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
return clip.getItemAt(0).getIntent();
}
return null;
}
示例10: onBindViewHolder
import android.content.ClipData; //導入依賴的package包/類
@Override
public void onBindViewHolder(GifViewHolder holder, int position) {
final Api.GifResult result = results[position];
holder.gifView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager clipboard =
(ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip =
ClipData.newPlainText("giphy_url", result.images.fixed_height.url);
Preconditions.checkNotNull(clipboard).setPrimaryClip(clip);
Intent fullscreenIntent = FullscreenActivity.getIntent(activity, result);
activity.startActivity(fullscreenIntent);
}
});
// clearOnDetach let's us stop animating GifDrawables that RecyclerView hasn't yet recycled
// but that are currently off screen.
requestBuilder.load(result).into(holder.gifView).clearOnDetach();
preloadSizeProvider.setView(holder.gifView);
}
示例11: onFinished
import android.content.ClipData; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void onFinished(Uri... uris) {
Log.d(TAG, "onFinished() " + Arrays.toString(uris));
final Intent intent = new Intent();
if (uris.length == 1) {
intent.setData(uris[0]);
} else if (uris.length > 1) {
final ClipData clipData = new ClipData(
null, mState.acceptMimes, new ClipData.Item(uris[0]));
for (int i = 1; i < uris.length; i++) {
clipData.addItem(new ClipData.Item(uris[i]));
}
if(Utils.hasJellyBean()){
intent.setClipData(clipData);
}
else{
intent.setData(uris[0]);
}
}
if (mState.action == DocumentsActivity.State.ACTION_GET_CONTENT) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else if (mState.action == ACTION_OPEN_TREE) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
} else {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
}
setResult(Activity.RESULT_OK, intent);
finish();
}
示例12: onTouch
import android.content.ClipData; //導入依賴的package包/類
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mSearch.getCompoundDrawables()[2] != null) {
boolean tappedX = event.getX() > (mSearch.getWidth()
- mSearch.getPaddingRight() - mIcon.getIntrinsicWidth());
if (tappedX) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (mSearch.hasFocus()) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", mSearch.getText()
.toString());
clipboard.setPrimaryClip(clip);
Utils.showToast(
mActivity,
mActivity.getResources().getString(
R.string.message_text_copied));
} else {
refreshOrStop();
}
}
return true;
}
}
return false;
}
示例13: onLinkMenuClicked
import android.content.ClipData; //導入依賴的package包/類
private void onLinkMenuClicked(Dialog d, int position) {
switch (position) {
case 0:
newTab(currentClickUrl, true);
break;
case 1:
if(getCurrentWebView()!=null) {
getCurrentWebView().loadUrl(currentClickUrl);
}
break;
case 2:
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", currentClickUrl);
clipboard.setPrimaryClip(clip);
Utils.showToast(mActivity,
mActivity.getResources().getString(R.string.message_link_copied));
break;
}
}
示例14: setEditText
import android.content.ClipData; //導入依賴的package包/類
public void setEditText(@NonNull Context context, @NonNull String text) throws MyException {
if (null == context) {
throw new NullPointerException("context");
}
if (null == text) {
throw new NullPointerException("text");
}
try {
//清空內容
Bundle arguments = new Bundle();
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT, AccessibilityNodeInfo
.MOVEMENT_GRANULARITY_LINE);
arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN, true);
mAccessibilityNodeInfo.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY,
arguments);
//粘貼內容
ClipData clipData = ClipData.newPlainText(context.getPackageName(), text);
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboardManager.setPrimaryClip(clipData);
mAccessibilityNodeInfo.performAction(AccessibilityNodeInfo.ACTION_PASTE);
} catch (Exception e) {
throw new MyException(e);
}
}
示例15: handleGallery
import android.content.ClipData; //導入依賴的package包/類
private ArrayList<Uri> handleGallery(Intent data) {
ArrayList<Uri> uris = new ArrayList<>();
if (data.getData() != null) { // Single select
uris.add(data.getData());
} else { // Multi select
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
ClipData clipData = data.getClipData();
for (int i = 0; i < clipData.getItemCount(); i++) {
uris.add(clipData.getItemAt(i).getUri());
}
}
}
return uris;
}