本文整理汇总了Java中android.content.ClipboardManager类的典型用法代码示例。如果您正苦于以下问题:Java ClipboardManager类的具体用法?Java ClipboardManager怎么用?Java ClipboardManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClipboardManager类属于android.content包,在下文中一共展示了ClipboardManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMenuItemClick
import android.content.ClipboardManager; //导入依赖的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;
}
示例2: copyText
import android.content.ClipboardManager; //导入依赖的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();
}
示例3: getIntent
import android.content.ClipboardManager; //导入依赖的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;
}
示例4: onTransaction
import android.content.ClipboardManager; //导入依赖的package包/类
private void onTransaction(String hash) {
hideDialog();
dialog = new AlertDialog.Builder(this)
.setTitle(R.string.transaction_succeeded)
.setMessage(hash)
.setPositiveButton(R.string.button_ok, (dialog1, id) -> {
finish();
})
.setNeutralButton(R.string.copy, (dialog1, id) -> {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("transaction hash", hash);
clipboard.setPrimaryClip(clip);
finish();
})
.create();
dialog.show();
}
示例5: onLongClick
import android.content.ClipboardManager; //导入依赖的package包/类
@Override
public boolean onLongClick(View v) {
if (v == mCloseButton) {
return showAccessibilityToast(v, getResources().getString(R.string.close_tab));
} else if (v == mCustomActionButton) {
return showAccessibilityToast(v, mCustomActionButton.getContentDescription());
} else if (v == mTitleUrlContainer) {
ClipboardManager clipboard = (ClipboardManager) getContext()
.getSystemService(Context.CLIPBOARD_SERVICE);
Tab tab = getCurrentTab();
if (tab == null) return false;
String url = tab.getOriginalUrl();
ClipData clip = ClipData.newPlainText("url", url);
clipboard.setPrimaryClip(clip);
Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
示例6: onBindViewHolder
import android.content.ClipboardManager; //导入依赖的package包/类
@Override
public void onBindViewHolder(CodigoDeBarraAdapter.ViewHolder holder, final int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager clipboard = (ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Codigo de barras copiado", extractList.get(position).getCodigoDeBarras());
clipboard.setPrimaryClip(clip);
Toast.makeText(v.getContext(), "Codigo de barras copiado", Toast.LENGTH_LONG).show();
}
});
holder.bindExtractViewModel(extractList.get(position));
}
示例7: TerminalLinesAdapter
import android.content.ClipboardManager; //导入依赖的package包/类
public TerminalLinesAdapter(Activity a, List<TerminalPrintedLine> lines) {
this.activity = a;
this.lines = lines;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
uiHandler = new Handler();
copyRunnable = new Runnable() {
@Override
public void run() {
clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (!copyLine.equals("")) {
clipboardManager.setPrimaryClip(ClipData.newPlainText("OneSheeldClipboard", copyLine));
Toast.makeText(activity.getApplicationContext(), R.string.terminal_line_copied_toast, Toast.LENGTH_SHORT).show();
}else
Toast.makeText(activity.getApplicationContext(), R.string.terminal_couldnt_copy_empty_line_toast, Toast.LENGTH_SHORT).show();
}
}
};
}
示例8: onCreate
import android.content.ClipboardManager; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
context=getApplicationContext();
mClipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
createNotificationChannel();
listener = new ClipboardManager.OnPrimaryClipChangedListener() {
public void onPrimaryClipChanged() {
performClipboardCheck();
}
};
}
示例9: getString
import android.content.ClipboardManager; //导入依赖的package包/类
@Override
@JSMethod
public void getString(@Nullable JSCallback callback) {
Context context = mWXSDKInstance.getContext();
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
Map<String, Object> map = new HashMap<>(2);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
ClipData.Item item = clip.getItemAt(0);
CharSequence text = coerceToText(context, item);
map.put(RESULT, text != null ? RESULT_OK : RESULT_FAILED);
map.put(DATA, text != null ? text : "");
} else {
map.put(RESULT, RESULT_FAILED);
map.put(DATA, "");
}
if (null != callback) {
callback.invoke(map);
}
}
示例10: setPrimaryClip
import android.content.ClipboardManager; //导入依赖的package包/类
private void setPrimaryClip(final ClipData clipData) {
try {
mUiThreadRule.runOnUiThread(new Runnable() {
@Override
public void run() {
ClipboardManager clipboardManager =
(ClipboardManager) InstrumentationRegistry.getTargetContext().getSystemService(CLIPBOARD_SERVICE);
clipboardManager.setPrimaryClip(clipData);
}
});
// ensure clipboard listener has time to react to the changes
// so that subsequent calls can verify what the listener has done.
delay(90);
} catch (Throwable t) {
fail("Unexpected error in setting clipboard. " + t.getMessage());
}
}
示例11: paste
import android.content.ClipboardManager; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void paste() {
ClipboardManager clipboard = (
ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
//noinspection StatementWithEmptyBody
if (clipboard.getText() == null || clipboard.getText() == "") {
//nothing to paste
}
if (!clipboard.hasText()) {
return;
}
if (getSelectionEnd() > getSelectionStart()) {
getText().replace(getSelectionStart(), getSelectionEnd(), clipboard.getText());
} else {
getText().replace(getSelectionEnd(), getSelectionStart(), clipboard.getText());
}
}
示例12: ua
import android.content.ClipboardManager; //导入依赖的package包/类
public void ua()
{
EditText et=(EditText) findViewById(R.id.mainEditText1);
String os =et.getText().toString();
char[] a = os.toCharArray();
StringBuffer b = new StringBuffer("");
String mo ="妮̶";
for (int i=0;i < a.length;i++)
{
b.append(mo.replace('妮', a[i])) ;
ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
manager.setText(b);
}
TextView t=(TextView) findViewById(R.id.mainTextView1);
t.setText(b);
}
示例13: onOptionsItemSelected
import android.content.ClipboardManager; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.fenlei_share:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, url);
startActivity(Intent.createChooser(intent, getTitle()));
break;
case R.id.fenlei_web_open:
Intent intent1 = new Intent();
intent1.setAction(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
break;
case R.id.fenlei_copy_link:
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newRawUri("label", Uri.parse(url));
clipboardManager.setPrimaryClip(clipData);
Snackbar.make(mWebView, "已复制到黏贴版", Snackbar.LENGTH_SHORT).show();
break;
}
return true;
}
示例14: copy
import android.content.ClipboardManager; //导入依赖的package包/类
/**
* 实现文本复制功能
*/
public static void copy(String content, Context context) {
if (context == null || content == null) {
return;
}
// 得到剪贴板管理器
ClipboardManager cmb = (ClipboardManager) context
.getSystemService(Context.CLIPBOARD_SERVICE);
if (cmb == null) {
return;
}
try {
cmb.setPrimaryClip(ClipData.newPlainText(null, content.trim()));
} catch (Exception e) {
LogUtils.e(e);
}
}
示例15: onTouch
import android.content.ClipboardManager; //导入依赖的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;
}