Search in sources :

Example 71 with ClipboardManager

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);
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) Context(android.content.Context)

Example 72 with ClipboardManager

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();
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 73 with ClipboardManager

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();
}
Also used : ClipboardManager(android.content.ClipboardManager) Intent(android.content.Intent) ClipData(android.content.ClipData)

Example 74 with ClipboardManager

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;
}
Also used : ClipboardManager(android.content.ClipboardManager) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) Uri(android.net.Uri) File(java.io.File)

Example 75 with ClipboardManager

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);
}
Also used : ClipboardManager(android.content.ClipboardManager)

Aggregations

ClipboardManager (android.content.ClipboardManager)125 ClipData (android.content.ClipData)82 Intent (android.content.Intent)17 View (android.view.View)15 TextView (android.widget.TextView)13 Context (android.content.Context)10 Paint (android.graphics.Paint)9 DialogInterface (android.content.DialogInterface)7 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 Editable (android.text.Editable)7 TextPaint (android.text.TextPaint)7 ImageView (android.widget.ImageView)6 TargetApi (android.annotation.TargetApi)5 Spanned (android.text.Spanned)5 AlertDialog (android.app.AlertDialog)4 Uri (android.net.Uri)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Drawable (android.graphics.drawable.Drawable)3 MenuItem (android.view.MenuItem)3