use of android.content.ClipboardManager in project Signal-Android by WhisperSystems.
the class Util method writeTextToClipboard.
public static void writeTextToClipboard(@NonNull Context context, @NonNull String text) {
if (VERSION.SDK_INT >= 11) {
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboardManager.setPrimaryClip(ClipData.newPlainText("Safety numbers", text));
} else {
android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboardManager.setText(text);
}
}
use of android.content.ClipboardManager in project platform_frameworks_base by android.
the class TextView method setPrimaryClip.
private void setPrimaryClip(ClipData clip) {
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(clip);
sLastCutCopyOrTextChangedTime = SystemClock.uptimeMillis();
}
use of android.content.ClipboardManager in project android by owncloud.
the class CopyToClipboardActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
// get the clipboard system service
ClipboardManager clipboardManager = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE);
// get the text to copy into the clipboard
Intent intent = getIntent();
CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
if (text != null && text.length() > 0) {
// minimum API level >= 11 -> only modern Clipboard
ClipData clip = ClipData.newPlainText(getString(R.string.clipboard_label, getString(R.string.app_name)), text);
clipboardManager.setPrimaryClip(clip);
// API level < 11 -> legacy Clipboard - NOT SUPPORTED ANYMORE
// clipboardManager.setText(text);
// alert the user that the text is in the clipboard and we're done
Toast.makeText(this, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, R.string.clipboard_no_text_to_copy, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(this, R.string.clipboard_uxexpected_error, Toast.LENGTH_SHORT).show();
Log_OC.e(TAG, "Exception caught while copying to clipboard", e);
}
finish();
}
use of android.content.ClipboardManager in project weiciyuan by qii.
the class LongClickListener method onLongClick.
@Override
public boolean onLongClick(View v) {
String[] values = { getString(R.string.copy_link_to_clipboard), getString(R.string.share), getString(R.string.save_pic_album) };
new AlertDialog.Builder(context).setItems(values, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 0:
ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(ClipData.newPlainText("sinaweibo", url));
Toast.makeText(context, getString(R.string.copy_successfully), Toast.LENGTH_SHORT).show();
break;
case 1:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
if (!TextUtils.isEmpty(filePath)) {
Uri uri = Uri.fromFile(new File(filePath));
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
if (Utility.isIntentSafe(context, sharingIntent)) {
context.startActivity(Intent.createChooser(sharingIntent, getString(R.string.share)));
}
}
break;
case 2:
saveBitmapToPictureDir(filePath);
break;
}
}
}).show();
return true;
}
use of android.content.ClipboardManager in project MVPArms by JessYanCoding.
the class DeviceUtils method copyTextToBoard.
@SuppressWarnings("deprecation")
public static void copyTextToBoard(Context context, String string) {
if (TextUtils.isEmpty(string))
return;
ClipboardManager clip = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clip.setText(string);
}
Aggregations