use of android.text.ClipboardManager in project android-ocr by rmtheis.
the class CaptureActivity method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem item) {
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
switch(item.getItemId()) {
case OPTIONS_COPY_RECOGNIZED_TEXT_ID:
clipboardManager.setText(ocrResultView.getText());
if (clipboardManager.hasText()) {
Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
}
return true;
case OPTIONS_SHARE_RECOGNIZED_TEXT_ID:
Intent shareRecognizedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
shareRecognizedTextIntent.setType("text/plain");
shareRecognizedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, ocrResultView.getText());
startActivity(Intent.createChooser(shareRecognizedTextIntent, "Share via"));
return true;
case OPTIONS_COPY_TRANSLATED_TEXT_ID:
clipboardManager.setText(translationView.getText());
if (clipboardManager.hasText()) {
Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
}
return true;
case OPTIONS_SHARE_TRANSLATED_TEXT_ID:
Intent shareTranslatedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
shareTranslatedTextIntent.setType("text/plain");
shareTranslatedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, translationView.getText());
startActivity(Intent.createChooser(shareTranslatedTextIntent, "Share via"));
return true;
default:
return super.onContextItemSelected(item);
}
}
use of android.text.ClipboardManager in project bee by orhanobut.
the class UiHandler method initListView.
private void initListView(ListView listView) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
ContentHolder contentHolder = (ContentHolder) parent.getItemAtPosition(position);
clipboard.setText(contentHolder.getValue());
showToast(contentHolder.getValue() + " is copied to clipboard");
return true;
}
});
}
use of android.text.ClipboardManager in project wechat by motianhuo.
the class PasteEditText method onTextContextMenuItem.
@SuppressLint("NewApi")
@Override
public boolean onTextContextMenuItem(int id) {
if (id == android.R.id.paste) {
ClipboardManager clip = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (clip == null || clip.getText() == null) {
return false;
}
String text = clip.getText().toString();
if (text.startsWith(ChatActivity.COPY_IMAGE)) {
// intent.setDataAndType(Uri.fromFile(new
// File("/sdcard/mn1.jpg")), "image/*");
text = text.replace(ChatActivity.COPY_IMAGE, "");
Intent intent = new Intent(context, AlertDialog.class);
String str = "发送以下图片?";
intent.putExtra("title", str);
intent.putExtra("forwardImage", text);
intent.putExtra("cancel", true);
((Activity) context).startActivityForResult(intent, ChatActivity.REQUEST_CODE_COPY_AND_PASTE);
// clip.setText("");
}
}
return super.onTextContextMenuItem(id);
}
use of android.text.ClipboardManager in project android-toolbox by Knickedi.
the class SafeClipboard method setText.
// PUBLIC =====================================================================================
/**
* Save text on clipboard and let it clear itself after given amount of milliseconds.<br>
* <br>
* Clipboard will only be cleared if it contains the text which was set with this method before,
* so when another text is clipped (e.g. by another application) it won't be cleared. A new call
* will stop old clearance timeout and start a new one.
*
* @param context
* @param text
* text to save on clipboard ({@code null} will clear clipboard)
* @param timeout
* amount of milliseconds text will be available on clipboard ({@code < 1000} equals
* forever)
*/
public static void setText(Context context, String text, long timeout) {
ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(text);
Intent service = new Intent(context, SafeClipboard.class);
if (text == null || timeout < 1000) {
// kill running service (if its running) because it's not needed anymore
context.stopService(service);
} else {
// start (or update) service which will clear
service.putExtra(EXTRA_TEXT, text);
service.putExtra(EXTRA_TIMEOUT, timeout);
context.startService(service);
}
}
use of android.text.ClipboardManager in project android-toolbox by Knickedi.
the class SwipeableListQuickActionActivity method onQuickAction.
/**
* React on quick action click.
*/
@Override
public void onQuickAction(AdapterView<?> parent, View view, int position, int quickActionId) {
switch(quickActionId) {
case QuickAction.OPEN:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(ITEMS[position][1]));
startActivity(i);
break;
case QuickAction.COPY:
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
cm.setText(ITEMS[position][1]);
Toast.makeText(this, "URL copied to clipboard", Toast.LENGTH_SHORT).show();
break;
}
}
Aggregations